22 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/slab.h>
34 #define JZ_REG_ADC_ENABLE 0x00
35 #define JZ_REG_ADC_CFG 0x04
36 #define JZ_REG_ADC_CTRL 0x08
37 #define JZ_REG_ADC_STATUS 0x0c
39 #define JZ_REG_ADC_TOUCHSCREEN_BASE 0x10
40 #define JZ_REG_ADC_BATTERY_BASE 0x1c
41 #define JZ_REG_ADC_HWMON_BASE 0x20
43 #define JZ_ADC_ENABLE_TOUCH BIT(2)
44 #define JZ_ADC_ENABLE_BATTERY BIT(1)
45 #define JZ_ADC_ENABLE_ADCIN BIT(0)
60 struct irq_chip_generic *
gc;
68 static void jz4740_adc_irq_demux(
unsigned int irq,
struct irq_desc *
desc)
70 struct irq_chip_generic *
gc = irq_desc_get_handler_data(desc);
76 for (i = 0; i < 5; ++
i) {
86 static inline void jz4740_adc_clk_enable(
struct jz4740_adc *
adc)
92 static inline void jz4740_adc_clk_disable(
struct jz4740_adc *adc)
98 static inline void jz4740_adc_set_enabled(
struct jz4740_adc *adc,
int engine,
113 spin_unlock_irqrestore(&adc->
lock, flags);
120 jz4740_adc_clk_enable(adc);
121 jz4740_adc_set_enabled(adc, pdev->
id,
true);
130 jz4740_adc_set_enabled(adc, pdev->
id,
false);
131 jz4740_adc_clk_disable(adc);
154 spin_unlock_irqrestore(&adc->
lock, flags);
160 static struct resource jz4740_hwmon_resources[] = {
172 static struct resource jz4740_battery_resources[] = {
184 static struct mfd_cell jz4740_adc_cells[] = {
187 .name =
"jz4740-hwmon",
188 .num_resources =
ARRAY_SIZE(jz4740_hwmon_resources),
189 .resources = jz4740_hwmon_resources,
191 .enable = jz4740_adc_cell_enable,
192 .disable = jz4740_adc_cell_disable,
196 .name =
"jz4740-battery",
197 .num_resources =
ARRAY_SIZE(jz4740_battery_resources),
198 .resources = jz4740_battery_resources,
200 .enable = jz4740_adc_cell_enable,
201 .disable = jz4740_adc_cell_disable,
207 struct irq_chip_generic *
gc;
208 struct irq_chip_type *
ct;
216 dev_err(&pdev->
dev,
"Failed to allocate driver structure\n");
223 dev_err(&pdev->
dev,
"Failed to get platform irq: %d\n", ret);
230 dev_err(&pdev->
dev,
"Failed to get irq base: %d\n", ret);
237 dev_err(&pdev->
dev,
"Failed to get platform mmio resource\n");
246 dev_err(&pdev->
dev,
"Failed to request mmio memory region\n");
253 dev_err(&pdev->
dev,
"Failed to ioremap mmio memory\n");
254 goto err_release_mem_region;
258 if (IS_ERR(adc->
clk)) {
259 ret = PTR_ERR(adc->
clk);
260 dev_err(&pdev->
dev,
"Failed to get clock: %d\n", ret);
267 platform_set_drvdata(pdev, adc);
284 irq_set_chained_handler(adc->
irq, jz4740_adc_irq_demux);
300 platform_set_drvdata(pdev,
NULL);
302 err_release_mem_region:
312 struct jz4740_adc *adc = platform_get_drvdata(pdev);
319 irq_set_chained_handler(adc->
irq,
NULL);
326 platform_set_drvdata(pdev,
NULL);
334 .probe = jz4740_adc_probe,
337 .name =
"jz4740-adc",