Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *
0004  * i2c-mux.h - functions for the i2c-bus mux support
0005  *
0006  * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
0007  * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
0008  * Michael Lawnick <michael.lawnick.ext@nsn.com>
0009  */
0010 
0011 #ifndef _LINUX_I2C_MUX_H
0012 #define _LINUX_I2C_MUX_H
0013 
0014 #ifdef __KERNEL__
0015 
0016 #include <linux/bitops.h>
0017 
0018 struct i2c_mux_core {
0019     struct i2c_adapter *parent;
0020     struct device *dev;
0021     unsigned int mux_locked:1;
0022     unsigned int arbitrator:1;
0023     unsigned int gate:1;
0024 
0025     void *priv;
0026 
0027     int (*select)(struct i2c_mux_core *, u32 chan_id);
0028     int (*deselect)(struct i2c_mux_core *, u32 chan_id);
0029 
0030     int num_adapters;
0031     int max_adapters;
0032     struct i2c_adapter *adapter[];
0033 };
0034 
0035 struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
0036                    struct device *dev, int max_adapters,
0037                    int sizeof_priv, u32 flags,
0038                    int (*select)(struct i2c_mux_core *, u32),
0039                    int (*deselect)(struct i2c_mux_core *, u32));
0040 
0041 /* flags for i2c_mux_alloc */
0042 #define I2C_MUX_LOCKED     BIT(0)
0043 #define I2C_MUX_ARBITRATOR BIT(1)
0044 #define I2C_MUX_GATE       BIT(2)
0045 
0046 static inline void *i2c_mux_priv(struct i2c_mux_core *muxc)
0047 {
0048     return muxc->priv;
0049 }
0050 
0051 struct i2c_adapter *i2c_root_adapter(struct device *dev);
0052 
0053 /*
0054  * Called to create an i2c bus on a multiplexed bus segment.
0055  * The chan_id parameter is passed to the select and deselect
0056  * callback functions to perform hardware-specific mux control.
0057  */
0058 int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
0059             u32 force_nr, u32 chan_id,
0060             unsigned int class);
0061 
0062 void i2c_mux_del_adapters(struct i2c_mux_core *muxc);
0063 
0064 #endif /* __KERNEL__ */
0065 
0066 #endif /* _LINUX_I2C_MUX_H */