OpenWrt Forum Archive

Topic: How to add GPIO based Interrupt Request support for AR9331 Board.

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I want to add support of GPIO based interrupt functionality and want to use GPIO based IRQ for my application in AR9331 board.

I have looked into irq.h file of mach-ath79 for GPIO irq base but could not found base address of GPIO based IRQ.

There are total 51 IRQ numbers are defined but non of them are used for GPIOs and i want to use IRQs for GPIOs.

I have also looked into gpio.c file of arch/mips/ath79 folder but there is no any implementation for gpio_toirq() function.

Does any one has idea about how to define GPIO IRQ base for AR9331?

Thanks for reply.

I will look into patch and let you know result after using that patch for my application.

ritesh.prajapati wrote:

Thanks for reply.

I will look into patch and let you know result after using that patch for my application.

Comments and test results are welcome. I would like to send this patch to the developers, but there is one part, which isn't clean:

+ /* TODO: reset GPIO MISC INT - this is not the usual place to do this */
+ __raw_writel(1<<3, base2 + AR71XX_RESET_REG_MISC_INT_STATUS);
+ /* and flush write */
+ __raw_readl(base2 + AR71XX_RESET_REG_MISC_INT_STATUS);

If you have any suggestion to get rid of this, please let me know.

Regards

Gerd

(Last edited by bertc3p0 on 10 Oct 2014, 13:30)

Thanks
i will test this patch with SD card-present detect GPIO by using this mod:
http://wiki.openwrt.org/ru/toh/tp-link/ … p.mmc.hack
with some changes:

...
#define TL_MR3X20_GPIO_BTN_MMC    <GPIO number>
...
/*
 * MMC-on-SPI setup code
 */

/* Which GPIO line is connected to the card-present detect line? */
#define MMC_CARD_PRESENT_GPIO    TL_MR3X20_GPIO_BTN_MMC

/*
 * Initializes SPI system to communicate with MMC/SD card
 */
static int ath79_mmc_spi_init(struct device *pdev, irqreturn_t (*card_det_irq_handler)(int, void *),
        void *mmc)
{
    int err, irq;

    err = gpio_request(MMC_CARD_PRESENT_GPIO, "ath79-mmc-spi");
    if (err)
        return err;

    err = gpio_direction_input(MMC_CARD_PRESENT_GPIO);
    if (err)
        goto fail;

    irq = gpio_to_irq(MMC_CARD_PRESENT_GPIO);
    err = request_irq(irq, card_det_irq_handler,
              IRQF_DISABLED | IRQF_TRIGGER_FALLING,
               "ath79-mmc-spi", mmc);
    if (err == 0) {
        printk(KERN_INFO "ath79-mmc-spi: assigned card detection IRQ %d\n", irq);
    } else {
        dev_err(pdev, "Cannot assign MMC/SD card detection IRQ (%i)!\n", irq);
        goto fail;
    }

    return 0;

fail:
    gpio_free(MMC_CARD_PRESENT_GPIO);
    return err;
}

static void ath79_mmc_spi_exit(struct device *pdev, void *mmc)
{
    free_irq(gpio_to_irq(MMC_CARD_PRESENT_GPIO), mmc);
    gpio_free(MMC_CARD_PRESENT_GPIO);
}

static struct mmc_spi_platform_data ath79_mmc_data = {
    .init        = &ath79_mmc_spi_init,    /* set up card detect GPIO IRQ */
    .exit        = &ath79_mmc_spi_exit,
    .get_ro        = NULL,                    /* no read-only detection here */
    .detect_delay    = 100,                /* card detection delay in msec */
    .ocr_mask    = MMC_VDD_32_33 | MMC_VDD_33_34,
};

static struct ath79_spi_controller_data ath79_spi1_cdata = {
    .cs_type = ATH79_SPI_CS_TYPE_GPIO,
    .cs_line = TL_MR3X20_GPIO_CS1_MMC,
}; 
...

offtopic
io util you can find on BB branches, just add it in /etc/opkg.conf next:

...
src/gz barrier_breaker_oldpackages http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages

after this:

opkg update
opkg install io

(Last edited by Deoptim on 10 Oct 2014, 16:25)

I've applied this patch in the hopes that it will add an "edge" file when the gpio is exported via sysfs, but no luck.

What would it take to make the exported gpios pollable via sysfs?

The discussion might have continued from here.