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.

AM335X- GPIO interrupt



Dear Sir,


I want to implement the reset button(S2_GPIO2_8 from BBB_SCH) interrupt in the BBB EVB, but it couldn't generate the interrupt when I pressed the S2 button, my code add into the drivers/watchdog/omap_wdt.c as bleow,

static irqreturn_t rst_button_handle_irq(int irq, void *dev)
{

    printk("=============rst_button_handle_irq\n");
    return IRQ_HANDLED;
}

static void reset_button_gpio_init(void)
{
    int gpio_reset_button_pin = 72;//gpio2_8
    int status = gpio_request(gpio_reset_button_pin,"rstButton\n");
    if (status < 0)
        pr_err("Failed to request gpio for rstButton");
    else
        printk("rstButton request success\n");

    gpio_direction_input(gpio_reset_button_pin);
 

    status = request_irq(gpio_to_irq(gpio_reset_button_pin), rst_button_handle_irq, 0, "rst_Button", NULL);
    if (status < 0)
        printk("rstButton irq failed\n");
    else
        printk("rstButton request_irq success\n");
}

static int omap_wdt_probe(struct platform_device *pdev)
{
    struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
    struct watchdog_device *omap_wdt;
    struct resource *res, *mem;
    struct omap_wdt_dev *wdev;
    u32 rs;
    int ret;

    reset_button_gpio_init();

.

.}

Power on message:

[    1.275139] rstButton request success
[    1.284016] rstButton request_irq success
[    1.289229] omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec

The interrupt was created by cat /proc/interrupts

root@am335x-evm:~# cat /proc/interrupts
           CPU0
 28:       1693      INTC  12  edma
 30:          0      INTC  14  edma_error
 44:         54      INTC  28  mmc1
 56:          0      INTC  40  4a100000.ethernet
 57:         22      INTC  41  4a100000.ethernet
 58:          2      INTC  42  4a100000.ethernet
 59:          0      INTC  43  4a100000.ethernet
 80:       5296      INTC  64  mmc0
 84:       4888      INTC  68  gp_timer
 86:        730      INTC  70  44e0b000.i2c
 87:          0      INTC  71  4802a000.i2c
 88:        806      INTC  72  OMAP UART0
 91:          0      INTC  75  rtc0
 92:          0      INTC  76  rtc0
 94:          0      INTC  78  wkup_m3_txev
125:          0      INTC 109  53100000.sham
127:          0      INTC 111  48310000.rng
150:          0  44e07000.gpio   6  mmc0
216:          0  481ac000.gpio   8  rst_Button
Err:          0
root@am335x-evm:~#


Please give me a favor for the question, thanks.


B.R.

Joe

  • Hi,

    try out the below code:

    #include <linux/module.h>
    #include <linux/version.h>
    #include <linux/delay.h>
    #include <linux/irq.h>
    #include <linux/interrupt.h>
    #include <linux/completion.h>
    #include <mach/hardware.h>
    #include <asm/gpio.h>


    static int gpio_num;

    DECLARE_COMPLETION(work);

    static irqreturn_t handler (int irq, void * dev)
    {
    complete_all(&work);
    return IRQ_HANDLED;
    }

    int init_module()
    {
    int status;
    int irq;

    init_completion(&work);

    gpio_num = 72;

    status = gpio_request(gpio_num, "gpio_test\n");
    if (status < 0) {
    printk("ERROR can not open GPIO %d\n", gpio_num);
    return status;
    }

    gpio_export(gpio_num, true);

    if(gpio_get_value(gpio_num) == 0)
    printk("OFF. \n\tWaiting for the pin to be on..\n");
    else
    printk("ON. \n\tWaiting for the pin to be off..\n");

    irq = gpio_to_irq(gpio_num);
    status = request_irq(irq, handler, 0, "gpio_test", NULL);
    if(status < 0) {
    printk(KERN_ERR "error %d requesting GPIO IRQ %d\n", status, gpio_num);
    return status;
    }

    set_irq_type(irq, IRQ_TYPE_EDGE_RISING);

    wait_for_completion_interruptible(&work);

    printk(".. done\n");

    return 0;
    }

    void cleanup_module(void) {
    free_irq(gpio_to_irq(gpio_num), NULL);
    gpio_free(gpio_num);
    }

    MODULE_LICENSE("GPL");

    Makefile:

    obj-m += gpio_gpio_test.o
    PWD := $(shell pwd)

    KERNEL_DIR=<path to your linux source>
    INSTALL_DIR=$(FINAL_DEST)/gpio

    # Set KERNEL_DIR to your local kernel location

    all:
    $(MAKE) -C $(KERNEL_DIR) M=$(PWD) ARCH=arm CROSS_COMPILE=arm-cortex_a8-linux-gnueabi-

    install:
    mkdir -p $(INSTALL_DIR)
    cp gpio_test.ko $(INSTALL_DIR)
    clean:
    rm -rf *.o *.ko *.mod.c .*.cmd .tmp_versions *.order *.symvers

    Change the KERNEL_DIR to linux source directory.

    Cheers,
    --Prabhakar Lad