Re: Supporting a Device with Switchable Current/Voltage Measurement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2 May 2024 16:05:45 +0200
Peter Rosin <peda@xxxxxxxxxx> wrote:

> 2024-05-02 at 15:49, Peter Rosin wrote:
> > Since you appear to need to change both the gpio pin and the io-channel, the
> > mux isn't a perfect fit. The closest you can get with the current code is to
> > create a gpio mux, I think. You would then use that mux twice to fan out both
> > io-channels, but only expose the "left leg" on the first fan-out and only the
> > "right leg" on the other. Something like this (untested, probably riddled with
> > errors, use salt etc etc):
> > 
> > rcs: raw-current-sense {
> > 	compatible = "current-sense-shunt";
> > 	io-channels = <&adc 0>;
> > 	io-channel-name = "raw-current";
> > 	#io-channel-cells = <1>;
> > 
> > 	shunt-resistor-micro-ohms = <3300000>;
> > };
> > 
> > rvs: raw-voltage-sense {
> > 	compatible = "voltage-divider";
> > 	io-channels = <&adc 1>;
> > 	io-channel-name = "raw-voltage";
> > 	#io-channel-cells = <1>;
> > 
> > 	output-ohms = <22>;
> > 	full-ohms = <222>;
> > };
> > 
> > mux: gpio-mux {
> > 	compatible = "gpio-mux";
> > 	#mux-control-cells = <0>;
> > 
> > 	gpios-mux = <&main_gpio0 29 GPIO_ACTIVE_HIGH>;
> > };
> > 
> > current-sense {
> > 	compatible = "io-channel-mux";
> > 	io-channels = <&rcs 0>;
> > 	io-channel-names = "parent";
> > 
> > 	mux-controls = <&mux>;
> > 
> > 	channels = "current", "";
> > };
> > 
> > voltage-sense {
> > 	compatible = "io-channel-mux";
> > 	io-channels = <&rvs 0>;
> > 	io-channel-names = "parent";
> > 
> > 	mux-controls = <&mux>;
> > 
> > 	channels = "", "voltage";
> > };
> > 
> > What the mux solves is exclusion, so that the gpio pin is locked while
> > measurement is made on either current-sense or voltage-sense.
> > 
> > However, the channels from the raw-{current,voltage}-sense nodes are exposed
> > to user space, and it will be possible to make "raw" measurements without
> > regard to how the gpio pin is set. That will of course not yield the desired
> > results, but is also a user error and might not be a big problem?  
> 
> I just realized that it's also possible to do this "the other way around". Maybe
> that makes more sense?
Ah, I'd failed to realize that this is about routing a single wire
through two different analog circuits that end on 'different' ADC inputs.

Pictures would help me out btw!  Everyone loves ascii art.

Anyhow, I 'think' what you have here should work.

Jonathan

> 
> Cheers,
> Peter
> 
> mux: gpio-mux {
> 	compatible = "gpio-mux";
> 	#mux-control-cells = <0>;
> 
> 	gpios-mux = <&main_gpio0 29 GPIO_ACTIVE_HIGH>;
> };
> 
> rcs: raw-current-sense {
> 	compatible = "io-channel-mux";
> 	io-channels = <&adc 0>;
> 	io-channel-names = "parent";
> 	#io-channel-cells = <1>;
> 
> 	mux-controls = <&mux>;
> 
> 	channels = "raw-current", "";
> };
> 
> rvs: raw-voltage-sense {
> 	compatible = "io-channel-mux";
> 	io-channels = <&adc 1>;
> 	io-channel-names = "parent";
> 	#io-channel-cells = <1>;
> 
> 	mux-controls = <&mux>;
> 
> 	channels = "", "raw-voltage";
> };
> 
> current-sense {
> 	compatible = "current-sense-shunt";
> 	io-channels = <&rcs 0>;
> 	io-channel-name = "current";
> 
> 	shunt-resistor-micro-ohms = <3300000>;
> };
> 
> voltage-sense {
> 	compatible = "voltage-divider";
> 	io-channels = <&rvs 1>;
> 	io-channel-name = "voltage";
> 
> 	output-ohms = <22>;
> 	full-ohms = <222>;
> };
> 
> Cheers,
> Peter





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux