diff options
| -rw-r--r-- | drivers/i2c/busses/i2c-designware.c | 488 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 64 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-pnx.c | 3 |
3 files changed, 398 insertions, 157 deletions
diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c index b444762e9b9f..9e18ef97f156 100644 --- a/drivers/i2c/busses/i2c-designware.c +++ b/drivers/i2c/busses/i2c-designware.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Synopsys Designware I2C adapter driver (master only). | 2 | * Synopsys DesignWare I2C adapter driver (master only). |
| 3 | * | 3 | * |
| 4 | * Based on the TI DAVINCI I2C adapter driver. | 4 | * Based on the TI DAVINCI I2C adapter driver. |
| 5 | * | 5 | * |
| @@ -49,7 +49,20 @@ | |||
| 49 | #define DW_IC_FS_SCL_LCNT 0x20 | 49 | #define DW_IC_FS_SCL_LCNT 0x20 |
| 50 | #define DW_IC_INTR_STAT 0x2c | 50 | #define DW_IC_INTR_STAT 0x2c |
| 51 | #define DW_IC_INTR_MASK 0x30 | 51 | #define DW_IC_INTR_MASK 0x30 |
| 52 | #define DW_IC_RAW_INTR_STAT 0x34 | ||
| 53 | #define DW_IC_RX_TL 0x38 | ||
| 54 | #define DW_IC_TX_TL 0x3c | ||
| 52 | #define DW_IC_CLR_INTR 0x40 | 55 | #define DW_IC_CLR_INTR 0x40 |
| 56 | #define DW_IC_CLR_RX_UNDER 0x44 | ||
| 57 | #define DW_IC_CLR_RX_OVER 0x48 | ||
| 58 | #define DW_IC_CLR_TX_OVER 0x4c | ||
| 59 | #define DW_IC_CLR_RD_REQ 0x50 | ||
| 60 | #define DW_IC_CLR_TX_ABRT 0x54 | ||
| 61 | #define DW_IC_CLR_RX_DONE 0x58 | ||
| 62 | #define DW_IC_CLR_ACTIVITY 0x5c | ||
| 63 | #define DW_IC_CLR_STOP_DET 0x60 | ||
| 64 | #define DW_IC_CLR_START_DET 0x64 | ||
| 65 | #define DW_IC_CLR_GEN_CALL 0x68 | ||
| 53 | #define DW_IC_ENABLE 0x6c | 66 | #define DW_IC_ENABLE 0x6c |
| 54 | #define DW_IC_STATUS 0x70 | 67 | #define DW_IC_STATUS 0x70 |
| 55 | #define DW_IC_TXFLR 0x74 | 68 | #define DW_IC_TXFLR 0x74 |
| @@ -64,9 +77,23 @@ | |||
| 64 | #define DW_IC_CON_RESTART_EN 0x20 | 77 | #define DW_IC_CON_RESTART_EN 0x20 |
| 65 | #define DW_IC_CON_SLAVE_DISABLE 0x40 | 78 | #define DW_IC_CON_SLAVE_DISABLE 0x40 |
| 66 | 79 | ||
| 67 | #define DW_IC_INTR_TX_EMPTY 0x10 | 80 | #define DW_IC_INTR_RX_UNDER 0x001 |
| 68 | #define DW_IC_INTR_TX_ABRT 0x40 | 81 | #define DW_IC_INTR_RX_OVER 0x002 |
| 82 | #define DW_IC_INTR_RX_FULL 0x004 | ||
| 83 | #define DW_IC_INTR_TX_OVER 0x008 | ||
| 84 | #define DW_IC_INTR_TX_EMPTY 0x010 | ||
| 85 | #define DW_IC_INTR_RD_REQ 0x020 | ||
| 86 | #define DW_IC_INTR_TX_ABRT 0x040 | ||
| 87 | #define DW_IC_INTR_RX_DONE 0x080 | ||
| 88 | #define DW_IC_INTR_ACTIVITY 0x100 | ||
| 69 | #define DW_IC_INTR_STOP_DET 0x200 | 89 | #define DW_IC_INTR_STOP_DET 0x200 |
| 90 | #define DW_IC_INTR_START_DET 0x400 | ||
| 91 | #define DW_IC_INTR_GEN_CALL 0x800 | ||
| 92 | |||
| 93 | #define DW_IC_INTR_DEFAULT_MASK (DW_IC_INTR_RX_FULL | \ | ||
| 94 | DW_IC_INTR_TX_EMPTY | \ | ||
| 95 | DW_IC_INTR_TX_ABRT | \ | ||
| 96 | DW_IC_INTR_STOP_DET) | ||
| 70 | 97 | ||
| 71 | #define DW_IC_STATUS_ACTIVITY 0x1 | 98 | #define DW_IC_STATUS_ACTIVITY 0x1 |
| 72 | 99 | ||
| @@ -96,31 +123,49 @@ | |||
| 96 | #define ABRT_SBYTE_ACKDET 7 | 123 | #define ABRT_SBYTE_ACKDET 7 |
| 97 | #define ABRT_SBYTE_NORSTRT 9 | 124 | #define ABRT_SBYTE_NORSTRT 9 |
| 98 | #define ABRT_10B_RD_NORSTRT 10 | 125 | #define ABRT_10B_RD_NORSTRT 10 |
| 99 | #define ARB_MASTER_DIS 11 | 126 | #define ABRT_MASTER_DIS 11 |
| 100 | #define ARB_LOST 12 | 127 | #define ARB_LOST 12 |
| 101 | 128 | ||
| 129 | #define DW_IC_TX_ABRT_7B_ADDR_NOACK (1UL << ABRT_7B_ADDR_NOACK) | ||
| 130 | #define DW_IC_TX_ABRT_10ADDR1_NOACK (1UL << ABRT_10ADDR1_NOACK) | ||
| 131 | #define DW_IC_TX_ABRT_10ADDR2_NOACK (1UL << ABRT_10ADDR2_NOACK) | ||
| 132 | #define DW_IC_TX_ABRT_TXDATA_NOACK (1UL << ABRT_TXDATA_NOACK) | ||
| 133 | #define DW_IC_TX_ABRT_GCALL_NOACK (1UL << ABRT_GCALL_NOACK) | ||
| 134 | #define DW_IC_TX_ABRT_GCALL_READ (1UL << ABRT_GCALL_READ) | ||
| 135 | #define DW_IC_TX_ABRT_SBYTE_ACKDET (1UL << ABRT_SBYTE_ACKDET) | ||
| 136 | #define DW_IC_TX_ABRT_SBYTE_NORSTRT (1UL << ABRT_SBYTE_NORSTRT) | ||
| 137 | #define DW_IC_TX_ABRT_10B_RD_NORSTRT (1UL << ABRT_10B_RD_NORSTRT) | ||
| 138 | #define DW_IC_TX_ABRT_MASTER_DIS (1UL << ABRT_MASTER_DIS) | ||
| 139 | #define DW_IC_TX_ARB_LOST (1UL << ARB_LOST) | ||
| 140 | |||
| 141 | #define DW_IC_TX_ABRT_NOACK (DW_IC_TX_ABRT_7B_ADDR_NOACK | \ | ||
| 142 | DW_IC_TX_ABRT_10ADDR1_NOACK | \ | ||
| 143 | DW_IC_TX_ABRT_10ADDR2_NOACK | \ | ||
| 144 | DW_IC_TX_ABRT_TXDATA_NOACK | \ | ||
| 145 | DW_IC_TX_ABRT_GCALL_NOACK) | ||
| 146 | |||
| 102 | static char *abort_sources[] = { | 147 | static char *abort_sources[] = { |
| 103 | [ABRT_7B_ADDR_NOACK] = | 148 | [ABRT_7B_ADDR_NOACK] = |
| 104 | "slave address not acknowledged (7bit mode)", | 149 | "slave address not acknowledged (7bit mode)", |
| 105 | [ABRT_10ADDR1_NOACK] = | 150 | [ABRT_10ADDR1_NOACK] = |
| 106 | "first address byte not acknowledged (10bit mode)", | 151 | "first address byte not acknowledged (10bit mode)", |
| 107 | [ABRT_10ADDR2_NOACK] = | 152 | [ABRT_10ADDR2_NOACK] = |
| 108 | "second address byte not acknowledged (10bit mode)", | 153 | "second address byte not acknowledged (10bit mode)", |
| 109 | [ABRT_TXDATA_NOACK] = | 154 | [ABRT_TXDATA_NOACK] = |
| 110 | "data not acknowledged", | 155 | "data not acknowledged", |
| 111 | [ABRT_GCALL_NOACK] = | 156 | [ABRT_GCALL_NOACK] = |
| 112 | "no acknowledgement for a general call", | 157 | "no acknowledgement for a general call", |
| 113 | [ABRT_GCALL_READ] = | 158 | [ABRT_GCALL_READ] = |
| 114 | "read after general call", | 159 | "read after general call", |
| 115 | [ABRT_SBYTE_ACKDET] = | 160 | [ABRT_SBYTE_ACKDET] = |
| 116 | "start byte acknowledged", | 161 | "start byte acknowledged", |
| 117 | [ABRT_SBYTE_NORSTRT] = | 162 | [ABRT_SBYTE_NORSTRT] = |
| 118 | "trying to send start byte when restart is disabled", | 163 | "trying to send start byte when restart is disabled", |
| 119 | [ABRT_10B_RD_NORSTRT] = | 164 | [ABRT_10B_RD_NORSTRT] = |
| 120 | "trying to read when restart is disabled (10bit mode)", | 165 | "trying to read when restart is disabled (10bit mode)", |
| 121 | [ARB_MASTER_DIS] = | 166 | [ABRT_MASTER_DIS] = |
| 122 | "trying to use disabled adapter", | 167 | "trying to use disabled adapter", |
| 123 | [ARB_LOST] = | 168 | [ARB_LOST] = |
| 124 | "lost arbitration", | 169 | "lost arbitration", |
| 125 | }; | 170 | }; |
| 126 | 171 | ||
| @@ -129,7 +174,6 @@ static char *abort_sources[] = { | |||
| 129 | * @dev: driver model device node | 174 | * @dev: driver model device node |
| 130 | * @base: IO registers pointer | 175 | * @base: IO registers pointer |
| 131 | * @cmd_complete: tx completion indicator | 176 | * @cmd_complete: tx completion indicator |
| 132 | * @pump_msg: continue in progress transfers | ||
| 133 | * @lock: protect this struct and IO registers | 177 | * @lock: protect this struct and IO registers |
| 134 | * @clk: input reference clock | 178 | * @clk: input reference clock |
| 135 | * @cmd_err: run time hadware error code | 179 | * @cmd_err: run time hadware error code |
| @@ -155,27 +199,81 @@ struct dw_i2c_dev { | |||
| 155 | struct device *dev; | 199 | struct device *dev; |
| 156 | void __iomem *base; | 200 | void __iomem *base; |
| 157 | struct completion cmd_complete; | 201 | struct completion cmd_complete; |
| 158 | struct tasklet_struct pump_msg; | ||
| 159 | struct mutex lock; | 202 | struct mutex lock; |
| 160 | struct clk *clk; | 203 | struct clk *clk; |
| 161 | int cmd_err; | 204 | int cmd_err; |
| 162 | struct i2c_msg *msgs; | 205 | struct i2c_msg *msgs; |
| 163 | int msgs_num; | 206 | int msgs_num; |
| 164 | int msg_write_idx; | 207 | int msg_write_idx; |
| 165 | u16 tx_buf_len; | 208 | u32 tx_buf_len; |
| 166 | u8 *tx_buf; | 209 | u8 *tx_buf; |
| 167 | int msg_read_idx; | 210 | int msg_read_idx; |
| 168 | u16 rx_buf_len; | 211 | u32 rx_buf_len; |
| 169 | u8 *rx_buf; | 212 | u8 *rx_buf; |
| 170 | int msg_err; | 213 | int msg_err; |
| 171 | unsigned int status; | 214 | unsigned int status; |
| 172 | u16 abort_source; | 215 | u32 abort_source; |
| 173 | int irq; | 216 | int irq; |
| 174 | struct i2c_adapter adapter; | 217 | struct i2c_adapter adapter; |
| 175 | unsigned int tx_fifo_depth; | 218 | unsigned int tx_fifo_depth; |
| 176 | unsigned int rx_fifo_depth; | 219 | unsigned int rx_fifo_depth; |
| 177 | }; | 220 | }; |
| 178 | 221 | ||
| 222 | static u32 | ||
| 223 | i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) | ||
| 224 | { | ||
| 225 | /* | ||
| 226 | * DesignWare I2C core doesn't seem to have solid strategy to meet | ||
| 227 | * the tHD;STA timing spec. Configuring _HCNT based on tHIGH spec | ||
| 228 | * will result in violation of the tHD;STA spec. | ||
| 229 | */ | ||
| 230 | if (cond) | ||
| 231 | /* | ||
| 232 | * Conditional expression: | ||
| 233 | * | ||
| 234 | * IC_[FS]S_SCL_HCNT + (1+4+3) >= IC_CLK * tHIGH | ||
| 235 | * | ||
| 236 | * This is based on the DW manuals, and represents an ideal | ||
| 237 | * configuration. The resulting I2C bus speed will be | ||
| 238 | * faster than any of the others. | ||
| 239 | * | ||
| 240 | * If your hardware is free from tHD;STA issue, try this one. | ||
| 241 | */ | ||
| 242 | return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset; | ||
| 243 | else | ||
| 244 | /* | ||
| 245 | * Conditional expression: | ||
| 246 | * | ||
| 247 | * IC_[FS]S_SCL_HCNT + 3 >= IC_CLK * (tHD;STA + tf) | ||
| 248 | * | ||
| 249 | * This is just experimental rule; the tHD;STA period turned | ||
| 250 | * out to be proportinal to (_HCNT + 3). With this setting, | ||
| 251 | * we could meet both tHIGH and tHD;STA timing specs. | ||
| 252 | * | ||
| 253 | * If unsure, you'd better to take this alternative. | ||
| 254 | * | ||
| 255 | * The reason why we need to take into account "tf" here, | ||
| 256 | * is the same as described in i2c_dw_scl_lcnt(). | ||
| 257 | */ | ||
| 258 | return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset; | ||
| 259 | } | ||
| 260 | |||
| 261 | static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) | ||
| 262 | { | ||
| 263 | /* | ||
| 264 | * Conditional expression: | ||
| 265 | * | ||
| 266 | * IC_[FS]S_SCL_LCNT + 1 >= IC_CLK * (tLOW + tf) | ||
| 267 | * | ||
| 268 | * DW I2C core starts counting the SCL CNTs for the LOW period | ||
| 269 | * of the SCL clock (tLOW) as soon as it pulls the SCL line. | ||
| 270 | * In order to meet the tLOW timing spec, we need to take into | ||
| 271 | * account the fall time of SCL signal (tf). Default tf value | ||
| 272 | * should be 0.3 us, for safety. | ||
| 273 | */ | ||
| 274 | return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; | ||
| 275 | } | ||
| 276 | |||
| 179 | /** | 277 | /** |
| 180 | * i2c_dw_init() - initialize the designware i2c master hardware | 278 | * i2c_dw_init() - initialize the designware i2c master hardware |
| 181 | * @dev: device private data | 279 | * @dev: device private data |
| @@ -187,25 +285,49 @@ struct dw_i2c_dev { | |||
| 187 | static void i2c_dw_init(struct dw_i2c_dev *dev) | 285 | static void i2c_dw_init(struct dw_i2c_dev *dev) |
| 188 | { | 286 | { |
| 189 | u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; | 287 | u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; |
| 190 | u16 ic_con; | 288 | u32 ic_con, hcnt, lcnt; |
| 191 | 289 | ||
| 192 | /* Disable the adapter */ | 290 | /* Disable the adapter */ |
| 193 | writeb(0, dev->base + DW_IC_ENABLE); | 291 | writel(0, dev->base + DW_IC_ENABLE); |
| 194 | 292 | ||
| 195 | /* set standard and fast speed deviders for high/low periods */ | 293 | /* set standard and fast speed deviders for high/low periods */ |
| 196 | writew((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */ | 294 | |
| 197 | dev->base + DW_IC_SS_SCL_HCNT); | 295 | /* Standard-mode */ |
| 198 | writew((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */ | 296 | hcnt = i2c_dw_scl_hcnt(input_clock_khz, |
| 199 | dev->base + DW_IC_SS_SCL_LCNT); | 297 | 40, /* tHD;STA = tHIGH = 4.0 us */ |
| 200 | writew((input_clock_khz * 6 / 10000)+1, /* fast speed high, 0.6us */ | 298 | 3, /* tf = 0.3 us */ |
| 201 | dev->base + DW_IC_FS_SCL_HCNT); | 299 | 0, /* 0: DW default, 1: Ideal */ |
| 202 | writew((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */ | 300 | 0); /* No offset */ |
| 203 | dev->base + DW_IC_FS_SCL_LCNT); | 301 | lcnt = i2c_dw_scl_lcnt(input_clock_khz, |
| 302 | 47, /* tLOW = 4.7 us */ | ||
| 303 | 3, /* tf = 0.3 us */ | ||
| 304 | 0); /* No offset */ | ||
| 305 | writel(hcnt, dev->base + DW_IC_SS_SCL_HCNT); | ||
| 306 | writel(lcnt, dev->base + DW_IC_SS_SCL_LCNT); | ||
| 307 | dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); | ||
| 308 | |||
| 309 | /* Fast-mode */ | ||
| 310 | hcnt = i2c_dw_scl_hcnt(input_clock_khz, | ||
| 311 | 6, /* tHD;STA = tHIGH = 0.6 us */ | ||
| 312 | 3, /* tf = 0.3 us */ | ||
| 313 | 0, /* 0: DW default, 1: Ideal */ | ||
| 314 | 0); /* No offset */ | ||
| 315 | lcnt = i2c_dw_scl_lcnt(input_clock_khz, | ||
| 316 | 13, /* tLOW = 1.3 us */ | ||
| 317 | 3, /* tf = 0.3 us */ | ||
| 318 | 0); /* No offset */ | ||
| 319 | writel(hcnt, dev->base + DW_IC_FS_SCL_HCNT); | ||
| 320 | writel(lcnt, dev->base + DW_IC_FS_SCL_LCNT); | ||
| 321 | dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); | ||
| 322 | |||
| 323 | /* Configure Tx/Rx FIFO threshold levels */ | ||
| 324 | writel(dev->tx_fifo_depth - 1, dev->base + DW_IC_TX_TL); | ||
| 325 | writel(0, dev->base + DW_IC_RX_TL); | ||
| 204 | 326 | ||
| 205 | /* configure the i2c master */ | 327 | /* configure the i2c master */ |
| 206 | ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | | 328 | ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | |
| 207 | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; | 329 | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; |
| 208 | writew(ic_con, dev->base + DW_IC_CON); | 330 | writel(ic_con, dev->base + DW_IC_CON); |
| 209 | } | 331 | } |
| 210 | 332 | ||
| 211 | /* | 333 | /* |
| @@ -215,7 +337,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) | |||
| 215 | { | 337 | { |
| 216 | int timeout = TIMEOUT; | 338 | int timeout = TIMEOUT; |
| 217 | 339 | ||
| 218 | while (readb(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { | 340 | while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { |
| 219 | if (timeout <= 0) { | 341 | if (timeout <= 0) { |
| 220 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); | 342 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); |
| 221 | return -ETIMEDOUT; | 343 | return -ETIMEDOUT; |
| @@ -227,106 +349,125 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) | |||
| 227 | return 0; | 349 | return 0; |
| 228 | } | 350 | } |
| 229 | 351 | ||
| 352 | static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) | ||
| 353 | { | ||
| 354 | struct i2c_msg *msgs = dev->msgs; | ||
| 355 | u32 ic_con; | ||
| 356 | |||
| 357 | /* Disable the adapter */ | ||
| 358 | writel(0, dev->base + DW_IC_ENABLE); | ||
| 359 | |||
| 360 | /* set the slave (target) address */ | ||
| 361 | writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR); | ||
| 362 | |||
| 363 | /* if the slave address is ten bit address, enable 10BITADDR */ | ||
| 364 | ic_con = readl(dev->base + DW_IC_CON); | ||
| 365 | if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) | ||
| 366 | ic_con |= DW_IC_CON_10BITADDR_MASTER; | ||
| 367 | else | ||
| 368 | ic_con &= ~DW_IC_CON_10BITADDR_MASTER; | ||
| 369 | writel(ic_con, dev->base + DW_IC_CON); | ||
| 370 | |||
| 371 | /* Enable the adapter */ | ||
| 372 | writel(1, dev->base + DW_IC_ENABLE); | ||
| 373 | |||
| 374 | /* Enable interrupts */ | ||
| 375 | writel(DW_IC_INTR_DEFAULT_MASK, dev->base + DW_IC_INTR_MASK); | ||
| 376 | } | ||
| 377 | |||
| 230 | /* | 378 | /* |
| 231 | * Initiate low level master read/write transaction. | 379 | * Initiate (and continue) low level master read/write transaction. |
| 232 | * This function is called from i2c_dw_xfer when starting a transfer. | 380 | * This function is only called from i2c_dw_isr, and pumping i2c_msg |
| 233 | * This function is also called from dw_i2c_pump_msg to continue a transfer | 381 | * messages into the tx buffer. Even if the size of i2c_msg data is |
| 234 | * that is longer than the size of the TX FIFO. | 382 | * longer than the size of the tx buffer, it handles everything. |
| 235 | */ | 383 | */ |
| 236 | static void | 384 | static void |
| 237 | i2c_dw_xfer_msg(struct i2c_adapter *adap) | 385 | i2c_dw_xfer_msg(struct dw_i2c_dev *dev) |
| 238 | { | 386 | { |
| 239 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); | ||
| 240 | struct i2c_msg *msgs = dev->msgs; | 387 | struct i2c_msg *msgs = dev->msgs; |
| 241 | int num = dev->msgs_num; | 388 | u32 intr_mask; |
| 242 | u16 ic_con, intr_mask; | 389 | int tx_limit, rx_limit; |
| 243 | int tx_limit = dev->tx_fifo_depth - readb(dev->base + DW_IC_TXFLR); | 390 | u32 addr = msgs[dev->msg_write_idx].addr; |
| 244 | int rx_limit = dev->rx_fifo_depth - readb(dev->base + DW_IC_RXFLR); | 391 | u32 buf_len = dev->tx_buf_len; |
| 245 | u16 addr = msgs[dev->msg_write_idx].addr; | 392 | u8 *buf = dev->tx_buf;; |
| 246 | u16 buf_len = dev->tx_buf_len; | ||
| 247 | |||
| 248 | if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { | ||
| 249 | /* Disable the adapter */ | ||
| 250 | writeb(0, dev->base + DW_IC_ENABLE); | ||
| 251 | |||
| 252 | /* set the slave (target) address */ | ||
| 253 | writew(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR); | ||
| 254 | 393 | ||
| 255 | /* if the slave address is ten bit address, enable 10BITADDR */ | 394 | intr_mask = DW_IC_INTR_DEFAULT_MASK; |
| 256 | ic_con = readw(dev->base + DW_IC_CON); | ||
| 257 | if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) | ||
| 258 | ic_con |= DW_IC_CON_10BITADDR_MASTER; | ||
| 259 | else | ||
| 260 | ic_con &= ~DW_IC_CON_10BITADDR_MASTER; | ||
| 261 | writew(ic_con, dev->base + DW_IC_CON); | ||
| 262 | 395 | ||
| 263 | /* Enable the adapter */ | 396 | for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) { |
| 264 | writeb(1, dev->base + DW_IC_ENABLE); | 397 | /* |
| 265 | } | 398 | * if target address has changed, we need to |
| 266 | |||
| 267 | for (; dev->msg_write_idx < num; dev->msg_write_idx++) { | ||
| 268 | /* if target address has changed, we need to | ||
| 269 | * reprogram the target address in the i2c | 399 | * reprogram the target address in the i2c |
| 270 | * adapter when we are done with this transfer | 400 | * adapter when we are done with this transfer |
| 271 | */ | 401 | */ |
| 272 | if (msgs[dev->msg_write_idx].addr != addr) | 402 | if (msgs[dev->msg_write_idx].addr != addr) { |
| 273 | return; | 403 | dev_err(dev->dev, |
| 404 | "%s: invalid target address\n", __func__); | ||
| 405 | dev->msg_err = -EINVAL; | ||
| 406 | break; | ||
| 407 | } | ||
| 274 | 408 | ||
| 275 | if (msgs[dev->msg_write_idx].len == 0) { | 409 | if (msgs[dev->msg_write_idx].len == 0) { |
| 276 | dev_err(dev->dev, | 410 | dev_err(dev->dev, |
| 277 | "%s: invalid message length\n", __func__); | 411 | "%s: invalid message length\n", __func__); |
| 278 | dev->msg_err = -EINVAL; | 412 | dev->msg_err = -EINVAL; |
| 279 | return; | 413 | break; |
| 280 | } | 414 | } |
| 281 | 415 | ||
| 282 | if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { | 416 | if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { |
| 283 | /* new i2c_msg */ | 417 | /* new i2c_msg */ |
| 284 | dev->tx_buf = msgs[dev->msg_write_idx].buf; | 418 | buf = msgs[dev->msg_write_idx].buf; |
| 285 | buf_len = msgs[dev->msg_write_idx].len; | 419 | buf_len = msgs[dev->msg_write_idx].len; |
| 286 | } | 420 | } |
| 287 | 421 | ||
| 422 | tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR); | ||
| 423 | rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR); | ||
| 424 | |||
| 288 | while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { | 425 | while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { |
| 289 | if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { | 426 | if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { |
| 290 | writew(0x100, dev->base + DW_IC_DATA_CMD); | 427 | writel(0x100, dev->base + DW_IC_DATA_CMD); |
| 291 | rx_limit--; | 428 | rx_limit--; |
| 292 | } else | 429 | } else |
| 293 | writew(*(dev->tx_buf++), | 430 | writel(*buf++, dev->base + DW_IC_DATA_CMD); |
| 294 | dev->base + DW_IC_DATA_CMD); | ||
| 295 | tx_limit--; buf_len--; | 431 | tx_limit--; buf_len--; |
| 296 | } | 432 | } |
| 433 | |||
| 434 | dev->tx_buf = buf; | ||
| 435 | dev->tx_buf_len = buf_len; | ||
| 436 | |||
| 437 | if (buf_len > 0) { | ||
| 438 | /* more bytes to be written */ | ||
| 439 | dev->status |= STATUS_WRITE_IN_PROGRESS; | ||
| 440 | break; | ||
| 441 | } else | ||
| 442 | dev->status &= ~STATUS_WRITE_IN_PROGRESS; | ||
| 297 | } | 443 | } |
| 298 | 444 | ||
| 299 | intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT; | 445 | /* |
| 300 | if (buf_len > 0) { /* more bytes to be written */ | 446 | * If i2c_msg index search is completed, we don't need TX_EMPTY |
| 301 | intr_mask |= DW_IC_INTR_TX_EMPTY; | 447 | * interrupt any more. |
| 302 | dev->status |= STATUS_WRITE_IN_PROGRESS; | 448 | */ |
| 303 | } else | 449 | if (dev->msg_write_idx == dev->msgs_num) |
| 304 | dev->status &= ~STATUS_WRITE_IN_PROGRESS; | 450 | intr_mask &= ~DW_IC_INTR_TX_EMPTY; |
| 305 | writew(intr_mask, dev->base + DW_IC_INTR_MASK); | 451 | |
| 452 | if (dev->msg_err) | ||
| 453 | intr_mask = 0; | ||
| 306 | 454 | ||
| 307 | dev->tx_buf_len = buf_len; | 455 | writel(intr_mask, dev->base + DW_IC_INTR_MASK); |
| 308 | } | 456 | } |
| 309 | 457 | ||
| 310 | static void | 458 | static void |
| 311 | i2c_dw_read(struct i2c_adapter *adap) | 459 | i2c_dw_read(struct dw_i2c_dev *dev) |
| 312 | { | 460 | { |
| 313 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); | ||
| 314 | struct i2c_msg *msgs = dev->msgs; | 461 | struct i2c_msg *msgs = dev->msgs; |
| 315 | int num = dev->msgs_num; | 462 | int rx_valid; |
| 316 | u16 addr = msgs[dev->msg_read_idx].addr; | ||
| 317 | int rx_valid = readw(dev->base + DW_IC_RXFLR); | ||
| 318 | 463 | ||
| 319 | for (; dev->msg_read_idx < num; dev->msg_read_idx++) { | 464 | for (; dev->msg_read_idx < dev->msgs_num; dev->msg_read_idx++) { |
| 320 | u16 len; | 465 | u32 len; |
| 321 | u8 *buf; | 466 | u8 *buf; |
| 322 | 467 | ||
| 323 | if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) | 468 | if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) |
| 324 | continue; | 469 | continue; |
| 325 | 470 | ||
| 326 | /* different i2c client, reprogram the i2c adapter */ | ||
| 327 | if (msgs[dev->msg_read_idx].addr != addr) | ||
| 328 | return; | ||
| 329 | |||
| 330 | if (!(dev->status & STATUS_READ_IN_PROGRESS)) { | 471 | if (!(dev->status & STATUS_READ_IN_PROGRESS)) { |
| 331 | len = msgs[dev->msg_read_idx].len; | 472 | len = msgs[dev->msg_read_idx].len; |
| 332 | buf = msgs[dev->msg_read_idx].buf; | 473 | buf = msgs[dev->msg_read_idx].buf; |
| @@ -335,8 +476,10 @@ i2c_dw_read(struct i2c_adapter *adap) | |||
| 335 | buf = dev->rx_buf; | 476 | buf = dev->rx_buf; |
| 336 | } | 477 | } |
| 337 | 478 | ||
| 479 | rx_valid = readl(dev->base + DW_IC_RXFLR); | ||
| 480 | |||
| 338 | for (; len > 0 && rx_valid > 0; len--, rx_valid--) | 481 | for (; len > 0 && rx_valid > 0; len--, rx_valid--) |
| 339 | *buf++ = readb(dev->base + DW_IC_DATA_CMD); | 482 | *buf++ = readl(dev->base + DW_IC_DATA_CMD); |
| 340 | 483 | ||
| 341 | if (len > 0) { | 484 | if (len > 0) { |
| 342 | dev->status |= STATUS_READ_IN_PROGRESS; | 485 | dev->status |= STATUS_READ_IN_PROGRESS; |
| @@ -348,6 +491,29 @@ i2c_dw_read(struct i2c_adapter *adap) | |||
| 348 | } | 491 | } |
| 349 | } | 492 | } |
| 350 | 493 | ||
| 494 | static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev) | ||
| 495 | { | ||
| 496 | unsigned long abort_source = dev->abort_source; | ||
| 497 | int i; | ||
| 498 | |||
| 499 | if (abort_source & DW_IC_TX_ABRT_NOACK) { | ||
| 500 | for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) | ||
| 501 | dev_dbg(dev->dev, | ||
| 502 | "%s: %s\n", __func__, abort_sources[i]); | ||
| 503 | return -EREMOTEIO; | ||
| 504 | } | ||
| 505 | |||
| 506 | for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) | ||
| 507 | dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]); | ||
| 508 | |||
| 509 | if (abort_source & DW_IC_TX_ARB_LOST) | ||
| 510 | return -EAGAIN; | ||
| 511 | else if (abort_source & DW_IC_TX_ABRT_GCALL_READ) | ||
| 512 | return -EINVAL; /* wrong msgs[] data */ | ||
| 513 | else | ||
| 514 | return -EIO; | ||
| 515 | } | ||
| 516 | |||
| 351 | /* | 517 | /* |
| 352 | * Prepare controller for a transaction and call i2c_dw_xfer_msg | 518 | * Prepare controller for a transaction and call i2c_dw_xfer_msg |
| 353 | */ | 519 | */ |
| @@ -369,13 +535,14 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
| 369 | dev->msg_read_idx = 0; | 535 | dev->msg_read_idx = 0; |
| 370 | dev->msg_err = 0; | 536 | dev->msg_err = 0; |
| 371 | dev->status = STATUS_IDLE; | 537 | dev->status = STATUS_IDLE; |
| 538 | dev->abort_source = 0; | ||
| 372 | 539 | ||
| 373 | ret = i2c_dw_wait_bus_not_busy(dev); | 540 | ret = i2c_dw_wait_bus_not_busy(dev); |
| 374 | if (ret < 0) | 541 | if (ret < 0) |
| 375 | goto done; | 542 | goto done; |
| 376 | 543 | ||
| 377 | /* start the transfers */ | 544 | /* start the transfers */ |
| 378 | i2c_dw_xfer_msg(adap); | 545 | i2c_dw_xfer_init(dev); |
| 379 | 546 | ||
| 380 | /* wait for tx to complete */ | 547 | /* wait for tx to complete */ |
| 381 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ); | 548 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ); |
| @@ -394,23 +561,16 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
| 394 | 561 | ||
| 395 | /* no error */ | 562 | /* no error */ |
| 396 | if (likely(!dev->cmd_err)) { | 563 | if (likely(!dev->cmd_err)) { |
| 397 | /* read rx fifo, and disable the adapter */ | 564 | /* Disable the adapter */ |
| 398 | do { | 565 | writel(0, dev->base + DW_IC_ENABLE); |
| 399 | i2c_dw_read(adap); | ||
| 400 | } while (dev->status & STATUS_READ_IN_PROGRESS); | ||
| 401 | writeb(0, dev->base + DW_IC_ENABLE); | ||
| 402 | ret = num; | 566 | ret = num; |
| 403 | goto done; | 567 | goto done; |
| 404 | } | 568 | } |
| 405 | 569 | ||
| 406 | /* We have an error */ | 570 | /* We have an error */ |
| 407 | if (dev->cmd_err == DW_IC_ERR_TX_ABRT) { | 571 | if (dev->cmd_err == DW_IC_ERR_TX_ABRT) { |
| 408 | unsigned long abort_source = dev->abort_source; | 572 | ret = i2c_dw_handle_tx_abort(dev); |
| 409 | int i; | 573 | goto done; |
| 410 | |||
| 411 | for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) { | ||
| 412 | dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]); | ||
| 413 | } | ||
| 414 | } | 574 | } |
| 415 | ret = -EIO; | 575 | ret = -EIO; |
| 416 | 576 | ||
| @@ -422,21 +582,67 @@ done: | |||
| 422 | 582 | ||
| 423 | static u32 i2c_dw_func(struct i2c_adapter *adap) | 583 | static u32 i2c_dw_func(struct i2c_adapter *adap) |
| 424 | { | 584 | { |
| 425 | return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR; | 585 | return I2C_FUNC_I2C | |
| 586 | I2C_FUNC_10BIT_ADDR | | ||
| 587 | I2C_FUNC_SMBUS_BYTE | | ||
| 588 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
| 589 | I2C_FUNC_SMBUS_WORD_DATA | | ||
| 590 | I2C_FUNC_SMBUS_I2C_BLOCK; | ||
| 426 | } | 591 | } |
| 427 | 592 | ||
| 428 | static void dw_i2c_pump_msg(unsigned long data) | 593 | static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) |
| 429 | { | 594 | { |
| 430 | struct dw_i2c_dev *dev = (struct dw_i2c_dev *) data; | 595 | u32 stat; |
| 431 | u16 intr_mask; | 596 | |
| 432 | 597 | /* | |
| 433 | i2c_dw_read(&dev->adapter); | 598 | * The IC_INTR_STAT register just indicates "enabled" interrupts. |
| 434 | i2c_dw_xfer_msg(&dev->adapter); | 599 | * Ths unmasked raw version of interrupt status bits are available |
| 435 | 600 | * in the IC_RAW_INTR_STAT register. | |
| 436 | intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT; | 601 | * |
| 437 | if (dev->status & STATUS_WRITE_IN_PROGRESS) | 602 | * That is, |
| 438 | intr_mask |= DW_IC_INTR_TX_EMPTY; | 603 | * stat = readl(IC_INTR_STAT); |
| 439 | writew(intr_mask, dev->base + DW_IC_INTR_MASK); | 604 | * equals to, |
| 605 | * stat = readl(IC_RAW_INTR_STAT) & readl(IC_INTR_MASK); | ||
| 606 | * | ||
| 607 | * The raw version might be useful for debugging purposes. | ||
| 608 | */ | ||
| 609 | stat = readl(dev->base + DW_IC_INTR_STAT); | ||
| 610 | |||
| 611 | /* | ||
| 612 | * Do not use the IC_CLR_INTR register to clear interrupts, or | ||
| 613 | * you'll miss some interrupts, triggered during the period from | ||
| 614 | * readl(IC_INTR_STAT) to readl(IC_CLR_INTR). | ||
| 615 | * | ||
| 616 | * Instead, use the separately-prepared IC_CLR_* registers. | ||
| 617 | */ | ||
| 618 | if (stat & DW_IC_INTR_RX_UNDER) | ||
| 619 | readl(dev->base + DW_IC_CLR_RX_UNDER); | ||
| 620 | if (stat & DW_IC_INTR_RX_OVER) | ||
| 621 | readl(dev->base + DW_IC_CLR_RX_OVER); | ||
| 622 | if (stat & DW_IC_INTR_TX_OVER) | ||
| 623 | readl(dev->base + DW_IC_CLR_TX_OVER); | ||
| 624 | if (stat & DW_IC_INTR_RD_REQ) | ||
| 625 | readl(dev->base + DW_IC_CLR_RD_REQ); | ||
| 626 | if (stat & DW_IC_INTR_TX_ABRT) { | ||
| 627 | /* | ||
| 628 | * The IC_TX_ABRT_SOURCE register is cleared whenever | ||
| 629 | * the IC_CLR_TX_ABRT is read. Preserve it beforehand. | ||
| 630 | */ | ||
| 631 | dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE); | ||
| 632 | readl(dev->base + DW_IC_CLR_TX_ABRT); | ||
| 633 | } | ||
| 634 | if (stat & DW_IC_INTR_RX_DONE) | ||
| 635 | readl(dev->base + DW_IC_CLR_RX_DONE); | ||
| 636 | if (stat & DW_IC_INTR_ACTIVITY) | ||
| 637 | readl(dev->base + DW_IC_CLR_ACTIVITY); | ||
| 638 | if (stat & DW_IC_INTR_STOP_DET) | ||
| 639 | readl(dev->base + DW_IC_CLR_STOP_DET); | ||
| 640 | if (stat & DW_IC_INTR_START_DET) | ||
| 641 | readl(dev->base + DW_IC_CLR_START_DET); | ||
| 642 | if (stat & DW_IC_INTR_GEN_CALL) | ||
| 643 | readl(dev->base + DW_IC_CLR_GEN_CALL); | ||
| 644 | |||
| 645 | return stat; | ||
| 440 | } | 646 | } |
| 441 | 647 | ||
| 442 | /* | 648 | /* |
| @@ -446,20 +652,37 @@ static void dw_i2c_pump_msg(unsigned long data) | |||
| 446 | static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) | 652 | static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) |
| 447 | { | 653 | { |
| 448 | struct dw_i2c_dev *dev = dev_id; | 654 | struct dw_i2c_dev *dev = dev_id; |
| 449 | u16 stat; | 655 | u32 stat; |
| 450 | 656 | ||
| 451 | stat = readw(dev->base + DW_IC_INTR_STAT); | 657 | stat = i2c_dw_read_clear_intrbits(dev); |
| 452 | dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); | 658 | dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); |
| 659 | |||
| 453 | if (stat & DW_IC_INTR_TX_ABRT) { | 660 | if (stat & DW_IC_INTR_TX_ABRT) { |
| 454 | dev->abort_source = readw(dev->base + DW_IC_TX_ABRT_SOURCE); | ||
| 455 | dev->cmd_err |= DW_IC_ERR_TX_ABRT; | 661 | dev->cmd_err |= DW_IC_ERR_TX_ABRT; |
| 456 | dev->status = STATUS_IDLE; | 662 | dev->status = STATUS_IDLE; |
| 457 | } else if (stat & DW_IC_INTR_TX_EMPTY) | ||
| 458 | tasklet_schedule(&dev->pump_msg); | ||
| 459 | 663 | ||
| 460 | readb(dev->base + DW_IC_CLR_INTR); /* clear interrupts */ | 664 | /* |
| 461 | writew(0, dev->base + DW_IC_INTR_MASK); /* disable interrupts */ | 665 | * Anytime TX_ABRT is set, the contents of the tx/rx |
| 462 | if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) | 666 | * buffers are flushed. Make sure to skip them. |
| 667 | */ | ||
| 668 | writel(0, dev->base + DW_IC_INTR_MASK); | ||
| 669 | goto tx_aborted; | ||
| 670 | } | ||
| 671 | |||
| 672 | if (stat & DW_IC_INTR_RX_FULL) | ||
| 673 | i2c_dw_read(dev); | ||
| 674 | |||
| 675 | if (stat & DW_IC_INTR_TX_EMPTY) | ||
| 676 | i2c_dw_xfer_msg(dev); | ||
| 677 | |||
| 678 | /* | ||
| 679 | * No need to modify or disable the interrupt mask here. | ||
| 680 | * i2c_dw_xfer_msg() will take care of it according to | ||
| 681 | * the current transmit status. | ||
| 682 | */ | ||
| 683 | |||
| 684 | tx_aborted: | ||
| 685 | if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err) | ||
| 463 | complete(&dev->cmd_complete); | 686 | complete(&dev->cmd_complete); |
| 464 | 687 | ||
| 465 | return IRQ_HANDLED; | 688 | return IRQ_HANDLED; |
| @@ -474,8 +697,8 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev) | |||
| 474 | { | 697 | { |
| 475 | struct dw_i2c_dev *dev; | 698 | struct dw_i2c_dev *dev; |
| 476 | struct i2c_adapter *adap; | 699 | struct i2c_adapter *adap; |
| 477 | struct resource *mem, *irq, *ioarea; | 700 | struct resource *mem, *ioarea; |
| 478 | int r; | 701 | int irq, r; |
| 479 | 702 | ||
| 480 | /* NOTE: driver uses the static register mapping */ | 703 | /* NOTE: driver uses the static register mapping */ |
| 481 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 704 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| @@ -484,10 +707,10 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev) | |||
| 484 | return -EINVAL; | 707 | return -EINVAL; |
| 485 | } | 708 | } |
| 486 | 709 | ||
| 487 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 710 | irq = platform_get_irq(pdev, 0); |
| 488 | if (!irq) { | 711 | if (irq < 0) { |
| 489 | dev_err(&pdev->dev, "no irq resource?\n"); | 712 | dev_err(&pdev->dev, "no irq resource?\n"); |
| 490 | return -EINVAL; | 713 | return irq; /* -ENXIO */ |
| 491 | } | 714 | } |
| 492 | 715 | ||
| 493 | ioarea = request_mem_region(mem->start, resource_size(mem), | 716 | ioarea = request_mem_region(mem->start, resource_size(mem), |
| @@ -504,10 +727,9 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev) | |||
| 504 | } | 727 | } |
| 505 | 728 | ||
| 506 | init_completion(&dev->cmd_complete); | 729 | init_completion(&dev->cmd_complete); |
| 507 | tasklet_init(&dev->pump_msg, dw_i2c_pump_msg, (unsigned long) dev); | ||
| 508 | mutex_init(&dev->lock); | 730 | mutex_init(&dev->lock); |
| 509 | dev->dev = get_device(&pdev->dev); | 731 | dev->dev = get_device(&pdev->dev); |
| 510 | dev->irq = irq->start; | 732 | dev->irq = irq; |
| 511 | platform_set_drvdata(pdev, dev); | 733 | platform_set_drvdata(pdev, dev); |
| 512 | 734 | ||
| 513 | dev->clk = clk_get(&pdev->dev, NULL); | 735 | dev->clk = clk_get(&pdev->dev, NULL); |
| @@ -531,8 +753,8 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev) | |||
| 531 | } | 753 | } |
| 532 | i2c_dw_init(dev); | 754 | i2c_dw_init(dev); |
| 533 | 755 | ||
| 534 | writew(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ | 756 | writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ |
| 535 | r = request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev); | 757 | r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev); |
| 536 | if (r) { | 758 | if (r) { |
| 537 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | 759 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); |
| 538 | goto err_iounmap; | 760 | goto err_iounmap; |
| @@ -587,7 +809,7 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev) | |||
| 587 | clk_put(dev->clk); | 809 | clk_put(dev->clk); |
| 588 | dev->clk = NULL; | 810 | dev->clk = NULL; |
| 589 | 811 | ||
| 590 | writeb(0, dev->base + DW_IC_ENABLE); | 812 | writel(0, dev->base + DW_IC_ENABLE); |
| 591 | free_irq(dev->irq, dev); | 813 | free_irq(dev->irq, dev); |
| 592 | kfree(dev); | 814 | kfree(dev); |
| 593 | 815 | ||
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 827da0858136..75bf3ad18099 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
| @@ -178,6 +178,12 @@ struct omap_i2c_dev { | |||
| 178 | unsigned b_hw:1; /* bad h/w fixes */ | 178 | unsigned b_hw:1; /* bad h/w fixes */ |
| 179 | unsigned idle:1; | 179 | unsigned idle:1; |
| 180 | u16 iestate; /* Saved interrupt register */ | 180 | u16 iestate; /* Saved interrupt register */ |
| 181 | u16 pscstate; | ||
| 182 | u16 scllstate; | ||
| 183 | u16 sclhstate; | ||
| 184 | u16 bufstate; | ||
| 185 | u16 syscstate; | ||
| 186 | u16 westate; | ||
| 181 | }; | 187 | }; |
| 182 | 188 | ||
| 183 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, | 189 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, |
| @@ -230,9 +236,18 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev) | |||
| 230 | 236 | ||
| 231 | clk_enable(dev->iclk); | 237 | clk_enable(dev->iclk); |
| 232 | clk_enable(dev->fclk); | 238 | clk_enable(dev->fclk); |
| 239 | if (cpu_is_omap34xx()) { | ||
| 240 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | ||
| 241 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); | ||
| 242 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); | ||
| 243 | omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, dev->sclhstate); | ||
| 244 | omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, dev->bufstate); | ||
| 245 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, dev->syscstate); | ||
| 246 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); | ||
| 247 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); | ||
| 248 | } | ||
| 233 | dev->idle = 0; | 249 | dev->idle = 0; |
| 234 | if (dev->iestate) | 250 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); |
| 235 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); | ||
| 236 | } | 251 | } |
| 237 | 252 | ||
| 238 | static void omap_i2c_idle(struct omap_i2c_dev *dev) | 253 | static void omap_i2c_idle(struct omap_i2c_dev *dev) |
| @@ -258,7 +273,7 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev) | |||
| 258 | 273 | ||
| 259 | static int omap_i2c_init(struct omap_i2c_dev *dev) | 274 | static int omap_i2c_init(struct omap_i2c_dev *dev) |
| 260 | { | 275 | { |
| 261 | u16 psc = 0, scll = 0, sclh = 0; | 276 | u16 psc = 0, scll = 0, sclh = 0, buf = 0; |
| 262 | u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; | 277 | u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; |
| 263 | unsigned long fclk_rate = 12000000; | 278 | unsigned long fclk_rate = 12000000; |
| 264 | unsigned long timeout; | 279 | unsigned long timeout; |
| @@ -287,24 +302,22 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
| 287 | SYSC_AUTOIDLE_MASK); | 302 | SYSC_AUTOIDLE_MASK); |
| 288 | 303 | ||
| 289 | } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { | 304 | } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { |
| 290 | u32 v; | 305 | dev->syscstate = SYSC_AUTOIDLE_MASK; |
| 291 | 306 | dev->syscstate |= SYSC_ENAWAKEUP_MASK; | |
| 292 | v = SYSC_AUTOIDLE_MASK; | 307 | dev->syscstate |= (SYSC_IDLEMODE_SMART << |
| 293 | v |= SYSC_ENAWAKEUP_MASK; | ||
| 294 | v |= (SYSC_IDLEMODE_SMART << | ||
| 295 | __ffs(SYSC_SIDLEMODE_MASK)); | 308 | __ffs(SYSC_SIDLEMODE_MASK)); |
| 296 | v |= (SYSC_CLOCKACTIVITY_FCLK << | 309 | dev->syscstate |= (SYSC_CLOCKACTIVITY_FCLK << |
| 297 | __ffs(SYSC_CLOCKACTIVITY_MASK)); | 310 | __ffs(SYSC_CLOCKACTIVITY_MASK)); |
| 298 | 311 | ||
| 299 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, v); | 312 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, |
| 313 | dev->syscstate); | ||
| 300 | /* | 314 | /* |
| 301 | * Enabling all wakup sources to stop I2C freezing on | 315 | * Enabling all wakup sources to stop I2C freezing on |
| 302 | * WFI instruction. | 316 | * WFI instruction. |
| 303 | * REVISIT: Some wkup sources might not be needed. | 317 | * REVISIT: Some wkup sources might not be needed. |
| 304 | */ | 318 | */ |
| 305 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, | 319 | dev->westate = OMAP_I2C_WE_ALL; |
| 306 | OMAP_I2C_WE_ALL); | 320 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); |
| 307 | |||
| 308 | } | 321 | } |
| 309 | } | 322 | } |
| 310 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 323 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
| @@ -394,23 +407,28 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
| 394 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); | 407 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); |
| 395 | omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); | 408 | omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); |
| 396 | 409 | ||
| 397 | if (dev->fifo_size) | 410 | if (dev->fifo_size) { |
| 398 | /* Note: setup required fifo size - 1 */ | 411 | /* Note: setup required fifo size - 1. RTRSH and XTRSH */ |
| 399 | omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, | 412 | buf = (dev->fifo_size - 1) << 8 | OMAP_I2C_BUF_RXFIF_CLR | |
| 400 | (dev->fifo_size - 1) << 8 | /* RTRSH */ | 413 | (dev->fifo_size - 1) | OMAP_I2C_BUF_TXFIF_CLR; |
| 401 | OMAP_I2C_BUF_RXFIF_CLR | | 414 | omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, buf); |
| 402 | (dev->fifo_size - 1) | /* XTRSH */ | 415 | } |
| 403 | OMAP_I2C_BUF_TXFIF_CLR); | ||
| 404 | 416 | ||
| 405 | /* Take the I2C module out of reset: */ | 417 | /* Take the I2C module out of reset: */ |
| 406 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); | 418 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); |
| 407 | 419 | ||
| 408 | /* Enable interrupts */ | 420 | /* Enable interrupts */ |
| 409 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, | 421 | dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | |
| 410 | (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | | ||
| 411 | OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | | 422 | OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | |
| 412 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? | 423 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? |
| 413 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0)); | 424 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); |
| 425 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); | ||
| 426 | if (cpu_is_omap34xx()) { | ||
| 427 | dev->pscstate = psc; | ||
| 428 | dev->scllstate = scll; | ||
| 429 | dev->sclhstate = sclh; | ||
| 430 | dev->bufstate = buf; | ||
| 431 | } | ||
| 414 | return 0; | 432 | return 0; |
| 415 | } | 433 | } |
| 416 | 434 | ||
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index fbab6846ae64..5d1c2603a130 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c | |||
| @@ -638,7 +638,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) | |||
| 638 | 638 | ||
| 639 | /* Register this adapter with the I2C subsystem */ | 639 | /* Register this adapter with the I2C subsystem */ |
| 640 | i2c_pnx->adapter->dev.parent = &pdev->dev; | 640 | i2c_pnx->adapter->dev.parent = &pdev->dev; |
| 641 | ret = i2c_add_adapter(i2c_pnx->adapter); | 641 | i2c_pnx->adapter->nr = pdev->id; |
| 642 | ret = i2c_add_numbered_adapter(i2c_pnx->adapter); | ||
| 642 | if (ret < 0) { | 643 | if (ret < 0) { |
| 643 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); | 644 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); |
| 644 | goto out_irq; | 645 | goto out_irq; |
