2 * Freescale MXS Low Resolution Analog-to-Digital Converter driver
4 * Copyright (c) 2012 DENX Software Engineering, GmbH.
5 * Copyright (c) 2017 Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
8 * Marek Vasut <marex@denx.de>
9 * Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
22 #include <linux/clk.h>
23 #include <linux/device.h>
24 #include <linux/mfd/core.h>
25 #include <linux/mfd/mxs-lradc.h>
26 #include <linux/module.h>
28 #include <linux/of_device.h>
29 #include <linux/platform_device.h>
30 #include <linux/slab.h>
36 enum mx23_lradc_irqs
{
37 MX23_LRADC_TS_IRQ
= 0,
48 enum mx28_lradc_irqs
{
49 MX28_LRADC_TS_IRQ
= 0,
50 MX28_LRADC_TRESH0_IRQ
,
51 MX28_LRADC_TRESH1_IRQ
,
60 MX28_LRADC_BUTTON0_IRQ
,
61 MX28_LRADC_BUTTON1_IRQ
,
64 static struct resource mx23_adc_resources
[] = {
65 DEFINE_RES_MEM(0x0, 0x0),
66 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH0_IRQ
, "mxs-lradc-channel0"),
67 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH1_IRQ
, "mxs-lradc-channel1"),
68 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH2_IRQ
, "mxs-lradc-channel2"),
69 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH3_IRQ
, "mxs-lradc-channel3"),
70 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH4_IRQ
, "mxs-lradc-channel4"),
71 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH5_IRQ
, "mxs-lradc-channel5"),
74 static struct resource mx23_touchscreen_resources
[] = {
75 DEFINE_RES_MEM(0x0, 0x0),
76 DEFINE_RES_IRQ_NAMED(MX23_LRADC_TS_IRQ
, "mxs-lradc-touchscreen"),
77 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH6_IRQ
, "mxs-lradc-channel6"),
78 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH7_IRQ
, "mxs-lradc-channel7"),
81 static struct resource mx28_adc_resources
[] = {
82 DEFINE_RES_MEM(0x0, 0x0),
83 DEFINE_RES_IRQ_NAMED(MX28_LRADC_TRESH0_IRQ
, "mxs-lradc-thresh0"),
84 DEFINE_RES_IRQ_NAMED(MX28_LRADC_TRESH1_IRQ
, "mxs-lradc-thresh1"),
85 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH0_IRQ
, "mxs-lradc-channel0"),
86 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH1_IRQ
, "mxs-lradc-channel1"),
87 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH2_IRQ
, "mxs-lradc-channel2"),
88 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH3_IRQ
, "mxs-lradc-channel3"),
89 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH4_IRQ
, "mxs-lradc-channel4"),
90 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH5_IRQ
, "mxs-lradc-channel5"),
91 DEFINE_RES_IRQ_NAMED(MX28_LRADC_BUTTON0_IRQ
, "mxs-lradc-button0"),
92 DEFINE_RES_IRQ_NAMED(MX28_LRADC_BUTTON1_IRQ
, "mxs-lradc-button1"),
95 static struct resource mx28_touchscreen_resources
[] = {
96 DEFINE_RES_MEM(0x0, 0x0),
97 DEFINE_RES_IRQ_NAMED(MX28_LRADC_TS_IRQ
, "mxs-lradc-touchscreen"),
98 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH6_IRQ
, "mxs-lradc-channel6"),
99 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH7_IRQ
, "mxs-lradc-channel7"),
102 static struct mfd_cell mx23_cells
[] = {
104 .name
= "mxs-lradc-adc",
105 .resources
= mx23_adc_resources
,
106 .num_resources
= ARRAY_SIZE(mx23_adc_resources
),
109 .name
= "mxs-lradc-ts",
110 .resources
= mx23_touchscreen_resources
,
111 .num_resources
= ARRAY_SIZE(mx23_touchscreen_resources
),
115 static struct mfd_cell mx28_cells
[] = {
117 .name
= "mxs-lradc-adc",
118 .resources
= mx28_adc_resources
,
119 .num_resources
= ARRAY_SIZE(mx28_adc_resources
),
122 .name
= "mxs-lradc-ts",
123 .resources
= mx28_touchscreen_resources
,
124 .num_resources
= ARRAY_SIZE(mx28_touchscreen_resources
),
128 static const struct of_device_id mxs_lradc_dt_ids
[] = {
129 { .compatible
= "fsl,imx23-lradc", .data
= (void *)IMX23_LRADC
, },
130 { .compatible
= "fsl,imx28-lradc", .data
= (void *)IMX28_LRADC
, },
133 MODULE_DEVICE_TABLE(of
, mxs_lradc_dt_ids
);
135 static int mxs_lradc_probe(struct platform_device
*pdev
)
137 const struct of_device_id
*of_id
;
138 struct device
*dev
= &pdev
->dev
;
139 struct device_node
*node
= dev
->of_node
;
140 struct mxs_lradc
*lradc
;
141 struct mfd_cell
*cells
= NULL
;
142 struct resource
*res
;
146 lradc
= devm_kzalloc(&pdev
->dev
, sizeof(*lradc
), GFP_KERNEL
);
150 of_id
= of_match_device(mxs_lradc_dt_ids
, &pdev
->dev
);
154 lradc
->soc
= (enum mxs_lradc_id
)of_id
->data
;
156 lradc
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
157 if (IS_ERR(lradc
->clk
)) {
158 dev_err(dev
, "Failed to get the delay unit clock\n");
159 return PTR_ERR(lradc
->clk
);
162 ret
= clk_prepare_enable(lradc
->clk
);
164 dev_err(dev
, "Failed to enable the delay unit clock\n");
168 ret
= of_property_read_u32(node
, "fsl,lradc-touchscreen-wires",
172 lradc
->buffer_vchans
= BUFFER_VCHANS_LIMITED
;
176 lradc
->touchscreen_wire
= MXS_LRADC_TOUCHSCREEN_4WIRE
;
179 if (lradc
->soc
== IMX28_LRADC
) {
180 lradc
->touchscreen_wire
=
181 MXS_LRADC_TOUCHSCREEN_5WIRE
;
184 /* fall through to an error message for i.MX23 */
187 "Unsupported number of touchscreen wires (%d)\n"
193 lradc
->buffer_vchans
= BUFFER_VCHANS_ALL
;
196 platform_set_drvdata(pdev
, lradc
);
198 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
204 switch (lradc
->soc
) {
206 mx23_adc_resources
[RES_MEM
] = *res
;
207 mx23_touchscreen_resources
[RES_MEM
] = *res
;
211 mx28_adc_resources
[RES_MEM
] = *res
;
212 mx28_touchscreen_resources
[RES_MEM
] = *res
;
216 dev_err(dev
, "Unsupported SoC\n");
221 ret
= devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
222 &cells
[ADC_CELL
], 1, NULL
, 0, NULL
);
224 dev_err(&pdev
->dev
, "Failed to add the ADC subdevice\n");
228 if (!lradc
->touchscreen_wire
)
231 ret
= devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
232 &cells
[TSC_CELL
], 1, NULL
, 0, NULL
);
235 "Failed to add the touchscreen subdevice\n");
242 clk_disable_unprepare(lradc
->clk
);
247 static int mxs_lradc_remove(struct platform_device
*pdev
)
249 struct mxs_lradc
*lradc
= platform_get_drvdata(pdev
);
251 clk_disable_unprepare(lradc
->clk
);
256 static struct platform_driver mxs_lradc_driver
= {
259 .of_match_table
= mxs_lradc_dt_ids
,
261 .probe
= mxs_lradc_probe
,
262 .remove
= mxs_lradc_remove
,
264 module_platform_driver(mxs_lradc_driver
);
266 MODULE_AUTHOR("Ksenija Stanojevic <ksenija.stanojevic@gmail.com>");
267 MODULE_DESCRIPTION("Freescale i.MX23/i.MX28 LRADC driver");
268 MODULE_LICENSE("GPL");
269 MODULE_ALIAS("platform:mxs-lradc");