diff --git a/subsys/disk/disk_access_usdhc.c b/subsys/disk/disk_access_usdhc.c index 677a55be3b4..09eb51b8850 100644 --- a/subsys/disk/disk_access_usdhc.c +++ b/subsys/disk/disk_access_usdhc.c @@ -6,6 +6,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT nxp_imx_usdhc + #include #include #include @@ -2874,28 +2876,16 @@ static int disk_usdhc_init(struct device *dev) return disk_access_register(&usdhc_disk); } -#ifdef CONFIG_DISK_ACCESS_USDHC1 -static struct usdhc_priv usdhc_priv_1; -#if DT_NODE_HAS_STATUS(DT_INST(0, nxp_imx_usdhc), okay) -DEVICE_AND_API_INIT(usdhc_dev1, - DT_LABEL(DT_INST(0, nxp_imx_usdhc)), disk_usdhc_init, - &usdhc_priv_1, NULL, APPLICATION, - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, - NULL); -#else -#error No USDHC1 slot on board. -#endif -#endif +#define DISK_ACCESS_USDHC_INIT(n) \ + static struct usdhc_priv usdhc_priv_##n; \ + \ + DEVICE_AND_API_INIT(usdhc_dev##n, \ + DT_INST_LABEL(n), \ + &disk_usdhc_init, \ + &usdhc_priv_##n, \ + NULL, \ + APPLICATION, \ + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + NULL); -#ifdef CONFIG_DISK_ACCESS_USDHC2 -static struct usdhc_priv usdhc_priv_2; -#if DT_NODE_HAS_STATUS(DT_INST(1, nxp_imx_usdhc), okay) -DEVICE_AND_API_INIT(usdhc_dev2, - DT_LABEL(DT_INST(1, nxp_imx_usdhc)), disk_usdhc_init, - usdhc_priv_2, NULL, APPLICATION, - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, - NULL); -#else -#error No USDHC2 slot on board. -#endif -#endif +DT_INST_FOREACH_STATUS_OKAY(DISK_ACCESS_USDHC_INIT)