启用上拉GPIO [英] Enable pullup GPIO

查看:215
本文介绍了启用上拉GPIO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM具有AT91SAM9G25板,有4个PIO控制器,管理多达32个可编程I / O线工作。每个引脚可配置为通用I / O线
或者只是作为一个I / O线复多达两个外设I / O。因此,例如,根据与文档( SAM9G25 ,第14页),信号PC0可复用这样的通用I / O线或图像的VIDEO_ATMEL_ISI(ISI传感器接口)的ISI_D0线。

<$p$p><$c$c>╔════════════╦════════════╦════════════╦════════════╦════════════╗
║║主要║候补委员║PeripA║PeripB║PeripC
╠════════════╬════════════╬════════════╬════════════╬════════════╣
║信号/风向║信号/风向║信号/风向║信号/风向║信号/目录║
║║--------- --------- ---------║║║--------- --------- ║
║PC0 / I / O║║║ISI_D0 / I║║
╚════════════╩════════════╩════════════╩════════════╩════════════╝

所有GPIO线的复位状态是方向和上拉启用。当我通过sysfs的使用GPIOLIB我读了几个GPIO由于上拉的值1作为输入。这是当他们可以与其他外设复用的GPIO(输入,上拉电阻)的在几个板复位正常安全状态?我不看我怎么可以通过用户空间与GPIOLIB禁止上拉。因此,例如,我看到,当内核启动它检查图像传感器在周边内核或者作为一个模块,如果启用,因此设置PC0到外设B.这是在/弓/ ARM /马赫内核源代码-at91 / at91sam9x5_devices.c

 #如果定义(CONFIG_VIDEO_ATMEL_ISI)||定义(CONFIG_VIDEO_ATMEL_ISI_MODULE)
....
         at91_set_B_periph(AT91_PIN_PC0,0); / * * ISI_D0 /
...
#万一

那么,如果我不能够支持ISI内核中,我可以使用PC0信号作为GPIO线。这是/ SYS /内核/调试/ GPIO:

 #猫/ SYS /内核/调试/ GPIO    个GPIO 32-63,A:    个GPIO 64-95,B:
    [atmel_usba_udc] GPIOB16:GPIO]集
    [D1] GPIOB18:GPIO]明确    个GPIO 96-127,C:    个GPIO 128-159,D:
    [ohci_vbus] GPIOD19:GPIO]明确
    [ohci_vbus] GPIOD20:GPIO]明确
    [D2] GPIOD21:GPIO]集

这是/ SYS /内核/调试/ at91_gpio

 #猫/ SYS /内核/调试/ at91_gpio    引脚PIOA PIOB PIOC PIOD    0:A A GPIO:1A
    1:A A GPIO:1A
    2:GPIO:1的GPIO:1的
    3:GPIO:1的GPIO:1的
    4:GPIO:1的GPIO:1 GPIO:1
    5:GPIO:1的GPIO:1 GPIO:1
    6:GPIO:1的GPIO:1的
    7:B A GPIO:1A
    8:GPIO:1 GPIO:GPIO 1:1的
    9:A A GPIO:1A
    10:A A GPIO:1A
    11:一个GPIO:GPIO 1:1的
    12:一个GPIO:GPIO 1:1的
    13:一个GPIO:GPIO 1:1的
    14:一个GPIO:1 GPIO:1 GPIO:1
    15:GPIO:1 GPIO:GPIO 1:1的
    16:GPIO:1 GPIO:1 GPIO:0
    17:GPIO:1 GPIO:GPIO 1:1的
    18:GPIO:1 GPIO:GPIO 1:1的
    19:GPIO:1的GPIO:1 GPIO:0
    20:GPIO:1的GPIO:GPIO 0:0
    21:GPIO:1的GPIO:0 GPIO:1
    22:GPIO:1的GPIO:1的
    23:GPIO:1的GPIO:1的
    24:GPIO:1的GPIO:1的
    25:GPIO:1的GPIO:1的
    26:GPIO:1的GPIO:1的
    27:GPIO:0 GPIO:1A
    28:GPIO:1的GPIO:0
    29:GPIO:1的GPIO:0
    30:GPIO:1的GPIO:1的
    31:GPIO:1的GPIO:1的

这PIOA0多路传输到外设A(TXD0 UART线)以上输出节目,例如PIOC20被清除,但文件说,在复位状态的所有GPIO线与上拉INPUTS,我不觉得那里的内核或u -boot禁用此GPIO的上拉(可能的GPIO保持自己的状态,如果没有碰他的寄存器?)

但他的主要问题是,我怎么能清除GPIO线的上拉寄存器?我在内核源代码发现/arch/arm/mach-at91/at91sam9x5_devices.c使用此功能在linux-2.6.39 /弓/ ARM /马赫-AT91 / gpio.c实现。

  / *
    *启用/禁用下拉。
    *如果拉了,而调用该函数已启用,我们将其禁用。
    * /
    INT __init_or_module at91_set_pulldown(无符号引脚INT is_on)
    {
        无效__iomem * PIO = pin_to_controller(针);
        无符号的面具= pin_to_mask(针);        如果(!PIO ||!cpu_has_pio3())
            返回-EINVAL;        / *禁用的上拉反正* /
        __raw_writel(面具,PIO + PIO_PUDR);
        __raw_writel(掩模,PIO +(is_on PIO_PPDER:PIO_PPDDR));
        返回0;
    }
    EXPORT_SYMBOL(at91_set_pulldown);

头弓/ ARM /马赫-AT91 /有/马赫/ gpio.h

 的#ifndef __ASSEMBLY__
    / *设置安装例程,从电路板init或司机探头(称呼)* /
    .....
    EXTERN INT __init_or_module at91_set_pulldown(无符号引脚INT is_on);
    .....
    #ENDIF / * * __ASSEMBLY__ /

如何使用此功能与我的工具链,或者我应该做一个内核模块?

感谢

PD:对不起,我英文任何错误,我知道我需要改进它。


解决方案

也许你可以离开独自上拉。我用GPIO的OMAP SoC中,在最低水平也有类似的管脚复选项,但没有必要担心上拉。通常无论是驾驶它可以吸收足够的电流(这是EE /电路的观点,如果你不熟悉不用担心)。浮动输入可以是随机的麻烦;拉升高度应该没问题。

我不认为你应该需要做一个内核模块。我建议你​​尝试使用现有的用户模式接口。你的核心应该已经上钩通过sysfs中提供获得低级别的驱动程序。参阅 sysfs的中的 OMAP GPIO 。我不认为我见过的sysfs上拉选项。如果你得到的东西的工作,需要从C code调用它,那么你可以看看的API,或者只是使用system()。

im working with a AT91SAM9G25 board which has 4 PIO controller managing up to 32 programmable I/O lines. Each pin is configurable as either a general-purpose I/O line only or as an I/O line multiplexed up to two peripheral I/Os. So, for example, according with the documentation (SAM9G25, page 14), signal PC0 can be multiplexed such a general purpose I/O line or as the ISI_D0 line of the VIDEO_ATMEL_ISI (ISI of Image Sensor Interface).

╔════════════╦════════════╦════════════╦════════════╦════════════╗
║  Primary   ║ Alternates ║   PeripA   ║   PeripB   ║  PeripC    ║
╠════════════╬════════════╬════════════╬════════════╬════════════╣
║ Signal/Dir ║ Signal/Dir ║ Signal/Dir ║ Signal/Dir ║ Signal/Dir ║
║ ---------  ║ ---------  ║ ---------  ║ ---------  ║ ---------  ║
║ PC0 / I/O  ║            ║            ║ ISI_D0 / I ║            ║
╚════════════╩════════════╩════════════╩════════════╩════════════╝

The reset state of all GPIO lines is with direction IN and Pullup enabled. when i use GPIOLIB via sysfs i read a "1" value as INPUT in several GPIOs due to pullup. Is this a normal safe state of GPIO (INPUT with Pullup resistor) at reset in several boards when they can be multiplexed with other Peripherals?. I dont see how i can disable the pullup via userspace with GPIOLIB. So for example, i see that when kernel is booting it checks if the Image Sensor Peripheral is enabled at kernel or as a module and if so it sets the PC0 to Peripheral B. This is in the kernel sources at /arch/arm/mach-at91/at91sam9x5_devices.c

#if defined(CONFIG_VIDEO_ATMEL_ISI) || defined(CONFIG_VIDEO_ATMEL_ISI_MODULE)
....
         at91_set_B_periph(AT91_PIN_PC0, 0);    /* ISI_D0 */
...
#endif

Then if i dont enable ISI support in kernel i can use the PC0 signal as GPIO line. This is the /sys/kernel/debug/gpio:

    # cat /sys/kernel/debug/gpio

    GPIOs 32-63, A:

    GPIOs 64-95, B:
    [atmel_usba_udc] GPIOB16: [gpio] set
    [d1] GPIOB18: [gpio] clear

    GPIOs 96-127, C:

    GPIOs 128-159, D:
    [ohci_vbus] GPIOD19: [gpio] clear
    [ohci_vbus] GPIOD20: [gpio] clear
    [d2] GPIOD21: [gpio] set

And this is /sys/kernel/debug/at91_gpio

    # cat /sys/kernel/debug/at91_gpio

    Pin     PIOA            PIOB            PIOC            PIOD

    0:      A               A               GPIO:1          A
    1:      A               A               GPIO:1          A
    2:      GPIO:1          A               GPIO:1          A
    3:      GPIO:1          A               GPIO:1          A
    4:      GPIO:1          A               GPIO:1          GPIO:1
    5:      GPIO:1          A               GPIO:1          GPIO:1
    6:      GPIO:1          A               GPIO:1          A
    7:      B               A               GPIO:1          A
    8:      GPIO:1          GPIO:1          GPIO:1          A
    9:      A               A               GPIO:1          A
    10:     A               A               GPIO:1          A
    11:     A               GPIO:1          GPIO:1          A
    12:     A               GPIO:1          GPIO:1          A
    13:     A               GPIO:1          GPIO:1          A
    14:     A               GPIO:1          GPIO:1          GPIO:1
    15:     GPIO:1          GPIO:1          GPIO:1          A
    16:     GPIO:1          GPIO:1          GPIO:0          A
    17:     GPIO:1          GPIO:1          GPIO:1          A
    18:     GPIO:1          GPIO:1          GPIO:1          A
    19:     GPIO:1          A               GPIO:1          GPIO:0
    20:     GPIO:1          A               GPIO:0          GPIO:0
    21:     GPIO:1          A               GPIO:0          GPIO:1
    22:     GPIO:1          A               GPIO:1          A
    23:     GPIO:1          A               GPIO:1          A
    24:     GPIO:1          A               GPIO:1          A
    25:     GPIO:1          A               GPIO:1          A
    26:     GPIO:1          A               GPIO:1          A
    27:     GPIO:0          A               GPIO:1          A
    28:     GPIO:1          A               GPIO:0          A
    29:     GPIO:1          A               GPIO:0          A
    30:     GPIO:1          A               GPIO:1          A
    31:     GPIO:1          A               GPIO:1          A

The above output show that PIOA0 is multiplexed to Peripheral A (TXD0 UART Line), and for example PIOC20 is cleared, but the documentation says that all GPIO lines at reset state are INPUTS with pullup and i dont find where kernel or u-boot disable the pullup of this GPIO (maybe GPIOs keep their state if none touch his registers?)

But he main question is, how can i clear the pullup register of the GPIO lines? I find in kernel sources that /arch/arm/mach-at91/at91sam9x5_devices.c uses this function implemented in linux-2.6.39/arch/arm/mach-at91/gpio.c .

    /*
    * enable/disable the pull-down.
    * If pull-up already enabled while calling the function, we disable it.
    */
    int __init_or_module at91_set_pulldown(unsigned pin, int is_on)
    {
        void __iomem    *pio = pin_to_controller(pin);
        unsigned    mask = pin_to_mask(pin);

        if (!pio || !cpu_has_pio3())
            return -EINVAL;

        /* Disable pull-up anyway */
        __raw_writel(mask, pio + PIO_PUDR);
        __raw_writel(mask, pio + (is_on ? PIO_PPDER : PIO_PPDDR));
        return 0;
    }
    EXPORT_SYMBOL(at91_set_pulldown);

Header arch/arm/mach-at91/include/mach/gpio.h

    #ifndef __ASSEMBLY__
    /* setup setup routines, called from board init or driver probe() */
    .....
    extern int __init_or_module at91_set_pulldown(unsigned pin, int is_on);
    .....
    #endif  /* __ASSEMBLY__ */

How can use this functions with my toolchain, or should i make a kernel module?

Thanks

PD: Sorry for any mistakes in my english, i know i need to improve it.

解决方案

Maybe you can just leave the pullup alone. I've used GPIO on OMAP SoCs, at lowest level there are similar pin mux options, but it wasn't necessary to worry about pullups. Usually whatever is driving it can sink enough current (this is EE/circuit viewpoint, don't worry if you are unfamiliar). Floating input could be random and troublesome; pulled up high should be OK.

I would not think you should need to make a kernel module. I'd suggest you experiment using existing user mode interfaces. Your kernel should already have low-level drivers hooked in to provide access through sysfs. Refer to sysfs, omap gpio. I don't think I've seen pullup options in sysfs. If you get something working and need to call it from C code, then you can look for APIs, or just use system().

这篇关于启用上拉GPIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆