Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aux-spi, aux-uart interrupt issues #1573

Closed
franzflasch opened this issue Jul 25, 2016 · 7 comments
Closed

aux-spi, aux-uart interrupt issues #1573

franzflasch opened this issue Jul 25, 2016 · 7 comments

Comments

@franzflasch
Copy link

Hi! I am using the rpi-compute module with kernel version 4.4 and got some issues when using aux spi1 and aux spi2 simultaneously. On the aux spi1 I've connected an spi lcd device and on aux spi2 I've connected an sd card, which I am using with the mmc_spi driver. When using both devices simultaneously I get errors when reading from the mmc card. I also backported the latest spi-bcm2835aux driver from kernel 4.6 which introduced some fixes.

I think the problem is, that the interrupt handlers are not implemented properly:

static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id)
{
    struct spi_master *master = dev_id;
    struct bcm2835aux_spi *bs = spi_master_get_devdata(master);
    irqreturn_t ret = IRQ_NONE;

    /* check if we have data to read */
    while (bs->rx_len &&
           (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
          BCM2835_AUX_SPI_STAT_RX_EMPTY))) {
        bcm2835aux_rd_fifo(bs);
        ret = IRQ_HANDLED;
    }

    /* check if we have data to write */
    while (bs->tx_len &&
           (bs->pending < 12) &&
           (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
          BCM2835_AUX_SPI_STAT_TX_FULL))) {
        bcm2835aux_wr_fifo(bs);
        ret = IRQ_HANDLED;
    }

    /* and check if we have reached "done" */
    while (bs->rx_len &&
           (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
          BCM2835_AUX_SPI_STAT_BUSY))) {
        bcm2835aux_rd_fifo(bs);
        ret = IRQ_HANDLED;
    }

    if (!bs->tx_len) {
        /* disable tx fifo empty interrupt */
        bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] |
            BCM2835_AUX_SPI_CNTL1_IDLE);
    }

    /* and if rx_len is 0 then disable interrupts and wake up completion */
    if (!bs->rx_len) {
        bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]);
        complete(&master->xfer_completion);
    }

    /* and return */
    return ret;
}

I can imagine that this routine will fail if there are massive interrupt requests simultaneously on aux spi1 and aux spi2.

Some notes regarding these issues:

  1. The bcm2835 has an interrupt status register on 0x7E21 5000 "AUX_IRQ" - however the aux spi drivers seem to ignore this status register completely. Shouldn't it be checked if the interrupt belongs to the corresponding device?
  2. I've already begun to fix these issues, but realized that there is another issue: According to the device tree of the compute module the above mentioned register is already mapped in the clk-bcm2835-aux.c driver:
        aux: aux@0x7e215004 {
            compatible = "brcm,bcm2835-aux";
            #clock-cells = <1>;
            reg = <0x7e215000 0x8>;
            clocks = <&clk_core>;
            status = "disabled";
        };

However the aux irq register is not used anywhrere in the driver.

I think it should be corrected to this:

        aux: aux@0x7e215004 {
            compatible = "brcm,bcm2835-aux";
            #clock-cells = <1>;
            reg = <0x7e215004 0x4>;
            clocks = <&clk_core>;
            status = "disabled";
        };

The main issue is, that the IRQ status register is not checked within the aux spi driver. It would be great if someone can take a look at this and fixes this.

@franzflasch
Copy link
Author

OK. I've fixed it myself. I really can't understand why the auxirq register was not taken into account in the spi drivers. If someone is interested: I've changed the interrupt routine to this:

static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id)
{
    struct spi_master *master = dev_id;
    struct bcm2835aux_spi *bs = spi_master_get_devdata(master);
    u32 irq_flags = readl(bcm2835_aux_irq_reg);

    if(!(irq_flags & (1<<master->bus_num)))
    {
        return IRQ_NONE;
    }

    /* check if we have data to read */
    while (bs->rx_len &&
           (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
          BCM2835_AUX_SPI_STAT_RX_EMPTY))) {
        bcm2835aux_rd_fifo(bs);
    }

    /* check if we have data to write */
    while (bs->tx_len &&
           (bs->pending < 12) &&
           (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
          BCM2835_AUX_SPI_STAT_TX_FULL))) {
        bcm2835aux_wr_fifo(bs);
    }

    /* and check if we have reached "done" */
    while (bs->rx_len &&
           (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
          BCM2835_AUX_SPI_STAT_BUSY))) {
        bcm2835aux_rd_fifo(bs);
    }

    if (!bs->tx_len) {
        /* disable tx fifo empty interrupt */
        bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1] |
            BCM2835_AUX_SPI_CNTL1_IDLE);
    }

    /* and if rx_len is 0 then disable interrupts and wake up completion */
    if (!bs->rx_len) {
        bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]);
        complete(&master->xfer_completion);
    }

    /* and return */
    return IRQ_HANDLED;;
}

The variable bcm2835_aux_irq_reg is an io mapped pointer which i've exported from the clk-bcm2835-aux.c driver to get access to the auxirq register.

It is just a quick and dirty hack and should be implemented in a clean way by someone who has the time for it. But I hope you guys get an idea whats wrong in the current driver. Now it is working like a charm ;)

@franzflasch franzflasch changed the title auxiliary peripherals interrupt issues aux-spi, aux-uart interrupt issues Jul 28, 2016
@lategoodbye
Copy link
Contributor

@franzflasch Thanks for providing a fix. Could you please create a patch based on linux-next (mainline) with your changes and send it to linux-rpi-kernel@lists.infradead.org ?

@franzflasch
Copy link
Author

@lategoodbye Yes I can send a patch, however at first I need to reimplement this. My "fix" works, but it is just an ugly hack.

@lategoodbye
Copy link
Contributor

lategoodbye commented Jul 29, 2016

Wonderful, but don't spend too much time in reimplementation. It's imporant that this issue is reported to the mailing list, the decision how this should be fixed finally lies to the maintainer. It's possible that we need to implement an additional instance which delegate the IRQs.

pelwell pushed a commit that referenced this issue Mar 23, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell pushed a commit that referenced this issue Mar 23, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell pushed a commit that referenced this issue Mar 23, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell pushed a commit that referenced this issue Mar 23, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell pushed a commit that referenced this issue Mar 23, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell pushed a commit that referenced this issue Mar 23, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
@pelwell
Copy link
Contributor

pelwell commented Mar 23, 2017

The current trees now include a modified bcm2835-aux driver that also acts as an interrupt controller, and DT modifications to activate it. I've tested it with the console over ttyS0 running an MFRC reader on SPI1.

@franzflasch
Copy link
Author

This is great! Thanks!

popcornmix added a commit to raspberrypi/firmware that referenced this issue Mar 24, 2017
kernel: BCM270X_DT: Enable AUX interrupt controller in DT
See: BCM270X_DT: Enable AUX interrupt controller in DT
See: raspberrypi/linux#1573

kernel: ASoC: Add prompt for ICS43432 codec

firmware: gpu_server: unreserve the qpu user shaders at end of each job
firmware: gpu_server: Only enable/disable qpus at start/end of service connection
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Mar 24, 2017
kernel: BCM270X_DT: Enable AUX interrupt controller in DT
See: BCM270X_DT: Enable AUX interrupt controller in DT
See: raspberrypi/linux#1573

kernel: ASoC: Add prompt for ICS43432 codec

firmware: gpu_server: unreserve the qpu user shaders at end of each job
firmware: gpu_server: Only enable/disable qpus at start/end of service connection
popcornmix pushed a commit that referenced this issue Mar 27, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Mar 27, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Mar 27, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Mar 27, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Mar 31, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Mar 31, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 2, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 2, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 4, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 4, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 10, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 10, 2017
See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Apr 10, 2017
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell pushed a commit that referenced this issue May 20, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue May 21, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue May 25, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue May 29, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 5, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 11, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 13, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 13, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 18, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 18, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 27, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jun 27, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jul 9, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jul 20, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jul 25, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Jul 30, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
sasikrishna2014 pushed a commit to sasikrishna2014/ubuntu-bionic that referenced this issue Aug 7, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Aug 7, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Aug 14, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Aug 22, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix pushed a commit that referenced this issue Aug 29, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: #1484
     #1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
bluegray pushed a commit to bluegray/ubuntu-bionic that referenced this issue Oct 17, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 11, 2018
commit b3c6dd9
Author: Phil Elwell <phil@raspberrypi.org>
Date:   Thu Mar 23 16:34:46 2017 +0000

    bcm2835-aux: Add aux interrupt controller
    
    The AUX block has a shared interrupt line with a register indicating
    which devices have active IRQs. Expose this as a nested interrupt
    controller to avoid sharing problems.
    
    See: raspberrypi/linux#1484
         raspberrypi/linux#1573
    
    Signed-off-by: Phil Elwell <phil@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1211_b3c6dd9ed905a1558061cbc144cc29f8766e31cf.patch
raspbian-autopush pushed a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 11, 2018
commit 09ee6ad
Author: Phil Elwell <phil@raspberrypi.org>
Date:   Thu Mar 23 17:08:44 2017 +0000

    BCM270X_DT: Enable AUX interrupt controller in DT
    
    See: raspberrypi/linux#1484
         raspberrypi/linux#1573
    
    Signed-off-by: Phil Elwell <phil@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1212_09ee6ad78fe69c4196edd973e0bb4fb3a417dd85.patch
Cyndent pushed a commit to Cyndent/ubuntu-core-4.15 that referenced this issue Dec 11, 2018
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
chongpohkit pushed a commit to chongpohkit/ubuntu-bionic that referenced this issue Feb 18, 2019
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
big-henry pushed a commit to big-henry/mirror_ubuntu-bionic-kernel that referenced this issue Feb 17, 2020
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
YadongQi pushed a commit to YadongQi/ubuntu-bionic that referenced this issue Mar 10, 2020
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
jai-raptee pushed a commit to jai-raptee/iliteck1 that referenced this issue Apr 30, 2024
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Clome pushed a commit to Clome/ubuntu-kernel that referenced this issue Jul 2, 2024
The AUX block has a shared interrupt line with a register indicating
which devices have active IRQs. Expose this as a nested interrupt
controller to avoid sharing problems.

See: raspberrypi/linux#1484
     raspberrypi/linux#1573

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants