2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* i2c-pca-isa.c driver for PCA9564 on ISA boards
|
|
|
|
* Copyright (C) 2004 Arcom Control Systems
|
2008-04-22 20:16:46 +00:00
|
|
|
* Copyright (C) 2008 Pengutronix
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2009-03-28 20:34:45 +00:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/wait.h>
|
2007-05-01 21:26:30 +00:00
|
|
|
#include <linux/isa.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/i2c-algo-pca.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
2008-04-22 20:16:46 +00:00
|
|
|
#define DRIVER "i2c-pca-isa"
|
2005-04-16 22:20:36 +00:00
|
|
|
#define IO_SIZE 4
|
|
|
|
|
2008-10-14 15:30:03 +00:00
|
|
|
static unsigned long base;
|
|
|
|
static int irq = -1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Data sheet recommends 59kHz for 100kHz operation due to variation
|
|
|
|
* in the actual clock rate */
|
2009-03-28 20:34:44 +00:00
|
|
|
static int clock = 59000;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-28 20:34:45 +00:00
|
|
|
static struct i2c_adapter pca_isa_ops;
|
2005-04-16 22:20:36 +00:00
|
|
|
static wait_queue_head_t pca_wait;
|
|
|
|
|
2008-04-22 20:16:46 +00:00
|
|
|
static void pca_isa_writebyte(void *pd, int reg, int val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
static char *names[] = { "T/O", "DAT", "ADR", "CON" };
|
2009-03-28 20:34:42 +00:00
|
|
|
printk(KERN_DEBUG "*** write %s at %#lx <= %#04x\n", names[reg],
|
|
|
|
base+reg, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
outb(val, base+reg);
|
|
|
|
}
|
|
|
|
|
2008-04-22 20:16:46 +00:00
|
|
|
static int pca_isa_readbyte(void *pd, int reg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int res = inb(base+reg);
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
{
|
2008-04-22 20:16:46 +00:00
|
|
|
static char *names[] = { "STA", "DAT", "ADR", "CON" };
|
2009-03-28 20:34:42 +00:00
|
|
|
printk(KERN_DEBUG "*** read %s => %#04x\n", names[reg], res);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-04-22 20:16:46 +00:00
|
|
|
static int pca_isa_waitforcompletion(void *pd)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-03-28 20:34:45 +00:00
|
|
|
long ret = ~0;
|
|
|
|
unsigned long timeout;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (irq > -1) {
|
2009-03-28 20:34:45 +00:00
|
|
|
ret = wait_event_interruptible_timeout(pca_wait,
|
|
|
|
pca_isa_readbyte(pd, I2C_PCA_CON)
|
|
|
|
& I2C_PCA_CON_SI, pca_isa_ops.timeout);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2009-03-28 20:34:45 +00:00
|
|
|
/* Do polling */
|
|
|
|
timeout = jiffies + pca_isa_ops.timeout;
|
|
|
|
while (((pca_isa_readbyte(pd, I2C_PCA_CON)
|
|
|
|
& I2C_PCA_CON_SI) == 0)
|
|
|
|
&& (ret = time_before(jiffies, timeout)))
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(100);
|
|
|
|
}
|
2009-03-28 20:34:45 +00:00
|
|
|
return ret > 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-22 20:16:46 +00:00
|
|
|
static void pca_isa_resetchip(void *pd)
|
|
|
|
{
|
|
|
|
/* apparently only an external reset will do it. not a lot can be done */
|
|
|
|
printk(KERN_WARNING DRIVER ": Haven't figured out how to do a reset yet\n");
|
|
|
|
}
|
|
|
|
|
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 13:55:46 +00:00
|
|
|
static irqreturn_t pca_handler(int this_irq, void *dev_id) {
|
2005-04-16 22:20:36 +00:00
|
|
|
wake_up_interruptible(&pca_wait);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_algo_pca_data pca_isa_data = {
|
2008-04-22 20:16:46 +00:00
|
|
|
/* .data intentionally left NULL, not needed with ISA */
|
2005-04-16 22:20:36 +00:00
|
|
|
.write_byte = pca_isa_writebyte,
|
|
|
|
.read_byte = pca_isa_readbyte,
|
2008-04-22 20:16:46 +00:00
|
|
|
.wait_for_completion = pca_isa_waitforcompletion,
|
|
|
|
.reset_chip = pca_isa_resetchip,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_adapter pca_isa_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.algo_data = &pca_isa_data,
|
2009-03-28 20:34:44 +00:00
|
|
|
.name = "PCA9564/PCA9665 ISA Adapter",
|
2009-03-28 20:34:45 +00:00
|
|
|
.timeout = HZ,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-10-14 15:30:03 +00:00
|
|
|
static int __devinit pca_isa_match(struct device *dev, unsigned int id)
|
|
|
|
{
|
|
|
|
int match = base != 0;
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
if (irq <= -1)
|
|
|
|
dev_warn(dev, "Using polling mode (specify irq)\n");
|
|
|
|
} else
|
|
|
|
dev_err(dev, "Please specify I/O base\n");
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2007-05-01 21:26:30 +00:00
|
|
|
static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
init_waitqueue_head(&pca_wait);
|
|
|
|
|
2007-05-01 21:26:30 +00:00
|
|
|
dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-22 21:41:31 +00:00
|
|
|
#ifdef CONFIG_PPC
|
2008-02-24 19:03:42 +00:00
|
|
|
if (check_legacy_ioport(base)) {
|
|
|
|
dev_err(dev, "I/O address %#08lx is not available\n", base);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
|
2007-05-01 21:26:30 +00:00
|
|
|
dev_err(dev, "I/O address %#08lx is in use\n", base);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq > -1) {
|
|
|
|
if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
|
2007-05-01 21:26:30 +00:00
|
|
|
dev_err(dev, "Request irq%d failed\n", irq);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out_region;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-22 20:16:46 +00:00
|
|
|
pca_isa_data.i2c_clock = clock;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
|
2007-05-01 21:26:30 +00:00
|
|
|
dev_err(dev, "Failed to add i2c bus\n");
|
2005-04-16 22:20:36 +00: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 21:26:30 +00:00
|
|
|
static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-12-10 20:21:33 +00:00
|
|
|
i2c_del_adapter(&pca_isa_ops);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-10-14 15:30:03 +00:00
|
|
|
if (irq > -1) {
|
2005-04-16 22:20:36 +00:00
|
|
|
disable_irq(irq);
|
|
|
|
free_irq(irq, &pca_isa_ops);
|
|
|
|
}
|
|
|
|
release_region(base, IO_SIZE);
|
2007-05-01 21:26:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct isa_driver pca_isa_driver = {
|
2008-10-14 15:30:03 +00:00
|
|
|
.match = pca_isa_match,
|
2007-05-01 21:26:30 +00:00
|
|
|
.probe = pca_isa_probe,
|
|
|
|
.remove = __devexit_p(pca_isa_remove),
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-04-22 20:16:46 +00:00
|
|
|
.name = DRIVER,
|
2007-05-01 21:26:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
|
2009-03-28 20:34:44 +00:00
|
|
|
MODULE_DESCRIPTION("ISA base PCA9564/PCA9665 driver");
|
2005-04-16 22:20:36 +00:00
|
|
|
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);
|
2009-03-28 20:34:44 +00:00
|
|
|
MODULE_PARM_DESC(clock, "Clock rate in hertz.\n\t\t"
|
|
|
|
"For PCA9564: 330000,288000,217000,146000,"
|
|
|
|
"88000,59000,44000,36000\n"
|
|
|
|
"\t\tFor PCA9665:\tStandard: 60300 - 100099\n"
|
|
|
|
"\t\t\t\tFast: 100100 - 400099\n"
|
|
|
|
"\t\t\t\tFast+: 400100 - 10000099\n"
|
|
|
|
"\t\t\t\tTurbo: Up to 1265800");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
module_init(pca_isa_init);
|
|
|
|
module_exit(pca_isa_exit);
|