Merge branch 'i2c-next' of git://aeryn.fluff.org.uk/bjdooks/linux

* 'i2c-next' of git://aeryn.fluff.org.uk/bjdooks/linux:
i2c-omap: fix type of irq handler function
i2c-s3c2410: Change IRQ to be plain integer.
i2c-s3c2410: Allow more than one i2c-s3c2410 adapter
i2c-s3c2410: Remove default platform data.
i2c-s3c2410: Use platform data for gpio configuration
i2c-s3c2410: Fixup style problems from checkpatch.pl
i2c-omap: Enable I2C wakeups for 34xx
i2c-omap: reprogram OCP_SYSCONFIG register after reset
i2c-omap: convert 'rev1' flag to generic 'rev' u8
i2c-omap: fix I2C timeouts due to recursive omap_i2c_{un,}idle()
i2c-omap: Clean-up i2c-omap
i2c-omap: Don't compile in OMAP15xx I2C ISR for non-OMAP15xx builds
i2c-omap: Mark init-only functions as __init
i2c-omap: Add support for omap34xx
i2c-omap: FIFO handling support and broken hw workaround for i2c-omap
i2c-omap: Add high-speed support to omap-i2c
i2c-omap: Close suspected race between omap_i2c_idle() and omap_i2c_isr()
i2c-omap: Do not use interruptible wait call in omap_i2c_xfer_msg

Fix up apparently-trivial conflict in drivers/i2c/busses/i2c-s3c2410.c

+412 -205
+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 + irq_handler_t 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
+78 -107
drivers/i2c/busses/i2c-s3c2410.c
··· 35 #include <linux/clk.h> 36 #include <linux/cpufreq.h> 37 38 - #include <mach/hardware.h> 39 #include <asm/irq.h> 40 #include <asm/io.h> 41 42 - #include <mach/regs-gpio.h> 43 #include <plat/regs-iic.h> 44 #include <plat/iic.h> 45 ··· 62 unsigned int msg_ptr; 63 64 unsigned int tx_setup; 65 66 enum s3c24xx_i2c_state state; 67 unsigned long clkrate; ··· 70 void __iomem *regs; 71 struct clk *clk; 72 struct device *dev; 73 - struct resource *irq; 74 struct resource *ioarea; 75 struct i2c_adapter adap; 76 ··· 78 #endif 79 }; 80 81 - /* default platform data to use if not supplied in the platform_device 82 - */ 83 - 84 - static struct s3c2410_platform_i2c s3c24xx_i2c_default_platform = { 85 - .flags = 0, 86 - .slave_addr = 0x10, 87 - .bus_freq = 100*1000, 88 - .max_freq = 400*1000, 89 - .sda_delay = S3C2410_IICLC_SDA_DELAY5 | S3C2410_IICLC_FILTER_ON, 90 - }; 91 92 /* s3c24xx_i2c_is2440() 93 * ··· 90 struct platform_device *pdev = to_platform_device(i2c->dev); 91 92 return !strcmp(pdev->name, "s3c2440-i2c"); 93 - } 94 - 95 - 96 - /* s3c24xx_i2c_get_platformdata 97 - * 98 - * get the platform data associated with the given device, or return 99 - * the default if there is none 100 - */ 101 - 102 - static inline struct s3c2410_platform_i2c *s3c24xx_i2c_get_platformdata(struct device *dev) 103 - { 104 - if (dev->platform_data != NULL) 105 - return (struct s3c2410_platform_i2c *)dev->platform_data; 106 - 107 - return &s3c24xx_i2c_default_platform; 108 } 109 110 /* s3c24xx_i2c_master_complete ··· 104 105 i2c->msg_ptr = 0; 106 i2c->msg = NULL; 107 - i2c->msg_idx ++; 108 i2c->msg_num = 0; 109 if (ret) 110 i2c->msg_idx = ret; ··· 115 static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) 116 { 117 unsigned long tmp; 118 - 119 tmp = readl(i2c->regs + S3C2410_IICCON); 120 writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); 121 - 122 } 123 124 static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) 125 { 126 unsigned long tmp; 127 - 128 tmp = readl(i2c->regs + S3C2410_IICCON); 129 writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); 130 - 131 } 132 133 /* irq enable/disable functions */ ··· 133 static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) 134 { 135 unsigned long tmp; 136 - 137 tmp = readl(i2c->regs + S3C2410_IICCON); 138 writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); 139 } ··· 141 static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) 142 { 143 unsigned long tmp; 144 - 145 tmp = readl(i2c->regs + S3C2410_IICCON); 146 writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); 147 } ··· 149 150 /* s3c24xx_i2c_message_start 151 * 152 - * put the start of a message onto the bus 153 */ 154 155 - static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, 156 struct i2c_msg *msg) 157 { 158 unsigned int addr = (msg->addr & 0x7f) << 1; ··· 171 if (msg->flags & I2C_M_REV_DIR_ADDR) 172 addr ^= 1; 173 174 - // todo - check for wether ack wanted or not 175 s3c24xx_i2c_enable_ack(i2c); 176 177 iiccon = readl(i2c->regs + S3C2410_IICCON); 178 writel(stat, i2c->regs + S3C2410_IICSTAT); 179 - 180 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); 181 writeb(addr, i2c->regs + S3C2410_IICDS); 182 - 183 /* delay here to ensure the data byte has gotten onto the bus 184 * before the transaction is started */ 185 ··· 187 188 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); 189 writel(iiccon, i2c->regs + S3C2410_IICCON); 190 - 191 - stat |= S3C2410_IICSTAT_START; 192 writel(stat, i2c->regs + S3C2410_IICSTAT); 193 } 194 ··· 199 dev_dbg(i2c->dev, "STOP\n"); 200 201 /* stop the transfer */ 202 - iicstat &= ~ S3C2410_IICSTAT_START; 203 writel(iicstat, i2c->regs + S3C2410_IICSTAT); 204 - 205 i2c->state = STATE_STOP; 206 - 207 s3c24xx_i2c_master_complete(i2c, ret); 208 s3c24xx_i2c_disable_irq(i2c); 209 } ··· 213 214 /* is_lastmsg() 215 * 216 - * returns TRUE if the current message is the last in the set 217 */ 218 219 static inline int is_lastmsg(struct s3c24xx_i2c *i2c) ··· 261 262 case STATE_STOP: 263 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); 264 - s3c24xx_i2c_disable_irq(i2c); 265 goto out_ack; 266 267 case STATE_START: 268 /* last thing we did was send a start condition on the 269 * bus, or started a new i2c message 270 */ 271 - 272 if (iicstat & S3C2410_IICSTAT_LASTBIT && 273 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 274 /* ack was not received... */ ··· 294 if (i2c->state == STATE_READ) 295 goto prepare_read; 296 297 - /* fall through to the write state, as we will need to 298 * send a byte as well */ 299 300 case STATE_WRITE: ··· 311 } 312 } 313 314 - retry_write: 315 316 if (!is_msgend(i2c)) { 317 byte = i2c->msg->buf[i2c->msg_ptr++]; ··· 331 dev_dbg(i2c->dev, "WRITE: Next Message\n"); 332 333 i2c->msg_ptr = 0; 334 - i2c->msg_idx ++; 335 i2c->msg++; 336 - 337 /* check to see if we need to do another message */ 338 if (i2c->msg->flags & I2C_M_NOSTART) { 339 ··· 347 348 goto retry_write; 349 } else { 350 - 351 /* send the new start */ 352 s3c24xx_i2c_message_start(i2c, i2c->msg); 353 i2c->state = STATE_START; ··· 360 break; 361 362 case STATE_READ: 363 - /* we have a byte of data in the data register, do 364 * something with it, and then work out wether we are 365 * going to do any more read/write 366 */ ··· 368 byte = readb(i2c->regs + S3C2410_IICDS); 369 i2c->msg->buf[i2c->msg_ptr++] = byte; 370 371 - prepare_read: 372 if (is_msglast(i2c)) { 373 /* last byte of buffer */ 374 375 if (is_lastmsg(i2c)) 376 s3c24xx_i2c_disable_ack(i2c); 377 - 378 } else if (is_msgend(i2c)) { 379 /* ok, we've read the entire buffer, see if there 380 * is anything else we need to do */ ··· 400 /* acknowlegde the IRQ and get back on with the work */ 401 402 out_ack: 403 - tmp = readl(i2c->regs + S3C2410_IICCON); 404 tmp &= ~S3C2410_IICCON_IRQPEND; 405 writel(tmp, i2c->regs + S3C2410_IICCON); 406 out: ··· 421 status = readl(i2c->regs + S3C2410_IICSTAT); 422 423 if (status & S3C2410_IICSTAT_ARBITR) { 424 - // deal with arbitration loss 425 dev_err(i2c->dev, "deal with arbitration loss\n"); 426 } 427 428 if (i2c->state == STATE_IDLE) { 429 dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); 430 431 - tmp = readl(i2c->regs + S3C2410_IICCON); 432 tmp &= ~S3C2410_IICCON_IRQPEND; 433 writel(tmp, i2c->regs + S3C2410_IICCON); 434 goto out; 435 } 436 - 437 /* pretty much this leaves us with the fact that we've 438 * transmitted or received whatever byte we last sent */ 439 ··· 456 457 while (timeout-- > 0) { 458 iicstat = readl(i2c->regs + S3C2410_IICSTAT); 459 - 460 if (!(iicstat & S3C2410_IICSTAT_BUSBUSY)) 461 return 0; 462 463 msleep(1); 464 } 465 - 466 - dev_dbg(i2c->dev, "timeout: GPEDAT is %08x\n", 467 - __raw_readl(S3C2410_GPEDAT)); 468 469 return -ETIMEDOUT; 470 } ··· 471 * this starts an i2c transfer 472 */ 473 474 - static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num) 475 { 476 unsigned long timeout; 477 int ret; ··· 498 s3c24xx_i2c_enable_irq(i2c); 499 s3c24xx_i2c_message_start(i2c, msgs); 500 spin_unlock_irq(&i2c->lock); 501 - 502 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 503 504 ret = i2c->msg_idx; 505 506 - /* having these next two as dev_err() makes life very 507 * noisy when doing an i2cdetect */ 508 509 if (timeout == 0) ··· 560 .functionality = s3c24xx_i2c_func, 561 }; 562 563 - static struct s3c24xx_i2c s3c24xx_i2c = { 564 - .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_i2c.lock), 565 - .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), 566 - .tx_setup = 50, 567 - .adap = { 568 - .name = "s3c2410-i2c", 569 - .owner = THIS_MODULE, 570 - .algo = &s3c24xx_i2c_algorithm, 571 - .retries = 2, 572 - .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 573 - }, 574 - }; 575 - 576 /* s3c24xx_i2c_calcdivisor 577 * 578 * return the divisor settings for a given frequency ··· 599 { 600 int diff = freq - wanted; 601 602 - return (diff >= -2 && diff <= 2); 603 } 604 605 /* s3c24xx_i2c_clockrate ··· 611 612 static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) 613 { 614 - struct s3c2410_platform_i2c *pdata; 615 unsigned long clkin = clk_get_rate(i2c->clk); 616 unsigned int divs, div1; 617 u32 iiccon; ··· 619 int start, end; 620 621 i2c->clkrate = clkin; 622 - 623 - pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent); 624 clkin /= 1000; /* clkin now in KHz */ 625 - 626 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", 627 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); 628 ··· 728 729 /* s3c24xx_i2c_init 730 * 731 - * initialise the controller, set the IO lines and frequency 732 */ 733 734 static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) ··· 739 740 /* get the plafrom data */ 741 742 - pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent); 743 744 /* inititalise the gpio */ 745 746 - s3c2410_gpio_cfgpin(S3C2410_GPE15, S3C2410_GPE15_IICSDA); 747 - s3c2410_gpio_cfgpin(S3C2410_GPE14, S3C2410_GPE14_IICSCL); 748 749 /* write slave address */ 750 - 751 writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); 752 753 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); ··· 785 786 static int s3c24xx_i2c_probe(struct platform_device *pdev) 787 { 788 - struct s3c24xx_i2c *i2c = &s3c24xx_i2c; 789 struct s3c2410_platform_i2c *pdata; 790 struct resource *res; 791 int ret; 792 793 - pdata = s3c24xx_i2c_get_platformdata(&pdev->dev); 794 795 /* find the clock and enable it */ 796 ··· 852 goto err_ioarea; 853 } 854 855 - dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); 856 857 /* setup info block for the i2c core */ 858 ··· 867 goto err_iomap; 868 869 /* find the IRQ for this unit (note, this relies on the init call to 870 - * ensure no current IRQs pending 871 */ 872 873 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 874 - if (res == NULL) { 875 dev_err(&pdev->dev, "cannot find IRQ\n"); 876 - ret = -ENOENT; 877 goto err_iomap; 878 } 879 880 - ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, 881 - pdev->name, i2c); 882 883 if (ret != 0) { 884 - dev_err(&pdev->dev, "cannot claim IRQ\n"); 885 goto err_iomap; 886 } 887 - 888 - i2c->irq = res; 889 - 890 - dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res, 891 - (unsigned long)res->start); 892 893 ret = s3c24xx_i2c_register_cpufreq(i2c); 894 if (ret < 0) { ··· 913 s3c24xx_i2c_deregister_cpufreq(i2c); 914 915 err_irq: 916 - free_irq(i2c->irq->start, i2c); 917 918 err_iomap: 919 iounmap(i2c->regs); ··· 927 clk_put(i2c->clk); 928 929 err_noclk: 930 return ret; 931 } 932 ··· 943 s3c24xx_i2c_deregister_cpufreq(i2c); 944 945 i2c_del_adapter(&i2c->adap); 946 - free_irq(i2c->irq->start, i2c); 947 948 clk_disable(i2c->clk); 949 clk_put(i2c->clk); ··· 952 953 release_resource(i2c->ioarea); 954 kfree(i2c->ioarea); 955 956 return 0; 957 }
··· 35 #include <linux/clk.h> 36 #include <linux/cpufreq.h> 37 38 #include <asm/irq.h> 39 #include <asm/io.h> 40 41 #include <plat/regs-iic.h> 42 #include <plat/iic.h> 43 ··· 64 unsigned int msg_ptr; 65 66 unsigned int tx_setup; 67 + unsigned int irq; 68 69 enum s3c24xx_i2c_state state; 70 unsigned long clkrate; ··· 71 void __iomem *regs; 72 struct clk *clk; 73 struct device *dev; 74 struct resource *ioarea; 75 struct i2c_adapter adap; 76 ··· 80 #endif 81 }; 82 83 + /* default platform data removed, dev should always carry data. */ 84 85 /* s3c24xx_i2c_is2440() 86 * ··· 101 struct platform_device *pdev = to_platform_device(i2c->dev); 102 103 return !strcmp(pdev->name, "s3c2440-i2c"); 104 } 105 106 /* s3c24xx_i2c_master_complete ··· 130 131 i2c->msg_ptr = 0; 132 i2c->msg = NULL; 133 + i2c->msg_idx++; 134 i2c->msg_num = 0; 135 if (ret) 136 i2c->msg_idx = ret; ··· 141 static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) 142 { 143 unsigned long tmp; 144 + 145 tmp = readl(i2c->regs + S3C2410_IICCON); 146 writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); 147 } 148 149 static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) 150 { 151 unsigned long tmp; 152 + 153 tmp = readl(i2c->regs + S3C2410_IICCON); 154 writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); 155 } 156 157 /* irq enable/disable functions */ ··· 161 static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) 162 { 163 unsigned long tmp; 164 + 165 tmp = readl(i2c->regs + S3C2410_IICCON); 166 writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); 167 } ··· 169 static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) 170 { 171 unsigned long tmp; 172 + 173 tmp = readl(i2c->regs + S3C2410_IICCON); 174 writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); 175 } ··· 177 178 /* s3c24xx_i2c_message_start 179 * 180 + * put the start of a message onto the bus 181 */ 182 183 + static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, 184 struct i2c_msg *msg) 185 { 186 unsigned int addr = (msg->addr & 0x7f) << 1; ··· 199 if (msg->flags & I2C_M_REV_DIR_ADDR) 200 addr ^= 1; 201 202 + /* todo - check for wether ack wanted or not */ 203 s3c24xx_i2c_enable_ack(i2c); 204 205 iiccon = readl(i2c->regs + S3C2410_IICCON); 206 writel(stat, i2c->regs + S3C2410_IICSTAT); 207 + 208 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); 209 writeb(addr, i2c->regs + S3C2410_IICDS); 210 + 211 /* delay here to ensure the data byte has gotten onto the bus 212 * before the transaction is started */ 213 ··· 215 216 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); 217 writel(iiccon, i2c->regs + S3C2410_IICCON); 218 + 219 + stat |= S3C2410_IICSTAT_START; 220 writel(stat, i2c->regs + S3C2410_IICSTAT); 221 } 222 ··· 227 dev_dbg(i2c->dev, "STOP\n"); 228 229 /* stop the transfer */ 230 + iicstat &= ~S3C2410_IICSTAT_START; 231 writel(iicstat, i2c->regs + S3C2410_IICSTAT); 232 + 233 i2c->state = STATE_STOP; 234 + 235 s3c24xx_i2c_master_complete(i2c, ret); 236 s3c24xx_i2c_disable_irq(i2c); 237 } ··· 241 242 /* is_lastmsg() 243 * 244 + * returns TRUE if the current message is the last in the set 245 */ 246 247 static inline int is_lastmsg(struct s3c24xx_i2c *i2c) ··· 289 290 case STATE_STOP: 291 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); 292 + s3c24xx_i2c_disable_irq(i2c); 293 goto out_ack; 294 295 case STATE_START: 296 /* last thing we did was send a start condition on the 297 * bus, or started a new i2c message 298 */ 299 + 300 if (iicstat & S3C2410_IICSTAT_LASTBIT && 301 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 302 /* ack was not received... */ ··· 322 if (i2c->state == STATE_READ) 323 goto prepare_read; 324 325 + /* fall through to the write state, as we will need to 326 * send a byte as well */ 327 328 case STATE_WRITE: ··· 339 } 340 } 341 342 + retry_write: 343 344 if (!is_msgend(i2c)) { 345 byte = i2c->msg->buf[i2c->msg_ptr++]; ··· 359 dev_dbg(i2c->dev, "WRITE: Next Message\n"); 360 361 i2c->msg_ptr = 0; 362 + i2c->msg_idx++; 363 i2c->msg++; 364 + 365 /* check to see if we need to do another message */ 366 if (i2c->msg->flags & I2C_M_NOSTART) { 367 ··· 375 376 goto retry_write; 377 } else { 378 /* send the new start */ 379 s3c24xx_i2c_message_start(i2c, i2c->msg); 380 i2c->state = STATE_START; ··· 389 break; 390 391 case STATE_READ: 392 + /* we have a byte of data in the data register, do 393 * something with it, and then work out wether we are 394 * going to do any more read/write 395 */ ··· 397 byte = readb(i2c->regs + S3C2410_IICDS); 398 i2c->msg->buf[i2c->msg_ptr++] = byte; 399 400 + prepare_read: 401 if (is_msglast(i2c)) { 402 /* last byte of buffer */ 403 404 if (is_lastmsg(i2c)) 405 s3c24xx_i2c_disable_ack(i2c); 406 + 407 } else if (is_msgend(i2c)) { 408 /* ok, we've read the entire buffer, see if there 409 * is anything else we need to do */ ··· 429 /* acknowlegde the IRQ and get back on with the work */ 430 431 out_ack: 432 + tmp = readl(i2c->regs + S3C2410_IICCON); 433 tmp &= ~S3C2410_IICCON_IRQPEND; 434 writel(tmp, i2c->regs + S3C2410_IICCON); 435 out: ··· 450 status = readl(i2c->regs + S3C2410_IICSTAT); 451 452 if (status & S3C2410_IICSTAT_ARBITR) { 453 + /* deal with arbitration loss */ 454 dev_err(i2c->dev, "deal with arbitration loss\n"); 455 } 456 457 if (i2c->state == STATE_IDLE) { 458 dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); 459 460 + tmp = readl(i2c->regs + S3C2410_IICCON); 461 tmp &= ~S3C2410_IICCON_IRQPEND; 462 writel(tmp, i2c->regs + S3C2410_IICCON); 463 goto out; 464 } 465 + 466 /* pretty much this leaves us with the fact that we've 467 * transmitted or received whatever byte we last sent */ 468 ··· 485 486 while (timeout-- > 0) { 487 iicstat = readl(i2c->regs + S3C2410_IICSTAT); 488 + 489 if (!(iicstat & S3C2410_IICSTAT_BUSBUSY)) 490 return 0; 491 492 msleep(1); 493 } 494 495 return -ETIMEDOUT; 496 } ··· 503 * this starts an i2c transfer 504 */ 505 506 + static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, 507 + struct i2c_msg *msgs, int num) 508 { 509 unsigned long timeout; 510 int ret; ··· 529 s3c24xx_i2c_enable_irq(i2c); 530 s3c24xx_i2c_message_start(i2c, msgs); 531 spin_unlock_irq(&i2c->lock); 532 + 533 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 534 535 ret = i2c->msg_idx; 536 537 + /* having these next two as dev_err() makes life very 538 * noisy when doing an i2cdetect */ 539 540 if (timeout == 0) ··· 591 .functionality = s3c24xx_i2c_func, 592 }; 593 594 /* s3c24xx_i2c_calcdivisor 595 * 596 * return the divisor settings for a given frequency ··· 643 { 644 int diff = freq - wanted; 645 646 + return diff >= -2 && diff <= 2; 647 } 648 649 /* s3c24xx_i2c_clockrate ··· 655 656 static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) 657 { 658 + struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data; 659 unsigned long clkin = clk_get_rate(i2c->clk); 660 unsigned int divs, div1; 661 u32 iiccon; ··· 663 int start, end; 664 665 i2c->clkrate = clkin; 666 clkin /= 1000; /* clkin now in KHz */ 667 + 668 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", 669 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); 670 ··· 774 775 /* s3c24xx_i2c_init 776 * 777 + * initialise the controller, set the IO lines and frequency 778 */ 779 780 static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) ··· 785 786 /* get the plafrom data */ 787 788 + pdata = i2c->dev->platform_data; 789 790 /* inititalise the gpio */ 791 792 + if (pdata->cfg_gpio) 793 + pdata->cfg_gpio(to_platform_device(i2c->dev)); 794 795 /* write slave address */ 796 + 797 writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); 798 799 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); ··· 831 832 static int s3c24xx_i2c_probe(struct platform_device *pdev) 833 { 834 + struct s3c24xx_i2c *i2c; 835 struct s3c2410_platform_i2c *pdata; 836 struct resource *res; 837 int ret; 838 839 + pdata = pdev->dev.platform_data; 840 + if (!pdata) { 841 + dev_err(&pdev->dev, "no platform data\n"); 842 + return -EINVAL; 843 + } 844 + 845 + i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL); 846 + if (!i2c) { 847 + dev_err(&pdev->dev, "no memory for state\n"); 848 + return -ENOMEM; 849 + } 850 + 851 + strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name)); 852 + i2c->adap.owner = THIS_MODULE; 853 + i2c->adap.algo = &s3c24xx_i2c_algorithm; 854 + i2c->adap.retries = 2; 855 + i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 856 + i2c->tx_setup = 50; 857 + 858 + spin_lock_init(&i2c->lock); 859 + init_waitqueue_head(&i2c->wait); 860 861 /* find the clock and enable it */ 862 ··· 878 goto err_ioarea; 879 } 880 881 + dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", 882 + i2c->regs, i2c->ioarea, res); 883 884 /* setup info block for the i2c core */ 885 ··· 892 goto err_iomap; 893 894 /* find the IRQ for this unit (note, this relies on the init call to 895 + * ensure no current IRQs pending 896 */ 897 898 + i2c->irq = ret = platform_get_irq(pdev, 0); 899 + if (ret <= 0) { 900 dev_err(&pdev->dev, "cannot find IRQ\n"); 901 goto err_iomap; 902 } 903 904 + ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED, 905 + dev_name(&pdev->dev), i2c); 906 907 if (ret != 0) { 908 + dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); 909 goto err_iomap; 910 } 911 912 ret = s3c24xx_i2c_register_cpufreq(i2c); 913 if (ret < 0) { ··· 944 s3c24xx_i2c_deregister_cpufreq(i2c); 945 946 err_irq: 947 + free_irq(i2c->irq, i2c); 948 949 err_iomap: 950 iounmap(i2c->regs); ··· 958 clk_put(i2c->clk); 959 960 err_noclk: 961 + kfree(i2c); 962 return ret; 963 } 964 ··· 973 s3c24xx_i2c_deregister_cpufreq(i2c); 974 975 i2c_del_adapter(&i2c->adap); 976 + free_irq(i2c->irq, i2c); 977 978 clk_disable(i2c->clk); 979 clk_put(i2c->clk); ··· 982 983 release_resource(i2c->ioarea); 984 kfree(i2c->ioarea); 985 + kfree(i2c); 986 987 return 0; 988 }