2 * EIM driver for Freescale's i.MX chips
4 * Copyright (C) 2013 Freescale Semiconductor, Inc.
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
10 #include <linux/module.h>
11 #include <linux/clk.h>
13 #include <linux/of_device.h>
15 struct imx_weim_devtype
{
16 unsigned int cs_count
;
17 unsigned int cs_regs_count
;
18 unsigned int cs_stride
;
21 static const struct imx_weim_devtype imx1_weim_devtype
= {
27 static const struct imx_weim_devtype imx27_weim_devtype
= {
33 static const struct imx_weim_devtype imx50_weim_devtype
= {
39 static const struct imx_weim_devtype imx51_weim_devtype
= {
45 static const struct of_device_id weim_id_table
[] = {
47 { .compatible
= "fsl,imx1-weim", .data
= &imx1_weim_devtype
, },
49 { .compatible
= "fsl,imx27-weim", .data
= &imx27_weim_devtype
, },
51 { .compatible
= "fsl,imx50-weim", .data
= &imx50_weim_devtype
, },
52 { .compatible
= "fsl,imx6q-weim", .data
= &imx50_weim_devtype
, },
54 { .compatible
= "fsl,imx51-weim", .data
= &imx51_weim_devtype
, },
57 MODULE_DEVICE_TABLE(of
, weim_id_table
);
59 /* Parse and set the timing for this device. */
60 static int __init
weim_timing_setup(struct device_node
*np
, void __iomem
*base
,
61 const struct imx_weim_devtype
*devtype
)
63 u32 cs_idx
, value
[devtype
->cs_regs_count
];
66 /* get the CS index from this child node's "reg" property. */
67 ret
= of_property_read_u32(np
, "reg", &cs_idx
);
71 if (cs_idx
>= devtype
->cs_count
)
74 ret
= of_property_read_u32_array(np
, "fsl,weim-cs-timing",
75 value
, devtype
->cs_regs_count
);
79 /* set the timing for WEIM */
80 for (i
= 0; i
< devtype
->cs_regs_count
; i
++)
81 writel(value
[i
], base
+ cs_idx
* devtype
->cs_stride
+ i
* 4);
86 static int __init
weim_parse_dt(struct platform_device
*pdev
,
89 const struct of_device_id
*of_id
= of_match_device(weim_id_table
,
91 const struct imx_weim_devtype
*devtype
= of_id
->data
;
92 struct device_node
*child
;
95 for_each_child_of_node(pdev
->dev
.of_node
, child
) {
99 ret
= weim_timing_setup(child
, base
, devtype
);
101 dev_err(&pdev
->dev
, "%s set timing failed.\n",
107 ret
= of_platform_populate(pdev
->dev
.of_node
, NULL
, NULL
, &pdev
->dev
);
109 dev_err(&pdev
->dev
, "%s fail to create devices.\n",
110 pdev
->dev
.of_node
->full_name
);
114 static int __init
weim_probe(struct platform_device
*pdev
)
116 struct resource
*res
;
121 /* get the resource */
122 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
123 base
= devm_ioremap_resource(&pdev
->dev
, res
);
125 return PTR_ERR(base
);
128 clk
= devm_clk_get(&pdev
->dev
, NULL
);
132 ret
= clk_prepare_enable(clk
);
136 /* parse the device node */
137 ret
= weim_parse_dt(pdev
, base
);
139 clk_disable_unprepare(clk
);
141 dev_info(&pdev
->dev
, "Driver registered.\n");
146 static struct platform_driver weim_driver
= {
149 .owner
= THIS_MODULE
,
150 .of_match_table
= weim_id_table
,
153 module_platform_driver_probe(weim_driver
, weim_probe
);
155 MODULE_AUTHOR("Freescale Semiconductor Inc.");
156 MODULE_DESCRIPTION("i.MX EIM Controller Driver");
157 MODULE_LICENSE("GPL");