32 #include <linux/kernel.h>
33 #include <linux/module.h>
35 #include <linux/slab.h>
38 #include <linux/errno.h>
39 #include <linux/stddef.h>
40 #include <linux/i2c.h>
51 #undef I2C_CHIP_ERRATA
53 #define CPM_MAX_READ 513
57 #define I2C_EB_CPM2 (0x30)
59 #define DPRAM_BASE ((u8 __iomem __force *)cpm_muram_addr(0))
83 #define I2COM_START 0x80
84 #define I2COM_MASTER 0x01
85 #define I2CER_TXE 0x10
86 #define I2CER_BUSY 0x04
87 #define I2CER_TXB 0x02
88 #define I2CER_RXB 0x01
134 cpm = i2c_get_adapdata(dev_id);
148 static void cpm_reset_i2c_params(
struct cpm_i2c *
cpm)
178 static void cpm_i2c_force_close(
struct i2c_adapter *adap)
180 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
183 dev_dbg(&adap->
dev,
"cpm_i2c_force_close()\n");
191 static void cpm_i2c_parse_message(
struct i2c_adapter *adap,
199 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
204 addr = pmsg->
addr << 1;
232 dev_dbg(&adap->
dev,
"cpm_i2c_read(abyte=0x%x)\n", addr);
243 dev_dbg(&adap->
dev,
"cpm_i2c_write(abyte=0x%x)\n", addr);
252 static int cpm_i2c_check_message(
struct i2c_adapter *adap,
253 struct i2c_msg *pmsg,
int tx,
int rx)
259 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
272 dev_dbg(&adap->
dev,
"tx sc 0x%04x, rx sc 0x%04x\n",
281 "I2C read; complete but rbuf empty\n");
302 dev_err(&adap->
dev,
"I2C write; Collision\n");
311 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
325 for (i = 0; i < num; i++) {
343 dev_dbg(&adap->
dev,
"R: %d T: %d\n", rptr, tptr);
345 cpm_i2c_parse_message(adap, pmsg, num, tptr, rptr);
377 dev_err(&adap->
dev,
"I2C transfer: timeout\n");
382 ret = cpm_i2c_check_message(adap, pmsg, tptr, rptr);
390 #ifdef I2C_CHIP_ERRATA
401 cpm_i2c_force_close(adap);
402 #ifdef I2C_CHIP_ERRATA
419 .master_xfer = cpm_i2c_xfer,
420 .functionality = cpm_i2c_func,
426 .algo = &cpm_i2c_algo,
455 if (i2c_base ==
NULL) {
499 if (!data || len != 4) {
506 if (data && len == 4)
510 if (data && len == 4)
537 if (!cpm->
rxbuf[i]) {
544 if (!cpm->
txbuf[i]) {
553 cpm_reset_i2c_params(cpm);
555 dev_dbg(&cpm->
ofdev->dev,
"i2c_ram 0x%p, i2c_addr 0x%04x, freq %d\n",
557 dev_dbg(&cpm->
ofdev->dev,
"tbase 0x%04x, rbase 0x%04x\n",
573 brg = get_brgfreq() / (32 * 2 * cpm->
freq) - 3;
607 static void cpm_i2c_shutdown(
struct cpm_i2c *cpm)
652 i2c_set_adapdata(&cpm->
adap, cpm);
653 cpm->
adap.dev.parent = &ofdev->
dev;
654 cpm->
adap.dev.of_node = of_node_get(ofdev->
dev.of_node);
656 result = cpm_i2c_setup(cpm);
658 dev_err(&ofdev->
dev,
"Unable to init hardware\n");
669 dev_err(&ofdev->
dev,
"Unable to register with I2C\n");
673 dev_dbg(&ofdev->
dev,
"hw routines for %s registered.\n",
683 cpm_i2c_shutdown(cpm);
697 cpm_i2c_shutdown(cpm);
707 .compatible =
"fsl,cpm1-i2c",
710 .compatible =
"fsl,cpm2-i2c",
718 .probe = cpm_i2c_probe,
721 .name =
"fsl-i2c-cpm",
723 .of_match_table = cpm_i2c_match,