Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: i2c: Constify i2c_client where possible i2c-algo-bit: Complain about masters which can't read SCL i2c-algo-bit: Refactor adapter registration i2c: Add generic I2C multiplexer using GPIO API i2c-nforce2: Remove unnecessary cast of pci_get_drvdata i2c-i801: Include <linux/slab.h>
This commit is contained in:
commit
8adbf8d467
|
@ -0,0 +1,65 @@
|
||||||
|
Kernel driver gpio-i2cmux
|
||||||
|
|
||||||
|
Author: Peter Korsgaard <peter.korsgaard@barco.com>
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
|
||||||
|
gpio-i2cmux is an i2c mux driver providing access to I2C bus segments
|
||||||
|
from a master I2C bus and a hardware MUX controlled through GPIO pins.
|
||||||
|
|
||||||
|
E.G.:
|
||||||
|
|
||||||
|
---------- ---------- Bus segment 1 - - - - -
|
||||||
|
| | SCL/SDA | |-------------- | |
|
||||||
|
| |------------| |
|
||||||
|
| | | | Bus segment 2 | |
|
||||||
|
| Linux | GPIO 1..N | MUX |--------------- Devices
|
||||||
|
| |------------| | | |
|
||||||
|
| | | | Bus segment M
|
||||||
|
| | | |---------------| |
|
||||||
|
---------- ---------- - - - - -
|
||||||
|
|
||||||
|
SCL/SDA of the master I2C bus is multiplexed to bus segment 1..M
|
||||||
|
according to the settings of the GPIO pins 1..N.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
gpio-i2cmux uses the platform bus, so you need to provide a struct
|
||||||
|
platform_device with the platform_data pointing to a struct
|
||||||
|
gpio_i2cmux_platform_data with the I2C adapter number of the master
|
||||||
|
bus, the number of bus segments to create and the GPIO pins used
|
||||||
|
to control it. See include/linux/gpio-i2cmux.h for details.
|
||||||
|
|
||||||
|
E.G. something like this for a MUX providing 4 bus segments
|
||||||
|
controlled through 3 GPIO pins:
|
||||||
|
|
||||||
|
#include <linux/gpio-i2cmux.h>
|
||||||
|
#include <linux/platform_device.h>
|
||||||
|
|
||||||
|
static const unsigned myboard_gpiomux_gpios[] = {
|
||||||
|
AT91_PIN_PC26, AT91_PIN_PC25, AT91_PIN_PC24
|
||||||
|
};
|
||||||
|
|
||||||
|
static const unsigned myboard_gpiomux_values[] = {
|
||||||
|
0, 1, 2, 3
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct gpio_i2cmux_platform_data myboard_i2cmux_data = {
|
||||||
|
.parent = 1,
|
||||||
|
.base_nr = 2, /* optional */
|
||||||
|
.values = myboard_gpiomux_values,
|
||||||
|
.n_values = ARRAY_SIZE(myboard_gpiomux_values),
|
||||||
|
.gpios = myboard_gpiomux_gpios,
|
||||||
|
.n_gpios = ARRAY_SIZE(myboard_gpiomux_gpios),
|
||||||
|
.idle = 4, /* optional */
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct platform_device myboard_i2cmux = {
|
||||||
|
.name = "gpio-i2cmux",
|
||||||
|
.id = 0,
|
||||||
|
.dev = {
|
||||||
|
.platform_data = &myboard_i2cmux_data,
|
||||||
|
},
|
||||||
|
};
|
|
@ -2692,6 +2692,14 @@ S: Supported
|
||||||
F: drivers/i2c/busses/i2c-gpio.c
|
F: drivers/i2c/busses/i2c-gpio.c
|
||||||
F: include/linux/i2c-gpio.h
|
F: include/linux/i2c-gpio.h
|
||||||
|
|
||||||
|
GENERIC GPIO I2C MULTIPLEXER DRIVER
|
||||||
|
M: Peter Korsgaard <peter.korsgaard@barco.com>
|
||||||
|
L: linux-i2c@vger.kernel.org
|
||||||
|
S: Supported
|
||||||
|
F: drivers/i2c/muxes/gpio-i2cmux.c
|
||||||
|
F: include/linux/gpio-i2cmux.h
|
||||||
|
F: Documentation/i2c/muxes/gpio-i2cmux
|
||||||
|
|
||||||
GENERIC HDLC (WAN) DRIVERS
|
GENERIC HDLC (WAN) DRIVERS
|
||||||
M: Krzysztof Halasa <khc@pm.waw.pl>
|
M: Krzysztof Halasa <khc@pm.waw.pl>
|
||||||
W: http://www.kernel.org/pub/linux/utils/net/hdlc/
|
W: http://www.kernel.org/pub/linux/utils/net/hdlc/
|
||||||
|
|
|
@ -600,12 +600,14 @@ static const struct i2c_algorithm i2c_bit_algo = {
|
||||||
/*
|
/*
|
||||||
* registering functions to load algorithms at runtime
|
* registering functions to load algorithms at runtime
|
||||||
*/
|
*/
|
||||||
static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
|
static int __i2c_bit_add_bus(struct i2c_adapter *adap,
|
||||||
|
int (*add_adapter)(struct i2c_adapter *))
|
||||||
{
|
{
|
||||||
struct i2c_algo_bit_data *bit_adap = adap->algo_data;
|
struct i2c_algo_bit_data *bit_adap = adap->algo_data;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (bit_test) {
|
if (bit_test) {
|
||||||
int ret = test_bus(bit_adap, adap->name);
|
ret = test_bus(bit_adap, adap->name);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
@ -614,30 +616,27 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
|
||||||
adap->algo = &i2c_bit_algo;
|
adap->algo = &i2c_bit_algo;
|
||||||
adap->retries = 3;
|
adap->retries = 3;
|
||||||
|
|
||||||
|
ret = add_adapter(adap);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* Complain if SCL can't be read */
|
||||||
|
if (bit_adap->getscl == NULL) {
|
||||||
|
dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n");
|
||||||
|
dev_warn(&adap->dev, "Bus may be unreliable\n");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_bit_add_bus(struct i2c_adapter *adap)
|
int i2c_bit_add_bus(struct i2c_adapter *adap)
|
||||||
{
|
{
|
||||||
int err;
|
return __i2c_bit_add_bus(adap, i2c_add_adapter);
|
||||||
|
|
||||||
err = i2c_bit_prepare_bus(adap);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
return i2c_add_adapter(adap);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(i2c_bit_add_bus);
|
EXPORT_SYMBOL(i2c_bit_add_bus);
|
||||||
|
|
||||||
int i2c_bit_add_numbered_bus(struct i2c_adapter *adap)
|
int i2c_bit_add_numbered_bus(struct i2c_adapter *adap)
|
||||||
{
|
{
|
||||||
int err;
|
return __i2c_bit_add_bus(adap, i2c_add_numbered_adapter);
|
||||||
|
|
||||||
err = i2c_bit_prepare_bus(adap);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
return i2c_add_numbered_adapter(adap);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(i2c_bit_add_numbered_bus);
|
EXPORT_SYMBOL(i2c_bit_add_numbered_bus);
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
#include <linux/acpi.h>
|
#include <linux/acpi.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/dmi.h>
|
#include <linux/dmi.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
|
||||||
/* I801 SMBus address offsets */
|
/* I801 SMBus address offsets */
|
||||||
#define SMBHSTSTS(p) (0 + (p)->smba)
|
#define SMBHSTSTS(p) (0 + (p)->smba)
|
||||||
|
|
|
@ -432,7 +432,7 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
|
||||||
|
|
||||||
static void __devexit nforce2_remove(struct pci_dev *dev)
|
static void __devexit nforce2_remove(struct pci_dev *dev)
|
||||||
{
|
{
|
||||||
struct nforce2_smbus *smbuses = (void*) pci_get_drvdata(dev);
|
struct nforce2_smbus *smbuses = pci_get_drvdata(dev);
|
||||||
|
|
||||||
nforce2_set_reference(NULL);
|
nforce2_set_reference(NULL);
|
||||||
if (smbuses[0].base) {
|
if (smbuses[0].base) {
|
||||||
|
|
|
@ -1362,7 +1362,7 @@ EXPORT_SYMBOL(i2c_transfer);
|
||||||
*
|
*
|
||||||
* Returns negative errno, or else the number of bytes written.
|
* Returns negative errno, or else the number of bytes written.
|
||||||
*/
|
*/
|
||||||
int i2c_master_send(struct i2c_client *client, const char *buf, int count)
|
int i2c_master_send(const struct i2c_client *client, const char *buf, int count)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct i2c_adapter *adap = client->adapter;
|
struct i2c_adapter *adap = client->adapter;
|
||||||
|
@ -1389,7 +1389,7 @@ EXPORT_SYMBOL(i2c_master_send);
|
||||||
*
|
*
|
||||||
* Returns negative errno, or else the number of bytes read.
|
* Returns negative errno, or else the number of bytes read.
|
||||||
*/
|
*/
|
||||||
int i2c_master_recv(struct i2c_client *client, char *buf, int count)
|
int i2c_master_recv(const struct i2c_client *client, char *buf, int count)
|
||||||
{
|
{
|
||||||
struct i2c_adapter *adap = client->adapter;
|
struct i2c_adapter *adap = client->adapter;
|
||||||
struct i2c_msg msg;
|
struct i2c_msg msg;
|
||||||
|
@ -1679,7 +1679,7 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
|
||||||
* This executes the SMBus "receive byte" protocol, returning negative errno
|
* This executes the SMBus "receive byte" protocol, returning negative errno
|
||||||
* else the byte received from the device.
|
* else the byte received from the device.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_read_byte(struct i2c_client *client)
|
s32 i2c_smbus_read_byte(const struct i2c_client *client)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
int status;
|
int status;
|
||||||
|
@ -1699,7 +1699,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte);
|
||||||
* This executes the SMBus "send byte" protocol, returning negative errno
|
* This executes the SMBus "send byte" protocol, returning negative errno
|
||||||
* else zero on success.
|
* else zero on success.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
|
s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)
|
||||||
{
|
{
|
||||||
return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
|
return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
|
||||||
I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
|
I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
|
||||||
|
@ -1714,7 +1714,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte);
|
||||||
* This executes the SMBus "read byte" protocol, returning negative errno
|
* This executes the SMBus "read byte" protocol, returning negative errno
|
||||||
* else a data byte received from the device.
|
* else a data byte received from the device.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
|
s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
int status;
|
int status;
|
||||||
|
@ -1735,7 +1735,8 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data);
|
||||||
* This executes the SMBus "write byte" protocol, returning negative errno
|
* This executes the SMBus "write byte" protocol, returning negative errno
|
||||||
* else zero on success.
|
* else zero on success.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
|
s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command,
|
||||||
|
u8 value)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
data.byte = value;
|
data.byte = value;
|
||||||
|
@ -1753,7 +1754,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte_data);
|
||||||
* This executes the SMBus "read word" protocol, returning negative errno
|
* This executes the SMBus "read word" protocol, returning negative errno
|
||||||
* else a 16-bit unsigned "word" received from the device.
|
* else a 16-bit unsigned "word" received from the device.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
|
s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
int status;
|
int status;
|
||||||
|
@ -1774,7 +1775,8 @@ EXPORT_SYMBOL(i2c_smbus_read_word_data);
|
||||||
* This executes the SMBus "write word" protocol, returning negative errno
|
* This executes the SMBus "write word" protocol, returning negative errno
|
||||||
* else zero on success.
|
* else zero on success.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
|
s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command,
|
||||||
|
u16 value)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
data.word = value;
|
data.word = value;
|
||||||
|
@ -1793,7 +1795,8 @@ EXPORT_SYMBOL(i2c_smbus_write_word_data);
|
||||||
* This executes the SMBus "process call" protocol, returning negative errno
|
* This executes the SMBus "process call" protocol, returning negative errno
|
||||||
* else a 16-bit unsigned "word" received from the device.
|
* else a 16-bit unsigned "word" received from the device.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value)
|
s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command,
|
||||||
|
u16 value)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
int status;
|
int status;
|
||||||
|
@ -1821,7 +1824,7 @@ EXPORT_SYMBOL(i2c_smbus_process_call);
|
||||||
* support this; its emulation through I2C messaging relies on a specific
|
* support this; its emulation through I2C messaging relies on a specific
|
||||||
* mechanism (I2C_M_RECV_LEN) which may not be implemented.
|
* mechanism (I2C_M_RECV_LEN) which may not be implemented.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command,
|
s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command,
|
||||||
u8 *values)
|
u8 *values)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
|
@ -1848,7 +1851,7 @@ EXPORT_SYMBOL(i2c_smbus_read_block_data);
|
||||||
* This executes the SMBus "block write" protocol, returning negative errno
|
* This executes the SMBus "block write" protocol, returning negative errno
|
||||||
* else zero on success.
|
* else zero on success.
|
||||||
*/
|
*/
|
||||||
s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
|
s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command,
|
||||||
u8 length, const u8 *values)
|
u8 length, const u8 *values)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
|
@ -1864,7 +1867,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
|
||||||
EXPORT_SYMBOL(i2c_smbus_write_block_data);
|
EXPORT_SYMBOL(i2c_smbus_write_block_data);
|
||||||
|
|
||||||
/* Returns the number of read bytes */
|
/* Returns the number of read bytes */
|
||||||
s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command,
|
s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command,
|
||||||
u8 length, u8 *values)
|
u8 length, u8 *values)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
|
@ -1884,7 +1887,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
|
EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
|
||||||
|
|
||||||
s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
|
s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command,
|
||||||
u8 length, const u8 *values)
|
u8 length, const u8 *values)
|
||||||
{
|
{
|
||||||
union i2c_smbus_data data;
|
union i2c_smbus_data data;
|
||||||
|
|
|
@ -5,6 +5,18 @@
|
||||||
menu "Multiplexer I2C Chip support"
|
menu "Multiplexer I2C Chip support"
|
||||||
depends on I2C_MUX
|
depends on I2C_MUX
|
||||||
|
|
||||||
|
config I2C_MUX_GPIO
|
||||||
|
tristate "GPIO-based I2C multiplexer"
|
||||||
|
depends on GENERIC_GPIO
|
||||||
|
help
|
||||||
|
If you say yes to this option, support will be included for a
|
||||||
|
GPIO based I2C multiplexer. This driver provides access to
|
||||||
|
I2C busses connected through a MUX, which is controlled
|
||||||
|
through GPIO pins.
|
||||||
|
|
||||||
|
This driver can also be built as a module. If so, the module
|
||||||
|
will be called gpio-i2cmux.
|
||||||
|
|
||||||
config I2C_MUX_PCA9541
|
config I2C_MUX_PCA9541
|
||||||
tristate "NXP PCA9541 I2C Master Selector"
|
tristate "NXP PCA9541 I2C Master Selector"
|
||||||
depends on EXPERIMENTAL
|
depends on EXPERIMENTAL
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#
|
#
|
||||||
# Makefile for multiplexer I2C chip drivers.
|
# Makefile for multiplexer I2C chip drivers.
|
||||||
|
|
||||||
|
obj-$(CONFIG_I2C_MUX_GPIO) += gpio-i2cmux.o
|
||||||
obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o
|
obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o
|
||||||
obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o
|
obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*
|
||||||
|
* I2C multiplexer using GPIO API
|
||||||
|
*
|
||||||
|
* Peter Korsgaard <peter.korsgaard@barco.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/i2c.h>
|
||||||
|
#include <linux/i2c-mux.h>
|
||||||
|
#include <linux/gpio-i2cmux.h>
|
||||||
|
#include <linux/platform_device.h>
|
||||||
|
#include <linux/init.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
#include <linux/gpio.h>
|
||||||
|
|
||||||
|
struct gpiomux {
|
||||||
|
struct i2c_adapter *parent;
|
||||||
|
struct i2c_adapter **adap; /* child busses */
|
||||||
|
struct gpio_i2cmux_platform_data data;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void gpiomux_set(const struct gpiomux *mux, unsigned val)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < mux->data.n_gpios; i++)
|
||||||
|
gpio_set_value(mux->data.gpios[i], val & (1 << i));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gpiomux_select(struct i2c_adapter *adap, void *data, u32 chan)
|
||||||
|
{
|
||||||
|
struct gpiomux *mux = data;
|
||||||
|
|
||||||
|
gpiomux_set(mux, mux->data.values[chan]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gpiomux_deselect(struct i2c_adapter *adap, void *data, u32 chan)
|
||||||
|
{
|
||||||
|
struct gpiomux *mux = data;
|
||||||
|
|
||||||
|
gpiomux_set(mux, mux->data.idle);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __devinit gpiomux_probe(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
struct gpiomux *mux;
|
||||||
|
struct gpio_i2cmux_platform_data *pdata;
|
||||||
|
struct i2c_adapter *parent;
|
||||||
|
int (*deselect) (struct i2c_adapter *, void *, u32);
|
||||||
|
unsigned initial_state;
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
|
pdata = pdev->dev.platform_data;
|
||||||
|
if (!pdata) {
|
||||||
|
dev_err(&pdev->dev, "Missing platform data\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent = i2c_get_adapter(pdata->parent);
|
||||||
|
if (!parent) {
|
||||||
|
dev_err(&pdev->dev, "Parent adapter (%d) not found\n",
|
||||||
|
pdata->parent);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
|
||||||
|
if (!mux) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto alloc_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
mux->parent = parent;
|
||||||
|
mux->data = *pdata;
|
||||||
|
mux->adap = kzalloc(sizeof(struct i2c_adapter *) * pdata->n_values,
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!mux->adap) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto alloc_failed2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdata->idle != GPIO_I2CMUX_NO_IDLE) {
|
||||||
|
initial_state = pdata->idle;
|
||||||
|
deselect = gpiomux_deselect;
|
||||||
|
} else {
|
||||||
|
initial_state = pdata->values[0];
|
||||||
|
deselect = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < pdata->n_gpios; i++) {
|
||||||
|
ret = gpio_request(pdata->gpios[i], "gpio-i2cmux");
|
||||||
|
if (ret)
|
||||||
|
goto err_request_gpio;
|
||||||
|
gpio_direction_output(pdata->gpios[i],
|
||||||
|
initial_state & (1 << i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < pdata->n_values; i++) {
|
||||||
|
u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0;
|
||||||
|
|
||||||
|
mux->adap[i] = i2c_add_mux_adapter(parent, mux, nr, i,
|
||||||
|
gpiomux_select, deselect);
|
||||||
|
if (!mux->adap[i]) {
|
||||||
|
ret = -ENODEV;
|
||||||
|
dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
|
||||||
|
goto add_adapter_failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_info(&pdev->dev, "%d port mux on %s adapter\n",
|
||||||
|
pdata->n_values, parent->name);
|
||||||
|
|
||||||
|
platform_set_drvdata(pdev, mux);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
add_adapter_failed:
|
||||||
|
for (; i > 0; i--)
|
||||||
|
i2c_del_mux_adapter(mux->adap[i - 1]);
|
||||||
|
i = pdata->n_gpios;
|
||||||
|
err_request_gpio:
|
||||||
|
for (; i > 0; i--)
|
||||||
|
gpio_free(pdata->gpios[i - 1]);
|
||||||
|
kfree(mux->adap);
|
||||||
|
alloc_failed2:
|
||||||
|
kfree(mux);
|
||||||
|
alloc_failed:
|
||||||
|
i2c_put_adapter(parent);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __devexit gpiomux_remove(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
struct gpiomux *mux = platform_get_drvdata(pdev);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < mux->data.n_values; i++)
|
||||||
|
i2c_del_mux_adapter(mux->adap[i]);
|
||||||
|
|
||||||
|
for (i = 0; i < mux->data.n_gpios; i++)
|
||||||
|
gpio_free(mux->data.gpios[i]);
|
||||||
|
|
||||||
|
platform_set_drvdata(pdev, NULL);
|
||||||
|
i2c_put_adapter(mux->parent);
|
||||||
|
kfree(mux->adap);
|
||||||
|
kfree(mux);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct platform_driver gpiomux_driver = {
|
||||||
|
.probe = gpiomux_probe,
|
||||||
|
.remove = __devexit_p(gpiomux_remove),
|
||||||
|
.driver = {
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.name = "gpio-i2cmux",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static int __init gpiomux_init(void)
|
||||||
|
{
|
||||||
|
return platform_driver_register(&gpiomux_driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit gpiomux_exit(void)
|
||||||
|
{
|
||||||
|
platform_driver_unregister(&gpiomux_driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
module_init(gpiomux_init);
|
||||||
|
module_exit(gpiomux_exit);
|
||||||
|
|
||||||
|
MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver");
|
||||||
|
MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>");
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
|
MODULE_ALIAS("platform:gpio-i2cmux");
|
|
@ -106,9 +106,9 @@ struct ds1307 {
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
struct rtc_device *rtc;
|
struct rtc_device *rtc;
|
||||||
struct work_struct work;
|
struct work_struct work;
|
||||||
s32 (*read_block_data)(struct i2c_client *client, u8 command,
|
s32 (*read_block_data)(const struct i2c_client *client, u8 command,
|
||||||
u8 length, u8 *values);
|
u8 length, u8 *values);
|
||||||
s32 (*write_block_data)(struct i2c_client *client, u8 command,
|
s32 (*write_block_data)(const struct i2c_client *client, u8 command,
|
||||||
u8 length, const u8 *values);
|
u8 length, const u8 *values);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -158,8 +158,8 @@ MODULE_DEVICE_TABLE(i2c, ds1307_id);
|
||||||
|
|
||||||
#define BLOCK_DATA_MAX_TRIES 10
|
#define BLOCK_DATA_MAX_TRIES 10
|
||||||
|
|
||||||
static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command,
|
static s32 ds1307_read_block_data_once(const struct i2c_client *client,
|
||||||
u8 length, u8 *values)
|
u8 command, u8 length, u8 *values)
|
||||||
{
|
{
|
||||||
s32 i, data;
|
s32 i, data;
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command,
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static s32 ds1307_read_block_data(struct i2c_client *client, u8 command,
|
static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
|
||||||
u8 length, u8 *values)
|
u8 length, u8 *values)
|
||||||
{
|
{
|
||||||
u8 oldvalues[I2C_SMBUS_BLOCK_MAX];
|
u8 oldvalues[I2C_SMBUS_BLOCK_MAX];
|
||||||
|
@ -198,7 +198,7 @@ static s32 ds1307_read_block_data(struct i2c_client *client, u8 command,
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static s32 ds1307_write_block_data(struct i2c_client *client, u8 command,
|
static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
|
||||||
u8 length, const u8 *values)
|
u8 length, const u8 *values)
|
||||||
{
|
{
|
||||||
u8 currvalues[I2C_SMBUS_BLOCK_MAX];
|
u8 currvalues[I2C_SMBUS_BLOCK_MAX];
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* gpio-i2cmux interface to platform code
|
||||||
|
*
|
||||||
|
* Peter Korsgaard <peter.korsgaard@barco.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LINUX_GPIO_I2CMUX_H
|
||||||
|
#define _LINUX_GPIO_I2CMUX_H
|
||||||
|
|
||||||
|
/* MUX has no specific idle mode */
|
||||||
|
#define GPIO_I2CMUX_NO_IDLE ((unsigned)-1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* struct gpio_i2cmux_platform_data - Platform-dependent data for gpio-i2cmux
|
||||||
|
* @parent: Parent I2C bus adapter number
|
||||||
|
* @base_nr: Base I2C bus number to number adapters from or zero for dynamic
|
||||||
|
* @values: Array of bitmasks of GPIO settings (low/high) for each
|
||||||
|
* position
|
||||||
|
* @n_values: Number of multiplexer positions (busses to instantiate)
|
||||||
|
* @gpios: Array of GPIO numbers used to control MUX
|
||||||
|
* @n_gpios: Number of GPIOs used to control MUX
|
||||||
|
* @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used
|
||||||
|
*/
|
||||||
|
struct gpio_i2cmux_platform_data {
|
||||||
|
int parent;
|
||||||
|
int base_nr;
|
||||||
|
const unsigned *values;
|
||||||
|
int n_values;
|
||||||
|
const unsigned *gpios;
|
||||||
|
int n_gpios;
|
||||||
|
unsigned idle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _LINUX_GPIO_I2CMUX_H */
|
|
@ -57,9 +57,10 @@ struct i2c_board_info;
|
||||||
* transmit an arbitrary number of messages without interruption.
|
* transmit an arbitrary number of messages without interruption.
|
||||||
* @count must be be less than 64k since msg.len is u16.
|
* @count must be be less than 64k since msg.len is u16.
|
||||||
*/
|
*/
|
||||||
extern int i2c_master_send(struct i2c_client *client, const char *buf,
|
extern int i2c_master_send(const struct i2c_client *client, const char *buf,
|
||||||
|
int count);
|
||||||
|
extern int i2c_master_recv(const struct i2c_client *client, char *buf,
|
||||||
int count);
|
int count);
|
||||||
extern int i2c_master_recv(struct i2c_client *client, char *buf, int count);
|
|
||||||
|
|
||||||
/* Transfer num messages.
|
/* Transfer num messages.
|
||||||
*/
|
*/
|
||||||
|
@ -78,23 +79,25 @@ extern s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
|
||||||
/* Now follow the 'nice' access routines. These also document the calling
|
/* Now follow the 'nice' access routines. These also document the calling
|
||||||
conventions of i2c_smbus_xfer. */
|
conventions of i2c_smbus_xfer. */
|
||||||
|
|
||||||
extern s32 i2c_smbus_read_byte(struct i2c_client *client);
|
extern s32 i2c_smbus_read_byte(const struct i2c_client *client);
|
||||||
extern s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value);
|
extern s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value);
|
||||||
extern s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command);
|
extern s32 i2c_smbus_read_byte_data(const struct i2c_client *client,
|
||||||
extern s32 i2c_smbus_write_byte_data(struct i2c_client *client,
|
u8 command);
|
||||||
|
extern s32 i2c_smbus_write_byte_data(const struct i2c_client *client,
|
||||||
u8 command, u8 value);
|
u8 command, u8 value);
|
||||||
extern s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command);
|
extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
|
||||||
extern s32 i2c_smbus_write_word_data(struct i2c_client *client,
|
u8 command);
|
||||||
|
extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
|
||||||
u8 command, u16 value);
|
u8 command, u16 value);
|
||||||
/* Returns the number of read bytes */
|
/* Returns the number of read bytes */
|
||||||
extern s32 i2c_smbus_read_block_data(struct i2c_client *client,
|
extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
|
||||||
u8 command, u8 *values);
|
u8 command, u8 *values);
|
||||||
extern s32 i2c_smbus_write_block_data(struct i2c_client *client,
|
extern s32 i2c_smbus_write_block_data(const struct i2c_client *client,
|
||||||
u8 command, u8 length, const u8 *values);
|
u8 command, u8 length, const u8 *values);
|
||||||
/* Returns the number of read bytes */
|
/* Returns the number of read bytes */
|
||||||
extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client,
|
extern s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
|
||||||
u8 command, u8 length, u8 *values);
|
u8 command, u8 length, u8 *values);
|
||||||
extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
|
extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client,
|
||||||
u8 command, u8 length,
|
u8 command, u8 length,
|
||||||
const u8 *values);
|
const u8 *values);
|
||||||
#endif /* I2C */
|
#endif /* I2C */
|
||||||
|
|
Loading…
Reference in New Issue