2010-01-29 04:47:07 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2009-2010
|
|
|
|
* Nokia Siemens Networks, michael.lawnick.ext@nsn.com
|
|
|
|
*
|
2016-03-18 16:46:26 +08:00
|
|
|
* Portions Copyright (C) 2010 - 2016 Cavium, Inc.
|
2010-01-29 04:47:07 +08:00
|
|
|
*
|
|
|
|
* This is a driver for the i2c adapter in Cavium Networks' OCTEON processors.
|
|
|
|
*
|
|
|
|
* This file is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2. This program is licensed "as is" without any
|
|
|
|
* warranty of any kind, whether express or implied.
|
|
|
|
*/
|
|
|
|
|
2016-04-25 22:33:35 +08:00
|
|
|
#include <linux/atomic.h>
|
2016-08-25 05:25:47 +08:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/i2c.h>
|
2012-07-06 00:12:39 +08:00
|
|
|
#include <linux/interrupt.h>
|
2016-08-25 05:25:47 +08:00
|
|
|
#include <linux/io.h>
|
2010-01-29 04:47:07 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2016-08-25 05:25:47 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_device.h>
|
2010-01-29 04:47:07 +08:00
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
#include <asm/octeon/octeon.h>
|
2016-08-25 05:25:43 +08:00
|
|
|
#include "i2c-octeon-core.h"
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
#define DRV_NAME "i2c-octeon"
|
|
|
|
|
|
|
|
/**
|
2016-03-07 23:10:44 +08:00
|
|
|
* octeon_i2c_int_enable - enable the CORE interrupt
|
|
|
|
* @i2c: The struct octeon_i2c
|
2010-01-29 04:47:07 +08:00
|
|
|
*
|
|
|
|
* The interrupt will be asserted when there is non-STAT_IDLE state in
|
|
|
|
* the SW_TWSI_EOP_TWSI_STAT register.
|
|
|
|
*/
|
|
|
|
static void octeon_i2c_int_enable(struct octeon_i2c *i2c)
|
|
|
|
{
|
2016-03-18 16:46:26 +08:00
|
|
|
octeon_i2c_write_int(i2c, TWSI_INT_CORE_EN);
|
2010-01-29 04:47:07 +08:00
|
|
|
}
|
|
|
|
|
2016-03-07 23:10:44 +08:00
|
|
|
/* disable the CORE interrupt */
|
2010-01-29 04:47:07 +08:00
|
|
|
static void octeon_i2c_int_disable(struct octeon_i2c *i2c)
|
|
|
|
{
|
2016-03-18 16:46:26 +08:00
|
|
|
/* clear TS/ST/IFLG events */
|
2010-01-29 04:47:07 +08:00
|
|
|
octeon_i2c_write_int(i2c, 0);
|
|
|
|
}
|
|
|
|
|
2016-04-25 22:33:35 +08:00
|
|
|
/**
|
|
|
|
* octeon_i2c_int_enable78 - enable the CORE interrupt
|
|
|
|
* @i2c: The struct octeon_i2c
|
|
|
|
*
|
|
|
|
* The interrupt will be asserted when there is non-STAT_IDLE state in the
|
|
|
|
* SW_TWSI_EOP_TWSI_STAT register.
|
|
|
|
*/
|
|
|
|
static void octeon_i2c_int_enable78(struct octeon_i2c *i2c)
|
|
|
|
{
|
|
|
|
atomic_inc_return(&i2c->int_enable_cnt);
|
|
|
|
enable_irq(i2c->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __octeon_i2c_irq_disable(atomic_t *cnt, int irq)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The interrupt can be disabled in two places, but we only
|
|
|
|
* want to make the disable_irq_nosync() call once, so keep
|
|
|
|
* track with the atomic variable.
|
|
|
|
*/
|
|
|
|
count = atomic_dec_if_positive(cnt);
|
|
|
|
if (count >= 0)
|
|
|
|
disable_irq_nosync(irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disable the CORE interrupt */
|
|
|
|
static void octeon_i2c_int_disable78(struct octeon_i2c *i2c)
|
|
|
|
{
|
|
|
|
__octeon_i2c_irq_disable(&i2c->int_enable_cnt, i2c->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* octeon_i2c_hlc_int_enable78 - enable the ST interrupt
|
|
|
|
* @i2c: The struct octeon_i2c
|
|
|
|
*
|
|
|
|
* The interrupt will be asserted when there is non-STAT_IDLE state in
|
|
|
|
* the SW_TWSI_EOP_TWSI_STAT register.
|
|
|
|
*/
|
|
|
|
static void octeon_i2c_hlc_int_enable78(struct octeon_i2c *i2c)
|
|
|
|
{
|
|
|
|
atomic_inc_return(&i2c->hlc_int_enable_cnt);
|
|
|
|
enable_irq(i2c->hlc_irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disable the ST interrupt */
|
|
|
|
static void octeon_i2c_hlc_int_disable78(struct octeon_i2c *i2c)
|
|
|
|
{
|
|
|
|
__octeon_i2c_irq_disable(&i2c->hlc_int_enable_cnt, i2c->hlc_irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HLC interrupt service routine */
|
|
|
|
static irqreturn_t octeon_i2c_hlc_isr78(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct octeon_i2c *i2c = dev_id;
|
|
|
|
|
|
|
|
i2c->hlc_int_disable(i2c);
|
2013-04-18 05:40:17 +08:00
|
|
|
wake_up(&i2c->queue);
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2016-04-25 22:33:34 +08:00
|
|
|
static void octeon_i2c_hlc_int_enable(struct octeon_i2c *i2c)
|
|
|
|
{
|
|
|
|
octeon_i2c_write_int(i2c, TWSI_INT_ST_EN);
|
|
|
|
}
|
|
|
|
|
2010-01-29 04:47:07 +08:00
|
|
|
static u32 octeon_i2c_functionality(struct i2c_adapter *adap)
|
|
|
|
{
|
2016-04-26 22:26:52 +08:00
|
|
|
return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK) |
|
2016-03-18 16:46:29 +08:00
|
|
|
I2C_FUNC_SMBUS_READ_BLOCK_DATA | I2C_SMBUS_BLOCK_PROC_CALL;
|
2010-01-29 04:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_algorithm octeon_i2c_algo = {
|
|
|
|
.master_xfer = octeon_i2c_xfer,
|
|
|
|
.functionality = octeon_i2c_functionality,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_adapter octeon_i2c_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "OCTEON adapter",
|
|
|
|
.algo = &octeon_i2c_algo,
|
|
|
|
};
|
|
|
|
|
2012-11-28 04:59:38 +08:00
|
|
|
static int octeon_i2c_probe(struct platform_device *pdev)
|
2010-01-29 04:47:07 +08:00
|
|
|
{
|
2016-03-18 16:46:26 +08:00
|
|
|
struct device_node *node = pdev->dev.of_node;
|
2016-04-25 22:33:35 +08:00
|
|
|
int irq, result = 0, hlc_irq = 0;
|
2010-01-29 04:47:07 +08:00
|
|
|
struct resource *res_mem;
|
2016-03-18 16:46:26 +08:00
|
|
|
struct octeon_i2c *i2c;
|
2016-04-25 22:33:35 +08:00
|
|
|
bool cn78xx_style;
|
|
|
|
|
|
|
|
cn78xx_style = of_device_is_compatible(node, "cavium,octeon-7890-twsi");
|
|
|
|
if (cn78xx_style) {
|
|
|
|
hlc_irq = platform_get_irq(pdev, 0);
|
|
|
|
if (hlc_irq < 0)
|
|
|
|
return hlc_irq;
|
2010-01-29 04:47:07 +08:00
|
|
|
|
2016-04-25 22:33:35 +08:00
|
|
|
irq = platform_get_irq(pdev, 2);
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
} else {
|
|
|
|
/* All adaptors have an irq. */
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
}
|
2010-01-29 04:47:07 +08:00
|
|
|
|
2012-07-06 00:12:39 +08:00
|
|
|
i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
|
2010-01-29 04:47:07 +08:00
|
|
|
if (!i2c) {
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
i2c->dev = &pdev->dev;
|
|
|
|
|
2016-08-25 05:25:46 +08:00
|
|
|
i2c->roff.sw_twsi = 0x00;
|
|
|
|
i2c->roff.twsi_int = 0x10;
|
|
|
|
i2c->roff.sw_twsi_ext = 0x18;
|
|
|
|
|
2010-01-29 04:47:07 +08:00
|
|
|
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2016-03-18 16:46:27 +08:00
|
|
|
i2c->twsi_base = devm_ioremap_resource(&pdev->dev, res_mem);
|
|
|
|
if (IS_ERR(i2c->twsi_base)) {
|
|
|
|
result = PTR_ERR(i2c->twsi_base);
|
2012-07-06 00:12:39 +08:00
|
|
|
goto out;
|
2010-01-29 04:47:07 +08:00
|
|
|
}
|
|
|
|
|
2012-07-06 00:12:39 +08:00
|
|
|
/*
|
|
|
|
* "clock-rate" is a legacy binding, the official binding is
|
|
|
|
* "clock-frequency". Try the official one first and then
|
|
|
|
* fall back if it doesn't exist.
|
|
|
|
*/
|
2016-03-18 16:46:26 +08:00
|
|
|
if (of_property_read_u32(node, "clock-frequency", &i2c->twsi_freq) &&
|
|
|
|
of_property_read_u32(node, "clock-rate", &i2c->twsi_freq)) {
|
2012-07-06 00:12:39 +08:00
|
|
|
dev_err(i2c->dev,
|
|
|
|
"no I2C 'clock-rate' or 'clock-frequency' property\n");
|
2010-01-29 04:47:07 +08:00
|
|
|
result = -ENXIO;
|
2012-07-06 00:12:39 +08:00
|
|
|
goto out;
|
2010-01-29 04:47:07 +08:00
|
|
|
}
|
|
|
|
|
2012-07-06 00:12:39 +08:00
|
|
|
i2c->sys_freq = octeon_get_io_clock_rate();
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
init_waitqueue_head(&i2c->queue);
|
|
|
|
|
|
|
|
i2c->irq = irq;
|
|
|
|
|
2016-04-25 22:33:35 +08:00
|
|
|
if (cn78xx_style) {
|
|
|
|
i2c->hlc_irq = hlc_irq;
|
|
|
|
|
|
|
|
i2c->int_enable = octeon_i2c_int_enable78;
|
|
|
|
i2c->int_disable = octeon_i2c_int_disable78;
|
|
|
|
i2c->hlc_int_enable = octeon_i2c_hlc_int_enable78;
|
|
|
|
i2c->hlc_int_disable = octeon_i2c_hlc_int_disable78;
|
|
|
|
|
|
|
|
irq_set_status_flags(i2c->irq, IRQ_NOAUTOEN);
|
|
|
|
irq_set_status_flags(i2c->hlc_irq, IRQ_NOAUTOEN);
|
|
|
|
|
|
|
|
result = devm_request_irq(&pdev->dev, i2c->hlc_irq,
|
|
|
|
octeon_i2c_hlc_isr78, 0,
|
|
|
|
DRV_NAME, i2c);
|
|
|
|
if (result < 0) {
|
|
|
|
dev_err(i2c->dev, "failed to attach interrupt\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i2c->int_enable = octeon_i2c_int_enable;
|
|
|
|
i2c->int_disable = octeon_i2c_int_disable;
|
|
|
|
i2c->hlc_int_enable = octeon_i2c_hlc_int_enable;
|
|
|
|
i2c->hlc_int_disable = octeon_i2c_int_disable;
|
|
|
|
}
|
|
|
|
|
2012-07-06 00:12:39 +08:00
|
|
|
result = devm_request_irq(&pdev->dev, i2c->irq,
|
|
|
|
octeon_i2c_isr, 0, DRV_NAME, i2c);
|
2010-01-29 04:47:07 +08:00
|
|
|
if (result < 0) {
|
|
|
|
dev_err(i2c->dev, "failed to attach interrupt\n");
|
2012-07-06 00:12:39 +08:00
|
|
|
goto out;
|
2010-01-29 04:47:07 +08:00
|
|
|
}
|
|
|
|
|
2016-04-27 17:44:39 +08:00
|
|
|
if (OCTEON_IS_MODEL(OCTEON_CN38XX))
|
|
|
|
i2c->broken_irq_check = true;
|
|
|
|
|
2016-03-18 16:46:26 +08:00
|
|
|
result = octeon_i2c_init_lowlevel(i2c);
|
2010-01-29 04:47:07 +08:00
|
|
|
if (result) {
|
|
|
|
dev_err(i2c->dev, "init low level failed\n");
|
2012-07-06 00:12:39 +08:00
|
|
|
goto out;
|
2010-01-29 04:47:07 +08:00
|
|
|
}
|
|
|
|
|
2016-03-18 16:46:26 +08:00
|
|
|
octeon_i2c_set_clock(i2c);
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
i2c->adap = octeon_i2c_ops;
|
2016-04-11 23:28:32 +08:00
|
|
|
i2c->adap.timeout = msecs_to_jiffies(2);
|
|
|
|
i2c->adap.retries = 5;
|
2016-04-25 22:33:31 +08:00
|
|
|
i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info;
|
2010-01-29 04:47:07 +08:00
|
|
|
i2c->adap.dev.parent = &pdev->dev;
|
2016-03-18 16:46:26 +08:00
|
|
|
i2c->adap.dev.of_node = node;
|
2010-01-29 04:47:07 +08:00
|
|
|
i2c_set_adapdata(&i2c->adap, i2c);
|
|
|
|
platform_set_drvdata(pdev, i2c);
|
|
|
|
|
2012-07-06 00:12:39 +08:00
|
|
|
result = i2c_add_adapter(&i2c->adap);
|
2016-08-09 19:36:17 +08:00
|
|
|
if (result < 0)
|
2013-02-15 21:18:35 +08:00
|
|
|
goto out;
|
2016-03-18 16:46:26 +08:00
|
|
|
dev_info(i2c->dev, "probed\n");
|
2012-07-06 00:12:39 +08:00
|
|
|
return 0;
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2012-11-28 04:59:38 +08:00
|
|
|
static int octeon_i2c_remove(struct platform_device *pdev)
|
2010-01-29 04:47:07 +08:00
|
|
|
{
|
|
|
|
struct octeon_i2c *i2c = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
i2c_del_adapter(&i2c->adap);
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2016-03-18 16:46:26 +08:00
|
|
|
static const struct of_device_id octeon_i2c_match[] = {
|
|
|
|
{ .compatible = "cavium,octeon-3860-twsi", },
|
2016-04-25 22:33:35 +08:00
|
|
|
{ .compatible = "cavium,octeon-7890-twsi", },
|
2012-07-06 00:12:39 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, octeon_i2c_match);
|
|
|
|
|
2010-01-29 04:47:07 +08:00
|
|
|
static struct platform_driver octeon_i2c_driver = {
|
|
|
|
.probe = octeon_i2c_probe,
|
2012-11-28 04:59:38 +08:00
|
|
|
.remove = octeon_i2c_remove,
|
2010-01-29 04:47:07 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
2012-07-06 00:12:39 +08:00
|
|
|
.of_match_table = octeon_i2c_match,
|
2010-01-29 04:47:07 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-13 03:32:04 +08:00
|
|
|
module_platform_driver(octeon_i2c_driver);
|
2010-01-29 04:47:07 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>");
|
|
|
|
MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
|
|
|
|
MODULE_LICENSE("GPL");
|