From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Andy Gross <agross@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amit.kucheria@verdurent.com>,
Jonathan Cameron <jic23@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, devicetree@vger.kernel.org,
Vinod Koul <vkoul@kernel.org>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH 2/5] iio: adc: qcom-vadc: move several adc5 functions to common file
Date: Sun, 21 Jun 2020 12:43:43 -0700 [thread overview]
Message-ID: <20200621194343.GO128451@builder.lan> (raw)
In-Reply-To: <20200621193549.2070434-3-dmitry.baryshkov@linaro.org>
On Sun 21 Jun 12:35 PDT 2020, Dmitry Baryshkov wrote:
> ADC-TM5 driver will make use of several functions from ADC5 driver. Move
> them to qcom-vadc-common driver.
>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Regards,
Bjorn
> ---
> drivers/iio/adc/qcom-spmi-adc5.c | 73 +++---------------------------
> drivers/iio/adc/qcom-vadc-common.c | 69 +++++++++++++++++++++++++++-
> drivers/iio/adc/qcom-vadc-common.h | 12 ++++-
> 3 files changed, 85 insertions(+), 69 deletions(-)
>
> diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c
> index 21fdcde77883..10ca0bf77160 100644
> --- a/drivers/iio/adc/qcom-spmi-adc5.c
> +++ b/drivers/iio/adc/qcom-spmi-adc5.c
> @@ -143,18 +143,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);
> @@ -165,55 +153,6 @@ static int adc5_write(struct adc5_chip *adc, u16 offset, u8 *data, int len)
> return regmap_bulk_write(adc->regmap, adc->base + offset, data, len);
> }
>
> -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;
> @@ -396,7 +335,7 @@ static int adc5_read_raw(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)
> @@ -539,7 +478,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);
> @@ -552,7 +491,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]);
> @@ -580,10 +519,10 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
> /* Digital controller >= 5.3 have hw_settle_2 option */
> if (dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
> dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR)
> - ret = adc5_hw_settle_time_from_dt(value,
> + ret = qcom_adc5_hw_settle_time_from_dt(value,
> data->hw_settle_2);
> else
> - ret = adc5_hw_settle_time_from_dt(value,
> + ret = qcom_adc5_hw_settle_time_from_dt(value,
> data->hw_settle_1);
>
> if (ret < 0) {
> @@ -598,7 +537,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 2bb78d1c4daa..ffa578ce76db 100644
> --- a/drivers/iio/adc/qcom-vadc-common.c
> +++ b/drivers/iio/adc/qcom-vadc-common.c
> @@ -89,6 +89,18 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
> { 46, 125000 },
> };
>
> +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,
> @@ -385,10 +397,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);
> @@ -400,6 +414,59 @@ 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 e074902a24cc..2c65ddc98696 100644
> --- a/drivers/iio/adc/qcom-vadc-common.h
> +++ b/drivers/iio/adc/qcom-vadc-common.h
> @@ -153,10 +153,20 @@ 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 */
> --
> 2.27.0
>
next prev parent reply other threads:[~2020-06-21 19:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 19:35 [PATCH 0/5] qcom: pm8150: add support for thermal monitoring Dmitry Baryshkov
2020-06-21 19:35 ` [PATCH 1/5] dt-bindings: thermal: qcom: add adc-thermal monitor bindings Dmitry Baryshkov
2020-06-29 21:57 ` Rob Herring
2020-06-21 19:35 ` [PATCH 2/5] iio: adc: qcom-vadc: move several adc5 functions to common file Dmitry Baryshkov
2020-06-21 19:43 ` Bjorn Andersson [this message]
2020-06-21 19:35 ` [PATCH 3/5] thermal: qcom: add support for adc-tm5 PMIC thermal monitor Dmitry Baryshkov
2020-06-22 5:39 ` Bjorn Andersson
2020-06-27 14:42 ` Jonathan Cameron
2020-06-21 19:35 ` [PATCH 4/5] arm64: dts: qcom: pm8150x: add definitions for adc-tm5 part Dmitry Baryshkov
2020-06-21 19:35 ` [PATCH 5/5] arm64: dts: sm8250-dts: add thermal zones using pmic's adc-tm5 Dmitry Baryshkov
2020-06-30 5:06 ` Amit Kucheria
2020-06-30 12:10 ` Dmitry Baryshkov
2020-07-01 6:05 ` Amit Kucheria
2020-07-01 10:56 ` 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=20200621194343.GO128451@builder.lan \
--to=bjorn.andersson@linaro.org \
--cc=agross@kernel.org \
--cc=amit.kucheria@verdurent.com \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=rui.zhang@intel.com \
--cc=vkoul@kernel.org \
/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).