.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for the ADC present in the Atmel AT91 evaluation boards. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2011 Free Electrons |
---|
5 | | - * |
---|
6 | | - * Licensed under the GPLv2 or later. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | #include <linux/bitmap.h> |
---|
.. | .. |
---|
158 | 157 | * struct at91_adc_reg_desc - Various informations relative to registers |
---|
159 | 158 | * @channel_base: Base offset for the channel data registers |
---|
160 | 159 | * @drdy_mask: Mask of the DRDY field in the relevant registers |
---|
161 | | - (Interruptions registers mostly) |
---|
| 160 | + * (Interruptions registers mostly) |
---|
162 | 161 | * @status_register: Offset of the Interrupt Status Register |
---|
163 | 162 | * @trigger_register: Offset of the Trigger setup register |
---|
164 | 163 | * @mr_prescal_mask: Mask of the PRESCAL field in the adc MR register |
---|
.. | .. |
---|
288 | 287 | } |
---|
289 | 288 | } |
---|
290 | 289 | |
---|
291 | | -static int at91_ts_sample(struct at91_adc_state *st) |
---|
| 290 | +static int at91_ts_sample(struct iio_dev *idev) |
---|
292 | 291 | { |
---|
| 292 | + struct at91_adc_state *st = iio_priv(idev); |
---|
293 | 293 | unsigned int xscale, yscale, reg, z1, z2; |
---|
294 | 294 | unsigned int x, y, pres, xpos, ypos; |
---|
295 | 295 | unsigned int rxp = 1; |
---|
296 | 296 | unsigned int factor = 1000; |
---|
297 | | - struct iio_dev *idev = iio_priv_to_dev(st); |
---|
298 | 297 | |
---|
299 | 298 | unsigned int xyz_mask_bits = st->res; |
---|
300 | 299 | unsigned int xyz_mask = (1 << xyz_mask_bits) - 1; |
---|
.. | .. |
---|
450 | 449 | |
---|
451 | 450 | if (status & AT91_ADC_ISR_PENS) { |
---|
452 | 451 | /* validate data by pen contact */ |
---|
453 | | - at91_ts_sample(st); |
---|
| 452 | + at91_ts_sample(idev); |
---|
454 | 453 | } else { |
---|
455 | 454 | /* triggered by event that is no pen contact, just read |
---|
456 | 455 | * them to clean the interrupt and discard all. |
---|
.. | .. |
---|
617 | 616 | trig->ops = &at91_adc_trigger_ops; |
---|
618 | 617 | |
---|
619 | 618 | ret = iio_trigger_register(trig); |
---|
620 | | - if (ret) |
---|
| 619 | + if (ret) { |
---|
| 620 | + iio_trigger_free(trig); |
---|
621 | 621 | return NULL; |
---|
| 622 | + } |
---|
622 | 623 | |
---|
623 | 624 | return trig; |
---|
624 | 625 | } |
---|
.. | .. |
---|
738 | 739 | return -EINVAL; |
---|
739 | 740 | } |
---|
740 | 741 | |
---|
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, |
---|
742 | 743 | struct platform_device *pdev) |
---|
743 | 744 | { |
---|
744 | | - struct iio_dev *idev = iio_priv_to_dev(st); |
---|
| 745 | + struct at91_adc_state *st = iio_priv(idev); |
---|
745 | 746 | struct device_node *np = pdev->dev.of_node; |
---|
746 | 747 | int count, i, ret = 0; |
---|
747 | 748 | char *res_name, *s; |
---|
.. | .. |
---|
867 | 868 | } |
---|
868 | 869 | } |
---|
869 | 870 | |
---|
870 | | -static int at91_adc_probe_dt(struct at91_adc_state *st, |
---|
| 871 | +static int at91_adc_probe_dt(struct iio_dev *idev, |
---|
871 | 872 | struct platform_device *pdev) |
---|
872 | 873 | { |
---|
873 | | - struct iio_dev *idev = iio_priv_to_dev(st); |
---|
| 874 | + struct at91_adc_state *st = iio_priv(idev); |
---|
874 | 875 | struct device_node *node = pdev->dev.of_node; |
---|
875 | 876 | struct device_node *trig_node; |
---|
876 | 877 | int i = 0, ret; |
---|
.. | .. |
---|
911 | 912 | } |
---|
912 | 913 | st->vref_mv = prop; |
---|
913 | 914 | |
---|
914 | | - ret = at91_adc_of_get_resolution(st, pdev); |
---|
| 915 | + ret = at91_adc_of_get_resolution(idev, pdev); |
---|
915 | 916 | if (ret) |
---|
916 | 917 | goto error_ret; |
---|
917 | 918 | |
---|
.. | .. |
---|
1011 | 1012 | at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN); |
---|
1012 | 1013 | } |
---|
1013 | 1014 | |
---|
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) |
---|
1015 | 1016 | { |
---|
1016 | | - struct iio_dev *idev = iio_priv_to_dev(st); |
---|
| 1017 | + struct at91_adc_state *st = iio_priv(idev); |
---|
1017 | 1018 | u32 reg = 0; |
---|
1018 | 1019 | u32 tssctim = 0; |
---|
1019 | 1020 | int i = 0; |
---|
.. | .. |
---|
1086 | 1087 | return 0; |
---|
1087 | 1088 | } |
---|
1088 | 1089 | |
---|
1089 | | -static int at91_ts_register(struct at91_adc_state *st, |
---|
| 1090 | +static int at91_ts_register(struct iio_dev *idev, |
---|
1090 | 1091 | struct platform_device *pdev) |
---|
1091 | 1092 | { |
---|
| 1093 | + struct at91_adc_state *st = iio_priv(idev); |
---|
1092 | 1094 | struct input_dev *input; |
---|
1093 | | - struct iio_dev *idev = iio_priv_to_dev(st); |
---|
1094 | 1095 | int ret; |
---|
1095 | 1096 | |
---|
1096 | 1097 | input = input_allocate_device(); |
---|
.. | .. |
---|
1153 | 1154 | int ret; |
---|
1154 | 1155 | struct iio_dev *idev; |
---|
1155 | 1156 | struct at91_adc_state *st; |
---|
1156 | | - struct resource *res; |
---|
1157 | 1157 | u32 reg; |
---|
1158 | 1158 | |
---|
1159 | 1159 | idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state)); |
---|
.. | .. |
---|
1163 | 1163 | st = iio_priv(idev); |
---|
1164 | 1164 | |
---|
1165 | 1165 | if (pdev->dev.of_node) |
---|
1166 | | - ret = at91_adc_probe_dt(st, pdev); |
---|
| 1166 | + ret = at91_adc_probe_dt(idev, pdev); |
---|
1167 | 1167 | else |
---|
1168 | 1168 | ret = at91_adc_probe_pdata(st, pdev); |
---|
1169 | 1169 | |
---|
.. | .. |
---|
1174 | 1174 | |
---|
1175 | 1175 | platform_set_drvdata(pdev, idev); |
---|
1176 | 1176 | |
---|
1177 | | - idev->dev.parent = &pdev->dev; |
---|
1178 | 1177 | idev->name = dev_name(&pdev->dev); |
---|
1179 | 1178 | idev->modes = INDIO_DIRECT_MODE; |
---|
1180 | 1179 | idev->info = &at91_adc_info; |
---|
1181 | 1180 | |
---|
1182 | 1181 | 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) |
---|
1185 | 1183 | return -ENODEV; |
---|
1186 | | - } |
---|
1187 | 1184 | |
---|
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); |
---|
1191 | 1186 | if (IS_ERR(st->reg_base)) |
---|
1192 | 1187 | return PTR_ERR(st->reg_base); |
---|
1193 | 1188 | |
---|
.. | .. |
---|
1307 | 1302 | goto error_disable_adc_clk; |
---|
1308 | 1303 | } |
---|
1309 | 1304 | } else { |
---|
1310 | | - ret = at91_ts_register(st, pdev); |
---|
| 1305 | + ret = at91_ts_register(idev, pdev); |
---|
1311 | 1306 | if (ret) |
---|
1312 | 1307 | goto error_disable_adc_clk; |
---|
1313 | 1308 | |
---|
1314 | | - at91_ts_hw_init(st, adc_clk_khz); |
---|
| 1309 | + at91_ts_hw_init(idev, adc_clk_khz); |
---|
1315 | 1310 | } |
---|
1316 | 1311 | |
---|
1317 | 1312 | ret = iio_device_register(idev); |
---|
.. | .. |
---|
1360 | 1355 | #ifdef CONFIG_PM_SLEEP |
---|
1361 | 1356 | static int at91_adc_suspend(struct device *dev) |
---|
1362 | 1357 | { |
---|
1363 | | - struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev)); |
---|
| 1358 | + struct iio_dev *idev = dev_get_drvdata(dev); |
---|
1364 | 1359 | struct at91_adc_state *st = iio_priv(idev); |
---|
1365 | 1360 | |
---|
1366 | 1361 | pinctrl_pm_select_sleep_state(dev); |
---|
.. | .. |
---|
1371 | 1366 | |
---|
1372 | 1367 | static int at91_adc_resume(struct device *dev) |
---|
1373 | 1368 | { |
---|
1374 | | - struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev)); |
---|
| 1369 | + struct iio_dev *idev = dev_get_drvdata(dev); |
---|
1375 | 1370 | struct at91_adc_state *st = iio_priv(idev); |
---|
1376 | 1371 | |
---|
1377 | 1372 | clk_prepare_enable(st->clk); |
---|
.. | .. |
---|
1476 | 1471 | .id_table = at91_adc_ids, |
---|
1477 | 1472 | .driver = { |
---|
1478 | 1473 | .name = DRIVER_NAME, |
---|
1479 | | - .of_match_table = of_match_ptr(at91_adc_dt_ids), |
---|
| 1474 | + .of_match_table = at91_adc_dt_ids, |
---|
1480 | 1475 | .pm = &at91_adc_pm_ops, |
---|
1481 | 1476 | }, |
---|
1482 | 1477 | }; |
---|