AUXADC: Mediatek auxadc driver
Subsystems (2)
cover AUXADC: Mediatek auxadc driver
This series includes two patchs:
1.add support for case IIO_CHAN_INFO_RAW.
2.update case IIO_CHAN_INFO_PROCESSED: convert raw data to voltage.
Changes in patch v1:
1)fix typo covert to convert in patch 2/2 description.
Hui Liu (2):
iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case
iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED
drivers/iio/adc/mt6577_auxadc.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
--
2.18.0
PATCH 1/2 iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case
Add support IIO_CHAN_INFO_RAW case.
--- drivers/iio/adc/mt6577_auxadc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/iio/adc/mt6577_auxadc.c +15 -1
@@ -60,7 +60,8 @@ static const struct mtk_auxadc_compatible mt6765_compat = { .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = (idx), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \ }static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
@@ -181,6 +182,19 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev,struct mt6577_auxadc_device *adc_dev =iio_priv (indio_dev);switch (info) { +case IIO_CHAN_INFO_RAW : + *val =mt6577_auxadc_read (indio_dev, chan); +if (*val <0 ) { +dev_notice (indio_dev->dev.parent, +"failed to sample data on channel[%d]\n" , + chan->channel); +return *val; + } +if (adc_dev->dev_comp->sample_data_cali) + *val =mt_auxadc_get_cali_data (*val, true); + +return IIO_VAL_INT ; +case IIO_CHAN_INFO_PROCESSED : *val =mt6577_auxadc_read (indio_dev, chan);if (*val <0 ) {
Signature · 1 line
2.18.0
Re: [PATCH v1 1/2] iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case
Quoted 1 line · On Thu, 12 Aug 2021 13:48:43 +0800 Hui Liu <[email protected]> wrote:
Add support
IIO_CHAN_INFO_RAWcase.
Why?
We almost never support both RAW and PROCESSED as userspace should be fine to use either. There are a few reasons we've let drivers do this but I would like know why it matters to you and it definitely needs to be in the patch description.
Quoted 40 lines
Signed-off-by Hui Liu <[email protected]>--- drivers/iio/adc/mt6577_auxadc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/iio/adc/mt6577_auxadc.c +15
-1@@ -60,7 +60,8 @@ static const struct mtk_auxadc_compatible mt6765_compat = { .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = (idx), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \ }static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {@@ -181,6 +182,19 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev,struct mt6577_auxadc_device *adc_dev =iio_priv (indio_dev);switch (info) { +case IIO_CHAN_INFO_RAW : + *val =mt6577_auxadc_read (indio_dev, chan); +if (*val <0 ) { +dev_notice (indio_dev->dev.parent, +"failed to sample data on channel[%d]\n" , + chan->channel); +return *val; + } +if (adc_dev->dev_comp->sample_data_cali) + *val =mt_auxadc_get_cali_data (*val, true); + +return IIO_VAL_INT ; +case IIO_CHAN_INFO_PROCESSED : *val =mt6577_auxadc_read (indio_dev, chan);if (*val <0 ) {
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jonathan Cameron
maintainerRe: [PATCH v1 1/2] iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case
Quoted 13 lines · On Fri, 13 Aug 2021 11:46:24 +0800 hui.liu <[email protected]> wrote:
Quoted 12 lines · Jonathan Cameron
Quoted 1 line · On Thu, 12 Aug 2021 13:48:43 +0800 Hui Liu <[email protected]> wrote:
Add support
IIO_CHAN_INFO_RAWcase.Why?
We almost never support both RAW and PROCESSED as userspace should be fine to use either. There are a few reasons we've let drivers do this but I would like know why it matters to you and it definitely needs to be in the patch description.
Quoted 5 lines
Hi Jonathan,
1. To support ADC consumers' different types of requirement: some consumers want to call
iio_read_channel_rawto get raw data, the others useiio_read_channel_processedto get voltage.
Give an example of the consumer using the raw channel readback (without acess to any scaling information?)
Quoted 5 lines
2. In our origin driver, if consumer call
iio_read_channel_processed, read back value is raw data.Could we use SCALE instead of PROCESSED in patch for next version, or what's your suggestion?
That would unfortunately be a userspace ABI change. We can add interfaces but taking them away is normally a problem :(
Your reasons here are fine, subject to information on what consumer cares about having _RAW, please resend the patch with this information added to the description.
Thanks,
Jonathan
Quoted 52 lines
Thanks.
Quoted 49 lines
Quoted 47 lines
Signed-off-by Hui Liu <[email protected]>--- drivers/iio/adc/mt6577_auxadc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/iio/adc/mt6577_auxadc.c +15
-1@@ -60,7 +60,8 @@ static const struct mtk_auxadc_compatible mt6765_compat = { .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = (idx), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \ } static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {@@ -181,6 +182,19 @@ static int mt6577_auxadc_read_raw(structiio_dev *indio_dev, struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);switch (info) { +case IIO_CHAN_INFO_RAW : + *val =mt6577_auxadc_read (indio_dev, chan); +if (*val <0 ) { +dev_notice (indio_dev->dev.parent, + "failed to sample data on channel[%d]\n", + chan->channel); +return *val; + } +if (adc_dev->dev_comp->sample_data_cali) + *val =mt_auxadc_get_cali_data (*val, true); + +return IIO_VAL_INT ; +case IIO_CHAN_INFO_PROCESSED :drivers/iio/adc/mt6577_auxadc.c +0
-0*val =mt6577_auxadc_read (indio_dev, chan);if (*val <0 ) {
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jonathan Cameron
maintainerRe: [PATCH v1 1/2] iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case
Quoted 52 lines · On Tue, 17 Aug 2021 16:37:52 +0800 hui.liu <[email protected]> wrote:
Quoted 51 lines · Jonathan Cameron
Quoted 16 lines · On Fri, 13 Aug 2021 11:46:24 +0800 hui.liu <[email protected]> wrote:
Quoted 5 lines · Jonathan Cameron
Quoted 1 line · On Thu, 12 Aug 2021 13:48:43 +0800 Hui Liu <[email protected]> wrote:
Add support
IIO_CHAN_INFO_RAWcase.Quoted 9 lines
Why?
We almost never support both RAW and PROCESSED as userspace should be
fine to use either. There are a few reasons we've let drivers do this but I would like know why it matters to you and it definitely
needs to be in the patch description.Quoted 6 lines
Hi Jonathan,
1. To support ADC consumers' different types of requirement: some consumers want to call
iio_read_channel_rawto get raw data, the others
useiio_read_channel_processedto get voltage.Give an example of the consumer using the raw channel readback (without
acess to any scaling information?)Quoted 7 lines
2. In our origin driver, if consumer call
iio_read_channel_processed,
read back value is raw data.Could we use SCALE instead of PROCESSED in patch for next version, or
what's your suggestion?That would unfortunately be a userspace ABI change. We can add interfaces
but taking them away is normally a problem :(Your reasons here are fine, subject to information on what consumer cares
about having_RAW, please resend the patch with this information added
to the description.Thanks,
Quoted 7 lines
Quoted 1 line
Jonathan
1. We found
afe/iio-rescale.c,dac/dpot-dac.candmultiplexer/iio-mux.ccalliio_read_channel_rawto get raw data. If they use our ADC driver, I think we should support_RAWcase.
If we support_RAWcase, we will add more information in v2 description.
iio-rescale has recently gained support for processed.
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/drivers/iio/afe/iio-rescale.c?h=testing&id=53ebee9499805add3eef630d998c40812e6a1c39
dpot-dac is a rather obscure special case, so I doubt you actually have one of those. If iio-mux is relevant then we should add processed support to that driver as well.
I would rather see those users of the interface fixed than us having to tweak lots of drivers to provide _raw when it isn't appropriate for that piece of hardware.
Jonathan
Quoted 67 lines
2. Since we change
_PROCESSEDreadback value from raw data to voltage, our consumer will make the changes synchronously.Quoted 63 lines
Quoted 61 lines
Thanks.
Quoted 58 lines
Quoted 56 lines
Signed-off-by Hui Liu <[email protected]>--- drivers/iio/adc/mt6577_auxadc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/iio/adc/mt6577_auxadc.c +0
-1@@ -60,7 +60,8 @@ static const struct mtk_auxadc_compatible mt6765_compat = { .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = (idx), \ - .info_mask_separate =
BIT(IIO_CHAN_INFO_PROCESSED), \drivers/iio/adc/mt6577_auxadc.c +2
-0+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \
}static const struct
iio_chan_specmt6577_auxadc_iio_channels[]
= {drivers/iio/adc/mt6577_auxadc.c +10
-0@@ -181,6 +182,19 @@ static int mt6577_auxadc_read_raw(structiio_dev *indio_dev, struct mt6577_auxadc_device *adc_dev =iio_priv (indio_dev);switch (info) { +case IIO_CHAN_INFO_RAW : + *val =mt6577_auxadc_read (indio_dev, chan); +if (*val <0 ) { +dev_notice (indio_dev->dev.parent, + "failed to sample data on channel[%d]\n", + chan->channel); +return *val; + } +if (adc_dev->dev_comp->sample_data_cali) + *val = mt_auxadc_get_cali_data(*val,true);
drivers/iio/adc/mt6577_auxadc.c +3
-0+ +return IIO_VAL_INT ; +case IIO_CHAN_INFO_PROCESSED : *val =mt6577_auxadc_read (indio_dev, chan);if (*val <0 ) {
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): SI2PR03MB56901E5D00D47948BE0E9F989BC69@SI2PR03MB5690.apcprd03.prod.outlook.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jonathan Cameron
maintainerRe: [PATCH v1 1/2] iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case
Quoted 4 lines · On Thu, 26 Aug 2021 10:27:34 +0800 hui.liu <[email protected]> wrote:
Hi Jonathan,
Our internal Kernel module CCCI use
_RAWcase, we described in the previous mail. Could you give your suggestion?
Fix your internal module? I would have assumed it would want calibrated values if available, so it seems a little odd to use _RAW. If there is a good reason for it doing so that you can talk about here then perhaps we can consider it.
As a general rule we don't put any significant effort into supporting out of tree drivers so I'm not very keen on adding _RAW on the basis one uses it.
Jonathan
Quoted 68 lines
Thanks.
HuiQuoted 64 lines · Jonathan Cameron
Quoted 62 lines
Quoted 58 lines · On Tue, 17 Aug 2021 16:37:52 +0800 hui.liu <[email protected]> wrote:
Quoted 42 lines · Jonathan Cameron
Quoted 17 lines · On Fri, 13 Aug 2021 11:46:24 +0800 hui.liu < [email protected]> wrote:
Quoted 7 lines · Jonathan Cameron
Quoted 1 line · On Thu, 12 Aug 2021 13:48:43 +0800 Hui Liu <[email protected]> wrote:
Add support
IIO_CHAN_INFO_RAWcase.Why?
Quoted 8 lines
We almost never support both RAW and PROCESSED as userspace
should be fine to use either. There are a few reasons we've
let drivers do this but I would like know why it matters to
you and it definitely needs to be in the patch description.Quoted 7 lines
Hi Jonathan,
1. To support ADC consumers' different types of requirement:
some
consumers want to calliio_read_channel_rawto get raw data, the
others useiio_read_channel_processedto get voltage.Give an example of the consumer using the raw channel readback (without acess to any scaling information?)
Quoted 5 lines
2. In our origin driver, if consumer call
iio_read_channel_processed, read back value is raw data.Could we use SCALE instead of PROCESSED in patch for next version, or what's your suggestion?
That would unfortunately be a userspace ABI change. We can add
interfaces but taking them away is normally a problem :(Quoted 7 lines
Your reasons here are fine, subject to information on what consumer cares about having
_RAW, please resend the patch with this information added to the description.Thanks,
Jonathan
1. We found
afe/iio-rescale.c,dac/dpot-dac.cand multiplexer/iio-mux.ccalliio_read_channel_rawto get raw data. If they use our ADC
driver, I think we should support_RAWcase.
If we support_RAWcase, we will add more information in v2 description.
Quoted 102 lines
Quoted 4 lines
Quoted 2 lines
iio-rescale has recently gained support for processed.
Quoted 97 lines
Quoted 6 lines
dpot-dac is a rather obscure special case, so I doubt you actually have one of those.
If iio-mux is relevant then we should add processed support to that
driver as well.Quoted 8 lines
I would rather see those users of the interface fixed than us having
to tweak lots of drivers to provide_rawwhen it isn't appropriate for
that piece of hardware.Jonathan
Hi Jonathan,
For we have an internal use scenario:
Our internal Kernel module CCCI(Communication interface between AP Core and Modem) would like get raw data from ADC, but CCCI driver have not do upstream now.If we no need add
_RAW, we will only change_PROCESSEDreadback value in the next version of patch.Quoted 70 lines
Quoted 68 lines
2. Since we change
_PROCESSEDreadback value from raw data to voltage, our consumer will make the changes synchronously.Quoted 64 lines
Quoted 62 lines
Thanks.
Quoted 59 lines
Quoted 57 lines
Signed-off-by Hui Liu <[email protected]>--- drivers/iio/adc/mt6577_auxadc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/iio/adc/mt6577_auxadc.cindex79c1dd68b909..e995d43287b2100644drivers/iio/adc/mt6577_auxadc.c +0
-0@@ -60,7 +60,8 @@ static const struct
mtk_auxadc_compatiblemt6765_compat= {drivers/iio/adc/mt6577_auxadc.c +0
-1.type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = (idx), \ - .info_mask_separate =
BIT(IIO_CHAN_INFO_PROCESSED), \drivers/iio/adc/mt6577_auxadc.c +2
-0+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \
}static const struct
iio_chan_spec
mt6577_auxadc_iio_channels[] = { @@ -181,6 +182,19 @@ static
int mt6577_auxadc_read_raw(structiio_dev*indio_dev,
structmt6577_auxadc_device*adc_dev=iio_priv(indio_dev);drivers/iio/adc/mt6577_auxadc.c +5
-0switch (info) { +case IIO_CHAN_INFO_RAW : + *val =mt6577_auxadc_read (indio_dev, chan); +if (*val <0 ) { + dev_notice(indio_dev->dev.parent, + "failed to sample data onchannel[%d]\n",
drivers/iio/adc/mt6577_auxadc.c +5
-0+ chan->channel); +return *val; + } +if (adc_dev->dev_comp->sample_data_cali) + *val = mt_auxadc_get_cali_data(*val,true);
drivers/iio/adc/mt6577_auxadc.c +3
-0+ +return IIO_VAL_INT ; +case IIO_CHAN_INFO_PROCESSED : *val =mt6577_auxadc_read (indio_dev, chan);if (*val <0 ) {
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
PATCH 2/2 iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED
In reply to Hui LiuConvert raw data to processed data.
--- drivers/iio/adc/mt6577_auxadc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/adc/mt6577_auxadc.c +8 -0
@@ -83,6 +83,10 @@ static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = { MT6577_AUXADC_CHANNEL(15), }; +/* For Voltage calculation */ +#define VOLTAGE_FULL_RANGE 1500/* VA voltage */ +#define AUXADC_PRECISE 4096/* 12 bits */ +static int mt_auxadc_get_cali_data (int rawdata,bool enable_cali) {return rawdata;
@@ -205,6 +209,10 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev, }if (adc_dev->dev_comp->sample_data_cali) *val =mt_auxadc_get_cali_data (*val, true); + +/* Convert adc raw data to voltage: 0 - 1500 mV */ + *val = *val *VOLTAGE_FULL_RANGE /AUXADC_PRECISE ; +return IIO_VAL_INT ;default :
Signature · 1 line
2.18.0