diff options
Diffstat (limited to 'drivers/i2c/busses/i2c-nomadik.c')
| -rw-r--r-- | drivers/i2c/busses/i2c-nomadik.c | 276 |
1 files changed, 184 insertions, 92 deletions
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index e10e5cf3751..0c731ca69f1 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c | |||
| @@ -15,13 +15,14 @@ | |||
| 15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/delay.h> | ||
| 19 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
| 20 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
| 21 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
| 22 | #include <linux/err.h> | 21 | #include <linux/err.h> |
| 23 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
| 24 | #include <linux/io.h> | 23 | #include <linux/io.h> |
| 24 | #include <linux/regulator/consumer.h> | ||
| 25 | #include <linux/pm_runtime.h> | ||
| 25 | 26 | ||
| 26 | #include <plat/i2c.h> | 27 | #include <plat/i2c.h> |
| 27 | 28 | ||
| @@ -103,9 +104,6 @@ | |||
| 103 | /* maximum threshold value */ | 104 | /* maximum threshold value */ |
| 104 | #define MAX_I2C_FIFO_THRESHOLD 15 | 105 | #define MAX_I2C_FIFO_THRESHOLD 15 |
| 105 | 106 | ||
| 106 | /* per-transfer delay, required for the hardware to stabilize */ | ||
| 107 | #define I2C_DELAY 150 | ||
| 108 | |||
| 109 | enum i2c_status { | 107 | enum i2c_status { |
| 110 | I2C_NOP, | 108 | I2C_NOP, |
| 111 | I2C_ON_GOING, | 109 | I2C_ON_GOING, |
| @@ -120,9 +118,6 @@ enum i2c_operation { | |||
| 120 | I2C_READ = 0x01 | 118 | I2C_READ = 0x01 |
| 121 | }; | 119 | }; |
| 122 | 120 | ||
| 123 | /* controller response timeout in ms */ | ||
| 124 | #define I2C_TIMEOUT_MS 2000 | ||
| 125 | |||
| 126 | /** | 121 | /** |
| 127 | * struct i2c_nmk_client - client specific data | 122 | * struct i2c_nmk_client - client specific data |
| 128 | * @slave_adr: 7-bit slave address | 123 | * @slave_adr: 7-bit slave address |
| @@ -151,6 +146,7 @@ struct i2c_nmk_client { | |||
| 151 | * @stop: stop condition | 146 | * @stop: stop condition |
| 152 | * @xfer_complete: acknowledge completion for a I2C message | 147 | * @xfer_complete: acknowledge completion for a I2C message |
| 153 | * @result: controller propogated result | 148 | * @result: controller propogated result |
| 149 | * @busy: Busy doing transfer | ||
| 154 | */ | 150 | */ |
| 155 | struct nmk_i2c_dev { | 151 | struct nmk_i2c_dev { |
| 156 | struct platform_device *pdev; | 152 | struct platform_device *pdev; |
| @@ -163,6 +159,8 @@ struct nmk_i2c_dev { | |||
| 163 | int stop; | 159 | int stop; |
| 164 | struct completion xfer_complete; | 160 | struct completion xfer_complete; |
| 165 | int result; | 161 | int result; |
| 162 | struct regulator *regulator; | ||
| 163 | bool busy; | ||
| 166 | }; | 164 | }; |
| 167 | 165 | ||
| 168 | /* controller's abort causes */ | 166 | /* controller's abort causes */ |
| @@ -209,7 +207,7 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev) | |||
| 209 | writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR); | 207 | writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR); |
| 210 | 208 | ||
| 211 | for (i = 0; i < LOOP_ATTEMPTS; i++) { | 209 | for (i = 0; i < LOOP_ATTEMPTS; i++) { |
| 212 | timeout = jiffies + msecs_to_jiffies(I2C_TIMEOUT_MS); | 210 | timeout = jiffies + dev->adap.timeout; |
| 213 | 211 | ||
| 214 | while (!time_after(jiffies, timeout)) { | 212 | while (!time_after(jiffies, timeout)) { |
| 215 | if ((readl(dev->virtbase + I2C_CR) & | 213 | if ((readl(dev->virtbase + I2C_CR) & |
| @@ -253,11 +251,9 @@ static int init_hw(struct nmk_i2c_dev *dev) | |||
| 253 | { | 251 | { |
| 254 | int stat; | 252 | int stat; |
| 255 | 253 | ||
| 256 | clk_enable(dev->clk); | ||
| 257 | |||
| 258 | stat = flush_i2c_fifo(dev); | 254 | stat = flush_i2c_fifo(dev); |
| 259 | if (stat) | 255 | if (stat) |
| 260 | return stat; | 256 | goto exit; |
| 261 | 257 | ||
| 262 | /* disable the controller */ | 258 | /* disable the controller */ |
| 263 | i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE); | 259 | i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE); |
| @@ -268,10 +264,8 @@ static int init_hw(struct nmk_i2c_dev *dev) | |||
| 268 | 264 | ||
| 269 | dev->cli.operation = I2C_NO_OPERATION; | 265 | dev->cli.operation = I2C_NO_OPERATION; |
| 270 | 266 | ||
| 271 | clk_disable(dev->clk); | 267 | exit: |
| 272 | 268 | return stat; | |
| 273 | udelay(I2C_DELAY); | ||
| 274 | return 0; | ||
| 275 | } | 269 | } |
| 276 | 270 | ||
| 277 | /* enable peripheral, master mode operation */ | 271 | /* enable peripheral, master mode operation */ |
| @@ -424,7 +418,7 @@ static int read_i2c(struct nmk_i2c_dev *dev) | |||
| 424 | dev->virtbase + I2C_IMSCR); | 418 | dev->virtbase + I2C_IMSCR); |
| 425 | 419 | ||
| 426 | timeout = wait_for_completion_interruptible_timeout( | 420 | timeout = wait_for_completion_interruptible_timeout( |
| 427 | &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); | 421 | &dev->xfer_complete, dev->adap.timeout); |
| 428 | 422 | ||
| 429 | if (timeout < 0) { | 423 | if (timeout < 0) { |
| 430 | dev_err(&dev->pdev->dev, | 424 | dev_err(&dev->pdev->dev, |
| @@ -434,14 +428,32 @@ static int read_i2c(struct nmk_i2c_dev *dev) | |||
| 434 | } | 428 | } |
| 435 | 429 | ||
| 436 | if (timeout == 0) { | 430 | if (timeout == 0) { |
| 437 | /* controller has timedout, re-init the h/w */ | 431 | /* Controller timed out */ |
| 438 | dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); | 432 | dev_err(&dev->pdev->dev, "read from slave 0x%x timed out\n", |
| 439 | (void) init_hw(dev); | 433 | dev->cli.slave_adr); |
| 440 | status = -ETIMEDOUT; | 434 | status = -ETIMEDOUT; |
| 441 | } | 435 | } |
| 442 | return status; | 436 | return status; |
| 443 | } | 437 | } |
| 444 | 438 | ||
| 439 | static void fill_tx_fifo(struct nmk_i2c_dev *dev, int no_bytes) | ||
| 440 | { | ||
| 441 | int count; | ||
| 442 | |||
| 443 | for (count = (no_bytes - 2); | ||
| 444 | (count > 0) && | ||
| 445 | (dev->cli.count != 0); | ||
| 446 | count--) { | ||
| 447 | /* write to the Tx FIFO */ | ||
| 448 | writeb(*dev->cli.buffer, | ||
| 449 | dev->virtbase + I2C_TFR); | ||
| 450 | dev->cli.buffer++; | ||
| 451 | dev->cli.count--; | ||
| 452 | dev->cli.xfer_bytes++; | ||
| 453 | } | ||
| 454 | |||
| 455 | } | ||
| 456 | |||
| 445 | /** | 457 | /** |
| 446 | * write_i2c() - Write data to I2C client. | 458 | * write_i2c() - Write data to I2C client. |
| 447 | * @dev: private data of I2C Driver | 459 | * @dev: private data of I2C Driver |
| @@ -469,8 +481,13 @@ static int write_i2c(struct nmk_i2c_dev *dev) | |||
| 469 | init_completion(&dev->xfer_complete); | 481 | init_completion(&dev->xfer_complete); |
| 470 | 482 | ||
| 471 | /* enable interrupts by settings the masks */ | 483 | /* enable interrupts by settings the masks */ |
| 472 | irq_mask = (I2C_IT_TXFNE | I2C_IT_TXFOVR | | 484 | irq_mask = (I2C_IT_TXFOVR | I2C_IT_MAL | I2C_IT_BERR); |
| 473 | I2C_IT_MAL | I2C_IT_BERR); | 485 | |
| 486 | /* Fill the TX FIFO with transmit data */ | ||
| 487 | fill_tx_fifo(dev, MAX_I2C_FIFO_THRESHOLD); | ||
| 488 | |||
| 489 | if (dev->cli.count != 0) | ||
| 490 | irq_mask |= I2C_IT_TXFNE; | ||
| 474 | 491 | ||
| 475 | /* | 492 | /* |
| 476 | * check if we want to transfer a single or multiple bytes, if so | 493 | * check if we want to transfer a single or multiple bytes, if so |
| @@ -488,7 +505,7 @@ static int write_i2c(struct nmk_i2c_dev *dev) | |||
| 488 | dev->virtbase + I2C_IMSCR); | 505 | dev->virtbase + I2C_IMSCR); |
| 489 | 506 | ||
| 490 | timeout = wait_for_completion_interruptible_timeout( | 507 | timeout = wait_for_completion_interruptible_timeout( |
| 491 | &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); | 508 | &dev->xfer_complete, dev->adap.timeout); |
| 492 | 509 | ||
| 493 | if (timeout < 0) { | 510 | if (timeout < 0) { |
| 494 | dev_err(&dev->pdev->dev, | 511 | dev_err(&dev->pdev->dev, |
| @@ -498,9 +515,9 @@ static int write_i2c(struct nmk_i2c_dev *dev) | |||
| 498 | } | 515 | } |
| 499 | 516 | ||
| 500 | if (timeout == 0) { | 517 | if (timeout == 0) { |
| 501 | /* controller has timedout, re-init the h/w */ | 518 | /* Controller timed out */ |
| 502 | dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); | 519 | dev_err(&dev->pdev->dev, "write to slave 0x%x timed out\n", |
| 503 | (void) init_hw(dev); | 520 | dev->cli.slave_adr); |
| 504 | status = -ETIMEDOUT; | 521 | status = -ETIMEDOUT; |
| 505 | } | 522 | } |
| 506 | 523 | ||
| @@ -508,6 +525,51 @@ static int write_i2c(struct nmk_i2c_dev *dev) | |||
| 508 | } | 525 | } |
| 509 | 526 | ||
| 510 | /** | 527 | /** |
| 528 | * nmk_i2c_xfer_one() - transmit a single I2C message | ||
| 529 | * @dev: device with a message encoded into it | ||
| 530 | * @flags: message flags | ||
| 531 | */ | ||
| 532 | static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) | ||
| 533 | { | ||
| 534 | int status; | ||
| 535 | |||
| 536 | if (flags & I2C_M_RD) { | ||
| 537 | /* read operation */ | ||
| 538 | dev->cli.operation = I2C_READ; | ||
| 539 | status = read_i2c(dev); | ||
| 540 | } else { | ||
| 541 | /* write operation */ | ||
| 542 | dev->cli.operation = I2C_WRITE; | ||
| 543 | status = write_i2c(dev); | ||
| 544 | } | ||
| 545 | |||
| 546 | if (status || (dev->result)) { | ||
| 547 | u32 i2c_sr; | ||
| 548 | u32 cause; | ||
| 549 | |||
| 550 | i2c_sr = readl(dev->virtbase + I2C_SR); | ||
| 551 | /* | ||
| 552 | * Check if the controller I2C operation status | ||
| 553 | * is set to ABORT(11b). | ||
| 554 | */ | ||
| 555 | if (((i2c_sr >> 2) & 0x3) == 0x3) { | ||
| 556 | /* get the abort cause */ | ||
| 557 | cause = (i2c_sr >> 4) & 0x7; | ||
| 558 | dev_err(&dev->pdev->dev, "%s\n", cause | ||
| 559 | >= ARRAY_SIZE(abort_causes) ? | ||
| 560 | "unknown reason" : | ||
| 561 | abort_causes[cause]); | ||
| 562 | } | ||
| 563 | |||
| 564 | (void) init_hw(dev); | ||
| 565 | |||
| 566 | status = status ? status : dev->result; | ||
| 567 | } | ||
| 568 | |||
| 569 | return status; | ||
| 570 | } | ||
| 571 | |||
| 572 | /** | ||
| 511 | * nmk_i2c_xfer() - I2C transfer function used by kernel framework | 573 | * nmk_i2c_xfer() - I2C transfer function used by kernel framework |
| 512 | * @i2c_adap: Adapter pointer to the controller | 574 | * @i2c_adap: Adapter pointer to the controller |
| 513 | * @msgs: Pointer to data to be written. | 575 | * @msgs: Pointer to data to be written. |
| @@ -559,53 +621,55 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
| 559 | { | 621 | { |
| 560 | int status; | 622 | int status; |
| 561 | int i; | 623 | int i; |
| 562 | u32 cause; | ||
| 563 | struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); | 624 | struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); |
| 625 | int j; | ||
| 626 | |||
| 627 | dev->busy = true; | ||
| 628 | |||
| 629 | if (dev->regulator) | ||
| 630 | regulator_enable(dev->regulator); | ||
| 631 | pm_runtime_get_sync(&dev->pdev->dev); | ||
| 632 | |||
| 633 | clk_enable(dev->clk); | ||
| 564 | 634 | ||
| 565 | status = init_hw(dev); | 635 | status = init_hw(dev); |
| 566 | if (status) | 636 | if (status) |
| 567 | return status; | 637 | goto out; |
| 568 | 638 | ||
| 569 | clk_enable(dev->clk); | 639 | /* Attempt three times to send the message queue */ |
| 640 | for (j = 0; j < 3; j++) { | ||
| 641 | /* setup the i2c controller */ | ||
| 642 | setup_i2c_controller(dev); | ||
| 570 | 643 | ||
| 571 | /* setup the i2c controller */ | 644 | for (i = 0; i < num_msgs; i++) { |
| 572 | setup_i2c_controller(dev); | 645 | if (unlikely(msgs[i].flags & I2C_M_TEN)) { |
| 646 | dev_err(&dev->pdev->dev, "10 bit addressing" | ||
| 647 | "not supported\n"); | ||
| 573 | 648 | ||
| 574 | for (i = 0; i < num_msgs; i++) { | 649 | status = -EINVAL; |
| 575 | if (unlikely(msgs[i].flags & I2C_M_TEN)) { | 650 | goto out; |
| 576 | dev_err(&dev->pdev->dev, "10 bit addressing" | 651 | } |
| 577 | "not supported\n"); | 652 | dev->cli.slave_adr = msgs[i].addr; |
| 578 | return -EINVAL; | 653 | dev->cli.buffer = msgs[i].buf; |
| 579 | } | 654 | dev->cli.count = msgs[i].len; |
| 580 | dev->cli.slave_adr = msgs[i].addr; | 655 | dev->stop = (i < (num_msgs - 1)) ? 0 : 1; |
| 581 | dev->cli.buffer = msgs[i].buf; | 656 | dev->result = 0; |
| 582 | dev->cli.count = msgs[i].len; | 657 | |
| 583 | dev->stop = (i < (num_msgs - 1)) ? 0 : 1; | 658 | status = nmk_i2c_xfer_one(dev, msgs[i].flags); |
| 584 | dev->result = 0; | 659 | if (status != 0) |
| 585 | 660 | break; | |
| 586 | if (msgs[i].flags & I2C_M_RD) { | ||
| 587 | /* it is a read operation */ | ||
| 588 | dev->cli.operation = I2C_READ; | ||
| 589 | status = read_i2c(dev); | ||
| 590 | } else { | ||
| 591 | /* write operation */ | ||
| 592 | dev->cli.operation = I2C_WRITE; | ||
| 593 | status = write_i2c(dev); | ||
| 594 | } | ||
| 595 | if (status || (dev->result)) { | ||
| 596 | /* get the abort cause */ | ||
| 597 | cause = (readl(dev->virtbase + I2C_SR) >> 4) & 0x7; | ||
| 598 | dev_err(&dev->pdev->dev, "error during I2C" | ||
| 599 | "message xfer: %d\n", cause); | ||
| 600 | dev_err(&dev->pdev->dev, "%s\n", | ||
| 601 | cause >= ARRAY_SIZE(abort_causes) | ||
| 602 | ? "unknown reason" : abort_causes[cause]); | ||
| 603 | clk_disable(dev->clk); | ||
| 604 | return status; | ||
| 605 | } | 661 | } |
| 606 | udelay(I2C_DELAY); | 662 | if (status == 0) |
| 663 | break; | ||
| 607 | } | 664 | } |
| 665 | |||
| 666 | out: | ||
| 608 | clk_disable(dev->clk); | 667 | clk_disable(dev->clk); |
| 668 | pm_runtime_put_sync(&dev->pdev->dev); | ||
| 669 | if (dev->regulator) | ||
| 670 | regulator_disable(dev->regulator); | ||
| 671 | |||
| 672 | dev->busy = false; | ||
| 609 | 673 | ||
| 610 | /* return the no. messages processed */ | 674 | /* return the no. messages processed */ |
| 611 | if (status) | 675 | if (status) |
| @@ -666,17 +730,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 666 | */ | 730 | */ |
| 667 | disable_interrupts(dev, I2C_IT_TXFNE); | 731 | disable_interrupts(dev, I2C_IT_TXFNE); |
| 668 | } else { | 732 | } else { |
| 669 | for (count = (MAX_I2C_FIFO_THRESHOLD - tft - 2); | 733 | fill_tx_fifo(dev, (MAX_I2C_FIFO_THRESHOLD - tft)); |
| 670 | (count > 0) && | ||
| 671 | (dev->cli.count != 0); | ||
| 672 | count--) { | ||
| 673 | /* write to the Tx FIFO */ | ||
| 674 | writeb(*dev->cli.buffer, | ||
| 675 | dev->virtbase + I2C_TFR); | ||
| 676 | dev->cli.buffer++; | ||
| 677 | dev->cli.count--; | ||
| 678 | dev->cli.xfer_bytes++; | ||
| 679 | } | ||
| 680 | /* | 734 | /* |
| 681 | * if done, close the transfer by disabling the | 735 | * if done, close the transfer by disabling the |
| 682 | * corresponding TXFNE interrupt | 736 | * corresponding TXFNE interrupt |
| @@ -729,16 +783,11 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 729 | } | 783 | } |
| 730 | } | 784 | } |
| 731 | 785 | ||
| 732 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTD); | 786 | disable_all_interrupts(dev); |
| 733 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTDWS); | 787 | clear_all_interrupts(dev); |
| 734 | |||
| 735 | disable_interrupts(dev, | ||
| 736 | (I2C_IT_TXFNE | I2C_IT_TXFE | I2C_IT_TXFF | ||
| 737 | | I2C_IT_TXFOVR | I2C_IT_RXFNF | ||
| 738 | | I2C_IT_RXFF | I2C_IT_RXFE)); | ||
| 739 | 788 | ||
| 740 | if (dev->cli.count) { | 789 | if (dev->cli.count) { |
| 741 | dev->result = -1; | 790 | dev->result = -EIO; |
| 742 | dev_err(&dev->pdev->dev, "%lu bytes still remain to be" | 791 | dev_err(&dev->pdev->dev, "%lu bytes still remain to be" |
| 743 | "xfered\n", dev->cli.count); | 792 | "xfered\n", dev->cli.count); |
| 744 | (void) init_hw(dev); | 793 | (void) init_hw(dev); |
| @@ -749,7 +798,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 749 | 798 | ||
| 750 | /* Master Arbitration lost interrupt */ | 799 | /* Master Arbitration lost interrupt */ |
| 751 | case I2C_IT_MAL: | 800 | case I2C_IT_MAL: |
| 752 | dev->result = -1; | 801 | dev->result = -EIO; |
| 753 | (void) init_hw(dev); | 802 | (void) init_hw(dev); |
| 754 | 803 | ||
| 755 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL); | 804 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL); |
| @@ -763,7 +812,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 763 | * during the transaction. | 812 | * during the transaction. |
| 764 | */ | 813 | */ |
| 765 | case I2C_IT_BERR: | 814 | case I2C_IT_BERR: |
| 766 | dev->result = -1; | 815 | dev->result = -EIO; |
| 767 | /* get the status */ | 816 | /* get the status */ |
| 768 | if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT) | 817 | if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT) |
| 769 | (void) init_hw(dev); | 818 | (void) init_hw(dev); |
| @@ -779,7 +828,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 779 | * the Tx FIFO is full. | 828 | * the Tx FIFO is full. |
| 780 | */ | 829 | */ |
| 781 | case I2C_IT_TXFOVR: | 830 | case I2C_IT_TXFOVR: |
| 782 | dev->result = -1; | 831 | dev->result = -EIO; |
| 783 | (void) init_hw(dev); | 832 | (void) init_hw(dev); |
| 784 | 833 | ||
| 785 | dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); | 834 | dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); |
| @@ -805,6 +854,38 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 805 | return IRQ_HANDLED; | 854 | return IRQ_HANDLED; |
| 806 | } | 855 | } |
| 807 | 856 | ||
| 857 | |||
| 858 | #ifdef CONFIG_PM | ||
| 859 | static int nmk_i2c_suspend(struct device *dev) | ||
| 860 | { | ||
| 861 | struct platform_device *pdev = to_platform_device(dev); | ||
| 862 | struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev); | ||
| 863 | |||
| 864 | if (nmk_i2c->busy) | ||
| 865 | return -EBUSY; | ||
| 866 | |||
| 867 | return 0; | ||
| 868 | } | ||
| 869 | |||
| 870 | static int nmk_i2c_resume(struct device *dev) | ||
| 871 | { | ||
| 872 | return 0; | ||
| 873 | } | ||
| 874 | #else | ||
| 875 | #define nmk_i2c_suspend NULL | ||
| 876 | #define nmk_i2c_resume NULL | ||
| 877 | #endif | ||
| 878 | |||
| 879 | /* | ||
| 880 | * We use noirq so that we suspend late and resume before the wakeup interrupt | ||
| 881 | * to ensure that we do the !pm_runtime_suspended() check in resume before | ||
| 882 | * there has been a regular pm runtime resume (via pm_runtime_get_sync()). | ||
| 883 | */ | ||
| 884 | static const struct dev_pm_ops nmk_i2c_pm = { | ||
| 885 | .suspend_noirq = nmk_i2c_suspend, | ||
| 886 | .resume_noirq = nmk_i2c_resume, | ||
| 887 | }; | ||
| 888 | |||
| 808 | static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) | 889 | static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) |
| 809 | { | 890 | { |
| 810 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | 891 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
| @@ -830,7 +911,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 830 | ret = -ENOMEM; | 911 | ret = -ENOMEM; |
| 831 | goto err_no_mem; | 912 | goto err_no_mem; |
| 832 | } | 913 | } |
| 833 | 914 | dev->busy = false; | |
| 834 | dev->pdev = pdev; | 915 | dev->pdev = pdev; |
| 835 | platform_set_drvdata(pdev, dev); | 916 | platform_set_drvdata(pdev, dev); |
| 836 | 917 | ||
| @@ -860,6 +941,15 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 860 | goto err_irq; | 941 | goto err_irq; |
| 861 | } | 942 | } |
| 862 | 943 | ||
| 944 | dev->regulator = regulator_get(&pdev->dev, "v-i2c"); | ||
| 945 | if (IS_ERR(dev->regulator)) { | ||
| 946 | dev_warn(&pdev->dev, "could not get i2c regulator\n"); | ||
| 947 | dev->regulator = NULL; | ||
| 948 | } | ||
| 949 | |||
| 950 | pm_suspend_ignore_children(&pdev->dev, true); | ||
| 951 | pm_runtime_enable(&pdev->dev); | ||
| 952 | |||
| 863 | dev->clk = clk_get(&pdev->dev, NULL); | 953 | dev->clk = clk_get(&pdev->dev, NULL); |
| 864 | if (IS_ERR(dev->clk)) { | 954 | if (IS_ERR(dev->clk)) { |
| 865 | dev_err(&pdev->dev, "could not get i2c clock\n"); | 955 | dev_err(&pdev->dev, "could not get i2c clock\n"); |
| @@ -872,6 +962,8 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 872 | adap->owner = THIS_MODULE; | 962 | adap->owner = THIS_MODULE; |
| 873 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 963 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
| 874 | adap->algo = &nmk_i2c_algo; | 964 | adap->algo = &nmk_i2c_algo; |
| 965 | adap->timeout = pdata->timeout ? msecs_to_jiffies(pdata->timeout) : | ||
| 966 | msecs_to_jiffies(20000); | ||
| 875 | snprintf(adap->name, sizeof(adap->name), | 967 | snprintf(adap->name, sizeof(adap->name), |
| 876 | "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); | 968 | "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); |
| 877 | 969 | ||
| @@ -887,12 +979,6 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 887 | 979 | ||
| 888 | i2c_set_adapdata(adap, dev); | 980 | i2c_set_adapdata(adap, dev); |
| 889 | 981 | ||
| 890 | ret = init_hw(dev); | ||
| 891 | if (ret != 0) { | ||
| 892 | dev_err(&pdev->dev, "error in initializing i2c hardware\n"); | ||
| 893 | goto err_init_hw; | ||
| 894 | } | ||
| 895 | |||
| 896 | dev_info(&pdev->dev, "initialize %s on virtual " | 982 | dev_info(&pdev->dev, "initialize %s on virtual " |
| 897 | "base %p\n", adap->name, dev->virtbase); | 983 | "base %p\n", adap->name, dev->virtbase); |
| 898 | 984 | ||
| @@ -904,10 +990,12 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 904 | 990 | ||
| 905 | return 0; | 991 | return 0; |
| 906 | 992 | ||
| 907 | err_init_hw: | ||
| 908 | err_add_adap: | 993 | err_add_adap: |
| 909 | clk_put(dev->clk); | 994 | clk_put(dev->clk); |
| 910 | err_no_clk: | 995 | err_no_clk: |
| 996 | if (dev->regulator) | ||
| 997 | regulator_put(dev->regulator); | ||
| 998 | pm_runtime_disable(&pdev->dev); | ||
| 911 | free_irq(dev->irq, dev); | 999 | free_irq(dev->irq, dev); |
| 912 | err_irq: | 1000 | err_irq: |
| 913 | iounmap(dev->virtbase); | 1001 | iounmap(dev->virtbase); |
| @@ -938,6 +1026,9 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev) | |||
| 938 | if (res) | 1026 | if (res) |
| 939 | release_mem_region(res->start, resource_size(res)); | 1027 | release_mem_region(res->start, resource_size(res)); |
| 940 | clk_put(dev->clk); | 1028 | clk_put(dev->clk); |
| 1029 | if (dev->regulator) | ||
| 1030 | regulator_put(dev->regulator); | ||
| 1031 | pm_runtime_disable(&pdev->dev); | ||
| 941 | platform_set_drvdata(pdev, NULL); | 1032 | platform_set_drvdata(pdev, NULL); |
| 942 | kfree(dev); | 1033 | kfree(dev); |
| 943 | 1034 | ||
| @@ -948,6 +1039,7 @@ static struct platform_driver nmk_i2c_driver = { | |||
| 948 | .driver = { | 1039 | .driver = { |
| 949 | .owner = THIS_MODULE, | 1040 | .owner = THIS_MODULE, |
| 950 | .name = DRIVER_NAME, | 1041 | .name = DRIVER_NAME, |
| 1042 | .pm = &nmk_i2c_pm, | ||
| 951 | }, | 1043 | }, |
| 952 | .probe = nmk_i2c_probe, | 1044 | .probe = nmk_i2c_probe, |
| 953 | .remove = __devexit_p(nmk_i2c_remove), | 1045 | .remove = __devexit_p(nmk_i2c_remove), |
