how to describe a peripheral with power enable pin


Peter A. Bigot
 

"Si7021-pwr" is not a GPIO device, it's a regulator device.  You don't need to configure the GPIO; the regulator device does that.  Use the `regulator_enable()` and `regulator_disable()` API with the device.


Rafael Dias
 

ok, ok.

I have to enable the regulator device driver.
Now it is working.

My overlay is as below:
/ {
Si7021_pwr: Si7021-pwr-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021-pwr";
};
};


But when I'll try to use the pin, I'm getting a EINVAL error after the gpio_pin_config function:   
const struct device* pwr = device_get_binding( "Si7021-pwr" );
if (NULL == pwr )
{
printf( "Could not get pwr port\n" );
return;
}

rc = gpio_pin_configure(pwr, 9, GPIO_OUTPUT_ACTIVE | GPIO_OUTPUT_INIT_HIGH );
if (rc < 0) {
printk("Failed to configure gpio pin\n");
return;
}

if I use the same sequence, but opening the gpiod port, everything works fine:
const struct device* gpiod = device_get_binding( DT_LABEL( DT_NODELABEL( gpiod ) ) );
if (NULL == gpiod )
{
printf( "Could not get gpiod port\n" );
return;
}

rc = gpio_pin_configure(gpiod, 9, GPIO_OUTPUT_ACTIVE | GPIO_OUTPUT_INIT_HIGH );
if (rc < 0) {
printk("Failed to configure gpio pin\n");
return;
}

I don't know where the error is..


On Thu, 8 Apr 2021 at 07:15, Rafael Dias via lists.zephyrproject.org <rdmeneze=gmail.com@...> wrote:
Hi,
I was performing tests with my board, and the label Si7021pwr didn't appear at the device list...

On Thu, 8 Apr 2021 at 06:31, Rafael Dias via lists.zephyrproject.org <rdmeneze=gmail.com@...> wrote:
I found a solution:

/ {
si7021_pwr: si7021-pwr-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

si7021_pwr2: si7021-pwr2-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

On Thu, 8 Apr 2021 at 06:03, Rafael Dias via lists.zephyrproject.org <rdmeneze=gmail.com@...> wrote:
Hi Peter,
thank you.

I was performing some tests here and I have a question: if I want to enable two or more supply-regulators in device three, how to proceed?

I tried this approach and it doesn't work:

/ {
regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin test";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

Using this declarations, only the second definition,  Si7021pwr2, appears on ./zephyr/include/generated/devicetree_unfixed.h

On Fri, 2 Apr 2021 at 13:08, Peter A. Bigot <pab@...> wrote:
The regulators API was designed for this purpose.  For a simple GPIO you should just be able to use a supply-gpios property in the devicetree node.  See https://docs.zephyrproject.org/latest/reference/peripherals/regulators.html

Peter



--
Rafael Dias Menezes
tel.:
+436507008854



--
Rafael Dias Menezes
tel.:
+436507008854



--
Rafael Dias Menezes
tel.:
+436507008854



--
Rafael Dias Menezes
tel.:
+436507008854


Rafael Dias
 

Hi,
I was performing tests with my board, and the label Si7021pwr didn't appear at the device list...

On Thu, 8 Apr 2021 at 06:31, Rafael Dias via lists.zephyrproject.org <rdmeneze=gmail.com@...> wrote:
I found a solution:

/ {
si7021_pwr: si7021-pwr-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

si7021_pwr2: si7021-pwr2-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

On Thu, 8 Apr 2021 at 06:03, Rafael Dias via lists.zephyrproject.org <rdmeneze=gmail.com@...> wrote:
Hi Peter,
thank you.

I was performing some tests here and I have a question: if I want to enable two or more supply-regulators in device three, how to proceed?

I tried this approach and it doesn't work:

/ {
regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin test";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

Using this declarations, only the second definition,  Si7021pwr2, appears on ./zephyr/include/generated/devicetree_unfixed.h

On Fri, 2 Apr 2021 at 13:08, Peter A. Bigot <pab@...> wrote:
The regulators API was designed for this purpose.  For a simple GPIO you should just be able to use a supply-gpios property in the devicetree node.  See https://docs.zephyrproject.org/latest/reference/peripherals/regulators.html

Peter



--
Rafael Dias Menezes
tel.:
+436507008854



--
Rafael Dias Menezes
tel.:
+436507008854



--
Rafael Dias Menezes
tel.:
+436507008854


Rafael Dias
 

I found a solution:

/ {
si7021_pwr: si7021-pwr-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

si7021_pwr2: si7021-pwr2-ctrl {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

On Thu, 8 Apr 2021 at 06:03, Rafael Dias via lists.zephyrproject.org <rdmeneze=gmail.com@...> wrote:
Hi Peter,
thank you.

I was performing some tests here and I have a question: if I want to enable two or more supply-regulators in device three, how to proceed?

I tried this approach and it doesn't work:

/ {
regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin test";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

Using this declarations, only the second definition,  Si7021pwr2, appears on ./zephyr/include/generated/devicetree_unfixed.h

On Fri, 2 Apr 2021 at 13:08, Peter A. Bigot <pab@...> wrote:
The regulators API was designed for this purpose.  For a simple GPIO you should just be able to use a supply-gpios property in the devicetree node.  See https://docs.zephyrproject.org/latest/reference/peripherals/regulators.html

Peter



--
Rafael Dias Menezes
tel.:
+436507008854



--
Rafael Dias Menezes
tel.:
+436507008854


Rafael Dias
 

Hi Peter,
thank you.

I was performing some tests here and I have a question: if I want to enable two or more supply-regulators in device three, how to proceed?

I tried this approach and it doesn't work:

/ {
regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin";
enable-gpios = < &gpiod 9 0 >;
label = "Si7021pwr";
};

regulator {
compatible = "regulator-fixed";
regulator-name = "Si7021 enable pin test";
enable-gpios = < &gpiod 10 0 >;
label = "Si7021pwr2";
};
};

Using this declarations, only the second definition,  Si7021pwr2, appears on ./zephyr/include/generated/devicetree_unfixed.h

On Fri, 2 Apr 2021 at 13:08, Peter A. Bigot <pab@...> wrote:
The regulators API was designed for this purpose.  For a simple GPIO you should just be able to use a supply-gpios property in the devicetree node.  See https://docs.zephyrproject.org/latest/reference/peripherals/regulators.html

Peter



--
Rafael Dias Menezes
tel.:
+436507008854


Peter A. Bigot
 

The regulators API was designed for this purpose.  For a simple GPIO you should just be able to use a supply-gpios property in the devicetree node.  See https://docs.zephyrproject.org/latest/reference/peripherals/regulators.html

Peter


Rafael Dias
 

Hi!
I'm starting with ZephyrProject and I'm playing with the development kit slstk3401a.

After implementing a very basic blinky app, I decided to use the si7021 sensor present at the board. I wrote an .overlay file with the definition of an I2C bus that is connected to the sensor but I'd like  also to define the GPIO that enables/disables the sensor operation. Bellow I share the circuit connection:

slstk3401a_tempsensor.png
And here is my overlay:

/ {
};

&i2c0 {
        status = "okay";
        si7021@40{
                compatible = "silabs,si7006";
                reg = <0x40>;
                label = "Si7021";
                status = "okay";
        };
};

Well, I don't know how to define the SENSOR_ENABLE pin at device three. I tried everything:
  • include a section called "resources":
/ {
resources {
power_en {
status = "okay";
compatible = "gpio-leds";
Si7021_power: Si7021_pwd0 {
gpios = <&gpiod 9 0>;
label = "Si7021_pwr";
};
};
};
};

  • include the section "resources" without "power_en":
/ {
resources {
status = "okay";
compatible = "gpio-leds";
Si7021_power: Si7021_pwd0 {
gpios = <&gpiod 9 0>;
label = "Si7021_pwr";
};
};
};

With these nodes, my firmware compiles, but when I call the function device_get_binding , I get a NULL return.

I solved this by the following code:
	const struct device* gpiod = device_get_binding( DT_LABEL( DT_NODELABEL( gpiod ) ) );
if (NULL == gpiod )
{
printf( "Could not get gpiod port\n" );
return;
} rc = gpio_pin_configure(gpiod, 9, GPIO_OUTPUT_ACTIVE | GPIO_OUTPUT_INIT_HIGH );
if (rc < 0) {
printk("Failed to configure gpio pin\n");
return;
}

I don't know, but I think that it isn't the beautiful way to do this.

Does anyone have advice on how to do this?

best regards,

--
Rafael Dias Menezes
tel.:
+436507008854