aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-01-10 20:09:13 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-10 20:09:13 -0500
commit8adbf8d46718a8f110de55ec82c40d04d0c362cc (patch)
treedbaf7109edaaa26496e131e6644074fbcb75c75d
parent0be8c8bd1de21d75ef14eb6af35b664f70a35746 (diff)
parent0cc43a1806f078f7fd414850d8f1f1761696e4af (diff)
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>
-rw-r--r--Documentation/i2c/muxes/gpio-i2cmux65
-rw-r--r--MAINTAINERS8
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c31
-rw-r--r--drivers/i2c/busses/i2c-i801.c1
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c2
-rw-r--r--drivers/i2c/i2c-core.c29
-rw-r--r--drivers/i2c/muxes/Kconfig12
-rw-r--r--drivers/i2c/muxes/Makefile1
-rw-r--r--drivers/i2c/muxes/gpio-i2cmux.c184
-rw-r--r--drivers/rtc/rtc-ds1307.c12
-rw-r--r--include/linux/gpio-i2cmux.h38
-rw-r--r--include/linux/i2c.h27
12 files changed, 362 insertions, 48 deletions
diff --git a/Documentation/i2c/muxes/gpio-i2cmux b/Documentation/i2c/muxes/gpio-i2cmux
new file mode 100644
index 000000000000..811cd78d4cdc
--- /dev/null
+++ b/Documentation/i2c/muxes/gpio-i2cmux
@@ -0,0 +1,65 @@
1Kernel driver gpio-i2cmux
2
3Author: Peter Korsgaard <peter.korsgaard@barco.com>
4
5Description
6-----------
7
8gpio-i2cmux is an i2c mux driver providing access to I2C bus segments
9from a master I2C bus and a hardware MUX controlled through GPIO pins.
10
11E.G.:
12
13 ---------- ---------- Bus segment 1 - - - - -
14 | | SCL/SDA | |-------------- | |
15 | |------------| |
16 | | | | Bus segment 2 | |
17 | Linux | GPIO 1..N | MUX |--------------- Devices
18 | |------------| | | |
19 | | | | Bus segment M
20 | | | |---------------| |
21 ---------- ---------- - - - - -
22
23SCL/SDA of the master I2C bus is multiplexed to bus segment 1..M
24according to the settings of the GPIO pins 1..N.
25
26Usage
27-----
28
29gpio-i2cmux uses the platform bus, so you need to provide a struct
30platform_device with the platform_data pointing to a struct
31gpio_i2cmux_platform_data with the I2C adapter number of the master
32bus, the number of bus segments to create and the GPIO pins used
33to control it. See include/linux/gpio-i2cmux.h for details.
34
35E.G. something like this for a MUX providing 4 bus segments
36controlled through 3 GPIO pins:
37
38#include <linux/gpio-i2cmux.h>
39#include <linux/platform_device.h>
40
41static const unsigned myboard_gpiomux_gpios[] = {
42 AT91_PIN_PC26, AT91_PIN_PC25, AT91_PIN_PC24
43};
44
45static const unsigned myboard_gpiomux_values[] = {
46 0, 1, 2, 3
47};
48
49static struct gpio_i2cmux_platform_data myboard_i2cmux_data = {
50 .parent = 1,
51 .base_nr = 2, /* optional */
52 .values = myboard_gpiomux_values,
53 .n_values = ARRAY_SIZE(myboard_gpiomux_values),
54 .gpios = myboard_gpiomux_gpios,
55 .n_gpios = ARRAY_SIZE(myboard_gpiomux_gpios),
56 .idle = 4, /* optional */
57};
58
59static struct platform_device myboard_i2cmux = {
60 .name = "gpio-i2cmux",
61 .id = 0,
62 .dev = {
63 .platform_data = &myboard_i2cmux_data,
64 },
65};
diff --git a/MAINTAINERS b/MAINTAINERS
index ad600c54c7bf..bb6c1ac85138 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2692,6 +2692,14 @@ S: Supported
2692F: drivers/i2c/busses/i2c-gpio.c 2692F: drivers/i2c/busses/i2c-gpio.c
2693F: include/linux/i2c-gpio.h 2693F: include/linux/i2c-gpio.h
2694 2694
2695GENERIC GPIO I2C MULTIPLEXER DRIVER
2696M: Peter Korsgaard <peter.korsgaard@barco.com>
2697L: linux-i2c@vger.kernel.org
2698S: Supported
2699F: drivers/i2c/muxes/gpio-i2cmux.c
2700F: include/linux/gpio-i2cmux.h
2701F: Documentation/i2c/muxes/gpio-i2cmux
2702
2695GENERIC HDLC (WAN) DRIVERS 2703GENERIC HDLC (WAN) DRIVERS
2696M: Krzysztof Halasa <khc@pm.waw.pl> 2704M: Krzysztof Halasa <khc@pm.waw.pl>
2697W: http://www.kernel.org/pub/linux/utils/net/hdlc/ 2705W: http://www.kernel.org/pub/linux/utils/net/hdlc/
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index a39e6cff86e7..38319a69bd0a 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -600,12 +600,14 @@ static const struct i2c_algorithm i2c_bit_algo = {
600/* 600/*
601 * registering functions to load algorithms at runtime 601 * registering functions to load algorithms at runtime
602 */ 602 */
603static int i2c_bit_prepare_bus(struct i2c_adapter *adap) 603static int __i2c_bit_add_bus(struct i2c_adapter *adap,
604 int (*add_adapter)(struct i2c_adapter *))
604{ 605{
605 struct i2c_algo_bit_data *bit_adap = adap->algo_data; 606 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
607 int ret;
606 608
607 if (bit_test) { 609 if (bit_test) {
608 int ret = test_bus(bit_adap, adap->name); 610 ret = test_bus(bit_adap, adap->name);
609 if (ret < 0) 611 if (ret < 0)
610 return -ENODEV; 612 return -ENODEV;
611 } 613 }
@@ -614,30 +616,27 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
614 adap->algo = &i2c_bit_algo; 616 adap->algo = &i2c_bit_algo;
615 adap->retries = 3; 617 adap->retries = 3;
616 618
619 ret = add_adapter(adap);
620 if (ret < 0)
621 return ret;
622
623 /* Complain if SCL can't be read */
624 if (bit_adap->getscl == NULL) {
625 dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n");
626 dev_warn(&adap->dev, "Bus may be unreliable\n");
627 }
617 return 0; 628 return 0;
618} 629}
619 630
620int i2c_bit_add_bus(struct i2c_adapter *adap) 631int i2c_bit_add_bus(struct i2c_adapter *adap)
621{ 632{
622 int err; 633 return __i2c_bit_add_bus(adap, i2c_add_adapter);
623
624 err = i2c_bit_prepare_bus(adap);
625 if (err)
626 return err;
627
628 return i2c_add_adapter(adap);
629} 634}
630EXPORT_SYMBOL(i2c_bit_add_bus); 635EXPORT_SYMBOL(i2c_bit_add_bus);
631 636
632int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) 637int i2c_bit_add_numbered_bus(struct i2c_adapter *adap)
633{ 638{
634 int err; 639 return __i2c_bit_add_bus(adap, i2c_add_numbered_adapter);
635
636 err = i2c_bit_prepare_bus(adap);
637 if (err)
638 return err;
639
640 return i2c_add_numbered_adapter(adap);
641} 640}
642EXPORT_SYMBOL(i2c_bit_add_numbered_bus); 641EXPORT_SYMBOL(i2c_bit_add_numbered_bus);
643 642
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 02835ce7ff4b..7979aef7ee7b 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -72,6 +72,7 @@
72#include <linux/acpi.h> 72#include <linux/acpi.h>
73#include <linux/io.h> 73#include <linux/io.h>
74#include <linux/dmi.h> 74#include <linux/dmi.h>
75#include <linux/slab.h>
75 76
76/* I801 SMBus address offsets */ 77/* I801 SMBus address offsets */
77#define SMBHSTSTS(p) (0 + (p)->smba) 78#define SMBHSTSTS(p) (0 + (p)->smba)
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index a605a5029cfe..ff1e127dfea8 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -432,7 +432,7 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
432 432
433static void __devexit nforce2_remove(struct pci_dev *dev) 433static void __devexit nforce2_remove(struct pci_dev *dev)
434{ 434{
435 struct nforce2_smbus *smbuses = (void*) pci_get_drvdata(dev); 435 struct nforce2_smbus *smbuses = pci_get_drvdata(dev);
436 436
437 nforce2_set_reference(NULL); 437 nforce2_set_reference(NULL);
438 if (smbuses[0].base) { 438 if (smbuses[0].base) {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6b4cc567645b..c7db6980e3a3 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1362,7 +1362,7 @@ EXPORT_SYMBOL(i2c_transfer);
1362 * 1362 *
1363 * Returns negative errno, or else the number of bytes written. 1363 * Returns negative errno, or else the number of bytes written.
1364 */ 1364 */
1365int i2c_master_send(struct i2c_client *client, const char *buf, int count) 1365int i2c_master_send(const struct i2c_client *client, const char *buf, int count)
1366{ 1366{
1367 int ret; 1367 int ret;
1368 struct i2c_adapter *adap = client->adapter; 1368 struct i2c_adapter *adap = client->adapter;
@@ -1389,7 +1389,7 @@ EXPORT_SYMBOL(i2c_master_send);
1389 * 1389 *
1390 * Returns negative errno, or else the number of bytes read. 1390 * Returns negative errno, or else the number of bytes read.
1391 */ 1391 */
1392int i2c_master_recv(struct i2c_client *client, char *buf, int count) 1392int i2c_master_recv(const struct i2c_client *client, char *buf, int count)
1393{ 1393{
1394 struct i2c_adapter *adap = client->adapter; 1394 struct i2c_adapter *adap = client->adapter;
1395 struct i2c_msg msg; 1395 struct i2c_msg msg;
@@ -1679,7 +1679,7 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
1679 * This executes the SMBus "receive byte" protocol, returning negative errno 1679 * This executes the SMBus "receive byte" protocol, returning negative errno
1680 * else the byte received from the device. 1680 * else the byte received from the device.
1681 */ 1681 */
1682s32 i2c_smbus_read_byte(struct i2c_client *client) 1682s32 i2c_smbus_read_byte(const struct i2c_client *client)
1683{ 1683{
1684 union i2c_smbus_data data; 1684 union i2c_smbus_data data;
1685 int status; 1685 int status;
@@ -1699,7 +1699,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte);
1699 * This executes the SMBus "send byte" protocol, returning negative errno 1699 * This executes the SMBus "send byte" protocol, returning negative errno
1700 * else zero on success. 1700 * else zero on success.
1701 */ 1701 */
1702s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1702s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)
1703{ 1703{
1704 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, 1704 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1705 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); 1705 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
@@ -1714,7 +1714,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte);
1714 * This executes the SMBus "read byte" protocol, returning negative errno 1714 * This executes the SMBus "read byte" protocol, returning negative errno
1715 * else a data byte received from the device. 1715 * else a data byte received from the device.
1716 */ 1716 */
1717s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 1717s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
1718{ 1718{
1719 union i2c_smbus_data data; 1719 union i2c_smbus_data data;
1720 int status; 1720 int status;
@@ -1735,7 +1735,8 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1735 * This executes the SMBus "write byte" protocol, returning negative errno 1735 * This executes the SMBus "write byte" protocol, returning negative errno
1736 * else zero on success. 1736 * else zero on success.
1737 */ 1737 */
1738s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 1738s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command,
1739 u8 value)
1739{ 1740{
1740 union i2c_smbus_data data; 1741 union i2c_smbus_data data;
1741 data.byte = value; 1742 data.byte = value;
@@ -1753,7 +1754,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1753 * This executes the SMBus "read word" protocol, returning negative errno 1754 * This executes the SMBus "read word" protocol, returning negative errno
1754 * else a 16-bit unsigned "word" received from the device. 1755 * else a 16-bit unsigned "word" received from the device.
1755 */ 1756 */
1756s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) 1757s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command)
1757{ 1758{
1758 union i2c_smbus_data data; 1759 union i2c_smbus_data data;
1759 int status; 1760 int status;
@@ -1774,7 +1775,8 @@ EXPORT_SYMBOL(i2c_smbus_read_word_data);
1774 * This executes the SMBus "write word" protocol, returning negative errno 1775 * This executes the SMBus "write word" protocol, returning negative errno
1775 * else zero on success. 1776 * else zero on success.
1776 */ 1777 */
1777s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 1778s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command,
1779 u16 value)
1778{ 1780{
1779 union i2c_smbus_data data; 1781 union i2c_smbus_data data;
1780 data.word = value; 1782 data.word = value;
@@ -1793,7 +1795,8 @@ EXPORT_SYMBOL(i2c_smbus_write_word_data);
1793 * This executes the SMBus "process call" protocol, returning negative errno 1795 * This executes the SMBus "process call" protocol, returning negative errno
1794 * else a 16-bit unsigned "word" received from the device. 1796 * else a 16-bit unsigned "word" received from the device.
1795 */ 1797 */
1796s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value) 1798s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command,
1799 u16 value)
1797{ 1800{
1798 union i2c_smbus_data data; 1801 union i2c_smbus_data data;
1799 int status; 1802 int status;
@@ -1821,7 +1824,7 @@ EXPORT_SYMBOL(i2c_smbus_process_call);
1821 * support this; its emulation through I2C messaging relies on a specific 1824 * support this; its emulation through I2C messaging relies on a specific
1822 * mechanism (I2C_M_RECV_LEN) which may not be implemented. 1825 * mechanism (I2C_M_RECV_LEN) which may not be implemented.
1823 */ 1826 */
1824s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, 1827s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command,
1825 u8 *values) 1828 u8 *values)
1826{ 1829{
1827 union i2c_smbus_data data; 1830 union i2c_smbus_data data;
@@ -1848,7 +1851,7 @@ EXPORT_SYMBOL(i2c_smbus_read_block_data);
1848 * This executes the SMBus "block write" protocol, returning negative errno 1851 * This executes the SMBus "block write" protocol, returning negative errno
1849 * else zero on success. 1852 * else zero on success.
1850 */ 1853 */
1851s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 1854s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command,
1852 u8 length, const u8 *values) 1855 u8 length, const u8 *values)
1853{ 1856{
1854 union i2c_smbus_data data; 1857 union i2c_smbus_data data;
@@ -1864,7 +1867,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1864EXPORT_SYMBOL(i2c_smbus_write_block_data); 1867EXPORT_SYMBOL(i2c_smbus_write_block_data);
1865 1868
1866/* Returns the number of read bytes */ 1869/* Returns the number of read bytes */
1867s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, 1870s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command,
1868 u8 length, u8 *values) 1871 u8 length, u8 *values)
1869{ 1872{
1870 union i2c_smbus_data data; 1873 union i2c_smbus_data data;
@@ -1884,7 +1887,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command,
1884} 1887}
1885EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); 1888EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1886 1889
1887s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, 1890s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command,
1888 u8 length, const u8 *values) 1891 u8 length, const u8 *values)
1889{ 1892{
1890 union i2c_smbus_data data; 1893 union i2c_smbus_data data;
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
index 4d91d80bfd23..90b7a0163899 100644
--- a/drivers/i2c/muxes/Kconfig
+++ b/drivers/i2c/muxes/Kconfig
@@ -5,6 +5,18 @@
5menu "Multiplexer I2C Chip support" 5menu "Multiplexer I2C Chip support"
6 depends on I2C_MUX 6 depends on I2C_MUX
7 7
8config I2C_MUX_GPIO
9 tristate "GPIO-based I2C multiplexer"
10 depends on GENERIC_GPIO
11 help
12 If you say yes to this option, support will be included for a
13 GPIO based I2C multiplexer. This driver provides access to
14 I2C busses connected through a MUX, which is controlled
15 through GPIO pins.
16
17 This driver can also be built as a module. If so, the module
18 will be called gpio-i2cmux.
19
8config I2C_MUX_PCA9541 20config I2C_MUX_PCA9541
9 tristate "NXP PCA9541 I2C Master Selector" 21 tristate "NXP PCA9541 I2C Master Selector"
10 depends on EXPERIMENTAL 22 depends on EXPERIMENTAL
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
index d743806d9b42..4640436ea61f 100644
--- a/drivers/i2c/muxes/Makefile
+++ b/drivers/i2c/muxes/Makefile
@@ -1,6 +1,7 @@
1# 1#
2# Makefile for multiplexer I2C chip drivers. 2# Makefile for multiplexer I2C chip drivers.
3 3
4obj-$(CONFIG_I2C_MUX_GPIO) += gpio-i2cmux.o
4obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o 5obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o
5obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o 6obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o
6 7
diff --git a/drivers/i2c/muxes/gpio-i2cmux.c b/drivers/i2c/muxes/gpio-i2cmux.c
new file mode 100644
index 000000000000..7b6ce624cd6e
--- /dev/null
+++ b/drivers/i2c/muxes/gpio-i2cmux.c
@@ -0,0 +1,184 @@
1/*
2 * I2C multiplexer using GPIO API
3 *
4 * Peter Korsgaard <peter.korsgaard@barco.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/i2c.h>
12#include <linux/i2c-mux.h>
13#include <linux/gpio-i2cmux.h>
14#include <linux/platform_device.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/slab.h>
18#include <linux/gpio.h>
19
20struct gpiomux {
21 struct i2c_adapter *parent;
22 struct i2c_adapter **adap; /* child busses */
23 struct gpio_i2cmux_platform_data data;
24};
25
26static void gpiomux_set(const struct gpiomux *mux, unsigned val)
27{
28 int i;
29
30 for (i = 0; i < mux->data.n_gpios; i++)
31 gpio_set_value(mux->data.gpios[i], val & (1 << i));
32}
33
34static int gpiomux_select(struct i2c_adapter *adap, void *data, u32 chan)
35{
36 struct gpiomux *mux = data;
37
38 gpiomux_set(mux, mux->data.values[chan]);
39
40 return 0;
41}
42
43static int gpiomux_deselect(struct i2c_adapter *adap, void *data, u32 chan)
44{
45 struct gpiomux *mux = data;
46
47 gpiomux_set(mux, mux->data.idle);
48
49 return 0;
50}
51
52static int __devinit gpiomux_probe(struct platform_device *pdev)
53{
54 struct gpiomux *mux;
55 struct gpio_i2cmux_platform_data *pdata;
56 struct i2c_adapter *parent;
57 int (*deselect) (struct i2c_adapter *, void *, u32);
58 unsigned initial_state;
59 int i, ret;
60
61 pdata = pdev->dev.platform_data;
62 if (!pdata) {
63 dev_err(&pdev->dev, "Missing platform data\n");
64 return -ENODEV;
65 }
66
67 parent = i2c_get_adapter(pdata->parent);
68 if (!parent) {
69 dev_err(&pdev->dev, "Parent adapter (%d) not found\n",
70 pdata->parent);
71 return -ENODEV;
72 }
73
74 mux = kzalloc(sizeof(*mux), GFP_KERNEL);
75 if (!mux) {
76 ret = -ENOMEM;
77 goto alloc_failed;
78 }
79
80 mux->parent = parent;
81 mux->data = *pdata;
82 mux->adap = kzalloc(sizeof(struct i2c_adapter *) * pdata->n_values,
83 GFP_KERNEL);
84 if (!mux->adap) {
85 ret = -ENOMEM;
86 goto alloc_failed2;
87 }
88
89 if (pdata->idle != GPIO_I2CMUX_NO_IDLE) {
90 initial_state = pdata->idle;
91 deselect = gpiomux_deselect;
92 } else {
93 initial_state = pdata->values[0];
94 deselect = NULL;
95 }
96
97 for (i = 0; i < pdata->n_gpios; i++) {
98 ret = gpio_request(pdata->gpios[i], "gpio-i2cmux");
99 if (ret)
100 goto err_request_gpio;
101 gpio_direction_output(pdata->gpios[i],
102 initial_state & (1 << i));
103 }
104
105 for (i = 0; i < pdata->n_values; i++) {
106 u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0;
107
108 mux->adap[i] = i2c_add_mux_adapter(parent, mux, nr, i,
109 gpiomux_select, deselect);
110 if (!mux->adap[i]) {
111 ret = -ENODEV;
112 dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
113 goto add_adapter_failed;
114 }
115 }
116
117 dev_info(&pdev->dev, "%d port mux on %s adapter\n",
118 pdata->n_values, parent->name);
119
120 platform_set_drvdata(pdev, mux);
121
122 return 0;
123
124add_adapter_failed:
125 for (; i > 0; i--)
126 i2c_del_mux_adapter(mux->adap[i - 1]);
127 i = pdata->n_gpios;
128err_request_gpio:
129 for (; i > 0; i--)
130 gpio_free(pdata->gpios[i - 1]);
131 kfree(mux->adap);
132alloc_failed2:
133 kfree(mux);
134alloc_failed:
135 i2c_put_adapter(parent);
136
137 return ret;
138}
139
140static int __devexit gpiomux_remove(struct platform_device *pdev)
141{
142 struct gpiomux *mux = platform_get_drvdata(pdev);
143 int i;
144
145 for (i = 0; i < mux->data.n_values; i++)
146 i2c_del_mux_adapter(mux->adap[i]);
147
148 for (i = 0; i < mux->data.n_gpios; i++)
149 gpio_free(mux->data.gpios[i]);
150
151 platform_set_drvdata(pdev, NULL);
152 i2c_put_adapter(mux->parent);
153 kfree(mux->adap);
154 kfree(mux);
155
156 return 0;
157}
158
159static struct platform_driver gpiomux_driver = {
160 .probe = gpiomux_probe,
161 .remove = __devexit_p(gpiomux_remove),
162 .driver = {
163 .owner = THIS_MODULE,
164 .name = "gpio-i2cmux",
165 },
166};
167
168static int __init gpiomux_init(void)
169{
170 return platform_driver_register(&gpiomux_driver);
171}
172
173static void __exit gpiomux_exit(void)
174{
175 platform_driver_unregister(&gpiomux_driver);
176}
177
178module_init(gpiomux_init);
179module_exit(gpiomux_exit);
180
181MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver");
182MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>");
183MODULE_LICENSE("GPL");
184MODULE_ALIAS("platform:gpio-i2cmux");
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index d827ce570a8c..0d559b6416dd 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -106,9 +106,9 @@ struct ds1307 {
106 struct i2c_client *client; 106 struct i2c_client *client;
107 struct rtc_device *rtc; 107 struct rtc_device *rtc;
108 struct work_struct work; 108 struct work_struct work;
109 s32 (*read_block_data)(struct i2c_client *client, u8 command, 109 s32 (*read_block_data)(const struct i2c_client *client, u8 command,
110 u8 length, u8 *values); 110 u8 length, u8 *values);
111 s32 (*write_block_data)(struct i2c_client *client, u8 command, 111 s32 (*write_block_data)(const struct i2c_client *client, u8 command,
112 u8 length, const u8 *values); 112 u8 length, const u8 *values);
113}; 113};
114 114
@@ -158,8 +158,8 @@ MODULE_DEVICE_TABLE(i2c, ds1307_id);
158 158
159#define BLOCK_DATA_MAX_TRIES 10 159#define BLOCK_DATA_MAX_TRIES 10
160 160
161static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command, 161static s32 ds1307_read_block_data_once(const struct i2c_client *client,
162 u8 length, u8 *values) 162 u8 command, u8 length, u8 *values)
163{ 163{
164 s32 i, data; 164 s32 i, data;
165 165
@@ -172,7 +172,7 @@ static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command,
172 return i; 172 return i;
173} 173}
174 174
175static s32 ds1307_read_block_data(struct i2c_client *client, u8 command, 175static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
176 u8 length, u8 *values) 176 u8 length, u8 *values)
177{ 177{
178 u8 oldvalues[I2C_SMBUS_BLOCK_MAX]; 178 u8 oldvalues[I2C_SMBUS_BLOCK_MAX];
@@ -198,7 +198,7 @@ static s32 ds1307_read_block_data(struct i2c_client *client, u8 command,
198 return length; 198 return length;
199} 199}
200 200
201static s32 ds1307_write_block_data(struct i2c_client *client, u8 command, 201static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
202 u8 length, const u8 *values) 202 u8 length, const u8 *values)
203{ 203{
204 u8 currvalues[I2C_SMBUS_BLOCK_MAX]; 204 u8 currvalues[I2C_SMBUS_BLOCK_MAX];
diff --git a/include/linux/gpio-i2cmux.h b/include/linux/gpio-i2cmux.h
new file mode 100644
index 000000000000..4a333bb0bd0d
--- /dev/null
+++ b/include/linux/gpio-i2cmux.h
@@ -0,0 +1,38 @@
1/*
2 * gpio-i2cmux interface to platform code
3 *
4 * Peter Korsgaard <peter.korsgaard@barco.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef _LINUX_GPIO_I2CMUX_H
12#define _LINUX_GPIO_I2CMUX_H
13
14/* MUX has no specific idle mode */
15#define GPIO_I2CMUX_NO_IDLE ((unsigned)-1)
16
17/**
18 * struct gpio_i2cmux_platform_data - Platform-dependent data for gpio-i2cmux
19 * @parent: Parent I2C bus adapter number
20 * @base_nr: Base I2C bus number to number adapters from or zero for dynamic
21 * @values: Array of bitmasks of GPIO settings (low/high) for each
22 * position
23 * @n_values: Number of multiplexer positions (busses to instantiate)
24 * @gpios: Array of GPIO numbers used to control MUX
25 * @n_gpios: Number of GPIOs used to control MUX
26 * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used
27 */
28struct gpio_i2cmux_platform_data {
29 int parent;
30 int base_nr;
31 const unsigned *values;
32 int n_values;
33 const unsigned *gpios;
34 int n_gpios;
35 unsigned idle;
36};
37
38#endif /* _LINUX_GPIO_I2CMUX_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 56cfe23ffb39..903576df88dc 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -57,9 +57,10 @@ struct i2c_board_info;
57 * transmit an arbitrary number of messages without interruption. 57 * transmit an arbitrary number of messages without interruption.
58 * @count must be be less than 64k since msg.len is u16. 58 * @count must be be less than 64k since msg.len is u16.
59 */ 59 */
60extern int i2c_master_send(struct i2c_client *client, const char *buf, 60extern int i2c_master_send(const struct i2c_client *client, const char *buf,
61 int count);
62extern int i2c_master_recv(const struct i2c_client *client, char *buf,
61 int count); 63 int count);
62extern int i2c_master_recv(struct i2c_client *client, char *buf, int count);
63 64
64/* Transfer num messages. 65/* Transfer num messages.
65 */ 66 */
@@ -78,23 +79,25 @@ extern s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
78/* Now follow the 'nice' access routines. These also document the calling 79/* Now follow the 'nice' access routines. These also document the calling
79 conventions of i2c_smbus_xfer. */ 80 conventions of i2c_smbus_xfer. */
80 81
81extern s32 i2c_smbus_read_byte(struct i2c_client *client); 82extern s32 i2c_smbus_read_byte(const struct i2c_client *client);
82extern s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value); 83extern s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value);
83extern s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command); 84extern s32 i2c_smbus_read_byte_data(const struct i2c_client *client,
84extern s32 i2c_smbus_write_byte_data(struct i2c_client *client, 85 u8 command);
86extern s32 i2c_smbus_write_byte_data(const struct i2c_client *client,
85 u8 command, u8 value); 87 u8 command, u8 value);
86extern s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command); 88extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
87extern s32 i2c_smbus_write_word_data(struct i2c_client *client, 89 u8 command);
90extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
88 u8 command, u16 value); 91 u8 command, u16 value);
89/* Returns the number of read bytes */ 92/* Returns the number of read bytes */
90extern s32 i2c_smbus_read_block_data(struct i2c_client *client, 93extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
91 u8 command, u8 *values); 94 u8 command, u8 *values);
92extern s32 i2c_smbus_write_block_data(struct i2c_client *client, 95extern s32 i2c_smbus_write_block_data(const struct i2c_client *client,
93 u8 command, u8 length, const u8 *values); 96 u8 command, u8 length, const u8 *values);
94/* Returns the number of read bytes */ 97/* Returns the number of read bytes */
95extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, 98extern s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
96 u8 command, u8 length, u8 *values); 99 u8 command, u8 length, u8 *values);
97extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, 100extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client,
98 u8 command, u8 length, 101 u8 command, u8 length,
99 const u8 *values); 102 const u8 *values);
100#endif /* I2C */ 103#endif /* I2C */