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 2321 }; 2322 2322 2323 2323 static struct clk i2chs2_fck = { 2324 - .name = "i2chs_fck", 2324 + .name = "i2c_fck", 2325 2325 .id = 2, 2326 2326 .parent = &func_96m_ck, 2327 2327 .flags = CLOCK_IN_OMAP243X, ··· 2354 2354 }; 2355 2355 2356 2356 static struct clk i2chs1_fck = { 2357 - .name = "i2chs_fck", 2357 + .name = "i2c_fck", 2358 2358 .id = 1, 2359 2359 .parent = &func_96m_ck, 2360 2360 .flags = CLOCK_IN_OMAP243X,
+332 -96
drivers/i2c/busses/i2c-omap.c
··· 2 2 * TI OMAP I2C master mode driver 3 3 * 4 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 5 * Copyright (C) 2005 Nokia Corporation 6 + * Copyright (C) 2004 - 2007 Texas Instruments. 10 7 * 11 - * Cleaned up by Juha Yrjölä <juha.yrjola@nokia.com> 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> 12 15 * 13 16 * This program is free software; you can redistribute it and/or modify 14 17 * it under the terms of the GNU General Public License as published by ··· 36 33 #include <linux/completion.h> 37 34 #include <linux/platform_device.h> 38 35 #include <linux/clk.h> 36 + #include <linux/io.h> 39 37 40 - #include <asm/io.h> 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 41 44 42 45 /* timeout waiting for the controller to respond */ 43 46 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) ··· 52 43 #define OMAP_I2C_IE_REG 0x04 53 44 #define OMAP_I2C_STAT_REG 0x08 54 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 55 48 #define OMAP_I2C_SYSS_REG 0x10 56 49 #define OMAP_I2C_BUF_REG 0x14 57 50 #define OMAP_I2C_CNT_REG 0x18 ··· 66 55 #define OMAP_I2C_SCLL_REG 0x34 67 56 #define OMAP_I2C_SCLH_REG 0x38 68 57 #define OMAP_I2C_SYSTEST_REG 0x3c 58 + #define OMAP_I2C_BUFSTAT_REG 0x40 69 59 70 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 */ 71 63 #define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */ 72 64 #define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */ 73 65 #define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */ ··· 78 64 #define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */ 79 65 80 66 /* I2C Status Register (OMAP_I2C_STAT): */ 81 - #define OMAP_I2C_STAT_SBD (1 << 15) /* Single byte data */ 67 + #define OMAP_I2C_STAT_XDR (1 << 14) /* TX Buffer draining */ 68 + #define OMAP_I2C_STAT_RDR (1 << 13) /* RX Buffer draining */ 82 69 #define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */ 83 70 #define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */ 84 71 #define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */ ··· 91 76 #define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */ 92 77 #define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */ 93 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 + 94 97 /* I2C Buffer Configuration Register (OMAP_I2C_BUF): */ 95 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 */ 96 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 */ 97 102 98 103 /* I2C Configuration Register (OMAP_I2C_CON): */ 99 104 #define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */ 100 105 #define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */ 106 + #define OMAP_I2C_CON_OPMODE_HS (1 << 12) /* High Speed support */ 101 107 #define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */ 102 108 #define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */ 103 109 #define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */ ··· 126 90 #define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */ 127 91 #define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */ 128 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 129 97 130 98 /* I2C System Test Register (OMAP_I2C_SYSTEST): */ 131 99 #ifdef DEBUG ··· 143 103 #define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */ 144 104 #endif 145 105 146 - /* I2C System Status register (OMAP_I2C_SYSS): */ 147 - #define OMAP_I2C_SYSS_RDONE (1 << 0) /* Reset Done */ 106 + /* OCP_SYSSTATUS bit definitions */ 107 + #define SYSS_RESETDONE_MASK (1 << 0) 148 108 149 - /* I2C System Configuration Register (OMAP_I2C_SYSC): */ 150 - #define OMAP_I2C_SYSC_SRST (1 << 1) /* Soft Reset */ 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) 151 115 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)"); 116 + #define SYSC_IDLEMODE_SMART 0x2 117 + #define SYSC_CLOCKACTIVITY_FCLK 0x2 118 + 157 119 158 120 struct omap_i2c_dev { 159 121 struct device *dev; ··· 165 123 struct clk *fclk; /* Functional clock */ 166 124 struct completion cmd_complete; 167 125 struct resource *ioarea; 126 + u32 speed; /* Speed of bus in Khz */ 168 127 u16 cmd_err; 169 128 u8 *buf; 170 129 size_t buf_len; 171 130 struct i2c_adapter adapter; 172 - unsigned rev1:1; 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 */ 173 137 unsigned idle:1; 174 138 u16 iestate; /* Saved interrupt register */ 175 139 }; ··· 191 143 return __raw_readw(i2c_dev->base + reg); 192 144 } 193 145 194 - static int omap_i2c_get_clocks(struct omap_i2c_dev *dev) 146 + static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev) 195 147 { 196 - if (cpu_is_omap16xx() || cpu_is_omap24xx()) { 148 + if (cpu_is_omap16xx() || cpu_class_is_omap2()) { 197 149 dev->iclk = clk_get(dev->dev, "i2c_ick"); 198 150 if (IS_ERR(dev->iclk)) { 199 151 dev->iclk = NULL; ··· 226 178 227 179 static void omap_i2c_unidle(struct omap_i2c_dev *dev) 228 180 { 181 + WARN_ON(!dev->idle); 182 + 229 183 if (dev->iclk != NULL) 230 184 clk_enable(dev->iclk); 231 185 clk_enable(dev->fclk); 186 + dev->idle = 0; 232 187 if (dev->iestate) 233 188 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); 234 - dev->idle = 0; 235 189 } 236 190 237 191 static void omap_i2c_idle(struct omap_i2c_dev *dev) 238 192 { 239 193 u16 iv; 240 194 241 - dev->idle = 1; 195 + WARN_ON(dev->idle); 196 + 242 197 dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 243 198 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 199 + if (dev->rev < OMAP_I2C_REV_2) { 200 + iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ 201 + } else { 247 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; 248 208 clk_disable(dev->fclk); 249 209 if (dev->iclk != NULL) 250 210 clk_disable(dev->iclk); ··· 260 204 261 205 static int omap_i2c_init(struct omap_i2c_dev *dev) 262 206 { 263 - u16 psc = 0; 207 + u16 psc = 0, scll = 0, sclh = 0; 208 + u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; 264 209 unsigned long fclk_rate = 12000000; 265 210 unsigned long timeout; 211 + unsigned long internal_clk = 0; 266 212 267 - if (!dev->rev1) { 268 - omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST); 213 + if (dev->rev >= OMAP_I2C_REV_2) { 214 + omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK); 269 215 /* For some reason we need to set the EN bit before the 270 216 * reset done bit gets set. */ 271 217 timeout = jiffies + OMAP_I2C_TIMEOUT; 272 218 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 273 219 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) & 274 - OMAP_I2C_SYSS_RDONE)) { 220 + SYSS_RESETDONE_MASK)) { 275 221 if (time_after(jiffies, timeout)) { 276 222 dev_warn(dev->dev, "timeout waiting " 277 223 "for controller reset\n"); 278 224 return -ETIMEDOUT; 279 225 } 280 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 + 281 254 } 282 255 } 283 256 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); ··· 334 249 psc = fclk_rate / 12000000; 335 250 } 336 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 + 337 287 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 338 288 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc); 339 289 340 - /* Program desired operating rate */ 341 - fclk_rate /= (psc + 1) * 1000; 342 - if (psc > 2) 343 - psc = 2; 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); 344 293 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); 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); 349 301 350 302 /* Take the I2C module out of reset: */ 351 303 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 352 304 353 305 /* Enable interrupts */ 354 306 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)); 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)); 358 311 return 0; 359 312 } 360 313 ··· 439 316 440 317 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len); 441 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 + 442 324 init_completion(&dev->cmd_complete); 443 325 dev->cmd_err = 0; 444 326 445 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 + 446 333 if (msg->flags & I2C_M_TEN) 447 334 w |= OMAP_I2C_CON_XA; 448 335 if (!(msg->flags & I2C_M_RD)) 449 336 w |= OMAP_I2C_CON_TRX; 450 - if (stop) 337 + 338 + if (!dev->b_hw && stop) 451 339 w |= OMAP_I2C_CON_STP; 340 + 452 341 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 453 342 454 - r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 455 - OMAP_I2C_TIMEOUT); 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); 456 372 dev->buf_len = 0; 457 373 if (r < 0) 458 374 return r; ··· 538 376 539 377 omap_i2c_unidle(dev); 540 378 541 - if ((r = omap_i2c_wait_for_bb(dev)) < 0) 379 + r = omap_i2c_wait_for_bb(dev); 380 + if (r < 0) 542 381 goto out; 543 382 544 383 for (i = 0; i < num; i++) { ··· 573 410 { 574 411 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 575 412 } 413 + 414 + /* rev1 devices are apparently only on some 15xx */ 415 + #ifdef CONFIG_ARCH_OMAP15XX 576 416 577 417 static irqreturn_t 578 418 omap_i2c_rev1_isr(int this_irq, void *dev_id) ··· 631 465 632 466 return IRQ_HANDLED; 633 467 } 468 + #else 469 + #define omap_i2c_rev1_isr NULL 470 + #endif 634 471 635 472 static irqreturn_t 636 473 omap_i2c_isr(int this_irq, void *dev_id) ··· 641 472 struct omap_i2c_dev *dev = dev_id; 642 473 u16 bits; 643 474 u16 stat, w; 644 - int count = 0; 475 + int err, count = 0; 645 476 646 477 if (dev->idle) 647 478 return IRQ_NONE; ··· 656 487 657 488 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 658 489 659 - if (stat & OMAP_I2C_STAT_ARDY) { 660 - omap_i2c_complete_cmd(dev, 0); 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)); 661 540 continue; 662 541 } 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--; 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; 668 554 if (dev->buf_len) { 669 - *dev->buf++ = w >> 8; 555 + w = *dev->buf++; 670 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; 671 575 } 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); 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)); 692 580 continue; 693 581 } 694 582 if (stat & OMAP_I2C_STAT_ROVR) { ··· 753 527 dev->cmd_err |= OMAP_I2C_STAT_ROVR; 754 528 } 755 529 if (stat & OMAP_I2C_STAT_XUDF) { 756 - dev_err(dev->dev, "Transmit overflow\n"); 530 + dev_err(dev->dev, "Transmit underflow\n"); 757 531 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 532 } 768 533 } 769 534 ··· 766 549 .functionality = omap_i2c_func, 767 550 }; 768 551 769 - static int 552 + static int __init 770 553 omap_i2c_probe(struct platform_device *pdev) 771 554 { 772 555 struct omap_i2c_dev *dev; 773 556 struct i2c_adapter *adap; 774 557 struct resource *mem, *irq, *ioarea; 558 + irq_handler_t isr; 775 559 int r; 560 + u32 speed = 0; 776 561 777 562 /* NOTE: driver uses the static register mapping */ 778 563 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 795 576 return -EBUSY; 796 577 } 797 578 798 - if (clock > 200) 799 - clock = 400; /* Fast mode */ 800 - else 801 - clock = 100; /* Standard mode */ 802 - 803 579 dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL); 804 580 if (!dev) { 805 581 r = -ENOMEM; 806 582 goto err_release_region; 807 583 } 808 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; 809 592 dev->dev = &pdev->dev; 810 593 dev->irq = irq->start; 811 594 dev->base = ioremap(mem->start, mem->end - mem->start + 1); ··· 823 602 824 603 omap_i2c_unidle(dev); 825 604 826 - if (cpu_is_omap15xx()) 827 - dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20; 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 + } 828 622 829 623 /* reset ASAP, clearing any IRQs */ 830 624 omap_i2c_init(dev); 831 625 832 - r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr, 833 - 0, pdev->name, dev); 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); 834 628 835 629 if (r) { 836 630 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); 837 631 goto err_unuse_clocks; 838 632 } 839 - r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 633 + 840 634 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", 841 - pdev->id, r >> 4, r & 0xf, clock); 635 + pdev->id, dev->rev >> 4, dev->rev & 0xf, dev->speed); 636 + 637 + omap_i2c_idle(dev); 842 638 843 639 adap = &dev->adapter; 844 640 i2c_set_adapdata(adap, dev); ··· 872 634 dev_err(dev->dev, "failure adding adapter\n"); 873 635 goto err_free_irq; 874 636 } 875 - 876 - omap_i2c_idle(dev); 877 637 878 638 return 0; 879 639
+78 -107
drivers/i2c/busses/i2c-s3c2410.c
··· 35 35 #include <linux/clk.h> 36 36 #include <linux/cpufreq.h> 37 37 38 - #include <mach/hardware.h> 39 38 #include <asm/irq.h> 40 39 #include <asm/io.h> 41 40 42 - #include <mach/regs-gpio.h> 43 41 #include <plat/regs-iic.h> 44 42 #include <plat/iic.h> 45 43 ··· 62 64 unsigned int msg_ptr; 63 65 64 66 unsigned int tx_setup; 67 + unsigned int irq; 65 68 66 69 enum s3c24xx_i2c_state state; 67 70 unsigned long clkrate; ··· 70 71 void __iomem *regs; 71 72 struct clk *clk; 72 73 struct device *dev; 73 - struct resource *irq; 74 74 struct resource *ioarea; 75 75 struct i2c_adapter adap; 76 76 ··· 78 80 #endif 79 81 }; 80 82 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 - }; 83 + /* default platform data removed, dev should always carry data. */ 91 84 92 85 /* s3c24xx_i2c_is2440() 93 86 * ··· 90 101 struct platform_device *pdev = to_platform_device(i2c->dev); 91 102 92 103 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 104 } 109 105 110 106 /* s3c24xx_i2c_master_complete ··· 104 130 105 131 i2c->msg_ptr = 0; 106 132 i2c->msg = NULL; 107 - i2c->msg_idx ++; 133 + i2c->msg_idx++; 108 134 i2c->msg_num = 0; 109 135 if (ret) 110 136 i2c->msg_idx = ret; ··· 115 141 static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) 116 142 { 117 143 unsigned long tmp; 118 - 144 + 119 145 tmp = readl(i2c->regs + S3C2410_IICCON); 120 146 writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); 121 - 122 147 } 123 148 124 149 static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) 125 150 { 126 151 unsigned long tmp; 127 - 152 + 128 153 tmp = readl(i2c->regs + S3C2410_IICCON); 129 154 writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); 130 - 131 155 } 132 156 133 157 /* irq enable/disable functions */ ··· 133 161 static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) 134 162 { 135 163 unsigned long tmp; 136 - 164 + 137 165 tmp = readl(i2c->regs + S3C2410_IICCON); 138 166 writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); 139 167 } ··· 141 169 static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) 142 170 { 143 171 unsigned long tmp; 144 - 172 + 145 173 tmp = readl(i2c->regs + S3C2410_IICCON); 146 174 writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); 147 175 } ··· 149 177 150 178 /* s3c24xx_i2c_message_start 151 179 * 152 - * put the start of a message onto the bus 180 + * put the start of a message onto the bus 153 181 */ 154 182 155 - static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, 183 + static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, 156 184 struct i2c_msg *msg) 157 185 { 158 186 unsigned int addr = (msg->addr & 0x7f) << 1; ··· 171 199 if (msg->flags & I2C_M_REV_DIR_ADDR) 172 200 addr ^= 1; 173 201 174 - // todo - check for wether ack wanted or not 202 + /* todo - check for wether ack wanted or not */ 175 203 s3c24xx_i2c_enable_ack(i2c); 176 204 177 205 iiccon = readl(i2c->regs + S3C2410_IICCON); 178 206 writel(stat, i2c->regs + S3C2410_IICSTAT); 179 - 207 + 180 208 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); 181 209 writeb(addr, i2c->regs + S3C2410_IICDS); 182 - 210 + 183 211 /* delay here to ensure the data byte has gotten onto the bus 184 212 * before the transaction is started */ 185 213 ··· 187 215 188 216 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); 189 217 writel(iiccon, i2c->regs + S3C2410_IICCON); 190 - 191 - stat |= S3C2410_IICSTAT_START; 218 + 219 + stat |= S3C2410_IICSTAT_START; 192 220 writel(stat, i2c->regs + S3C2410_IICSTAT); 193 221 } 194 222 ··· 199 227 dev_dbg(i2c->dev, "STOP\n"); 200 228 201 229 /* stop the transfer */ 202 - iicstat &= ~ S3C2410_IICSTAT_START; 230 + iicstat &= ~S3C2410_IICSTAT_START; 203 231 writel(iicstat, i2c->regs + S3C2410_IICSTAT); 204 - 232 + 205 233 i2c->state = STATE_STOP; 206 - 234 + 207 235 s3c24xx_i2c_master_complete(i2c, ret); 208 236 s3c24xx_i2c_disable_irq(i2c); 209 237 } ··· 213 241 214 242 /* is_lastmsg() 215 243 * 216 - * returns TRUE if the current message is the last in the set 244 + * returns TRUE if the current message is the last in the set 217 245 */ 218 246 219 247 static inline int is_lastmsg(struct s3c24xx_i2c *i2c) ··· 261 289 262 290 case STATE_STOP: 263 291 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); 264 - s3c24xx_i2c_disable_irq(i2c); 292 + s3c24xx_i2c_disable_irq(i2c); 265 293 goto out_ack; 266 294 267 295 case STATE_START: 268 296 /* last thing we did was send a start condition on the 269 297 * bus, or started a new i2c message 270 298 */ 271 - 299 + 272 300 if (iicstat & S3C2410_IICSTAT_LASTBIT && 273 301 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 274 302 /* ack was not received... */ ··· 294 322 if (i2c->state == STATE_READ) 295 323 goto prepare_read; 296 324 297 - /* fall through to the write state, as we will need to 325 + /* fall through to the write state, as we will need to 298 326 * send a byte as well */ 299 327 300 328 case STATE_WRITE: ··· 311 339 } 312 340 } 313 341 314 - retry_write: 342 + retry_write: 315 343 316 344 if (!is_msgend(i2c)) { 317 345 byte = i2c->msg->buf[i2c->msg_ptr++]; ··· 331 359 dev_dbg(i2c->dev, "WRITE: Next Message\n"); 332 360 333 361 i2c->msg_ptr = 0; 334 - i2c->msg_idx ++; 362 + i2c->msg_idx++; 335 363 i2c->msg++; 336 - 364 + 337 365 /* check to see if we need to do another message */ 338 366 if (i2c->msg->flags & I2C_M_NOSTART) { 339 367 ··· 347 375 348 376 goto retry_write; 349 377 } else { 350 - 351 378 /* send the new start */ 352 379 s3c24xx_i2c_message_start(i2c, i2c->msg); 353 380 i2c->state = STATE_START; ··· 360 389 break; 361 390 362 391 case STATE_READ: 363 - /* we have a byte of data in the data register, do 392 + /* we have a byte of data in the data register, do 364 393 * something with it, and then work out wether we are 365 394 * going to do any more read/write 366 395 */ ··· 368 397 byte = readb(i2c->regs + S3C2410_IICDS); 369 398 i2c->msg->buf[i2c->msg_ptr++] = byte; 370 399 371 - prepare_read: 400 + prepare_read: 372 401 if (is_msglast(i2c)) { 373 402 /* last byte of buffer */ 374 403 375 404 if (is_lastmsg(i2c)) 376 405 s3c24xx_i2c_disable_ack(i2c); 377 - 406 + 378 407 } else if (is_msgend(i2c)) { 379 408 /* ok, we've read the entire buffer, see if there 380 409 * is anything else we need to do */ ··· 400 429 /* acknowlegde the IRQ and get back on with the work */ 401 430 402 431 out_ack: 403 - tmp = readl(i2c->regs + S3C2410_IICCON); 432 + tmp = readl(i2c->regs + S3C2410_IICCON); 404 433 tmp &= ~S3C2410_IICCON_IRQPEND; 405 434 writel(tmp, i2c->regs + S3C2410_IICCON); 406 435 out: ··· 421 450 status = readl(i2c->regs + S3C2410_IICSTAT); 422 451 423 452 if (status & S3C2410_IICSTAT_ARBITR) { 424 - // deal with arbitration loss 453 + /* deal with arbitration loss */ 425 454 dev_err(i2c->dev, "deal with arbitration loss\n"); 426 455 } 427 456 428 457 if (i2c->state == STATE_IDLE) { 429 458 dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); 430 459 431 - tmp = readl(i2c->regs + S3C2410_IICCON); 460 + tmp = readl(i2c->regs + S3C2410_IICCON); 432 461 tmp &= ~S3C2410_IICCON_IRQPEND; 433 462 writel(tmp, i2c->regs + S3C2410_IICCON); 434 463 goto out; 435 464 } 436 - 465 + 437 466 /* pretty much this leaves us with the fact that we've 438 467 * transmitted or received whatever byte we last sent */ 439 468 ··· 456 485 457 486 while (timeout-- > 0) { 458 487 iicstat = readl(i2c->regs + S3C2410_IICSTAT); 459 - 488 + 460 489 if (!(iicstat & S3C2410_IICSTAT_BUSBUSY)) 461 490 return 0; 462 491 463 492 msleep(1); 464 493 } 465 - 466 - dev_dbg(i2c->dev, "timeout: GPEDAT is %08x\n", 467 - __raw_readl(S3C2410_GPEDAT)); 468 494 469 495 return -ETIMEDOUT; 470 496 } ··· 471 503 * this starts an i2c transfer 472 504 */ 473 505 474 - static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num) 506 + static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, 507 + struct i2c_msg *msgs, int num) 475 508 { 476 509 unsigned long timeout; 477 510 int ret; ··· 498 529 s3c24xx_i2c_enable_irq(i2c); 499 530 s3c24xx_i2c_message_start(i2c, msgs); 500 531 spin_unlock_irq(&i2c->lock); 501 - 532 + 502 533 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 503 534 504 535 ret = i2c->msg_idx; 505 536 506 - /* having these next two as dev_err() makes life very 537 + /* having these next two as dev_err() makes life very 507 538 * noisy when doing an i2cdetect */ 508 539 509 540 if (timeout == 0) ··· 560 591 .functionality = s3c24xx_i2c_func, 561 592 }; 562 593 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 594 /* s3c24xx_i2c_calcdivisor 577 595 * 578 596 * return the divisor settings for a given frequency ··· 599 643 { 600 644 int diff = freq - wanted; 601 645 602 - return (diff >= -2 && diff <= 2); 646 + return diff >= -2 && diff <= 2; 603 647 } 604 648 605 649 /* s3c24xx_i2c_clockrate ··· 611 655 612 656 static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) 613 657 { 614 - struct s3c2410_platform_i2c *pdata; 658 + struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data; 615 659 unsigned long clkin = clk_get_rate(i2c->clk); 616 660 unsigned int divs, div1; 617 661 u32 iiccon; ··· 619 663 int start, end; 620 664 621 665 i2c->clkrate = clkin; 622 - 623 - pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent); 624 666 clkin /= 1000; /* clkin now in KHz */ 625 - 667 + 626 668 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", 627 669 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); 628 670 ··· 728 774 729 775 /* s3c24xx_i2c_init 730 776 * 731 - * initialise the controller, set the IO lines and frequency 777 + * initialise the controller, set the IO lines and frequency 732 778 */ 733 779 734 780 static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) ··· 739 785 740 786 /* get the plafrom data */ 741 787 742 - pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent); 788 + pdata = i2c->dev->platform_data; 743 789 744 790 /* inititalise the gpio */ 745 791 746 - s3c2410_gpio_cfgpin(S3C2410_GPE15, S3C2410_GPE15_IICSDA); 747 - s3c2410_gpio_cfgpin(S3C2410_GPE14, S3C2410_GPE14_IICSCL); 792 + if (pdata->cfg_gpio) 793 + pdata->cfg_gpio(to_platform_device(i2c->dev)); 748 794 749 795 /* write slave address */ 750 - 796 + 751 797 writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); 752 798 753 799 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); ··· 785 831 786 832 static int s3c24xx_i2c_probe(struct platform_device *pdev) 787 833 { 788 - struct s3c24xx_i2c *i2c = &s3c24xx_i2c; 834 + struct s3c24xx_i2c *i2c; 789 835 struct s3c2410_platform_i2c *pdata; 790 836 struct resource *res; 791 837 int ret; 792 838 793 - pdata = s3c24xx_i2c_get_platformdata(&pdev->dev); 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); 794 860 795 861 /* find the clock and enable it */ 796 862 ··· 852 878 goto err_ioarea; 853 879 } 854 880 855 - dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); 881 + dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", 882 + i2c->regs, i2c->ioarea, res); 856 883 857 884 /* setup info block for the i2c core */ 858 885 ··· 867 892 goto err_iomap; 868 893 869 894 /* find the IRQ for this unit (note, this relies on the init call to 870 - * ensure no current IRQs pending 895 + * ensure no current IRQs pending 871 896 */ 872 897 873 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 874 - if (res == NULL) { 898 + i2c->irq = ret = platform_get_irq(pdev, 0); 899 + if (ret <= 0) { 875 900 dev_err(&pdev->dev, "cannot find IRQ\n"); 876 - ret = -ENOENT; 877 901 goto err_iomap; 878 902 } 879 903 880 - ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, 881 - pdev->name, i2c); 904 + ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED, 905 + dev_name(&pdev->dev), i2c); 882 906 883 907 if (ret != 0) { 884 - dev_err(&pdev->dev, "cannot claim IRQ\n"); 908 + dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); 885 909 goto err_iomap; 886 910 } 887 - 888 - i2c->irq = res; 889 - 890 - dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res, 891 - (unsigned long)res->start); 892 911 893 912 ret = s3c24xx_i2c_register_cpufreq(i2c); 894 913 if (ret < 0) { ··· 913 944 s3c24xx_i2c_deregister_cpufreq(i2c); 914 945 915 946 err_irq: 916 - free_irq(i2c->irq->start, i2c); 947 + free_irq(i2c->irq, i2c); 917 948 918 949 err_iomap: 919 950 iounmap(i2c->regs); ··· 927 958 clk_put(i2c->clk); 928 959 929 960 err_noclk: 961 + kfree(i2c); 930 962 return ret; 931 963 } 932 964 ··· 943 973 s3c24xx_i2c_deregister_cpufreq(i2c); 944 974 945 975 i2c_del_adapter(&i2c->adap); 946 - free_irq(i2c->irq->start, i2c); 976 + free_irq(i2c->irq, i2c); 947 977 948 978 clk_disable(i2c->clk); 949 979 clk_put(i2c->clk); ··· 952 982 953 983 release_resource(i2c->ioarea); 954 984 kfree(i2c->ioarea); 985 + kfree(i2c); 955 986 956 987 return 0; 957 988 }