2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2006-10-04 04:01:26 +07:00
|
|
|
* drivers/i2c/busses/i2c-ibm_iic.c
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Support for the IIC peripheral on IBM PPC 4xx
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003, 2004 Zultys Technologies.
|
|
|
|
* Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
|
|
|
|
*
|
2008-04-23 03:16:47 +07:00
|
|
|
* Copyright (c) 2008 PIKA Technologies
|
|
|
|
* Sean MacLennan <smaclennan@pikatech.com>
|
|
|
|
*
|
2008-01-28 00:14:45 +07:00
|
|
|
* Based on original work by
|
2005-04-17 05:20:36 +07:00
|
|
|
* Ian DaSilva <idasilva@mvista.com>
|
|
|
|
* Armin Kuster <akuster@mvista.com>
|
|
|
|
* Matt Porter <mporter@mvista.com>
|
|
|
|
*
|
|
|
|
* Copyright 2000-2003 MontaVista Software Inc.
|
|
|
|
*
|
|
|
|
* Original driver version was highly leveraged from i2c-elektor.c
|
|
|
|
*
|
|
|
|
* Copyright 1995-97 Simon G. Vogl
|
|
|
|
* 1998-99 Hans Berglund
|
|
|
|
*
|
2007-10-20 04:21:04 +07:00
|
|
|
* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>
|
2005-04-17 05:20:36 +07:00
|
|
|
* and even Frodo Looijaard <frodol@dds.nl>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <asm/irq.h>
|
2010-05-21 23:41:01 +07:00
|
|
|
#include <linux/io.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/i2c.h>
|
2013-09-18 02:28:33 +07:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2008-04-23 03:16:47 +07:00
|
|
|
#include <linux/of_platform.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include "i2c-ibm_iic.h"
|
|
|
|
|
2008-04-23 03:16:47 +07:00
|
|
|
#define DRIVER_VERSION "2.2"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("IBM IIC driver v" DRIVER_VERSION);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool iic_force_poll;
|
2005-04-17 05:20:36 +07:00
|
|
|
module_param(iic_force_poll, bool, 0);
|
|
|
|
MODULE_PARM_DESC(iic_force_poll, "Force polling mode");
|
|
|
|
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool iic_force_fast;
|
2005-04-17 05:20:36 +07:00
|
|
|
module_param(iic_force_fast, bool, 0);
|
2008-04-11 17:07:04 +07:00
|
|
|
MODULE_PARM_DESC(iic_force_fast, "Force fast mode (400 kHz)");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define DBG_LEVEL 0
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
#undef DBG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DBG2
|
|
|
|
#undef DBG2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DBG_LEVEL > 0
|
|
|
|
# define DBG(f,x...) printk(KERN_DEBUG "ibm-iic" f, ##x)
|
|
|
|
#else
|
|
|
|
# define DBG(f,x...) ((void)0)
|
|
|
|
#endif
|
|
|
|
#if DBG_LEVEL > 1
|
|
|
|
# define DBG2(f,x...) DBG(f, ##x)
|
|
|
|
#else
|
|
|
|
# define DBG2(f,x...) ((void)0)
|
|
|
|
#endif
|
|
|
|
#if DBG_LEVEL > 2
|
|
|
|
static void dump_iic_regs(const char* header, struct ibm_iic_private* dev)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
printk(KERN_DEBUG "ibm-iic%d: %s\n", dev->idx, header);
|
2009-07-07 03:05:40 +07:00
|
|
|
printk(KERN_DEBUG
|
|
|
|
" cntl = 0x%02x, mdcntl = 0x%02x\n"
|
|
|
|
" sts = 0x%02x, extsts = 0x%02x\n"
|
|
|
|
" clkdiv = 0x%02x, xfrcnt = 0x%02x\n"
|
|
|
|
" xtcntlss = 0x%02x, directcntl = 0x%02x\n",
|
2008-01-28 00:14:45 +07:00
|
|
|
in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts),
|
|
|
|
in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt),
|
2005-04-17 05:20:36 +07:00
|
|
|
in_8(&iic->xtcntlss), in_8(&iic->directcntl));
|
|
|
|
}
|
|
|
|
# define DUMP_REGS(h,dev) dump_iic_regs((h),(dev))
|
|
|
|
#else
|
|
|
|
# define DUMP_REGS(h,dev) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Bus timings (in ns) for bit-banging */
|
2015-12-16 11:48:13 +07:00
|
|
|
static struct ibm_iic_timings {
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned int hd_sta;
|
|
|
|
unsigned int su_sto;
|
|
|
|
unsigned int low;
|
|
|
|
unsigned int high;
|
|
|
|
unsigned int buf;
|
|
|
|
} timings [] = {
|
|
|
|
/* Standard mode (100 KHz) */
|
|
|
|
{
|
|
|
|
.hd_sta = 4000,
|
|
|
|
.su_sto = 4000,
|
|
|
|
.low = 4700,
|
|
|
|
.high = 4000,
|
|
|
|
.buf = 4700,
|
|
|
|
},
|
|
|
|
/* Fast mode (400 KHz) */
|
|
|
|
{
|
|
|
|
.hd_sta = 600,
|
|
|
|
.su_sto = 600,
|
|
|
|
.low = 1300,
|
|
|
|
.high = 600,
|
|
|
|
.buf = 1300,
|
|
|
|
}};
|
|
|
|
|
|
|
|
/* Enable/disable interrupt generation */
|
|
|
|
static inline void iic_interrupt_mode(struct ibm_iic_private* dev, int enable)
|
|
|
|
{
|
|
|
|
out_8(&dev->vaddr->intmsk, enable ? INTRMSK_EIMTC : 0);
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Initialize IIC interface.
|
|
|
|
*/
|
|
|
|
static void iic_dev_init(struct ibm_iic_private* dev)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
|
|
|
|
DBG("%d: init\n", dev->idx);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Clear master address */
|
|
|
|
out_8(&iic->lmadr, 0);
|
|
|
|
out_8(&iic->hmadr, 0);
|
|
|
|
|
|
|
|
/* Clear slave address */
|
|
|
|
out_8(&iic->lsadr, 0);
|
|
|
|
out_8(&iic->hsadr, 0);
|
|
|
|
|
|
|
|
/* Clear status & extended status */
|
|
|
|
out_8(&iic->sts, STS_SCMP | STS_IRQA);
|
|
|
|
out_8(&iic->extsts, EXTSTS_IRQP | EXTSTS_IRQD | EXTSTS_LA
|
|
|
|
| EXTSTS_ICT | EXTSTS_XFRA);
|
|
|
|
|
|
|
|
/* Set clock divider */
|
|
|
|
out_8(&iic->clkdiv, dev->clckdiv);
|
|
|
|
|
|
|
|
/* Clear transfer count */
|
|
|
|
out_8(&iic->xfrcnt, 0);
|
|
|
|
|
|
|
|
/* Clear extended control and status */
|
|
|
|
out_8(&iic->xtcntlss, XTCNTLSS_SRC | XTCNTLSS_SRS | XTCNTLSS_SWC
|
|
|
|
| XTCNTLSS_SWS);
|
|
|
|
|
|
|
|
/* Clear control register */
|
|
|
|
out_8(&iic->cntl, 0);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Enable interrupts if possible */
|
|
|
|
iic_interrupt_mode(dev, dev->irq >= 0);
|
|
|
|
|
|
|
|
/* Set mode control */
|
|
|
|
out_8(&iic->mdcntl, MDCNTL_FMDB | MDCNTL_EINT | MDCNTL_EUBS
|
|
|
|
| (dev->fast_mode ? MDCNTL_FSM : 0));
|
|
|
|
|
|
|
|
DUMP_REGS("iic_init", dev);
|
|
|
|
}
|
|
|
|
|
2008-01-28 00:14:45 +07:00
|
|
|
/*
|
2005-04-17 05:20:36 +07:00
|
|
|
* Reset IIC interface
|
|
|
|
*/
|
|
|
|
static void iic_dev_reset(struct ibm_iic_private* dev)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
int i;
|
|
|
|
u8 dc;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
DBG("%d: soft reset\n", dev->idx);
|
|
|
|
DUMP_REGS("reset", dev);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Place chip in the reset state */
|
|
|
|
out_8(&iic->xtcntlss, XTCNTLSS_SRST);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Check if bus is free */
|
2008-01-28 00:14:45 +07:00
|
|
|
dc = in_8(&iic->directcntl);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!DIRCTNL_FREE(dc)){
|
|
|
|
DBG("%d: trying to regain bus control\n", dev->idx);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Try to set bus free state */
|
2008-01-28 00:14:45 +07:00
|
|
|
out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Wait until we regain bus control */
|
|
|
|
for (i = 0; i < 100; ++i){
|
|
|
|
dc = in_8(&iic->directcntl);
|
|
|
|
if (DIRCTNL_FREE(dc))
|
|
|
|
break;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Toggle SCL line */
|
|
|
|
dc ^= DIRCNTL_SCC;
|
|
|
|
out_8(&iic->directcntl, dc);
|
|
|
|
udelay(10);
|
|
|
|
dc ^= DIRCNTL_SCC;
|
|
|
|
out_8(&iic->directcntl, dc);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* be nice */
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Remove reset */
|
|
|
|
out_8(&iic->xtcntlss, 0);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Reinitialize interface */
|
|
|
|
iic_dev_init(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do 0-length transaction using bit-banging through IIC_DIRECTCNTL register.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Wait for SCL and/or SDA to be high */
|
|
|
|
static int iic_dc_wait(volatile struct iic_regs __iomem *iic, u8 mask)
|
|
|
|
{
|
|
|
|
unsigned long x = jiffies + HZ / 28 + 2;
|
|
|
|
while ((in_8(&iic->directcntl) & mask) != mask){
|
|
|
|
if (unlikely(time_after(jiffies, x)))
|
|
|
|
return -1;
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iic_smbus_quick(struct ibm_iic_private* dev, const struct i2c_msg* p)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
2015-12-16 11:48:13 +07:00
|
|
|
const struct ibm_iic_timings *t = &timings[dev->fast_mode ? 1 : 0];
|
2005-04-17 05:20:36 +07:00
|
|
|
u8 mask, v, sda;
|
|
|
|
int i, res;
|
|
|
|
|
|
|
|
/* Only 7-bit addresses are supported */
|
|
|
|
if (unlikely(p->flags & I2C_M_TEN)){
|
|
|
|
DBG("%d: smbus_quick - 10 bit addresses are not supported\n",
|
|
|
|
dev->idx);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG("%d: smbus_quick(0x%02x)\n", dev->idx, p->addr);
|
|
|
|
|
|
|
|
/* Reset IIC interface */
|
|
|
|
out_8(&iic->xtcntlss, XTCNTLSS_SRST);
|
|
|
|
|
|
|
|
/* Wait for bus to become free */
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC);
|
|
|
|
if (unlikely(iic_dc_wait(iic, DIRCNTL_MSDA | DIRCNTL_MSC)))
|
|
|
|
goto err;
|
|
|
|
ndelay(t->buf);
|
|
|
|
|
|
|
|
/* START */
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SCC);
|
|
|
|
sda = 0;
|
|
|
|
ndelay(t->hd_sta);
|
|
|
|
|
|
|
|
/* Send address */
|
2016-04-04 01:44:51 +07:00
|
|
|
v = i2c_8bit_addr_from_msg(p);
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = 0, mask = 0x80; i < 8; ++i, mask >>= 1){
|
|
|
|
out_8(&iic->directcntl, sda);
|
|
|
|
ndelay(t->low / 2);
|
|
|
|
sda = (v & mask) ? DIRCNTL_SDAC : 0;
|
|
|
|
out_8(&iic->directcntl, sda);
|
|
|
|
ndelay(t->low / 2);
|
|
|
|
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SCC | sda);
|
|
|
|
if (unlikely(iic_dc_wait(iic, DIRCNTL_MSC)))
|
|
|
|
goto err;
|
|
|
|
ndelay(t->high);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ACK */
|
|
|
|
out_8(&iic->directcntl, sda);
|
|
|
|
ndelay(t->low / 2);
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SDAC);
|
|
|
|
ndelay(t->low / 2);
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC);
|
|
|
|
if (unlikely(iic_dc_wait(iic, DIRCNTL_MSC)))
|
|
|
|
goto err;
|
|
|
|
res = (in_8(&iic->directcntl) & DIRCNTL_MSDA) ? -EREMOTEIO : 1;
|
|
|
|
ndelay(t->high);
|
|
|
|
|
|
|
|
/* STOP */
|
|
|
|
out_8(&iic->directcntl, 0);
|
|
|
|
ndelay(t->low);
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SCC);
|
|
|
|
if (unlikely(iic_dc_wait(iic, DIRCNTL_MSC)))
|
|
|
|
goto err;
|
|
|
|
ndelay(t->su_sto);
|
|
|
|
out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC);
|
|
|
|
|
|
|
|
ndelay(t->buf);
|
|
|
|
|
|
|
|
DBG("%d: smbus_quick -> %s\n", dev->idx, res ? "NACK" : "ACK");
|
|
|
|
out:
|
|
|
|
/* Remove reset */
|
|
|
|
out_8(&iic->xtcntlss, 0);
|
|
|
|
|
|
|
|
/* Reinitialize interface */
|
|
|
|
iic_dev_init(dev);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
err:
|
|
|
|
DBG("%d: smbus_quick - bus is stuck\n", dev->idx);
|
|
|
|
res = -EREMOTEIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IIC interrupt handler
|
|
|
|
*/
|
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 iic_handler(int irq, void *dev_id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct ibm_iic_private* dev = (struct ibm_iic_private*)dev_id;
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
|
|
|
DBG2("%d: irq handler, STS = 0x%02x, EXTSTS = 0x%02x\n",
|
2005-04-17 05:20:36 +07:00
|
|
|
dev->idx, in_8(&iic->sts), in_8(&iic->extsts));
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Acknowledge IRQ and wakeup iic_wait_for_tc */
|
|
|
|
out_8(&iic->sts, STS_IRQA | STS_SCMP);
|
|
|
|
wake_up_interruptible(&dev->wq);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get master transfer result and clear errors if any.
|
|
|
|
* Returns the number of actually transferred bytes or error (<0)
|
|
|
|
*/
|
|
|
|
static int iic_xfer_result(struct ibm_iic_private* dev)
|
|
|
|
{
|
2008-01-28 00:14:45 +07:00
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (unlikely(in_8(&iic->sts) & STS_ERR)){
|
2008-01-28 00:14:45 +07:00
|
|
|
DBG("%d: xfer error, EXTSTS = 0x%02x\n", dev->idx,
|
2005-04-17 05:20:36 +07:00
|
|
|
in_8(&iic->extsts));
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Clear errors and possible pending IRQs */
|
2008-01-28 00:14:45 +07:00
|
|
|
out_8(&iic->extsts, EXTSTS_IRQP | EXTSTS_IRQD |
|
2005-04-17 05:20:36 +07:00
|
|
|
EXTSTS_LA | EXTSTS_ICT | EXTSTS_XFRA);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Flush master data buffer */
|
|
|
|
out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Is bus free?
|
|
|
|
* If error happened during combined xfer
|
|
|
|
* IIC interface is usually stuck in some strange
|
|
|
|
* state, the only way out - soft reset.
|
|
|
|
*/
|
|
|
|
if ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){
|
|
|
|
DBG("%d: bus is stuck, resetting\n", dev->idx);
|
|
|
|
iic_dev_reset(dev);
|
|
|
|
}
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return in_8(&iic->xfrcnt) & XFRCNT_MTC_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to abort active transfer.
|
|
|
|
*/
|
|
|
|
static void iic_abort_xfer(struct ibm_iic_private* dev)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
unsigned long x;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
DBG("%d: iic_abort_xfer\n", dev->idx);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
out_8(&iic->cntl, CNTL_HMT);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Wait for the abort command to complete.
|
|
|
|
* It's not worth to be optimized, just poll (timeout >= 1 tick)
|
|
|
|
*/
|
|
|
|
x = jiffies + 2;
|
|
|
|
while ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){
|
|
|
|
if (time_after(jiffies, x)){
|
|
|
|
DBG("%d: abort timeout, resetting...\n", dev->idx);
|
|
|
|
iic_dev_reset(dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
schedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just to clear errors */
|
|
|
|
iic_xfer_result(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for master transfer to complete.
|
|
|
|
* It puts current process to sleep until we get interrupt or timeout expires.
|
|
|
|
* Returns the number of transferred bytes or error (<0)
|
|
|
|
*/
|
|
|
|
static int iic_wait_for_tc(struct ibm_iic_private* dev){
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
int ret = 0;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (dev->irq >= 0){
|
|
|
|
/* Interrupt mode */
|
2008-01-28 00:14:45 +07:00
|
|
|
ret = wait_event_interruptible_timeout(dev->wq,
|
2009-03-29 03:34:43 +07:00
|
|
|
!(in_8(&iic->sts) & STS_PT), dev->adap.timeout);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (unlikely(ret < 0))
|
|
|
|
DBG("%d: wait interrupted\n", dev->idx);
|
|
|
|
else if (unlikely(in_8(&iic->sts) & STS_PT)){
|
|
|
|
DBG("%d: wait timeout\n", dev->idx);
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Polling mode */
|
2009-03-29 03:34:43 +07:00
|
|
|
unsigned long x = jiffies + dev->adap.timeout;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
while (in_8(&iic->sts) & STS_PT){
|
|
|
|
if (unlikely(time_after(jiffies, x))){
|
|
|
|
DBG("%d: poll timeout\n", dev->idx);
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (unlikely(signal_pending(current))){
|
|
|
|
DBG("%d: poll interrupted\n", dev->idx);
|
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
schedule();
|
2008-01-28 00:14:45 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (unlikely(ret < 0))
|
|
|
|
iic_abort_xfer(dev);
|
|
|
|
else
|
|
|
|
ret = iic_xfer_result(dev);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
DBG2("%d: iic_wait_for_tc -> %d\n", dev->idx, ret);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Low level master transfer routine
|
|
|
|
*/
|
2008-01-28 00:14:45 +07:00
|
|
|
static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm,
|
2005-04-17 05:20:36 +07:00
|
|
|
int combined_xfer)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
char* buf = pm->buf;
|
|
|
|
int i, j, loops, ret = 0;
|
|
|
|
int len = pm->len;
|
|
|
|
|
|
|
|
u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
|
|
|
|
if (pm->flags & I2C_M_RD)
|
|
|
|
cntl |= CNTL_RW;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
loops = (len + 3) / 4;
|
|
|
|
for (i = 0; i < loops; ++i, len -= 4){
|
|
|
|
int count = len > 4 ? 4 : len;
|
|
|
|
u8 cmd = cntl | ((count - 1) << CNTL_TCT_SHIFT);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!(cntl & CNTL_RW))
|
|
|
|
for (j = 0; j < count; ++j)
|
|
|
|
out_8((void __iomem *)&iic->mdbuf, *buf++);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (i < loops - 1)
|
|
|
|
cmd |= CNTL_CHT;
|
|
|
|
else if (combined_xfer)
|
|
|
|
cmd |= CNTL_RPST;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, count, cmd);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Start transfer */
|
|
|
|
out_8(&iic->cntl, cmd);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Wait for completion */
|
|
|
|
ret = iic_wait_for_tc(dev);
|
|
|
|
|
|
|
|
if (unlikely(ret < 0))
|
|
|
|
break;
|
|
|
|
else if (unlikely(ret != count)){
|
2011-03-31 08:57:33 +07:00
|
|
|
DBG("%d: xfer_bytes, requested %d, transferred %d\n",
|
2005-04-17 05:20:36 +07:00
|
|
|
dev->idx, count, ret);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* If it's not a last part of xfer, abort it */
|
|
|
|
if (combined_xfer || (i < loops - 1))
|
|
|
|
iic_abort_xfer(dev);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
ret = -EREMOTEIO;
|
2008-01-28 00:14:45 +07:00
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (cntl & CNTL_RW)
|
|
|
|
for (j = 0; j < count; ++j)
|
|
|
|
*buf++ = in_8((void __iomem *)&iic->mdbuf);
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return ret > 0 ? 0 : ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set target slave address for master transfer
|
|
|
|
*/
|
|
|
|
static inline void iic_address(struct ibm_iic_private* dev, struct i2c_msg* msg)
|
|
|
|
{
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
u16 addr = msg->addr;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
|
|
|
DBG2("%d: iic_address, 0x%03x (%d-bit)\n", dev->idx,
|
2005-04-17 05:20:36 +07:00
|
|
|
addr, msg->flags & I2C_M_TEN ? 10 : 7);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (msg->flags & I2C_M_TEN){
|
|
|
|
out_8(&iic->cntl, CNTL_AMD);
|
|
|
|
out_8(&iic->lmadr, addr);
|
|
|
|
out_8(&iic->hmadr, 0xf0 | ((addr >> 7) & 0x06));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
out_8(&iic->cntl, 0);
|
|
|
|
out_8(&iic->lmadr, addr << 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int iic_invalid_address(const struct i2c_msg* p)
|
|
|
|
{
|
|
|
|
return (p->addr > 0x3ff) || (!(p->flags & I2C_M_TEN) && (p->addr > 0x7f));
|
|
|
|
}
|
|
|
|
|
2008-01-28 00:14:45 +07:00
|
|
|
static inline int iic_address_neq(const struct i2c_msg* p1,
|
2005-04-17 05:20:36 +07:00
|
|
|
const struct i2c_msg* p2)
|
|
|
|
{
|
2008-01-28 00:14:45 +07:00
|
|
|
return (p1->addr != p2->addr)
|
2005-04-17 05:20:36 +07:00
|
|
|
|| ((p1->flags & I2C_M_TEN) != (p2->flags & I2C_M_TEN));
|
2008-01-28 00:14:45 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
2008-01-28 00:14:45 +07:00
|
|
|
* Generic master transfer entrypoint.
|
2005-04-17 05:20:36 +07:00
|
|
|
* Returns the number of processed messages or error (<0)
|
|
|
|
*/
|
|
|
|
static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
|
|
|
|
{
|
|
|
|
struct ibm_iic_private* dev = (struct ibm_iic_private*)(i2c_get_adapdata(adap));
|
|
|
|
volatile struct iic_regs __iomem *iic = dev->vaddr;
|
|
|
|
int i, ret = 0;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!num)
|
|
|
|
return 0;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Check the sanity of the passed messages.
|
|
|
|
* Uhh, generic i2c layer is more suitable place for such code...
|
|
|
|
*/
|
|
|
|
if (unlikely(iic_invalid_address(&msgs[0]))){
|
2008-01-28 00:14:45 +07:00
|
|
|
DBG("%d: invalid address 0x%03x (%d-bit)\n", dev->idx,
|
2005-04-17 05:20:36 +07:00
|
|
|
msgs[0].addr, msgs[0].flags & I2C_M_TEN ? 10 : 7);
|
|
|
|
return -EINVAL;
|
2008-01-28 00:14:45 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = 0; i < num; ++i){
|
|
|
|
if (unlikely(msgs[i].len <= 0)){
|
|
|
|
if (num == 1 && !msgs[0].len){
|
|
|
|
/* Special case for I2C_SMBUS_QUICK emulation.
|
|
|
|
* IBM IIC doesn't support 0-length transactions
|
|
|
|
* so we have to emulate them using bit-banging.
|
|
|
|
*/
|
|
|
|
return iic_smbus_quick(dev, &msgs[0]);
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
DBG("%d: invalid len %d in msg[%d]\n", dev->idx,
|
2005-04-17 05:20:36 +07:00
|
|
|
msgs[i].len, i);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (unlikely(iic_address_neq(&msgs[0], &msgs[i]))){
|
|
|
|
DBG("%d: invalid addr in msg[%d]\n", dev->idx, i);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Check bus state */
|
|
|
|
if (unlikely((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE)){
|
|
|
|
DBG("%d: iic_xfer, bus is not free\n", dev->idx);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2011-03-31 08:57:33 +07:00
|
|
|
/* Usually it means something serious has happened.
|
2005-04-17 05:20:36 +07:00
|
|
|
* We *cannot* have unfinished previous transfer
|
|
|
|
* so it doesn't make any sense to try to stop it.
|
2008-01-28 00:14:45 +07:00
|
|
|
* Probably we were not able to recover from the
|
2005-04-17 05:20:36 +07:00
|
|
|
* previous error.
|
|
|
|
* The only *reasonable* thing I can think of here
|
|
|
|
* is soft reset. --ebs
|
|
|
|
*/
|
|
|
|
iic_dev_reset(dev);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){
|
|
|
|
DBG("%d: iic_xfer, bus is still not free\n", dev->idx);
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
else {
|
|
|
|
/* Flush master data buffer (just in case) */
|
|
|
|
out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB);
|
|
|
|
}
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Load slave address */
|
|
|
|
iic_address(dev, &msgs[0]);
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Do real transfer */
|
|
|
|
for (i = 0; i < num && !ret; ++i)
|
|
|
|
ret = iic_xfer_bytes(dev, &msgs[i], i < num - 1);
|
|
|
|
|
|
|
|
return ret < 0 ? ret : num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 iic_func(struct i2c_adapter *adap)
|
|
|
|
{
|
|
|
|
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
|
|
|
|
}
|
|
|
|
|
2006-09-04 03:39:46 +07:00
|
|
|
static const struct i2c_algorithm iic_algo = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.master_xfer = iic_xfer,
|
|
|
|
.functionality = iic_func
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculates IICx_CLCKDIV value for a specific OPB clock frequency
|
|
|
|
*/
|
|
|
|
static inline u8 iic_clckdiv(unsigned int opb)
|
|
|
|
{
|
|
|
|
/* Compatibility kludge, should go away after all cards
|
|
|
|
* are fixed to fill correct value for opbfreq.
|
|
|
|
* Previous driver version used hardcoded divider value 4,
|
|
|
|
* it corresponds to OPB frequency from the range (40, 50] MHz
|
|
|
|
*/
|
|
|
|
if (!opb){
|
|
|
|
printk(KERN_WARNING "ibm-iic: using compatibility value for OPB freq,"
|
|
|
|
" fix your board specific setup\n");
|
|
|
|
opb = 50000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert to MHz */
|
|
|
|
opb /= 1000000;
|
2008-01-28 00:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (opb < 20 || opb > 150){
|
2008-04-23 03:16:46 +07:00
|
|
|
printk(KERN_WARNING "ibm-iic: invalid OPB clock frequency %u MHz\n",
|
2005-04-17 05:20:36 +07:00
|
|
|
opb);
|
|
|
|
opb = opb < 20 ? 20 : 150;
|
|
|
|
}
|
|
|
|
return (u8)((opb + 9) / 10 - 1);
|
|
|
|
}
|
|
|
|
|
2012-11-28 03:59:38 +07:00
|
|
|
static int iic_request_irq(struct platform_device *ofdev,
|
2008-04-23 03:16:47 +07:00
|
|
|
struct ibm_iic_private *dev)
|
|
|
|
{
|
2010-04-14 06:12:29 +07:00
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
2008-04-23 03:16:47 +07:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
if (iic_force_poll)
|
2009-10-04 18:08:16 +07:00
|
|
|
return 0;
|
2008-04-23 03:16:47 +07:00
|
|
|
|
|
|
|
irq = irq_of_parse_and_map(np, 0);
|
2009-10-04 18:08:16 +07:00
|
|
|
if (!irq) {
|
2008-04-23 03:16:47 +07:00
|
|
|
dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n");
|
2009-10-04 18:08:16 +07:00
|
|
|
return 0;
|
2008-04-23 03:16:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable interrupts until we finish initialization, assumes
|
|
|
|
* level-sensitive IRQ setup...
|
|
|
|
*/
|
|
|
|
iic_interrupt_mode(dev, 0);
|
|
|
|
if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) {
|
|
|
|
dev_err(&ofdev->dev, "request_irq %d failed\n", irq);
|
|
|
|
/* Fallback to the polling mode */
|
2009-10-04 18:08:16 +07:00
|
|
|
return 0;
|
2008-04-23 03:16:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register single IIC interface
|
|
|
|
*/
|
2012-11-28 03:59:38 +07:00
|
|
|
static int iic_probe(struct platform_device *ofdev)
|
2008-04-23 03:16:47 +07:00
|
|
|
{
|
2010-04-14 06:12:29 +07:00
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
2008-04-23 03:16:47 +07:00
|
|
|
struct ibm_iic_private *dev;
|
|
|
|
struct i2c_adapter *adap;
|
2008-07-15 03:38:36 +07:00
|
|
|
const u32 *freq;
|
2008-04-23 03:16:47 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
|
|
|
if (!dev) {
|
|
|
|
dev_err(&ofdev->dev, "failed to allocate device data\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-05-23 17:22:40 +07:00
|
|
|
platform_set_drvdata(ofdev, dev);
|
2008-04-23 03:16:47 +07:00
|
|
|
|
|
|
|
dev->vaddr = of_iomap(np, 0);
|
|
|
|
if (dev->vaddr == NULL) {
|
|
|
|
dev_err(&ofdev->dev, "failed to iomap device\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto error_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_waitqueue_head(&dev->wq);
|
|
|
|
|
|
|
|
dev->irq = iic_request_irq(ofdev, dev);
|
2009-10-04 18:08:16 +07:00
|
|
|
if (!dev->irq)
|
2008-04-23 03:16:47 +07:00
|
|
|
dev_warn(&ofdev->dev, "using polling mode\n");
|
|
|
|
|
|
|
|
/* Board specific settings */
|
|
|
|
if (iic_force_fast || of_get_property(np, "fast-mode", NULL))
|
|
|
|
dev->fast_mode = 1;
|
|
|
|
|
|
|
|
freq = of_get_property(np, "clock-frequency", NULL);
|
|
|
|
if (freq == NULL) {
|
|
|
|
freq = of_get_property(np->parent, "clock-frequency", NULL);
|
|
|
|
if (freq == NULL) {
|
|
|
|
dev_err(&ofdev->dev, "Unable to get bus frequency\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto error_cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->clckdiv = iic_clckdiv(*freq);
|
|
|
|
dev_dbg(&ofdev->dev, "clckdiv = %d\n", dev->clckdiv);
|
|
|
|
|
|
|
|
/* Initialize IIC interface */
|
|
|
|
iic_dev_init(dev);
|
|
|
|
|
|
|
|
/* Register it with i2c layer */
|
|
|
|
adap = &dev->adap;
|
|
|
|
adap->dev.parent = &ofdev->dev;
|
2010-06-08 20:48:18 +07:00
|
|
|
adap->dev.of_node = of_node_get(np);
|
2008-04-23 03:16:47 +07:00
|
|
|
strlcpy(adap->name, "IBM IIC", sizeof(adap->name));
|
|
|
|
i2c_set_adapdata(adap, dev);
|
2008-07-15 03:38:29 +07:00
|
|
|
adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
|
2008-04-23 03:16:47 +07:00
|
|
|
adap->algo = &iic_algo;
|
2009-03-29 03:34:43 +07:00
|
|
|
adap->timeout = HZ;
|
2008-04-23 03:16:47 +07:00
|
|
|
|
2008-07-15 03:38:36 +07:00
|
|
|
ret = i2c_add_adapter(adap);
|
2008-04-23 03:16:47 +07:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&ofdev->dev, "failed to register i2c adapter\n");
|
|
|
|
goto error_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(&ofdev->dev, "using %s mode\n",
|
|
|
|
dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_cleanup:
|
2009-10-04 18:08:16 +07:00
|
|
|
if (dev->irq) {
|
2008-04-23 03:16:47 +07:00
|
|
|
iic_interrupt_mode(dev, 0);
|
|
|
|
free_irq(dev->irq, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->vaddr)
|
|
|
|
iounmap(dev->vaddr);
|
|
|
|
|
|
|
|
kfree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup initialized IIC interface
|
|
|
|
*/
|
2012-11-28 03:59:38 +07:00
|
|
|
static int iic_remove(struct platform_device *ofdev)
|
2008-04-23 03:16:47 +07:00
|
|
|
{
|
2013-05-23 17:22:40 +07:00
|
|
|
struct ibm_iic_private *dev = platform_get_drvdata(ofdev);
|
2008-04-23 03:16:47 +07:00
|
|
|
|
|
|
|
i2c_del_adapter(&dev->adap);
|
|
|
|
|
2009-10-04 18:08:16 +07:00
|
|
|
if (dev->irq) {
|
2008-04-23 03:16:47 +07:00
|
|
|
iic_interrupt_mode(dev, 0);
|
|
|
|
free_irq(dev->irq, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
iounmap(dev->vaddr);
|
|
|
|
kfree(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id ibm_iic_match[] = {
|
2008-07-15 03:38:30 +07:00
|
|
|
{ .compatible = "ibm,iic", },
|
2008-04-23 03:16:47 +07:00
|
|
|
{}
|
|
|
|
};
|
2015-10-20 21:16:27 +07:00
|
|
|
MODULE_DEVICE_TABLE(of, ibm_iic_match);
|
2008-04-23 03:16:47 +07:00
|
|
|
|
2011-02-17 16:43:24 +07:00
|
|
|
static struct platform_driver ibm_iic_driver = {
|
2010-04-14 06:13:02 +07:00
|
|
|
.driver = {
|
|
|
|
.name = "ibm-iic",
|
|
|
|
.of_match_table = ibm_iic_match,
|
|
|
|
},
|
2008-04-23 03:16:47 +07:00
|
|
|
.probe = iic_probe,
|
2012-11-28 03:59:38 +07:00
|
|
|
.remove = iic_remove,
|
2008-04-23 03:16:47 +07:00
|
|
|
};
|
|
|
|
|
2012-01-13 02:32:04 +07:00
|
|
|
module_platform_driver(ibm_iic_driver);
|