2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* i2c-pca-isa.c driver for PCA9564 on ISA boards
|
|
|
|
* Copyright (C) 2004 Arcom Control Systems
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
|
2007-05-01 23:26:30 +02:00
|
|
|
#include <linux/isa.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/i2c-algo-pca.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
#include "../algos/i2c-algo-pca.h"
|
|
|
|
|
|
|
|
#define IO_SIZE 4
|
|
|
|
|
|
|
|
#undef DEBUG_IO
|
|
|
|
//#define DEBUG_IO
|
|
|
|
|
|
|
|
static unsigned long base = 0x330;
|
|
|
|
static int irq = 10;
|
|
|
|
|
|
|
|
/* Data sheet recommends 59kHz for 100kHz operation due to variation
|
|
|
|
* in the actual clock rate */
|
|
|
|
static int clock = I2C_PCA_CON_59kHz;
|
|
|
|
|
|
|
|
static int own = 0x55;
|
|
|
|
|
|
|
|
static wait_queue_head_t pca_wait;
|
|
|
|
|
|
|
|
static int pca_isa_getown(struct i2c_algo_pca_data *adap)
|
|
|
|
{
|
|
|
|
return (own);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pca_isa_getclock(struct i2c_algo_pca_data *adap)
|
|
|
|
{
|
|
|
|
return (clock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
static char *names[] = { "T/O", "DAT", "ADR", "CON" };
|
|
|
|
printk("*** write %s at %#lx <= %#04x\n", names[reg], base+reg, val);
|
|
|
|
#endif
|
|
|
|
outb(val, base+reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pca_isa_readbyte(struct i2c_algo_pca_data *adap, int reg)
|
|
|
|
{
|
|
|
|
int res = inb(base+reg);
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
{
|
|
|
|
static char *names[] = { "STA", "DAT", "ADR", "CON" };
|
|
|
|
printk("*** read %s => %#04x\n", names[reg], res);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pca_isa_waitforinterrupt(struct i2c_algo_pca_data *adap)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (irq > -1) {
|
|
|
|
ret = wait_event_interruptible(pca_wait,
|
|
|
|
pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI);
|
|
|
|
} else {
|
|
|
|
while ((pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0)
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 15:55:46 +02:00
|
|
|
static irqreturn_t pca_handler(int this_irq, void *dev_id) {
|
2005-04-17 00:20:36 +02:00
|
|
|
wake_up_interruptible(&pca_wait);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_algo_pca_data pca_isa_data = {
|
|
|
|
.get_own = pca_isa_getown,
|
|
|
|
.get_clock = pca_isa_getclock,
|
|
|
|
.write_byte = pca_isa_writebyte,
|
|
|
|
.read_byte = pca_isa_readbyte,
|
|
|
|
.wait_for_interrupt = pca_isa_waitforinterrupt,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_adapter pca_isa_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.id = I2C_HW_A_ISA,
|
|
|
|
.algo_data = &pca_isa_data,
|
|
|
|
.name = "PCA9564 ISA Adapter",
|
|
|
|
};
|
|
|
|
|
2007-05-01 23:26:30 +02:00
|
|
|
static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
init_waitqueue_head(&pca_wait);
|
|
|
|
|
2007-05-01 23:26:30 +02:00
|
|
|
dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
|
2007-05-01 23:26:30 +02:00
|
|
|
dev_err(dev, "I/O address %#08lx is in use\n", base);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq > -1) {
|
|
|
|
if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
|
2007-05-01 23:26:30 +02:00
|
|
|
dev_err(dev, "Request irq%d failed\n", irq);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto out_region;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
|
2007-05-01 23:26:30 +02:00
|
|
|
dev_err(dev, "Failed to add i2c bus\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto out_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_irq:
|
|
|
|
if (irq > -1)
|
|
|
|
free_irq(irq, &pca_isa_ops);
|
|
|
|
out_region:
|
|
|
|
release_region(base, IO_SIZE);
|
|
|
|
out:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:30 +02:00
|
|
|
static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-12-10 21:21:33 +01:00
|
|
|
i2c_del_adapter(&pca_isa_ops);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (irq > 0) {
|
|
|
|
disable_irq(irq);
|
|
|
|
free_irq(irq, &pca_isa_ops);
|
|
|
|
}
|
|
|
|
release_region(base, IO_SIZE);
|
2007-05-01 23:26:30 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct isa_driver pca_isa_driver = {
|
|
|
|
.probe = pca_isa_probe,
|
|
|
|
.remove = __devexit_p(pca_isa_remove),
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "i2c-pca-isa",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pca_isa_init(void)
|
|
|
|
{
|
|
|
|
return isa_register_driver(&pca_isa_driver, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit pca_isa_exit(void)
|
|
|
|
{
|
|
|
|
isa_unregister_driver(&pca_isa_driver);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
|
|
|
|
MODULE_DESCRIPTION("ISA base PCA9564 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_param(base, ulong, 0);
|
|
|
|
MODULE_PARM_DESC(base, "I/O base address");
|
|
|
|
|
|
|
|
module_param(irq, int, 0);
|
|
|
|
MODULE_PARM_DESC(irq, "IRQ");
|
|
|
|
module_param(clock, int, 0);
|
|
|
|
MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet");
|
|
|
|
|
|
|
|
module_param(own, int, 0); /* the driver can't do slave mode, so there's no real point in this */
|
|
|
|
|
|
|
|
module_init(pca_isa_init);
|
|
|
|
module_exit(pca_isa_exit);
|