Message ID | cover.1738328714.git.mazziesaccount@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | Support ROHM BD79124 ADC/GPO | expand |
On Fri, 31 Jan 2025 15:34:43 +0200 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > Support ROHM BD79124 ADC. > > Quite usual stuff. 12-bit, 8-channel ADC with threshold monitoring. > > Except that: > - each ADC input pin can be configured as a general purpose output. > - manually starting an ADC conversion and reading the result would > require the I2C _master_ to do clock stretching(!) for the duration > of the conversion... Let's just say this is not well supported. > - IC supports 'autonomous measurement mode' and storing latest results > to the result registers. This mode is used by the driver due to the > "peculiar" I2C when doing manual reads. > > I sent this as an RFC because I implemented the pin purposing (GPO/ADC) > using pinmux - which I've never done for upstream stuff before. Hence > it's better to ask if this makes sense, or if there is better way to go. > Anyways, resulted drivers spread to 3 subsystems (MFD, pinctrl and IIO) In principle nothing against pin mux for this. There are other options though if pin mux ends up being too complex. - provide ADC channels in the binding channel@x etc. Anything else is freely available as a GPIO. Normal GPIO bindings etc for those. The channel bit is common on SoC ADC anyway where we don't want to expose channels that aren't wired out. For combined ADC GPIO chips we normally don't bother with an MFD. Just host the gpio driver in the ADC one unless there is a strong reasons someone will put this down for GPIO usage only. > > Furthermore, the GPO functionality has not been (properly) tested. I'll > do more testing for v2 if this pinmux approach is appropriate. > > Furthermore, because the ADC uses this continuous autonomous measuring, > and because the IC keeps producing new 'out of window' IRQs if > measurements are out of window - the driver disables the event when > sending one. This prevents generating storm of events, but it also > requires users to reconfigure / re-enable an event if they wish to > continue monitoring after receiving one. Again I am not sure if this is > the best way to handle such HW - so better to ask for an opinion than a > nose bleed, right? Maybe the next version will no longer be a RFC :) Oddly I thought we had ABI for this but not finding it. We basically want a thing that lets us say don't allow a repeat event for X seconds. Then we set a timer and reenable the interrupt after that time. I think there are drivers doing this but can't find one right now :( It's close to _timeout used for gesture detection. > > --- > > Matti Vaittinen (5): > dt-bindings: ROHM BD79124 ADC/GPO > mfd: Add ROHM BD79124 ADC/GPO > iio: adc: Support ROHM BD79124 ADC > pinctrl: Support ROHM BD79124 pinmux / GPO > MAINTAINERS: Add ROHM BD79124 ADC/GPO > > .../devicetree/bindings/mfd/rohm,bd79124.yaml | 111 +++ > MAINTAINERS | 8 + > drivers/iio/adc/Kconfig | 10 + > drivers/iio/adc/Makefile | 1 + > drivers/iio/adc/rohm-bd79124-adc.c | 890 ++++++++++++++++++ > drivers/mfd/Kconfig | 12 + > drivers/mfd/Makefile | 1 + > drivers/mfd/rohm-bd79124.c | 165 ++++ > drivers/pinctrl/Kconfig | 11 + > drivers/pinctrl/Makefile | 1 + > drivers/pinctrl/pinctrl-bd79124.c | 276 ++++++ > include/linux/mfd/rohm-bd79124.h | 32 + > 12 files changed, 1518 insertions(+) > create mode 100644 Documentation/devicetree/bindings/mfd/rohm,bd79124.yaml > create mode 100644 drivers/iio/adc/rohm-bd79124-adc.c > create mode 100644 drivers/mfd/rohm-bd79124.c > create mode 100644 drivers/pinctrl/pinctrl-bd79124.c > create mode 100644 include/linux/mfd/rohm-bd79124.h > > > base-commit: 5bc55a333a2f7316b58edc7573e8e893f7acb532
Hi Jonathan, Thanks a ton for the help! :) On 31/01/2025 19:08, Jonathan Cameron wrote: > On Fri, 31 Jan 2025 15:34:43 +0200 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> Support ROHM BD79124 ADC. >> >> Quite usual stuff. 12-bit, 8-channel ADC with threshold monitoring. >> >> Except that: >> - each ADC input pin can be configured as a general purpose output. >> - manually starting an ADC conversion and reading the result would >> require the I2C _master_ to do clock stretching(!) for the duration >> of the conversion... Let's just say this is not well supported. >> - IC supports 'autonomous measurement mode' and storing latest results >> to the result registers. This mode is used by the driver due to the >> "peculiar" I2C when doing manual reads. >> >> I sent this as an RFC because I implemented the pin purposing (GPO/ADC) >> using pinmux - which I've never done for upstream stuff before. Hence >> it's better to ask if this makes sense, or if there is better way to go. >> Anyways, resulted drivers spread to 3 subsystems (MFD, pinctrl and IIO) > In principle nothing against pin mux for this. > There are other options though if pin mux ends up being too complex. > > - provide ADC channels in the binding channel@x etc. > Anything else is freely available as a GPIO. > Normal GPIO bindings etc for those. > > The channel bit is common on SoC ADC anyway where we don't want to > expose channels that aren't wired out. Thanks for the insight on how things are usually done :) I think the only reason for having all the channels visible in IIO, could be, if there was a need to provide a runtime configuration. > For combined ADC GPIO chips we normally don't bother with an MFD. > Just host the gpio driver in the ADC one unless there is a strong > reasons someone will put this down for GPIO usage only. I don't really know about that. I don't like arguing, yet I seem to do that all the time XD I personally like using MFD and having smaller drivers in relevant subsystems, because it tends to keep the drivers leaner - and allows re-use of drivers when some of the hardware blocks are re-used. In some cases this results (much) cleaner drivers. (Let's assume they did "new" ADC, and just dropped the GPO from it. With the MFD the deal is to add new compatible, and have an MFD cell array without the pinctrl/GPO matching this new device. And lets imagine they later add this ADC to a PMIC. We add yet another MFD cell array for this new device, with a cell for the regulators, power-supply and the ADC... The same platform subdevice can be re-used to drive ADC (well, with added register offsets)). Allright. I believe you have more experience on this area than I do, but I definitely think MFD has it's merits also for ADCs - they do tend to put ADCs to all kinds of devices (like in PMICs after all, although maybe not with 8 channels and less often without an accumulator). >> Furthermore, the GPO functionality has not been (properly) tested. I'll >> do more testing for v2 if this pinmux approach is appropriate. I took a better look at the pinctrl docs while listening the FOSDEM talks :) (Which inevitably means I missed a few things from some of the presentations, and also didn't really properly understand what I was reading. "Multipasking..." like some rude Finns might say.) Anyways, I think the pinctrl should have some out-of-the-box support for use-cases where pin(s) can be used for GPIO, and for an another function. (I think, I saw functions which take care of the pins having right state for GPIO use). I don't think I properly used those features. >> Furthermore, because the ADC uses this continuous autonomous measuring, >> and because the IC keeps producing new 'out of window' IRQs if >> measurements are out of window - the driver disables the event when >> sending one. This prevents generating storm of events, but it also >> requires users to reconfigure / re-enable an event if they wish to >> continue monitoring after receiving one. Again I am not sure if this is >> the best way to handle such HW - so better to ask for an opinion than a >> nose bleed, right? Maybe the next version will no longer be a RFC :) > > Oddly I thought we had ABI for this but not finding it. > We basically want a thing that lets us say don't allow a repeat event > for X seconds. Then we set a timer and reenable the interrupt after that > time. I think there are drivers doing this but can't find one right > now :( It's close to _timeout used for gesture detection. So, a good old timer for doing unmasking. I think this makes sense if the existing users of ADCs aren't prepared for the events to get disabled by driver. Thanks! I'll follow this suggestion :) Yours, -- Matti
On Sat, 1 Feb 2025 17:00:51 +0200 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > Hi Jonathan, > > Thanks a ton for the help! :) > > On 31/01/2025 19:08, Jonathan Cameron wrote: > > On Fri, 31 Jan 2025 15:34:43 +0200 > > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > > > >> Support ROHM BD79124 ADC. > >> > >> Quite usual stuff. 12-bit, 8-channel ADC with threshold monitoring. > >> > >> Except that: > >> - each ADC input pin can be configured as a general purpose output. > >> - manually starting an ADC conversion and reading the result would > >> require the I2C _master_ to do clock stretching(!) for the duration > >> of the conversion... Let's just say this is not well supported. > >> - IC supports 'autonomous measurement mode' and storing latest results > >> to the result registers. This mode is used by the driver due to the > >> "peculiar" I2C when doing manual reads. > >> > >> I sent this as an RFC because I implemented the pin purposing (GPO/ADC) > >> using pinmux - which I've never done for upstream stuff before. Hence > >> it's better to ask if this makes sense, or if there is better way to go. > >> Anyways, resulted drivers spread to 3 subsystems (MFD, pinctrl and IIO) > > In principle nothing against pin mux for this. > > There are other options though if pin mux ends up being too complex. > > > > - provide ADC channels in the binding channel@x etc. > > Anything else is freely available as a GPIO. > > Normal GPIO bindings etc for those. > > > > The channel bit is common on SoC ADC anyway where we don't want to > > expose channels that aren't wired out. > > Thanks for the insight on how things are usually done :) > > I think the only reason for having all the channels visible in IIO, > could be, if there was a need to provide a runtime configuration. > > > For combined ADC GPIO chips we normally don't bother with an MFD. > > Just host the gpio driver in the ADC one unless there is a strong > > reasons someone will put this down for GPIO usage only. > > I don't really know about that. I don't like arguing, yet I seem to do > that all the time XD > > I personally like using MFD and having smaller drivers in relevant > subsystems, because it tends to keep the drivers leaner - and allows > re-use of drivers when some of the hardware blocks are re-used. In some > cases this results (much) cleaner drivers. I'm fully in agreement with MFD being useful, but for very simple parts of a device it can be overkill. > > (Let's assume they did "new" ADC, and just dropped the GPO from it. With > the MFD the deal is to add new compatible, and have an MFD cell array > without the pinctrl/GPO matching this new device. And lets imagine they > later add this ADC to a PMIC. We add yet another MFD cell array for this > new device, with a cell for the regulators, power-supply and the ADC... > The same platform subdevice can be re-used to drive ADC (well, with > added register offsets)). > > Allright. I believe you have more experience on this area than I do, but > I definitely think MFD has it's merits also for ADCs - they do tend to > put ADCs to all kinds of devices (like in PMICs after all, although > maybe not with 8 channels and less often without an accumulator). It's a trade off. Sometimes we just have a little code duplication to the need for a more complex design. Enjoy the rest of Fosdem Jonathan
On 01/02/2025 18:30, Jonathan Cameron wrote: > > Enjoy the rest of Fosdem Thanks! Just watching the live streams though :( Yours, -- Matti