2019-05-27 13:55:06 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* i2c-pca-isa.c driver for PCA9564 on ISA boards
|
|
|
|
* Copyright (C) 2004 Arcom Control Systems
|
2008-04-23 03:16:46 +07:00
|
|
|
* Copyright (C) 2008 Pengutronix
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/delay.h>
|
2009-03-29 03:34:45 +07:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/wait.h>
|
2007-05-02 04:26:30 +07:00
|
|
|
#include <linux/isa.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/i2c-algo-pca.h>
|
2010-05-21 23:41:01 +07:00
|
|
|
#include <linux/io.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
2008-04-23 03:16:46 +07:00
|
|
|
#define DRIVER "i2c-pca-isa"
|
2005-04-17 05:20:36 +07:00
|
|
|
#define IO_SIZE 4
|
|
|
|
|
2008-10-14 22:30:03 +07:00
|
|
|
static unsigned long base;
|
|
|
|
static int irq = -1;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Data sheet recommends 59kHz for 100kHz operation due to variation
|
|
|
|
* in the actual clock rate */
|
2009-03-29 03:34:44 +07:00
|
|
|
static int clock = 59000;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-03-29 03:34:45 +07:00
|
|
|
static struct i2c_adapter pca_isa_ops;
|
2005-04-17 05:20:36 +07:00
|
|
|
static wait_queue_head_t pca_wait;
|
|
|
|
|
2008-04-23 03:16:46 +07:00
|
|
|
static void pca_isa_writebyte(void *pd, int reg, int val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
static char *names[] = { "T/O", "DAT", "ADR", "CON" };
|
2009-03-29 03:34:42 +07:00
|
|
|
printk(KERN_DEBUG "*** write %s at %#lx <= %#04x\n", names[reg],
|
|
|
|
base+reg, val);
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
outb(val, base+reg);
|
|
|
|
}
|
|
|
|
|
2008-04-23 03:16:46 +07:00
|
|
|
static int pca_isa_readbyte(void *pd, int reg)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int res = inb(base+reg);
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
{
|
2008-04-23 03:16:46 +07:00
|
|
|
static char *names[] = { "STA", "DAT", "ADR", "CON" };
|
2009-03-29 03:34:42 +07:00
|
|
|
printk(KERN_DEBUG "*** read %s => %#04x\n", names[reg], res);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-04-23 03:16:46 +07:00
|
|
|
static int pca_isa_waitforcompletion(void *pd)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-03-29 03:34:45 +07:00
|
|
|
unsigned long timeout;
|
2010-09-30 19:14:22 +07:00
|
|
|
long ret;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (irq > -1) {
|
2010-01-17 02:43:13 +07:00
|
|
|
ret = wait_event_timeout(pca_wait,
|
2009-03-29 03:34:45 +07:00
|
|
|
pca_isa_readbyte(pd, I2C_PCA_CON)
|
|
|
|
& I2C_PCA_CON_SI, pca_isa_ops.timeout);
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
2009-03-29 03:34:45 +07:00
|
|
|
/* Do polling */
|
|
|
|
timeout = jiffies + pca_isa_ops.timeout;
|
2010-09-30 19:14:22 +07:00
|
|
|
do {
|
|
|
|
ret = time_before(jiffies, timeout);
|
|
|
|
if (pca_isa_readbyte(pd, I2C_PCA_CON)
|
|
|
|
& I2C_PCA_CON_SI)
|
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
udelay(100);
|
2010-09-30 19:14:22 +07:00
|
|
|
} while (ret);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2010-09-30 19:14:22 +07:00
|
|
|
|
2009-03-29 03:34:45 +07:00
|
|
|
return ret > 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-04-23 03:16:46 +07: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 20:55:46 +07:00
|
|
|
static irqreturn_t pca_handler(int this_irq, void *dev_id) {
|
2010-01-17 02:43:13 +07:00
|
|
|
wake_up(&pca_wait);
|
2005-04-17 05:20:36 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_algo_pca_data pca_isa_data = {
|
2008-04-23 03:16:46 +07:00
|
|
|
/* .data intentionally left NULL, not needed with ISA */
|
2005-04-17 05:20:36 +07:00
|
|
|
.write_byte = pca_isa_writebyte,
|
|
|
|
.read_byte = pca_isa_readbyte,
|
2008-04-23 03:16:46 +07:00
|
|
|
.wait_for_completion = pca_isa_waitforcompletion,
|
|
|
|
.reset_chip = pca_isa_resetchip,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_adapter pca_isa_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.algo_data = &pca_isa_data,
|
2009-03-29 03:34:44 +07:00
|
|
|
.name = "PCA9564/PCA9665 ISA Adapter",
|
2009-03-29 03:34:45 +07:00
|
|
|
.timeout = HZ,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2012-11-28 03:59:38 +07:00
|
|
|
static int pca_isa_match(struct device *dev, unsigned int id)
|
2008-10-14 22:30:03 +07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-28 03:59:38 +07:00
|
|
|
static int pca_isa_probe(struct device *dev, unsigned int id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
init_waitqueue_head(&pca_wait);
|
|
|
|
|
2007-05-02 04:26:30 +07:00
|
|
|
dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-09-23 04:41:31 +07:00
|
|
|
#ifdef CONFIG_PPC
|
2008-02-25 02:03:42 +07:00
|
|
|
if (check_legacy_ioport(base)) {
|
|
|
|
dev_err(dev, "I/O address %#08lx is not available\n", base);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
|
2007-05-02 04:26:30 +07:00
|
|
|
dev_err(dev, "I/O address %#08lx is in use\n", base);
|
2005-04-17 05:20:36 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq > -1) {
|
|
|
|
if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
|
2007-05-02 04:26:30 +07:00
|
|
|
dev_err(dev, "Request irq%d failed\n", irq);
|
2005-04-17 05:20:36 +07:00
|
|
|
goto out_region;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-23 03:16:46 +07:00
|
|
|
pca_isa_data.i2c_clock = clock;
|
2005-04-17 05:20:36 +07:00
|
|
|
if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
|
2007-05-02 04:26:30 +07:00
|
|
|
dev_err(dev, "Failed to add i2c bus\n");
|
2005-04-17 05:20:36 +07: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;
|
|
|
|
}
|
|
|
|
|
2012-11-28 03:59:38 +07:00
|
|
|
static int pca_isa_remove(struct device *dev, unsigned int id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-12-11 03:21:33 +07:00
|
|
|
i2c_del_adapter(&pca_isa_ops);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-10-14 22:30:03 +07:00
|
|
|
if (irq > -1) {
|
2005-04-17 05:20:36 +07:00
|
|
|
disable_irq(irq);
|
|
|
|
free_irq(irq, &pca_isa_ops);
|
|
|
|
}
|
|
|
|
release_region(base, IO_SIZE);
|
2007-05-02 04:26:30 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct isa_driver pca_isa_driver = {
|
2008-10-14 22:30:03 +07:00
|
|
|
.match = pca_isa_match,
|
2007-05-02 04:26:30 +07:00
|
|
|
.probe = pca_isa_probe,
|
2012-11-28 03:59:38 +07:00
|
|
|
.remove = pca_isa_remove,
|
2007-05-02 04:26:30 +07:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-04-23 03:16:46 +07:00
|
|
|
.name = DRIVER,
|
2007-05-02 04:26:30 +07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
|
2009-03-29 03:34:44 +07:00
|
|
|
MODULE_DESCRIPTION("ISA base PCA9564/PCA9665 driver");
|
2005-04-17 05:20:36 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2017-04-04 22:54:23 +07:00
|
|
|
module_param_hw(base, ulong, ioport, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
MODULE_PARM_DESC(base, "I/O base address");
|
2017-04-04 22:54:23 +07:00
|
|
|
module_param_hw(irq, int, irq, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
MODULE_PARM_DESC(irq, "IRQ");
|
|
|
|
module_param(clock, int, 0);
|
2009-03-29 03:34:44 +07: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");
|
2016-05-31 23:22:34 +07:00
|
|
|
module_isa_driver(pca_isa_driver, 1);
|