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>
20 static const struct of_device_id weim_id_table
[] = {
21 { .compatible
= "fsl,imx6q-weim", },
24 MODULE_DEVICE_TABLE(of
, weim_id_table
);
26 #define CS_TIMING_LEN 6
27 #define CS_REG_RANGE 0x18
29 /* Parse and set the timing for this device. */
31 weim_timing_setup(struct platform_device
*pdev
, struct device_node
*np
)
33 struct imx_weim
*weim
= platform_get_drvdata(pdev
);
34 u32 value
[CS_TIMING_LEN
];
39 /* get the CS index from this child node's "reg" property. */
40 ret
= of_property_read_u32(np
, "reg", &cs_idx
);
44 /* The weim has four chip selects. */
48 ret
= of_property_read_u32_array(np
, "fsl,weim-cs-timing",
49 value
, CS_TIMING_LEN
);
53 /* set the timing for WEIM */
54 for (i
= 0; i
< CS_TIMING_LEN
; i
++)
55 writel(value
[i
], weim
->base
+ cs_idx
* CS_REG_RANGE
+ i
* 4);
59 static int weim_parse_dt(struct platform_device
*pdev
)
61 struct device_node
*child
;
64 for_each_child_of_node(pdev
->dev
.of_node
, child
) {
68 ret
= weim_timing_setup(pdev
, child
);
70 dev_err(&pdev
->dev
, "%s set timing failed.\n",
76 ret
= of_platform_populate(pdev
->dev
.of_node
, NULL
, NULL
, &pdev
->dev
);
78 dev_err(&pdev
->dev
, "%s fail to create devices.\n",
79 pdev
->dev
.of_node
->full_name
);
83 static int weim_probe(struct platform_device
*pdev
)
85 struct imx_weim
*weim
;
89 weim
= devm_kzalloc(&pdev
->dev
, sizeof(*weim
), GFP_KERNEL
);
94 platform_set_drvdata(pdev
, weim
);
96 /* get the resource */
97 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
98 weim
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
99 if (IS_ERR(weim
->base
)) {
100 ret
= PTR_ERR(weim
->base
);
105 weim
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
106 if (IS_ERR(weim
->clk
))
109 ret
= clk_prepare_enable(weim
->clk
);
113 /* parse the device node */
114 ret
= weim_parse_dt(pdev
);
116 clk_disable_unprepare(weim
->clk
);
120 dev_info(&pdev
->dev
, "WEIM driver registered.\n");
127 static struct platform_driver weim_driver
= {
130 .of_match_table
= weim_id_table
,
135 module_platform_driver(weim_driver
);
136 MODULE_AUTHOR("Freescale Semiconductor Inc.");
137 MODULE_DESCRIPTION("i.MX EIM Controller Driver");
138 MODULE_LICENSE("GPL");