add multiplexed I2C bus support
cover add multiplexed I2C bus support
This patchseries adds multiplexed I2C bus support to barebox and a driver for pca954x bus multiplexer.
This series has the "RFC" status mostly because of these adapter numbering hack in drivers/i2c/i2c-mux.c:
/* FIXME */
// priv->adap.nr = mux_dev->id;
priv->adap.nr = -1;
ret = i2c_add_numbered_adapter(&priv->adap);Antony Pavlov (2):
i2c: import multiplexed I2C bus core support from linux kernel
i2c: add pca954x bus multiplexer driver
drivers/i2c/Kconfig | 9 ++ drivers/i2c/Makefile | 3 +- drivers/i2c/i2c-mux.c | 118 ++++++++++++++++++++ drivers/i2c/muxes/Kconfig | 15 +++ drivers/i2c/muxes/Makefile | 4 + drivers/i2c/muxes/pca954x.c | 254 ++++++++++++++++++++++++++++++++++++++++++++ include/i2c/i2c-mux.h | 40 +++++++ include/i2c/i2c.h | 19 +++- 8 files changed, 460 insertions(+), 2 deletions(-) create mode 100644 drivers/i2c/i2c-mux.c create mode 100644 drivers/i2c/muxes/Kconfig create mode 100644 drivers/i2c/muxes/Makefile create mode 100644 drivers/i2c/muxes/pca954x.c create mode 100644 include/i2c/i2c-mux.h
Signature · 7 lines
2.6.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 1/2 i2c: import multiplexed I2C bus core support from linux kernel
--- drivers/i2c/Kconfig | 7 +++ drivers/i2c/Makefile | 1 + drivers/i2c/i2c-mux.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/i2c/i2c-mux.h | 40 +++++++++++++++++ include/i2c/i2c.h | 6 ++- 5 files changed, 171 insertions(+), 1 deletion(-)
drivers/i2c/Kconfig +7 -0
@@ -6,4 +6,11 @@ if I2C source drivers/i2c/algos/Kconfig source drivers/i2c/busses/Kconfig +config I2C_MUX + tristate "I2C bus multiplexing support" + help + Say Y here if you want the I2C core to support the ability to + handle multiplexed I2C bus topologies, by presenting each + multiplexed segment as a I2C adapter. + endif
drivers/i2c/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_I2C) += i2c.o i2c-smbus.o busses/ algos/ +obj-$(CONFIG_I2C_MUX) += i2c-mux.o
drivers/i2c/i2c-mux.c new file +118 -0
118 lines not on this page · raw message
include/i2c/i2c-mux.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* +* i2c-mux.h - functions for the i2c-bus mux support +* +* Copyright (c) 2008-2009 Rodolfo Giometti <[email protected]> +* Copyright (c) 2008-2009 Eurotech S.p.A. <[email protected]> +* Michael Lawnick <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_I2C_MUX_H +#define _LINUX_I2C_MUX_H + +/* +* Called to create a i2c bus on a multiplexed bus segment. +* The mux_dev and chan_id parameters are passed to the select +* and deselect callback functions to perform hardware-specific +* mux control. +*/ +struct i2c_adapter *i2c_add_mux_adapter (struct i2c_adapter *parent, +struct device_d *mux_dev, +void *mux_priv,u32 force_nr,u32 chan_id, +int (*select) (struct i2c_adapter *, +void *mux_dev,u32 chan_id), +int (*deselect) (struct i2c_adapter *, +void *mux_dev,u32 chan_id)); + +void i2c_del_mux_adapter (struct i2c_adapter *adap); + +#endif /* _LINUX_I2C_MUX_H */
include/i2c/i2c.h +5 -1
@@ -245,7 +245,11 @@ extern struct list_head i2c_adapter_list;extern struct i2c_client *i2c_new_dummy (struct i2c_adapter *adap,u16 address); - +/* Return the adapter number for a specific adapter */ +static inline int i2c_adapter_id (struct i2c_adapter *adap) +{ +return adap->nr; +}extern int i2c_transfer (struct i2c_adapter *adap,struct i2c_msg *msgs,int num);extern int i2c_master_send (struct i2c_client *client,const char *buf,int count);
Signature · 7 lines
2.6.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 2/2 i2c: add pca954x bus multiplexer driver
In reply to Antony Pavlov--- drivers/i2c/Kconfig | 2 + drivers/i2c/Makefile | 2 +- drivers/i2c/muxes/Kconfig | 15 +++ drivers/i2c/muxes/Makefile | 4 + drivers/i2c/muxes/pca954x.c | 254 ++++++++++++++++++++++++++++++++++++++++++++ include/i2c/i2c.h | 13 +++ 6 files changed, 289 insertions(+), 1 deletion(-)
drivers/i2c/Kconfig +2 -0
@@ -13,4 +13,6 @@ config I2C_MUX handle multiplexed I2C bus topologies, by presenting each multiplexed segment as a I2C adapter. +source drivers/i2c/muxes/Kconfig + endif
drivers/i2c/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-$(CONFIG_I2C) += i2c.o i2c-smbus.o busses/ algos/ +obj-$(CONFIG_I2C) += i2c.o i2c-smbus.o busses/ algos/ muxes/ obj-$(CONFIG_I2C_MUX) += i2c-mux.o
drivers/i2c/muxes/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# +# Multiplexer I2C chip drivers configuration +# + +menu "Multiplexer I2C Chip support" + depends on I2C_MUX + +config I2C_MUX_PCA954x + tristate "Philips PCA954x I2C Mux/switches" + select I2C_ALGOBIT + help + If you say yes here you get support for the Philips PCA954x + I2C mux/switch devices. + +endmenu
drivers/i2c/muxes/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# +# Makefile for multiplexer I2C chip drivers. + +obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o
drivers/i2c/muxes/pca954x.c new file +254 -0
254 lines not on this page · raw message
include/i2c/i2c.h +13 -0
@@ -121,15 +121,28 @@ struct i2c_adapter {struct i2c_bus_recovery_info *bus_recovery_info; }; +#define to_i2c_adapter (d) container_of(d, struct i2c_adapter, dev)struct i2c_client {struct device_d dev;struct i2c_adapter *adapter;unsigned short addr; +void *driver_data;/* Driver data, set and get with +dev_set/get_drvdata */ };#define to_i2c_client (a) container_of(a, struct i2c_client, dev) +static inline void *i2c_get_clientdata (const struct i2c_client *dev) +{ +return dev->driver_data; +} + +static inline void i2c_set_clientdata (struct i2c_client *dev,void *data) +{ + dev->driver_data = data; +} +/*flags for the client struct: */ #define I2C_CLIENT_PEC 0x04/* Use Packet Error Checking */ #define I2C_CLIENT_SCCB 0x9000/* Use Omnivision SCCB protocol */
Signature · 7 lines
2.6.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 10 lines · Antony Pavlov
This patchseries adds multiplexed I2C bus support to barebox and a driver for pca954x bus multiplexer.
This series has the "RFC" status mostly because of these adapter numbering hack in
drivers/i2c/i2c-mux.c:/* FIXME */ // priv->adap.nr = mux_dev->id; priv->adap.nr = -1; ret = i2c_add_numbered_adapter(&priv->adap);
What's wrong with -1 as adapter nr? Why do consider this a hack?
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox