hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/iio/adc/twl6030-gpadc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * TWL6030 GPADC module driver
34 *
....@@ -12,21 +13,6 @@
1213 * Based on twl4030-madc.c
1314 * Copyright (C) 2008 Nokia Corporation
1415 * Mikko Ylinen <mikko.k.ylinen@nokia.com>
15
- *
16
- * This program is free software; you can redistribute it and/or
17
- * modify it under the terms of the GNU General Public License
18
- * version 2 as published by the Free Software Foundation.
19
- *
20
- * This program is distributed in the hope that it will be useful, but
21
- * WITHOUT ANY WARRANTY; without even the implied warranty of
22
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
- * General Public License for more details.
24
- *
25
- * You should have received a copy of the GNU General Public License
26
- * along with this program; if not, write to the Free Software
27
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28
- * 02110-1301 USA
29
- *
3016 */
3117 #include <linux/interrupt.h>
3218 #include <linux/kernel.h>
....@@ -71,6 +57,18 @@
7157 #define TWL6030_GPADCS BIT(1)
7258 #define TWL6030_GPADCR BIT(0)
7359
60
+#define USB_VBUS_CTRL_SET 0x04
61
+#define USB_ID_CTRL_SET 0x06
62
+
63
+#define TWL6030_MISC1 0xE4
64
+#define VBUS_MEAS 0x01
65
+#define ID_MEAS 0x01
66
+
67
+#define VAC_MEAS 0x04
68
+#define VBAT_MEAS 0x02
69
+#define BB_MEAS 0x01
70
+
71
+
7472 /**
7573 * struct twl6030_chnl_calib - channel calibration
7674 * @gain: slope coefficient for ideal curve
....@@ -108,9 +106,9 @@
108106 * struct twl6030_gpadc_platform_data - platform specific data
109107 * @nchannels: number of GPADC channels
110108 * @iio_channels: iio channels
111
- * @twl6030_ideal: pointer to calibration parameters
109
+ * @ideal: pointer to calibration parameters
112110 * @start_conversion: pointer to ADC start conversion function
113
- * @channel_to_reg pointer to ADC function to convert channel to
111
+ * @channel_to_reg: pointer to ADC function to convert channel to
114112 * register address for reading conversion result
115113 * @calibrate: pointer to calibration function
116114 */
....@@ -919,14 +917,14 @@
919917 }
920918
921919 irq = platform_get_irq(pdev, 0);
922
- if (irq < 0) {
923
- dev_err(&pdev->dev, "failed to get irq\n");
920
+ if (irq < 0)
924921 return irq;
925
- }
926922
927923 ret = devm_request_threaded_irq(dev, irq, NULL,
928924 twl6030_gpadc_irq_handler,
929925 IRQF_ONESHOT, "twl6030_gpadc", indio_dev);
926
+ if (ret)
927
+ return ret;
930928
931929 ret = twl6030_gpadc_enable_irq(TWL6030_GPADC_RT_SW1_EOC_MASK);
932930 if (ret < 0) {
....@@ -941,8 +939,27 @@
941939 return ret;
942940 }
943941
942
+ ret = twl_i2c_write_u8(TWL_MODULE_USB, VBUS_MEAS, USB_VBUS_CTRL_SET);
943
+ if (ret < 0) {
944
+ dev_err(dev, "failed to wire up inputs\n");
945
+ return ret;
946
+ }
947
+
948
+ ret = twl_i2c_write_u8(TWL_MODULE_USB, ID_MEAS, USB_ID_CTRL_SET);
949
+ if (ret < 0) {
950
+ dev_err(dev, "failed to wire up inputs\n");
951
+ return ret;
952
+ }
953
+
954
+ ret = twl_i2c_write_u8(TWL6030_MODULE_ID0,
955
+ VBAT_MEAS | BB_MEAS | VAC_MEAS,
956
+ TWL6030_MISC1);
957
+ if (ret < 0) {
958
+ dev_err(dev, "failed to wire up inputs\n");
959
+ return ret;
960
+ }
961
+
944962 indio_dev->name = DRIVER_NAME;
945
- indio_dev->dev.parent = dev;
946963 indio_dev->info = &twl6030_gpadc_iio_info;
947964 indio_dev->modes = INDIO_DIRECT_MODE;
948965 indio_dev->channels = pdata->iio_channels;