From: Jonathan Cameron <jic23@kernel.org>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Andy Gross <agross@kernel.org>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Rob Herring <robh+dt@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amitk@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 3/9] iio: adc: qcom-vadc: move several adc5 functions to common file
Date: Sun, 6 Sep 2020 15:18:52 +0100 [thread overview]
Message-ID: <20200906151852.6c93e059@archlinux> (raw)
In-Reply-To: <20200903132109.1914011-4-dmitry.baryshkov@linaro.org>
On Thu, 3 Sep 2020 16:21:03 +0300
Dmitry Baryshkov <dmitry.baryshkov@linaro.org> wrote:
> ADC-TM5 driver will make use of several functions from ADC5 driver. Move
> them to qcom-vadc-common driver.
>
LGTM
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/iio/adc/qcom-spmi-adc5.c | 75 +++---------------------------
> drivers/iio/adc/qcom-vadc-common.c | 68 ++++++++++++++++++++++++++-
> drivers/iio/adc/qcom-vadc-common.h | 10 +++-
> 3 files changed, 82 insertions(+), 71 deletions(-)
>
> diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c
> index b4b73c9920b4..30b8867b31e4 100644
> --- a/drivers/iio/adc/qcom-spmi-adc5.c
> +++ b/drivers/iio/adc/qcom-spmi-adc5.c
> @@ -154,18 +154,6 @@ struct adc5_chip {
> const struct adc5_data *data;
> };
>
> -static const struct vadc_prescale_ratio adc5_prescale_ratios[] = {
> - {.num = 1, .den = 1},
> - {.num = 1, .den = 3},
> - {.num = 1, .den = 4},
> - {.num = 1, .den = 6},
> - {.num = 1, .den = 20},
> - {.num = 1, .den = 8},
> - {.num = 10, .den = 81},
> - {.num = 1, .den = 10},
> - {.num = 1, .den = 16}
> -};
> -
> static int adc5_read(struct adc5_chip *adc, u16 offset, u8 *data, int len)
> {
> return regmap_bulk_read(adc->regmap, adc->base + offset, data, len);
> @@ -181,55 +169,6 @@ static int adc5_masked_write(struct adc5_chip *adc, u16 offset, u8 mask, u8 val)
> return regmap_update_bits(adc->regmap, adc->base + offset, mask, val);
> }
>
> -static int adc5_prescaling_from_dt(u32 num, u32 den)
> -{
> - unsigned int pre;
> -
> - for (pre = 0; pre < ARRAY_SIZE(adc5_prescale_ratios); pre++)
> - if (adc5_prescale_ratios[pre].num == num &&
> - adc5_prescale_ratios[pre].den == den)
> - break;
> -
> - if (pre == ARRAY_SIZE(adc5_prescale_ratios))
> - return -EINVAL;
> -
> - return pre;
> -}
> -
> -static int adc5_hw_settle_time_from_dt(u32 value,
> - const unsigned int *hw_settle)
> -{
> - unsigned int i;
> -
> - for (i = 0; i < VADC_HW_SETTLE_SAMPLES_MAX; i++) {
> - if (value == hw_settle[i])
> - return i;
> - }
> -
> - return -EINVAL;
> -}
> -
> -static int adc5_avg_samples_from_dt(u32 value)
> -{
> - if (!is_power_of_2(value) || value > ADC5_AVG_SAMPLES_MAX)
> - return -EINVAL;
> -
> - return __ffs(value);
> -}
> -
> -static int adc5_decimation_from_dt(u32 value,
> - const unsigned int *decimation)
> -{
> - unsigned int i;
> -
> - for (i = 0; i < ADC5_DECIMATION_SAMPLES_MAX; i++) {
> - if (value == decimation[i])
> - return i;
> - }
> -
> - return -EINVAL;
> -}
> -
> static int adc5_read_voltage_data(struct adc5_chip *adc, u16 *data)
> {
> int ret;
> @@ -511,7 +450,7 @@ static int adc_read_raw_common(struct iio_dev *indio_dev,
> return ret;
>
> ret = qcom_adc5_hw_scale(prop->scale_fn_type,
> - &adc5_prescale_ratios[prop->prescale],
> + prop->prescale,
> adc->data,
> adc_code_volt, val);
> if (ret)
> @@ -717,7 +656,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
>
> ret = of_property_read_u32(node, "qcom,decimation", &value);
> if (!ret) {
> - ret = adc5_decimation_from_dt(value, data->decimation);
> + ret = qcom_adc5_decimation_from_dt(value, data->decimation);
> if (ret < 0) {
> dev_err(dev, "%02x invalid decimation %d\n",
> chan, value);
> @@ -730,7 +669,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
>
> ret = of_property_read_u32_array(node, "qcom,pre-scaling", varr, 2);
> if (!ret) {
> - ret = adc5_prescaling_from_dt(varr[0], varr[1]);
> + ret = qcom_adc5_prescaling_from_dt(varr[0], varr[1]);
> if (ret < 0) {
> dev_err(dev, "%02x invalid pre-scaling <%d %d>\n",
> chan, varr[0], varr[1]);
> @@ -759,11 +698,9 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
> if ((dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
> dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR) ||
> adc->data->info == &adc7_info)
> - ret = adc5_hw_settle_time_from_dt(value,
> - data->hw_settle_2);
> + ret = qcom_adc5_hw_settle_time_from_dt(value, data->hw_settle_2);
> else
> - ret = adc5_hw_settle_time_from_dt(value,
> - data->hw_settle_1);
> + ret = qcom_adc5_hw_settle_time_from_dt(value, data->hw_settle_1);
>
> if (ret < 0) {
> dev_err(dev, "%02x invalid hw-settle-time %d us\n",
> @@ -777,7 +714,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
>
> ret = of_property_read_u32(node, "qcom,avg-samples", &value);
> if (!ret) {
> - ret = adc5_avg_samples_from_dt(value);
> + ret = qcom_adc5_avg_samples_from_dt(value);
> if (ret < 0) {
> dev_err(dev, "%02x invalid avg-samples %d\n",
> chan, value);
> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
> index 5113aaa6ba67..d11f3343ad52 100644
> --- a/drivers/iio/adc/qcom-vadc-common.c
> +++ b/drivers/iio/adc/qcom-vadc-common.c
> @@ -278,6 +278,18 @@ static const struct vadc_map_pt adcmap7_100k[] = {
> { 2420, 130048 }
> };
>
> +static const struct vadc_prescale_ratio adc5_prescale_ratios[] = {
> + {.num = 1, .den = 1},
> + {.num = 1, .den = 3},
> + {.num = 1, .den = 4},
> + {.num = 1, .den = 6},
> + {.num = 1, .den = 20},
> + {.num = 1, .den = 8},
> + {.num = 10, .den = 81},
> + {.num = 1, .den = 10},
> + {.num = 1, .den = 16}
> +};
> +
> static int qcom_vadc_scale_hw_calib_volt(
> const struct vadc_prescale_ratio *prescale,
> const struct adc5_data *data,
> @@ -647,10 +659,12 @@ int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
> EXPORT_SYMBOL(qcom_vadc_scale);
>
> int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
> - const struct vadc_prescale_ratio *prescale,
> + unsigned int prescale_ratio,
> const struct adc5_data *data,
> u16 adc_code, int *result)
> {
> + const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio];
> +
> if (!(scaletype >= SCALE_HW_CALIB_DEFAULT &&
> scaletype < SCALE_HW_CALIB_INVALID)) {
> pr_err("Invalid scale type %d\n", scaletype);
> @@ -662,6 +676,58 @@ int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
> }
> EXPORT_SYMBOL(qcom_adc5_hw_scale);
>
> +int qcom_adc5_prescaling_from_dt(u32 num, u32 den)
> +{
> + unsigned int pre;
> +
> + for (pre = 0; pre < ARRAY_SIZE(adc5_prescale_ratios); pre++)
> + if (adc5_prescale_ratios[pre].num == num &&
> + adc5_prescale_ratios[pre].den == den)
> + break;
> +
> + if (pre == ARRAY_SIZE(adc5_prescale_ratios))
> + return -EINVAL;
> +
> + return pre;
> +}
> +EXPORT_SYMBOL(qcom_adc5_prescaling_from_dt);
> +
> +int qcom_adc5_hw_settle_time_from_dt(u32 value,
> + const unsigned int *hw_settle)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < VADC_HW_SETTLE_SAMPLES_MAX; i++) {
> + if (value == hw_settle[i])
> + return i;
> + }
> +
> + return -EINVAL;
> +}
> +EXPORT_SYMBOL(qcom_adc5_hw_settle_time_from_dt);
> +
> +int qcom_adc5_avg_samples_from_dt(u32 value)
> +{
> + if (!is_power_of_2(value) || value > ADC5_AVG_SAMPLES_MAX)
> + return -EINVAL;
> +
> + return __ffs(value);
> +}
> +EXPORT_SYMBOL(qcom_adc5_avg_samples_from_dt);
> +
> +int qcom_adc5_decimation_from_dt(u32 value, const unsigned int *decimation)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < ADC5_DECIMATION_SAMPLES_MAX; i++) {
> + if (value == decimation[i])
> + return i;
> + }
> +
> + return -EINVAL;
> +}
> +EXPORT_SYMBOL(qcom_adc5_decimation_from_dt);
> +
> int qcom_vadc_decimation_from_dt(u32 value)
> {
> if (!is_power_of_2(value) || value < VADC_DECIMATION_MIN ||
> diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h
> index 17b2fc4d8bf2..7e5f6428e311 100644
> --- a/drivers/iio/adc/qcom-vadc-common.h
> +++ b/drivers/iio/adc/qcom-vadc-common.h
> @@ -168,10 +168,18 @@ struct qcom_adc5_scale_type {
> };
>
> int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
> - const struct vadc_prescale_ratio *prescale,
> + 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 */
next prev parent reply other threads:[~2020-09-06 14:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-03 13:21 [PATCH v2 0/0] qcom: pm8150: add support for thermal monitoring Dmitry Baryshkov
2020-09-03 13:21 ` [PATCH v2 1/9] dt-bindings: thermal: qcom: add adc-thermal monitor bindings Dmitry Baryshkov
2020-09-03 16:34 ` Rob Herring
2020-09-06 14:14 ` Jonathan Cameron
2020-09-03 13:21 ` [PATCH v2 2/9] fixp-arith: add a linear interpolation function Dmitry Baryshkov
2020-09-03 13:21 ` [PATCH v2 3/9] iio: adc: qcom-vadc: move several adc5 functions to common file Dmitry Baryshkov
2020-09-06 14:18 ` Jonathan Cameron [this message]
2020-09-03 13:21 ` [PATCH v2 4/9] iio: adc: qcom-vadc-common: use fixp_linear_interpolate Dmitry Baryshkov
2020-09-03 19:38 ` Andy Shevchenko
2020-09-06 14:23 ` Jonathan Cameron
2020-09-03 13:21 ` [PATCH v2 5/9] iio: adc: qcom-spmi-adc5: fix driver name Dmitry Baryshkov
2020-09-04 11:14 ` Manivannan Sadhasivam
2020-09-06 14:24 ` Jonathan Cameron
2020-09-03 13:21 ` [PATCH v2 6/9] iio: adc: qcom-spmi-adc5: use of_device_get_match_data Dmitry Baryshkov
2020-09-04 11:12 ` Manivannan Sadhasivam
2020-09-03 13:21 ` [PATCH v2 7/9] thermal: qcom: add support for adc-tm5 PMIC thermal monitor Dmitry Baryshkov
2020-09-06 14:45 ` Jonathan Cameron
2020-09-03 13:21 ` [PATCH v2 8/9] arm64: dts: qcom: pm8150x: add definitions for adc-tm5 part Dmitry Baryshkov
2020-09-03 13:21 ` [PATCH v2 9/9] arm64: dts: sm8250-mtp: add thermal zones using pmic's adc-tm5 Dmitry Baryshkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200906151852.6c93e059@archlinux \
--to=jic23@kernel.org \
--cc=agross@kernel.org \
--cc=amitk@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).