1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Freescale MXS Low Resolution Analog-to-Digital Converter driver
5 * Copyright (c) 2012 DENX Software Engineering, GmbH.
6 * Copyright (c) 2017 Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
9 * Marek Vasut <marex@denx.de>
10 * Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
13 #include <linux/clk.h>
14 #include <linux/device.h>
15 #include <linux/mfd/core.h>
16 #include <linux/mfd/mxs-lradc.h>
17 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/property.h>
21 #include <linux/slab.h>
27 enum mx23_lradc_irqs
{
28 MX23_LRADC_TS_IRQ
= 0,
39 enum mx28_lradc_irqs
{
40 MX28_LRADC_TS_IRQ
= 0,
41 MX28_LRADC_TRESH0_IRQ
,
42 MX28_LRADC_TRESH1_IRQ
,
51 MX28_LRADC_BUTTON0_IRQ
,
52 MX28_LRADC_BUTTON1_IRQ
,
55 static struct resource mx23_adc_resources
[] = {
56 DEFINE_RES_MEM(0x0, 0x0),
57 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH0_IRQ
, "mxs-lradc-channel0"),
58 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH1_IRQ
, "mxs-lradc-channel1"),
59 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH2_IRQ
, "mxs-lradc-channel2"),
60 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH3_IRQ
, "mxs-lradc-channel3"),
61 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH4_IRQ
, "mxs-lradc-channel4"),
62 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH5_IRQ
, "mxs-lradc-channel5"),
65 static struct resource mx23_touchscreen_resources
[] = {
66 DEFINE_RES_MEM(0x0, 0x0),
67 DEFINE_RES_IRQ_NAMED(MX23_LRADC_TS_IRQ
, "mxs-lradc-touchscreen"),
68 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH6_IRQ
, "mxs-lradc-channel6"),
69 DEFINE_RES_IRQ_NAMED(MX23_LRADC_CH7_IRQ
, "mxs-lradc-channel7"),
72 static struct resource mx28_adc_resources
[] = {
73 DEFINE_RES_MEM(0x0, 0x0),
74 DEFINE_RES_IRQ_NAMED(MX28_LRADC_TRESH0_IRQ
, "mxs-lradc-thresh0"),
75 DEFINE_RES_IRQ_NAMED(MX28_LRADC_TRESH1_IRQ
, "mxs-lradc-thresh1"),
76 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH0_IRQ
, "mxs-lradc-channel0"),
77 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH1_IRQ
, "mxs-lradc-channel1"),
78 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH2_IRQ
, "mxs-lradc-channel2"),
79 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH3_IRQ
, "mxs-lradc-channel3"),
80 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH4_IRQ
, "mxs-lradc-channel4"),
81 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH5_IRQ
, "mxs-lradc-channel5"),
82 DEFINE_RES_IRQ_NAMED(MX28_LRADC_BUTTON0_IRQ
, "mxs-lradc-button0"),
83 DEFINE_RES_IRQ_NAMED(MX28_LRADC_BUTTON1_IRQ
, "mxs-lradc-button1"),
86 static struct resource mx28_touchscreen_resources
[] = {
87 DEFINE_RES_MEM(0x0, 0x0),
88 DEFINE_RES_IRQ_NAMED(MX28_LRADC_TS_IRQ
, "mxs-lradc-touchscreen"),
89 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH6_IRQ
, "mxs-lradc-channel6"),
90 DEFINE_RES_IRQ_NAMED(MX28_LRADC_CH7_IRQ
, "mxs-lradc-channel7"),
93 static struct mfd_cell mx23_cells
[] = {
95 .name
= "mxs-lradc-adc",
96 .resources
= mx23_adc_resources
,
97 .num_resources
= ARRAY_SIZE(mx23_adc_resources
),
100 .name
= "mxs-lradc-ts",
101 .resources
= mx23_touchscreen_resources
,
102 .num_resources
= ARRAY_SIZE(mx23_touchscreen_resources
),
106 static struct mfd_cell mx28_cells
[] = {
108 .name
= "mxs-lradc-adc",
109 .resources
= mx28_adc_resources
,
110 .num_resources
= ARRAY_SIZE(mx28_adc_resources
),
113 .name
= "mxs-lradc-ts",
114 .resources
= mx28_touchscreen_resources
,
115 .num_resources
= ARRAY_SIZE(mx28_touchscreen_resources
),
119 static const struct of_device_id mxs_lradc_dt_ids
[] = {
120 { .compatible
= "fsl,imx23-lradc", .data
= (void *)IMX23_LRADC
, },
121 { .compatible
= "fsl,imx28-lradc", .data
= (void *)IMX28_LRADC
, },
124 MODULE_DEVICE_TABLE(of
, mxs_lradc_dt_ids
);
126 static int mxs_lradc_probe(struct platform_device
*pdev
)
128 struct device
*dev
= &pdev
->dev
;
129 struct device_node
*node
= dev
->of_node
;
130 struct mxs_lradc
*lradc
;
131 struct mfd_cell
*cells
= NULL
;
132 struct resource
*res
;
136 lradc
= devm_kzalloc(&pdev
->dev
, sizeof(*lradc
), GFP_KERNEL
);
140 lradc
->soc
= (kernel_ulong_t
)device_get_match_data(&pdev
->dev
);
142 lradc
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
143 if (IS_ERR(lradc
->clk
)) {
144 dev_err(dev
, "Failed to get the delay unit clock\n");
145 return PTR_ERR(lradc
->clk
);
148 ret
= clk_prepare_enable(lradc
->clk
);
150 dev_err(dev
, "Failed to enable the delay unit clock\n");
154 ret
= of_property_read_u32(node
, "fsl,lradc-touchscreen-wires",
158 lradc
->buffer_vchans
= BUFFER_VCHANS_LIMITED
;
162 lradc
->touchscreen_wire
= MXS_LRADC_TOUCHSCREEN_4WIRE
;
165 if (lradc
->soc
== IMX28_LRADC
) {
166 lradc
->touchscreen_wire
=
167 MXS_LRADC_TOUCHSCREEN_5WIRE
;
170 fallthrough
; /* to an error message for i.MX23 */
173 "Unsupported number of touchscreen wires (%d)\n"
179 lradc
->buffer_vchans
= BUFFER_VCHANS_ALL
;
182 platform_set_drvdata(pdev
, lradc
);
184 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
190 switch (lradc
->soc
) {
192 mx23_adc_resources
[RES_MEM
] = *res
;
193 mx23_touchscreen_resources
[RES_MEM
] = *res
;
197 mx28_adc_resources
[RES_MEM
] = *res
;
198 mx28_touchscreen_resources
[RES_MEM
] = *res
;
202 dev_err(dev
, "Unsupported SoC\n");
207 ret
= devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
208 &cells
[ADC_CELL
], 1, NULL
, 0, NULL
);
210 dev_err(&pdev
->dev
, "Failed to add the ADC subdevice\n");
214 if (!lradc
->touchscreen_wire
)
217 ret
= devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
218 &cells
[TSC_CELL
], 1, NULL
, 0, NULL
);
221 "Failed to add the touchscreen subdevice\n");
228 clk_disable_unprepare(lradc
->clk
);
233 static void mxs_lradc_remove(struct platform_device
*pdev
)
235 struct mxs_lradc
*lradc
= platform_get_drvdata(pdev
);
237 clk_disable_unprepare(lradc
->clk
);
240 static struct platform_driver mxs_lradc_driver
= {
243 .of_match_table
= mxs_lradc_dt_ids
,
245 .probe
= mxs_lradc_probe
,
246 .remove
= mxs_lradc_remove
,
248 module_platform_driver(mxs_lradc_driver
);
250 MODULE_AUTHOR("Ksenija Stanojevic <ksenija.stanojevic@gmail.com>");
251 MODULE_DESCRIPTION("Freescale i.MX23/i.MX28 LRADC driver");
252 MODULE_LICENSE("GPL");
253 MODULE_ALIAS("platform:mxs-lradc");