aboutsummaryrefslogtreecommitdiff
path: root/Documentation/i2c/muxes/i2c-mux-gpio
blob: bd9b2299b73992036f39bdbaf4af2667eba0e575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Kernel driver i2c-gpio-mux

Author: Peter Korsgaard <peter.korsgaard@barco.com>

Description
-----------

i2c-gpio-mux 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
-----

i2c-gpio-mux 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/i2c-gpio-mux.h for details.

E.G. something like this for a MUX providing 4 bus segments
controlled through 3 GPIO pins:

#include <linux/i2c-gpio-mux.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		= "i2c-gpio-mux",
	.id		= 0,
	.dev		= {
		.platform_data	= &myboard_i2cmux_data,
	},
};