2005-04-16 22:20:36 +00:00
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes */
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
/* Copyright (C) 1995-97 Simon G. Vogl
|
|
|
|
|
1998-99 Hans Berglund
|
|
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/* With some changes from Ky<4B>sti M<>lkki <kmalkki@cc.hut.fi> and even
|
|
|
|
|
Frodo Looijaard <frodol@dds.nl> */
|
|
|
|
|
|
2005-10-07 22:23:27 +00:00
|
|
|
|
/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of
|
2005-04-16 22:20:36 +00:00
|
|
|
|
for Alpha Processor Inc. UP-2000(+) boards */
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
#include <linux/wait.h>
|
|
|
|
|
|
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
|
#include <linux/i2c-algo-pcf.h>
|
|
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
|
|
#include "../algos/i2c-algo-pcf.h"
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_BASE 0x330
|
|
|
|
|
|
|
|
|
|
static int base;
|
2005-10-07 22:21:48 +00:00
|
|
|
|
static u8 __iomem *base_iomem;
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
static int irq;
|
|
|
|
|
static int clock = 0x1c;
|
|
|
|
|
static int own = 0x55;
|
|
|
|
|
static int mmapped;
|
|
|
|
|
|
2005-10-07 22:23:27 +00:00
|
|
|
|
/* vdovikin: removed static struct i2c_pcf_isa gpi; code -
|
2005-04-16 22:20:36 +00:00
|
|
|
|
this module in real supports only one device, due to missing arguments
|
|
|
|
|
in some functions, called from the algo-pcf module. Sometimes it's
|
|
|
|
|
need to be rewriten - but for now just remove this for simpler reading */
|
|
|
|
|
|
|
|
|
|
static wait_queue_head_t pcf_wait;
|
|
|
|
|
static int pcf_pending;
|
|
|
|
|
static spinlock_t lock;
|
|
|
|
|
|
2005-10-07 22:23:27 +00:00
|
|
|
|
static struct i2c_adapter pcf_isa_ops;
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
/* ----- local functions ---------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
static void pcf_isa_setbyte(void *data, int ctl, int val)
|
|
|
|
|
{
|
2005-10-07 22:21:48 +00:00
|
|
|
|
u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
/* enable irq if any specified for serial operation */
|
|
|
|
|
if (ctl && irq && (val & I2C_PCF_ESO)) {
|
|
|
|
|
val |= I2C_PCF_ENI;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-07 22:23:27 +00:00
|
|
|
|
pr_debug("%s: Write %p 0x%02X\n", pcf_isa_ops.name, address, val);
|
2005-10-07 22:21:48 +00:00
|
|
|
|
iowrite8(val, address);
|
|
|
|
|
#ifdef __alpha__
|
|
|
|
|
/* API UP2000 needs some hardware fudging to make the write stick */
|
|
|
|
|
iowrite8(val, address);
|
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int pcf_isa_getbyte(void *data, int ctl)
|
|
|
|
|
{
|
2005-10-07 22:21:48 +00:00
|
|
|
|
u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
|
|
|
|
|
int val = ioread8(address);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
2005-10-07 22:23:27 +00:00
|
|
|
|
pr_debug("%s: Read %p 0x%02X\n", pcf_isa_ops.name, address, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
return (val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int pcf_isa_getown(void *data)
|
|
|
|
|
{
|
|
|
|
|
return (own);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int pcf_isa_getclock(void *data)
|
|
|
|
|
{
|
|
|
|
|
return (clock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void pcf_isa_waitforpin(void) {
|
|
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
|
int timeout = 2;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
if (irq > 0) {
|
|
|
|
|
spin_lock_irqsave(&lock, flags);
|
|
|
|
|
if (pcf_pending == 0) {
|
|
|
|
|
spin_unlock_irqrestore(&lock, flags);
|
|
|
|
|
prepare_to_wait(&pcf_wait, &wait, TASK_INTERRUPTIBLE);
|
|
|
|
|
if (schedule_timeout(timeout*HZ)) {
|
|
|
|
|
spin_lock_irqsave(&lock, flags);
|
|
|
|
|
if (pcf_pending == 1) {
|
|
|
|
|
pcf_pending = 0;
|
|
|
|
|
}
|
|
|
|
|
spin_unlock_irqrestore(&lock, flags);
|
|
|
|
|
}
|
|
|
|
|
finish_wait(&pcf_wait, &wait);
|
|
|
|
|
} else {
|
|
|
|
|
pcf_pending = 0;
|
|
|
|
|
spin_unlock_irqrestore(&lock, flags);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
udelay(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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 pcf_isa_handler(int this_irq, void *dev_id) {
|
2005-04-16 22:20:36 +00:00
|
|
|
|
spin_lock(&lock);
|
|
|
|
|
pcf_pending = 1;
|
|
|
|
|
spin_unlock(&lock);
|
|
|
|
|
wake_up_interruptible(&pcf_wait);
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int pcf_isa_init(void)
|
|
|
|
|
{
|
|
|
|
|
spin_lock_init(&lock);
|
|
|
|
|
if (!mmapped) {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
if (!request_region(base, 2, pcf_isa_ops.name)) {
|
|
|
|
|
printk(KERN_ERR "%s: requested I/O region (%#x:2) is "
|
|
|
|
|
"in use\n", pcf_isa_ops.name, base);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
2005-10-07 22:21:48 +00:00
|
|
|
|
base_iomem = ioport_map(base, 2);
|
|
|
|
|
if (!base_iomem) {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
printk(KERN_ERR "%s: remap of I/O region %#x failed\n",
|
|
|
|
|
pcf_isa_ops.name, base);
|
2005-10-07 22:21:48 +00:00
|
|
|
|
release_region(base, 2);
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
if (!request_mem_region(base, 2, pcf_isa_ops.name)) {
|
|
|
|
|
printk(KERN_ERR "%s: requested memory region (%#x:2) "
|
|
|
|
|
"is in use\n", pcf_isa_ops.name, base);
|
2005-10-07 22:21:48 +00:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
base_iomem = ioremap(base, 2);
|
|
|
|
|
if (base_iomem == NULL) {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
printk(KERN_ERR "%s: remap of memory region %#x "
|
|
|
|
|
"failed\n", pcf_isa_ops.name, base);
|
2005-10-07 22:21:48 +00:00
|
|
|
|
release_mem_region(base, 2);
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
}
|
2005-10-07 22:23:27 +00:00
|
|
|
|
pr_debug("%s: registers %#x remapped to %p\n", pcf_isa_ops.name, base,
|
2005-10-07 22:21:48 +00:00
|
|
|
|
base_iomem);
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
if (irq > 0) {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
if (request_irq(irq, pcf_isa_handler, 0, pcf_isa_ops.name,
|
|
|
|
|
NULL) < 0) {
|
|
|
|
|
printk(KERN_ERR "%s: Request irq%d failed\n",
|
|
|
|
|
pcf_isa_ops.name, irq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
irq = 0;
|
|
|
|
|
} else
|
|
|
|
|
enable_irq(irq);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
|
* Encapsulate the above functions in the correct operations structure.
|
|
|
|
|
* This is only done when more than one hardware adapter is supported.
|
|
|
|
|
*/
|
|
|
|
|
static struct i2c_algo_pcf_data pcf_isa_data = {
|
|
|
|
|
.setpcf = pcf_isa_setbyte,
|
|
|
|
|
.getpcf = pcf_isa_getbyte,
|
|
|
|
|
.getown = pcf_isa_getown,
|
|
|
|
|
.getclock = pcf_isa_getclock,
|
|
|
|
|
.waitforpin = pcf_isa_waitforpin,
|
|
|
|
|
.udelay = 10,
|
|
|
|
|
.timeout = 100,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct i2c_adapter pcf_isa_ops = {
|
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
|
.class = I2C_CLASS_HWMON,
|
|
|
|
|
.id = I2C_HW_P_ELEK,
|
|
|
|
|
.algo_data = &pcf_isa_data,
|
2005-10-07 22:23:27 +00:00
|
|
|
|
.name = "i2c-elektor",
|
2005-04-16 22:20:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-10-07 22:23:27 +00:00
|
|
|
|
static int __init i2c_pcfisa_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
{
|
|
|
|
|
#ifdef __alpha__
|
2005-10-07 22:23:27 +00:00
|
|
|
|
/* check to see we have memory mapped PCF8584 connected to the
|
2005-04-16 22:20:36 +00:00
|
|
|
|
Cypress cy82c693 PCI-ISA bridge as on UP2000 board */
|
|
|
|
|
if (base == 0) {
|
|
|
|
|
struct pci_dev *cy693_dev;
|
2005-10-07 22:23:27 +00:00
|
|
|
|
|
|
|
|
|
cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ,
|
2005-04-16 22:20:36 +00:00
|
|
|
|
PCI_DEVICE_ID_CONTAQ_82C693, NULL);
|
|
|
|
|
if (cy693_dev) {
|
2005-10-07 22:21:48 +00:00
|
|
|
|
unsigned char config;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
/* yeap, we've found cypress, let's check config */
|
|
|
|
|
if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
|
|
|
|
|
pr_debug("%s: found cy82c693, config "
|
|
|
|
|
"register 0x47 = 0x%02x\n",
|
|
|
|
|
pcf_isa_ops.name, config);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
/* UP2000 board has this register set to 0xe1,
|
2005-10-07 22:23:27 +00:00
|
|
|
|
but the most significant bit as seems can be
|
2005-04-16 22:20:36 +00:00
|
|
|
|
reset during the proper initialisation
|
2005-10-07 22:23:27 +00:00
|
|
|
|
sequence if guys from API decides to do that
|
|
|
|
|
(so, we can even enable Tsunami Pchip
|
|
|
|
|
window for the upper 1 Gb) */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
/* so just check for ROMCS at 0xe0000,
|
2005-10-07 22:23:27 +00:00
|
|
|
|
ROMCS enabled for writes
|
2005-04-16 22:20:36 +00:00
|
|
|
|
and external XD Bus buffer in use. */
|
|
|
|
|
if ((config & 0x7f) == 0x61) {
|
|
|
|
|
/* seems to be UP2000 like board */
|
|
|
|
|
base = 0xe0000;
|
2005-10-07 22:21:48 +00:00
|
|
|
|
mmapped = 1;
|
2005-10-07 22:23:27 +00:00
|
|
|
|
/* UP2000 drives ISA with
|
2005-04-16 22:20:36 +00:00
|
|
|
|
8.25 MHz (PCI/4) clock
|
|
|
|
|
(this can be read from cypress) */
|
|
|
|
|
clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
|
2005-10-07 22:23:27 +00:00
|
|
|
|
pr_info("%s: found API UP2000 like "
|
|
|
|
|
"board, will probe PCF8584 "
|
|
|
|
|
"later\n", pcf_isa_ops.name);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pci_dev_put(cy693_dev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* sanity checks for mmapped I/O */
|
|
|
|
|
if (mmapped && base < 0xc8000) {
|
2005-10-07 22:23:27 +00:00
|
|
|
|
printk(KERN_ERR "%s: incorrect base address (%#x) specified "
|
|
|
|
|
"for mmapped I/O\n", pcf_isa_ops.name, base);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (base == 0) {
|
|
|
|
|
base = DEFAULT_BASE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_waitqueue_head(&pcf_wait);
|
|
|
|
|
if (pcf_isa_init())
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
|
|
|
|
|
goto fail;
|
2005-10-07 22:23:27 +00:00
|
|
|
|
|
|
|
|
|
dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
if (irq > 0) {
|
|
|
|
|
disable_irq(irq);
|
|
|
|
|
free_irq(irq, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-07 22:21:48 +00:00
|
|
|
|
if (!mmapped) {
|
|
|
|
|
ioport_unmap(base_iomem);
|
2005-10-07 22:23:27 +00:00
|
|
|
|
release_region(base, 2);
|
2005-10-07 22:21:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
iounmap(base_iomem);
|
|
|
|
|
release_mem_region(base, 2);
|
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void i2c_pcfisa_exit(void)
|
|
|
|
|
{
|
|
|
|
|
i2c_pcf_del_bus(&pcf_isa_ops);
|
|
|
|
|
|
|
|
|
|
if (irq > 0) {
|
|
|
|
|
disable_irq(irq);
|
|
|
|
|
free_irq(irq, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-07 22:21:48 +00:00
|
|
|
|
if (!mmapped) {
|
|
|
|
|
ioport_unmap(base_iomem);
|
2005-10-07 22:23:27 +00:00
|
|
|
|
release_region(base, 2);
|
2005-10-07 22:21:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
iounmap(base_iomem);
|
|
|
|
|
release_mem_region(base, 2);
|
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
|
|
|
|
|
MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
|
|
module_param(base, int, 0);
|
|
|
|
|
module_param(irq, int, 0);
|
|
|
|
|
module_param(clock, int, 0);
|
|
|
|
|
module_param(own, int, 0);
|
|
|
|
|
module_param(mmapped, int, 0);
|
|
|
|
|
|
|
|
|
|
module_init(i2c_pcfisa_init);
|
|
|
|
|
module_exit(i2c_pcfisa_exit);
|