Loading...
1/*
2 * I2C multiplexer driver for PCA9541 bus master selector
3 *
4 * Copyright (c) 2010 Ericsson AB.
5 *
6 * Author: Guenter Roeck <linux@roeck-us.net>
7 *
8 * Derived from:
9 * pca954x.c
10 *
11 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
12 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
13 *
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 */
18
19#include <linux/bitops.h>
20#include <linux/delay.h>
21#include <linux/device.h>
22#include <linux/i2c.h>
23#include <linux/i2c-mux.h>
24#include <linux/jiffies.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27
28/*
29 * The PCA9541 is a bus master selector. It supports two I2C masters connected
30 * to a single slave bus.
31 *
32 * Before each bus transaction, a master has to acquire bus ownership. After the
33 * transaction is complete, bus ownership has to be released. This fits well
34 * into the I2C multiplexer framework, which provides select and release
35 * functions for this purpose. For this reason, this driver is modeled as
36 * single-channel I2C bus multiplexer.
37 *
38 * This driver assumes that the two bus masters are controlled by two different
39 * hosts. If a single host controls both masters, platform code has to ensure
40 * that only one of the masters is instantiated at any given time.
41 */
42
43#define PCA9541_CONTROL 0x01
44#define PCA9541_ISTAT 0x02
45
46#define PCA9541_CTL_MYBUS BIT(0)
47#define PCA9541_CTL_NMYBUS BIT(1)
48#define PCA9541_CTL_BUSON BIT(2)
49#define PCA9541_CTL_NBUSON BIT(3)
50#define PCA9541_CTL_BUSINIT BIT(4)
51#define PCA9541_CTL_TESTON BIT(6)
52#define PCA9541_CTL_NTESTON BIT(7)
53
54#define PCA9541_ISTAT_INTIN BIT(0)
55#define PCA9541_ISTAT_BUSINIT BIT(1)
56#define PCA9541_ISTAT_BUSOK BIT(2)
57#define PCA9541_ISTAT_BUSLOST BIT(3)
58#define PCA9541_ISTAT_MYTEST BIT(6)
59#define PCA9541_ISTAT_NMYTEST BIT(7)
60
61#define BUSON (PCA9541_CTL_BUSON | PCA9541_CTL_NBUSON)
62#define MYBUS (PCA9541_CTL_MYBUS | PCA9541_CTL_NMYBUS)
63#define mybus(x) (!((x) & MYBUS) || ((x) & MYBUS) == MYBUS)
64#define busoff(x) (!((x) & BUSON) || ((x) & BUSON) == BUSON)
65
66/* arbitration timeouts, in jiffies */
67#define ARB_TIMEOUT (HZ / 8) /* 125 ms until forcing bus ownership */
68#define ARB2_TIMEOUT (HZ / 4) /* 250 ms until acquisition failure */
69
70/* arbitration retry delays, in us */
71#define SELECT_DELAY_SHORT 50
72#define SELECT_DELAY_LONG 1000
73
74struct pca9541 {
75 struct i2c_client *client;
76 unsigned long select_timeout;
77 unsigned long arb_timeout;
78};
79
80static const struct i2c_device_id pca9541_id[] = {
81 {"pca9541", 0},
82 {}
83};
84
85MODULE_DEVICE_TABLE(i2c, pca9541_id);
86
87#ifdef CONFIG_OF
88static const struct of_device_id pca9541_of_match[] = {
89 { .compatible = "nxp,pca9541" },
90 {}
91};
92MODULE_DEVICE_TABLE(of, pca9541_of_match);
93#endif
94
95/*
96 * Write to chip register. Don't use i2c_transfer()/i2c_smbus_xfer()
97 * as they will try to lock the adapter a second time.
98 */
99static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val)
100{
101 struct i2c_adapter *adap = client->adapter;
102 union i2c_smbus_data data = { .byte = val };
103
104 return __i2c_smbus_xfer(adap, client->addr, client->flags,
105 I2C_SMBUS_WRITE, command,
106 I2C_SMBUS_BYTE_DATA, &data);
107}
108
109/*
110 * Read from chip register. Don't use i2c_transfer()/i2c_smbus_xfer()
111 * as they will try to lock adapter a second time.
112 */
113static int pca9541_reg_read(struct i2c_client *client, u8 command)
114{
115 struct i2c_adapter *adap = client->adapter;
116 union i2c_smbus_data data;
117 int ret;
118
119 ret = __i2c_smbus_xfer(adap, client->addr, client->flags,
120 I2C_SMBUS_READ, command,
121 I2C_SMBUS_BYTE_DATA, &data);
122
123 return ret ?: data.byte;
124}
125
126/*
127 * Arbitration management functions
128 */
129
130/* Release bus. Also reset NTESTON and BUSINIT if it was set. */
131static void pca9541_release_bus(struct i2c_client *client)
132{
133 int reg;
134
135 reg = pca9541_reg_read(client, PCA9541_CONTROL);
136 if (reg >= 0 && !busoff(reg) && mybus(reg))
137 pca9541_reg_write(client, PCA9541_CONTROL,
138 (reg & PCA9541_CTL_NBUSON) >> 1);
139}
140
141/*
142 * Arbitration is defined as a two-step process. A bus master can only activate
143 * the slave bus if it owns it; otherwise it has to request ownership first.
144 * This multi-step process ensures that access contention is resolved
145 * gracefully.
146 *
147 * Bus Ownership Other master Action
148 * state requested access
149 * ----------------------------------------------------
150 * off - yes wait for arbitration timeout or
151 * for other master to drop request
152 * off no no take ownership
153 * off yes no turn on bus
154 * on yes - done
155 * on no - wait for arbitration timeout or
156 * for other master to release bus
157 *
158 * The main contention point occurs if the slave bus is off and both masters
159 * request ownership at the same time. In this case, one master will turn on
160 * the slave bus, believing that it owns it. The other master will request
161 * bus ownership. Result is that the bus is turned on, and master which did
162 * _not_ own the slave bus before ends up owning it.
163 */
164
165/* Control commands per PCA9541 datasheet */
166static const u8 pca9541_control[16] = {
167 4, 0, 1, 5, 4, 4, 5, 5, 0, 0, 1, 1, 0, 4, 5, 1
168};
169
170/*
171 * Channel arbitration
172 *
173 * Return values:
174 * <0: error
175 * 0 : bus not acquired
176 * 1 : bus acquired
177 */
178static int pca9541_arbitrate(struct i2c_client *client)
179{
180 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
181 struct pca9541 *data = i2c_mux_priv(muxc);
182 int reg;
183
184 reg = pca9541_reg_read(client, PCA9541_CONTROL);
185 if (reg < 0)
186 return reg;
187
188 if (busoff(reg)) {
189 int istat;
190 /*
191 * Bus is off. Request ownership or turn it on unless
192 * other master requested ownership.
193 */
194 istat = pca9541_reg_read(client, PCA9541_ISTAT);
195 if (!(istat & PCA9541_ISTAT_NMYTEST)
196 || time_is_before_eq_jiffies(data->arb_timeout)) {
197 /*
198 * Other master did not request ownership,
199 * or arbitration timeout expired. Take the bus.
200 */
201 pca9541_reg_write(client,
202 PCA9541_CONTROL,
203 pca9541_control[reg & 0x0f]
204 | PCA9541_CTL_NTESTON);
205 data->select_timeout = SELECT_DELAY_SHORT;
206 } else {
207 /*
208 * Other master requested ownership.
209 * Set extra long timeout to give it time to acquire it.
210 */
211 data->select_timeout = SELECT_DELAY_LONG * 2;
212 }
213 } else if (mybus(reg)) {
214 /*
215 * Bus is on, and we own it. We are done with acquisition.
216 * Reset NTESTON and BUSINIT, then return success.
217 */
218 if (reg & (PCA9541_CTL_NTESTON | PCA9541_CTL_BUSINIT))
219 pca9541_reg_write(client,
220 PCA9541_CONTROL,
221 reg & ~(PCA9541_CTL_NTESTON
222 | PCA9541_CTL_BUSINIT));
223 return 1;
224 } else {
225 /*
226 * Other master owns the bus.
227 * If arbitration timeout has expired, force ownership.
228 * Otherwise request it.
229 */
230 data->select_timeout = SELECT_DELAY_LONG;
231 if (time_is_before_eq_jiffies(data->arb_timeout)) {
232 /* Time is up, take the bus and reset it. */
233 pca9541_reg_write(client,
234 PCA9541_CONTROL,
235 pca9541_control[reg & 0x0f]
236 | PCA9541_CTL_BUSINIT
237 | PCA9541_CTL_NTESTON);
238 } else {
239 /* Request bus ownership if needed */
240 if (!(reg & PCA9541_CTL_NTESTON))
241 pca9541_reg_write(client,
242 PCA9541_CONTROL,
243 reg | PCA9541_CTL_NTESTON);
244 }
245 }
246 return 0;
247}
248
249static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan)
250{
251 struct pca9541 *data = i2c_mux_priv(muxc);
252 struct i2c_client *client = data->client;
253 int ret;
254 unsigned long timeout = jiffies + ARB2_TIMEOUT;
255 /* give up after this time */
256
257 data->arb_timeout = jiffies + ARB_TIMEOUT;
258 /* force bus ownership after this time */
259
260 do {
261 ret = pca9541_arbitrate(client);
262 if (ret)
263 return ret < 0 ? ret : 0;
264
265 if (data->select_timeout == SELECT_DELAY_SHORT)
266 udelay(data->select_timeout);
267 else
268 msleep(data->select_timeout / 1000);
269 } while (time_is_after_eq_jiffies(timeout));
270
271 return -ETIMEDOUT;
272}
273
274static int pca9541_release_chan(struct i2c_mux_core *muxc, u32 chan)
275{
276 struct pca9541 *data = i2c_mux_priv(muxc);
277 struct i2c_client *client = data->client;
278
279 pca9541_release_bus(client);
280 return 0;
281}
282
283/*
284 * I2C init/probing/exit functions
285 */
286static int pca9541_probe(struct i2c_client *client,
287 const struct i2c_device_id *id)
288{
289 struct i2c_adapter *adap = client->adapter;
290 struct i2c_mux_core *muxc;
291 struct pca9541 *data;
292 int ret;
293
294 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA))
295 return -ENODEV;
296
297 /*
298 * I2C accesses are unprotected here.
299 * We have to lock the I2C segment before releasing the bus.
300 */
301 i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
302 pca9541_release_bus(client);
303 i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
304
305 /* Create mux adapter */
306
307 muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data),
308 I2C_MUX_ARBITRATOR,
309 pca9541_select_chan, pca9541_release_chan);
310 if (!muxc)
311 return -ENOMEM;
312
313 data = i2c_mux_priv(muxc);
314 data->client = client;
315
316 i2c_set_clientdata(client, muxc);
317
318 ret = i2c_mux_add_adapter(muxc, 0, 0, 0);
319 if (ret)
320 return ret;
321
322 dev_info(&client->dev, "registered master selector for I2C %s\n",
323 client->name);
324
325 return 0;
326}
327
328static int pca9541_remove(struct i2c_client *client)
329{
330 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
331
332 i2c_mux_del_adapters(muxc);
333 return 0;
334}
335
336static struct i2c_driver pca9541_driver = {
337 .driver = {
338 .name = "pca9541",
339 .of_match_table = of_match_ptr(pca9541_of_match),
340 },
341 .probe = pca9541_probe,
342 .remove = pca9541_remove,
343 .id_table = pca9541_id,
344};
345
346module_i2c_driver(pca9541_driver);
347
348MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
349MODULE_DESCRIPTION("PCA9541 I2C master selector driver");
350MODULE_LICENSE("GPL v2");
1/*
2 * I2C multiplexer driver for PCA9541 bus master selector
3 *
4 * Copyright (c) 2010 Ericsson AB.
5 *
6 * Author: Guenter Roeck <guenter.roeck@ericsson.com>
7 *
8 * Derived from:
9 * pca954x.c
10 *
11 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
12 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
13 *
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 */
18
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/jiffies.h>
22#include <linux/delay.h>
23#include <linux/slab.h>
24#include <linux/device.h>
25#include <linux/i2c.h>
26#include <linux/i2c-mux.h>
27
28#include <linux/i2c/pca954x.h>
29
30/*
31 * The PCA9541 is a bus master selector. It supports two I2C masters connected
32 * to a single slave bus.
33 *
34 * Before each bus transaction, a master has to acquire bus ownership. After the
35 * transaction is complete, bus ownership has to be released. This fits well
36 * into the I2C multiplexer framework, which provides select and release
37 * functions for this purpose. For this reason, this driver is modeled as
38 * single-channel I2C bus multiplexer.
39 *
40 * This driver assumes that the two bus masters are controlled by two different
41 * hosts. If a single host controls both masters, platform code has to ensure
42 * that only one of the masters is instantiated at any given time.
43 */
44
45#define PCA9541_CONTROL 0x01
46#define PCA9541_ISTAT 0x02
47
48#define PCA9541_CTL_MYBUS (1 << 0)
49#define PCA9541_CTL_NMYBUS (1 << 1)
50#define PCA9541_CTL_BUSON (1 << 2)
51#define PCA9541_CTL_NBUSON (1 << 3)
52#define PCA9541_CTL_BUSINIT (1 << 4)
53#define PCA9541_CTL_TESTON (1 << 6)
54#define PCA9541_CTL_NTESTON (1 << 7)
55
56#define PCA9541_ISTAT_INTIN (1 << 0)
57#define PCA9541_ISTAT_BUSINIT (1 << 1)
58#define PCA9541_ISTAT_BUSOK (1 << 2)
59#define PCA9541_ISTAT_BUSLOST (1 << 3)
60#define PCA9541_ISTAT_MYTEST (1 << 6)
61#define PCA9541_ISTAT_NMYTEST (1 << 7)
62
63#define BUSON (PCA9541_CTL_BUSON | PCA9541_CTL_NBUSON)
64#define MYBUS (PCA9541_CTL_MYBUS | PCA9541_CTL_NMYBUS)
65#define mybus(x) (!((x) & MYBUS) || ((x) & MYBUS) == MYBUS)
66#define busoff(x) (!((x) & BUSON) || ((x) & BUSON) == BUSON)
67
68/* arbitration timeouts, in jiffies */
69#define ARB_TIMEOUT (HZ / 8) /* 125 ms until forcing bus ownership */
70#define ARB2_TIMEOUT (HZ / 4) /* 250 ms until acquisition failure */
71
72/* arbitration retry delays, in us */
73#define SELECT_DELAY_SHORT 50
74#define SELECT_DELAY_LONG 1000
75
76struct pca9541 {
77 struct i2c_adapter *mux_adap;
78 unsigned long select_timeout;
79 unsigned long arb_timeout;
80};
81
82static const struct i2c_device_id pca9541_id[] = {
83 {"pca9541", 0},
84 {}
85};
86
87MODULE_DEVICE_TABLE(i2c, pca9541_id);
88
89/*
90 * Write to chip register. Don't use i2c_transfer()/i2c_smbus_xfer()
91 * as they will try to lock the adapter a second time.
92 */
93static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val)
94{
95 struct i2c_adapter *adap = client->adapter;
96 int ret;
97
98 if (adap->algo->master_xfer) {
99 struct i2c_msg msg;
100 char buf[2];
101
102 msg.addr = client->addr;
103 msg.flags = 0;
104 msg.len = 2;
105 buf[0] = command;
106 buf[1] = val;
107 msg.buf = buf;
108 ret = adap->algo->master_xfer(adap, &msg, 1);
109 } else {
110 union i2c_smbus_data data;
111
112 data.byte = val;
113 ret = adap->algo->smbus_xfer(adap, client->addr,
114 client->flags,
115 I2C_SMBUS_WRITE,
116 command,
117 I2C_SMBUS_BYTE_DATA, &data);
118 }
119
120 return ret;
121}
122
123/*
124 * Read from chip register. Don't use i2c_transfer()/i2c_smbus_xfer()
125 * as they will try to lock adapter a second time.
126 */
127static int pca9541_reg_read(struct i2c_client *client, u8 command)
128{
129 struct i2c_adapter *adap = client->adapter;
130 int ret;
131 u8 val;
132
133 if (adap->algo->master_xfer) {
134 struct i2c_msg msg[2] = {
135 {
136 .addr = client->addr,
137 .flags = 0,
138 .len = 1,
139 .buf = &command
140 },
141 {
142 .addr = client->addr,
143 .flags = I2C_M_RD,
144 .len = 1,
145 .buf = &val
146 }
147 };
148 ret = adap->algo->master_xfer(adap, msg, 2);
149 if (ret == 2)
150 ret = val;
151 else if (ret >= 0)
152 ret = -EIO;
153 } else {
154 union i2c_smbus_data data;
155
156 ret = adap->algo->smbus_xfer(adap, client->addr,
157 client->flags,
158 I2C_SMBUS_READ,
159 command,
160 I2C_SMBUS_BYTE_DATA, &data);
161 if (!ret)
162 ret = data.byte;
163 }
164 return ret;
165}
166
167/*
168 * Arbitration management functions
169 */
170
171/* Release bus. Also reset NTESTON and BUSINIT if it was set. */
172static void pca9541_release_bus(struct i2c_client *client)
173{
174 int reg;
175
176 reg = pca9541_reg_read(client, PCA9541_CONTROL);
177 if (reg >= 0 && !busoff(reg) && mybus(reg))
178 pca9541_reg_write(client, PCA9541_CONTROL,
179 (reg & PCA9541_CTL_NBUSON) >> 1);
180}
181
182/*
183 * Arbitration is defined as a two-step process. A bus master can only activate
184 * the slave bus if it owns it; otherwise it has to request ownership first.
185 * This multi-step process ensures that access contention is resolved
186 * gracefully.
187 *
188 * Bus Ownership Other master Action
189 * state requested access
190 * ----------------------------------------------------
191 * off - yes wait for arbitration timeout or
192 * for other master to drop request
193 * off no no take ownership
194 * off yes no turn on bus
195 * on yes - done
196 * on no - wait for arbitration timeout or
197 * for other master to release bus
198 *
199 * The main contention point occurs if the slave bus is off and both masters
200 * request ownership at the same time. In this case, one master will turn on
201 * the slave bus, believing that it owns it. The other master will request
202 * bus ownership. Result is that the bus is turned on, and master which did
203 * _not_ own the slave bus before ends up owning it.
204 */
205
206/* Control commands per PCA9541 datasheet */
207static const u8 pca9541_control[16] = {
208 4, 0, 1, 5, 4, 4, 5, 5, 0, 0, 1, 1, 0, 4, 5, 1
209};
210
211/*
212 * Channel arbitration
213 *
214 * Return values:
215 * <0: error
216 * 0 : bus not acquired
217 * 1 : bus acquired
218 */
219static int pca9541_arbitrate(struct i2c_client *client)
220{
221 struct pca9541 *data = i2c_get_clientdata(client);
222 int reg;
223
224 reg = pca9541_reg_read(client, PCA9541_CONTROL);
225 if (reg < 0)
226 return reg;
227
228 if (busoff(reg)) {
229 int istat;
230 /*
231 * Bus is off. Request ownership or turn it on unless
232 * other master requested ownership.
233 */
234 istat = pca9541_reg_read(client, PCA9541_ISTAT);
235 if (!(istat & PCA9541_ISTAT_NMYTEST)
236 || time_is_before_eq_jiffies(data->arb_timeout)) {
237 /*
238 * Other master did not request ownership,
239 * or arbitration timeout expired. Take the bus.
240 */
241 pca9541_reg_write(client,
242 PCA9541_CONTROL,
243 pca9541_control[reg & 0x0f]
244 | PCA9541_CTL_NTESTON);
245 data->select_timeout = SELECT_DELAY_SHORT;
246 } else {
247 /*
248 * Other master requested ownership.
249 * Set extra long timeout to give it time to acquire it.
250 */
251 data->select_timeout = SELECT_DELAY_LONG * 2;
252 }
253 } else if (mybus(reg)) {
254 /*
255 * Bus is on, and we own it. We are done with acquisition.
256 * Reset NTESTON and BUSINIT, then return success.
257 */
258 if (reg & (PCA9541_CTL_NTESTON | PCA9541_CTL_BUSINIT))
259 pca9541_reg_write(client,
260 PCA9541_CONTROL,
261 reg & ~(PCA9541_CTL_NTESTON
262 | PCA9541_CTL_BUSINIT));
263 return 1;
264 } else {
265 /*
266 * Other master owns the bus.
267 * If arbitration timeout has expired, force ownership.
268 * Otherwise request it.
269 */
270 data->select_timeout = SELECT_DELAY_LONG;
271 if (time_is_before_eq_jiffies(data->arb_timeout)) {
272 /* Time is up, take the bus and reset it. */
273 pca9541_reg_write(client,
274 PCA9541_CONTROL,
275 pca9541_control[reg & 0x0f]
276 | PCA9541_CTL_BUSINIT
277 | PCA9541_CTL_NTESTON);
278 } else {
279 /* Request bus ownership if needed */
280 if (!(reg & PCA9541_CTL_NTESTON))
281 pca9541_reg_write(client,
282 PCA9541_CONTROL,
283 reg | PCA9541_CTL_NTESTON);
284 }
285 }
286 return 0;
287}
288
289static int pca9541_select_chan(struct i2c_adapter *adap, void *client, u32 chan)
290{
291 struct pca9541 *data = i2c_get_clientdata(client);
292 int ret;
293 unsigned long timeout = jiffies + ARB2_TIMEOUT;
294 /* give up after this time */
295
296 data->arb_timeout = jiffies + ARB_TIMEOUT;
297 /* force bus ownership after this time */
298
299 do {
300 ret = pca9541_arbitrate(client);
301 if (ret)
302 return ret < 0 ? ret : 0;
303
304 if (data->select_timeout == SELECT_DELAY_SHORT)
305 udelay(data->select_timeout);
306 else
307 msleep(data->select_timeout / 1000);
308 } while (time_is_after_eq_jiffies(timeout));
309
310 return -ETIMEDOUT;
311}
312
313static int pca9541_release_chan(struct i2c_adapter *adap,
314 void *client, u32 chan)
315{
316 pca9541_release_bus(client);
317 return 0;
318}
319
320/*
321 * I2C init/probing/exit functions
322 */
323static int pca9541_probe(struct i2c_client *client,
324 const struct i2c_device_id *id)
325{
326 struct i2c_adapter *adap = client->adapter;
327 struct pca954x_platform_data *pdata = client->dev.platform_data;
328 struct pca9541 *data;
329 int force;
330 int ret = -ENODEV;
331
332 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA))
333 goto err;
334
335 data = kzalloc(sizeof(struct pca9541), GFP_KERNEL);
336 if (!data) {
337 ret = -ENOMEM;
338 goto err;
339 }
340
341 i2c_set_clientdata(client, data);
342
343 /*
344 * I2C accesses are unprotected here.
345 * We have to lock the adapter before releasing the bus.
346 */
347 i2c_lock_adapter(adap);
348 pca9541_release_bus(client);
349 i2c_unlock_adapter(adap);
350
351 /* Create mux adapter */
352
353 force = 0;
354 if (pdata)
355 force = pdata->modes[0].adap_id;
356 data->mux_adap = i2c_add_mux_adapter(adap, &client->dev, client,
357 force, 0,
358 pca9541_select_chan,
359 pca9541_release_chan);
360
361 if (data->mux_adap == NULL) {
362 dev_err(&client->dev, "failed to register master selector\n");
363 goto exit_free;
364 }
365
366 dev_info(&client->dev, "registered master selector for I2C %s\n",
367 client->name);
368
369 return 0;
370
371exit_free:
372 kfree(data);
373err:
374 return ret;
375}
376
377static int pca9541_remove(struct i2c_client *client)
378{
379 struct pca9541 *data = i2c_get_clientdata(client);
380
381 i2c_del_mux_adapter(data->mux_adap);
382
383 kfree(data);
384 return 0;
385}
386
387static struct i2c_driver pca9541_driver = {
388 .driver = {
389 .name = "pca9541",
390 .owner = THIS_MODULE,
391 },
392 .probe = pca9541_probe,
393 .remove = pca9541_remove,
394 .id_table = pca9541_id,
395};
396
397module_i2c_driver(pca9541_driver);
398
399MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
400MODULE_DESCRIPTION("PCA9541 I2C master selector driver");
401MODULE_LICENSE("GPL v2");