Hello everyone,
I learn how to create a kernel module using the i.MX 6Quad SABRE development board.
I could do cross compile the kernel module of i.MX6 and use printk to display the string.
*The kernel version used is "4.19.35-1.1.0+g0f9917c56d59"
I want to control GPIO as the next step.
1. Where is the .h file required to control GPIO in Yocto project?
2. How should I write the source code for controlling GPIO?
Could you tell me how?
Best regards.
Dear Radhika Somaiya
Thank you for your reply.
Sorry, the reply was delayed...
I tried the solution you taught.
As a result, I was able to confirm the HIGH and LOW of the port.
Thank you very much.
Best regards,
Ono Takumi
Hitakumiono ,
We are able to control GPIO_2, Please follow the below steps:
1) comment the line as follows in imx6qdl-sabresd.dtsi
line 246
// leds {
// compatible = "gpio-leds";
// pinctrl-names = "default";
// pinctrl-0 = <&pinctrl_gpio_leds>;
// charger-led {
// gpios = <&gpio1 2 0>;
// linux,default-trigger = "max8903-charger-charging";
// retain-state-suspended;
// };
// };
line 945
gpio_leds {
pinctrl_gpio_leds: gpioledsgrp {
// fsl,pins = <
// MX6QDL_PAD_GPIO_2__GPIO1_IO02 0x1b0b0
// >;
};
};
2) After that use the following commands:
1. bitbake -c compile linux-imx -f
2. bitbake -c deploy linux-imx -f
3. bitbake imx-image-multimedia
Regards,
Radhika Somaiya.
Dear Karan Gajjar
Thank you for your reply.
I am trying the solution you taught me.
I searched for a .dst file.
The following files were found in the following path:
Path: ~/imx-yocto-bsp/build-x11/tmp/work/imx6qsabresd-poky-linux-gnueabi/linux-imx/4.19.35-r0/git/arch/arm/boot/dts
-imx6q-sabresd.dts
-imx6q.dtsi
-imx6qdl-sabresd.dtsi
The board I'm using is sabresd, so fix these files in my case?
I looked in the file and found the following in imx6qdl-sabresd.dtsi:
--------------------------------------
line 246
//Leds {
// Compatible = "gpio-leds";
// pinctrl-names = "default";
// pinctrl-0 = <&pinctrl_gpio_leds>;
// charger-led {
// gpios = <&gpio1 2 0>;
// linux,default-trigger = "max8903-charger-charging";
// retain-state-suspended;
// };
//}};
line 945
//Gpio_leds {
// pinctrl_gpio_leds: gpioledsgrp {
// Fsl,pins = <MX6QDL_PAD_GPIO_2__GPIO1_IO02 0x1b0b0>;
// };
//}};
--------------------------------------
I commented out as above and ran bitbake imx-image-multimedia.
I created and ran the yocto image, but nothing seems to have changed.
Is my fix correct?
Thank you for reading this long message.
Best regards,
Ono Takumi
Hi, takumi ono
You can use this API "gpio_set_value" and "gpio_get_value" in your kernel module to control the GPIO.
Ex : gpio_set_value (3, 1/0);
There are some GPIO used by another driver, in this case, no other driver can access the GPIO.
As mentioned in the previous comment, please refer to this link.
Let us know in case of any concerns.
Regards,
Karan Gajjar
Dear Karan Gajjar
Thank you for your reply. I read the link and it was very helpful.
I found the functions "gpio_set_value" and "gpio_get_value" in "gpio.h". When I want to control GPIO from a kernel module created by myself, can I use these APIs?
For example,
In the case of blinking the GPIO_2 pin (USR_DEF_RED_LED) on the i.MX6 SABER board, is the following code correct?
#gpio_set_value (2, On/Off).
Is it impossible to control the port already used like Log2?
Command ⇒ root @ imx6qsabresd:/# cat /sys/kernel/debug/gpio
Log1 ⇒ gpiochip0: GPIO 0-31, parent: platform/209c000.gpio, 209c000.gpio:
Log2 ⇒ gpio-2 (|charger-led) out lo <----already used?????
Log3 ⇒ gpio-4 (| Increase volume) in hi IRQ
Best regards,
Ono Takumi
Hi takumi ono ,
We hope below links will be helpful to you:
Definitive GPIO guide - Studio Kousagi Wiki
VAR-SOM-MX6 GPIO - Variscite Wiki
Let us know in case of any concerns.
Regards,
Karan Gajjar