aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorShinya Kuribayashi <shinya.kuribayashi@necel.com>2009-11-06 07:43:52 -0500
committerBen Dooks <ben-linux@fluff.org>2009-12-08 19:19:09 -0500
commited5e1dd5f2daa8a59bc8116888417a6ff96d2ae9 (patch)
treee68b2585942c67b5f9627b90bbbcb9b1913d8161 /drivers
parent6035ccd8e9e40bb654fbfdef325902ab531679a5 (diff)
i2c-designware: Consolidate to use 32-bit word accesses
This driver looks originally meant for armel machines where readw()/ writew() works perfectly fine with this hardware. But that doens't work for big-endian systems. This patch converts all 8/16-bit-aware usages to 32-bit variants. Signed-off-by: Shinya Kuribayashi <shinya.kuribayashi@necel.com> Acked-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/busses/i2c-designware.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c
index b444762e9b9f..a4f928e1fc5b 100644
--- a/drivers/i2c/busses/i2c-designware.c
+++ b/drivers/i2c/busses/i2c-designware.c
@@ -162,14 +162,14 @@ struct dw_i2c_dev {
162 struct i2c_msg *msgs; 162 struct i2c_msg *msgs;
163 int msgs_num; 163 int msgs_num;
164 int msg_write_idx; 164 int msg_write_idx;
165 u16 tx_buf_len; 165 u32 tx_buf_len;
166 u8 *tx_buf; 166 u8 *tx_buf;
167 int msg_read_idx; 167 int msg_read_idx;
168 u16 rx_buf_len; 168 u32 rx_buf_len;
169 u8 *rx_buf; 169 u8 *rx_buf;
170 int msg_err; 170 int msg_err;
171 unsigned int status; 171 unsigned int status;
172 u16 abort_source; 172 u32 abort_source;
173 int irq; 173 int irq;
174 struct i2c_adapter adapter; 174 struct i2c_adapter adapter;
175 unsigned int tx_fifo_depth; 175 unsigned int tx_fifo_depth;
@@ -187,25 +187,25 @@ struct dw_i2c_dev {
187static void i2c_dw_init(struct dw_i2c_dev *dev) 187static void i2c_dw_init(struct dw_i2c_dev *dev)
188{ 188{
189 u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; 189 u32 input_clock_khz = clk_get_rate(dev->clk) / 1000;
190 u16 ic_con; 190 u32 ic_con;
191 191
192 /* Disable the adapter */ 192 /* Disable the adapter */
193 writeb(0, dev->base + DW_IC_ENABLE); 193 writel(0, dev->base + DW_IC_ENABLE);
194 194
195 /* set standard and fast speed deviders for high/low periods */ 195 /* set standard and fast speed deviders for high/low periods */
196 writew((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */ 196 writel((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */
197 dev->base + DW_IC_SS_SCL_HCNT); 197 dev->base + DW_IC_SS_SCL_HCNT);
198 writew((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */ 198 writel((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */
199 dev->base + DW_IC_SS_SCL_LCNT); 199 dev->base + DW_IC_SS_SCL_LCNT);
200 writew((input_clock_khz * 6 / 10000)+1, /* fast speed high, 0.6us */ 200 writel((input_clock_khz * 6 / 10000)+1, /* fast speed high, 0.6us */
201 dev->base + DW_IC_FS_SCL_HCNT); 201 dev->base + DW_IC_FS_SCL_HCNT);
202 writew((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */ 202 writel((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */
203 dev->base + DW_IC_FS_SCL_LCNT); 203 dev->base + DW_IC_FS_SCL_LCNT);
204 204
205 /* configure the i2c master */ 205 /* configure the i2c master */
206 ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | 206 ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
207 DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; 207 DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
208 writew(ic_con, dev->base + DW_IC_CON); 208 writel(ic_con, dev->base + DW_IC_CON);
209} 209}
210 210
211/* 211/*
@@ -215,7 +215,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev)
215{ 215{
216 int timeout = TIMEOUT; 216 int timeout = TIMEOUT;
217 217
218 while (readb(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { 218 while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
219 if (timeout <= 0) { 219 if (timeout <= 0) {
220 dev_warn(dev->dev, "timeout waiting for bus ready\n"); 220 dev_warn(dev->dev, "timeout waiting for bus ready\n");
221 return -ETIMEDOUT; 221 return -ETIMEDOUT;
@@ -239,29 +239,29 @@ i2c_dw_xfer_msg(struct i2c_adapter *adap)
239 struct dw_i2c_dev *dev = i2c_get_adapdata(adap); 239 struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
240 struct i2c_msg *msgs = dev->msgs; 240 struct i2c_msg *msgs = dev->msgs;
241 int num = dev->msgs_num; 241 int num = dev->msgs_num;
242 u16 ic_con, intr_mask; 242 u32 ic_con, intr_mask;
243 int tx_limit = dev->tx_fifo_depth - readb(dev->base + DW_IC_TXFLR); 243 int tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR);
244 int rx_limit = dev->rx_fifo_depth - readb(dev->base + DW_IC_RXFLR); 244 int rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR);
245 u16 addr = msgs[dev->msg_write_idx].addr; 245 u32 addr = msgs[dev->msg_write_idx].addr;
246 u16 buf_len = dev->tx_buf_len; 246 u32 buf_len = dev->tx_buf_len;
247 247
248 if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { 248 if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
249 /* Disable the adapter */ 249 /* Disable the adapter */
250 writeb(0, dev->base + DW_IC_ENABLE); 250 writel(0, dev->base + DW_IC_ENABLE);
251 251
252 /* set the slave (target) address */ 252 /* set the slave (target) address */
253 writew(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR); 253 writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
254 254
255 /* if the slave address is ten bit address, enable 10BITADDR */ 255 /* if the slave address is ten bit address, enable 10BITADDR */
256 ic_con = readw(dev->base + DW_IC_CON); 256 ic_con = readl(dev->base + DW_IC_CON);
257 if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) 257 if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
258 ic_con |= DW_IC_CON_10BITADDR_MASTER; 258 ic_con |= DW_IC_CON_10BITADDR_MASTER;
259 else 259 else
260 ic_con &= ~DW_IC_CON_10BITADDR_MASTER; 260 ic_con &= ~DW_IC_CON_10BITADDR_MASTER;
261 writew(ic_con, dev->base + DW_IC_CON); 261 writel(ic_con, dev->base + DW_IC_CON);
262 262
263 /* Enable the adapter */ 263 /* Enable the adapter */
264 writeb(1, dev->base + DW_IC_ENABLE); 264 writel(1, dev->base + DW_IC_ENABLE);
265 } 265 }
266 266
267 for (; dev->msg_write_idx < num; dev->msg_write_idx++) { 267 for (; dev->msg_write_idx < num; dev->msg_write_idx++) {
@@ -287,10 +287,10 @@ i2c_dw_xfer_msg(struct i2c_adapter *adap)
287 287
288 while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { 288 while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
289 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { 289 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
290 writew(0x100, dev->base + DW_IC_DATA_CMD); 290 writel(0x100, dev->base + DW_IC_DATA_CMD);
291 rx_limit--; 291 rx_limit--;
292 } else 292 } else
293 writew(*(dev->tx_buf++), 293 writel(*(dev->tx_buf++),
294 dev->base + DW_IC_DATA_CMD); 294 dev->base + DW_IC_DATA_CMD);
295 tx_limit--; buf_len--; 295 tx_limit--; buf_len--;
296 } 296 }
@@ -302,7 +302,7 @@ i2c_dw_xfer_msg(struct i2c_adapter *adap)
302 dev->status |= STATUS_WRITE_IN_PROGRESS; 302 dev->status |= STATUS_WRITE_IN_PROGRESS;
303 } else 303 } else
304 dev->status &= ~STATUS_WRITE_IN_PROGRESS; 304 dev->status &= ~STATUS_WRITE_IN_PROGRESS;
305 writew(intr_mask, dev->base + DW_IC_INTR_MASK); 305 writel(intr_mask, dev->base + DW_IC_INTR_MASK);
306 306
307 dev->tx_buf_len = buf_len; 307 dev->tx_buf_len = buf_len;
308} 308}
@@ -313,11 +313,11 @@ i2c_dw_read(struct i2c_adapter *adap)
313 struct dw_i2c_dev *dev = i2c_get_adapdata(adap); 313 struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
314 struct i2c_msg *msgs = dev->msgs; 314 struct i2c_msg *msgs = dev->msgs;
315 int num = dev->msgs_num; 315 int num = dev->msgs_num;
316 u16 addr = msgs[dev->msg_read_idx].addr; 316 u32 addr = msgs[dev->msg_read_idx].addr;
317 int rx_valid = readw(dev->base + DW_IC_RXFLR); 317 int rx_valid = readl(dev->base + DW_IC_RXFLR);
318 318
319 for (; dev->msg_read_idx < num; dev->msg_read_idx++) { 319 for (; dev->msg_read_idx < num; dev->msg_read_idx++) {
320 u16 len; 320 u32 len;
321 u8 *buf; 321 u8 *buf;
322 322
323 if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) 323 if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD))
@@ -336,7 +336,7 @@ i2c_dw_read(struct i2c_adapter *adap)
336 } 336 }
337 337
338 for (; len > 0 && rx_valid > 0; len--, rx_valid--) 338 for (; len > 0 && rx_valid > 0; len--, rx_valid--)
339 *buf++ = readb(dev->base + DW_IC_DATA_CMD); 339 *buf++ = readl(dev->base + DW_IC_DATA_CMD);
340 340
341 if (len > 0) { 341 if (len > 0) {
342 dev->status |= STATUS_READ_IN_PROGRESS; 342 dev->status |= STATUS_READ_IN_PROGRESS;
@@ -398,7 +398,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
398 do { 398 do {
399 i2c_dw_read(adap); 399 i2c_dw_read(adap);
400 } while (dev->status & STATUS_READ_IN_PROGRESS); 400 } while (dev->status & STATUS_READ_IN_PROGRESS);
401 writeb(0, dev->base + DW_IC_ENABLE); 401 writel(0, dev->base + DW_IC_ENABLE);
402 ret = num; 402 ret = num;
403 goto done; 403 goto done;
404 } 404 }
@@ -428,7 +428,7 @@ static u32 i2c_dw_func(struct i2c_adapter *adap)
428static void dw_i2c_pump_msg(unsigned long data) 428static void dw_i2c_pump_msg(unsigned long data)
429{ 429{
430 struct dw_i2c_dev *dev = (struct dw_i2c_dev *) data; 430 struct dw_i2c_dev *dev = (struct dw_i2c_dev *) data;
431 u16 intr_mask; 431 u32 intr_mask;
432 432
433 i2c_dw_read(&dev->adapter); 433 i2c_dw_read(&dev->adapter);
434 i2c_dw_xfer_msg(&dev->adapter); 434 i2c_dw_xfer_msg(&dev->adapter);
@@ -436,7 +436,7 @@ static void dw_i2c_pump_msg(unsigned long data)
436 intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT; 436 intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT;
437 if (dev->status & STATUS_WRITE_IN_PROGRESS) 437 if (dev->status & STATUS_WRITE_IN_PROGRESS)
438 intr_mask |= DW_IC_INTR_TX_EMPTY; 438 intr_mask |= DW_IC_INTR_TX_EMPTY;
439 writew(intr_mask, dev->base + DW_IC_INTR_MASK); 439 writel(intr_mask, dev->base + DW_IC_INTR_MASK);
440} 440}
441 441
442/* 442/*
@@ -446,19 +446,19 @@ static void dw_i2c_pump_msg(unsigned long data)
446static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) 446static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
447{ 447{
448 struct dw_i2c_dev *dev = dev_id; 448 struct dw_i2c_dev *dev = dev_id;
449 u16 stat; 449 u32 stat;
450 450
451 stat = readw(dev->base + DW_IC_INTR_STAT); 451 stat = readl(dev->base + DW_IC_INTR_STAT);
452 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); 452 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
453 if (stat & DW_IC_INTR_TX_ABRT) { 453 if (stat & DW_IC_INTR_TX_ABRT) {
454 dev->abort_source = readw(dev->base + DW_IC_TX_ABRT_SOURCE); 454 dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE);
455 dev->cmd_err |= DW_IC_ERR_TX_ABRT; 455 dev->cmd_err |= DW_IC_ERR_TX_ABRT;
456 dev->status = STATUS_IDLE; 456 dev->status = STATUS_IDLE;
457 } else if (stat & DW_IC_INTR_TX_EMPTY) 457 } else if (stat & DW_IC_INTR_TX_EMPTY)
458 tasklet_schedule(&dev->pump_msg); 458 tasklet_schedule(&dev->pump_msg);
459 459
460 readb(dev->base + DW_IC_CLR_INTR); /* clear interrupts */ 460 readl(dev->base + DW_IC_CLR_INTR); /* clear interrupts */
461 writew(0, dev->base + DW_IC_INTR_MASK); /* disable interrupts */ 461 writel(0, dev->base + DW_IC_INTR_MASK); /* disable interrupts */
462 if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) 462 if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET))
463 complete(&dev->cmd_complete); 463 complete(&dev->cmd_complete);
464 464
@@ -531,7 +531,7 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
531 } 531 }
532 i2c_dw_init(dev); 532 i2c_dw_init(dev);
533 533
534 writew(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ 534 writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */
535 r = request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev); 535 r = request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev);
536 if (r) { 536 if (r) {
537 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); 537 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
@@ -587,7 +587,7 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
587 clk_put(dev->clk); 587 clk_put(dev->clk);
588 dev->clk = NULL; 588 dev->clk = NULL;
589 589
590 writeb(0, dev->base + DW_IC_ENABLE); 590 writel(0, dev->base + DW_IC_ENABLE);
591 free_irq(dev->irq, dev); 591 free_irq(dev->irq, dev);
592 kfree(dev); 592 kfree(dev);
593 593