This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM3356: GPIO direction call for a pin not pinmuxed as GPIO

Part Number: AM3356

I am revising some kernel code for AM3356 uart1 support. The code has been changed to adapt it to our board.

I see in the  code calls a call  to gpio_direction_output()  to set direction &value for some GPIO.

In the DTS  file for uart1 the  processor pin is configured as an uart1 RTS (rtsn) pin.  It is not configured as GPIO (mode 7).

Is it legal to call to  gpio_direction_output() while the pin is configured to be not a GPIO ?  Does it make any change on the RTS signal of uart1?

It looks like a mistake in the code, but I want to be sure before fixing the code

  • Hi Martin,

    gpio_direction_output() should be used only when GPIO pin is used for UART's RTS line. Refer to below files for details and examples:

    linux-4.19.38/Documentation/devicetree/bindings/serial/serial.txt

    linux-4.19.38/arch/arm/boot/dts/am335x-nano.dts

    This case is handled in below UART driver:

    linux-4.19.38/drivers/tty/serial/omap-serial.c

    This omap-serial.c is parsing your DTS file, and if you have GPIO pin used for UART's RTS line (like in am335x-nano.dts), then gpio_direction_output() function is used. So if you mean to fix omap-serial.c file, this is not needed, gpio_direction_output() is called only if GPIO pin is used.

    Regards,
    Pavel

  • Pavel,

    Thanks for your professional respond.
    I followed the references that you have provided and it is clear to me how code should be organized.
    Unfortunately the code and the DTS files that I use has been seriously corrupted and does not follow the format of
    linux-4.19.38/Documentation/devicetree/bindings/serial/serial.txt  
    linux-4.19.38/arch/arm/boot/dts/am335x-nano.dts
    linux-4.19.38/drivers/tty/serial/omap-serial.c.
    I have now 2 choices:
    a) To make proper configuration in the DTS files and port the omap-serial.c according to ilnux-4.19.38/Documentation/devicetree/bindings/serial/serial.txt  
    b)  To  verify  in the code that call to   gpio_direction_output()  is done only if the pin  is configured as a GPIO.
           If it is not configured as an GPIO (mode 7) - then calling to gpio_direction_output() is wrong and should be revised. 
    Please correct me if I am wrong in b). 
    Pavel, thanks for the assistance
    Regards,
    Martin
  • Martin,

    Martin Roth said:
    b)  To  verify  in the code that call to   gpio_direction_output()  is done only if the pin  is configured as a GPIO.
           If it is not configured as an GPIO (mode 7) - then calling to gpio_direction_output() is wrong and should be revised. 

    Yes, this seems correct to me. Just note that linux-4.19.38/drivers/tty/serial/omap-serial.c driver is generic and should not be modified unless you have found bug in it. When porting to custom board, DTS file should be updated.

    Regards,
    Pavel