aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c121
2 files changed, 62 insertions, 61 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 970a1612e79..42d9fdd63de 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -551,7 +551,7 @@ config I2C_PMCMSP
551 551
552config I2C_PNX 552config I2C_PNX
553 tristate "I2C bus support for Philips PNX and NXP LPC targets" 553 tristate "I2C bus support for Philips PNX and NXP LPC targets"
554 depends on ARCH_PNX4008 || ARCH_LPC32XX 554 depends on ARCH_LPC32XX
555 help 555 help
556 This driver supports the Philips IP3204 I2C IP block master and/or 556 This driver supports the Philips IP3204 I2C IP block master and/or
557 slave controller 557 slave controller
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 93f147a96b6..2f99613fd67 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -4,13 +4,13 @@
4/* Copyright (C) 2003 Peter Milne, D-TACQ Solutions Ltd 4/* Copyright (C) 2003 Peter Milne, D-TACQ Solutions Ltd
5 * <Peter dot Milne at D hyphen TACQ dot com> 5 * <Peter dot Milne at D hyphen TACQ dot com>
6 * 6 *
7 * With acknowledgements to i2c-algo-ibm_ocp.c by 7 * With acknowledgements to i2c-algo-ibm_ocp.c by
8 * Ian DaSilva, MontaVista Software, Inc. idasilva@mvista.com 8 * Ian DaSilva, MontaVista Software, Inc. idasilva@mvista.com
9 * 9 *
10 * And i2c-algo-pcf.c, which was created by Simon G. Vogl and Hans Berglund: 10 * And i2c-algo-pcf.c, which was created by Simon G. Vogl and Hans Berglund:
11 * 11 *
12 * Copyright (C) 1995-1997 Simon G. Vogl, 1998-2000 Hans Berglund 12 * Copyright (C) 1995-1997 Simon G. Vogl, 1998-2000 Hans Berglund
13 * 13 *
14 * And which acknowledged Kyösti Mälkki <kmalkki@cc.hut.fi>, 14 * And which acknowledged Kyösti Mälkki <kmalkki@cc.hut.fi>,
15 * Frodo Looijaard <frodol@dds.nl>, Martin Bailey<mbailey@littlefeet-inc.com> 15 * Frodo Looijaard <frodol@dds.nl>, Martin Bailey<mbailey@littlefeet-inc.com>
16 * 16 *
@@ -39,14 +39,15 @@
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/gpio.h>
42 43
43#include "i2c-iop3xx.h" 44#include "i2c-iop3xx.h"
44 45
45/* global unit counter */ 46/* global unit counter */
46static int i2c_id; 47static int i2c_id;
47 48
48static inline unsigned char 49static inline unsigned char
49iic_cook_addr(struct i2c_msg *msg) 50iic_cook_addr(struct i2c_msg *msg)
50{ 51{
51 unsigned char addr; 52 unsigned char addr;
52 53
@@ -55,38 +56,38 @@ iic_cook_addr(struct i2c_msg *msg)
55 if (msg->flags & I2C_M_RD) 56 if (msg->flags & I2C_M_RD)
56 addr |= 1; 57 addr |= 1;
57 58
58 return addr; 59 return addr;
59} 60}
60 61
61static void 62static void
62iop3xx_i2c_reset(struct i2c_algo_iop3xx_data *iop3xx_adap) 63iop3xx_i2c_reset(struct i2c_algo_iop3xx_data *iop3xx_adap)
63{ 64{
64 /* Follows devman 9.3 */ 65 /* Follows devman 9.3 */
65 __raw_writel(IOP3XX_ICR_UNIT_RESET, iop3xx_adap->ioaddr + CR_OFFSET); 66 __raw_writel(IOP3XX_ICR_UNIT_RESET, iop3xx_adap->ioaddr + CR_OFFSET);
66 __raw_writel(IOP3XX_ISR_CLEARBITS, iop3xx_adap->ioaddr + SR_OFFSET); 67 __raw_writel(IOP3XX_ISR_CLEARBITS, iop3xx_adap->ioaddr + SR_OFFSET);
67 __raw_writel(0, iop3xx_adap->ioaddr + CR_OFFSET); 68 __raw_writel(0, iop3xx_adap->ioaddr + CR_OFFSET);
68} 69}
69 70
70static void 71static void
71iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap) 72iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
72{ 73{
73 u32 cr = IOP3XX_ICR_GCD | IOP3XX_ICR_SCLEN | IOP3XX_ICR_UE; 74 u32 cr = IOP3XX_ICR_GCD | IOP3XX_ICR_SCLEN | IOP3XX_ICR_UE;
74 75
75 /* 76 /*
76 * Every time unit enable is asserted, GPOD needs to be cleared 77 * Every time unit enable is asserted, GPOD needs to be cleared
77 * on IOP3XX to avoid data corruption on the bus. 78 * on IOP3XX to avoid data corruption on the bus.
78 */ 79 */
79#if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X) 80#if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X)
80 if (iop3xx_adap->id == 0) { 81 if (iop3xx_adap->id == 0) {
81 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW); 82 gpio_set_value(7, 0);
82 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW); 83 gpio_set_value(6, 0);
83 } else { 84 } else {
84 gpio_line_set(IOP3XX_GPIO_LINE(5), GPIO_LOW); 85 gpio_set_value(5, 0);
85 gpio_line_set(IOP3XX_GPIO_LINE(4), GPIO_LOW); 86 gpio_set_value(4, 0);
86 } 87 }
87#endif 88#endif
88 /* NB SR bits not same position as CR IE bits :-( */ 89 /* NB SR bits not same position as CR IE bits :-( */
89 iop3xx_adap->SR_enabled = 90 iop3xx_adap->SR_enabled =
90 IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD | 91 IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD |
91 IOP3XX_ISR_RXFULL | IOP3XX_ISR_TXEMPTY; 92 IOP3XX_ISR_RXFULL | IOP3XX_ISR_TXEMPTY;
92 93
@@ -96,23 +97,23 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
96 __raw_writel(cr, iop3xx_adap->ioaddr + CR_OFFSET); 97 __raw_writel(cr, iop3xx_adap->ioaddr + CR_OFFSET);
97} 98}
98 99
99static void 100static void
100iop3xx_i2c_transaction_cleanup(struct i2c_algo_iop3xx_data *iop3xx_adap) 101iop3xx_i2c_transaction_cleanup(struct i2c_algo_iop3xx_data *iop3xx_adap)
101{ 102{
102 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET); 103 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET);
103 104
104 cr &= ~(IOP3XX_ICR_MSTART | IOP3XX_ICR_TBYTE | 105 cr &= ~(IOP3XX_ICR_MSTART | IOP3XX_ICR_TBYTE |
105 IOP3XX_ICR_MSTOP | IOP3XX_ICR_SCLEN); 106 IOP3XX_ICR_MSTOP | IOP3XX_ICR_SCLEN);
106 107
107 __raw_writel(cr, iop3xx_adap->ioaddr + CR_OFFSET); 108 __raw_writel(cr, iop3xx_adap->ioaddr + CR_OFFSET);
108} 109}
109 110
110/* 111/*
111 * NB: the handler has to clear the source of the interrupt! 112 * NB: the handler has to clear the source of the interrupt!
112 * Then it passes the SR flags of interest to BH via adap data 113 * Then it passes the SR flags of interest to BH via adap data
113 */ 114 */
114static irqreturn_t 115static irqreturn_t
115iop3xx_i2c_irq_handler(int this_irq, void *dev_id) 116iop3xx_i2c_irq_handler(int this_irq, void *dev_id)
116{ 117{
117 struct i2c_algo_iop3xx_data *iop3xx_adap = dev_id; 118 struct i2c_algo_iop3xx_data *iop3xx_adap = dev_id;
118 u32 sr = __raw_readl(iop3xx_adap->ioaddr + SR_OFFSET); 119 u32 sr = __raw_readl(iop3xx_adap->ioaddr + SR_OFFSET);
@@ -126,7 +127,7 @@ iop3xx_i2c_irq_handler(int this_irq, void *dev_id)
126} 127}
127 128
128/* check all error conditions, clear them , report most important */ 129/* check all error conditions, clear them , report most important */
129static int 130static int
130iop3xx_i2c_error(u32 sr) 131iop3xx_i2c_error(u32 sr)
131{ 132{
132 int rc = 0; 133 int rc = 0;
@@ -135,12 +136,12 @@ iop3xx_i2c_error(u32 sr)
135 if ( !rc ) rc = -I2C_ERR_BERR; 136 if ( !rc ) rc = -I2C_ERR_BERR;
136 } 137 }
137 if ((sr & IOP3XX_ISR_ALD)) { 138 if ((sr & IOP3XX_ISR_ALD)) {
138 if ( !rc ) rc = -I2C_ERR_ALD; 139 if ( !rc ) rc = -I2C_ERR_ALD;
139 } 140 }
140 return rc; 141 return rc;
141} 142}
142 143
143static inline u32 144static inline u32
144iop3xx_i2c_get_srstat(struct i2c_algo_iop3xx_data *iop3xx_adap) 145iop3xx_i2c_get_srstat(struct i2c_algo_iop3xx_data *iop3xx_adap)
145{ 146{
146 unsigned long flags; 147 unsigned long flags;
@@ -161,8 +162,8 @@ iop3xx_i2c_get_srstat(struct i2c_algo_iop3xx_data *iop3xx_adap)
161typedef int (* compare_func)(unsigned test, unsigned mask); 162typedef int (* compare_func)(unsigned test, unsigned mask);
162/* returns 1 on correct comparison */ 163/* returns 1 on correct comparison */
163 164
164static int 165static int
165iop3xx_i2c_wait_event(struct i2c_algo_iop3xx_data *iop3xx_adap, 166iop3xx_i2c_wait_event(struct i2c_algo_iop3xx_data *iop3xx_adap,
166 unsigned flags, unsigned* status, 167 unsigned flags, unsigned* status,
167 compare_func compare) 168 compare_func compare)
168{ 169{
@@ -192,47 +193,47 @@ iop3xx_i2c_wait_event(struct i2c_algo_iop3xx_data *iop3xx_adap,
192} 193}
193 194
194/* 195/*
195 * Concrete compare_funcs 196 * Concrete compare_funcs
196 */ 197 */
197static int 198static int
198all_bits_clear(unsigned test, unsigned mask) 199all_bits_clear(unsigned test, unsigned mask)
199{ 200{
200 return (test & mask) == 0; 201 return (test & mask) == 0;
201} 202}
202 203
203static int 204static int
204any_bits_set(unsigned test, unsigned mask) 205any_bits_set(unsigned test, unsigned mask)
205{ 206{
206 return (test & mask) != 0; 207 return (test & mask) != 0;
207} 208}
208 209
209static int 210static int
210iop3xx_i2c_wait_tx_done(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status) 211iop3xx_i2c_wait_tx_done(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
211{ 212{
212 return iop3xx_i2c_wait_event( 213 return iop3xx_i2c_wait_event(
213 iop3xx_adap, 214 iop3xx_adap,
214 IOP3XX_ISR_TXEMPTY | IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD, 215 IOP3XX_ISR_TXEMPTY | IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD,
215 status, any_bits_set); 216 status, any_bits_set);
216} 217}
217 218
218static int 219static int
219iop3xx_i2c_wait_rx_done(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status) 220iop3xx_i2c_wait_rx_done(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
220{ 221{
221 return iop3xx_i2c_wait_event( 222 return iop3xx_i2c_wait_event(
222 iop3xx_adap, 223 iop3xx_adap,
223 IOP3XX_ISR_RXFULL | IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD, 224 IOP3XX_ISR_RXFULL | IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD,
224 status, any_bits_set); 225 status, any_bits_set);
225} 226}
226 227
227static int 228static int
228iop3xx_i2c_wait_idle(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status) 229iop3xx_i2c_wait_idle(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
229{ 230{
230 return iop3xx_i2c_wait_event( 231 return iop3xx_i2c_wait_event(
231 iop3xx_adap, IOP3XX_ISR_UNITBUSY, status, all_bits_clear); 232 iop3xx_adap, IOP3XX_ISR_UNITBUSY, status, all_bits_clear);
232} 233}
233 234
234static int 235static int
235iop3xx_i2c_send_target_addr(struct i2c_algo_iop3xx_data *iop3xx_adap, 236iop3xx_i2c_send_target_addr(struct i2c_algo_iop3xx_data *iop3xx_adap,
236 struct i2c_msg* msg) 237 struct i2c_msg* msg)
237{ 238{
238 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET); 239 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET);
@@ -247,7 +248,7 @@ iop3xx_i2c_send_target_addr(struct i2c_algo_iop3xx_data *iop3xx_adap,
247 } 248 }
248 249
249 __raw_writel(iic_cook_addr(msg), iop3xx_adap->ioaddr + DBR_OFFSET); 250 __raw_writel(iic_cook_addr(msg), iop3xx_adap->ioaddr + DBR_OFFSET);
250 251
251 cr &= ~(IOP3XX_ICR_MSTOP | IOP3XX_ICR_NACK); 252 cr &= ~(IOP3XX_ICR_MSTOP | IOP3XX_ICR_NACK);
252 cr |= IOP3XX_ICR_MSTART | IOP3XX_ICR_TBYTE; 253 cr |= IOP3XX_ICR_MSTART | IOP3XX_ICR_TBYTE;
253 254
@@ -257,8 +258,8 @@ iop3xx_i2c_send_target_addr(struct i2c_algo_iop3xx_data *iop3xx_adap,
257 return rc; 258 return rc;
258} 259}
259 260
260static int 261static int
261iop3xx_i2c_write_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char byte, 262iop3xx_i2c_write_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char byte,
262 int stop) 263 int stop)
263{ 264{
264 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET); 265 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET);
@@ -277,10 +278,10 @@ iop3xx_i2c_write_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char byte,
277 rc = iop3xx_i2c_wait_tx_done(iop3xx_adap, &status); 278 rc = iop3xx_i2c_wait_tx_done(iop3xx_adap, &status);
278 279
279 return rc; 280 return rc;
280} 281}
281 282
282static int 283static int
283iop3xx_i2c_read_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char* byte, 284iop3xx_i2c_read_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char* byte,
284 int stop) 285 int stop)
285{ 286{
286 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET); 287 unsigned long cr = __raw_readl(iop3xx_adap->ioaddr + CR_OFFSET);
@@ -304,19 +305,19 @@ iop3xx_i2c_read_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char* byte,
304 return rc; 305 return rc;
305} 306}
306 307
307static int 308static int
308iop3xx_i2c_writebytes(struct i2c_adapter *i2c_adap, const char *buf, int count) 309iop3xx_i2c_writebytes(struct i2c_adapter *i2c_adap, const char *buf, int count)
309{ 310{
310 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data; 311 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
311 int ii; 312 int ii;
312 int rc = 0; 313 int rc = 0;
313 314
314 for (ii = 0; rc == 0 && ii != count; ++ii) 315 for (ii = 0; rc == 0 && ii != count; ++ii)
315 rc = iop3xx_i2c_write_byte(iop3xx_adap, buf[ii], ii==count-1); 316 rc = iop3xx_i2c_write_byte(iop3xx_adap, buf[ii], ii==count-1);
316 return rc; 317 return rc;
317} 318}
318 319
319static int 320static int
320iop3xx_i2c_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count) 321iop3xx_i2c_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count)
321{ 322{
322 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data; 323 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
@@ -325,7 +326,7 @@ iop3xx_i2c_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count)
325 326
326 for (ii = 0; rc == 0 && ii != count; ++ii) 327 for (ii = 0; rc == 0 && ii != count; ++ii)
327 rc = iop3xx_i2c_read_byte(iop3xx_adap, &buf[ii], ii==count-1); 328 rc = iop3xx_i2c_read_byte(iop3xx_adap, &buf[ii], ii==count-1);
328 329
329 return rc; 330 return rc;
330} 331}
331 332
@@ -336,8 +337,8 @@ iop3xx_i2c_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count)
336 * Each transfer (i.e. a read or a write) is separated by a repeated start 337 * Each transfer (i.e. a read or a write) is separated by a repeated start
337 * condition. 338 * condition.
338 */ 339 */
339static int 340static int
340iop3xx_i2c_handle_msg(struct i2c_adapter *i2c_adap, struct i2c_msg* pmsg) 341iop3xx_i2c_handle_msg(struct i2c_adapter *i2c_adap, struct i2c_msg* pmsg)
341{ 342{
342 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data; 343 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
343 int rc; 344 int rc;
@@ -357,8 +358,8 @@ iop3xx_i2c_handle_msg(struct i2c_adapter *i2c_adap, struct i2c_msg* pmsg)
357/* 358/*
358 * master_xfer() - main read/write entry 359 * master_xfer() - main read/write entry
359 */ 360 */
360static int 361static int
361iop3xx_i2c_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, 362iop3xx_i2c_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
362 int num) 363 int num)
363{ 364{
364 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data; 365 struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
@@ -375,14 +376,14 @@ iop3xx_i2c_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
375 } 376 }
376 377
377 iop3xx_i2c_transaction_cleanup(iop3xx_adap); 378 iop3xx_i2c_transaction_cleanup(iop3xx_adap);
378 379
379 if(ret) 380 if(ret)
380 return ret; 381 return ret;
381 382
382 return im; 383 return im;
383} 384}
384 385
385static u32 386static u32
386iop3xx_i2c_func(struct i2c_adapter *adap) 387iop3xx_i2c_func(struct i2c_adapter *adap)
387{ 388{
388 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 389 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
@@ -393,11 +394,11 @@ static const struct i2c_algorithm iop3xx_i2c_algo = {
393 .functionality = iop3xx_i2c_func, 394 .functionality = iop3xx_i2c_func,
394}; 395};
395 396
396static int 397static int
397iop3xx_i2c_remove(struct platform_device *pdev) 398iop3xx_i2c_remove(struct platform_device *pdev)
398{ 399{
399 struct i2c_adapter *padapter = platform_get_drvdata(pdev); 400 struct i2c_adapter *padapter = platform_get_drvdata(pdev);
400 struct i2c_algo_iop3xx_data *adapter_data = 401 struct i2c_algo_iop3xx_data *adapter_data =
401 (struct i2c_algo_iop3xx_data *)padapter->algo_data; 402 (struct i2c_algo_iop3xx_data *)padapter->algo_data;
402 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 403 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
403 unsigned long cr = __raw_readl(adapter_data->ioaddr + CR_OFFSET); 404 unsigned long cr = __raw_readl(adapter_data->ioaddr + CR_OFFSET);
@@ -419,7 +420,7 @@ iop3xx_i2c_remove(struct platform_device *pdev)
419 return 0; 420 return 0;
420} 421}
421 422
422static int 423static int
423iop3xx_i2c_probe(struct platform_device *pdev) 424iop3xx_i2c_probe(struct platform_device *pdev)
424{ 425{
425 struct resource *res; 426 struct resource *res;