3

I am facing an interesting problem. I like to set a pin of my cpu. So far I created a module for controlling the pin. This module is setting the default pin configuration(high). The default pin configuration becomes active when the module is loaded. That is working fine.

Now I like to enable my default pin configuration right away from the start of boot process. To archive that I wrote a patch for the ATMEL bootloader(at91bootstrap) and the uboot(u-boot-at91). This works fine till the moment the kernel starts. At the kernel start the pins is set to the ATMEL default. They pins are defined in the device tree as gpios.

I think I have two possibilities:

1st - patch the /init/main.c at the "right" spot. Where is the right spot?

2nd - modify the device tree to set the GPIOs to an other default value. How to "re set" an gpio a value?

Stefan Jaritz
  • 1,999
  • 7
  • 36
  • 60
  • 3
    Forget about 1st option, it's an ugly hack. Consider only modifying device tree or loading some device tree overlay. Also, the information you provided is insufficient. You should provide device tree file/files you are using (or a link to those files on LXR/kernel.org), and tell us which exactly GPIO you want to modify (with details: default value, where it's described in Datasheet/User Manual, etc). – Sam Protsenko Feb 27 '17 at 11:09
  • So I am looking for an example to reset/overlay a pin value at the dts. Any ideas where to find it? Tried to use the "led" class. This lead to conflicts with my module. The led module and my module trying to get the same pin. – Stefan Jaritz Feb 27 '17 at 11:28
  • In that case you should control your GPIO pin state only from your driver. I don't quite understand why do you want to do that from device tree? Just obtain that pin in your driver (from device tree), and change its state correspondingly. – Sam Protsenko Feb 28 '17 at 12:07
  • my problem is, that the PIn is set to Low by the default dts config. It stays low from the moment the kernel is loaded till the moment the driver is loaded(it is set to high). I like to overcome this. – Stefan Jaritz Mar 01 '17 at 07:35

1 Answers1

2

When you modify the pin in u-boot level; it will be override by the kernel. /init/main.c is worse idea and so I think you should not followed this approach

In kernel level if you you want to set the GPIO pin, there are two possibilities (apart from your module)

1) Kernel board file.

2) Device tree file.

Suppose if you want to set the SDIO pin as GPIO in i.MX6 board then you need to modify the code like this.

leds {
   compatible = "gpio-leds";
   pinctrl-names = "default";
   pinctrl-0 = <&pinctrl_gpio_leds>;

red {
       gpios = <&gpio7 0 0>;
       default-state = "on";
};

MX6QDL_PAD_SD3_DAT5__GPIO7_IO00 0x1b0b0  //set the pin as GPIO

For the default state of the pin please refer the datasheet of your processor. And one pin may have different functionalities.

And if you want to use the same pin for some other functionalities instead of GPIO then you can choose on of the below configuration.

MX6QDL_PAD_SD3_DAT5__UART2_RX_DATA  //UART2 RX Data pin
MX6QDL_PAD_SD3_DAT5__GPIO7_IO00  //As a GPIO pin
MX6QDL_PAD_SD3_DAT6__UART1_RX_DATA // UART1 RX data
MX6QDL_PAD_SD3_DAT6__SD3_DATA6 //SDIO pin which is default in this case

Please add more details if you are looking for something more (like pin number and device tree file name).

vinod maverick
  • 670
  • 4
  • 14
  • At my first approach I came up with the same solution. But sadly, by using the pin by the led driver it got blocked by it. I my case I like to use the pin by my own kernel driver. This reduces the problem to: "set the pin to high till my own module is loaded". – Stefan Jaritz Feb 27 '17 at 16:15
  • You want to use one pin for your custom functionalities and right now that pin is already occupied by the LED driver. Ideally there should be two different pin for two different purpose. So am assuming there will be one pin for your LED driver (if you want to use this driver as well) and one will be for your custom functionalities. You can set the the state (High/low) of pin from device tree entry of your driver like gpios = <&gpio7 0 0>; . By changing the third parameter you can change the state of GPIO pin. 0 is for Active High state and 1 for Active Low state. – vinod maverick Feb 28 '17 at 01:37