forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/adc/at91_adc.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for the ADC present in the Atmel AT91 evaluation boards.
34 *
45 * Copyright 2011 Free Electrons
5
- *
6
- * Licensed under the GPLv2 or later.
76 */
87
98 #include <linux/bitmap.h>
....@@ -158,7 +157,7 @@
158157 * struct at91_adc_reg_desc - Various informations relative to registers
159158 * @channel_base: Base offset for the channel data registers
160159 * @drdy_mask: Mask of the DRDY field in the relevant registers
161
- (Interruptions registers mostly)
160
+ * (Interruptions registers mostly)
162161 * @status_register: Offset of the Interrupt Status Register
163162 * @trigger_register: Offset of the Trigger setup register
164163 * @mr_prescal_mask: Mask of the PRESCAL field in the adc MR register
....@@ -288,13 +287,13 @@
288287 }
289288 }
290289
291
-static int at91_ts_sample(struct at91_adc_state *st)
290
+static int at91_ts_sample(struct iio_dev *idev)
292291 {
292
+ struct at91_adc_state *st = iio_priv(idev);
293293 unsigned int xscale, yscale, reg, z1, z2;
294294 unsigned int x, y, pres, xpos, ypos;
295295 unsigned int rxp = 1;
296296 unsigned int factor = 1000;
297
- struct iio_dev *idev = iio_priv_to_dev(st);
298297
299298 unsigned int xyz_mask_bits = st->res;
300299 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1;
....@@ -450,7 +449,7 @@
450449
451450 if (status & AT91_ADC_ISR_PENS) {
452451 /* validate data by pen contact */
453
- at91_ts_sample(st);
452
+ at91_ts_sample(idev);
454453 } else {
455454 /* triggered by event that is no pen contact, just read
456455 * them to clean the interrupt and discard all.
....@@ -617,8 +616,10 @@
617616 trig->ops = &at91_adc_trigger_ops;
618617
619618 ret = iio_trigger_register(trig);
620
- if (ret)
619
+ if (ret) {
620
+ iio_trigger_free(trig);
621621 return NULL;
622
+ }
622623
623624 return trig;
624625 }
....@@ -738,10 +739,10 @@
738739 return -EINVAL;
739740 }
740741
741
-static int at91_adc_of_get_resolution(struct at91_adc_state *st,
742
+static int at91_adc_of_get_resolution(struct iio_dev *idev,
742743 struct platform_device *pdev)
743744 {
744
- struct iio_dev *idev = iio_priv_to_dev(st);
745
+ struct at91_adc_state *st = iio_priv(idev);
745746 struct device_node *np = pdev->dev.of_node;
746747 int count, i, ret = 0;
747748 char *res_name, *s;
....@@ -867,10 +868,10 @@
867868 }
868869 }
869870
870
-static int at91_adc_probe_dt(struct at91_adc_state *st,
871
+static int at91_adc_probe_dt(struct iio_dev *idev,
871872 struct platform_device *pdev)
872873 {
873
- struct iio_dev *idev = iio_priv_to_dev(st);
874
+ struct at91_adc_state *st = iio_priv(idev);
874875 struct device_node *node = pdev->dev.of_node;
875876 struct device_node *trig_node;
876877 int i = 0, ret;
....@@ -911,7 +912,7 @@
911912 }
912913 st->vref_mv = prop;
913914
914
- ret = at91_adc_of_get_resolution(st, pdev);
915
+ ret = at91_adc_of_get_resolution(idev, pdev);
915916 if (ret)
916917 goto error_ret;
917918
....@@ -1011,9 +1012,9 @@
10111012 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN);
10121013 }
10131014
1014
-static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz)
1015
+static int at91_ts_hw_init(struct iio_dev *idev, u32 adc_clk_khz)
10151016 {
1016
- struct iio_dev *idev = iio_priv_to_dev(st);
1017
+ struct at91_adc_state *st = iio_priv(idev);
10171018 u32 reg = 0;
10181019 u32 tssctim = 0;
10191020 int i = 0;
....@@ -1086,11 +1087,11 @@
10861087 return 0;
10871088 }
10881089
1089
-static int at91_ts_register(struct at91_adc_state *st,
1090
+static int at91_ts_register(struct iio_dev *idev,
10901091 struct platform_device *pdev)
10911092 {
1093
+ struct at91_adc_state *st = iio_priv(idev);
10921094 struct input_dev *input;
1093
- struct iio_dev *idev = iio_priv_to_dev(st);
10941095 int ret;
10951096
10961097 input = input_allocate_device();
....@@ -1153,7 +1154,6 @@
11531154 int ret;
11541155 struct iio_dev *idev;
11551156 struct at91_adc_state *st;
1156
- struct resource *res;
11571157 u32 reg;
11581158
11591159 idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state));
....@@ -1163,7 +1163,7 @@
11631163 st = iio_priv(idev);
11641164
11651165 if (pdev->dev.of_node)
1166
- ret = at91_adc_probe_dt(st, pdev);
1166
+ ret = at91_adc_probe_dt(idev, pdev);
11671167 else
11681168 ret = at91_adc_probe_pdata(st, pdev);
11691169
....@@ -1174,20 +1174,15 @@
11741174
11751175 platform_set_drvdata(pdev, idev);
11761176
1177
- idev->dev.parent = &pdev->dev;
11781177 idev->name = dev_name(&pdev->dev);
11791178 idev->modes = INDIO_DIRECT_MODE;
11801179 idev->info = &at91_adc_info;
11811180
11821181 st->irq = platform_get_irq(pdev, 0);
1183
- if (st->irq < 0) {
1184
- dev_err(&pdev->dev, "No IRQ ID is designated\n");
1182
+ if (st->irq < 0)
11851183 return -ENODEV;
1186
- }
11871184
1188
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1189
-
1190
- st->reg_base = devm_ioremap_resource(&pdev->dev, res);
1185
+ st->reg_base = devm_platform_ioremap_resource(pdev, 0);
11911186 if (IS_ERR(st->reg_base))
11921187 return PTR_ERR(st->reg_base);
11931188
....@@ -1307,11 +1302,11 @@
13071302 goto error_disable_adc_clk;
13081303 }
13091304 } else {
1310
- ret = at91_ts_register(st, pdev);
1305
+ ret = at91_ts_register(idev, pdev);
13111306 if (ret)
13121307 goto error_disable_adc_clk;
13131308
1314
- at91_ts_hw_init(st, adc_clk_khz);
1309
+ at91_ts_hw_init(idev, adc_clk_khz);
13151310 }
13161311
13171312 ret = iio_device_register(idev);
....@@ -1360,7 +1355,7 @@
13601355 #ifdef CONFIG_PM_SLEEP
13611356 static int at91_adc_suspend(struct device *dev)
13621357 {
1363
- struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev));
1358
+ struct iio_dev *idev = dev_get_drvdata(dev);
13641359 struct at91_adc_state *st = iio_priv(idev);
13651360
13661361 pinctrl_pm_select_sleep_state(dev);
....@@ -1371,7 +1366,7 @@
13711366
13721367 static int at91_adc_resume(struct device *dev)
13731368 {
1374
- struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev));
1369
+ struct iio_dev *idev = dev_get_drvdata(dev);
13751370 struct at91_adc_state *st = iio_priv(idev);
13761371
13771372 clk_prepare_enable(st->clk);
....@@ -1476,7 +1471,7 @@
14761471 .id_table = at91_adc_ids,
14771472 .driver = {
14781473 .name = DRIVER_NAME,
1479
- .of_match_table = of_match_ptr(at91_adc_dt_ids),
1474
+ .of_match_table = at91_adc_dt_ids,
14801475 .pm = &at91_adc_pm_ops,
14811476 },
14821477 };