LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 08-23-2010, 04:42 PM   #1
Peatmoss
Member
 
Registered: Nov 2007
Location: Vancouver
Distribution: Ubuntu 7.10
Posts: 44

Rep: Reputation: 15
First Time - Trying to Use GPIO Expander Driver called pca953x.c


Hi

I’ve been adding a GPIO expander chip to my marvell pxa310 development board. The CPU core is an ARM processor and the kernel I’ve got is 2.6.28. The driver I’ve been trying to use is the

/drivers/gpio/pca359x.c

The driver has a lot of code related to interrupts which I mostly understand now, but I’m stuck on a basic problem – what should I define the “.irq” value in the i2c_board_info structure? The GPIO expander chip has an interrupt signal which I’ve connected to GPIO125.

On the Marvell PXA310, GPIOs 2 through 127 share a common IRQ – number 10, or GPIO_IRQ_2_x. It seems logical that I should assign the irq value to GPIO_IRQ_2_x. There is a confusing bit of code in the pca953x.c driver where it sets up interrupts:

Quote:
for (irq = irq_start; irq < irq_start + chip->gpio_chip.ngpio; irq++) {
set_irq_chip(irq, ic);
set_irq_chip_data(irq, chip);
set_irq_handler(irq, handle_edge_irq);
set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
}

set_irq_type(chip->irq, IRQT_FALLING);
set_irq_data(chip->irq, chip);
set_irq_chained_handler(chip->irq, pca953x_irq_demux);
This for loop goes on to install a handler, etc. for each of the GPIO lines in this chip (total of 8). The control variable of the for loop is the irq number itself. If it starts at number 10 and loops 8 times, it will install irq_handler functions overtop of irq’s 10 through 17. That’s my confusion – IRQs 11 through 17 have nothing to do with GPIOs. I wonder how this works, whether installing handlers on these IRQs will clobber any IRQs that may already be set there by other device drivers, etc.

Documentation/IRQ.txt wasn’t very helpful. I need more detail. If anyone can point me at a book, website, article, etc. that serves as a good programmer’s reference to Linux’s kernel/irq/chip.c mechanisms, I’d be grateful. If anyone has a quick answer or two that can shed some light on my confusion I’d welcome that too.

Thanks for reading my long post.

Peat

Last edited by Peatmoss; 08-23-2010 at 04:45 PM. Reason: Added quotes around code snippet
 
Old 08-23-2010, 05:44 PM   #2
Peatmoss
Member
 
Registered: Nov 2007
Location: Vancouver
Distribution: Ubuntu 7.10
Posts: 44

Original Poster
Rep: Reputation: 15
Update

I've discovered an important clue to what's going on - but still confused.

The driver - pca953x.c - uses two different numbers for IRQs. The first one is the one you define within the i2c_board_info structure. The second one is the one used for the "for" loop I mentioned in my first post. This comes from a call to function:

gpio_to_irq( chip->gpio_start);

and I've selected gpio_start to be 192 in my machine. That function returns a value 288 and this is the value used in the for loop.

So now I'm guessing that the base vector - 10 in this case - triggers the whole show; when the GPIO expander chip generates the interrupt, the handler for irq 10 is invoked. Then, a miracle happens, and somehow the handlers for IRQs 288 through 295 are invoked, depending upon the GPIO Line(s) on the chip that changed to generate the interrupt.

The value of 288 is computed from a long string of pre-processor macros by adding my base GPIO number (which I arbitrarily selected) to 96:

192+96 = 288

Cheers,

Peat

Last edited by Peatmoss; 08-23-2010 at 05:53 PM. Reason: Corrected spelling of driver name
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ppc4xx gpio driver not loading using arch_initcall max21226 Linux - Kernel 3 08-31-2010 11:04 AM
GPIO driver for MPC837xerdb ramukaka Linux - Kernel 1 08-15-2010 09:29 PM
Using GPIO (from kernel GPIO support) in MY application DannyGilbert Linux - Kernel 2 03-16-2009 07:52 AM
getenv Returns different pointers every time it is called? worldgnat Programming 3 08-15-2008 09:58 PM
GPIO driver for Intel 6300ESB I/O Controller lartip Linux - Software 0 03-13-2007 05:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration