2008-08-30 05:34:14 +00:00
|
|
|
/* bbc_i2c.c: I2C low-level driver for BBC device on UltraSPARC-III
|
2005-04-16 22:20:36 +00:00
|
|
|
* platforms.
|
|
|
|
*
|
2008-08-30 05:34:14 +00:00
|
|
|
* Copyright (C) 2001, 2008 David S. Miller (davem@davemloft.net)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
2008-08-30 05:34:14 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/bbc.h>
|
2007-05-14 05:22:13 +00:00
|
|
|
#include <asm/io.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "bbc_i2c.h"
|
|
|
|
|
|
|
|
/* Convert this driver to use i2c bus layer someday... */
|
|
|
|
#define I2C_PCF_PIN 0x80
|
|
|
|
#define I2C_PCF_ESO 0x40
|
|
|
|
#define I2C_PCF_ES1 0x20
|
|
|
|
#define I2C_PCF_ES2 0x10
|
|
|
|
#define I2C_PCF_ENI 0x08
|
|
|
|
#define I2C_PCF_STA 0x04
|
|
|
|
#define I2C_PCF_STO 0x02
|
|
|
|
#define I2C_PCF_ACK 0x01
|
|
|
|
|
|
|
|
#define I2C_PCF_START (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_ENI | I2C_PCF_STA | I2C_PCF_ACK)
|
|
|
|
#define I2C_PCF_STOP (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
|
|
|
|
#define I2C_PCF_REPSTART ( I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
|
|
|
|
#define I2C_PCF_IDLE (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_ACK)
|
|
|
|
|
|
|
|
#define I2C_PCF_INI 0x40 /* 1 if not initialized */
|
|
|
|
#define I2C_PCF_STS 0x20
|
|
|
|
#define I2C_PCF_BER 0x10
|
|
|
|
#define I2C_PCF_AD0 0x08
|
|
|
|
#define I2C_PCF_LRB 0x08
|
|
|
|
#define I2C_PCF_AAS 0x04
|
|
|
|
#define I2C_PCF_LAB 0x02
|
|
|
|
#define I2C_PCF_BB 0x01
|
|
|
|
|
|
|
|
/* The BBC devices have two I2C controllers. The first I2C controller
|
|
|
|
* connects mainly to configuration proms (NVRAM, cpu configuration,
|
|
|
|
* dimm types, etc.). Whereas the second I2C controller connects to
|
|
|
|
* environmental control devices such as fans and temperature sensors.
|
|
|
|
* The second controller also connects to the smartcard reader, if present.
|
|
|
|
*/
|
|
|
|
|
2010-08-06 15:25:50 +00:00
|
|
|
static void set_device_claimage(struct bbc_i2c_bus *bp, struct platform_device *op, int val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_CHILDREN; i++) {
|
2008-08-30 05:34:14 +00:00
|
|
|
if (bp->devs[i].device == op) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bp->devs[i].client_claimed = val;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define claim_device(BP,ECHILD) set_device_claimage(BP,ECHILD,1)
|
|
|
|
#define release_device(BP,ECHILD) set_device_claimage(BP,ECHILD,0)
|
|
|
|
|
2010-08-06 15:25:50 +00:00
|
|
|
struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *bp, int index)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-08-06 15:25:50 +00:00
|
|
|
struct platform_device *op = NULL;
|
2008-08-30 05:34:14 +00:00
|
|
|
int curidx = 0, i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
for (i = 0; i < NUM_CHILDREN; i++) {
|
|
|
|
if (!(op = bp->devs[i].device))
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2008-08-30 05:34:14 +00:00
|
|
|
if (curidx == index)
|
|
|
|
goto out;
|
|
|
|
op = NULL;
|
|
|
|
curidx++;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (curidx == index)
|
2008-08-30 05:34:14 +00:00
|
|
|
return op;
|
2005-04-16 22:20:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-06 15:25:50 +00:00
|
|
|
struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *op)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct bbc_i2c_client *client;
|
2008-08-30 05:34:14 +00:00
|
|
|
const u32 *reg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 08:49:03 +00:00
|
|
|
client = kzalloc(sizeof(*client), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!client)
|
|
|
|
return NULL;
|
|
|
|
client->bp = bp;
|
2008-08-30 05:34:14 +00:00
|
|
|
client->op = op;
|
|
|
|
|
2010-04-13 23:12:29 +00:00
|
|
|
reg = of_get_property(op->dev.of_node, "reg", NULL);
|
2008-08-30 05:34:14 +00:00
|
|
|
if (!reg) {
|
|
|
|
kfree(client);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
client->bus = reg[0];
|
|
|
|
client->address = reg[1];
|
|
|
|
|
|
|
|
claim_device(bp, op);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bbc_i2c_detach(struct bbc_i2c_client *client)
|
|
|
|
{
|
|
|
|
struct bbc_i2c_bus *bp = client->bp;
|
2010-08-06 15:25:50 +00:00
|
|
|
struct platform_device *op = client->op;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
release_device(bp, op);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wait_for_pin(struct bbc_i2c_bus *bp, u8 *status)
|
|
|
|
{
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
int limit = 32;
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
bp->waiting = 1;
|
|
|
|
add_wait_queue(&bp->wq, &wait);
|
|
|
|
while (limit-- > 0) {
|
2009-03-04 08:19:28 +00:00
|
|
|
long val;
|
2007-02-26 18:11:35 +00:00
|
|
|
|
|
|
|
val = wait_event_interruptible_timeout(
|
|
|
|
bp->wq,
|
|
|
|
(((*status = readb(bp->i2c_control_regs + 0))
|
|
|
|
& I2C_PCF_PIN) == 0),
|
|
|
|
msecs_to_jiffies(250));
|
|
|
|
if (val > 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remove_wait_queue(&bp->wq, &wait);
|
|
|
|
bp->waiting = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bbc_i2c_writeb(struct bbc_i2c_client *client, unsigned char val, int off)
|
|
|
|
{
|
|
|
|
struct bbc_i2c_bus *bp = client->bp;
|
|
|
|
int address = client->address;
|
|
|
|
u8 status;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (bp->i2c_bussel_reg != NULL)
|
|
|
|
writeb(client->bus, bp->i2c_bussel_reg);
|
|
|
|
|
|
|
|
writeb(address, bp->i2c_control_regs + 0x1);
|
|
|
|
writeb(I2C_PCF_START, bp->i2c_control_regs + 0x0);
|
|
|
|
if (wait_for_pin(bp, &status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
writeb(off, bp->i2c_control_regs + 0x1);
|
|
|
|
if (wait_for_pin(bp, &status) ||
|
|
|
|
(status & I2C_PCF_LRB) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
writeb(val, bp->i2c_control_regs + 0x1);
|
|
|
|
if (wait_for_pin(bp, &status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
writeb(I2C_PCF_STOP, bp->i2c_control_regs + 0x0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bbc_i2c_readb(struct bbc_i2c_client *client, unsigned char *byte, int off)
|
|
|
|
{
|
|
|
|
struct bbc_i2c_bus *bp = client->bp;
|
|
|
|
unsigned char address = client->address, status;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (bp->i2c_bussel_reg != NULL)
|
|
|
|
writeb(client->bus, bp->i2c_bussel_reg);
|
|
|
|
|
|
|
|
writeb(address, bp->i2c_control_regs + 0x1);
|
|
|
|
writeb(I2C_PCF_START, bp->i2c_control_regs + 0x0);
|
|
|
|
if (wait_for_pin(bp, &status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
writeb(off, bp->i2c_control_regs + 0x1);
|
|
|
|
if (wait_for_pin(bp, &status) ||
|
|
|
|
(status & I2C_PCF_LRB) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
writeb(I2C_PCF_STOP, bp->i2c_control_regs + 0x0);
|
|
|
|
|
|
|
|
address |= 0x1; /* READ */
|
|
|
|
|
|
|
|
writeb(address, bp->i2c_control_regs + 0x1);
|
|
|
|
writeb(I2C_PCF_START, bp->i2c_control_regs + 0x0);
|
|
|
|
if (wait_for_pin(bp, &status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Set PIN back to one so the device sends the first
|
|
|
|
* byte.
|
|
|
|
*/
|
|
|
|
(void) readb(bp->i2c_control_regs + 0x1);
|
|
|
|
if (wait_for_pin(bp, &status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
writeb(I2C_PCF_ESO | I2C_PCF_ENI, bp->i2c_control_regs + 0x0);
|
|
|
|
*byte = readb(bp->i2c_control_regs + 0x1);
|
|
|
|
if (wait_for_pin(bp, &status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
writeb(I2C_PCF_STOP, bp->i2c_control_regs + 0x0);
|
|
|
|
(void) readb(bp->i2c_control_regs + 0x1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bbc_i2c_write_buf(struct bbc_i2c_client *client,
|
|
|
|
char *buf, int len, int off)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (len > 0) {
|
2011-11-21 21:42:20 +00:00
|
|
|
ret = bbc_i2c_writeb(client, *buf, off);
|
|
|
|
if (ret < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
len--;
|
|
|
|
buf++;
|
|
|
|
off++;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bbc_i2c_read_buf(struct bbc_i2c_client *client,
|
|
|
|
char *buf, int len, int off)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (len > 0) {
|
2011-11-21 21:42:20 +00:00
|
|
|
ret = bbc_i2c_readb(client, buf, off);
|
|
|
|
if (ret < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
len--;
|
|
|
|
buf++;
|
|
|
|
off++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_getdev);
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_attach);
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_detach);
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_writeb);
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_readb);
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_write_buf);
|
|
|
|
EXPORT_SYMBOL(bbc_i2c_read_buf);
|
|
|
|
|
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 bbc_i2c_interrupt(int irq, void *dev_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct bbc_i2c_bus *bp = dev_id;
|
|
|
|
|
|
|
|
/* PIN going from set to clear is the only event which
|
|
|
|
* makes the i2c assert an interrupt.
|
|
|
|
*/
|
|
|
|
if (bp->waiting &&
|
|
|
|
!(readb(bp->i2c_control_regs + 0x0) & I2C_PCF_PIN))
|
2007-02-26 18:11:35 +00:00
|
|
|
wake_up_interruptible(&bp->wq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-03-30 11:44:24 +00:00
|
|
|
static void reset_one_i2c(struct bbc_i2c_bus *bp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
writeb(I2C_PCF_PIN, bp->i2c_control_regs + 0x0);
|
|
|
|
writeb(bp->own, bp->i2c_control_regs + 0x1);
|
|
|
|
writeb(I2C_PCF_PIN | I2C_PCF_ES1, bp->i2c_control_regs + 0x0);
|
|
|
|
writeb(bp->clock, bp->i2c_control_regs + 0x1);
|
|
|
|
writeb(I2C_PCF_IDLE, bp->i2c_control_regs + 0x0);
|
|
|
|
}
|
|
|
|
|
2013-03-30 11:44:24 +00:00
|
|
|
static struct bbc_i2c_bus * attach_one_i2c(struct platform_device *op, int index)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-07-31 21:04:57 +00:00
|
|
|
struct bbc_i2c_bus *bp;
|
2008-08-30 05:34:14 +00:00
|
|
|
struct device_node *dp;
|
2005-04-16 22:20:36 +00:00
|
|
|
int entry;
|
|
|
|
|
2007-07-31 21:04:57 +00:00
|
|
|
bp = kzalloc(sizeof(*bp), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!bp)
|
2008-08-30 05:34:14 +00:00
|
|
|
return NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-08-03 13:44:52 +00:00
|
|
|
INIT_LIST_HEAD(&bp->temps);
|
|
|
|
INIT_LIST_HEAD(&bp->fans);
|
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
bp->i2c_control_regs = of_ioremap(&op->resource[0], 0, 0x2, "bbc_i2c_regs");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!bp->i2c_control_regs)
|
|
|
|
goto fail;
|
|
|
|
|
2014-08-03 13:44:52 +00:00
|
|
|
if (op->num_resources == 2) {
|
|
|
|
bp->i2c_bussel_reg = of_ioremap(&op->resource[1], 0, 0x1, "bbc_i2c_bussel");
|
|
|
|
if (!bp->i2c_bussel_reg)
|
|
|
|
goto fail;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
bp->waiting = 0;
|
|
|
|
init_waitqueue_head(&bp->wq);
|
2010-06-18 17:09:58 +00:00
|
|
|
if (request_irq(op->archdata.irqs[0], bbc_i2c_interrupt,
|
2006-07-02 02:29:38 +00:00
|
|
|
IRQF_SHARED, "bbc_i2c", bp))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
bp->index = index;
|
2008-08-30 05:34:14 +00:00
|
|
|
bp->op = op;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_init(&bp->lock);
|
|
|
|
|
|
|
|
entry = 0;
|
2010-04-13 23:12:29 +00:00
|
|
|
for (dp = op->dev.of_node->child;
|
2008-08-30 05:34:14 +00:00
|
|
|
dp && entry < 8;
|
|
|
|
dp = dp->sibling, entry++) {
|
2010-08-06 15:25:50 +00:00
|
|
|
struct platform_device *child_op;
|
2008-08-30 05:34:14 +00:00
|
|
|
|
|
|
|
child_op = of_find_device_by_node(dp);
|
|
|
|
bp->devs[entry].device = child_op;
|
2005-04-16 22:20:36 +00:00
|
|
|
bp->devs[entry].client_claimed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
writeb(I2C_PCF_PIN, bp->i2c_control_regs + 0x0);
|
|
|
|
bp->own = readb(bp->i2c_control_regs + 0x01);
|
|
|
|
writeb(I2C_PCF_PIN | I2C_PCF_ES1, bp->i2c_control_regs + 0x0);
|
|
|
|
bp->clock = readb(bp->i2c_control_regs + 0x01);
|
|
|
|
|
|
|
|
printk(KERN_INFO "i2c-%d: Regs at %p, %d devices, own %02x, clock %02x.\n",
|
|
|
|
bp->index, bp->i2c_control_regs, entry, bp->own, bp->clock);
|
|
|
|
|
|
|
|
reset_one_i2c(bp);
|
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
return bp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if (bp->i2c_bussel_reg)
|
2008-08-30 05:34:14 +00:00
|
|
|
of_iounmap(&op->resource[1], bp->i2c_bussel_reg, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (bp->i2c_control_regs)
|
2008-08-30 05:34:14 +00:00
|
|
|
of_iounmap(&op->resource[0], bp->i2c_control_regs, 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(bp);
|
2008-08-30 05:34:14 +00:00
|
|
|
return NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
extern int bbc_envctrl_init(struct bbc_i2c_bus *bp);
|
|
|
|
extern void bbc_envctrl_cleanup(struct bbc_i2c_bus *bp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-12-21 21:24:23 +00:00
|
|
|
static int bbc_i2c_probe(struct platform_device *op)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-08-30 05:34:14 +00:00
|
|
|
struct bbc_i2c_bus *bp;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err, index = 0;
|
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
bp = attach_one_i2c(op, index);
|
|
|
|
if (!bp)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
err = bbc_envctrl_init(bp);
|
|
|
|
if (err) {
|
2010-06-18 17:09:58 +00:00
|
|
|
free_irq(op->archdata.irqs[0], bp);
|
2008-08-30 05:34:14 +00:00
|
|
|
if (bp->i2c_bussel_reg)
|
|
|
|
of_iounmap(&op->resource[0], bp->i2c_bussel_reg, 1);
|
|
|
|
if (bp->i2c_control_regs)
|
|
|
|
of_iounmap(&op->resource[1], bp->i2c_control_regs, 2);
|
|
|
|
kfree(bp);
|
|
|
|
} else {
|
|
|
|
dev_set_drvdata(&op->dev, bp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-21 21:24:23 +00:00
|
|
|
static int bbc_i2c_remove(struct platform_device *op)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-08-30 05:34:14 +00:00
|
|
|
struct bbc_i2c_bus *bp = dev_get_drvdata(&op->dev);
|
|
|
|
|
|
|
|
bbc_envctrl_cleanup(bp);
|
|
|
|
|
2010-06-18 17:09:58 +00:00
|
|
|
free_irq(op->archdata.irqs[0], bp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
if (bp->i2c_bussel_reg)
|
|
|
|
of_iounmap(&op->resource[0], bp->i2c_bussel_reg, 1);
|
|
|
|
if (bp->i2c_control_regs)
|
|
|
|
of_iounmap(&op->resource[1], bp->i2c_control_regs, 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
kfree(bp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-30 05:34:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-31 08:23:17 +00:00
|
|
|
static const struct of_device_id bbc_i2c_match[] = {
|
2008-08-30 05:34:14 +00:00
|
|
|
{
|
|
|
|
.name = "i2c",
|
|
|
|
.compatible = "SUNW,bbc-i2c",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, bbc_i2c_match);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-02-23 03:01:33 +00:00
|
|
|
static struct platform_driver bbc_i2c_driver = {
|
2010-04-13 23:13:02 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "bbc_i2c",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = bbc_i2c_match,
|
|
|
|
},
|
2008-08-30 05:34:14 +00:00
|
|
|
.probe = bbc_i2c_probe,
|
2012-12-21 21:24:23 +00:00
|
|
|
.remove = bbc_i2c_remove,
|
2008-08-30 05:34:14 +00:00
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-26 19:04:25 +00:00
|
|
|
module_platform_driver(bbc_i2c_driver);
|
2008-08-30 05:34:14 +00:00
|
|
|
|
2006-03-17 21:23:56 +00:00
|
|
|
MODULE_LICENSE("GPL");
|