Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus/2640/i2c' of git://git.fluff.org/bjdooks/linux

* 'for-linus/2640/i2c' of git://git.fluff.org/bjdooks/linux: (21 commits)
mach-ux500: set proper I2C platform data from MOP500s
i2c-nomadik: break out single messsage transmission
i2c-nomadik: reset the hw after status check
i2c-nomadik: remove the unnecessary delay
i2c-nomadik: change the TX and RX threshold
i2c-nomadik: add code to retry on timeout failure
i2c-nomadik: use pm_runtime API
i2c-nomadik: print abort cause only on abort tag
i2c-nomadik: correct adapter timeout initialization
i2c-nomadik: remove the redundant error message
i2c-nomadik: corrrect returned error numbers
i2c-nomadik: fix speed enumerator
i2c-nomadik: make i2c timeout specific per i2c bus
i2c-nomadik: add regulator support
i2c: i2c-sh_mobile bus speed platform data V2
i2c: i2c-sh_mobile clock string removal
i2c-eg20t: Support new device ML7223 IOH
i2c: tegra: Add de-bounce cycles.
i2c: tegra: fix repeated start handling
i2c: tegra: recover from spurious interrupt storm
...

+263 -115
+8 -6
arch/arm/mach-ux500/board-mop500.c
··· 204 204 }, 205 205 }; 206 206 207 - #define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, _sm) \ 207 + #define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, t_out, _sm) \ 208 208 static struct nmk_i2c_controller u8500_i2c##id##_data = { \ 209 209 /* \ 210 210 * slave data setup time, which is \ ··· 219 219 .rft = _rft, \ 220 220 /* std. mode operation */ \ 221 221 .clk_freq = clk, \ 222 + /* Slave response timeout(ms) */\ 223 + .timeout = t_out, \ 222 224 .sm = _sm, \ 223 225 } 224 226 225 227 /* 226 228 * The board uses 4 i2c controllers, initialize all of 227 229 * them with slave data setup time of 250 ns, 228 - * Tx & Rx FIFO threshold values as 1 and standard 230 + * Tx & Rx FIFO threshold values as 8 and standard 229 231 * mode of operation 230 232 */ 231 - U8500_I2C_CONTROLLER(0, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 232 - U8500_I2C_CONTROLLER(1, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 233 - U8500_I2C_CONTROLLER(2, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 234 - U8500_I2C_CONTROLLER(3, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 233 + U8500_I2C_CONTROLLER(0, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST); 234 + U8500_I2C_CONTROLLER(1, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST); 235 + U8500_I2C_CONTROLLER(2, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST); 236 + U8500_I2C_CONTROLLER(3, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST); 235 237 236 238 static void __init mop500_i2c_init(void) 237 239 {
+5 -3
arch/arm/plat-nomadik/include/plat/i2c.h
··· 11 11 enum i2c_freq_mode { 12 12 I2C_FREQ_MODE_STANDARD, /* up to 100 Kb/s */ 13 13 I2C_FREQ_MODE_FAST, /* up to 400 Kb/s */ 14 + I2C_FREQ_MODE_HIGH_SPEED, /* up to 3.4 Mb/s */ 14 15 I2C_FREQ_MODE_FAST_PLUS, /* up to 1 Mb/s */ 15 - I2C_FREQ_MODE_HIGH_SPEED /* up to 3.4 Mb/s */ 16 16 }; 17 17 18 18 /** ··· 24 24 * to the values of 14, 6, 2 for a 48 MHz i2c clk 25 25 * @tft: Tx FIFO Threshold in bytes 26 26 * @rft: Rx FIFO Threshold in bytes 27 + * @timeout Slave response timeout(ms) 27 28 * @sm: speed mode 28 29 */ 29 30 struct nmk_i2c_controller { 30 31 unsigned long clk_freq; 31 32 unsigned short slsu; 32 - unsigned char tft; 33 - unsigned char rft; 33 + unsigned char tft; 34 + unsigned char rft; 35 + int timeout; 34 36 enum i2c_freq_mode sm; 35 37 }; 36 38
+7 -3
drivers/i2c/busses/Kconfig
··· 673 673 will be called xilinx_i2c. 674 674 675 675 config I2C_EG20T 676 - tristate "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH" 676 + tristate "Intel EG20T PCH / OKI SEMICONDUCTOR IOH(ML7213/ML7223)" 677 677 depends on PCI 678 678 help 679 679 This driver is for PCH(Platform controller Hub) I2C of EG20T which 680 680 is an IOH(Input/Output Hub) for x86 embedded processor. 681 681 This driver can access PCH I2C bus device. 682 682 683 - This driver also supports the ML7213, a companion chip for the 684 - Atom E6xx series and compatible with the Intel EG20T PCH. 683 + This driver also can be used for OKI SEMICONDUCTOR IOH(Input/ 684 + Output Hub), ML7213 and ML7223. 685 + ML7213 IOH is for IVI(In-Vehicle Infotainment) use and ML7223 IOH is 686 + for MP(Media Phone) use. 687 + ML7213/ML7223 is companion chip for Intel Atom E6xx series. 688 + ML7213/ML7223 is completely compatible for Intel EG20T PCH. 685 689 686 690 comment "External I2C/SMBus adapter drivers" 687 691
+2
drivers/i2c/busses/i2c-eg20t.c
··· 182 182 /* Definition for ML7213 by OKI SEMICONDUCTOR */ 183 183 #define PCI_VENDOR_ID_ROHM 0x10DB 184 184 #define PCI_DEVICE_ID_ML7213_I2C 0x802D 185 + #define PCI_DEVICE_ID_ML7223_I2C 0x8010 185 186 186 187 static struct pci_device_id __devinitdata pch_pcidev_id[] = { 187 188 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, }, 188 189 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, }, 190 + { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, }, 189 191 {0,} 190 192 }; 191 193
+184 -92
drivers/i2c/busses/i2c-nomadik.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/module.h> 17 17 #include <linux/platform_device.h> 18 - #include <linux/delay.h> 19 18 #include <linux/slab.h> 20 19 #include <linux/interrupt.h> 21 20 #include <linux/i2c.h> 22 21 #include <linux/err.h> 23 22 #include <linux/clk.h> 24 23 #include <linux/io.h> 24 + #include <linux/regulator/consumer.h> 25 + #include <linux/pm_runtime.h> 25 26 26 27 #include <plat/i2c.h> 27 28 ··· 104 103 /* maximum threshold value */ 105 104 #define MAX_I2C_FIFO_THRESHOLD 15 106 105 107 - /* per-transfer delay, required for the hardware to stabilize */ 108 - #define I2C_DELAY 150 109 - 110 106 enum i2c_status { 111 107 I2C_NOP, 112 108 I2C_ON_GOING, ··· 117 119 I2C_WRITE = 0x00, 118 120 I2C_READ = 0x01 119 121 }; 120 - 121 - /* controller response timeout in ms */ 122 - #define I2C_TIMEOUT_MS 2000 123 122 124 123 /** 125 124 * struct i2c_nmk_client - client specific data ··· 146 151 * @stop: stop condition 147 152 * @xfer_complete: acknowledge completion for a I2C message 148 153 * @result: controller propogated result 154 + * @busy: Busy doing transfer 149 155 */ 150 156 struct nmk_i2c_dev { 151 157 struct platform_device *pdev; ··· 159 163 int stop; 160 164 struct completion xfer_complete; 161 165 int result; 166 + struct regulator *regulator; 167 + bool busy; 162 168 }; 163 169 164 170 /* controller's abort causes */ ··· 207 209 writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR); 208 210 209 211 for (i = 0; i < LOOP_ATTEMPTS; i++) { 210 - timeout = jiffies + msecs_to_jiffies(I2C_TIMEOUT_MS); 212 + timeout = jiffies + dev->adap.timeout; 211 213 212 214 while (!time_after(jiffies, timeout)) { 213 215 if ((readl(dev->virtbase + I2C_CR) & ··· 251 253 { 252 254 int stat; 253 255 254 - clk_enable(dev->clk); 255 - 256 256 stat = flush_i2c_fifo(dev); 257 257 if (stat) 258 - return stat; 258 + goto exit; 259 259 260 260 /* disable the controller */ 261 261 i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE); ··· 264 268 265 269 dev->cli.operation = I2C_NO_OPERATION; 266 270 267 - clk_disable(dev->clk); 268 - 269 - udelay(I2C_DELAY); 270 - return 0; 271 + exit: 272 + return stat; 271 273 } 272 274 273 275 /* enable peripheral, master mode operation */ ··· 418 424 dev->virtbase + I2C_IMSCR); 419 425 420 426 timeout = wait_for_completion_interruptible_timeout( 421 - &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); 427 + &dev->xfer_complete, dev->adap.timeout); 422 428 423 429 if (timeout < 0) { 424 430 dev_err(&dev->pdev->dev, ··· 428 434 } 429 435 430 436 if (timeout == 0) { 431 - /* controller has timedout, re-init the h/w */ 432 - dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); 433 - (void) init_hw(dev); 437 + /* Controller timed out */ 438 + dev_err(&dev->pdev->dev, "read from slave 0x%x timed out\n", 439 + dev->cli.slave_adr); 434 440 status = -ETIMEDOUT; 435 441 } 436 442 return status; 443 + } 444 + 445 + static void fill_tx_fifo(struct nmk_i2c_dev *dev, int no_bytes) 446 + { 447 + int count; 448 + 449 + for (count = (no_bytes - 2); 450 + (count > 0) && 451 + (dev->cli.count != 0); 452 + count--) { 453 + /* write to the Tx FIFO */ 454 + writeb(*dev->cli.buffer, 455 + dev->virtbase + I2C_TFR); 456 + dev->cli.buffer++; 457 + dev->cli.count--; 458 + dev->cli.xfer_bytes++; 459 + } 460 + 437 461 } 438 462 439 463 /** ··· 481 469 init_completion(&dev->xfer_complete); 482 470 483 471 /* enable interrupts by settings the masks */ 484 - irq_mask = (I2C_IT_TXFNE | I2C_IT_TXFOVR | 485 - I2C_IT_MAL | I2C_IT_BERR); 472 + irq_mask = (I2C_IT_TXFOVR | I2C_IT_MAL | I2C_IT_BERR); 473 + 474 + /* Fill the TX FIFO with transmit data */ 475 + fill_tx_fifo(dev, MAX_I2C_FIFO_THRESHOLD); 476 + 477 + if (dev->cli.count != 0) 478 + irq_mask |= I2C_IT_TXFNE; 486 479 487 480 /* 488 481 * check if we want to transfer a single or multiple bytes, if so ··· 505 488 dev->virtbase + I2C_IMSCR); 506 489 507 490 timeout = wait_for_completion_interruptible_timeout( 508 - &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); 491 + &dev->xfer_complete, dev->adap.timeout); 509 492 510 493 if (timeout < 0) { 511 494 dev_err(&dev->pdev->dev, ··· 515 498 } 516 499 517 500 if (timeout == 0) { 518 - /* controller has timedout, re-init the h/w */ 519 - dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); 520 - (void) init_hw(dev); 501 + /* Controller timed out */ 502 + dev_err(&dev->pdev->dev, "write to slave 0x%x timed out\n", 503 + dev->cli.slave_adr); 521 504 status = -ETIMEDOUT; 505 + } 506 + 507 + return status; 508 + } 509 + 510 + /** 511 + * nmk_i2c_xfer_one() - transmit a single I2C message 512 + * @dev: device with a message encoded into it 513 + * @flags: message flags 514 + */ 515 + static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) 516 + { 517 + int status; 518 + 519 + if (flags & I2C_M_RD) { 520 + /* read operation */ 521 + dev->cli.operation = I2C_READ; 522 + status = read_i2c(dev); 523 + } else { 524 + /* write operation */ 525 + dev->cli.operation = I2C_WRITE; 526 + status = write_i2c(dev); 527 + } 528 + 529 + if (status || (dev->result)) { 530 + u32 i2c_sr; 531 + u32 cause; 532 + 533 + i2c_sr = readl(dev->virtbase + I2C_SR); 534 + /* 535 + * Check if the controller I2C operation status 536 + * is set to ABORT(11b). 537 + */ 538 + if (((i2c_sr >> 2) & 0x3) == 0x3) { 539 + /* get the abort cause */ 540 + cause = (i2c_sr >> 4) & 0x7; 541 + dev_err(&dev->pdev->dev, "%s\n", cause 542 + >= ARRAY_SIZE(abort_causes) ? 543 + "unknown reason" : 544 + abort_causes[cause]); 545 + } 546 + 547 + (void) init_hw(dev); 548 + 549 + status = status ? status : dev->result; 522 550 } 523 551 524 552 return status; ··· 621 559 { 622 560 int status; 623 561 int i; 624 - u32 cause; 625 562 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); 563 + int j; 626 564 627 - status = init_hw(dev); 628 - if (status) 629 - return status; 565 + dev->busy = true; 566 + 567 + if (dev->regulator) 568 + regulator_enable(dev->regulator); 569 + pm_runtime_get_sync(&dev->pdev->dev); 630 570 631 571 clk_enable(dev->clk); 632 572 633 - /* setup the i2c controller */ 634 - setup_i2c_controller(dev); 573 + status = init_hw(dev); 574 + if (status) 575 + goto out; 635 576 636 - for (i = 0; i < num_msgs; i++) { 637 - if (unlikely(msgs[i].flags & I2C_M_TEN)) { 638 - dev_err(&dev->pdev->dev, "10 bit addressing" 639 - "not supported\n"); 640 - return -EINVAL; 641 - } 642 - dev->cli.slave_adr = msgs[i].addr; 643 - dev->cli.buffer = msgs[i].buf; 644 - dev->cli.count = msgs[i].len; 645 - dev->stop = (i < (num_msgs - 1)) ? 0 : 1; 646 - dev->result = 0; 577 + /* Attempt three times to send the message queue */ 578 + for (j = 0; j < 3; j++) { 579 + /* setup the i2c controller */ 580 + setup_i2c_controller(dev); 647 581 648 - if (msgs[i].flags & I2C_M_RD) { 649 - /* it is a read operation */ 650 - dev->cli.operation = I2C_READ; 651 - status = read_i2c(dev); 652 - } else { 653 - /* write operation */ 654 - dev->cli.operation = I2C_WRITE; 655 - status = write_i2c(dev); 582 + for (i = 0; i < num_msgs; i++) { 583 + if (unlikely(msgs[i].flags & I2C_M_TEN)) { 584 + dev_err(&dev->pdev->dev, "10 bit addressing" 585 + "not supported\n"); 586 + 587 + status = -EINVAL; 588 + goto out; 589 + } 590 + dev->cli.slave_adr = msgs[i].addr; 591 + dev->cli.buffer = msgs[i].buf; 592 + dev->cli.count = msgs[i].len; 593 + dev->stop = (i < (num_msgs - 1)) ? 0 : 1; 594 + dev->result = 0; 595 + 596 + status = nmk_i2c_xfer_one(dev, msgs[i].flags); 597 + if (status != 0) 598 + break; 656 599 } 657 - if (status || (dev->result)) { 658 - /* get the abort cause */ 659 - cause = (readl(dev->virtbase + I2C_SR) >> 4) & 0x7; 660 - dev_err(&dev->pdev->dev, "error during I2C" 661 - "message xfer: %d\n", cause); 662 - dev_err(&dev->pdev->dev, "%s\n", 663 - cause >= ARRAY_SIZE(abort_causes) 664 - ? "unknown reason" : abort_causes[cause]); 665 - clk_disable(dev->clk); 666 - return status; 667 - } 668 - udelay(I2C_DELAY); 600 + if (status == 0) 601 + break; 669 602 } 603 + 604 + out: 670 605 clk_disable(dev->clk); 606 + pm_runtime_put_sync(&dev->pdev->dev); 607 + if (dev->regulator) 608 + regulator_disable(dev->regulator); 609 + 610 + dev->busy = false; 671 611 672 612 /* return the no. messages processed */ 673 613 if (status) ··· 730 666 */ 731 667 disable_interrupts(dev, I2C_IT_TXFNE); 732 668 } else { 733 - for (count = (MAX_I2C_FIFO_THRESHOLD - tft - 2); 734 - (count > 0) && 735 - (dev->cli.count != 0); 736 - count--) { 737 - /* write to the Tx FIFO */ 738 - writeb(*dev->cli.buffer, 739 - dev->virtbase + I2C_TFR); 740 - dev->cli.buffer++; 741 - dev->cli.count--; 742 - dev->cli.xfer_bytes++; 743 - } 669 + fill_tx_fifo(dev, (MAX_I2C_FIFO_THRESHOLD - tft)); 744 670 /* 745 671 * if done, close the transfer by disabling the 746 672 * corresponding TXFNE interrupt ··· 783 729 } 784 730 } 785 731 786 - i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTD); 787 - i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTDWS); 788 - 789 - disable_interrupts(dev, 790 - (I2C_IT_TXFNE | I2C_IT_TXFE | I2C_IT_TXFF 791 - | I2C_IT_TXFOVR | I2C_IT_RXFNF 792 - | I2C_IT_RXFF | I2C_IT_RXFE)); 732 + disable_all_interrupts(dev); 733 + clear_all_interrupts(dev); 793 734 794 735 if (dev->cli.count) { 795 - dev->result = -1; 736 + dev->result = -EIO; 796 737 dev_err(&dev->pdev->dev, "%lu bytes still remain to be" 797 738 "xfered\n", dev->cli.count); 798 739 (void) init_hw(dev); ··· 798 749 799 750 /* Master Arbitration lost interrupt */ 800 751 case I2C_IT_MAL: 801 - dev->result = -1; 752 + dev->result = -EIO; 802 753 (void) init_hw(dev); 803 754 804 755 i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL); ··· 812 763 * during the transaction. 813 764 */ 814 765 case I2C_IT_BERR: 815 - dev->result = -1; 766 + dev->result = -EIO; 816 767 /* get the status */ 817 768 if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT) 818 769 (void) init_hw(dev); ··· 828 779 * the Tx FIFO is full. 829 780 */ 830 781 case I2C_IT_TXFOVR: 831 - dev->result = -1; 782 + dev->result = -EIO; 832 783 (void) init_hw(dev); 833 784 834 785 dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); ··· 853 804 854 805 return IRQ_HANDLED; 855 806 } 807 + 808 + 809 + #ifdef CONFIG_PM 810 + static int nmk_i2c_suspend(struct device *dev) 811 + { 812 + struct platform_device *pdev = to_platform_device(dev); 813 + struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev); 814 + 815 + if (nmk_i2c->busy) 816 + return -EBUSY; 817 + 818 + return 0; 819 + } 820 + 821 + static int nmk_i2c_resume(struct device *dev) 822 + { 823 + return 0; 824 + } 825 + #else 826 + #define nmk_i2c_suspend NULL 827 + #define nmk_i2c_resume NULL 828 + #endif 829 + 830 + /* 831 + * We use noirq so that we suspend late and resume before the wakeup interrupt 832 + * to ensure that we do the !pm_runtime_suspended() check in resume before 833 + * there has been a regular pm runtime resume (via pm_runtime_get_sync()). 834 + */ 835 + static const struct dev_pm_ops nmk_i2c_pm = { 836 + .suspend_noirq = nmk_i2c_suspend, 837 + .resume_noirq = nmk_i2c_resume, 838 + }; 856 839 857 840 static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) 858 841 { ··· 911 830 ret = -ENOMEM; 912 831 goto err_no_mem; 913 832 } 914 - 833 + dev->busy = false; 915 834 dev->pdev = pdev; 916 835 platform_set_drvdata(pdev, dev); 917 836 ··· 941 860 goto err_irq; 942 861 } 943 862 863 + dev->regulator = regulator_get(&pdev->dev, "v-i2c"); 864 + if (IS_ERR(dev->regulator)) { 865 + dev_warn(&pdev->dev, "could not get i2c regulator\n"); 866 + dev->regulator = NULL; 867 + } 868 + 869 + pm_suspend_ignore_children(&pdev->dev, true); 870 + pm_runtime_enable(&pdev->dev); 871 + 944 872 dev->clk = clk_get(&pdev->dev, NULL); 945 873 if (IS_ERR(dev->clk)) { 946 874 dev_err(&pdev->dev, "could not get i2c clock\n"); ··· 962 872 adap->owner = THIS_MODULE; 963 873 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 964 874 adap->algo = &nmk_i2c_algo; 875 + adap->timeout = pdata->timeout ? msecs_to_jiffies(pdata->timeout) : 876 + msecs_to_jiffies(20000); 965 877 snprintf(adap->name, sizeof(adap->name), 966 878 "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); 967 879 ··· 979 887 980 888 i2c_set_adapdata(adap, dev); 981 889 982 - ret = init_hw(dev); 983 - if (ret != 0) { 984 - dev_err(&pdev->dev, "error in initializing i2c hardware\n"); 985 - goto err_init_hw; 986 - } 987 - 988 890 dev_info(&pdev->dev, "initialize %s on virtual " 989 891 "base %p\n", adap->name, dev->virtbase); 990 892 ··· 990 904 991 905 return 0; 992 906 993 - err_init_hw: 994 907 err_add_adap: 995 908 clk_put(dev->clk); 996 909 err_no_clk: 910 + if (dev->regulator) 911 + regulator_put(dev->regulator); 912 + pm_runtime_disable(&pdev->dev); 997 913 free_irq(dev->irq, dev); 998 914 err_irq: 999 915 iounmap(dev->virtbase); ··· 1026 938 if (res) 1027 939 release_mem_region(res->start, resource_size(res)); 1028 940 clk_put(dev->clk); 941 + if (dev->regulator) 942 + regulator_put(dev->regulator); 943 + pm_runtime_disable(&pdev->dev); 1029 944 platform_set_drvdata(pdev, NULL); 1030 945 kfree(dev); 1031 946 ··· 1039 948 .driver = { 1040 949 .owner = THIS_MODULE, 1041 950 .name = DRIVER_NAME, 951 + .pm = &nmk_i2c_pm, 1042 952 }, 1043 953 .probe = nmk_i2c_probe, 1044 954 .remove = __devexit_p(nmk_i2c_remove),
+13 -6
drivers/i2c/busses/i2c-sh_mobile.c
··· 32 32 #include <linux/clk.h> 33 33 #include <linux/io.h> 34 34 #include <linux/slab.h> 35 + #include <linux/i2c/i2c-sh_mobile.h> 35 36 36 37 /* Transmit operation: */ 37 38 /* */ ··· 118 117 struct device *dev; 119 118 void __iomem *reg; 120 119 struct i2c_adapter adap; 121 - 120 + unsigned long bus_speed; 122 121 struct clk *clk; 123 122 u_int8_t icic; 124 123 u_int8_t iccl; ··· 206 205 * We also round off the result. 207 206 */ 208 207 num = i2c_clk * 5; 209 - denom = NORMAL_SPEED * 9; 208 + denom = pd->bus_speed * 9; 210 209 tmp = num * 10 / denom; 211 210 if (tmp % 10 >= 5) 212 211 pd->iccl = (u_int8_t)((num/denom) + 1); ··· 575 574 576 575 static int sh_mobile_i2c_probe(struct platform_device *dev) 577 576 { 577 + struct i2c_sh_mobile_platform_data *pdata = dev->dev.platform_data; 578 578 struct sh_mobile_i2c_data *pd; 579 579 struct i2c_adapter *adap; 580 580 struct resource *res; 581 - char clk_name[8]; 582 581 int size; 583 582 int ret; 584 583 ··· 588 587 return -ENOMEM; 589 588 } 590 589 591 - snprintf(clk_name, sizeof(clk_name), "i2c%d", dev->id); 592 - pd->clk = clk_get(&dev->dev, clk_name); 590 + pd->clk = clk_get(&dev->dev, NULL); 593 591 if (IS_ERR(pd->clk)) { 594 - dev_err(&dev->dev, "cannot get clock \"%s\"\n", clk_name); 592 + dev_err(&dev->dev, "cannot get clock\n"); 595 593 ret = PTR_ERR(pd->clk); 596 594 goto err; 597 595 } ··· 619 619 ret = -ENXIO; 620 620 goto err_irq; 621 621 } 622 + 623 + /* Use platformd data bus speed or NORMAL_SPEED */ 624 + pd->bus_speed = NORMAL_SPEED; 625 + if (pdata && pdata->bus_speed) 626 + pd->bus_speed = pdata->bus_speed; 622 627 623 628 /* The IIC blocks on SH-Mobile ARM processors 624 629 * come with two new bits in ICIC. ··· 665 660 goto err_all; 666 661 } 667 662 663 + dev_info(&dev->dev, "I2C adapter %d with bus speed %lu Hz\n", 664 + adap->nr, pd->bus_speed); 668 665 return 0; 669 666 670 667 err_all:
+34 -5
drivers/i2c/busses/i2c-tegra.c
··· 35 35 #define BYTES_PER_FIFO_WORD 4 36 36 37 37 #define I2C_CNFG 0x000 38 + #define I2C_CNFG_DEBOUNCE_CNT_SHIFT 12 38 39 #define I2C_CNFG_PACKET_MODE_EN (1<<10) 39 40 #define I2C_CNFG_NEW_MASTER_FSM (1<<11) 41 + #define I2C_STATUS 0x01C 40 42 #define I2C_SL_CNFG 0x020 41 43 #define I2C_SL_CNFG_NEWSL (1<<2) 42 44 #define I2C_SL_ADDR1 0x02c ··· 79 77 #define I2C_ERR_NONE 0x00 80 78 #define I2C_ERR_NO_ACK 0x01 81 79 #define I2C_ERR_ARBITRATION_LOST 0x02 80 + #define I2C_ERR_UNKNOWN_INTERRUPT 0x04 82 81 83 82 #define PACKET_HEADER0_HEADER_SIZE_SHIFT 28 84 83 #define PACKET_HEADER0_PACKET_ID_SHIFT 16 ··· 124 121 void __iomem *base; 125 122 int cont_id; 126 123 int irq; 124 + bool irq_disabled; 127 125 int is_dvc; 128 126 struct completion msg_complete; 129 127 int msg_err; ··· 329 325 if (i2c_dev->is_dvc) 330 326 tegra_dvc_init(i2c_dev); 331 327 332 - val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN; 328 + val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN | 329 + (0x2 << I2C_CNFG_DEBOUNCE_CNT_SHIFT); 333 330 i2c_writel(i2c_dev, val, I2C_CNFG); 334 331 i2c_writel(i2c_dev, 0, I2C_INT_MASK); 335 332 clk_set_rate(i2c_dev->clk, i2c_dev->bus_clk_rate * 8); 333 + 334 + if (!i2c_dev->is_dvc) { 335 + u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG); 336 + i2c_writel(i2c_dev, sl_cfg | I2C_SL_CNFG_NEWSL, I2C_SL_CNFG); 337 + } 336 338 337 339 val = 7 << I2C_FIFO_CONTROL_TX_TRIG_SHIFT | 338 340 0 << I2C_FIFO_CONTROL_RX_TRIG_SHIFT; ··· 348 338 err = -ETIMEDOUT; 349 339 350 340 clk_disable(i2c_dev->clk); 341 + 342 + if (i2c_dev->irq_disabled) { 343 + i2c_dev->irq_disabled = 0; 344 + enable_irq(i2c_dev->irq); 345 + } 346 + 351 347 return err; 352 348 } 353 349 ··· 366 350 status = i2c_readl(i2c_dev, I2C_INT_STATUS); 367 351 368 352 if (status == 0) { 369 - dev_warn(i2c_dev->dev, "interrupt with no status\n"); 370 - return IRQ_NONE; 353 + dev_warn(i2c_dev->dev, "irq status 0 %08x %08x %08x\n", 354 + i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS), 355 + i2c_readl(i2c_dev, I2C_STATUS), 356 + i2c_readl(i2c_dev, I2C_CNFG)); 357 + i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT; 358 + 359 + if (!i2c_dev->irq_disabled) { 360 + disable_irq_nosync(i2c_dev->irq); 361 + i2c_dev->irq_disabled = 1; 362 + } 363 + 364 + complete(&i2c_dev->msg_complete); 365 + goto err; 371 366 } 372 367 373 368 if (unlikely(status & status_err)) { ··· 418 391 I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | 419 392 I2C_INT_RX_FIFO_DATA_REQ); 420 393 i2c_writel(i2c_dev, status, I2C_INT_STATUS); 394 + if (i2c_dev->is_dvc) 395 + dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); 421 396 return IRQ_HANDLED; 422 397 } 423 398 ··· 453 424 454 425 packet_header = msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; 455 426 packet_header |= I2C_HEADER_IE_ENABLE; 427 + if (!stop) 428 + packet_header |= I2C_HEADER_REPEAT_START; 456 429 if (msg->flags & I2C_M_TEN) 457 430 packet_header |= I2C_HEADER_10BIT_ADDR; 458 431 if (msg->flags & I2C_M_IGNORE_NAK) 459 432 packet_header |= I2C_HEADER_CONT_ON_NAK; 460 - if (msg->flags & I2C_M_NOSTART) 461 - packet_header |= I2C_HEADER_REPEAT_START; 462 433 if (msg->flags & I2C_M_RD) 463 434 packet_header |= I2C_HEADER_READ; 464 435 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
+10
include/linux/i2c/i2c-sh_mobile.h
··· 1 + #ifndef __I2C_SH_MOBILE_H__ 2 + #define __I2C_SH_MOBILE_H__ 3 + 4 + #include <linux/platform_device.h> 5 + 6 + struct i2c_sh_mobile_platform_data { 7 + unsigned long bus_speed; 8 + }; 9 + 10 + #endif /* __I2C_SH_MOBILE_H__ */