SAMA5D27-SOM1-EK1 GPIO Configuration

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

embeddedDevC
Posts: 3
Joined: Sun Aug 25, 2019 10:39 pm

SAMA5D27-SOM1-EK1 GPIO Configuration

Sun Aug 25, 2019 11:10 pm

I am new to linux device driver. I wanted to use couple of pins as GPIO's. So started looking at linux kernel code and device tree for SAMA5D27 SOM1 EK1. I saw few example for gpio-keys and gpio leds and the respective drivers in linux kernel but I couldn't find any driver for GPIO supporting samad27_som1_ek1. So my understanding is if I have to use pins GPIO's than I have to write a GPIO driver for the it as it's not available.

Code: Select all

//Device tree snippet I have removed the pinmux from ISC so no conflicts for Pins.
//Modified Pinctrl node
pinctrl_gpio_test_default: gpio_test_default {
                                        pinmux = <PIN_PC12__GPIO>,
                                                 <PIN_PC11__GPIO>;
                                        bias-disable;
                                };
//Added a new node
gpio_test {
                                compatible = "gpio"
                                pinctrl-names = "default";
                                pinctrl-0 = <&pinctrl_gpio_test_default>;

                                pc11 {
                                        label = "TEST1";
                                        gpios = <&pioA PIN_PC11 GPIO_ACTIVE_HIGH>;
                                        output-high;
                                };

                                pc12 {

                                        label = "TEST2";
                                        gpios = <&pioA PIN_PC12 GPIO_ACTIVE_LOW>;
                                        output-low;
                                };
                        };
But again gpio driver is a basic need and should have been there which make me thinks that there is something else which I am missing.
:?: Please help me to understand how I can configure and use pins as GPIO's using device tree and correct my understanding if anything wrong. Thanks
blue_z
Location: USA
Posts: 1954
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D27-SOM1-EK1 GPIO Configuration

Mon Aug 26, 2019 9:18 pm

embeddedDevC wrote: I am new to linux device driver. I wanted to use couple of pins as GPIO's. So started looking at linux kernel code and device tree for SAMA5D27 SOM1 EK1.
If you're going to use GPIOs in a device driver, then there are examples to follow.
If you intend to use GPIOs in userspace, then your post is confusing.
You neglect to mention a kernel version.

embeddedDevC wrote: But again gpio driver is a basic need and should have been there which make me thinks that there is something else which I am missing.
There is no "at91"-specific driver for gpio in the Linux kernel.
Atmel SoCs use the generic gpio drivers in conjunction with the pinctrl-at91 or pinctrl-at91-pio4 driver.

embeddedDevC wrote: Please help me to understand how I can configure and use pins as GPIO's using device tree and correct my understanding if anything wrong.
On the hardware side:
Atmel/Microchip refers to PIO (Parallel I/O) as the set of SoC pins that are not dedicated to power, clocks, addressing, or data. These PIO pins can be multiplexed (for peripheral assignment) and configured .
Any of these PIO pins can be used as a GPIO pin if (and only if) it is not multiplexed/assigned for use by a peripheral.
(There are some SoCs (e.g. maybe Broadcom?) that have dedicated GPIO pins.)
Refer to your SoC datasheet for more details.

On the software side (which resembles the Atmel hardware):
Linux kernel uses the pinctrl driver to manage (i.e. allocate as a resource), multiplex, and configure the (non-dedicated) pins of the SoC (e.g. the PIO pins of Atmel SoCs).
Linux kernel uses the gpio driver to manage and configure the (left-over) pinctrl pins that are not assigned or acquired by any other peripheral driver.

The Device Tree is the method (for ARM) to assign (multiplex) pins to peripheral functions and to assign pins to device drivers for use as GPIO.
GPIO pins (for userspace) cannot be defined using the Device Tree.
A GPIO pin "exists" as the default condition because that pin has not been assigned (multiplexed) to a peripheral function or been requested by a device driver.


Study Documentation/gpio/drivers-on-gpio.txt to make sure that you are not reinventing the wheel.


Regards


ADDENDUM

Some of the above information is out of date.
The Linux kernel does allow GPIO configuration through the Device Tree, including the naming of the pin.
Refer to Documentation/devicetree/bindings/gpio/gpio.txt
embeddedDevC
Posts: 3
Joined: Sun Aug 25, 2019 10:39 pm

Re: SAMA5D27-SOM1-EK1 GPIO Configuration

Mon Aug 26, 2019 11:34 pm

Thanks for your quick response @blue_z.
You neglect to mention a kernel version
I am using latest build linux4sam_6.1 (Linux arm 4.19.56-inux4sam-6.1).
If you intend to use GPIOs in userspace, then your post is confusing.
My intention is to set the GPIO's to some default state on boot up and once system is booted up I would like to use the libgpiod for accessing these GPIO's from user space. How do I set GPIO's to some default state on bootup ?
If you're going to use GPIOs in a device driver, then there are examples to follow.
Also please could you point me to the examples for using GPIO's within device driver.
blue_z
Location: USA
Posts: 1954
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D27-SOM1-EK1 GPIO Configuration

Tue Aug 27, 2019 3:29 am

embeddedDevC wrote: My intention is to set the GPIO's to some default state on boot up and once system is booted up I would like to use the libgpiod for accessing these GPIO's from user space. How do I set GPIO's to some default state on bootup ?
"Bootup" is actually a complex process.
Do you require pin initialization as soon as processor reset is de-asserted, or can that be deferred until the kernel has been initialized and userspace is active?

embeddedDevC wrote: Also please could you point me to the examples for using GPIO's within device driver.
Take a look at the usb1: ohci@400000 node in at91-sama5d27_som1_ek.dts.
The "atmel,vbus-gpio" property is described in Documentation/devicetree/bindings/usb/atmel-usb.txt as

Code: Select all

 - atmel,vbus-gpio: If present, specifies a gpio that needs to be activated for the bus to be powered.
Driver code in drivers/usb/gadget/udc/at91_udc.c utilizes this property for a GPIO.

Regards
embeddedDevC
Posts: 3
Joined: Sun Aug 25, 2019 10:39 pm

Re: SAMA5D27-SOM1-EK1 GPIO Configuration

Tue Aug 27, 2019 8:21 pm

Do you require pin initialization as soon as processor reset is de-asserted, or can that be deferred until the kernel has been initialized and userspace is active?
I would like to set it up as soon as processor reset is de-asserted and maintain it in same state throughout the boot process.
blue_z
Location: USA
Posts: 1954
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D27-SOM1-EK1 GPIO Configuration

Wed Aug 28, 2019 1:34 am

embeddedDevC wrote: I would like to set it up as soon as processor reset is de-asserted and maintain it in same state throughout the boot process.
Then you will need external hardware support, e.g. pull up/down resistors.
You will not get any software control of the PIO controller until the 2nd-stage boot program, e.g. AT91Bootstrap.
(The 1st-stage boot program is hardcoded in ROM.)

Regards

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 2 guests