Pull i2c updates from Wolfram Sang: "Highlights: - class based instantiation finally dropped for most embedded drivers bringing boot up performance gains - removed two drivers (one outdated, one a duplicate) - ACPI has now operation region support (thanks to Lan Tianyu) - the i2c-stub driver got overhauled and gained new features to become more useful when writing i2c client drivers (thanks to Guenter Roeck and Jean Delvare) The rest is driver bugfixes, added bindings/ids, cleanups..." * 'i2c/for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (43 commits) i2c: mpc: delete unneeded test before of_node_put i2c: rk3x: fix interrupt handling issue i2c: imx: Fix format warning for dev_dbg i2c: qup: disable clks and return instead of just returning error i2c: exynos5: always enable HSI2C i2c: designware: add new bindings i2c: gpio: Drop dead code in i2c_gpio_remove i2c: pca954x: put the mux to disconnected state after resume i2c: st: Update i2c timings drivers/i2c/busses: use correct type for dma_map/unmap i2c: i2c-st: Use %pa to print 'resource_size_t' type i2c: s3c2410: resume the I2C controller earlier i2c: stub: Avoid an array overrun on I2C block transfers i2c: i801: Add device ID for Intel Wildcat Point PCH i2c: i801: Fix the alignment of the device table i2c: stub: Add support for banked register ranges i2c: stub: Remember the number of emulated chips i2c: stub: Add support for SMBus block commands i2c: efm32: correct namespacing of location property i2c: exynos5: remove extra line and fix an assignment ...tirimbino
commit
f7dbaef505
@ -1,404 +0,0 @@ |
||||
/*
|
||||
* drivers/i2c/busses/i2c-s6000.c |
||||
* |
||||
* Description: Driver for S6000 Family I2C Interface |
||||
* Copyright (c) 2008 emlix GmbH |
||||
* Author: Oskar Schirmer <oskar@scara.com> |
||||
* |
||||
* Partially based on i2c-bfin-twi.c driver by <sonic.zhang@analog.com> |
||||
* Copyright (c) 2005-2007 Analog Devices, Inc. |
||||
* |
||||
* 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., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
#include <linux/clk.h> |
||||
#include <linux/err.h> |
||||
#include <linux/module.h> |
||||
#include <linux/kernel.h> |
||||
#include <linux/init.h> |
||||
#include <linux/delay.h> |
||||
#include <linux/i2c.h> |
||||
#include <linux/i2c/s6000.h> |
||||
#include <linux/timer.h> |
||||
#include <linux/spinlock.h> |
||||
#include <linux/completion.h> |
||||
#include <linux/interrupt.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/io.h> |
||||
|
||||
#include "i2c-s6000.h" |
||||
|
||||
#define DRV_NAME "i2c-s6000" |
||||
|
||||
#define POLL_TIMEOUT (2 * HZ) |
||||
|
||||
struct s6i2c_if { |
||||
u8 __iomem *reg; /* memory mapped registers */ |
||||
int irq; |
||||
spinlock_t lock; |
||||
struct i2c_msg *msgs; /* messages currently handled */ |
||||
int msgs_num; /* nb of msgs to do */ |
||||
int msgs_push; /* nb of msgs read/written */ |
||||
int msgs_done; /* nb of msgs finally handled */ |
||||
unsigned push; /* nb of bytes read/written in msg */ |
||||
unsigned done; /* nb of bytes finally handled */ |
||||
int timeout_count; /* timeout retries left */ |
||||
struct timer_list timeout_timer; |
||||
struct i2c_adapter adap; |
||||
struct completion complete; |
||||
struct clk *clk; |
||||
struct resource *res; |
||||
}; |
||||
|
||||
static inline u16 i2c_rd16(struct s6i2c_if *iface, unsigned n) |
||||
{ |
||||
return readw(iface->reg + (n)); |
||||
} |
||||
|
||||
static inline void i2c_wr16(struct s6i2c_if *iface, unsigned n, u16 v) |
||||
{ |
||||
writew(v, iface->reg + (n)); |
||||
} |
||||
|
||||
static inline u32 i2c_rd32(struct s6i2c_if *iface, unsigned n) |
||||
{ |
||||
return readl(iface->reg + (n)); |
||||
} |
||||
|
||||
static inline void i2c_wr32(struct s6i2c_if *iface, unsigned n, u32 v) |
||||
{ |
||||
writel(v, iface->reg + (n)); |
||||
} |
||||
|
||||
static struct s6i2c_if s6i2c_if; |
||||
|
||||
static void s6i2c_handle_interrupt(struct s6i2c_if *iface) |
||||
{ |
||||
if (i2c_rd16(iface, S6_I2C_INTRSTAT) & (1 << S6_I2C_INTR_TXABRT)) { |
||||
i2c_rd16(iface, S6_I2C_CLRTXABRT); |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 0); |
||||
complete(&iface->complete); |
||||
return; |
||||
} |
||||
if (iface->msgs_done >= iface->msgs_num) { |
||||
dev_err(&iface->adap.dev, "s6i2c: spurious I2C irq: %04x\n", |
||||
i2c_rd16(iface, S6_I2C_INTRSTAT)); |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 0); |
||||
return; |
||||
} |
||||
while ((iface->msgs_push < iface->msgs_num) |
||||
&& (i2c_rd16(iface, S6_I2C_STATUS) & (1 << S6_I2C_STATUS_TFNF))) { |
||||
struct i2c_msg *m = &iface->msgs[iface->msgs_push]; |
||||
if (!(m->flags & I2C_M_RD)) |
||||
i2c_wr16(iface, S6_I2C_DATACMD, m->buf[iface->push]); |
||||
else |
||||
i2c_wr16(iface, S6_I2C_DATACMD, |
||||
1 << S6_I2C_DATACMD_READ); |
||||
if (++iface->push >= m->len) { |
||||
iface->push = 0; |
||||
iface->msgs_push += 1; |
||||
} |
||||
} |
||||
do { |
||||
struct i2c_msg *m = &iface->msgs[iface->msgs_done]; |
||||
if (!(m->flags & I2C_M_RD)) { |
||||
if (iface->msgs_done < iface->msgs_push) |
||||
iface->msgs_done += 1; |
||||
else |
||||
break; |
||||
} else if (i2c_rd16(iface, S6_I2C_STATUS) |
||||
& (1 << S6_I2C_STATUS_RFNE)) { |
||||
m->buf[iface->done] = i2c_rd16(iface, S6_I2C_DATACMD); |
||||
if (++iface->done >= m->len) { |
||||
iface->done = 0; |
||||
iface->msgs_done += 1; |
||||
} |
||||
} else{ |
||||
break; |
||||
} |
||||
} while (iface->msgs_done < iface->msgs_num); |
||||
if (iface->msgs_done >= iface->msgs_num) { |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 1 << S6_I2C_INTR_TXABRT); |
||||
complete(&iface->complete); |
||||
} else if (iface->msgs_push >= iface->msgs_num) { |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, (1 << S6_I2C_INTR_TXABRT) | |
||||
(1 << S6_I2C_INTR_RXFULL)); |
||||
} else { |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, (1 << S6_I2C_INTR_TXABRT) | |
||||
(1 << S6_I2C_INTR_TXEMPTY) | |
||||
(1 << S6_I2C_INTR_RXFULL)); |
||||
} |
||||
} |
||||
|
||||
static irqreturn_t s6i2c_interrupt_entry(int irq, void *dev_id) |
||||
{ |
||||
struct s6i2c_if *iface = dev_id; |
||||
if (!(i2c_rd16(iface, S6_I2C_STATUS) & ((1 << S6_I2C_INTR_RXUNDER) |
||||
| (1 << S6_I2C_INTR_RXOVER) |
||||
| (1 << S6_I2C_INTR_RXFULL) |
||||
| (1 << S6_I2C_INTR_TXOVER) |
||||
| (1 << S6_I2C_INTR_TXEMPTY) |
||||
| (1 << S6_I2C_INTR_RDREQ) |
||||
| (1 << S6_I2C_INTR_TXABRT) |
||||
| (1 << S6_I2C_INTR_RXDONE) |
||||
| (1 << S6_I2C_INTR_ACTIVITY) |
||||
| (1 << S6_I2C_INTR_STOPDET) |
||||
| (1 << S6_I2C_INTR_STARTDET) |
||||
| (1 << S6_I2C_INTR_GENCALL)))) |
||||
return IRQ_NONE; |
||||
|
||||
spin_lock(&iface->lock); |
||||
del_timer(&iface->timeout_timer); |
||||
s6i2c_handle_interrupt(iface); |
||||
spin_unlock(&iface->lock); |
||||
return IRQ_HANDLED; |
||||
} |
||||
|
||||
static void s6i2c_timeout(unsigned long data) |
||||
{ |
||||
struct s6i2c_if *iface = (struct s6i2c_if *)data; |
||||
unsigned long flags; |
||||
|
||||
spin_lock_irqsave(&iface->lock, flags); |
||||
s6i2c_handle_interrupt(iface); |
||||
if (--iface->timeout_count > 0) { |
||||
iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; |
||||
add_timer(&iface->timeout_timer); |
||||
} else { |
||||
complete(&iface->complete); |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 0); |
||||
} |
||||
spin_unlock_irqrestore(&iface->lock, flags); |
||||
} |
||||
|
||||
static int s6i2c_master_xfer(struct i2c_adapter *adap, |
||||
struct i2c_msg *msgs, int num) |
||||
{ |
||||
struct s6i2c_if *iface = adap->algo_data; |
||||
int i; |
||||
if (num == 0) |
||||
return 0; |
||||
if (i2c_rd16(iface, S6_I2C_STATUS) & (1 << S6_I2C_STATUS_ACTIVITY)) |
||||
yield(); |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 0); |
||||
i2c_rd16(iface, S6_I2C_CLRINTR); |
||||
for (i = 0; i < num; i++) { |
||||
if (msgs[i].flags & I2C_M_TEN) { |
||||
dev_err(&adap->dev, |
||||
"s6i2c: 10 bits addr not supported\n"); |
||||
return -EINVAL; |
||||
} |
||||
if (msgs[i].len == 0) { |
||||
dev_err(&adap->dev, |
||||
"s6i2c: zero length message not supported\n"); |
||||
return -EINVAL; |
||||
} |
||||
if (msgs[i].addr != msgs[0].addr) { |
||||
dev_err(&adap->dev, |
||||
"s6i2c: multiple xfer cannot change target\n"); |
||||
return -EINVAL; |
||||
} |
||||
} |
||||
|
||||
iface->msgs = msgs; |
||||
iface->msgs_num = num; |
||||
iface->msgs_push = 0; |
||||
iface->msgs_done = 0; |
||||
iface->push = 0; |
||||
iface->done = 0; |
||||
iface->timeout_count = 10; |
||||
i2c_wr16(iface, S6_I2C_TAR, msgs[0].addr); |
||||
i2c_wr16(iface, S6_I2C_ENABLE, 1); |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, (1 << S6_I2C_INTR_TXEMPTY) | |
||||
(1 << S6_I2C_INTR_TXABRT)); |
||||
|
||||
iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; |
||||
add_timer(&iface->timeout_timer); |
||||
wait_for_completion(&iface->complete); |
||||
del_timer_sync(&iface->timeout_timer); |
||||
while (i2c_rd32(iface, S6_I2C_TXFLR) > 0) |
||||
schedule(); |
||||
while (i2c_rd16(iface, S6_I2C_STATUS) & (1 << S6_I2C_STATUS_ACTIVITY)) |
||||
schedule(); |
||||
|
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 0); |
||||
i2c_wr16(iface, S6_I2C_ENABLE, 0); |
||||
return iface->msgs_done; |
||||
} |
||||
|
||||
static u32 s6i2c_functionality(struct i2c_adapter *adap) |
||||
{ |
||||
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
||||
} |
||||
|
||||
static struct i2c_algorithm s6i2c_algorithm = { |
||||
.master_xfer = s6i2c_master_xfer, |
||||
.functionality = s6i2c_functionality, |
||||
}; |
||||
|
||||
static u16 nanoseconds_on_clk(struct s6i2c_if *iface, u32 ns) |
||||
{ |
||||
u32 dividend = ((clk_get_rate(iface->clk) / 1000) * ns) / 1000000; |
||||
if (dividend > 0xffff) |
||||
return 0xffff; |
||||
return dividend; |
||||
} |
||||
|
||||
static int s6i2c_probe(struct platform_device *dev) |
||||
{ |
||||
struct s6i2c_if *iface = &s6i2c_if; |
||||
struct i2c_adapter *p_adap; |
||||
const char *clock; |
||||
int bus_num, rc; |
||||
spin_lock_init(&iface->lock); |
||||
init_completion(&iface->complete); |
||||
iface->irq = platform_get_irq(dev, 0); |
||||
if (iface->irq < 0) { |
||||
rc = iface->irq; |
||||
goto err_out; |
||||
} |
||||
iface->res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
||||
if (!iface->res) { |
||||
rc = -ENXIO; |
||||
goto err_out; |
||||
} |
||||
iface->res = request_mem_region(iface->res->start, |
||||
resource_size(iface->res), |
||||
dev->dev.bus_id); |
||||
if (!iface->res) { |
||||
rc = -EBUSY; |
||||
goto err_out; |
||||
} |
||||
iface->reg = ioremap_nocache(iface->res->start, |
||||
resource_size(iface->res)); |
||||
if (!iface->reg) { |
||||
rc = -ENOMEM; |
||||
goto err_reg; |
||||
} |
||||
|
||||
clock = 0; |
||||
bus_num = -1; |
||||
if (dev_get_platdata(&dev->dev)) { |
||||
struct s6_i2c_platform_data *pdata = |
||||
dev_get_platdata(&dev->dev); |
||||
bus_num = pdata->bus_num; |
||||
clock = pdata->clock; |
||||
} |
||||
iface->clk = clk_get(&dev->dev, clock); |
||||
if (IS_ERR(iface->clk)) { |
||||
rc = PTR_ERR(iface->clk); |
||||
goto err_map; |
||||
} |
||||
rc = clk_enable(iface->clk); |
||||
if (rc < 0) |
||||
goto err_clk_put; |
||||
init_timer(&iface->timeout_timer); |
||||
iface->timeout_timer.function = s6i2c_timeout; |
||||
iface->timeout_timer.data = (unsigned long)iface; |
||||
|
||||
p_adap = &iface->adap; |
||||
strlcpy(p_adap->name, dev->name, sizeof(p_adap->name)); |
||||
p_adap->algo = &s6i2c_algorithm; |
||||
p_adap->algo_data = iface; |
||||
p_adap->nr = bus_num; |
||||
p_adap->class = 0; |
||||
p_adap->dev.parent = &dev->dev; |
||||
i2c_wr16(iface, S6_I2C_INTRMASK, 0); |
||||
rc = request_irq(iface->irq, s6i2c_interrupt_entry, |
||||
IRQF_SHARED, dev->name, iface); |
||||
if (rc) { |
||||
dev_err(&p_adap->dev, "s6i2c: can't get IRQ %d\n", iface->irq); |
||||
goto err_clk_dis; |
||||
} |
||||
|
||||
i2c_wr16(iface, S6_I2C_ENABLE, 0); |
||||
udelay(1); |
||||
i2c_wr32(iface, S6_I2C_SRESET, 1 << S6_I2C_SRESET_IC_SRST); |
||||
i2c_wr16(iface, S6_I2C_CLRTXABRT, 1); |
||||
i2c_wr16(iface, S6_I2C_CON, |
||||
(1 << S6_I2C_CON_MASTER) | |
||||
(S6_I2C_CON_SPEED_NORMAL << S6_I2C_CON_SPEED) | |
||||
(0 << S6_I2C_CON_10BITSLAVE) | |
||||
(0 << S6_I2C_CON_10BITMASTER) | |
||||
(1 << S6_I2C_CON_RESTARTENA) | |
||||
(1 << S6_I2C_CON_SLAVEDISABLE)); |
||||
i2c_wr16(iface, S6_I2C_SSHCNT, nanoseconds_on_clk(iface, 4000)); |
||||
i2c_wr16(iface, S6_I2C_SSLCNT, nanoseconds_on_clk(iface, 4700)); |
||||
i2c_wr16(iface, S6_I2C_FSHCNT, nanoseconds_on_clk(iface, 600)); |
||||
i2c_wr16(iface, S6_I2C_FSLCNT, nanoseconds_on_clk(iface, 1300)); |
||||
i2c_wr16(iface, S6_I2C_RXTL, 0); |
||||
i2c_wr16(iface, S6_I2C_TXTL, 0); |
||||
|
||||
platform_set_drvdata(dev, iface); |
||||
rc = i2c_add_numbered_adapter(p_adap); |
||||
if (rc) |
||||
goto err_irq_free; |
||||
return 0; |
||||
|
||||
err_irq_free: |
||||
free_irq(iface->irq, iface); |
||||
err_clk_dis: |
||||
clk_disable(iface->clk); |
||||
err_clk_put: |
||||
clk_put(iface->clk); |
||||
err_map: |
||||
iounmap(iface->reg); |
||||
err_reg: |
||||
release_mem_region(iface->res->start, |
||||
resource_size(iface->res)); |
||||
err_out: |
||||
return rc; |
||||
} |
||||
|
||||
static int s6i2c_remove(struct platform_device *pdev) |
||||
{ |
||||
struct s6i2c_if *iface = platform_get_drvdata(pdev); |
||||
i2c_wr16(iface, S6_I2C_ENABLE, 0); |
||||
i2c_del_adapter(&iface->adap); |
||||
free_irq(iface->irq, iface); |
||||
clk_disable(iface->clk); |
||||
clk_put(iface->clk); |
||||
iounmap(iface->reg); |
||||
release_mem_region(iface->res->start, |
||||
resource_size(iface->res)); |
||||
return 0; |
||||
} |
||||
|
||||
static struct platform_driver s6i2c_driver = { |
||||
.probe = s6i2c_probe, |
||||
.remove = s6i2c_remove, |
||||
.driver = { |
||||
.name = DRV_NAME, |
||||
.owner = THIS_MODULE, |
||||
}, |
||||
}; |
||||
|
||||
static int __init s6i2c_init(void) |
||||
{ |
||||
pr_info("I2C: S6000 I2C driver\n"); |
||||
return platform_driver_register(&s6i2c_driver); |
||||
} |
||||
|
||||
static void __exit s6i2c_exit(void) |
||||
{ |
||||
platform_driver_unregister(&s6i2c_driver); |
||||
} |
||||
|
||||
MODULE_DESCRIPTION("I2C-Bus adapter routines for S6000 I2C"); |
||||
MODULE_LICENSE("GPL"); |
||||
MODULE_ALIAS("platform:" DRV_NAME); |
||||
|
||||
subsys_initcall(s6i2c_init); |
||||
module_exit(s6i2c_exit); |
@ -1,79 +0,0 @@ |
||||
/*
|
||||
* drivers/i2c/busses/i2c-s6000.h |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU General Public |
||||
* License. See the file "COPYING" in the main directory of this archive |
||||
* for more details. |
||||
* |
||||
* Copyright (C) 2008 Emlix GmbH <info@emlix.com> |
||||
* Author: Oskar Schirmer <oskar@scara.com> |
||||
*/ |
||||
|
||||
#ifndef __DRIVERS_I2C_BUSSES_I2C_S6000_H |
||||
#define __DRIVERS_I2C_BUSSES_I2C_S6000_H |
||||
|
||||
#define S6_I2C_CON 0x000 |
||||
#define S6_I2C_CON_MASTER 0 |
||||
#define S6_I2C_CON_SPEED 1 |
||||
#define S6_I2C_CON_SPEED_NORMAL 1 |
||||
#define S6_I2C_CON_SPEED_FAST 2 |
||||
#define S6_I2C_CON_SPEED_MASK 3 |
||||
#define S6_I2C_CON_10BITSLAVE 3 |
||||
#define S6_I2C_CON_10BITMASTER 4 |
||||
#define S6_I2C_CON_RESTARTENA 5 |
||||
#define S6_I2C_CON_SLAVEDISABLE 6 |
||||
#define S6_I2C_TAR 0x004 |
||||
#define S6_I2C_TAR_GCORSTART 10 |
||||
#define S6_I2C_TAR_SPECIAL 11 |
||||
#define S6_I2C_SAR 0x008 |
||||
#define S6_I2C_HSMADDR 0x00C |
||||
#define S6_I2C_DATACMD 0x010 |
||||
#define S6_I2C_DATACMD_READ 8 |
||||
#define S6_I2C_SSHCNT 0x014 |
||||
#define S6_I2C_SSLCNT 0x018 |
||||
#define S6_I2C_FSHCNT 0x01C |
||||
#define S6_I2C_FSLCNT 0x020 |
||||
#define S6_I2C_INTRSTAT 0x02C |
||||
#define S6_I2C_INTRMASK 0x030 |
||||
#define S6_I2C_RAWINTR 0x034 |
||||
#define S6_I2C_INTR_RXUNDER 0 |
||||
#define S6_I2C_INTR_RXOVER 1 |
||||
#define S6_I2C_INTR_RXFULL 2 |
||||
#define S6_I2C_INTR_TXOVER 3 |
||||
#define S6_I2C_INTR_TXEMPTY 4 |
||||
#define S6_I2C_INTR_RDREQ 5 |
||||
#define S6_I2C_INTR_TXABRT 6 |
||||
#define S6_I2C_INTR_RXDONE 7 |
||||
#define S6_I2C_INTR_ACTIVITY 8 |
||||
#define S6_I2C_INTR_STOPDET 9 |
||||
#define S6_I2C_INTR_STARTDET 10 |
||||
#define S6_I2C_INTR_GENCALL 11 |
||||
#define S6_I2C_RXTL 0x038 |
||||
#define S6_I2C_TXTL 0x03C |
||||
#define S6_I2C_CLRINTR 0x040 |
||||
#define S6_I2C_CLRRXUNDER 0x044 |
||||
#define S6_I2C_CLRRXOVER 0x048 |
||||
#define S6_I2C_CLRTXOVER 0x04C |
||||
#define S6_I2C_CLRRDREQ 0x050 |
||||
#define S6_I2C_CLRTXABRT 0x054 |
||||
#define S6_I2C_CLRRXDONE 0x058 |
||||
#define S6_I2C_CLRACTIVITY 0x05C |
||||
#define S6_I2C_CLRSTOPDET 0x060 |
||||
#define S6_I2C_CLRSTARTDET 0x064 |
||||
#define S6_I2C_CLRGENCALL 0x068 |
||||
#define S6_I2C_ENABLE 0x06C |
||||
#define S6_I2C_STATUS 0x070 |
||||
#define S6_I2C_STATUS_ACTIVITY 0 |
||||
#define S6_I2C_STATUS_TFNF 1 |
||||
#define S6_I2C_STATUS_TFE 2 |
||||
#define S6_I2C_STATUS_RFNE 3 |
||||
#define S6_I2C_STATUS_RFF 4 |
||||
#define S6_I2C_TXFLR 0x074 |
||||
#define S6_I2C_RXFLR 0x078 |
||||
#define S6_I2C_SRESET 0x07C |
||||
#define S6_I2C_SRESET_IC_SRST 0 |
||||
#define S6_I2C_SRESET_IC_MASTER_SRST 1 |
||||
#define S6_I2C_SRESET_IC_SLAVE_SRST 2 |
||||
#define S6_I2C_TXABRTSOURCE 0x080 |
||||
|
||||
#endif |
@ -1,129 +0,0 @@ |
||||
/* linux/drivers/i2c/busses/scx200_i2c.c
|
||||
|
||||
Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> |
||||
|
||||
National Semiconductor SCx200 I2C bus on GPIO pins |
||||
|
||||
Based on i2c-velleman.c Copyright (C) 1995-96, 2000 Simon G. Vogl |
||||
|
||||
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.
|
||||
*/ |
||||
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
||||
|
||||
#include <linux/module.h> |
||||
#include <linux/errno.h> |
||||
#include <linux/kernel.h> |
||||
#include <linux/i2c.h> |
||||
#include <linux/i2c-algo-bit.h> |
||||
#include <linux/io.h> |
||||
|
||||
#include <linux/scx200_gpio.h> |
||||
|
||||
MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>"); |
||||
MODULE_DESCRIPTION("NatSemi SCx200 I2C Driver"); |
||||
MODULE_LICENSE("GPL"); |
||||
|
||||
static int scl = CONFIG_SCx200_I2C_SCL; |
||||
static int sda = CONFIG_SCx200_I2C_SDA; |
||||
|
||||
module_param(scl, int, 0); |
||||
MODULE_PARM_DESC(scl, "GPIO line for SCL"); |
||||
module_param(sda, int, 0); |
||||
MODULE_PARM_DESC(sda, "GPIO line for SDA"); |
||||
|
||||
static void scx200_i2c_setscl(void *data, int state) |
||||
{ |
||||
scx200_gpio_set(scl, state); |
||||
} |
||||
|
||||
static void scx200_i2c_setsda(void *data, int state) |
||||
{ |
||||
scx200_gpio_set(sda, state); |
||||
}
|
||||
|
||||
static int scx200_i2c_getscl(void *data) |
||||
{ |
||||
return scx200_gpio_get(scl); |
||||
} |
||||
|
||||
static int scx200_i2c_getsda(void *data) |
||||
{ |
||||
return scx200_gpio_get(sda); |
||||
} |
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* 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_bit_data scx200_i2c_data = { |
||||
.setsda = scx200_i2c_setsda, |
||||
.setscl = scx200_i2c_setscl, |
||||
.getsda = scx200_i2c_getsda, |
||||
.getscl = scx200_i2c_getscl, |
||||
.udelay = 10, |
||||
.timeout = HZ, |
||||
}; |
||||
|
||||
static struct i2c_adapter scx200_i2c_ops = { |
||||
.owner = THIS_MODULE, |
||||
.class = I2C_CLASS_HWMON | I2C_CLASS_SPD, |
||||
.algo_data = &scx200_i2c_data, |
||||
.name = "NatSemi SCx200 I2C", |
||||
}; |
||||
|
||||
static int scx200_i2c_init(void) |
||||
{ |
||||
pr_debug("NatSemi SCx200 I2C Driver\n"); |
||||
|
||||
if (!scx200_gpio_present()) { |
||||
pr_err("no SCx200 gpio pins available\n"); |
||||
return -ENODEV; |
||||
} |
||||
|
||||
pr_debug("SCL=GPIO%02u, SDA=GPIO%02u\n", scl, sda); |
||||
|
||||
if (scl == -1 || sda == -1 || scl == sda) { |
||||
pr_err("scl and sda must be specified\n"); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
/* Configure GPIOs as open collector outputs */ |
||||
scx200_gpio_configure(scl, ~2, 5); |
||||
scx200_gpio_configure(sda, ~2, 5); |
||||
|
||||
if (i2c_bit_add_bus(&scx200_i2c_ops) < 0) { |
||||
pr_err("adapter %s registration failed\n", scx200_i2c_ops.name); |
||||
return -ENODEV; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void scx200_i2c_cleanup(void) |
||||
{ |
||||
i2c_del_adapter(&scx200_i2c_ops); |
||||
} |
||||
|
||||
module_init(scx200_i2c_init); |
||||
module_exit(scx200_i2c_cleanup); |
||||
|
||||
/*
|
||||
Local variables: |
||||
compile-command: "make -k -C ../.. SUBDIRS=drivers/i2c modules" |
||||
c-basic-offset: 8 |
||||
End: |
||||
*/ |
@ -0,0 +1,362 @@ |
||||
/*
|
||||
* I2C ACPI code |
||||
* |
||||
* Copyright (C) 2014 Intel Corp |
||||
* |
||||
* Author: Lan Tianyu <tianyu.lan@intel.com> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License version 2 as |
||||
* published by the Free Software Foundation. |
||||
* |
||||
* 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. |
||||
*/ |
||||
#define pr_fmt(fmt) "I2C/ACPI : " fmt |
||||
|
||||
#include <linux/kernel.h> |
||||
#include <linux/errno.h> |
||||
#include <linux/err.h> |
||||
#include <linux/i2c.h> |
||||
#include <linux/acpi.h> |
||||
|
||||
struct acpi_i2c_handler_data { |
||||
struct acpi_connection_info info; |
||||
struct i2c_adapter *adapter; |
||||
}; |
||||
|
||||
struct gsb_buffer { |
||||
u8 status; |
||||
u8 len; |
||||
union { |
||||
u16 wdata; |
||||
u8 bdata; |
||||
u8 data[0]; |
||||
}; |
||||
} __packed; |
||||
|
||||
static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data) |
||||
{ |
||||
struct i2c_board_info *info = data; |
||||
|
||||
if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) { |
||||
struct acpi_resource_i2c_serialbus *sb; |
||||
|
||||
sb = &ares->data.i2c_serial_bus; |
||||
if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) { |
||||
info->addr = sb->slave_address; |
||||
if (sb->access_mode == ACPI_I2C_10BIT_MODE) |
||||
info->flags |= I2C_CLIENT_TEN; |
||||
} |
||||
} else if (info->irq < 0) { |
||||
struct resource r; |
||||
|
||||
if (acpi_dev_resource_interrupt(ares, 0, &r)) |
||||
info->irq = r.start; |
||||
} |
||||
|
||||
/* Tell the ACPI core to skip this resource */ |
||||
return 1; |
||||
} |
||||
|
||||
static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level, |
||||
void *data, void **return_value) |
||||
{ |
||||
struct i2c_adapter *adapter = data; |
||||
struct list_head resource_list; |
||||
struct i2c_board_info info; |
||||
struct acpi_device *adev; |
||||
int ret; |
||||
|
||||
if (acpi_bus_get_device(handle, &adev)) |
||||
return AE_OK; |
||||
if (acpi_bus_get_status(adev) || !adev->status.present) |
||||
return AE_OK; |
||||
|
||||
memset(&info, 0, sizeof(info)); |
||||
info.acpi_node.companion = adev; |
||||
info.irq = -1; |
||||
|
||||
INIT_LIST_HEAD(&resource_list); |
||||
ret = acpi_dev_get_resources(adev, &resource_list, |
||||
acpi_i2c_add_resource, &info); |
||||
acpi_dev_free_resource_list(&resource_list); |
||||
|
||||
if (ret < 0 || !info.addr) |
||||
return AE_OK; |
||||
|
||||
adev->power.flags.ignore_parent = true; |
||||
strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type)); |
||||
if (!i2c_new_device(adapter, &info)) { |
||||
adev->power.flags.ignore_parent = false; |
||||
dev_err(&adapter->dev, |
||||
"failed to add I2C device %s from ACPI\n", |
||||
dev_name(&adev->dev)); |
||||
} |
||||
|
||||
return AE_OK; |
||||
} |
||||
|
||||
/**
|
||||
* acpi_i2c_register_devices - enumerate I2C slave devices behind adapter |
||||
* @adap: pointer to adapter |
||||
* |
||||
* Enumerate all I2C slave devices behind this adapter by walking the ACPI |
||||
* namespace. When a device is found it will be added to the Linux device |
||||
* model and bound to the corresponding ACPI handle. |
||||
*/ |
||||
void acpi_i2c_register_devices(struct i2c_adapter *adap) |
||||
{ |
||||
acpi_handle handle; |
||||
acpi_status status; |
||||
|
||||
if (!adap->dev.parent) |
||||
return; |
||||
|
||||
handle = ACPI_HANDLE(adap->dev.parent); |
||||
if (!handle) |
||||
return; |
||||
|
||||
status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, |
||||
acpi_i2c_add_device, NULL, |
||||
adap, NULL); |
||||
if (ACPI_FAILURE(status)) |
||||
dev_warn(&adap->dev, "failed to enumerate I2C slaves\n"); |
||||
} |
||||
|
||||
static int acpi_gsb_i2c_read_bytes(struct i2c_client *client, |
||||
u8 cmd, u8 *data, u8 data_len) |
||||
{ |
||||
|
||||
struct i2c_msg msgs[2]; |
||||
int ret; |
||||
u8 *buffer; |
||||
|
||||
buffer = kzalloc(data_len, GFP_KERNEL); |
||||
if (!buffer) |
||||
return AE_NO_MEMORY; |
||||
|
||||
msgs[0].addr = client->addr; |
||||
msgs[0].flags = client->flags; |
||||
msgs[0].len = 1; |
||||
msgs[0].buf = &cmd; |
||||
|
||||
msgs[1].addr = client->addr; |
||||
msgs[1].flags = client->flags | I2C_M_RD; |
||||
msgs[1].len = data_len; |
||||
msgs[1].buf = buffer; |
||||
|
||||
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); |
||||
if (ret < 0) |
||||
dev_err(&client->adapter->dev, "i2c read failed\n"); |
||||
else |
||||
memcpy(data, buffer, data_len); |
||||
|
||||
kfree(buffer); |
||||
return ret; |
||||
} |
||||
|
||||
static int acpi_gsb_i2c_write_bytes(struct i2c_client *client, |
||||
u8 cmd, u8 *data, u8 data_len) |
||||
{ |
||||
|
||||
struct i2c_msg msgs[1]; |
||||
u8 *buffer; |
||||
int ret = AE_OK; |
||||
|
||||
buffer = kzalloc(data_len + 1, GFP_KERNEL); |
||||
if (!buffer) |
||||
return AE_NO_MEMORY; |
||||
|
||||
buffer[0] = cmd; |
||||
memcpy(buffer + 1, data, data_len); |
||||
|
||||
msgs[0].addr = client->addr; |
||||
msgs[0].flags = client->flags; |
||||
msgs[0].len = data_len + 1; |
||||
msgs[0].buf = buffer; |
||||
|
||||
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); |
||||
if (ret < 0) |
||||
dev_err(&client->adapter->dev, "i2c write failed\n"); |
||||
|
||||
kfree(buffer); |
||||
return ret; |
||||
} |
||||
|
||||
static acpi_status |
||||
acpi_i2c_space_handler(u32 function, acpi_physical_address command, |
||||
u32 bits, u64 *value64, |
||||
void *handler_context, void *region_context) |
||||
{ |
||||
struct gsb_buffer *gsb = (struct gsb_buffer *)value64; |
||||
struct acpi_i2c_handler_data *data = handler_context; |
||||
struct acpi_connection_info *info = &data->info; |
||||
struct acpi_resource_i2c_serialbus *sb; |
||||
struct i2c_adapter *adapter = data->adapter; |
||||
struct i2c_client client; |
||||
struct acpi_resource *ares; |
||||
u32 accessor_type = function >> 16; |
||||
u8 action = function & ACPI_IO_MASK; |
||||
acpi_status ret = AE_OK; |
||||
int status; |
||||
|
||||
ret = acpi_buffer_to_resource(info->connection, info->length, &ares); |
||||
if (ACPI_FAILURE(ret)) |
||||
return ret; |
||||
|
||||
if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) { |
||||
ret = AE_BAD_PARAMETER; |
||||
goto err; |
||||
} |
||||
|
||||
sb = &ares->data.i2c_serial_bus; |
||||
if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) { |
||||
ret = AE_BAD_PARAMETER; |
||||
goto err; |
||||
} |
||||
|
||||
memset(&client, 0, sizeof(client)); |
||||
client.adapter = adapter; |
||||
client.addr = sb->slave_address; |
||||
client.flags = 0; |
||||
|
||||
if (sb->access_mode == ACPI_I2C_10BIT_MODE) |
||||
client.flags |= I2C_CLIENT_TEN; |
||||
|
||||
switch (accessor_type) { |
||||
case ACPI_GSB_ACCESS_ATTRIB_SEND_RCV: |
||||
if (action == ACPI_READ) { |
||||
status = i2c_smbus_read_byte(&client); |
||||
if (status >= 0) { |
||||
gsb->bdata = status; |
||||
status = 0; |
||||
} |
||||
} else { |
||||
status = i2c_smbus_write_byte(&client, gsb->bdata); |
||||
} |
||||
break; |
||||
|
||||
case ACPI_GSB_ACCESS_ATTRIB_BYTE: |
||||
if (action == ACPI_READ) { |
||||
status = i2c_smbus_read_byte_data(&client, command); |
||||
if (status >= 0) { |
||||
gsb->bdata = status; |
||||
status = 0; |
||||
} |
||||
} else { |
||||
status = i2c_smbus_write_byte_data(&client, command, |
||||
gsb->bdata); |
||||
} |
||||
break; |
||||
|
||||
case ACPI_GSB_ACCESS_ATTRIB_WORD: |
||||
if (action == ACPI_READ) { |
||||
status = i2c_smbus_read_word_data(&client, command); |
||||
if (status >= 0) { |
||||
gsb->wdata = status; |
||||
status = 0; |
||||
} |
||||
} else { |
||||
status = i2c_smbus_write_word_data(&client, command, |
||||
gsb->wdata); |
||||
} |
||||
break; |
||||
|
||||
case ACPI_GSB_ACCESS_ATTRIB_BLOCK: |
||||
if (action == ACPI_READ) { |
||||
status = i2c_smbus_read_block_data(&client, command, |
||||
gsb->data); |
||||
if (status >= 0) { |
||||
gsb->len = status; |
||||
status = 0; |
||||
} |
||||
} else { |
||||
status = i2c_smbus_write_block_data(&client, command, |
||||
gsb->len, gsb->data); |
||||
} |
||||
break; |
||||
|
||||
case ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE: |
||||
if (action == ACPI_READ) { |
||||
status = acpi_gsb_i2c_read_bytes(&client, command, |
||||
gsb->data, info->access_length); |
||||
if (status > 0) |
||||
status = 0; |
||||
} else { |
||||
status = acpi_gsb_i2c_write_bytes(&client, command, |
||||
gsb->data, info->access_length); |
||||
} |
||||
break; |
||||
|
||||
default: |
||||
pr_info("protocol(0x%02x) is not supported.\n", accessor_type); |
||||
ret = AE_BAD_PARAMETER; |
||||
goto err; |
||||
} |
||||
|
||||
gsb->status = status; |
||||
|
||||
err: |
||||
ACPI_FREE(ares); |
||||
return ret; |
||||
} |
||||
|
||||
|
||||
int acpi_i2c_install_space_handler(struct i2c_adapter *adapter) |
||||
{ |
||||
acpi_handle handle = ACPI_HANDLE(adapter->dev.parent); |
||||
struct acpi_i2c_handler_data *data; |
||||
acpi_status status; |
||||
|
||||
if (!handle) |
||||
return -ENODEV; |
||||
|
||||
data = kzalloc(sizeof(struct acpi_i2c_handler_data), |
||||
GFP_KERNEL); |
||||
if (!data) |
||||
return -ENOMEM; |
||||
|
||||
data->adapter = adapter; |
||||
status = acpi_bus_attach_private_data(handle, (void *)data); |
||||
if (ACPI_FAILURE(status)) { |
||||
kfree(data); |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
status = acpi_install_address_space_handler(handle, |
||||
ACPI_ADR_SPACE_GSBUS, |
||||
&acpi_i2c_space_handler, |
||||
NULL, |
||||
data); |
||||
if (ACPI_FAILURE(status)) { |
||||
dev_err(&adapter->dev, "Error installing i2c space handler\n"); |
||||
acpi_bus_detach_private_data(handle); |
||||
kfree(data); |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void acpi_i2c_remove_space_handler(struct i2c_adapter *adapter) |
||||
{ |
||||
acpi_handle handle = ACPI_HANDLE(adapter->dev.parent); |
||||
struct acpi_i2c_handler_data *data; |
||||
acpi_status status; |
||||
|
||||
if (!handle) |
||||
return; |
||||
|
||||
acpi_remove_address_space_handler(handle, |
||||
ACPI_ADR_SPACE_GSBUS, |
||||
&acpi_i2c_space_handler); |
||||
|
||||
status = acpi_bus_get_private_data(handle, (void **)&data); |
||||
if (ACPI_SUCCESS(status)) |
||||
kfree(data); |
||||
|
||||
acpi_bus_detach_private_data(handle); |
||||
} |
@ -1,10 +0,0 @@ |
||||
#ifndef __LINUX_I2C_S6000_H |
||||
#define __LINUX_I2C_S6000_H |
||||
|
||||
struct s6_i2c_platform_data { |
||||
const char *clock; /* the clock to use */ |
||||
int bus_num; /* the bus number to register */ |
||||
}; |
||||
|
||||
#endif |
||||
|
Loading…
Reference in new issue