i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
/*
|
|
|
|
* Bitbanging I2C bus driver using the GPIO API
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Atmel Corporation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/i2c-algo-bit.h>
|
|
|
|
#include <linux/i2c-gpio.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
#include <linux/platform_device.h>
|
2012-02-05 10:22:34 +00:00
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
#include <linux/of_i2c.h>
|
|
|
|
|
|
|
|
struct i2c_gpio_private_data {
|
|
|
|
struct i2c_adapter adap;
|
|
|
|
struct i2c_algo_bit_data bit_data;
|
|
|
|
struct i2c_gpio_platform_data pdata;
|
|
|
|
};
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
|
|
|
|
/* Toggle SDA by changing the direction of the pin */
|
|
|
|
static void i2c_gpio_setsda_dir(void *data, int state)
|
|
|
|
{
|
|
|
|
struct i2c_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
gpio_direction_input(pdata->sda_pin);
|
|
|
|
else
|
|
|
|
gpio_direction_output(pdata->sda_pin, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toggle SDA by changing the output value of the pin. This is only
|
|
|
|
* valid for pins configured as open drain (i.e. setting the value
|
|
|
|
* high effectively turns off the output driver.)
|
|
|
|
*/
|
|
|
|
static void i2c_gpio_setsda_val(void *data, int state)
|
|
|
|
{
|
|
|
|
struct i2c_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
gpio_set_value(pdata->sda_pin, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Toggle SCL by changing the direction of the pin. */
|
|
|
|
static void i2c_gpio_setscl_dir(void *data, int state)
|
|
|
|
{
|
|
|
|
struct i2c_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
gpio_direction_input(pdata->scl_pin);
|
|
|
|
else
|
|
|
|
gpio_direction_output(pdata->scl_pin, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toggle SCL by changing the output value of the pin. This is used
|
|
|
|
* for pins that are configured as open drain and for output-only
|
|
|
|
* pins. The latter case will break the i2c protocol, but it will
|
|
|
|
* often work in practice.
|
|
|
|
*/
|
|
|
|
static void i2c_gpio_setscl_val(void *data, int state)
|
|
|
|
{
|
|
|
|
struct i2c_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
gpio_set_value(pdata->scl_pin, state);
|
|
|
|
}
|
|
|
|
|
2007-07-12 12:12:30 +00:00
|
|
|
static int i2c_gpio_getsda(void *data)
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
{
|
|
|
|
struct i2c_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
return gpio_get_value(pdata->sda_pin);
|
|
|
|
}
|
|
|
|
|
2007-07-12 12:12:30 +00:00
|
|
|
static int i2c_gpio_getscl(void *data)
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
{
|
|
|
|
struct i2c_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
return gpio_get_value(pdata->scl_pin);
|
|
|
|
}
|
|
|
|
|
2012-02-05 10:22:34 +00:00
|
|
|
static int __devinit of_i2c_gpio_probe(struct device_node *np,
|
|
|
|
struct i2c_gpio_platform_data *pdata)
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
if (of_gpio_count(np) < 2)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pdata->sda_pin = of_get_gpio(np, 0);
|
|
|
|
pdata->scl_pin = of_get_gpio(np, 1);
|
|
|
|
|
|
|
|
if (!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin)) {
|
|
|
|
pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n",
|
|
|
|
np->full_name, pdata->sda_pin, pdata->scl_pin);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);
|
|
|
|
|
|
|
|
if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", ®))
|
|
|
|
pdata->timeout = msecs_to_jiffies(reg);
|
|
|
|
|
|
|
|
pdata->sda_is_open_drain =
|
|
|
|
of_property_read_bool(np, "i2c-gpio,sda-open-drain");
|
|
|
|
pdata->scl_is_open_drain =
|
|
|
|
of_property_read_bool(np, "i2c-gpio,scl-open-drain");
|
|
|
|
pdata->scl_is_output_only =
|
|
|
|
of_property_read_bool(np, "i2c-gpio,scl-output-only");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-28 11:04:09 +00:00
|
|
|
static int __devinit i2c_gpio_probe(struct platform_device *pdev)
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
{
|
2012-02-05 10:22:34 +00:00
|
|
|
struct i2c_gpio_private_data *priv;
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
struct i2c_gpio_platform_data *pdata;
|
|
|
|
struct i2c_algo_bit_data *bit_data;
|
|
|
|
struct i2c_adapter *adap;
|
|
|
|
int ret;
|
|
|
|
|
2012-02-05 10:22:34 +00:00
|
|
|
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
adap = &priv->adap;
|
|
|
|
bit_data = &priv->bit_data;
|
|
|
|
pdata = &priv->pdata;
|
|
|
|
|
|
|
|
if (pdev->dev.of_node) {
|
|
|
|
ret = of_i2c_gpio_probe(pdev->dev.of_node, pdata);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
if (!pdev->dev.platform_data)
|
|
|
|
return -ENXIO;
|
|
|
|
memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata));
|
|
|
|
}
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
|
|
|
|
ret = gpio_request(pdata->sda_pin, "sda");
|
|
|
|
if (ret)
|
|
|
|
goto err_request_sda;
|
|
|
|
ret = gpio_request(pdata->scl_pin, "scl");
|
|
|
|
if (ret)
|
|
|
|
goto err_request_scl;
|
|
|
|
|
|
|
|
if (pdata->sda_is_open_drain) {
|
|
|
|
gpio_direction_output(pdata->sda_pin, 1);
|
|
|
|
bit_data->setsda = i2c_gpio_setsda_val;
|
|
|
|
} else {
|
|
|
|
gpio_direction_input(pdata->sda_pin);
|
|
|
|
bit_data->setsda = i2c_gpio_setsda_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->scl_is_open_drain || pdata->scl_is_output_only) {
|
|
|
|
gpio_direction_output(pdata->scl_pin, 1);
|
|
|
|
bit_data->setscl = i2c_gpio_setscl_val;
|
|
|
|
} else {
|
|
|
|
gpio_direction_input(pdata->scl_pin);
|
|
|
|
bit_data->setscl = i2c_gpio_setscl_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pdata->scl_is_output_only)
|
|
|
|
bit_data->getscl = i2c_gpio_getscl;
|
|
|
|
bit_data->getsda = i2c_gpio_getsda;
|
|
|
|
|
|
|
|
if (pdata->udelay)
|
|
|
|
bit_data->udelay = pdata->udelay;
|
|
|
|
else if (pdata->scl_is_output_only)
|
|
|
|
bit_data->udelay = 50; /* 10 kHz */
|
|
|
|
else
|
|
|
|
bit_data->udelay = 5; /* 100 kHz */
|
|
|
|
|
|
|
|
if (pdata->timeout)
|
|
|
|
bit_data->timeout = pdata->timeout;
|
|
|
|
else
|
|
|
|
bit_data->timeout = HZ / 10; /* 100 ms */
|
|
|
|
|
|
|
|
bit_data->data = pdata;
|
|
|
|
|
|
|
|
adap->owner = THIS_MODULE;
|
|
|
|
snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
|
|
|
|
adap->algo_data = bit_data;
|
2008-07-14 20:38:29 +00:00
|
|
|
adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
adap->dev.parent = &pdev->dev;
|
2012-02-05 10:22:34 +00:00
|
|
|
adap->dev.of_node = pdev->dev.of_node;
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
|
2007-07-12 12:12:30 +00:00
|
|
|
/*
|
|
|
|
* If "dev->id" is negative we consider it as zero.
|
|
|
|
* The reason to do so is to avoid sysfs names that only make
|
|
|
|
* sense when there are multiple adapters.
|
|
|
|
*/
|
2007-09-09 20:29:13 +00:00
|
|
|
adap->nr = (pdev->id != -1) ? pdev->id : 0;
|
2007-07-12 12:12:30 +00:00
|
|
|
ret = i2c_bit_add_numbered_bus(adap);
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_add_bus;
|
|
|
|
|
2012-02-05 10:22:34 +00:00
|
|
|
of_i2c_register_devices(adap);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, priv);
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
|
|
|
|
dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n",
|
|
|
|
pdata->sda_pin, pdata->scl_pin,
|
|
|
|
pdata->scl_is_output_only
|
|
|
|
? ", no clock stretching" : "");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_add_bus:
|
|
|
|
gpio_free(pdata->scl_pin);
|
|
|
|
err_request_scl:
|
|
|
|
gpio_free(pdata->sda_pin);
|
|
|
|
err_request_sda:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-07-28 11:04:09 +00:00
|
|
|
static int __devexit i2c_gpio_remove(struct platform_device *pdev)
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
{
|
2012-02-05 10:22:34 +00:00
|
|
|
struct i2c_gpio_private_data *priv;
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
struct i2c_gpio_platform_data *pdata;
|
|
|
|
struct i2c_adapter *adap;
|
|
|
|
|
2012-02-05 10:22:34 +00:00
|
|
|
priv = platform_get_drvdata(pdev);
|
|
|
|
adap = &priv->adap;
|
|
|
|
pdata = &priv->pdata;
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
|
|
|
|
i2c_del_adapter(adap);
|
|
|
|
gpio_free(pdata->scl_pin);
|
|
|
|
gpio_free(pdata->sda_pin);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-05 10:22:34 +00:00
|
|
|
#if defined(CONFIG_OF)
|
|
|
|
static const struct of_device_id i2c_gpio_dt_ids[] = {
|
|
|
|
{ .compatible = "i2c-gpio", },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids);
|
|
|
|
#endif
|
|
|
|
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
static struct platform_driver i2c_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "i2c-gpio",
|
|
|
|
.owner = THIS_MODULE,
|
2012-02-05 10:22:34 +00:00
|
|
|
.of_match_table = of_match_ptr(i2c_gpio_dt_ids),
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
},
|
2008-07-28 11:04:09 +00:00
|
|
|
.probe = i2c_gpio_probe,
|
|
|
|
.remove = __devexit_p(i2c_gpio_remove),
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init i2c_gpio_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-07-28 11:04:09 +00:00
|
|
|
ret = platform_driver_register(&i2c_gpio_driver);
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-05-21 16:40:58 +00:00
|
|
|
subsys_initcall(i2c_gpio_init);
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
|
|
|
|
static void __exit i2c_gpio_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&i2c_gpio_driver);
|
|
|
|
}
|
|
|
|
module_exit(i2c_gpio_exit);
|
|
|
|
|
2011-05-18 14:49:24 +00:00
|
|
|
MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01 21:26:34 +00:00
|
|
|
MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-22 20:16:49 +00:00
|
|
|
MODULE_ALIAS("platform:i2c-gpio");
|