| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * TWL6030 GPADC module driver |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 12 | 13 | * Based on twl4030-madc.c |
|---|
| 13 | 14 | * Copyright (C) 2008 Nokia Corporation |
|---|
| 14 | 15 | * 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 | | - * |
|---|
| 30 | 16 | */ |
|---|
| 31 | 17 | #include <linux/interrupt.h> |
|---|
| 32 | 18 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 71 | 57 | #define TWL6030_GPADCS BIT(1) |
|---|
| 72 | 58 | #define TWL6030_GPADCR BIT(0) |
|---|
| 73 | 59 | |
|---|
| 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 | + |
|---|
| 74 | 72 | /** |
|---|
| 75 | 73 | * struct twl6030_chnl_calib - channel calibration |
|---|
| 76 | 74 | * @gain: slope coefficient for ideal curve |
|---|
| .. | .. |
|---|
| 108 | 106 | * struct twl6030_gpadc_platform_data - platform specific data |
|---|
| 109 | 107 | * @nchannels: number of GPADC channels |
|---|
| 110 | 108 | * @iio_channels: iio channels |
|---|
| 111 | | - * @twl6030_ideal: pointer to calibration parameters |
|---|
| 109 | + * @ideal: pointer to calibration parameters |
|---|
| 112 | 110 | * @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 |
|---|
| 114 | 112 | * register address for reading conversion result |
|---|
| 115 | 113 | * @calibrate: pointer to calibration function |
|---|
| 116 | 114 | */ |
|---|
| .. | .. |
|---|
| 919 | 917 | } |
|---|
| 920 | 918 | |
|---|
| 921 | 919 | irq = platform_get_irq(pdev, 0); |
|---|
| 922 | | - if (irq < 0) { |
|---|
| 923 | | - dev_err(&pdev->dev, "failed to get irq\n"); |
|---|
| 920 | + if (irq < 0) |
|---|
| 924 | 921 | return irq; |
|---|
| 925 | | - } |
|---|
| 926 | 922 | |
|---|
| 927 | 923 | ret = devm_request_threaded_irq(dev, irq, NULL, |
|---|
| 928 | 924 | twl6030_gpadc_irq_handler, |
|---|
| 929 | 925 | IRQF_ONESHOT, "twl6030_gpadc", indio_dev); |
|---|
| 926 | + if (ret) |
|---|
| 927 | + return ret; |
|---|
| 930 | 928 | |
|---|
| 931 | 929 | ret = twl6030_gpadc_enable_irq(TWL6030_GPADC_RT_SW1_EOC_MASK); |
|---|
| 932 | 930 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 941 | 939 | return ret; |
|---|
| 942 | 940 | } |
|---|
| 943 | 941 | |
|---|
| 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 | + |
|---|
| 944 | 962 | indio_dev->name = DRIVER_NAME; |
|---|
| 945 | | - indio_dev->dev.parent = dev; |
|---|
| 946 | 963 | indio_dev->info = &twl6030_gpadc_iio_info; |
|---|
| 947 | 964 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 948 | 965 | indio_dev->channels = pdata->iio_channels; |
|---|