Merge branch 'i2c-for-ben' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6 into i2c-next

Ben Dooks 5a93f420 1bda7128

+334 -98
+2 -2
arch/arm/mach-omap2/clock24xx.h
··· 2321 }; 2322 2323 static struct clk i2chs2_fck = { 2324 - .name = "i2chs_fck", 2325 .id = 2, 2326 .parent = &func_96m_ck, 2327 .flags = CLOCK_IN_OMAP243X, ··· 2354 }; 2355 2356 static struct clk i2chs1_fck = { 2357 - .name = "i2chs_fck", 2358 .id = 1, 2359 .parent = &func_96m_ck, 2360 .flags = CLOCK_IN_OMAP243X,
··· 2321 }; 2322 2323 static struct clk i2chs2_fck = { 2324 + .name = "i2c_fck", 2325 .id = 2, 2326 .parent = &func_96m_ck, 2327 .flags = CLOCK_IN_OMAP243X, ··· 2354 }; 2355 2356 static struct clk i2chs1_fck = { 2357 + .name = "i2c_fck", 2358 .id = 1, 2359 .parent = &func_96m_ck, 2360 .flags = CLOCK_IN_OMAP243X,
+332 -96
drivers/i2c/busses/i2c-omap.c
··· 2 * TI OMAP I2C master mode driver 3 * 4 * Copyright (C) 2003 MontaVista Software, Inc. 5 - * Copyright (C) 2004 Texas Instruments. 6 - * 7 - * Updated to work with multiple I2C interfaces on 24xx by 8 - * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com> 9 * Copyright (C) 2005 Nokia Corporation 10 * 11 - * Cleaned up by Juha Yrjölä <juha.yrjola@nokia.com> 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by ··· 36 #include <linux/completion.h> 37 #include <linux/platform_device.h> 38 #include <linux/clk.h> 39 40 - #include <asm/io.h> 41 42 /* timeout waiting for the controller to respond */ 43 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) ··· 52 #define OMAP_I2C_IE_REG 0x04 53 #define OMAP_I2C_STAT_REG 0x08 54 #define OMAP_I2C_IV_REG 0x0c 55 #define OMAP_I2C_SYSS_REG 0x10 56 #define OMAP_I2C_BUF_REG 0x14 57 #define OMAP_I2C_CNT_REG 0x18 ··· 66 #define OMAP_I2C_SCLL_REG 0x34 67 #define OMAP_I2C_SCLH_REG 0x38 68 #define OMAP_I2C_SYSTEST_REG 0x3c 69 70 /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ 71 #define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */ 72 #define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */ 73 #define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */ ··· 78 #define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */ 79 80 /* I2C Status Register (OMAP_I2C_STAT): */ 81 - #define OMAP_I2C_STAT_SBD (1 << 15) /* Single byte data */ 82 #define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */ 83 #define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */ 84 #define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */ ··· 91 #define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */ 92 #define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */ 93 94 /* I2C Buffer Configuration Register (OMAP_I2C_BUF): */ 95 #define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */ 96 #define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */ 97 98 /* I2C Configuration Register (OMAP_I2C_CON): */ 99 #define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */ 100 #define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */ 101 #define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */ 102 #define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */ 103 #define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */ ··· 126 #define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */ 127 #define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */ 128 #define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */ 129 130 /* I2C System Test Register (OMAP_I2C_SYSTEST): */ 131 #ifdef DEBUG ··· 143 #define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */ 144 #endif 145 146 - /* I2C System Status register (OMAP_I2C_SYSS): */ 147 - #define OMAP_I2C_SYSS_RDONE (1 << 0) /* Reset Done */ 148 149 - /* I2C System Configuration Register (OMAP_I2C_SYSC): */ 150 - #define OMAP_I2C_SYSC_SRST (1 << 1) /* Soft Reset */ 151 152 - /* REVISIT: Use platform_data instead of module parameters */ 153 - /* Fast Mode = 400 kHz, Standard = 100 kHz */ 154 - static int clock = 100; /* Default: 100 kHz */ 155 - module_param(clock, int, 0); 156 - MODULE_PARM_DESC(clock, "Set I2C clock in kHz: 400=fast mode (default == 100)"); 157 158 struct omap_i2c_dev { 159 struct device *dev; ··· 165 struct clk *fclk; /* Functional clock */ 166 struct completion cmd_complete; 167 struct resource *ioarea; 168 u16 cmd_err; 169 u8 *buf; 170 size_t buf_len; 171 struct i2c_adapter adapter; 172 - unsigned rev1:1; 173 unsigned idle:1; 174 u16 iestate; /* Saved interrupt register */ 175 }; ··· 191 return __raw_readw(i2c_dev->base + reg); 192 } 193 194 - static int omap_i2c_get_clocks(struct omap_i2c_dev *dev) 195 { 196 - if (cpu_is_omap16xx() || cpu_is_omap24xx()) { 197 dev->iclk = clk_get(dev->dev, "i2c_ick"); 198 if (IS_ERR(dev->iclk)) { 199 dev->iclk = NULL; ··· 226 227 static void omap_i2c_unidle(struct omap_i2c_dev *dev) 228 { 229 if (dev->iclk != NULL) 230 clk_enable(dev->iclk); 231 clk_enable(dev->fclk); 232 if (dev->iestate) 233 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); 234 - dev->idle = 0; 235 } 236 237 static void omap_i2c_idle(struct omap_i2c_dev *dev) 238 { 239 u16 iv; 240 241 - dev->idle = 1; 242 dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 243 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); 244 - if (dev->rev1) 245 - iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ 246 - else 247 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate); 248 clk_disable(dev->fclk); 249 if (dev->iclk != NULL) 250 clk_disable(dev->iclk); ··· 260 261 static int omap_i2c_init(struct omap_i2c_dev *dev) 262 { 263 - u16 psc = 0; 264 unsigned long fclk_rate = 12000000; 265 unsigned long timeout; 266 267 - if (!dev->rev1) { 268 - omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST); 269 /* For some reason we need to set the EN bit before the 270 * reset done bit gets set. */ 271 timeout = jiffies + OMAP_I2C_TIMEOUT; 272 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 273 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) & 274 - OMAP_I2C_SYSS_RDONE)) { 275 if (time_after(jiffies, timeout)) { 276 dev_warn(dev->dev, "timeout waiting " 277 "for controller reset\n"); 278 return -ETIMEDOUT; 279 } 280 msleep(1); 281 } 282 } 283 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); ··· 334 psc = fclk_rate / 12000000; 335 } 336 337 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 338 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc); 339 340 - /* Program desired operating rate */ 341 - fclk_rate /= (psc + 1) * 1000; 342 - if (psc > 2) 343 - psc = 2; 344 345 - omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, 346 - fclk_rate / (clock * 2) - 7 + psc); 347 - omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, 348 - fclk_rate / (clock * 2) - 7 + psc); 349 350 /* Take the I2C module out of reset: */ 351 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 352 353 /* Enable interrupts */ 354 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 355 - (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 356 - OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 357 - OMAP_I2C_IE_AL)); 358 return 0; 359 } 360 ··· 439 440 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len); 441 442 init_completion(&dev->cmd_complete); 443 dev->cmd_err = 0; 444 445 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT; 446 if (msg->flags & I2C_M_TEN) 447 w |= OMAP_I2C_CON_XA; 448 if (!(msg->flags & I2C_M_RD)) 449 w |= OMAP_I2C_CON_TRX; 450 - if (stop) 451 w |= OMAP_I2C_CON_STP; 452 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 453 454 - r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 455 - OMAP_I2C_TIMEOUT); 456 dev->buf_len = 0; 457 if (r < 0) 458 return r; ··· 538 539 omap_i2c_unidle(dev); 540 541 - if ((r = omap_i2c_wait_for_bb(dev)) < 0) 542 goto out; 543 544 for (i = 0; i < num; i++) { ··· 573 { 574 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 575 } 576 577 static irqreturn_t 578 omap_i2c_rev1_isr(int this_irq, void *dev_id) ··· 631 632 return IRQ_HANDLED; 633 } 634 635 static irqreturn_t 636 omap_i2c_isr(int this_irq, void *dev_id) ··· 641 struct omap_i2c_dev *dev = dev_id; 642 u16 bits; 643 u16 stat, w; 644 - int count = 0; 645 646 if (dev->idle) 647 return IRQ_NONE; ··· 656 657 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 658 659 - if (stat & OMAP_I2C_STAT_ARDY) { 660 - omap_i2c_complete_cmd(dev, 0); 661 continue; 662 } 663 - if (stat & OMAP_I2C_STAT_RRDY) { 664 - w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); 665 - if (dev->buf_len) { 666 - *dev->buf++ = w; 667 - dev->buf_len--; 668 if (dev->buf_len) { 669 - *dev->buf++ = w >> 8; 670 dev->buf_len--; 671 } 672 - } else 673 - dev_err(dev->dev, "RRDY IRQ while no data " 674 - "requested\n"); 675 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY); 676 - continue; 677 - } 678 - if (stat & OMAP_I2C_STAT_XRDY) { 679 - w = 0; 680 - if (dev->buf_len) { 681 - w = *dev->buf++; 682 - dev->buf_len--; 683 - if (dev->buf_len) { 684 - w |= *dev->buf++ << 8; 685 - dev->buf_len--; 686 - } 687 - } else 688 - dev_err(dev->dev, "XRDY IRQ while no " 689 - "data to send\n"); 690 - omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 691 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY); 692 continue; 693 } 694 if (stat & OMAP_I2C_STAT_ROVR) { ··· 753 dev->cmd_err |= OMAP_I2C_STAT_ROVR; 754 } 755 if (stat & OMAP_I2C_STAT_XUDF) { 756 - dev_err(dev->dev, "Transmit overflow\n"); 757 dev->cmd_err |= OMAP_I2C_STAT_XUDF; 758 - } 759 - if (stat & OMAP_I2C_STAT_NACK) { 760 - omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK); 761 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 762 - OMAP_I2C_CON_STP); 763 - } 764 - if (stat & OMAP_I2C_STAT_AL) { 765 - dev_err(dev->dev, "Arbitration lost\n"); 766 - omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL); 767 } 768 } 769 ··· 766 .functionality = omap_i2c_func, 767 }; 768 769 - static int 770 omap_i2c_probe(struct platform_device *pdev) 771 { 772 struct omap_i2c_dev *dev; 773 struct i2c_adapter *adap; 774 struct resource *mem, *irq, *ioarea; 775 int r; 776 777 /* NOTE: driver uses the static register mapping */ 778 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 795 return -EBUSY; 796 } 797 798 - if (clock > 200) 799 - clock = 400; /* Fast mode */ 800 - else 801 - clock = 100; /* Standard mode */ 802 - 803 dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL); 804 if (!dev) { 805 r = -ENOMEM; 806 goto err_release_region; 807 } 808 809 dev->dev = &pdev->dev; 810 dev->irq = irq->start; 811 dev->base = ioremap(mem->start, mem->end - mem->start + 1); ··· 823 824 omap_i2c_unidle(dev); 825 826 - if (cpu_is_omap15xx()) 827 - dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20; 828 829 /* reset ASAP, clearing any IRQs */ 830 omap_i2c_init(dev); 831 832 - r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr, 833 - 0, pdev->name, dev); 834 835 if (r) { 836 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); 837 goto err_unuse_clocks; 838 } 839 - r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 840 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", 841 - pdev->id, r >> 4, r & 0xf, clock); 842 843 adap = &dev->adapter; 844 i2c_set_adapdata(adap, dev); ··· 872 dev_err(dev->dev, "failure adding adapter\n"); 873 goto err_free_irq; 874 } 875 - 876 - omap_i2c_idle(dev); 877 878 return 0; 879
··· 2 * TI OMAP I2C master mode driver 3 * 4 * Copyright (C) 2003 MontaVista Software, Inc. 5 * Copyright (C) 2005 Nokia Corporation 6 + * Copyright (C) 2004 - 2007 Texas Instruments. 7 * 8 + * Originally written by MontaVista Software, Inc. 9 + * Additional contributions by: 10 + * Tony Lindgren <tony@atomide.com> 11 + * Imre Deak <imre.deak@nokia.com> 12 + * Juha Yrjölä <juha.yrjola@solidboot.com> 13 + * Syed Khasim <x0khasim@ti.com> 14 + * Nishant Menon <nm@ti.com> 15 * 16 * This program is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by ··· 33 #include <linux/completion.h> 34 #include <linux/platform_device.h> 35 #include <linux/clk.h> 36 + #include <linux/io.h> 37 38 + /* I2C controller revisions */ 39 + #define OMAP_I2C_REV_2 0x20 40 + 41 + /* I2C controller revisions present on specific hardware */ 42 + #define OMAP_I2C_REV_ON_2430 0x36 43 + #define OMAP_I2C_REV_ON_3430 0x3C 44 45 /* timeout waiting for the controller to respond */ 46 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) ··· 43 #define OMAP_I2C_IE_REG 0x04 44 #define OMAP_I2C_STAT_REG 0x08 45 #define OMAP_I2C_IV_REG 0x0c 46 + /* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */ 47 + #define OMAP_I2C_WE_REG 0x0c 48 #define OMAP_I2C_SYSS_REG 0x10 49 #define OMAP_I2C_BUF_REG 0x14 50 #define OMAP_I2C_CNT_REG 0x18 ··· 55 #define OMAP_I2C_SCLL_REG 0x34 56 #define OMAP_I2C_SCLH_REG 0x38 57 #define OMAP_I2C_SYSTEST_REG 0x3c 58 + #define OMAP_I2C_BUFSTAT_REG 0x40 59 60 /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ 61 + #define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */ 62 + #define OMAP_I2C_IE_RDR (1 << 13) /* RX Buffer drain int enable */ 63 #define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */ 64 #define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */ 65 #define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */ ··· 64 #define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */ 65 66 /* I2C Status Register (OMAP_I2C_STAT): */ 67 + #define OMAP_I2C_STAT_XDR (1 << 14) /* TX Buffer draining */ 68 + #define OMAP_I2C_STAT_RDR (1 << 13) /* RX Buffer draining */ 69 #define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */ 70 #define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */ 71 #define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */ ··· 76 #define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */ 77 #define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */ 78 79 + /* I2C WE wakeup enable register */ 80 + #define OMAP_I2C_WE_XDR_WE (1 << 14) /* TX drain wakup */ 81 + #define OMAP_I2C_WE_RDR_WE (1 << 13) /* RX drain wakeup */ 82 + #define OMAP_I2C_WE_AAS_WE (1 << 9) /* Address as slave wakeup*/ 83 + #define OMAP_I2C_WE_BF_WE (1 << 8) /* Bus free wakeup */ 84 + #define OMAP_I2C_WE_STC_WE (1 << 6) /* Start condition wakeup */ 85 + #define OMAP_I2C_WE_GC_WE (1 << 5) /* General call wakeup */ 86 + #define OMAP_I2C_WE_DRDY_WE (1 << 3) /* TX/RX data ready wakeup */ 87 + #define OMAP_I2C_WE_ARDY_WE (1 << 2) /* Reg access ready wakeup */ 88 + #define OMAP_I2C_WE_NACK_WE (1 << 1) /* No acknowledgment wakeup */ 89 + #define OMAP_I2C_WE_AL_WE (1 << 0) /* Arbitration lost wakeup */ 90 + 91 + #define OMAP_I2C_WE_ALL (OMAP_I2C_WE_XDR_WE | OMAP_I2C_WE_RDR_WE | \ 92 + OMAP_I2C_WE_AAS_WE | OMAP_I2C_WE_BF_WE | \ 93 + OMAP_I2C_WE_STC_WE | OMAP_I2C_WE_GC_WE | \ 94 + OMAP_I2C_WE_DRDY_WE | OMAP_I2C_WE_ARDY_WE | \ 95 + OMAP_I2C_WE_NACK_WE | OMAP_I2C_WE_AL_WE) 96 + 97 /* I2C Buffer Configuration Register (OMAP_I2C_BUF): */ 98 #define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */ 99 + #define OMAP_I2C_BUF_RXFIF_CLR (1 << 14) /* RX FIFO Clear */ 100 #define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */ 101 + #define OMAP_I2C_BUF_TXFIF_CLR (1 << 6) /* TX FIFO Clear */ 102 103 /* I2C Configuration Register (OMAP_I2C_CON): */ 104 #define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */ 105 #define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */ 106 + #define OMAP_I2C_CON_OPMODE_HS (1 << 12) /* High Speed support */ 107 #define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */ 108 #define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */ 109 #define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */ ··· 90 #define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */ 91 #define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */ 92 #define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */ 93 + 94 + /* I2C SCL time value when Master */ 95 + #define OMAP_I2C_SCLL_HSSCLL 8 96 + #define OMAP_I2C_SCLH_HSSCLH 8 97 98 /* I2C System Test Register (OMAP_I2C_SYSTEST): */ 99 #ifdef DEBUG ··· 103 #define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */ 104 #endif 105 106 + /* OCP_SYSSTATUS bit definitions */ 107 + #define SYSS_RESETDONE_MASK (1 << 0) 108 109 + /* OCP_SYSCONFIG bit definitions */ 110 + #define SYSC_CLOCKACTIVITY_MASK (0x3 << 8) 111 + #define SYSC_SIDLEMODE_MASK (0x3 << 3) 112 + #define SYSC_ENAWAKEUP_MASK (1 << 2) 113 + #define SYSC_SOFTRESET_MASK (1 << 1) 114 + #define SYSC_AUTOIDLE_MASK (1 << 0) 115 116 + #define SYSC_IDLEMODE_SMART 0x2 117 + #define SYSC_CLOCKACTIVITY_FCLK 0x2 118 + 119 120 struct omap_i2c_dev { 121 struct device *dev; ··· 123 struct clk *fclk; /* Functional clock */ 124 struct completion cmd_complete; 125 struct resource *ioarea; 126 + u32 speed; /* Speed of bus in Khz */ 127 u16 cmd_err; 128 u8 *buf; 129 size_t buf_len; 130 struct i2c_adapter adapter; 131 + u8 fifo_size; /* use as flag and value 132 + * fifo_size==0 implies no fifo 133 + * if set, should be trsh+1 134 + */ 135 + u8 rev; 136 + unsigned b_hw:1; /* bad h/w fixes */ 137 unsigned idle:1; 138 u16 iestate; /* Saved interrupt register */ 139 }; ··· 143 return __raw_readw(i2c_dev->base + reg); 144 } 145 146 + static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev) 147 { 148 + if (cpu_is_omap16xx() || cpu_class_is_omap2()) { 149 dev->iclk = clk_get(dev->dev, "i2c_ick"); 150 if (IS_ERR(dev->iclk)) { 151 dev->iclk = NULL; ··· 178 179 static void omap_i2c_unidle(struct omap_i2c_dev *dev) 180 { 181 + WARN_ON(!dev->idle); 182 + 183 if (dev->iclk != NULL) 184 clk_enable(dev->iclk); 185 clk_enable(dev->fclk); 186 + dev->idle = 0; 187 if (dev->iestate) 188 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); 189 } 190 191 static void omap_i2c_idle(struct omap_i2c_dev *dev) 192 { 193 u16 iv; 194 195 + WARN_ON(dev->idle); 196 + 197 dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 198 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); 199 + if (dev->rev < OMAP_I2C_REV_2) { 200 + iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ 201 + } else { 202 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate); 203 + 204 + /* Flush posted write before the dev->idle store occurs */ 205 + omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); 206 + } 207 + dev->idle = 1; 208 clk_disable(dev->fclk); 209 if (dev->iclk != NULL) 210 clk_disable(dev->iclk); ··· 204 205 static int omap_i2c_init(struct omap_i2c_dev *dev) 206 { 207 + u16 psc = 0, scll = 0, sclh = 0; 208 + u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; 209 unsigned long fclk_rate = 12000000; 210 unsigned long timeout; 211 + unsigned long internal_clk = 0; 212 213 + if (dev->rev >= OMAP_I2C_REV_2) { 214 + omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK); 215 /* For some reason we need to set the EN bit before the 216 * reset done bit gets set. */ 217 timeout = jiffies + OMAP_I2C_TIMEOUT; 218 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 219 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) & 220 + SYSS_RESETDONE_MASK)) { 221 if (time_after(jiffies, timeout)) { 222 dev_warn(dev->dev, "timeout waiting " 223 "for controller reset\n"); 224 return -ETIMEDOUT; 225 } 226 msleep(1); 227 + } 228 + 229 + /* SYSC register is cleared by the reset; rewrite it */ 230 + if (dev->rev == OMAP_I2C_REV_ON_2430) { 231 + 232 + omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, 233 + SYSC_AUTOIDLE_MASK); 234 + 235 + } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { 236 + u32 v; 237 + 238 + v = SYSC_AUTOIDLE_MASK; 239 + v |= SYSC_ENAWAKEUP_MASK; 240 + v |= (SYSC_IDLEMODE_SMART << 241 + __ffs(SYSC_SIDLEMODE_MASK)); 242 + v |= (SYSC_CLOCKACTIVITY_FCLK << 243 + __ffs(SYSC_CLOCKACTIVITY_MASK)); 244 + 245 + omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, v); 246 + /* 247 + * Enabling all wakup sources to stop I2C freezing on 248 + * WFI instruction. 249 + * REVISIT: Some wkup sources might not be needed. 250 + */ 251 + omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, 252 + OMAP_I2C_WE_ALL); 253 + 254 } 255 } 256 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); ··· 249 psc = fclk_rate / 12000000; 250 } 251 252 + if (cpu_is_omap2430() || cpu_is_omap34xx()) { 253 + 254 + /* HSI2C controller internal clk rate should be 19.2 Mhz */ 255 + internal_clk = 19200; 256 + fclk_rate = clk_get_rate(dev->fclk) / 1000; 257 + 258 + /* Compute prescaler divisor */ 259 + psc = fclk_rate / internal_clk; 260 + psc = psc - 1; 261 + 262 + /* If configured for High Speed */ 263 + if (dev->speed > 400) { 264 + /* For first phase of HS mode */ 265 + fsscll = internal_clk / (400 * 2) - 6; 266 + fssclh = internal_clk / (400 * 2) - 6; 267 + 268 + /* For second phase of HS mode */ 269 + hsscll = fclk_rate / (dev->speed * 2) - 6; 270 + hssclh = fclk_rate / (dev->speed * 2) - 6; 271 + } else { 272 + /* To handle F/S modes */ 273 + fsscll = internal_clk / (dev->speed * 2) - 6; 274 + fssclh = internal_clk / (dev->speed * 2) - 6; 275 + } 276 + scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll; 277 + sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh; 278 + } else { 279 + /* Program desired operating rate */ 280 + fclk_rate /= (psc + 1) * 1000; 281 + if (psc > 2) 282 + psc = 2; 283 + scll = fclk_rate / (dev->speed * 2) - 7 + psc; 284 + sclh = fclk_rate / (dev->speed * 2) - 7 + psc; 285 + } 286 + 287 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 288 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc); 289 290 + /* SCL low and high time values */ 291 + omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); 292 + omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); 293 294 + if (dev->fifo_size) 295 + /* Note: setup required fifo size - 1 */ 296 + omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, 297 + (dev->fifo_size - 1) << 8 | /* RTRSH */ 298 + OMAP_I2C_BUF_RXFIF_CLR | 299 + (dev->fifo_size - 1) | /* XTRSH */ 300 + OMAP_I2C_BUF_TXFIF_CLR); 301 302 /* Take the I2C module out of reset: */ 303 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 304 305 /* Enable interrupts */ 306 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 307 + (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 308 + OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 309 + OMAP_I2C_IE_AL) | ((dev->fifo_size) ? 310 + (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0)); 311 return 0; 312 } 313 ··· 316 317 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len); 318 319 + /* Clear the FIFO Buffers */ 320 + w = omap_i2c_read_reg(dev, OMAP_I2C_BUF_REG); 321 + w |= OMAP_I2C_BUF_RXFIF_CLR | OMAP_I2C_BUF_TXFIF_CLR; 322 + omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, w); 323 + 324 init_completion(&dev->cmd_complete); 325 dev->cmd_err = 0; 326 327 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT; 328 + 329 + /* High speed configuration */ 330 + if (dev->speed > 400) 331 + w |= OMAP_I2C_CON_OPMODE_HS; 332 + 333 if (msg->flags & I2C_M_TEN) 334 w |= OMAP_I2C_CON_XA; 335 if (!(msg->flags & I2C_M_RD)) 336 w |= OMAP_I2C_CON_TRX; 337 + 338 + if (!dev->b_hw && stop) 339 w |= OMAP_I2C_CON_STP; 340 + 341 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 342 343 + /* 344 + * Don't write stt and stp together on some hardware. 345 + */ 346 + if (dev->b_hw && stop) { 347 + unsigned long delay = jiffies + OMAP_I2C_TIMEOUT; 348 + u16 con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 349 + while (con & OMAP_I2C_CON_STT) { 350 + con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 351 + 352 + /* Let the user know if i2c is in a bad state */ 353 + if (time_after(jiffies, delay)) { 354 + dev_err(dev->dev, "controller timed out " 355 + "waiting for start condition to finish\n"); 356 + return -ETIMEDOUT; 357 + } 358 + cpu_relax(); 359 + } 360 + 361 + w |= OMAP_I2C_CON_STP; 362 + w &= ~OMAP_I2C_CON_STT; 363 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 364 + } 365 + 366 + /* 367 + * REVISIT: We should abort the transfer on signals, but the bus goes 368 + * into arbitration and we're currently unable to recover from it. 369 + */ 370 + r = wait_for_completion_timeout(&dev->cmd_complete, 371 + OMAP_I2C_TIMEOUT); 372 dev->buf_len = 0; 373 if (r < 0) 374 return r; ··· 376 377 omap_i2c_unidle(dev); 378 379 + r = omap_i2c_wait_for_bb(dev); 380 + if (r < 0) 381 goto out; 382 383 for (i = 0; i < num; i++) { ··· 410 { 411 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 412 } 413 + 414 + /* rev1 devices are apparently only on some 15xx */ 415 + #ifdef CONFIG_ARCH_OMAP15XX 416 417 static irqreturn_t 418 omap_i2c_rev1_isr(int this_irq, void *dev_id) ··· 465 466 return IRQ_HANDLED; 467 } 468 + #else 469 + #define omap_i2c_rev1_isr NULL 470 + #endif 471 472 static irqreturn_t 473 omap_i2c_isr(int this_irq, void *dev_id) ··· 472 struct omap_i2c_dev *dev = dev_id; 473 u16 bits; 474 u16 stat, w; 475 + int err, count = 0; 476 477 if (dev->idle) 478 return IRQ_NONE; ··· 487 488 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 489 490 + err = 0; 491 + if (stat & OMAP_I2C_STAT_NACK) { 492 + err |= OMAP_I2C_STAT_NACK; 493 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 494 + OMAP_I2C_CON_STP); 495 + } 496 + if (stat & OMAP_I2C_STAT_AL) { 497 + dev_err(dev->dev, "Arbitration lost\n"); 498 + err |= OMAP_I2C_STAT_AL; 499 + } 500 + if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK | 501 + OMAP_I2C_STAT_AL)) 502 + omap_i2c_complete_cmd(dev, err); 503 + if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) { 504 + u8 num_bytes = 1; 505 + if (dev->fifo_size) { 506 + if (stat & OMAP_I2C_STAT_RRDY) 507 + num_bytes = dev->fifo_size; 508 + else 509 + num_bytes = omap_i2c_read_reg(dev, 510 + OMAP_I2C_BUFSTAT_REG); 511 + } 512 + while (num_bytes) { 513 + num_bytes--; 514 + w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); 515 + if (dev->buf_len) { 516 + *dev->buf++ = w; 517 + dev->buf_len--; 518 + /* Data reg from 2430 is 8 bit wide */ 519 + if (!cpu_is_omap2430() && 520 + !cpu_is_omap34xx()) { 521 + if (dev->buf_len) { 522 + *dev->buf++ = w >> 8; 523 + dev->buf_len--; 524 + } 525 + } 526 + } else { 527 + if (stat & OMAP_I2C_STAT_RRDY) 528 + dev_err(dev->dev, 529 + "RRDY IRQ while no data" 530 + " requested\n"); 531 + if (stat & OMAP_I2C_STAT_RDR) 532 + dev_err(dev->dev, 533 + "RDR IRQ while no data" 534 + " requested\n"); 535 + break; 536 + } 537 + } 538 + omap_i2c_ack_stat(dev, 539 + stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)); 540 continue; 541 } 542 + if (stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)) { 543 + u8 num_bytes = 1; 544 + if (dev->fifo_size) { 545 + if (stat & OMAP_I2C_STAT_XRDY) 546 + num_bytes = dev->fifo_size; 547 + else 548 + num_bytes = omap_i2c_read_reg(dev, 549 + OMAP_I2C_BUFSTAT_REG); 550 + } 551 + while (num_bytes) { 552 + num_bytes--; 553 + w = 0; 554 if (dev->buf_len) { 555 + w = *dev->buf++; 556 dev->buf_len--; 557 + /* Data reg from 2430 is 8 bit wide */ 558 + if (!cpu_is_omap2430() && 559 + !cpu_is_omap34xx()) { 560 + if (dev->buf_len) { 561 + w |= *dev->buf++ << 8; 562 + dev->buf_len--; 563 + } 564 + } 565 + } else { 566 + if (stat & OMAP_I2C_STAT_XRDY) 567 + dev_err(dev->dev, 568 + "XRDY IRQ while no " 569 + "data to send\n"); 570 + if (stat & OMAP_I2C_STAT_XDR) 571 + dev_err(dev->dev, 572 + "XDR IRQ while no " 573 + "data to send\n"); 574 + break; 575 } 576 + omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 577 + } 578 + omap_i2c_ack_stat(dev, 579 + stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); 580 continue; 581 } 582 if (stat & OMAP_I2C_STAT_ROVR) { ··· 527 dev->cmd_err |= OMAP_I2C_STAT_ROVR; 528 } 529 if (stat & OMAP_I2C_STAT_XUDF) { 530 + dev_err(dev->dev, "Transmit underflow\n"); 531 dev->cmd_err |= OMAP_I2C_STAT_XUDF; 532 } 533 } 534 ··· 549 .functionality = omap_i2c_func, 550 }; 551 552 + static int __init 553 omap_i2c_probe(struct platform_device *pdev) 554 { 555 struct omap_i2c_dev *dev; 556 struct i2c_adapter *adap; 557 struct resource *mem, *irq, *ioarea; 558 + void *isr; 559 int r; 560 + u32 speed = 0; 561 562 /* NOTE: driver uses the static register mapping */ 563 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 576 return -EBUSY; 577 } 578 579 dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL); 580 if (!dev) { 581 r = -ENOMEM; 582 goto err_release_region; 583 } 584 585 + if (pdev->dev.platform_data != NULL) 586 + speed = *(u32 *)pdev->dev.platform_data; 587 + else 588 + speed = 100; /* Defualt speed */ 589 + 590 + dev->speed = speed; 591 + dev->idle = 1; 592 dev->dev = &pdev->dev; 593 dev->irq = irq->start; 594 dev->base = ioremap(mem->start, mem->end - mem->start + 1); ··· 602 603 omap_i2c_unidle(dev); 604 605 + dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 606 + 607 + if (cpu_is_omap2430() || cpu_is_omap34xx()) { 608 + u16 s; 609 + 610 + /* Set up the fifo size - Get total size */ 611 + s = (omap_i2c_read_reg(dev, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3; 612 + dev->fifo_size = 0x8 << s; 613 + 614 + /* 615 + * Set up notification threshold as half the total available 616 + * size. This is to ensure that we can handle the status on int 617 + * call back latencies. 618 + */ 619 + dev->fifo_size = (dev->fifo_size / 2); 620 + dev->b_hw = 1; /* Enable hardware fixes */ 621 + } 622 623 /* reset ASAP, clearing any IRQs */ 624 omap_i2c_init(dev); 625 626 + isr = (dev->rev < OMAP_I2C_REV_2) ? omap_i2c_rev1_isr : omap_i2c_isr; 627 + r = request_irq(dev->irq, isr, 0, pdev->name, dev); 628 629 if (r) { 630 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); 631 goto err_unuse_clocks; 632 } 633 + 634 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", 635 + pdev->id, dev->rev >> 4, dev->rev & 0xf, dev->speed); 636 + 637 + omap_i2c_idle(dev); 638 639 adap = &dev->adapter; 640 i2c_set_adapdata(adap, dev); ··· 634 dev_err(dev->dev, "failure adding adapter\n"); 635 goto err_free_irq; 636 } 637 638 return 0; 639