33 #include <linux/kernel.h>
34 #include <linux/module.h>
36 #include <linux/slab.h>
38 #include <linux/errno.h>
40 #include <linux/i2c.h>
49 static inline unsigned char
54 addr = (msg->
addr << 1);
80 #if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X)
81 if (iop3xx_adap->
id == 0) {
116 iop3xx_i2c_irq_handler(
int this_irq,
void *
dev_id)
131 iop3xx_i2c_error(
u32 sr)
153 spin_unlock_irqrestore(&iop3xx_adap->
lock, flags);
178 (done = compare( sr = iop3xx_i2c_get_srstat(iop3xx_adap) ,flags )),
181 if ((rc = iop3xx_i2c_error(sr)) < 0) {
184 }
else if (!interrupted) {
199 all_bits_clear(
unsigned test,
unsigned mask)
201 return (test & mask) == 0;
205 any_bits_set(
unsigned test,
unsigned mask)
207 return (test & mask) != 0;
213 return iop3xx_i2c_wait_event(
216 status, any_bits_set);
222 return iop3xx_i2c_wait_event(
225 status, any_bits_set);
231 return iop3xx_i2c_wait_event(
256 rc = iop3xx_i2c_wait_tx_done(iop3xx_adap, &status);
278 rc = iop3xx_i2c_wait_tx_done(iop3xx_adap, &status);
301 rc = iop3xx_i2c_wait_rx_done(iop3xx_adap, &status);
315 for (ii = 0; rc == 0 && ii !=
count; ++ii)
316 rc = iop3xx_i2c_write_byte(iop3xx_adap, buf[ii], ii==count-1);
321 iop3xx_i2c_readbytes(
struct i2c_adapter *i2c_adap,
char *buf,
int count)
327 for (ii = 0; rc == 0 && ii !=
count; ++ii)
328 rc = iop3xx_i2c_read_byte(iop3xx_adap, &buf[ii], ii==count-1);
346 rc = iop3xx_i2c_send_target_addr(iop3xx_adap, pmsg);
352 return iop3xx_i2c_readbytes(i2c_adap, pmsg->
buf, pmsg->
len);
354 return iop3xx_i2c_writebytes(i2c_adap, pmsg->
buf, pmsg->
len);
370 iop3xx_i2c_wait_idle(iop3xx_adap, &status);
371 iop3xx_i2c_reset(iop3xx_adap);
372 iop3xx_i2c_enable(iop3xx_adap);
374 for (im = 0; ret == 0 && im != num; im++) {
375 ret = iop3xx_i2c_handle_msg(i2c_adap, &msgs[im]);
378 iop3xx_i2c_transaction_cleanup(iop3xx_adap);
393 .master_xfer = iop3xx_i2c_master_xfer,
394 .functionality = iop3xx_i2c_func,
400 struct i2c_adapter *padapter = platform_get_drvdata(pdev);
418 platform_set_drvdata(pdev,
NULL);
455 adapter_data->
id = i2c_id++;
458 if (!adapter_data->
ioaddr) {
469 pdev->
name, adapter_data);
479 new_adapter->
dev.parent = &pdev->
dev;
480 new_adapter->
nr = pdev->
id;
486 new_adapter->
algo = &iop3xx_i2c_algo;
491 iop3xx_i2c_reset(adapter_data);
492 iop3xx_i2c_enable(adapter_data);
494 platform_set_drvdata(pdev, new_adapter);
519 .probe = iop3xx_i2c_probe,
520 .remove = iop3xx_i2c_remove,
523 .name =
"IOP3xx-I2C",