diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-cpm.c | 1 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-pxa.c | 2 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-s3c2410.c | 22 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-sh_mobile.c | 73 |
4 files changed, 55 insertions, 43 deletions
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c index 228f75723063..3fcf78e906db 100644 --- a/drivers/i2c/busses/i2c-cpm.c +++ b/drivers/i2c/busses/i2c-cpm.c | |||
@@ -365,6 +365,7 @@ static int cpm_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
365 | pmsg = &msgs[tptr]; | 365 | pmsg = &msgs[tptr]; |
366 | if (pmsg->flags & I2C_M_RD) | 366 | if (pmsg->flags & I2C_M_RD) |
367 | ret = wait_event_interruptible_timeout(cpm->i2c_wait, | 367 | ret = wait_event_interruptible_timeout(cpm->i2c_wait, |
368 | (in_be16(&tbdf[tptr].cbd_sc) & BD_SC_NAK) || | ||
368 | !(in_be16(&rbdf[rptr].cbd_sc) & BD_SC_EMPTY), | 369 | !(in_be16(&rbdf[rptr].cbd_sc) & BD_SC_EMPTY), |
369 | 1 * HZ); | 370 | 1 * HZ); |
370 | else | 371 | else |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 906f9b9d715d..587f5b2380d4 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -1016,7 +1016,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
1016 | snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u", | 1016 | snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u", |
1017 | i2c->adap.nr); | 1017 | i2c->adap.nr); |
1018 | 1018 | ||
1019 | i2c->clk = clk_get(&dev->dev, "I2CCLK"); | 1019 | i2c->clk = clk_get(&dev->dev, NULL); |
1020 | if (IS_ERR(i2c->clk)) { | 1020 | if (IS_ERR(i2c->clk)) { |
1021 | ret = PTR_ERR(i2c->clk); | 1021 | ret = PTR_ERR(i2c->clk); |
1022 | goto eclk; | 1022 | goto eclk; |
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 2a0de645ccf3..f69f91ffb469 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c | |||
@@ -38,8 +38,8 @@ | |||
38 | #include <asm/irq.h> | 38 | #include <asm/irq.h> |
39 | #include <asm/io.h> | 39 | #include <asm/io.h> |
40 | 40 | ||
41 | #include <asm/plat-s3c/regs-iic.h> | 41 | #include <plat/regs-iic.h> |
42 | #include <asm/plat-s3c/iic.h> | 42 | #include <plat/iic.h> |
43 | 43 | ||
44 | /* i2c controller state */ | 44 | /* i2c controller state */ |
45 | 45 | ||
@@ -54,6 +54,7 @@ enum s3c24xx_i2c_state { | |||
54 | struct s3c24xx_i2c { | 54 | struct s3c24xx_i2c { |
55 | spinlock_t lock; | 55 | spinlock_t lock; |
56 | wait_queue_head_t wait; | 56 | wait_queue_head_t wait; |
57 | unsigned int suspended:1; | ||
57 | 58 | ||
58 | struct i2c_msg *msg; | 59 | struct i2c_msg *msg; |
59 | unsigned int msg_num; | 60 | unsigned int msg_num; |
@@ -476,7 +477,7 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, | |||
476 | unsigned long timeout; | 477 | unsigned long timeout; |
477 | int ret; | 478 | int ret; |
478 | 479 | ||
479 | if (!(readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN)) | 480 | if (i2c->suspended) |
480 | return -EIO; | 481 | return -EIO; |
481 | 482 | ||
482 | ret = s3c24xx_i2c_set_master(i2c); | 483 | ret = s3c24xx_i2c_set_master(i2c); |
@@ -957,17 +958,26 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) | |||
957 | } | 958 | } |
958 | 959 | ||
959 | #ifdef CONFIG_PM | 960 | #ifdef CONFIG_PM |
961 | static int s3c24xx_i2c_suspend_late(struct platform_device *dev, | ||
962 | pm_message_t msg) | ||
963 | { | ||
964 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); | ||
965 | i2c->suspended = 1; | ||
966 | return 0; | ||
967 | } | ||
968 | |||
960 | static int s3c24xx_i2c_resume(struct platform_device *dev) | 969 | static int s3c24xx_i2c_resume(struct platform_device *dev) |
961 | { | 970 | { |
962 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); | 971 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); |
963 | 972 | ||
964 | if (i2c != NULL) | 973 | i2c->suspended = 0; |
965 | s3c24xx_i2c_init(i2c); | 974 | s3c24xx_i2c_init(i2c); |
966 | 975 | ||
967 | return 0; | 976 | return 0; |
968 | } | 977 | } |
969 | 978 | ||
970 | #else | 979 | #else |
980 | #define s3c24xx_i2c_suspend_late NULL | ||
971 | #define s3c24xx_i2c_resume NULL | 981 | #define s3c24xx_i2c_resume NULL |
972 | #endif | 982 | #endif |
973 | 983 | ||
@@ -976,6 +986,7 @@ static int s3c24xx_i2c_resume(struct platform_device *dev) | |||
976 | static struct platform_driver s3c2410_i2c_driver = { | 986 | static struct platform_driver s3c2410_i2c_driver = { |
977 | .probe = s3c24xx_i2c_probe, | 987 | .probe = s3c24xx_i2c_probe, |
978 | .remove = s3c24xx_i2c_remove, | 988 | .remove = s3c24xx_i2c_remove, |
989 | .suspend_late = s3c24xx_i2c_suspend_late, | ||
979 | .resume = s3c24xx_i2c_resume, | 990 | .resume = s3c24xx_i2c_resume, |
980 | .driver = { | 991 | .driver = { |
981 | .owner = THIS_MODULE, | 992 | .owner = THIS_MODULE, |
@@ -986,6 +997,7 @@ static struct platform_driver s3c2410_i2c_driver = { | |||
986 | static struct platform_driver s3c2440_i2c_driver = { | 997 | static struct platform_driver s3c2440_i2c_driver = { |
987 | .probe = s3c24xx_i2c_probe, | 998 | .probe = s3c24xx_i2c_probe, |
988 | .remove = s3c24xx_i2c_remove, | 999 | .remove = s3c24xx_i2c_remove, |
1000 | .suspend_late = s3c24xx_i2c_suspend_late, | ||
989 | .resume = s3c24xx_i2c_resume, | 1001 | .resume = s3c24xx_i2c_resume, |
990 | .driver = { | 1002 | .driver = { |
991 | .owner = THIS_MODULE, | 1003 | .owner = THIS_MODULE, |
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index 3384a717fec0..6c3d60b939bf 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c | |||
@@ -160,9 +160,39 @@ struct sh_mobile_i2c_data { | |||
160 | 160 | ||
161 | static void activate_ch(struct sh_mobile_i2c_data *pd) | 161 | static void activate_ch(struct sh_mobile_i2c_data *pd) |
162 | { | 162 | { |
163 | unsigned long i2c_clk; | ||
164 | u_int32_t num; | ||
165 | u_int32_t denom; | ||
166 | u_int32_t tmp; | ||
167 | |||
163 | /* Make sure the clock is enabled */ | 168 | /* Make sure the clock is enabled */ |
164 | clk_enable(pd->clk); | 169 | clk_enable(pd->clk); |
165 | 170 | ||
171 | /* Get clock rate after clock is enabled */ | ||
172 | i2c_clk = clk_get_rate(pd->clk); | ||
173 | |||
174 | /* Calculate the value for iccl. From the data sheet: | ||
175 | * iccl = (p clock / transfer rate) * (L / (L + H)) | ||
176 | * where L and H are the SCL low/high ratio (5/4 in this case). | ||
177 | * We also round off the result. | ||
178 | */ | ||
179 | num = i2c_clk * 5; | ||
180 | denom = NORMAL_SPEED * 9; | ||
181 | tmp = num * 10 / denom; | ||
182 | if (tmp % 10 >= 5) | ||
183 | pd->iccl = (u_int8_t)((num/denom) + 1); | ||
184 | else | ||
185 | pd->iccl = (u_int8_t)(num/denom); | ||
186 | |||
187 | /* Calculate the value for icch. From the data sheet: | ||
188 | icch = (p clock / transfer rate) * (H / (L + H)) */ | ||
189 | num = i2c_clk * 4; | ||
190 | tmp = num * 10 / denom; | ||
191 | if (tmp % 10 >= 5) | ||
192 | pd->icch = (u_int8_t)((num/denom) + 1); | ||
193 | else | ||
194 | pd->icch = (u_int8_t)(num/denom); | ||
195 | |||
166 | /* Enable channel and configure rx ack */ | 196 | /* Enable channel and configure rx ack */ |
167 | iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); | 197 | iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); |
168 | 198 | ||
@@ -459,40 +489,6 @@ static struct i2c_algorithm sh_mobile_i2c_algorithm = { | |||
459 | .master_xfer = sh_mobile_i2c_xfer, | 489 | .master_xfer = sh_mobile_i2c_xfer, |
460 | }; | 490 | }; |
461 | 491 | ||
462 | static void sh_mobile_i2c_setup_channel(struct platform_device *dev) | ||
463 | { | ||
464 | struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); | ||
465 | unsigned long peripheral_clk = clk_get_rate(pd->clk); | ||
466 | u_int32_t num; | ||
467 | u_int32_t denom; | ||
468 | u_int32_t tmp; | ||
469 | |||
470 | spin_lock_init(&pd->lock); | ||
471 | init_waitqueue_head(&pd->wait); | ||
472 | |||
473 | /* Calculate the value for iccl. From the data sheet: | ||
474 | * iccl = (p clock / transfer rate) * (L / (L + H)) | ||
475 | * where L and H are the SCL low/high ratio (5/4 in this case). | ||
476 | * We also round off the result. | ||
477 | */ | ||
478 | num = peripheral_clk * 5; | ||
479 | denom = NORMAL_SPEED * 9; | ||
480 | tmp = num * 10 / denom; | ||
481 | if (tmp % 10 >= 5) | ||
482 | pd->iccl = (u_int8_t)((num/denom) + 1); | ||
483 | else | ||
484 | pd->iccl = (u_int8_t)(num/denom); | ||
485 | |||
486 | /* Calculate the value for icch. From the data sheet: | ||
487 | icch = (p clock / transfer rate) * (H / (L + H)) */ | ||
488 | num = peripheral_clk * 4; | ||
489 | tmp = num * 10 / denom; | ||
490 | if (tmp % 10 >= 5) | ||
491 | pd->icch = (u_int8_t)((num/denom) + 1); | ||
492 | else | ||
493 | pd->icch = (u_int8_t)(num/denom); | ||
494 | } | ||
495 | |||
496 | static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) | 492 | static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) |
497 | { | 493 | { |
498 | struct resource *res; | 494 | struct resource *res; |
@@ -533,6 +529,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
533 | struct sh_mobile_i2c_data *pd; | 529 | struct sh_mobile_i2c_data *pd; |
534 | struct i2c_adapter *adap; | 530 | struct i2c_adapter *adap; |
535 | struct resource *res; | 531 | struct resource *res; |
532 | char clk_name[8]; | ||
536 | int size; | 533 | int size; |
537 | int ret; | 534 | int ret; |
538 | 535 | ||
@@ -542,9 +539,10 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
542 | return -ENOMEM; | 539 | return -ENOMEM; |
543 | } | 540 | } |
544 | 541 | ||
545 | pd->clk = clk_get(&dev->dev, "peripheral_clk"); | 542 | snprintf(clk_name, sizeof(clk_name), "i2c%d", dev->id); |
543 | pd->clk = clk_get(&dev->dev, clk_name); | ||
546 | if (IS_ERR(pd->clk)) { | 544 | if (IS_ERR(pd->clk)) { |
547 | dev_err(&dev->dev, "cannot get peripheral clock\n"); | 545 | dev_err(&dev->dev, "cannot get clock \"%s\"\n", clk_name); |
548 | ret = PTR_ERR(pd->clk); | 546 | ret = PTR_ERR(pd->clk); |
549 | goto err; | 547 | goto err; |
550 | } | 548 | } |
@@ -586,7 +584,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
586 | 584 | ||
587 | strlcpy(adap->name, dev->name, sizeof(adap->name)); | 585 | strlcpy(adap->name, dev->name, sizeof(adap->name)); |
588 | 586 | ||
589 | sh_mobile_i2c_setup_channel(dev); | 587 | spin_lock_init(&pd->lock); |
588 | init_waitqueue_head(&pd->wait); | ||
590 | 589 | ||
591 | ret = i2c_add_numbered_adapter(adap); | 590 | ret = i2c_add_numbered_adapter(adap); |
592 | if (ret < 0) { | 591 | if (ret < 0) { |