iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
Subsystems (2)
PATCH v4 3/3 iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
The Qualcomm PM8xxx PMICs contain a simpler ADC than its successors (already in the kernel as qcom-spmi-adc.c):
the HK/XO ADC (Housekeeping/Chrystal oscillator ADC).
As far as I can understand this is equal to the PMICs using SSBI transport and encompass PM8018, PM8038, PM8058, and PM8921, so this is shortly named PM8xxx.
This ADC monitors a bunch of on-board voltages and the die temperature of the PMIC itself, but it can also be routed to convert a few external MPPs (multi-purpose pins). On the APQ8060 DragonBoard this feature is used to let this ADC convert an analog ALS (Ambient Light Sensor) voltage signal from a Capella CM3605 ALS into a LUX value.
Developed and tested with APQ8060 DragonBoard based on Ivan's driver and Rama Krishna's patches. The SPMI VADC driver is quite different, but share enough minor functionality that I have split out to the common file in a previous patch.
---
ChangeLog v3->v4:
- Only reposting this patch as the DT bindings and refactorings are merged.
- Prefix all channel names with PM8XXX_* to avoid namespace clashes.
- Use the compatible string to name the IIO device for greater model precision.
- Fix up a few excess newlines.
ChangeLog v2->v3:
- Rebase using Rama Krishna's improvements, set up defaults for scaling function and prescaler for each channel, per ASIC variant.
- Also set up RSV per-variant as the vendor tree does this and it seems necessary to set RSV0 on the muxoff channel to get readings from the XO thermistor.
- Encode default IIO type in the default per-PMIC channel table.
- Fixed a bug in ratiometric calibration (needed to force ratiometric mode).
- Dropped PM8917: that doesn't have any XOADC.
- Added a special flag for the PM8058: it apparently needs special RSV muxing due to being necessarily different.
- Augmented to handle altered ratiometric DT property.
- Do not hardcode that the reference voltage must be 2.2V, just fetch and enable the regulator. Different PMICs use different reference voltages.
ChangeLog v1->v2:
- Introduce a mutex to avoid different clients stepping on each others' toes
- Add an of_xlate function to be sure to match the right ADC
- Add all compatible strings, not just PM8058
--- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/qcom-pm8xxx-xoadc.c | 930 ++++++++++++++++++++++++++++++++++++ 3 files changed, 941 insertions(+) create mode 100644 drivers/iio/adc/qcom-pm8xxx-xoadc.c
drivers/iio/adc/Kconfig +10 -0
@@ -421,6 +421,16 @@ config PALMAS_GPADC is used in smartphones and tablets and supports a 16 channel general purpose ADC. +config QCOM_PM8XXX_XOADC + tristate "Qualcomm SSBI PM8xxx PMIC XOADCs" + depends on MFD_PM8XXX + help + ADC driver for the XOADC portions of the Qualcomm PM8xxx PMICs + using SSBI transport: PM8018, PM8038, PM8058, PM8921. + + To compile this driver as a module, choose M here: the module + will be called qcom-pm8xxx-xoadc. + config QCOM_SPMI_IADC tristate "Qualcomm SPMI PMIC current ADC" depends on SPMI
drivers/iio/adc/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o qcom-vadc-y := qcom-vadc-common.o obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-vadc.o qcom-spmi-vadc.o +obj-$(CONFIG_QCOM_PM8XXX_XOADC) += qcom-vadc.o qcom-pm8xxx-xoadc.o obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o obj-$(CONFIG_STX104) += stx104.o obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o
drivers/iio/adc/qcom-pm8xxx-xoadc.c new file +930 -0
930 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v4 3/3 iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
Quoted 1 line · Linus Walleij
ChangeLog
v3->v4:
Oh and I didn't remove the dev_info() where the driver brags about being present.
I usually like to have those positive affirmations from my drivers so I know they are there. Otherwise I can't tell the state when I for some reason forgot to compile it in because of some Kconfig issue from the state where it is silently present. This is especially helpful in mailed bug reports where people post dmesg logs. Then I can see "aha at least it probed".
It's not super-important, feel free to edit it out when applying if you totally hate it, I won't hold it against you :)
Yours,
Linus Walleij
Jonathan Cameron
maintainerPATCH v4 3/3 iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
Quoted 15 lines · Linus Walleij
Quoted 1 line · Linus Walleij
ChangeLog
v3->v4:Oh and I didn't remove the
dev_info()where the driver brags about being present.I usually like to have those positive affirmations from my drivers so I know they are there. Otherwise I can't tell the state when I for some reason forgot to compile it in because of some
Kconfigissue from the state where it is silently present. This is especially helpful in mailed bug reports where people post dmesg logs. Then I can see "aha at least it probed".
Quoted 2 lines
It's not super-important, feel free to edit it out when applying if you totally hate it, I won't hold it against you :)
Meh. I'm not that fussed ;)
Anyhow I clearly did something crazy last night as the first two patches had disappeared from my local tree anyway, so I've tried again and now hopefully all is in order.
Applied this one as well with a spot of fuzz but all obvious stuff in the Makefile.
However...
ERROR: "qcom_vadc_decimation_from_dt" [drivers/iio/adc/qcom-spmi-vadc.ko] undefined!
ERROR: "qcom_vadc_scale" [drivers/iio/adc/qcom-spmi-vadc.ko] undefined! make[1]: *** [scripts/Makefile.modpost:91: __modpost] Error 1
make: *** [Makefile:1198: modules] Error 2
I've fixed that up and some static declaration issue.
Please do sanity check builds as modules! It all needs to be one one object file when added to the $(magic)-m
However, I can't see any way of keeping them module name as was (qcom-smpi-vadc.ko) without renaming one of the c files out of the way. Please check I haven't messed anything up. The new naming is a bit naff, but I couldn't think of anything better off the top of my head!
Actually this is enough of a mess I'm pulling these last two patches for now. Will push them out in a special testing2 branch for you to take a look at though.
I also temporarily changed the mfd dependencies to add COMPILE_TEST. Seems fine, so if you could do a patch adding that we'll get better build coverage.
Jonathan
Quoted 8 lines
Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 3/3 iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
Quoted 10 lines · Jonathan Cameron
Applied this one as well with a spot of fuzz but all obvious stuff in the
Makefile.However...
ERROR: "
qcom_vadc_decimation_from_dt" [drivers/iio/adc/qcom-spmi-vadc.ko] undefined!
ERROR: "qcom_vadc_scale" [drivers/iio/adc/qcom-spmi-vadc.ko] undefined! make[1]: *** [scripts/Makefile.modpost:91:__modpost] Error 1
make: *** [Makefile:1198: modules] Error 2
Quoted 4 lines
I've fixed that up and some static declaration issue.
Please do sanity check builds as modules! It all needs to be one one object file when added to the $(magic)-m
Sorry :(
I guess I should really get better at that. I guess the sloppiness comes from never using modules for anything on any system in the first place.
I did push a branch to my kernelorg git linux-integrator.git so I was expecting the zerodaybuild to pick it up and build it and find these things but apparently I doesn't. Mea culpa, need to check with Fenguang about this.
Quoted 4 lines
However, I can't see any way of keeping them module name as was (qcom-smpi-vadc.ko) without renaming one of the c files out of the way. Please check I haven't messed anything up. The new naming is a bit naff, but I couldn't think of anything better off the top of my head!
It looks all right to me, there is a dangling space after +obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o otherwise it looks fine.
Quoted 2 lines
Actually this is enough of a mess I'm pulling these last two patches for now. Will push them out in a special testing2 branch for you to take a look at though.
By all means save it for whenever later or just tell me to resend after v4.11-rc1. I have all time in the world.
Anyways, I cherry-picked a commit needed for a boot regression and added a hacky DT patch and built and booted this!
The dmesg detects the device fine with nice calibration results, lsiio reports it and the readings from the voltage ADCs work just fine.
Quoted 2 lines
I also temporarily changed the mfd dependencies to add
COMPILE_TEST. Seems fine, so if you could do a patch adding that we'll get better build coverage.
I added || COMPILE_TEST to MFD_PM8XXX
Then I get the following with x86_64 allyesconfig:
LD drivers/iio/adc/built-in.odrivers/iio/adc/qcom-pm8xxx-xoadc.o: In function `qcom_vadc_decimation_from_dt':
(.text+0x410): multiple definition of qcom_vadc_decimation_from_dt' drivers/iio/adc/qcom-spmi-vadc.o:(.text+0x410): first defined here drivers/iio/adc/qcom-pm8xxx-xoadc.o: In function qcom_vadc_scale':
(.text+0x0): multiple definition of `qcom_vadc_scale' drivers/iio/adc/qcom-spmi-vadc.o:(.text+0x0): first defined here ../scripts/Makefile.build:446: recipe for target 'drivers/iio/adc/built-in.o' failed
make[5]: *** [drivers/iio/adc/built-in.o] Error 1 ../scripts/Makefile.build:551: recipe for target 'drivers/iio/adc' failed make[4]: *** [drivers/iio/adc] Error 2 ../scripts/Makefile.build:551: recipe for target 'drivers/iio' failed
I looked at how you handle it in the Makefile, and it all makes sense to me unfortunately, it's just this thing with baking several objects into one module - it seems the Kbuild around that is easy to get wrong and simply hard :(
I first naturally put all the common code into its own module and export the symbols, simple. It just works, but that's just sooo.... ugly. So the elegant solutions are hard to get right.
I can't figure it out right now, will get back to it after dinner or so.
Yours,
Linus Walleij
PATCH v4 3/3 iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
Quoted 92 lines · Linus Walleij
Quoted 1 line · Jonathan Cameron
Applied this one as well with a spot of fuzz but all obvious stuff in
the
Quoted 5 lines
Makefile.However...
ERROR: "
qcom_vadc_decimation_from_dt"[
drivers/iio/adc/qcom-spmi-vadc.ko] undefined!Quoted 1 line
ERROR: "
qcom_vadc_scale" [drivers/iio/adc/qcom-spmi-vadc.ko]undefined!
Quoted 6 lines
make[1]: *** [
scripts/Makefile.modpost:91:__modpost] Error 1
make: *** [Makefile:1198: modules] Error 2I've fixed that up and some static declaration issue.
Please do sanity check builds as modules! It all needs to be one one
object file
Quoted 1 line
when added to the $(magic)-m
Sorry :(
I guess I should really get better at that. I guess the sloppiness comes
from never using modules for anything on any system in the first place.I did push a branch to my kernelorg git linux-integrator.git so I was expecting the zerodaybuild to pick it up and build it and find these things
but apparently I doesn't. Mea culpa, need to check with Fenguang about this.Quoted 1 line
However, I can't see any way of keeping them module name as was
(qcom-smpi-vadc.ko)
Quoted 1 line
without renaming one of the c files out of the way. Please check I
haven't messed
Quoted 1 line
anything up. The new naming is a bit naff, but I couldn't think of
anything better
Quoted 1 line
off the top of my head!
It looks all right to me, there is a dangling space after +obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o otherwise it looks fine.
Quoted 1 line
Actually this is enough of a mess I'm pulling these last two patches
for now.
Quoted 1 line
Will push them out in a special testing2 branch for you to take a
look at though.
By all means save it for whenever later or just tell me to resend after v4.11-rc1. I have all time in the world.
Anyways, I cherry-picked a commit needed for a boot regression and added a hacky DT patch and built and booted this!
The dmesg detects the device fine with nice calibration results, lsiio reports it and the readings from the voltage ADCs work just fine.
Quoted 2 lines
I also temporarily changed the mfd dependencies to add
COMPILE_TEST. Seems fine, so if you could do a patch adding that we'll get betterbuild coverage.
I added ||
COMPILE_TESTtoMFD_PM8XXXThen I get the following with
x86_64allyesconfig:LD
drivers/iio/adc/built-in.odrivers/iio/adc/qcom-pm8xxx-xoadc.o: In function `qcom_vadc_decimation_from_dt':
(.text+0x410): multiple definition ofqcom_vadc_decimation_from_dt' drivers/iio/adc/qcom-spmi-vadc.o:(.text+0x410): first defined here drivers/iio/adc/qcom-pm8xxx-xoadc.o: In functionqcom_vadc_scale':
(.text+0x0): multiple definition of `qcom_vadc_scale' drivers/iio/adc/qcom-spmi-vadc.o:(.text+0x0): first defined here ../scripts/Makefile.build:446: recipe for target 'drivers/iio/adc/built-in.o' failed
make[5]: *** [drivers/iio/adc/built-in.o] Error 1 ../scripts/Makefile.build:551: recipe for target 'drivers/iio/adc' failed
make[4]: *** [drivers/iio/adc] Error 2 ../scripts/Makefile.build:551: recipe for target 'drivers/iio' failedI looked at how you handle it in the
Makefile, and it all makes sense to
me unfortunately, it's just this thing with baking several objects into one
module - it seems theKbuildaround that is easy to get wrong and simply hard :(
Quoted 8 lines
I first naturally put all the common code into its own module and export
the symbols, simple. It just works, but that's just sooo.... ugly. So the
elegant solutions are hard to get right.I can't figure it out right now, will get back to it after dinner or so.
Drat shows I never build other than modules :)
Will probably have to be a helper module.
J
Quoted 3 lines
Yours,
Linus Walleij
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
PATCH v4 3/3 iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC
Quoted 3 lines · Jonathan Cameron
Quoted 1 line · Linus Walleij
Then I get the following with
x86_64allyesconfig:
(...)
Quoted 2 lines
Drat shows I never build other than modules :)
Will probably have to be a helper module.
Hahah yeah I guess we resort to that if I can't figure this out, what a mess. I'm trying my best to figure something out that works with both allyesconfig and allmodconfig and when I find it I will use the pattern everywhere for the rest of my life.
Yours,
Linus Walleij