2

I want to do following pin muxing. i.e USART Tx -> to GPIO -> Back to USART Tx pin inside Linux kernel for some purpose.

I tried to make the PIN as GPIO using gpio_request and gpio_direction_output, so i am able to make that pin as GPIO . But as i want to switch back from GPIO to USART Tx pin, it is not working, I tried following at91_set_A_periph to that pin, still no luck.

Working on kernel : 3.18 and at91 atmel board.

Ezequiel Garcia
  • 1,037
  • 8
  • 20
  • 1
    There are many vendor kernels out there, so it would be better if you could point out exactly *what* kernel you are using. Also, you should paste the code you have tried and have not worked. That will make helping you easier. – Ezequiel Garcia May 24 '16 at 04:52

1 Answers1

2

You can have a look at the i2c-imx driver. It does exactly that.

You need to use pinctrl_lookup_state to retrieve the different pinctrl states (one of those being USART Tx and the other one GPIO). Then you can switch between both with pinctrl_select_state.

To sum it up, you'd have something like that in your uart node:

    usart3: serial@fc00c000 {
        pinctrl-names = "default","gpio";
        pinctrl-0 = <&pinctrl_usart3>;
        pinctrl-1 = <&pinctrl_usart3_gpio>;
        tx-gpio = <&pioE 4 GPIO_ACTIVE_LOW>;
        status = "okay";
    };

In the driver code:

pinctrl_pins_default = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
pinctrl_pins_gpio = pinctrl_lookup_state(pinctrl, "gpio");
tx_gpio = of_get_named_gpio(pdev->dev.of_node, "tx-gpio", 0);

Then, you can use pinctrl_select_state to switch back and forth between pinctrl_pins_default and pinctrl_pins_gpio. tx_gpio is your gpio.

Alexandre Belloni
  • 2,244
  • 13
  • 12