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>
14 #include <linux/mfd/syscon.h>
15 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
16 #include <linux/regmap.h>
18 struct imx_weim_devtype
{
19 unsigned int cs_count
;
20 unsigned int cs_regs_count
;
21 unsigned int cs_stride
;
24 static const struct imx_weim_devtype imx1_weim_devtype
= {
30 static const struct imx_weim_devtype imx27_weim_devtype
= {
36 static const struct imx_weim_devtype imx50_weim_devtype
= {
42 static const struct imx_weim_devtype imx51_weim_devtype
= {
48 static const struct of_device_id weim_id_table
[] = {
50 { .compatible
= "fsl,imx1-weim", .data
= &imx1_weim_devtype
, },
52 { .compatible
= "fsl,imx27-weim", .data
= &imx27_weim_devtype
, },
54 { .compatible
= "fsl,imx50-weim", .data
= &imx50_weim_devtype
, },
55 { .compatible
= "fsl,imx6q-weim", .data
= &imx50_weim_devtype
, },
57 { .compatible
= "fsl,imx51-weim", .data
= &imx51_weim_devtype
, },
60 MODULE_DEVICE_TABLE(of
, weim_id_table
);
62 static int __init
imx_weim_gpr_setup(struct platform_device
*pdev
)
64 struct device_node
*np
= pdev
->dev
.of_node
;
65 struct property
*prop
;
69 05, /* CS0(128M) CS1(0M) CS2(0M) CS3(0M) */
70 033, /* CS0(64M) CS1(64M) CS2(0M) CS3(0M) */
71 0113, /* CS0(64M) CS1(32M) CS2(32M) CS3(0M) */
72 01111, /* CS0(32M) CS1(32M) CS2(32M) CS3(32M) */
79 gpr
= syscon_regmap_lookup_by_phandle(np
, "fsl,weim-cs-gpr");
81 dev_dbg(&pdev
->dev
, "failed to find weim-cs-gpr\n");
85 of_property_for_each_u32(np
, "ranges", prop
, p
, val
) {
88 } else if (i
% 4 == 3 && val
) {
89 val
= (val
/ SZ_32M
) | 1;
90 gprval
|= val
<< cs
* 3;
98 for (i
= 0; i
< ARRAY_SIZE(gprvals
); i
++) {
99 if (gprval
== gprvals
[i
]) {
100 /* Found it. Set up IOMUXC_GPR1[11:0] with it. */
101 regmap_update_bits(gpr
, IOMUXC_GPR1
, 0xfff, gprval
);
107 dev_err(&pdev
->dev
, "Invalid 'ranges' configuration\n");
111 /* Parse and set the timing for this device. */
112 static int __init
weim_timing_setup(struct device_node
*np
, void __iomem
*base
,
113 const struct imx_weim_devtype
*devtype
)
115 u32 cs_idx
, value
[devtype
->cs_regs_count
];
118 /* get the CS index from this child node's "reg" property. */
119 ret
= of_property_read_u32(np
, "reg", &cs_idx
);
123 if (cs_idx
>= devtype
->cs_count
)
126 ret
= of_property_read_u32_array(np
, "fsl,weim-cs-timing",
127 value
, devtype
->cs_regs_count
);
131 /* set the timing for WEIM */
132 for (i
= 0; i
< devtype
->cs_regs_count
; i
++)
133 writel(value
[i
], base
+ cs_idx
* devtype
->cs_stride
+ i
* 4);
138 static int __init
weim_parse_dt(struct platform_device
*pdev
,
141 const struct of_device_id
*of_id
= of_match_device(weim_id_table
,
143 const struct imx_weim_devtype
*devtype
= of_id
->data
;
144 struct device_node
*child
;
145 int ret
, have_child
= 0;
147 if (devtype
== &imx50_weim_devtype
) {
148 ret
= imx_weim_gpr_setup(pdev
);
153 for_each_available_child_of_node(pdev
->dev
.of_node
, child
) {
157 ret
= weim_timing_setup(child
, base
, devtype
);
159 dev_warn(&pdev
->dev
, "%s set timing failed.\n",
166 ret
= of_platform_populate(pdev
->dev
.of_node
,
167 of_default_bus_match_table
,
170 dev_err(&pdev
->dev
, "%s fail to create devices.\n",
171 pdev
->dev
.of_node
->full_name
);
175 static int __init
weim_probe(struct platform_device
*pdev
)
177 struct resource
*res
;
182 /* get the resource */
183 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
184 base
= devm_ioremap_resource(&pdev
->dev
, res
);
186 return PTR_ERR(base
);
189 clk
= devm_clk_get(&pdev
->dev
, NULL
);
193 ret
= clk_prepare_enable(clk
);
197 /* parse the device node */
198 ret
= weim_parse_dt(pdev
, base
);
200 clk_disable_unprepare(clk
);
202 dev_info(&pdev
->dev
, "Driver registered.\n");
207 static struct platform_driver weim_driver
= {
210 .of_match_table
= weim_id_table
,
213 module_platform_driver_probe(weim_driver
, weim_probe
);
215 MODULE_AUTHOR("Freescale Semiconductor Inc.");
216 MODULE_DESCRIPTION("i.MX EIM Controller Driver");
217 MODULE_LICENSE("GPL");