]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/bus/imx-weim.c
Merge branch 'x86/jumplabel' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
[mirror_ubuntu-zesty-kernel.git] / drivers / bus / imx-weim.c
CommitLineData
85bf6d4e
HS
1/*
2 * EIM driver for Freescale's i.MX chips
3 *
4 * Copyright (C) 2013 Freescale Semiconductor, Inc.
5 *
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.
9 */
10#include <linux/module.h>
11#include <linux/clk.h>
12#include <linux/io.h>
13#include <linux/of_device.h>
14
3f98b6ba
AS
15struct imx_weim_devtype {
16 unsigned int cs_count;
17 unsigned int cs_regs_count;
18 unsigned int cs_stride;
19};
20
21static const struct imx_weim_devtype imx1_weim_devtype = {
22 .cs_count = 6,
23 .cs_regs_count = 2,
24 .cs_stride = 0x08,
25};
26
27static const struct imx_weim_devtype imx27_weim_devtype = {
28 .cs_count = 6,
29 .cs_regs_count = 3,
30 .cs_stride = 0x10,
31};
32
33static const struct imx_weim_devtype imx50_weim_devtype = {
34 .cs_count = 4,
35 .cs_regs_count = 6,
36 .cs_stride = 0x18,
37};
38
39static const struct imx_weim_devtype imx51_weim_devtype = {
40 .cs_count = 6,
41 .cs_regs_count = 6,
42 .cs_stride = 0x18,
43};
44
85bf6d4e 45static const struct of_device_id weim_id_table[] = {
3f98b6ba
AS
46 /* i.MX1/21 */
47 { .compatible = "fsl,imx1-weim", .data = &imx1_weim_devtype, },
48 /* i.MX25/27/31/35 */
49 { .compatible = "fsl,imx27-weim", .data = &imx27_weim_devtype, },
50 /* i.MX50/53/6Q */
51 { .compatible = "fsl,imx50-weim", .data = &imx50_weim_devtype, },
52 { .compatible = "fsl,imx6q-weim", .data = &imx50_weim_devtype, },
53 /* i.MX51 */
54 { .compatible = "fsl,imx51-weim", .data = &imx51_weim_devtype, },
55 { }
85bf6d4e
HS
56};
57MODULE_DEVICE_TABLE(of, weim_id_table);
58
85bf6d4e 59/* Parse and set the timing for this device. */
3f98b6ba
AS
60static int __init weim_timing_setup(struct device_node *np, void __iomem *base,
61 const struct imx_weim_devtype *devtype)
85bf6d4e 62{
3f98b6ba
AS
63 u32 cs_idx, value[devtype->cs_regs_count];
64 int i, ret;
85bf6d4e
HS
65
66 /* get the CS index from this child node's "reg" property. */
67 ret = of_property_read_u32(np, "reg", &cs_idx);
68 if (ret)
69 return ret;
70
3f98b6ba 71 if (cs_idx >= devtype->cs_count)
85bf6d4e
HS
72 return -EINVAL;
73
74 ret = of_property_read_u32_array(np, "fsl,weim-cs-timing",
3f98b6ba 75 value, devtype->cs_regs_count);
85bf6d4e
HS
76 if (ret)
77 return ret;
78
79 /* set the timing for WEIM */
3f98b6ba
AS
80 for (i = 0; i < devtype->cs_regs_count; i++)
81 writel(value[i], base + cs_idx * devtype->cs_stride + i * 4);
82
85bf6d4e
HS
83 return 0;
84}
85
29e54970
AS
86static int __init weim_parse_dt(struct platform_device *pdev,
87 void __iomem *base)
85bf6d4e 88{
3f98b6ba
AS
89 const struct of_device_id *of_id = of_match_device(weim_id_table,
90 &pdev->dev);
91 const struct imx_weim_devtype *devtype = of_id->data;
85bf6d4e
HS
92 struct device_node *child;
93 int ret;
94
95 for_each_child_of_node(pdev->dev.of_node, child) {
96 if (!child->name)
97 continue;
98
3f98b6ba 99 ret = weim_timing_setup(child, base, devtype);
85bf6d4e
HS
100 if (ret) {
101 dev_err(&pdev->dev, "%s set timing failed.\n",
102 child->full_name);
103 return ret;
104 }
105 }
106
107 ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
108 if (ret)
109 dev_err(&pdev->dev, "%s fail to create devices.\n",
110 pdev->dev.of_node->full_name);
111 return ret;
112}
113
29e54970 114static int __init weim_probe(struct platform_device *pdev)
85bf6d4e 115{
85bf6d4e 116 struct resource *res;
70ac98da
AS
117 struct clk *clk;
118 void __iomem *base;
b2d1fb73 119 int ret;
85bf6d4e 120
85bf6d4e
HS
121 /* get the resource */
122 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
70ac98da 123 base = devm_ioremap_resource(&pdev->dev, res);
b2d1fb73
AS
124 if (IS_ERR(base))
125 return PTR_ERR(base);
85bf6d4e
HS
126
127 /* get the clock */
70ac98da
AS
128 clk = devm_clk_get(&pdev->dev, NULL);
129 if (IS_ERR(clk))
b2d1fb73 130 return PTR_ERR(clk);
85bf6d4e 131
70ac98da 132 ret = clk_prepare_enable(clk);
85bf6d4e 133 if (ret)
b2d1fb73 134 return ret;
85bf6d4e
HS
135
136 /* parse the device node */
70ac98da 137 ret = weim_parse_dt(pdev, base);
b2d1fb73 138 if (ret)
70ac98da 139 clk_disable_unprepare(clk);
b2d1fb73
AS
140 else
141 dev_info(&pdev->dev, "Driver registered.\n");
85bf6d4e 142
85bf6d4e
HS
143 return ret;
144}
145
146static struct platform_driver weim_driver = {
147 .driver = {
fc608c74
AS
148 .name = "imx-weim",
149 .owner = THIS_MODULE,
150 .of_match_table = weim_id_table,
85bf6d4e 151 },
85bf6d4e 152};
29e54970 153module_platform_driver_probe(weim_driver, weim_probe);
85bf6d4e 154
85bf6d4e
HS
155MODULE_AUTHOR("Freescale Semiconductor Inc.");
156MODULE_DESCRIPTION("i.MX EIM Controller Driver");
157MODULE_LICENSE("GPL");