启用上拉 GPIO [英] Enable pullup GPIO

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

问题描述

我正在使用 AT91SAM9G25 板,该板具有 4 个 PIO 控制器,可管理多达 32 条可编程 I/O 线.每个引脚都可配置为通用 I/O 线仅或作为 I/O 线复用多达两个外围 I/O.因此,例如,根据文档 (SAM9G25,第 14 页),信号 PC0 可以多路复用,例如通用 I/O 线或作为 VIDEO_ATMEL_ISI(图像传感器接口的 ISI)的 ISI_D0 线.

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 ║            ║
╚════════════╩════════════╩════════════╩════════════╩════════════╝

所有 GPIO 线的复位状态是方向 IN 和上拉使能.当我通过 sysfs 使用 GPIOLIB 时,由于上拉,我在几个 GPIO 中读取了一个1"值作为 INPUT.当它们可以与其他外设复用时,这是 GPIO(带有上拉电阻的输入)在复位时的正常安全状态吗?我不知道如何使用 GPIOLIB 通过用户空间禁用上拉.例如,我看到当内核启动时,它会检查图像传感器外设是否在内核或作为模块启用,如果是,则将 PC0 设置为外设 B.这是在/arch/arm/mach 的内核源代码中-at91/at91sam9x5_devices.c

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

然后如果我不在内核中启用 ISI 支持,我可以使用 PC0 信号作为 GPIO 线.这是/sys/kernel/debug/gpio:

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

这是/sys/kernel/debug/at91_gpio

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

上面的输出显示 PIOA0 多路复用到外设 A(TXD0 UART 线),例如 PIOC20 被清除,但文档说复位状态下的所有 GPIO 线都是带上拉的输入,我找不到内核或 u-boot 禁用这个 GPIO 的上拉(如果没有人接触他的寄存器,也许 GPIO 会保持它们的状态?)

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?)

但他的主要问题是,我如何清除 GPIO 线的上拉寄存器?我在内核源代码中发现/arch/arm/mach-at91/at91sam9x5_devices.c 使用了在 linux-2.6.39/arch/arm/mach-at91/gpio.c 中实现的这个函数.

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);

头部 arch/arm/mach-at91/include/mach/gpio.h

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?

谢谢

PD:抱歉我的英语有任何错误,我知道我需要改进它.

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

推荐答案

也许你可以不理会pullup.我在 OMAP SoC 上使用了 GPIO,在最低级别有类似的引脚复用选项,但没有必要担心上拉.通常无论是什么驱动它都可以吸收足够的电流(这是 EE/电路的观点,如果您不熟悉,请不要担心).浮动输入可能是随机且麻烦的;拉高应该没问题.

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.

我认为您不需要制作内核模块.我建议您尝试使用现有的用户模式界面.您的内核应该已经挂接了低级驱动程序以通过 sysfs 提供访问.参考 sysfsomap gpio.我认为我没有在 sysfs 中看到过上拉选项.如果你得到了一些东西并且需要从 C 代码中调用它,那么你可以寻找 API,或者只使用 system().

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天全站免登陆