diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/algos/i2c-algo-bit.c | 31 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-i801.c | 1 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-iop3xx.c | 6 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-iop3xx.h | 2 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-mv64xxx.c | 45 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-nforce2.c | 2 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 83 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 29 | ||||
-rw-r--r-- | drivers/i2c/muxes/Kconfig | 12 | ||||
-rw-r--r-- | drivers/i2c/muxes/Makefile | 1 | ||||
-rw-r--r-- | drivers/i2c/muxes/gpio-i2cmux.c | 184 |
11 files changed, 303 insertions, 93 deletions
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 | */ |
603 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | 603 | static 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 | ||
620 | int i2c_bit_add_bus(struct i2c_adapter *adap) | 631 | int 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 | } |
630 | EXPORT_SYMBOL(i2c_bit_add_bus); | 635 | EXPORT_SYMBOL(i2c_bit_add_bus); |
631 | 636 | ||
632 | int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) | 637 | int 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 | } |
642 | EXPORT_SYMBOL(i2c_bit_add_numbered_bus); | 641 | EXPORT_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-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c index 112c61f7b8cd..f09c9319a2ba 100644 --- a/drivers/i2c/busses/i2c-iop3xx.c +++ b/drivers/i2c/busses/i2c-iop3xx.c | |||
@@ -409,7 +409,7 @@ iop3xx_i2c_remove(struct platform_device *pdev) | |||
409 | IOP3XX_ICR_RXFULL_IE | IOP3XX_ICR_TXEMPTY_IE); | 409 | IOP3XX_ICR_RXFULL_IE | IOP3XX_ICR_TXEMPTY_IE); |
410 | __raw_writel(cr, adapter_data->ioaddr + CR_OFFSET); | 410 | __raw_writel(cr, adapter_data->ioaddr + CR_OFFSET); |
411 | 411 | ||
412 | iounmap((void __iomem*)adapter_data->ioaddr); | 412 | iounmap(adapter_data->ioaddr); |
413 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); | 413 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); |
414 | kfree(adapter_data); | 414 | kfree(adapter_data); |
415 | kfree(padapter); | 415 | kfree(padapter); |
@@ -453,7 +453,7 @@ iop3xx_i2c_probe(struct platform_device *pdev) | |||
453 | /* set the adapter enumeration # */ | 453 | /* set the adapter enumeration # */ |
454 | adapter_data->id = i2c_id++; | 454 | adapter_data->id = i2c_id++; |
455 | 455 | ||
456 | adapter_data->ioaddr = (u32)ioremap(res->start, IOP3XX_I2C_IO_SIZE); | 456 | adapter_data->ioaddr = ioremap(res->start, IOP3XX_I2C_IO_SIZE); |
457 | if (!adapter_data->ioaddr) { | 457 | if (!adapter_data->ioaddr) { |
458 | ret = -ENOMEM; | 458 | ret = -ENOMEM; |
459 | goto release_region; | 459 | goto release_region; |
@@ -498,7 +498,7 @@ iop3xx_i2c_probe(struct platform_device *pdev) | |||
498 | return 0; | 498 | return 0; |
499 | 499 | ||
500 | unmap: | 500 | unmap: |
501 | iounmap((void __iomem*)adapter_data->ioaddr); | 501 | iounmap(adapter_data->ioaddr); |
502 | 502 | ||
503 | release_region: | 503 | release_region: |
504 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); | 504 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); |
diff --git a/drivers/i2c/busses/i2c-iop3xx.h b/drivers/i2c/busses/i2c-iop3xx.h index 8485861f6a36..097e270955d0 100644 --- a/drivers/i2c/busses/i2c-iop3xx.h +++ b/drivers/i2c/busses/i2c-iop3xx.h | |||
@@ -97,7 +97,7 @@ | |||
97 | #define IOP3XX_I2C_IO_SIZE 0x18 | 97 | #define IOP3XX_I2C_IO_SIZE 0x18 |
98 | 98 | ||
99 | struct i2c_algo_iop3xx_data { | 99 | struct i2c_algo_iop3xx_data { |
100 | u32 ioaddr; | 100 | void __iomem *ioaddr; |
101 | wait_queue_head_t waitq; | 101 | wait_queue_head_t waitq; |
102 | spinlock_t lock; | 102 | spinlock_t lock; |
103 | u32 SR_enabled, SR_received; | 103 | u32 SR_enabled, SR_received; |
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index 16242063144f..a9941c65f226 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
@@ -59,6 +59,7 @@ enum { | |||
59 | MV64XXX_I2C_STATE_INVALID, | 59 | MV64XXX_I2C_STATE_INVALID, |
60 | MV64XXX_I2C_STATE_IDLE, | 60 | MV64XXX_I2C_STATE_IDLE, |
61 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND, | 61 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND, |
62 | MV64XXX_I2C_STATE_WAITING_FOR_RESTART, | ||
62 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK, | 63 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK, |
63 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK, | 64 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK, |
64 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK, | 65 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK, |
@@ -70,6 +71,7 @@ enum { | |||
70 | MV64XXX_I2C_ACTION_INVALID, | 71 | MV64XXX_I2C_ACTION_INVALID, |
71 | MV64XXX_I2C_ACTION_CONTINUE, | 72 | MV64XXX_I2C_ACTION_CONTINUE, |
72 | MV64XXX_I2C_ACTION_SEND_START, | 73 | MV64XXX_I2C_ACTION_SEND_START, |
74 | MV64XXX_I2C_ACTION_SEND_RESTART, | ||
73 | MV64XXX_I2C_ACTION_SEND_ADDR_1, | 75 | MV64XXX_I2C_ACTION_SEND_ADDR_1, |
74 | MV64XXX_I2C_ACTION_SEND_ADDR_2, | 76 | MV64XXX_I2C_ACTION_SEND_ADDR_2, |
75 | MV64XXX_I2C_ACTION_SEND_DATA, | 77 | MV64XXX_I2C_ACTION_SEND_DATA, |
@@ -91,6 +93,7 @@ struct mv64xxx_i2c_data { | |||
91 | u32 addr2; | 93 | u32 addr2; |
92 | u32 bytes_left; | 94 | u32 bytes_left; |
93 | u32 byte_posn; | 95 | u32 byte_posn; |
96 | u32 send_stop; | ||
94 | u32 block; | 97 | u32 block; |
95 | int rc; | 98 | int rc; |
96 | u32 freq_m; | 99 | u32 freq_m; |
@@ -159,8 +162,15 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status) | |||
159 | if ((drv_data->bytes_left == 0) | 162 | if ((drv_data->bytes_left == 0) |
160 | || (drv_data->aborting | 163 | || (drv_data->aborting |
161 | && (drv_data->byte_posn != 0))) { | 164 | && (drv_data->byte_posn != 0))) { |
162 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; | 165 | if (drv_data->send_stop) { |
163 | drv_data->state = MV64XXX_I2C_STATE_IDLE; | 166 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
167 | drv_data->state = MV64XXX_I2C_STATE_IDLE; | ||
168 | } else { | ||
169 | drv_data->action = | ||
170 | MV64XXX_I2C_ACTION_SEND_RESTART; | ||
171 | drv_data->state = | ||
172 | MV64XXX_I2C_STATE_WAITING_FOR_RESTART; | ||
173 | } | ||
164 | } else { | 174 | } else { |
165 | drv_data->action = MV64XXX_I2C_ACTION_SEND_DATA; | 175 | drv_data->action = MV64XXX_I2C_ACTION_SEND_DATA; |
166 | drv_data->state = | 176 | drv_data->state = |
@@ -228,6 +238,15 @@ static void | |||
228 | mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) | 238 | mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) |
229 | { | 239 | { |
230 | switch(drv_data->action) { | 240 | switch(drv_data->action) { |
241 | case MV64XXX_I2C_ACTION_SEND_RESTART: | ||
242 | drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START; | ||
243 | drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN; | ||
244 | writel(drv_data->cntl_bits, | ||
245 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); | ||
246 | drv_data->block = 0; | ||
247 | wake_up_interruptible(&drv_data->waitq); | ||
248 | break; | ||
249 | |||
231 | case MV64XXX_I2C_ACTION_CONTINUE: | 250 | case MV64XXX_I2C_ACTION_CONTINUE: |
232 | writel(drv_data->cntl_bits, | 251 | writel(drv_data->cntl_bits, |
233 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); | 252 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
@@ -386,7 +405,8 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data) | |||
386 | } | 405 | } |
387 | 406 | ||
388 | static int | 407 | static int |
389 | mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg) | 408 | mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg, |
409 | int is_first, int is_last) | ||
390 | { | 410 | { |
391 | unsigned long flags; | 411 | unsigned long flags; |
392 | 412 | ||
@@ -406,10 +426,18 @@ mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg) | |||
406 | drv_data->bytes_left--; | 426 | drv_data->bytes_left--; |
407 | } | 427 | } |
408 | } else { | 428 | } else { |
409 | drv_data->action = MV64XXX_I2C_ACTION_SEND_START; | 429 | if (is_first) { |
410 | drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND; | 430 | drv_data->action = MV64XXX_I2C_ACTION_SEND_START; |
431 | drv_data->state = | ||
432 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND; | ||
433 | } else { | ||
434 | drv_data->action = MV64XXX_I2C_ACTION_SEND_ADDR_1; | ||
435 | drv_data->state = | ||
436 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK; | ||
437 | } | ||
411 | } | 438 | } |
412 | 439 | ||
440 | drv_data->send_stop = is_last; | ||
413 | drv_data->block = 1; | 441 | drv_data->block = 1; |
414 | mv64xxx_i2c_do_action(drv_data); | 442 | mv64xxx_i2c_do_action(drv_data); |
415 | spin_unlock_irqrestore(&drv_data->lock, flags); | 443 | spin_unlock_irqrestore(&drv_data->lock, flags); |
@@ -437,9 +465,12 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
437 | struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); | 465 | struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); |
438 | int i, rc; | 466 | int i, rc; |
439 | 467 | ||
440 | for (i=0; i<num; i++) | 468 | for (i = 0; i < num; i++) { |
441 | if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) < 0) | 469 | rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i], |
470 | i == 0, i + 1 == num); | ||
471 | if (rc < 0) | ||
442 | return rc; | 472 | return rc; |
473 | } | ||
443 | 474 | ||
444 | return num; | 475 | return num; |
445 | } | 476 | } |
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 | ||
433 | static void __devexit nforce2_remove(struct pci_dev *dev) | 433 | static 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/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index b33c78586bfc..b605ff3a1fa0 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/io.h> | 39 | #include <linux/io.h> |
40 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
41 | #include <linux/i2c-omap.h> | 41 | #include <linux/i2c-omap.h> |
42 | #include <linux/pm_runtime.h> | ||
42 | 43 | ||
43 | /* I2C controller revisions */ | 44 | /* I2C controller revisions */ |
44 | #define OMAP_I2C_REV_2 0x20 | 45 | #define OMAP_I2C_REV_2 0x20 |
@@ -175,8 +176,6 @@ struct omap_i2c_dev { | |||
175 | void __iomem *base; /* virtual */ | 176 | void __iomem *base; /* virtual */ |
176 | int irq; | 177 | int irq; |
177 | int reg_shift; /* bit shift for I2C register addresses */ | 178 | int reg_shift; /* bit shift for I2C register addresses */ |
178 | struct clk *iclk; /* Interface clock */ | ||
179 | struct clk *fclk; /* Functional clock */ | ||
180 | struct completion cmd_complete; | 179 | struct completion cmd_complete; |
181 | struct resource *ioarea; | 180 | struct resource *ioarea; |
182 | u32 latency; /* maximum mpu wkup latency */ | 181 | u32 latency; /* maximum mpu wkup latency */ |
@@ -265,45 +264,18 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) | |||
265 | (i2c_dev->regs[reg] << i2c_dev->reg_shift)); | 264 | (i2c_dev->regs[reg] << i2c_dev->reg_shift)); |
266 | } | 265 | } |
267 | 266 | ||
268 | static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev) | 267 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) |
269 | { | 268 | { |
270 | int ret; | 269 | struct platform_device *pdev; |
271 | 270 | struct omap_i2c_bus_platform_data *pdata; | |
272 | dev->iclk = clk_get(dev->dev, "ick"); | ||
273 | if (IS_ERR(dev->iclk)) { | ||
274 | ret = PTR_ERR(dev->iclk); | ||
275 | dev->iclk = NULL; | ||
276 | return ret; | ||
277 | } | ||
278 | 271 | ||
279 | dev->fclk = clk_get(dev->dev, "fck"); | 272 | WARN_ON(!dev->idle); |
280 | if (IS_ERR(dev->fclk)) { | ||
281 | ret = PTR_ERR(dev->fclk); | ||
282 | if (dev->iclk != NULL) { | ||
283 | clk_put(dev->iclk); | ||
284 | dev->iclk = NULL; | ||
285 | } | ||
286 | dev->fclk = NULL; | ||
287 | return ret; | ||
288 | } | ||
289 | |||
290 | return 0; | ||
291 | } | ||
292 | 273 | ||
293 | static void omap_i2c_put_clocks(struct omap_i2c_dev *dev) | 274 | pdev = to_platform_device(dev->dev); |
294 | { | 275 | pdata = pdev->dev.platform_data; |
295 | clk_put(dev->fclk); | ||
296 | dev->fclk = NULL; | ||
297 | clk_put(dev->iclk); | ||
298 | dev->iclk = NULL; | ||
299 | } | ||
300 | 276 | ||
301 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) | 277 | pm_runtime_get_sync(&pdev->dev); |
302 | { | ||
303 | WARN_ON(!dev->idle); | ||
304 | 278 | ||
305 | clk_enable(dev->iclk); | ||
306 | clk_enable(dev->fclk); | ||
307 | if (cpu_is_omap34xx()) { | 279 | if (cpu_is_omap34xx()) { |
308 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 280 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
309 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); | 281 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); |
@@ -326,10 +298,15 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev) | |||
326 | 298 | ||
327 | static void omap_i2c_idle(struct omap_i2c_dev *dev) | 299 | static void omap_i2c_idle(struct omap_i2c_dev *dev) |
328 | { | 300 | { |
301 | struct platform_device *pdev; | ||
302 | struct omap_i2c_bus_platform_data *pdata; | ||
329 | u16 iv; | 303 | u16 iv; |
330 | 304 | ||
331 | WARN_ON(dev->idle); | 305 | WARN_ON(dev->idle); |
332 | 306 | ||
307 | pdev = to_platform_device(dev->dev); | ||
308 | pdata = pdev->dev.platform_data; | ||
309 | |||
333 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); | 310 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); |
334 | if (dev->rev >= OMAP_I2C_REV_ON_4430) | 311 | if (dev->rev >= OMAP_I2C_REV_ON_4430) |
335 | omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1); | 312 | omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1); |
@@ -345,8 +322,8 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev) | |||
345 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); | 322 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); |
346 | } | 323 | } |
347 | dev->idle = 1; | 324 | dev->idle = 1; |
348 | clk_disable(dev->fclk); | 325 | |
349 | clk_disable(dev->iclk); | 326 | pm_runtime_put_sync(&pdev->dev); |
350 | } | 327 | } |
351 | 328 | ||
352 | static int omap_i2c_init(struct omap_i2c_dev *dev) | 329 | static int omap_i2c_init(struct omap_i2c_dev *dev) |
@@ -356,6 +333,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
356 | unsigned long fclk_rate = 12000000; | 333 | unsigned long fclk_rate = 12000000; |
357 | unsigned long timeout; | 334 | unsigned long timeout; |
358 | unsigned long internal_clk = 0; | 335 | unsigned long internal_clk = 0; |
336 | struct clk *fclk; | ||
359 | 337 | ||
360 | if (dev->rev >= OMAP_I2C_REV_2) { | 338 | if (dev->rev >= OMAP_I2C_REV_2) { |
361 | /* Disable I2C controller before soft reset */ | 339 | /* Disable I2C controller before soft reset */ |
@@ -414,7 +392,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
414 | * always returns 12MHz for the functional clock, we can | 392 | * always returns 12MHz for the functional clock, we can |
415 | * do this bit unconditionally. | 393 | * do this bit unconditionally. |
416 | */ | 394 | */ |
417 | fclk_rate = clk_get_rate(dev->fclk); | 395 | fclk = clk_get(dev->dev, "fck"); |
396 | fclk_rate = clk_get_rate(fclk); | ||
397 | clk_put(fclk); | ||
418 | 398 | ||
419 | /* TRM for 5912 says the I2C clock must be prescaled to be | 399 | /* TRM for 5912 says the I2C clock must be prescaled to be |
420 | * between 7 - 12 MHz. The XOR input clock is typically | 400 | * between 7 - 12 MHz. The XOR input clock is typically |
@@ -443,7 +423,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
443 | internal_clk = 9600; | 423 | internal_clk = 9600; |
444 | else | 424 | else |
445 | internal_clk = 4000; | 425 | internal_clk = 4000; |
446 | fclk_rate = clk_get_rate(dev->fclk) / 1000; | 426 | fclk = clk_get(dev->dev, "fck"); |
427 | fclk_rate = clk_get_rate(fclk) / 1000; | ||
428 | clk_put(fclk); | ||
447 | 429 | ||
448 | /* Compute prescaler divisor */ | 430 | /* Compute prescaler divisor */ |
449 | psc = fclk_rate / internal_clk; | 431 | psc = fclk_rate / internal_clk; |
@@ -616,12 +598,8 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap, | |||
616 | * REVISIT: We should abort the transfer on signals, but the bus goes | 598 | * REVISIT: We should abort the transfer on signals, but the bus goes |
617 | * into arbitration and we're currently unable to recover from it. | 599 | * into arbitration and we're currently unable to recover from it. |
618 | */ | 600 | */ |
619 | if (dev->set_mpu_wkup_lat != NULL) | ||
620 | dev->set_mpu_wkup_lat(dev->dev, dev->latency); | ||
621 | r = wait_for_completion_timeout(&dev->cmd_complete, | 601 | r = wait_for_completion_timeout(&dev->cmd_complete, |
622 | OMAP_I2C_TIMEOUT); | 602 | OMAP_I2C_TIMEOUT); |
623 | if (dev->set_mpu_wkup_lat != NULL) | ||
624 | dev->set_mpu_wkup_lat(dev->dev, -1); | ||
625 | dev->buf_len = 0; | 603 | dev->buf_len = 0; |
626 | if (r < 0) | 604 | if (r < 0) |
627 | return r; | 605 | return r; |
@@ -672,12 +650,18 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
672 | if (r < 0) | 650 | if (r < 0) |
673 | goto out; | 651 | goto out; |
674 | 652 | ||
653 | if (dev->set_mpu_wkup_lat != NULL) | ||
654 | dev->set_mpu_wkup_lat(dev->dev, dev->latency); | ||
655 | |||
675 | for (i = 0; i < num; i++) { | 656 | for (i = 0; i < num; i++) { |
676 | r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1))); | 657 | r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1))); |
677 | if (r != 0) | 658 | if (r != 0) |
678 | break; | 659 | break; |
679 | } | 660 | } |
680 | 661 | ||
662 | if (dev->set_mpu_wkup_lat != NULL) | ||
663 | dev->set_mpu_wkup_lat(dev->dev, -1); | ||
664 | |||
681 | if (r == 0) | 665 | if (r == 0) |
682 | r = num; | 666 | r = num; |
683 | 667 | ||
@@ -1048,14 +1032,12 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1048 | else | 1032 | else |
1049 | dev->reg_shift = 2; | 1033 | dev->reg_shift = 2; |
1050 | 1034 | ||
1051 | if ((r = omap_i2c_get_clocks(dev)) != 0) | ||
1052 | goto err_iounmap; | ||
1053 | |||
1054 | if (cpu_is_omap44xx()) | 1035 | if (cpu_is_omap44xx()) |
1055 | dev->regs = (u8 *) omap4_reg_map; | 1036 | dev->regs = (u8 *) omap4_reg_map; |
1056 | else | 1037 | else |
1057 | dev->regs = (u8 *) reg_map; | 1038 | dev->regs = (u8 *) reg_map; |
1058 | 1039 | ||
1040 | pm_runtime_enable(&pdev->dev); | ||
1059 | omap_i2c_unidle(dev); | 1041 | omap_i2c_unidle(dev); |
1060 | 1042 | ||
1061 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; | 1043 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; |
@@ -1127,8 +1109,6 @@ err_free_irq: | |||
1127 | err_unuse_clocks: | 1109 | err_unuse_clocks: |
1128 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1110 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
1129 | omap_i2c_idle(dev); | 1111 | omap_i2c_idle(dev); |
1130 | omap_i2c_put_clocks(dev); | ||
1131 | err_iounmap: | ||
1132 | iounmap(dev->base); | 1112 | iounmap(dev->base); |
1133 | err_free_mem: | 1113 | err_free_mem: |
1134 | platform_set_drvdata(pdev, NULL); | 1114 | platform_set_drvdata(pdev, NULL); |
@@ -1150,7 +1130,6 @@ omap_i2c_remove(struct platform_device *pdev) | |||
1150 | free_irq(dev->irq, dev); | 1130 | free_irq(dev->irq, dev); |
1151 | i2c_del_adapter(&dev->adapter); | 1131 | i2c_del_adapter(&dev->adapter); |
1152 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1132 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
1153 | omap_i2c_put_clocks(dev); | ||
1154 | iounmap(dev->base); | 1133 | iounmap(dev->base); |
1155 | kfree(dev); | 1134 | kfree(dev); |
1156 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1135 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -1162,7 +1141,7 @@ static struct platform_driver omap_i2c_driver = { | |||
1162 | .probe = omap_i2c_probe, | 1141 | .probe = omap_i2c_probe, |
1163 | .remove = omap_i2c_remove, | 1142 | .remove = omap_i2c_remove, |
1164 | .driver = { | 1143 | .driver = { |
1165 | .name = "i2c_omap", | 1144 | .name = "omap_i2c", |
1166 | .owner = THIS_MODULE, | 1145 | .owner = THIS_MODULE, |
1167 | }, | 1146 | }, |
1168 | }; | 1147 | }; |
@@ -1184,4 +1163,4 @@ module_exit(omap_i2c_exit_driver); | |||
1184 | MODULE_AUTHOR("MontaVista Software, Inc. (and others)"); | 1163 | MODULE_AUTHOR("MontaVista Software, Inc. (and others)"); |
1185 | MODULE_DESCRIPTION("TI OMAP I2C bus adapter"); | 1164 | MODULE_DESCRIPTION("TI OMAP I2C bus adapter"); |
1186 | MODULE_LICENSE("GPL"); | 1165 | MODULE_LICENSE("GPL"); |
1187 | MODULE_ALIAS("platform:i2c_omap"); | 1166 | MODULE_ALIAS("platform:omap_i2c"); |
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 | */ |
1365 | int i2c_master_send(struct i2c_client *client, const char *buf, int count) | 1365 | int 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 | */ |
1392 | int i2c_master_recv(struct i2c_client *client, char *buf, int count) | 1392 | int 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 | */ |
1682 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 1682 | s32 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 | */ |
1702 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) | 1702 | s32 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 | */ |
1717 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) | 1717 | s32 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 | */ |
1738 | s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) | 1738 | s32 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 | */ |
1756 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) | 1757 | s32 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 | */ |
1777 | s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | 1778 | s32 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 | */ |
1796 | s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value) | 1798 | s32 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 | */ |
1824 | s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, | 1827 | s32 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 | */ |
1851 | s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | 1854 | s32 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, | |||
1864 | EXPORT_SYMBOL(i2c_smbus_write_block_data); | 1867 | EXPORT_SYMBOL(i2c_smbus_write_block_data); |
1865 | 1868 | ||
1866 | /* Returns the number of read bytes */ | 1869 | /* Returns the number of read bytes */ |
1867 | s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, | 1870 | s32 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 | } |
1885 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); | 1888 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); |
1886 | 1889 | ||
1887 | s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | 1890 | s32 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 @@ | |||
5 | menu "Multiplexer I2C Chip support" | 5 | menu "Multiplexer I2C Chip support" |
6 | depends on I2C_MUX | 6 | depends on I2C_MUX |
7 | 7 | ||
8 | config 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 | |||
8 | config I2C_MUX_PCA9541 | 20 | config 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 | ||
4 | obj-$(CONFIG_I2C_MUX_GPIO) += gpio-i2cmux.o | ||
4 | obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o | 5 | obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o |
5 | obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o | 6 | obj-$(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 | |||
20 | struct gpiomux { | ||
21 | struct i2c_adapter *parent; | ||
22 | struct i2c_adapter **adap; /* child busses */ | ||
23 | struct gpio_i2cmux_platform_data data; | ||
24 | }; | ||
25 | |||
26 | static 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 | |||
34 | static 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 | |||
43 | static 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 | |||
52 | static 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 | |||
124 | add_adapter_failed: | ||
125 | for (; i > 0; i--) | ||
126 | i2c_del_mux_adapter(mux->adap[i - 1]); | ||
127 | i = pdata->n_gpios; | ||
128 | err_request_gpio: | ||
129 | for (; i > 0; i--) | ||
130 | gpio_free(pdata->gpios[i - 1]); | ||
131 | kfree(mux->adap); | ||
132 | alloc_failed2: | ||
133 | kfree(mux); | ||
134 | alloc_failed: | ||
135 | i2c_put_adapter(parent); | ||
136 | |||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | static 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 | |||
159 | static 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 | |||
168 | static int __init gpiomux_init(void) | ||
169 | { | ||
170 | return platform_driver_register(&gpiomux_driver); | ||
171 | } | ||
172 | |||
173 | static void __exit gpiomux_exit(void) | ||
174 | { | ||
175 | platform_driver_unregister(&gpiomux_driver); | ||
176 | } | ||
177 | |||
178 | module_init(gpiomux_init); | ||
179 | module_exit(gpiomux_exit); | ||
180 | |||
181 | MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver"); | ||
182 | MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>"); | ||
183 | MODULE_LICENSE("GPL"); | ||
184 | MODULE_ALIAS("platform:gpio-i2cmux"); | ||