From 8d502ef682fdbe0ddf2274dae903b07baf1140e0 Mon Sep 17 00:00:00 2001 From: Craig Tatlor Date: Fri, 4 Dec 2020 05:54:56 +0300 Subject: fixp-arith: add a linear interpolation function Adds a function to interpolate against two points, this is carried arount as a helper function by tons of drivers. Signed-off-by: Craig Tatlor Signed-off-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20201204025509.1075506-3-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron --- include/linux/fixp-arith.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include') diff --git a/include/linux/fixp-arith.h b/include/linux/fixp-arith.h index 8396013785ef..281cb4f83dbe 100644 --- a/include/linux/fixp-arith.h +++ b/include/linux/fixp-arith.h @@ -141,4 +141,23 @@ static inline s32 fixp_sin32_rad(u32 radians, u32 twopi) #define fixp_cos32_rad(rad, twopi) \ fixp_sin32_rad(rad + twopi / 4, twopi) +/** + * fixp_linear_interpolate() - interpolates a value from two known points + * + * @x0: x value of point 0 + * @y0: y value of point 0 + * @x1: x value of point 1 + * @y1: y value of point 1 + * @x: the linear interpolant + */ +static inline int fixp_linear_interpolate(int x0, int y0, int x1, int y1, int x) +{ + if (y0 == y1 || x == x0) + return y0; + if (x1 == x0 || x == x1) + return y1; + + return y0 + ((y1 - y0) * (x - x0) / (x1 - x0)); +} + #endif -- cgit v1.2.3 From ec82edb258bbf0233306cc45f65d4b6092243ee9 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 4 Dec 2020 05:54:59 +0300 Subject: iio: adc: move qcom-vadc-common.h to include dir qcom-vadc-common module will be used by ADC thermal monitoring driver, so move it to global include dir. Signed-off-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20201204025509.1075506-6-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron --- drivers/iio/adc/qcom-pm8xxx-xoadc.c | 3 +- drivers/iio/adc/qcom-spmi-adc5.c | 2 +- drivers/iio/adc/qcom-spmi-vadc.c | 3 +- drivers/iio/adc/qcom-vadc-common.c | 3 +- drivers/iio/adc/qcom-vadc-common.h | 185 ------------------------------ include/linux/iio/adc/qcom-vadc-common.h | 187 +++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 192 deletions(-) delete mode 100644 drivers/iio/adc/qcom-vadc-common.h create mode 100644 include/linux/iio/adc/qcom-vadc-common.h (limited to 'include') diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c index 7e108da7d255..0610bf254771 100644 --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c @@ -10,6 +10,7 @@ * Author: Linus Walleij */ +#include #include #include #include @@ -21,8 +22,6 @@ #include #include -#include "qcom-vadc-common.h" - /* * Definitions for the "user processor" registers lifted from the v3.4 * Qualcomm tree. Their kernel has two out-of-tree drivers for the ADC: diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index c2da8f068b87..b10a0fcf09dc 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include -#include "qcom-vadc-common.h" #define ADC5_USR_REVISION1 0x0 #define ADC5_USR_STATUS1 0x8 diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c index b0388f8a69f4..05ff948372b3 100644 --- a/drivers/iio/adc/qcom-spmi-vadc.c +++ b/drivers/iio/adc/qcom-spmi-vadc.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -20,8 +21,6 @@ #include -#include "qcom-vadc-common.h" - /* VADC register and bit definitions */ #define VADC_REVISION2 0x1 #define VADC_REVISION2_SUPPORTED_VADC 1 diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index 40d77b3af1bb..ee94774b72e6 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -3,14 +3,13 @@ #include #include #include +#include #include #include #include #include #include -#include "qcom-vadc-common.h" - /* Voltage to temperature */ static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = { {1758, -40}, diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h deleted file mode 100644 index 7e5f6428e311..000000000000 --- a/drivers/iio/adc/qcom-vadc-common.h +++ /dev/null @@ -1,185 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Code shared between the different Qualcomm PMIC voltage ADCs - */ - -#ifndef QCOM_VADC_COMMON_H -#define QCOM_VADC_COMMON_H - -#define VADC_CONV_TIME_MIN_US 2000 -#define VADC_CONV_TIME_MAX_US 2100 - -/* Min ADC code represents 0V */ -#define VADC_MIN_ADC_CODE 0x6000 -/* Max ADC code represents full-scale range of 1.8V */ -#define VADC_MAX_ADC_CODE 0xa800 - -#define VADC_ABSOLUTE_RANGE_UV 625000 -#define VADC_RATIOMETRIC_RANGE 1800 - -#define VADC_DEF_PRESCALING 0 /* 1:1 */ -#define VADC_DEF_DECIMATION 0 /* 512 */ -#define VADC_DEF_HW_SETTLE_TIME 0 /* 0 us */ -#define VADC_DEF_AVG_SAMPLES 0 /* 1 sample */ -#define VADC_DEF_CALIB_TYPE VADC_CALIB_ABSOLUTE - -#define VADC_DECIMATION_MIN 512 -#define VADC_DECIMATION_MAX 4096 -#define ADC5_DEF_VBAT_PRESCALING 1 /* 1:3 */ -#define ADC5_DECIMATION_SHORT 250 -#define ADC5_DECIMATION_MEDIUM 420 -#define ADC5_DECIMATION_LONG 840 -/* Default decimation - 1024 for rev2, 840 for pmic5 */ -#define ADC5_DECIMATION_DEFAULT 2 -#define ADC5_DECIMATION_SAMPLES_MAX 3 - -#define VADC_HW_SETTLE_DELAY_MAX 10000 -#define VADC_HW_SETTLE_SAMPLES_MAX 16 -#define VADC_AVG_SAMPLES_MAX 512 -#define ADC5_AVG_SAMPLES_MAX 16 - -#define PMIC5_CHG_TEMP_SCALE_FACTOR 377500 -#define PMIC5_SMB_TEMP_CONSTANT 419400 -#define PMIC5_SMB_TEMP_SCALE_FACTOR 356 - -#define PMI_CHG_SCALE_1 -138890 -#define PMI_CHG_SCALE_2 391750000000LL - -#define VADC5_MAX_CODE 0x7fff -#define ADC5_FULL_SCALE_CODE 0x70e4 -#define ADC5_USR_DATA_CHECK 0x8000 - -#define R_PU_100K 100000 -#define RATIO_MAX_ADC7 BIT(14) - -#define DIE_TEMP_ADC7_SCALE_1 -60000 -#define DIE_TEMP_ADC7_SCALE_2 20000 -#define DIE_TEMP_ADC7_SCALE_FACTOR 1000 -#define DIE_TEMP_ADC7_MAX 160000 - -/** - * struct vadc_map_pt - Map the graph representation for ADC channel - * @x: Represent the ADC digitized code. - * @y: Represent the physical data which can be temperature, voltage, - * resistance. - */ -struct vadc_map_pt { - s32 x; - s32 y; -}; - -/* - * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. - * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for - * calibration. - */ -enum vadc_calibration { - VADC_CALIB_ABSOLUTE = 0, - VADC_CALIB_RATIOMETRIC -}; - -/** - * struct vadc_linear_graph - Represent ADC characteristics. - * @dy: numerator slope to calculate the gain. - * @dx: denominator slope to calculate the gain. - * @gnd: A/D word of the ground reference used for the channel. - * - * Each ADC device has different offset and gain parameters which are - * computed to calibrate the device. - */ -struct vadc_linear_graph { - s32 dy; - s32 dx; - s32 gnd; -}; - -/** - * struct vadc_prescale_ratio - Represent scaling ratio for ADC input. - * @num: the inverse numerator of the gain applied to the input channel. - * @den: the inverse denominator of the gain applied to the input channel. - */ -struct vadc_prescale_ratio { - u32 num; - u32 den; -}; - -/** - * enum vadc_scale_fn_type - Scaling function to convert ADC code to - * physical scaled units for the channel. - * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV). - * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC. - * Uses a mapping table with 100K pullup. - * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. - * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC. - * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp - * SCALE_HW_CALIB_DEFAULT: Default scaling to convert raw adc code to - * voltage (uV) with hardware applied offset/slope values to adc code. - * SCALE_HW_CALIB_THERM_100K_PULLUP: Returns temperature in millidegC using - * lookup table. The hardware applies offset/slope to adc code. - * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using - * 100k pullup. The hardware applies offset/slope to adc code. - * SCALE_HW_CALIB_THERM_100K_PU_PM7: Returns temperature in millidegC using - * lookup table for PMIC7. The hardware applies offset/slope to adc code. - * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade. - * The hardware applies offset/slope to adc code. - * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade. - * The hardware applies offset/slope to adc code. This is for PMIC7. - * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5 - * charger temperature. - * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5 - * SMB1390 temperature. - */ -enum vadc_scale_fn_type { - SCALE_DEFAULT = 0, - SCALE_THERM_100K_PULLUP, - SCALE_PMIC_THERM, - SCALE_XOTHERM, - SCALE_PMI_CHG_TEMP, - SCALE_HW_CALIB_DEFAULT, - SCALE_HW_CALIB_THERM_100K_PULLUP, - SCALE_HW_CALIB_XOTHERM, - SCALE_HW_CALIB_THERM_100K_PU_PM7, - SCALE_HW_CALIB_PMIC_THERM, - SCALE_HW_CALIB_PMIC_THERM_PM7, - SCALE_HW_CALIB_PM5_CHG_TEMP, - SCALE_HW_CALIB_PM5_SMB_TEMP, - SCALE_HW_CALIB_INVALID, -}; - -struct adc5_data { - const u32 full_scale_code_volt; - const u32 full_scale_code_cur; - const struct adc5_channels *adc_chans; - const struct iio_info *info; - unsigned int *decimation; - unsigned int *hw_settle_1; - unsigned int *hw_settle_2; -}; - -int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, - const struct vadc_linear_graph *calib_graph, - const struct vadc_prescale_ratio *prescale, - bool absolute, - u16 adc_code, int *result_mdec); - -struct qcom_adc5_scale_type { - int (*scale_fn)(const struct vadc_prescale_ratio *prescale, - const struct adc5_data *data, u16 adc_code, int *result); -}; - -int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, - unsigned int prescale_ratio, - const struct adc5_data *data, - u16 adc_code, int *result_mdec); - -int qcom_adc5_prescaling_from_dt(u32 num, u32 den); - -int qcom_adc5_hw_settle_time_from_dt(u32 value, const unsigned int *hw_settle); - -int qcom_adc5_avg_samples_from_dt(u32 value); - -int qcom_adc5_decimation_from_dt(u32 value, const unsigned int *decimation); - -int qcom_vadc_decimation_from_dt(u32 value); - -#endif /* QCOM_VADC_COMMON_H */ diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h new file mode 100644 index 000000000000..03a9119edc71 --- /dev/null +++ b/include/linux/iio/adc/qcom-vadc-common.h @@ -0,0 +1,187 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Code shared between the different Qualcomm PMIC voltage ADCs + */ + +#ifndef QCOM_VADC_COMMON_H +#define QCOM_VADC_COMMON_H + +#include + +#define VADC_CONV_TIME_MIN_US 2000 +#define VADC_CONV_TIME_MAX_US 2100 + +/* Min ADC code represents 0V */ +#define VADC_MIN_ADC_CODE 0x6000 +/* Max ADC code represents full-scale range of 1.8V */ +#define VADC_MAX_ADC_CODE 0xa800 + +#define VADC_ABSOLUTE_RANGE_UV 625000 +#define VADC_RATIOMETRIC_RANGE 1800 + +#define VADC_DEF_PRESCALING 0 /* 1:1 */ +#define VADC_DEF_DECIMATION 0 /* 512 */ +#define VADC_DEF_HW_SETTLE_TIME 0 /* 0 us */ +#define VADC_DEF_AVG_SAMPLES 0 /* 1 sample */ +#define VADC_DEF_CALIB_TYPE VADC_CALIB_ABSOLUTE + +#define VADC_DECIMATION_MIN 512 +#define VADC_DECIMATION_MAX 4096 +#define ADC5_DEF_VBAT_PRESCALING 1 /* 1:3 */ +#define ADC5_DECIMATION_SHORT 250 +#define ADC5_DECIMATION_MEDIUM 420 +#define ADC5_DECIMATION_LONG 840 +/* Default decimation - 1024 for rev2, 840 for pmic5 */ +#define ADC5_DECIMATION_DEFAULT 2 +#define ADC5_DECIMATION_SAMPLES_MAX 3 + +#define VADC_HW_SETTLE_DELAY_MAX 10000 +#define VADC_HW_SETTLE_SAMPLES_MAX 16 +#define VADC_AVG_SAMPLES_MAX 512 +#define ADC5_AVG_SAMPLES_MAX 16 + +#define PMIC5_CHG_TEMP_SCALE_FACTOR 377500 +#define PMIC5_SMB_TEMP_CONSTANT 419400 +#define PMIC5_SMB_TEMP_SCALE_FACTOR 356 + +#define PMI_CHG_SCALE_1 -138890 +#define PMI_CHG_SCALE_2 391750000000LL + +#define VADC5_MAX_CODE 0x7fff +#define ADC5_FULL_SCALE_CODE 0x70e4 +#define ADC5_USR_DATA_CHECK 0x8000 + +#define R_PU_100K 100000 +#define RATIO_MAX_ADC7 BIT(14) + +#define DIE_TEMP_ADC7_SCALE_1 -60000 +#define DIE_TEMP_ADC7_SCALE_2 20000 +#define DIE_TEMP_ADC7_SCALE_FACTOR 1000 +#define DIE_TEMP_ADC7_MAX 160000 + +/** + * struct vadc_map_pt - Map the graph representation for ADC channel + * @x: Represent the ADC digitized code. + * @y: Represent the physical data which can be temperature, voltage, + * resistance. + */ +struct vadc_map_pt { + s32 x; + s32 y; +}; + +/* + * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. + * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for + * calibration. + */ +enum vadc_calibration { + VADC_CALIB_ABSOLUTE = 0, + VADC_CALIB_RATIOMETRIC +}; + +/** + * struct vadc_linear_graph - Represent ADC characteristics. + * @dy: numerator slope to calculate the gain. + * @dx: denominator slope to calculate the gain. + * @gnd: A/D word of the ground reference used for the channel. + * + * Each ADC device has different offset and gain parameters which are + * computed to calibrate the device. + */ +struct vadc_linear_graph { + s32 dy; + s32 dx; + s32 gnd; +}; + +/** + * struct vadc_prescale_ratio - Represent scaling ratio for ADC input. + * @num: the inverse numerator of the gain applied to the input channel. + * @den: the inverse denominator of the gain applied to the input channel. + */ +struct vadc_prescale_ratio { + u32 num; + u32 den; +}; + +/** + * enum vadc_scale_fn_type - Scaling function to convert ADC code to + * physical scaled units for the channel. + * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV). + * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC. + * Uses a mapping table with 100K pullup. + * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. + * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC. + * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp + * SCALE_HW_CALIB_DEFAULT: Default scaling to convert raw adc code to + * voltage (uV) with hardware applied offset/slope values to adc code. + * SCALE_HW_CALIB_THERM_100K_PULLUP: Returns temperature in millidegC using + * lookup table. The hardware applies offset/slope to adc code. + * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using + * 100k pullup. The hardware applies offset/slope to adc code. + * SCALE_HW_CALIB_THERM_100K_PU_PM7: Returns temperature in millidegC using + * lookup table for PMIC7. The hardware applies offset/slope to adc code. + * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade. + * The hardware applies offset/slope to adc code. + * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade. + * The hardware applies offset/slope to adc code. This is for PMIC7. + * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5 + * charger temperature. + * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5 + * SMB1390 temperature. + */ +enum vadc_scale_fn_type { + SCALE_DEFAULT = 0, + SCALE_THERM_100K_PULLUP, + SCALE_PMIC_THERM, + SCALE_XOTHERM, + SCALE_PMI_CHG_TEMP, + SCALE_HW_CALIB_DEFAULT, + SCALE_HW_CALIB_THERM_100K_PULLUP, + SCALE_HW_CALIB_XOTHERM, + SCALE_HW_CALIB_THERM_100K_PU_PM7, + SCALE_HW_CALIB_PMIC_THERM, + SCALE_HW_CALIB_PMIC_THERM_PM7, + SCALE_HW_CALIB_PM5_CHG_TEMP, + SCALE_HW_CALIB_PM5_SMB_TEMP, + SCALE_HW_CALIB_INVALID, +}; + +struct adc5_data { + const u32 full_scale_code_volt; + const u32 full_scale_code_cur; + const struct adc5_channels *adc_chans; + const struct iio_info *info; + unsigned int *decimation; + unsigned int *hw_settle_1; + unsigned int *hw_settle_2; +}; + +int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, + const struct vadc_linear_graph *calib_graph, + const struct vadc_prescale_ratio *prescale, + bool absolute, + u16 adc_code, int *result_mdec); + +struct qcom_adc5_scale_type { + int (*scale_fn)(const struct vadc_prescale_ratio *prescale, + const struct adc5_data *data, u16 adc_code, int *result); +}; + +int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, + unsigned int prescale_ratio, + const struct adc5_data *data, + u16 adc_code, int *result_mdec); + +int qcom_adc5_prescaling_from_dt(u32 num, u32 den); + +int qcom_adc5_hw_settle_time_from_dt(u32 value, const unsigned int *hw_settle); + +int qcom_adc5_avg_samples_from_dt(u32 value); + +int qcom_adc5_decimation_from_dt(u32 value, const unsigned int *decimation); + +int qcom_vadc_decimation_from_dt(u32 value); + +#endif /* QCOM_VADC_COMMON_H */ -- cgit v1.2.3 From 6e39b145cef7577cd6b550e633155e5fc1e5838e Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 4 Dec 2020 05:55:01 +0300 Subject: iio: provide of_iio_channel_get_by_name() and devm_ version it There might be cases when the IIO channel is attached to the device subnode instead of being attached to the main device node. Allow drivers to query IIO channels by using device tree nodes. Signed-off-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20201204025509.1075506-8-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron --- drivers/iio/inkern.c | 34 ++++++++++++++++++++++++++-------- include/linux/iio/consumer.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index fe30bcb6a57b..db77a2d4a56b 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -191,8 +191,8 @@ err_free_channel: return ERR_PTR(err); } -static struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, - const char *name) +struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, + const char *name) { struct iio_channel *chan = NULL; @@ -230,6 +230,7 @@ static struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, return chan; } +EXPORT_SYMBOL_GPL(of_iio_channel_get_by_name); static struct iio_channel *of_iio_channel_get_all(struct device *dev) { @@ -272,12 +273,6 @@ error_free_chans: #else /* CONFIG_OF */ -static inline struct iio_channel * -of_iio_channel_get_by_name(struct device_node *np, const char *name) -{ - return NULL; -} - static inline struct iio_channel *of_iio_channel_get_all(struct device *dev) { return NULL; @@ -393,6 +388,29 @@ struct iio_channel *devm_iio_channel_get(struct device *dev, } EXPORT_SYMBOL_GPL(devm_iio_channel_get); +struct iio_channel *devm_of_iio_channel_get_by_name(struct device *dev, + struct device_node *np, + const char *channel_name) +{ + struct iio_channel **ptr, *channel; + + ptr = devres_alloc(devm_iio_channel_free, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + channel = of_iio_channel_get_by_name(np, channel_name); + if (IS_ERR(channel)) { + devres_free(ptr); + return channel; + } + + *ptr = channel; + devres_add(dev, ptr); + + return channel; +} +EXPORT_SYMBOL_GPL(devm_of_iio_channel_get_by_name); + struct iio_channel *iio_channel_get_all(struct device *dev) { const char *name; diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index c4118dcb8e05..0a90ba8fa1bb 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -13,6 +13,7 @@ struct iio_dev; struct iio_chan_spec; struct device; +struct device_node; /** * struct iio_channel - everything needed for a consumer to use a channel @@ -97,6 +98,41 @@ void iio_channel_release_all(struct iio_channel *chan); */ struct iio_channel *devm_iio_channel_get_all(struct device *dev); +/** + * of_iio_channel_get_by_name() - get description of all that is needed to access channel. + * @np: Pointer to consumer device tree node + * @consumer_channel: Unique name to identify the channel on the consumer + * side. This typically describes the channels use within + * the consumer. E.g. 'battery_voltage' + */ +#ifdef CONFIG_OF +struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, const char *name); +#else +static inline struct iio_channel * +of_iio_channel_get_by_name(struct device_node *np, const char *name) +{ + return NULL; +} +#endif + +/** + * devm_of_iio_channel_get_by_name() - Resource managed version of of_iio_channel_get_by_name(). + * @dev: Pointer to consumer device. + * @np: Pointer to consumer device tree node + * @consumer_channel: Unique name to identify the channel on the consumer + * side. This typically describes the channels use within + * the consumer. E.g. 'battery_voltage' + * + * Returns a pointer to negative errno if it is not able to get the iio channel + * otherwise returns valid pointer for iio channel. + * + * The allocated iio channel is automatically released when the device is + * unbound. + */ +struct iio_channel *devm_of_iio_channel_get_by_name(struct device *dev, + struct device_node *np, + const char *consumer_channel); + struct iio_cb_buffer; /** * iio_channel_get_all_cb() - register callback for triggered capture -- cgit v1.2.3 From bb01e263743293d37148f1fa00e3ea04dca416a5 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 4 Dec 2020 05:55:02 +0300 Subject: iio: adc: move vadc_map_pt from header to the source file struct vadc_map_pt is not used outside of qcom-vadc-common.c, so move it there from the global header file. Signed-off-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20201204025509.1075506-9-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron --- drivers/iio/adc/qcom-vadc-common.c | 11 +++++++++++ include/linux/iio/adc/qcom-vadc-common.h | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index ee94774b72e6..45a38602f66a 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -10,6 +10,17 @@ #include #include +/** + * struct vadc_map_pt - Map the graph representation for ADC channel + * @x: Represent the ADC digitized code. + * @y: Represent the physical data which can be temperature, voltage, + * resistance. + */ +struct vadc_map_pt { + s32 x; + s32 y; +}; + /* Voltage to temperature */ static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = { {1758, -40}, diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h index 03a9119edc71..1d337dd9e3dc 100644 --- a/include/linux/iio/adc/qcom-vadc-common.h +++ b/include/linux/iio/adc/qcom-vadc-common.h @@ -59,17 +59,6 @@ #define DIE_TEMP_ADC7_SCALE_FACTOR 1000 #define DIE_TEMP_ADC7_MAX 160000 -/** - * struct vadc_map_pt - Map the graph representation for ADC channel - * @x: Represent the ADC digitized code. - * @y: Represent the physical data which can be temperature, voltage, - * resistance. - */ -struct vadc_map_pt { - s32 x; - s32 y; -}; - /* * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for -- cgit v1.2.3 From 3bd0ceb566f700adc5d164f431d1da039374aa97 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 4 Dec 2020 05:55:03 +0300 Subject: iio: adc: qcom-vadc-common: rewrite vadc7 die temp calculation qcom_vadc7_scale_hw_calib_die_temp() uses a table format different from the rest of volt/temp conversion functions in this file. Also the conversion functions results in non-monothonic values conversion, which seems wrong. Rewrite qcom_vadc7_scale_hw_calib_die_temp() to use qcom_vadc_map_voltage_temp() directly, like the rest of conversion functions do. Signed-off-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20201204025509.1075506-10-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron --- drivers/iio/adc/qcom-vadc-common.c | 50 ++++++++++---------------------- include/linux/iio/adc/qcom-vadc-common.h | 5 ---- 2 files changed, 15 insertions(+), 40 deletions(-) (limited to 'include') diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index 45a38602f66a..0c705bb473fe 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -101,18 +101,18 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = { }; static const struct vadc_map_pt adcmap7_die_temp[] = { - { 433700, 1967}, - { 473100, 1964}, - { 512400, 1957}, - { 551500, 1949}, - { 590500, 1940}, - { 629300, 1930}, - { 667900, 1921}, - { 706400, 1910}, - { 744600, 1896}, - { 782500, 1878}, - { 820100, 1859}, - { 857300, 0}, + { 857300, 160000 }, + { 820100, 140000 }, + { 782500, 120000 }, + { 744600, 100000 }, + { 706400, 80000 }, + { 667900, 60000 }, + { 629300, 40000 }, + { 590500, 20000 }, + { 551500, 0 }, + { 512400, -20000 }, + { 473100, -40000 }, + { 433700, -60000 }, }; /* @@ -585,33 +585,13 @@ static int qcom_vadc7_scale_hw_calib_die_temp( u16 adc_code, int *result_mdec) { - int voltage, vtemp0, temp, i; + int voltage; voltage = qcom_vadc_scale_code_voltage_factor(adc_code, prescale, data, 1); - if (adcmap7_die_temp[0].x > voltage) { - *result_mdec = DIE_TEMP_ADC7_SCALE_1; - return 0; - } - - if (adcmap7_die_temp[ARRAY_SIZE(adcmap7_die_temp) - 1].x <= voltage) { - *result_mdec = DIE_TEMP_ADC7_MAX; - return 0; - } - - for (i = 0; i < ARRAY_SIZE(adcmap7_die_temp); i++) - if (adcmap7_die_temp[i].x > voltage) - break; - - vtemp0 = adcmap7_die_temp[i - 1].x; - voltage = voltage - vtemp0; - temp = div64_s64(voltage * DIE_TEMP_ADC7_SCALE_FACTOR, - adcmap7_die_temp[i - 1].y); - temp += DIE_TEMP_ADC7_SCALE_1 + (DIE_TEMP_ADC7_SCALE_2 * (i - 1)); - *result_mdec = temp; - - return 0; + return qcom_vadc_map_voltage_temp(adcmap7_die_temp, ARRAY_SIZE(adcmap7_die_temp), + voltage, result_mdec); } static int qcom_vadc_scale_hw_smb_temp( diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h index 1d337dd9e3dc..58216124d89d 100644 --- a/include/linux/iio/adc/qcom-vadc-common.h +++ b/include/linux/iio/adc/qcom-vadc-common.h @@ -54,11 +54,6 @@ #define R_PU_100K 100000 #define RATIO_MAX_ADC7 BIT(14) -#define DIE_TEMP_ADC7_SCALE_1 -60000 -#define DIE_TEMP_ADC7_SCALE_2 20000 -#define DIE_TEMP_ADC7_SCALE_FACTOR 1000 -#define DIE_TEMP_ADC7_MAX 160000 - /* * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for -- cgit v1.2.3 From 239319670e2a7c405eeb4b3e7721cf8bf8eef840 Mon Sep 17 00:00:00 2001 From: Ye Xiang Date: Tue, 15 Dec 2020 13:44:42 +0800 Subject: HID: hid-sensor-custom: Add custom sensor iio support Currently custom sensors properties are not decoded and it is up to user space to interpret. Some manufacturers already standardized the meaning of some custom sensors. They can be presented as a proper IIO sensor. We can identify these sensors based on manufacturer and serial number property in the report. This change is identifying hinge sensor when the manufacturer is "INTEL". This creates a platform device so that a sensor driver can be loaded to process these sensors. Signed-off-by: Ye Xiang Acked-by: Jiri Kosina Link: https://lore.kernel.org/r/20201215054444.9324-2-xiang.ye@intel.com Signed-off-by: Jonathan Cameron --- drivers/hid/hid-sensor-custom.c | 143 ++++++++++++++++++++++++++++++++++++++++ include/linux/hid-sensor-ids.h | 14 ++++ 2 files changed, 157 insertions(+) (limited to 'include') diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 4d25577a8573..2628bc53ed80 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -4,6 +4,7 @@ * Copyright (c) 2015, Intel Corporation. */ +#include #include #include #include @@ -21,6 +22,7 @@ #define HID_CUSTOM_TOTAL_ATTRS (HID_CUSTOM_MAX_CORE_ATTRS + 1) #define HID_CUSTOM_FIFO_SIZE 4096 #define HID_CUSTOM_MAX_FEATURE_BYTES 64 +#define HID_SENSOR_USAGE_LENGTH (4 + 1) struct hid_sensor_custom_field { int report_id; @@ -50,6 +52,7 @@ struct hid_sensor_custom { struct kfifo data_fifo; unsigned long misc_opened; wait_queue_head_t wait; + struct platform_device *custom_pdev; }; /* Header for each sample to user space via dev interface */ @@ -746,11 +749,130 @@ static void hid_sensor_custom_dev_if_remove(struct hid_sensor_custom } +/* luid defined in FW (e.g. ISH). Maybe used to identify sensor. */ +static const char *const known_sensor_luid[] = { "020B000000000000" }; + +static int get_luid_table_index(unsigned char *usage_str) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(known_sensor_luid); i++) { + if (!strncmp(usage_str, known_sensor_luid[i], + strlen(known_sensor_luid[i]))) + return i; + } + + return -ENODEV; +} + +static int get_known_custom_sensor_index(struct hid_sensor_hub_device *hsdev) +{ + struct hid_sensor_hub_attribute_info sensor_manufacturer = { 0 }; + struct hid_sensor_hub_attribute_info sensor_luid_info = { 0 }; + int report_size; + int ret; + static u16 w_buf[HID_CUSTOM_MAX_FEATURE_BYTES]; + static char buf[HID_CUSTOM_MAX_FEATURE_BYTES]; + int i; + + memset(w_buf, 0, sizeof(w_buf)); + memset(buf, 0, sizeof(buf)); + + /* get manufacturer info */ + ret = sensor_hub_input_get_attribute_info(hsdev, + HID_FEATURE_REPORT, hsdev->usage, + HID_USAGE_SENSOR_PROP_MANUFACTURER, &sensor_manufacturer); + if (ret < 0) + return ret; + + report_size = + sensor_hub_get_feature(hsdev, sensor_manufacturer.report_id, + sensor_manufacturer.index, sizeof(w_buf), + w_buf); + if (report_size <= 0) { + hid_err(hsdev->hdev, + "Failed to get sensor manufacturer info %d\n", + report_size); + return -ENODEV; + } + + /* convert from wide char to char */ + for (i = 0; i < ARRAY_SIZE(buf) - 1 && w_buf[i]; i++) + buf[i] = (char)w_buf[i]; + + /* ensure it's ISH sensor */ + if (strncmp(buf, "INTEL", strlen("INTEL"))) + return -ENODEV; + + memset(w_buf, 0, sizeof(w_buf)); + memset(buf, 0, sizeof(buf)); + + /* get real usage id */ + ret = sensor_hub_input_get_attribute_info(hsdev, + HID_FEATURE_REPORT, hsdev->usage, + HID_USAGE_SENSOR_PROP_SERIAL_NUM, &sensor_luid_info); + if (ret < 0) + return ret; + + report_size = sensor_hub_get_feature(hsdev, sensor_luid_info.report_id, + sensor_luid_info.index, sizeof(w_buf), + w_buf); + if (report_size <= 0) { + hid_err(hsdev->hdev, "Failed to get real usage info %d\n", + report_size); + return -ENODEV; + } + + /* convert from wide char to char */ + for (i = 0; i < ARRAY_SIZE(buf) - 1 && w_buf[i]; i++) + buf[i] = (char)w_buf[i]; + + if (strlen(buf) != strlen(known_sensor_luid[0]) + 5) { + hid_err(hsdev->hdev, + "%s luid length not match %zu != (%zu + 5)\n", __func__, + strlen(buf), strlen(known_sensor_luid[0])); + return -ENODEV; + } + + /* get table index with luid (not matching 'LUID: ' in luid) */ + return get_luid_table_index(&buf[5]); +} + +static struct platform_device * +hid_sensor_register_platform_device(struct platform_device *pdev, + struct hid_sensor_hub_device *hsdev, + int index) +{ + char real_usage[HID_SENSOR_USAGE_LENGTH] = { 0 }; + struct platform_device *custom_pdev; + const char *dev_name; + char *c; + + /* copy real usage id */ + memcpy(real_usage, known_sensor_luid[index], 4); + + /* usage id are all lowcase */ + for (c = real_usage; *c != '\0'; c++) + *c = tolower(*c); + + /* HID-SENSOR-INT-REAL_USAGE_ID */ + dev_name = kasprintf(GFP_KERNEL, "HID-SENSOR-INT-%s", real_usage); + if (!dev_name) + return ERR_PTR(-ENOMEM); + + custom_pdev = platform_device_register_data(pdev->dev.parent, dev_name, + PLATFORM_DEVID_NONE, hsdev, + sizeof(*hsdev)); + kfree(dev_name); + return custom_pdev; +} + static int hid_sensor_custom_probe(struct platform_device *pdev) { struct hid_sensor_custom *sensor_inst; struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; int ret; + int index; sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), GFP_KERNEL); @@ -764,6 +886,22 @@ static int hid_sensor_custom_probe(struct platform_device *pdev) sensor_inst->pdev = pdev; mutex_init(&sensor_inst->mutex); platform_set_drvdata(pdev, sensor_inst); + + index = get_known_custom_sensor_index(hsdev); + if (index >= 0 && index < ARRAY_SIZE(known_sensor_luid)) { + sensor_inst->custom_pdev = + hid_sensor_register_platform_device(pdev, hsdev, index); + + ret = PTR_ERR_OR_ZERO(sensor_inst->custom_pdev); + if (ret) { + dev_err(&pdev->dev, + "register_platform_device failed\n"); + return ret; + } + + return 0; + } + ret = sensor_hub_register_callback(hsdev, hsdev->usage, &sensor_inst->callbacks); if (ret < 0) { @@ -802,6 +940,11 @@ static int hid_sensor_custom_remove(struct platform_device *pdev) struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; + if (sensor_inst->custom_pdev) { + platform_device_unregister(sensor_inst->custom_pdev); + return 0; + } + hid_sensor_custom_dev_if_remove(sensor_inst); hid_sensor_custom_remove_attributes(sensor_inst); sysfs_remove_group(&sensor_inst->pdev->dev.kobj, diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index d82a97e311d3..3bbdbccc5805 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -128,6 +128,10 @@ #define HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND 0x15 /* Common selectors */ +#define HID_USAGE_SENSOR_PROP_DESC 0x200300 +#define HID_USAGE_SENSOR_PROP_FRIENDLY_NAME 0x200301 +#define HID_USAGE_SENSOR_PROP_SERIAL_NUM 0x200307 +#define HID_USAGE_SENSOR_PROP_MANUFACTURER 0x200305 #define HID_USAGE_SENSOR_PROP_REPORT_INTERVAL 0x20030E #define HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS 0x20030F #define HID_USAGE_SENSOR_PROP_SENSITIVITY_RANGE_PCT 0x200310 @@ -158,4 +162,14 @@ #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM 0x200840 #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM 0x200841 +/* Custom Sensor (2000e1) */ +#define HID_USAGE_SENSOR_HINGE 0x20020B +#define HID_USAGE_SENSOR_DATA_FIELD_LOCATION 0x200400 +#define HID_USAGE_SENSOR_DATA_FIELE_TIME_SINCE_SYS_BOOT 0x20052B +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_USAGE 0x200541 +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_BASE 0x200543 +/* Custom Sensor data 28=>x>=0 */ +#define HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(x) \ + (HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE_BASE + (x)) + #endif -- cgit v1.2.3 From fd765da06066215b5e75c5c2a0db1543a81aa14d Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 21 Jan 2021 08:18:12 +0100 Subject: staging: hikey9xx: hi6421v600-regulator: fix delay logic The original driver, which can be seen at commit 42f24d9d446a ("staging: regulator: add a regulator driver for HiSilicon 6421v600 SPMI PMIC") had a complex logic to ensure that there won't be multiple power enable/disable commands running at the same time. At the original logic, it were ensured that: - a next power up/down would wait for at least the on/off period; - an extra delay would be granted. It turns that such extra delay has a value of zero, but it was relying on gettimeofday() call, which can take some time. This was later simplified, but there are still some possible issues. In order to avoid that, let's simply add a delay to wait for the power up line to stabilize after powering up a device. Signed-off-by: Mauro Carvalho Chehab Link: https://lore.kernel.org/r/6733dac9813ba6688def404142cb7b964accf758.1611212783.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hikey9xx/hi6421v600-regulator.c | 5 +++-- include/linux/mfd/hi6421-spmi-pmic.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 5e78eebfc1f3..e5a492ee7121 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -113,14 +113,15 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) /* cannot enable more than one regulator at one time */ mutex_lock(&sreg->enable_mutex); - usleep_range(HISI_REGS_ENA_PROTECT_TIME, - HISI_REGS_ENA_PROTECT_TIME + 1000); /* set enable register */ ret = hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, rdev->desc->enable_mask, rdev->desc->enable_mask); + /* Avoid powering up multiple devices at the same time */ + usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 60); + mutex_unlock(&sreg->enable_mutex); return ret; diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index 2c8896fd852e..0c2214612c4e 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -13,7 +13,6 @@ #include -#define HISI_REGS_ENA_PROTECT_TIME (0) /* in microseconds */ #define HISI_ECO_MODE_ENABLE (1) #define HISI_ECO_MODE_DISABLE (0) -- cgit v1.2.3 From fb02e3ebfb2da27172da47f79a5481c4fe83d751 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 29 Jan 2021 20:51:47 +0100 Subject: staging: hikey9xx: spmi driver: convert to regmap Instead of doing its own SPMI I/O implementation, use the already-existing regmap one. Signed-off-by: Mauro Carvalho Chehab Link: https://lore.kernel.org/r/7084885f3007ca5daf0d5bc85d038e26ee82dc0d.1611949675.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hikey9xx/Kconfig | 2 + drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 115 ++++++++---------------- drivers/staging/hikey9xx/hi6421v600-regulator.c | 26 +++--- include/linux/mfd/hi6421-spmi-pmic.h | 7 +- 4 files changed, 54 insertions(+), 96 deletions(-) (limited to 'include') diff --git a/drivers/staging/hikey9xx/Kconfig b/drivers/staging/hikey9xx/Kconfig index 2e48ded92a7e..82bb4a22b286 100644 --- a/drivers/staging/hikey9xx/Kconfig +++ b/drivers/staging/hikey9xx/Kconfig @@ -29,6 +29,7 @@ config MFD_HI6421_SPMI depends on OF depends on SPMI select MFD_CORE + select REGMAP_SPMI help Add support for HiSilicon Hi6421v600 SPMI PMIC. Hi6421 includes multi-functions, such as regulators, RTC, codec, Coulomb counter, @@ -44,6 +45,7 @@ config REGULATOR_HI6421V600 tristate "HiSilicon Hi6421v600 PMIC voltage regulator support" depends on MFD_HI6421_SPMI && OF depends on REGULATOR + select REGMAP help This driver provides support for the voltage regulators on HiSilicon Hi6421v600 PMU / Codec IC. diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 69570876f93e..3d612bd46231 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -41,81 +41,22 @@ static const struct mfd_cell hi6421v600_devs[] = { { .name = "hi6421v600-regulator", }, }; -/* - * The PMIC register is only 8-bit. - * Hisilicon SoC use hardware to map PMIC register into SoC mapping. - * At here, we are accessing SoC register with 32-bit. - */ -int hi6421_spmi_pmic_read(struct hi6421_spmi_pmic *pmic, int reg) +static irqreturn_t hi6421_spmi_irq_handler(int irq, void *priv) { - struct spmi_device *pdev; - u8 read_value = 0; - u32 ret; - - pdev = to_spmi_device(pmic->dev); - if (!pdev) { - pr_err("%s: pdev get failed!\n", __func__); - return -ENODEV; - } - - ret = spmi_ext_register_readl(pdev, reg, &read_value, 1); - if (ret) { - pr_err("%s: spmi_ext_register_readl failed!\n", __func__); - return ret; - } - return read_value; -} -EXPORT_SYMBOL(hi6421_spmi_pmic_read); - -int hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, int reg, u32 val) -{ - struct spmi_device *pdev; - u32 ret; - - pdev = to_spmi_device(pmic->dev); - if (!pdev) { - pr_err("%s: pdev get failed!\n", __func__); - return -ENODEV; - } - - ret = spmi_ext_register_writel(pdev, reg, (unsigned char *)&val, 1); - if (ret) - pr_err("%s: spmi_ext_register_writel failed!\n", __func__); - - return ret; -} -EXPORT_SYMBOL(hi6421_spmi_pmic_write); - -int hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, - u32 mask, u32 bits) -{ - unsigned long flags; - u32 data; - int ret; - - spin_lock_irqsave(&pmic->lock, flags); - data = hi6421_spmi_pmic_read(pmic, reg) & ~mask; - data |= mask & bits; - ret = hi6421_spmi_pmic_write(pmic, reg, data); - spin_unlock_irqrestore(&pmic->lock, flags); - - return ret; -} -EXPORT_SYMBOL(hi6421_spmi_pmic_rmw); - -static irqreturn_t hi6421_spmi_irq_handler(int irq, void *data) -{ - struct hi6421_spmi_pmic *pmic = (struct hi6421_spmi_pmic *)data; + struct hi6421_spmi_pmic *pmic = (struct hi6421_spmi_pmic *)priv; unsigned long pending; + unsigned int data; int i, offset; for (i = 0; i < HISI_IRQ_ARRAY; i++) { - pending = hi6421_spmi_pmic_read(pmic, (i + SOC_PMIC_IRQ0_ADDR)); - pending &= HISI_MASK_FIELD; - if (pending != 0) - pr_debug("pending[%d]=0x%lx\n\r", i, pending); + regmap_read(pmic->map, offset, &data); + data &= HISI_MASK_FIELD; + if (data != 0) + pr_debug("data[%d]=0x%d\n\r", i, data); + regmap_write(pmic->map, i + SOC_PMIC_IRQ0_ADDR, data); - hi6421_spmi_pmic_write(pmic, (i + SOC_PMIC_IRQ0_ADDR), pending); + /* for_each_set_bit() macro requires unsigned long */ + pending = data; /* solve powerkey order */ if ((i == HISI_IRQ_KEY_NUM) && @@ -137,16 +78,18 @@ static irqreturn_t hi6421_spmi_irq_handler(int irq, void *data) static void hi6421_spmi_irq_mask(struct irq_data *d) { struct hi6421_spmi_pmic *pmic = irq_data_get_irq_chip_data(d); - u32 data, offset; unsigned long flags; + unsigned int data; + u32 offset; offset = (irqd_to_hwirq(d) >> 3); offset += SOC_PMIC_IRQ_MASK_0_ADDR; spin_lock_irqsave(&pmic->lock, flags); - data = hi6421_spmi_pmic_read(pmic, offset); + + regmap_read(pmic->map, offset, &data); data |= (1 << (irqd_to_hwirq(d) & 0x07)); - hi6421_spmi_pmic_write(pmic, offset, data); + regmap_write(pmic->map, offset, data); spin_unlock_irqrestore(&pmic->lock, flags); } @@ -160,9 +103,9 @@ static void hi6421_spmi_irq_unmask(struct irq_data *d) offset += SOC_PMIC_IRQ_MASK_0_ADDR; spin_lock_irqsave(&pmic->lock, flags); - data = hi6421_spmi_pmic_read(pmic, offset); + regmap_read(pmic->map, offset, &data); data &= ~(1 << (irqd_to_hwirq(d) & 0x07)); - hi6421_spmi_pmic_write(pmic, offset, data); + regmap_write(pmic->map, offset, data); spin_unlock_irqrestore(&pmic->lock, flags); } @@ -194,27 +137,36 @@ static const struct irq_domain_ops hi6421_spmi_domain_ops = { static void hi6421_spmi_pmic_irq_prc(struct hi6421_spmi_pmic *pmic) { - int i, pending; + int i; + unsigned int pending; for (i = 0 ; i < HISI_IRQ_ARRAY; i++) - hi6421_spmi_pmic_write(pmic, SOC_PMIC_IRQ_MASK_0_ADDR + i, + regmap_write(pmic->map, SOC_PMIC_IRQ_MASK_0_ADDR + i, HISI_MASK_STATE); for (i = 0 ; i < HISI_IRQ_ARRAY; i++) { - pending = hi6421_spmi_pmic_read(pmic, SOC_PMIC_IRQ0_ADDR + i); + regmap_read(pmic->map, SOC_PMIC_IRQ0_ADDR + i, &pending); pr_debug("PMU IRQ address value:irq[0x%x] = 0x%x\n", SOC_PMIC_IRQ0_ADDR + i, pending); - hi6421_spmi_pmic_write(pmic, SOC_PMIC_IRQ0_ADDR + i, - HISI_MASK_STATE); + regmap_write(pmic->map, SOC_PMIC_IRQ0_ADDR + i, + HISI_MASK_STATE); } } +static const struct regmap_config spmi_regmap_config = { + .reg_bits = 16, + .val_bits = 8, + .max_register = 0xffff, + .fast_io = true +}; + static int hi6421_spmi_pmic_probe(struct spmi_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct hi6421_spmi_pmic *pmic; + struct regmap *map; unsigned int virq; int ret, i; @@ -222,9 +174,14 @@ static int hi6421_spmi_pmic_probe(struct spmi_device *pdev) if (!pmic) return -ENOMEM; + map = devm_regmap_init_spmi_ext(pdev, &spmi_regmap_config); + if (IS_ERR(map)) + return PTR_ERR(map); + spin_lock_init(&pmic->lock); pmic->dev = dev; + pmic->map = map; pmic->gpio = of_get_gpio(np, 0); if (pmic->gpio < 0) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 382a0b21643e..9e319fa11137 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -100,7 +101,7 @@ static int hi6421_spmi_regulator_is_enabled(struct regulator_dev *rdev) struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val; - reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); + regmap_read(pmic->map, rdev->desc->enable_reg, ®_val); return ((reg_val & rdev->desc->enable_mask) != 0); } @@ -114,9 +115,9 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) /* cannot enable more than one regulator at one time */ mutex_lock(&sreg->enable_mutex); - ret = hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, - rdev->desc->enable_mask, - rdev->desc->enable_mask); + ret = regmap_update_bits(pmic->map, rdev->desc->enable_reg, + rdev->desc->enable_mask, + rdev->desc->enable_mask); /* Avoid powering up multiple devices at the same time */ usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 60); @@ -131,8 +132,8 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - return hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, - rdev->desc->enable_mask, 0); + return regmap_update_bits(pmic->map, rdev->desc->enable_reg, + rdev->desc->enable_mask, 0); } static int hi6421_spmi_regulator_get_voltage_sel(struct regulator_dev *rdev) @@ -141,7 +142,7 @@ static int hi6421_spmi_regulator_get_voltage_sel(struct regulator_dev *rdev) struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val; - reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->vsel_reg); + regmap_read(pmic->map, rdev->desc->vsel_reg, ®_val); return (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1); } @@ -159,8 +160,8 @@ static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev, reg_val = selector << (ffs(rdev->desc->vsel_mask) - 1); /* set voltage selector */ - return hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg, - rdev->desc->vsel_mask, reg_val); + return regmap_update_bits(pmic->map, rdev->desc->vsel_reg, + rdev->desc->vsel_mask, reg_val); } static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) @@ -169,7 +170,7 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val; - reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); + regmap_read(pmic->map, rdev->desc->enable_reg, ®_val); if (reg_val & sreg->eco_mode_mask) return REGULATOR_MODE_IDLE; @@ -195,8 +196,8 @@ static int hi6421_spmi_regulator_set_mode(struct regulator_dev *rdev, return -EINVAL; } - return hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, - sreg->eco_mode_mask, val); + return regmap_update_bits(pmic->map, rdev->desc->enable_reg, + sreg->eco_mode_mask, val); } static unsigned int @@ -304,6 +305,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev) config.dev = pdev->dev.parent; config.driver_data = sreg; + config.regmap = pmic->map; rdev = devm_regulator_register(dev, &info->desc, &config); if (IS_ERR(rdev)) { diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index 0c2214612c4e..c5a4eac1fdc0 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -12,6 +12,7 @@ #define __HISI_PMIC_H #include +#include #define HISI_ECO_MODE_ENABLE (1) #define HISI_ECO_MODE_DISABLE (0) @@ -25,13 +26,9 @@ struct hi6421_spmi_pmic { int irq; int gpio; unsigned int *irqs; + struct regmap *map; }; -int hi6421_spmi_pmic_read(struct hi6421_spmi_pmic *pmic, int reg); -int hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, int reg, u32 val); -int hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, - u32 mask, u32 bits); - enum hi6421_spmi_pmic_irq_list { OTMP = 0, VBUS_CONNECT, -- cgit v1.2.3 From fcd732406c5d65ba92515af81ca281a4f8348687 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 29 Jan 2021 20:51:49 +0100 Subject: staging: hikey9xx: hi6421-spmi-pmic: rename some vars - When referring to regmap, rename map to regmap - inside hi6421-spmi-pmic, call private data struct as ddata. No functional changes. Signed-off-by: Mauro Carvalho Chehab Link: https://lore.kernel.org/r/d23592b11ac606e3b9a3ff95a754cb75921e60aa.1611949675.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 104 ++++++++++++------------ drivers/staging/hikey9xx/hi6421v600-regulator.c | 10 +-- include/linux/mfd/hi6421-spmi-pmic.h | 2 +- 3 files changed, 58 insertions(+), 58 deletions(-) (limited to 'include') diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 3d612bd46231..a4ffeb06ed6a 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -43,17 +43,17 @@ static const struct mfd_cell hi6421v600_devs[] = { static irqreturn_t hi6421_spmi_irq_handler(int irq, void *priv) { - struct hi6421_spmi_pmic *pmic = (struct hi6421_spmi_pmic *)priv; + struct hi6421_spmi_pmic *ddata = (struct hi6421_spmi_pmic *)priv; unsigned long pending; unsigned int data; int i, offset; for (i = 0; i < HISI_IRQ_ARRAY; i++) { - regmap_read(pmic->map, offset, &data); + regmap_read(ddata->regmap, offset, &data); data &= HISI_MASK_FIELD; if (data != 0) pr_debug("data[%d]=0x%d\n\r", i, data); - regmap_write(pmic->map, i + SOC_PMIC_IRQ0_ADDR, data); + regmap_write(ddata->regmap, i + SOC_PMIC_IRQ0_ADDR, data); /* for_each_set_bit() macro requires unsigned long */ pending = data; @@ -61,14 +61,14 @@ static irqreturn_t hi6421_spmi_irq_handler(int irq, void *priv) /* solve powerkey order */ if ((i == HISI_IRQ_KEY_NUM) && ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { - generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_DOWN]); - generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_UP]); + generic_handle_irq(ddata->irqs[HISI_IRQ_KEY_DOWN]); + generic_handle_irq(ddata->irqs[HISI_IRQ_KEY_UP]); pending &= (~HISI_IRQ_KEY_VALUE); } if (pending) { for_each_set_bit(offset, &pending, HISI_BITS) - generic_handle_irq(pmic->irqs[offset + i * HISI_BITS]); + generic_handle_irq(ddata->irqs[offset + i * HISI_BITS]); } } @@ -77,7 +77,7 @@ static irqreturn_t hi6421_spmi_irq_handler(int irq, void *priv) static void hi6421_spmi_irq_mask(struct irq_data *d) { - struct hi6421_spmi_pmic *pmic = irq_data_get_irq_chip_data(d); + struct hi6421_spmi_pmic *ddata = irq_data_get_irq_chip_data(d); unsigned long flags; unsigned int data; u32 offset; @@ -85,28 +85,28 @@ static void hi6421_spmi_irq_mask(struct irq_data *d) offset = (irqd_to_hwirq(d) >> 3); offset += SOC_PMIC_IRQ_MASK_0_ADDR; - spin_lock_irqsave(&pmic->lock, flags); + spin_lock_irqsave(&ddata->lock, flags); - regmap_read(pmic->map, offset, &data); + regmap_read(ddata->regmap, offset, &data); data |= (1 << (irqd_to_hwirq(d) & 0x07)); - regmap_write(pmic->map, offset, data); - spin_unlock_irqrestore(&pmic->lock, flags); + regmap_write(ddata->regmap, offset, data); + spin_unlock_irqrestore(&ddata->lock, flags); } static void hi6421_spmi_irq_unmask(struct irq_data *d) { - struct hi6421_spmi_pmic *pmic = irq_data_get_irq_chip_data(d); + struct hi6421_spmi_pmic *ddata = irq_data_get_irq_chip_data(d); u32 data, offset; unsigned long flags; offset = (irqd_to_hwirq(d) >> 3); offset += SOC_PMIC_IRQ_MASK_0_ADDR; - spin_lock_irqsave(&pmic->lock, flags); - regmap_read(pmic->map, offset, &data); + spin_lock_irqsave(&ddata->lock, flags); + regmap_read(ddata->regmap, offset, &data); data &= ~(1 << (irqd_to_hwirq(d) & 0x07)); - regmap_write(pmic->map, offset, data); - spin_unlock_irqrestore(&pmic->lock, flags); + regmap_write(ddata->regmap, offset, data); + spin_unlock_irqrestore(&ddata->lock, flags); } static struct irq_chip hi6421_spmi_pmu_irqchip = { @@ -120,11 +120,11 @@ static struct irq_chip hi6421_spmi_pmu_irqchip = { static int hi6421_spmi_irq_map(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw) { - struct hi6421_spmi_pmic *pmic = d->host_data; + struct hi6421_spmi_pmic *ddata = d->host_data; irq_set_chip_and_handler_name(virq, &hi6421_spmi_pmu_irqchip, handle_simple_irq, "hisi"); - irq_set_chip_data(virq, pmic); + irq_set_chip_data(virq, ddata); irq_set_irq_type(virq, IRQ_TYPE_NONE); return 0; @@ -135,21 +135,21 @@ static const struct irq_domain_ops hi6421_spmi_domain_ops = { .xlate = irq_domain_xlate_twocell, }; -static void hi6421_spmi_pmic_irq_prc(struct hi6421_spmi_pmic *pmic) +static void hi6421_spmi_pmic_irq_prc(struct hi6421_spmi_pmic *ddata) { int i; unsigned int pending; for (i = 0 ; i < HISI_IRQ_ARRAY; i++) - regmap_write(pmic->map, SOC_PMIC_IRQ_MASK_0_ADDR + i, + regmap_write(ddata->regmap, SOC_PMIC_IRQ_MASK_0_ADDR + i, HISI_MASK_STATE); for (i = 0 ; i < HISI_IRQ_ARRAY; i++) { - regmap_read(pmic->map, SOC_PMIC_IRQ0_ADDR + i, &pending); + regmap_read(ddata->regmap, SOC_PMIC_IRQ0_ADDR + i, &pending); pr_debug("PMU IRQ address value:irq[0x%x] = 0x%x\n", SOC_PMIC_IRQ0_ADDR + i, pending); - regmap_write(pmic->map, SOC_PMIC_IRQ0_ADDR + i, + regmap_write(ddata->regmap, SOC_PMIC_IRQ0_ADDR + i, HISI_MASK_STATE); } } @@ -165,79 +165,79 @@ static int hi6421_spmi_pmic_probe(struct spmi_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - struct hi6421_spmi_pmic *pmic; + struct hi6421_spmi_pmic *ddata; struct regmap *map; unsigned int virq; int ret, i; - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); - if (!pmic) + ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + if (!ddata) return -ENOMEM; map = devm_regmap_init_spmi_ext(pdev, &spmi_regmap_config); if (IS_ERR(map)) return PTR_ERR(map); - spin_lock_init(&pmic->lock); + spin_lock_init(&ddata->lock); - pmic->dev = dev; - pmic->map = map; + ddata->dev = dev; + ddata->regmap = map; - pmic->gpio = of_get_gpio(np, 0); - if (pmic->gpio < 0) - return pmic->gpio; + ddata->gpio = of_get_gpio(np, 0); + if (ddata->gpio < 0) + return ddata->gpio; - if (!gpio_is_valid(pmic->gpio)) + if (!gpio_is_valid(ddata->gpio)) return -EINVAL; - ret = devm_gpio_request_one(dev, pmic->gpio, GPIOF_IN, "pmic"); + ret = devm_gpio_request_one(dev, ddata->gpio, GPIOF_IN, "pmic"); if (ret < 0) { - dev_err(dev, "failed to request gpio%d\n", pmic->gpio); + dev_err(dev, "failed to request gpio%d\n", ddata->gpio); return ret; } - pmic->irq = gpio_to_irq(pmic->gpio); + ddata->irq = gpio_to_irq(ddata->gpio); - hi6421_spmi_pmic_irq_prc(pmic); + hi6421_spmi_pmic_irq_prc(ddata); - pmic->irqs = devm_kzalloc(dev, HISI_IRQ_NUM * sizeof(int), GFP_KERNEL); - if (!pmic->irqs) { + ddata->irqs = devm_kzalloc(dev, HISI_IRQ_NUM * sizeof(int), GFP_KERNEL); + if (!ddata->irqs) { ret = -ENOMEM; goto irq_malloc; } - pmic->domain = irq_domain_add_simple(np, HISI_IRQ_NUM, 0, - &hi6421_spmi_domain_ops, pmic); - if (!pmic->domain) { + ddata->domain = irq_domain_add_simple(np, HISI_IRQ_NUM, 0, + &hi6421_spmi_domain_ops, ddata); + if (!ddata->domain) { dev_err(dev, "failed irq domain add simple!\n"); ret = -ENODEV; goto irq_malloc; } for (i = 0; i < HISI_IRQ_NUM; i++) { - virq = irq_create_mapping(pmic->domain, i); + virq = irq_create_mapping(ddata->domain, i); if (!virq) { dev_err(dev, "Failed mapping hwirq\n"); ret = -ENOSPC; goto irq_malloc; } - pmic->irqs[i] = virq; - dev_dbg(dev, "%s: pmic->irqs[%d] = %d\n", - __func__, i, pmic->irqs[i]); + ddata->irqs[i] = virq; + dev_dbg(dev, "%s: ddata->irqs[%d] = %d\n", + __func__, i, ddata->irqs[i]); } - ret = request_threaded_irq(pmic->irq, hi6421_spmi_irq_handler, NULL, + ret = request_threaded_irq(ddata->irq, hi6421_spmi_irq_handler, NULL, IRQF_TRIGGER_LOW | IRQF_SHARED | IRQF_NO_SUSPEND, - "pmic", pmic); + "pmic", ddata); if (ret < 0) { dev_err(dev, "could not claim pmic IRQ: error %d\n", ret); goto irq_malloc; } - dev_set_drvdata(&pdev->dev, pmic); + dev_set_drvdata(&pdev->dev, ddata); /* - * The logic below will rely that the pmic is already stored at + * The logic below will rely that the ddata is already stored at * drvdata. */ dev_dbg(&pdev->dev, "SPMI-PMIC: adding children for %pOF\n", @@ -251,16 +251,16 @@ static int hi6421_spmi_pmic_probe(struct spmi_device *pdev) dev_err(dev, "Failed to add child devices: %d\n", ret); irq_malloc: - free_irq(pmic->irq, pmic); + free_irq(ddata->irq, ddata); return ret; } static void hi6421_spmi_pmic_remove(struct spmi_device *pdev) { - struct hi6421_spmi_pmic *pmic = dev_get_drvdata(&pdev->dev); + struct hi6421_spmi_pmic *ddata = dev_get_drvdata(&pdev->dev); - free_irq(pmic->irq, pmic); + free_irq(ddata->irq, ddata); } static const struct of_device_id pmic_spmi_id_table[] = { diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 7090107b9ec2..c801bb840962 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -104,7 +104,7 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) /* cannot enable more than one regulator at one time */ mutex_lock(&sreg->enable_mutex); - ret = regmap_update_bits(pmic->map, rdev->desc->enable_reg, + ret = regmap_update_bits(pmic->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, rdev->desc->enable_mask); @@ -121,7 +121,7 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - return regmap_update_bits(pmic->map, rdev->desc->enable_reg, + return regmap_update_bits(pmic->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, 0); } @@ -131,7 +131,7 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val; - regmap_read(pmic->map, rdev->desc->enable_reg, ®_val); + regmap_read(pmic->regmap, rdev->desc->enable_reg, ®_val); if (reg_val & sreg->eco_mode_mask) return REGULATOR_MODE_IDLE; @@ -157,7 +157,7 @@ static int hi6421_spmi_regulator_set_mode(struct regulator_dev *rdev, return -EINVAL; } - return regmap_update_bits(pmic->map, rdev->desc->enable_reg, + return regmap_update_bits(pmic->regmap, rdev->desc->enable_reg, sreg->eco_mode_mask, val); } @@ -266,7 +266,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev) config.dev = pdev->dev.parent; config.driver_data = sreg; - config.regmap = pmic->map; + config.regmap = pmic->regmap; rdev = devm_regulator_register(dev, &info->desc, &config); if (IS_ERR(rdev)) { diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index c5a4eac1fdc0..aa8d5382f559 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -26,7 +26,7 @@ struct hi6421_spmi_pmic { int irq; int gpio; unsigned int *irqs; - struct regmap *map; + struct regmap *regmap; }; enum hi6421_spmi_pmic_irq_list { -- cgit v1.2.3 From 9d8dbe989029e6d767ed56773ac65409da625381 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 29 Jan 2021 20:51:51 +0100 Subject: staging: hikey9xx: hi6421-spmi-pmic: cleanup header file Remove the IRQ list from the header, as this is used only inside the driver itself. Also, get rid of two unused defines. The net result is that only struct hi6421_spmi_pmic remains on it, as this is used by the regulator driver. Signed-off-by: Mauro Carvalho Chehab Link: https://lore.kernel.org/r/138c3a11e4de0ebabdf27932957852136c2f7510.1611949675.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 17 +++++++++++++++++ include/linux/mfd/hi6421-spmi-pmic.h | 20 -------------------- 2 files changed, 17 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index c8e55b7b08e2..909f7b106af4 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -17,6 +17,23 @@ #include #include +enum hi6421_spmi_pmic_irq_list { + OTMP = 0, + VBUS_CONNECT, + VBUS_DISCONNECT, + ALARMON_R, + HOLD_6S, + HOLD_1S, + POWERKEY_UP, + POWERKEY_DOWN, + OCP_SCP_R, + COUL_R, + SIM0_HPD_R, + SIM0_HPD_F, + SIM1_HPD_R, + SIM1_HPD_F, + PMIC_IRQ_LIST_MAX, +}; /* 8-bit register offset in PMIC */ #define HISI_MASK_STATE 0xff diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index aa8d5382f559..4d61cb266a18 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -14,9 +14,6 @@ #include #include -#define HISI_ECO_MODE_ENABLE (1) -#define HISI_ECO_MODE_DISABLE (0) - struct hi6421_spmi_pmic { struct resource *res; struct device *dev; @@ -29,21 +26,4 @@ struct hi6421_spmi_pmic { struct regmap *regmap; }; -enum hi6421_spmi_pmic_irq_list { - OTMP = 0, - VBUS_CONNECT, - VBUS_DISCONNECT, - ALARMON_R, - HOLD_6S, - HOLD_1S, - POWERKEY_UP, - POWERKEY_DOWN, - OCP_SCP_R, - COUL_R, - SIM0_HPD_R, - SIM0_HPD_F, - SIM1_HPD_R, - SIM1_HPD_F, - PMIC_IRQ_LIST_MAX, -}; #endif /* __HISI_PMIC_H */ -- cgit v1.2.3 From fb7ba1870d5fdf45513fc04af8e46492eb65a5e3 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 29 Jan 2021 20:51:55 +0100 Subject: staging: hikey9xx: hi6421-spmi-pmic: update copyright notes At PMIC subsystem, C89 comments are preferred over C99. While here, also update the copyrights of the header file. Signed-off-by: Mauro Carvalho Chehab Link: https://lore.kernel.org/r/5a86478c8ccb93d3105485b5f16e20e9c12e2196.1611949675.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 14 +++++++------- include/linux/mfd/hi6421-spmi-pmic.h | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 9c10f7c4e7c9..2301f4fcd48d 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 -// -// Device driver for regulators in HISI PMIC IC -// -// Copyright (c) 2013 Linaro Ltd. -// Copyright (c) 2011 Hisilicon. -// -// Copyright (c) 2020-2021 Huawei Technologies Co., Ltd +/* + * Device driver for regulators in HISI PMIC IC + * + * Copyright (c) 2013 Linaro Ltd. + * Copyright (c) 2011 Hisilicon. + * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd + */ #include #include diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index 4d61cb266a18..2660226138b8 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -4,6 +4,7 @@ * * Copyright (c) 2013 Linaro Ltd. * Copyright (C) 2011 Hisilicon. + * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd * * Guodong Xu */ -- cgit v1.2.3