Lines Matching +full:mmp +full:- +full:twsi
7 * Copyright (C) 2004-2005 Deep Blue Solutions Ltd.
16 * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
17 * Jan 2003: added limited signal handling [Kai-Uwe Bloem]
31 #include <linux/i2c-pxa.h>
39 #include <linux/platform_data/i2c-pxa.h>
63 #define ICR_BUSMODE_FM (1 << 16) /* shifted fast mode for armada-3700 */
64 #define ICR_BUSMODE_HS (1 << 17) /* shifted high speed mode for armada-3700 */
112 { "pxa2xx-i2c", REGS_PXA2XX },
113 { "pxa3xx-pwri2c", REGS_PXA3XX },
114 { "ce4100-i2c", REGS_CE4100 },
115 { "pxa910-i2c", REGS_PXA910 },
116 { "armada-3700-i2c", REGS_A3700 },
216 #define _IBMR(i2c) ((i2c)->reg_ibmr)
217 #define _IDBR(i2c) ((i2c)->reg_idbr)
218 #define _ICR(i2c) ((i2c)->reg_icr)
219 #define _ISR(i2c) ((i2c)->reg_isr)
220 #define _ISAR(i2c) ((i2c)->reg_isar)
221 #define _ILCR(i2c) ((i2c)->reg_ilcr)
222 #define _IWCR(i2c) ((i2c)->reg_iwcr)
242 while (num--) { in decode_bits()
243 const char *str = val & bits->mask ? bits->set : bits->unset; in decode_bits()
300 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno, in i2c_pxa_show_state()
309 struct device *dev = &i2c->adap.dev; in i2c_pxa_scream_blue_murder()
312 i2c->req_slave_addr >> 1, why); in i2c_pxa_scream_blue_murder()
314 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); in i2c_pxa_scream_blue_murder()
319 for (i = 0; i < i2c->irqlogidx; i++) in i2c_pxa_scream_blue_murder()
320 pr_cont(" [%03x:%05x]", i2c->isrlog[i], i2c->icrlog[i]); in i2c_pxa_scream_blue_murder()
348 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__); in i2c_pxa_abort()
363 i --; in i2c_pxa_abort()
374 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) { in i2c_pxa_wait_bus_not_busy()
394 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_wait_master()
399 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__); in i2c_pxa_wait_master()
409 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); in i2c_pxa_wait_master()
417 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__); in i2c_pxa_wait_master()
425 dev_dbg(&i2c->adap.dev, "setting to bus master\n"); in i2c_pxa_set_master()
428 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__); in i2c_pxa_set_master()
430 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__); in i2c_pxa_set_master()
450 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_wait_slave()
457 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); in i2c_pxa_wait_slave()
465 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__); in i2c_pxa_wait_slave()
489 dev_err(&i2c->adap.dev, "%s: wait timedout\n", in i2c_pxa_set_slave()
499 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c))); in i2c_pxa_set_slave()
519 if (i2c->reg_isar && IS_ENABLED(CONFIG_I2C_PXA_SLAVE)) in i2c_pxa_reset()
520 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_reset()
523 writel(I2C_ICR_INIT | (i2c->fast_mode ? i2c->fm_mask : 0), _ICR(i2c)); in i2c_pxa_reset()
524 writel(readl(_ICR(i2c)) | (i2c->high_mode ? i2c->hs_mask : 0), _ICR(i2c)); in i2c_pxa_reset()
527 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); in i2c_pxa_reset()
551 if (i2c->slave != NULL) in i2c_pxa_slave_txempty()
552 ret = i2c->slave->read(i2c->slave->data); in i2c_pxa_slave_txempty()
563 if (i2c->slave != NULL) in i2c_pxa_slave_rxfull()
564 i2c->slave->write(i2c->slave->data, byte); in i2c_pxa_slave_rxfull()
574 dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n", in i2c_pxa_slave_start()
577 if (i2c->slave != NULL) in i2c_pxa_slave_start()
578 i2c->slave->event(i2c->slave->data, in i2c_pxa_slave_start()
595 timeout--; in i2c_pxa_slave_start()
598 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n"); in i2c_pxa_slave_start()
609 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n"); in i2c_pxa_slave_stop()
611 if (i2c->slave != NULL) in i2c_pxa_slave_stop()
612 i2c->slave->event(i2c->slave->data, I2C_SLAVE_EVENT_STOP); in i2c_pxa_slave_stop()
615 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n"); in i2c_pxa_slave_stop()
618 * If we have a master-mode message waiting, in i2c_pxa_slave_stop()
621 if (i2c->msg) in i2c_pxa_slave_stop()
658 timeout--; in i2c_pxa_slave_start()
661 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n"); in i2c_pxa_slave_start()
671 if (i2c->msg) in i2c_pxa_slave_stop()
682 unsigned int addr = (msg->addr & 0x7f) << 1; in i2c_pxa_addr_byte()
684 if (msg->flags & I2C_M_RD) in i2c_pxa_addr_byte()
697 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c)); in i2c_pxa_start_message()
698 i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg); in i2c_pxa_start_message()
725 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) { in i2c_pxa_pio_set_master()
732 dev_err(&i2c->adap.dev, in i2c_pxa_pio_set_master()
756 spin_lock_irq(&i2c->lock); in i2c_pxa_send_mastercode()
757 i2c->highmode_enter = true; in i2c_pxa_send_mastercode()
758 writel(i2c->master_code, _IDBR(i2c)); in i2c_pxa_send_mastercode()
764 spin_unlock_irq(&i2c->lock); in i2c_pxa_send_mastercode()
765 timeout = wait_event_timeout(i2c->wait, in i2c_pxa_send_mastercode()
766 i2c->highmode_enter == false, HZ * 1); in i2c_pxa_send_mastercode()
768 i2c->highmode_enter = false; in i2c_pxa_send_mastercode()
783 i2c->msg = msg; in i2c_pxa_do_pio_xfer()
784 i2c->msg_num = num; in i2c_pxa_do_pio_xfer()
785 i2c->msg_idx = 0; in i2c_pxa_do_pio_xfer()
786 i2c->msg_ptr = 0; in i2c_pxa_do_pio_xfer()
787 i2c->irqlogidx = 0; in i2c_pxa_do_pio_xfer()
791 while (i2c->msg_num > 0 && --timeout) { in i2c_pxa_do_pio_xfer()
799 * We place the return code in i2c->msg_idx. in i2c_pxa_do_pio_xfer()
801 ret = i2c->msg_idx; in i2c_pxa_do_pio_xfer()
825 dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n"); in i2c_pxa_do_xfer()
834 dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret); in i2c_pxa_do_xfer()
838 if (i2c->high_mode) { in i2c_pxa_do_xfer()
841 dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n"); in i2c_pxa_do_xfer()
846 spin_lock_irq(&i2c->lock); in i2c_pxa_do_xfer()
848 i2c->msg = msg; in i2c_pxa_do_xfer()
849 i2c->msg_num = num; in i2c_pxa_do_xfer()
850 i2c->msg_idx = 0; in i2c_pxa_do_xfer()
851 i2c->msg_ptr = 0; in i2c_pxa_do_xfer()
852 i2c->irqlogidx = 0; in i2c_pxa_do_xfer()
856 spin_unlock_irq(&i2c->lock); in i2c_pxa_do_xfer()
861 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); in i2c_pxa_do_xfer()
865 * We place the return code in i2c->msg_idx. in i2c_pxa_do_xfer()
867 ret = i2c->msg_idx; in i2c_pxa_do_xfer()
869 if (!timeout && i2c->msg_num) { in i2c_pxa_do_xfer()
881 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_pio_xfer()
891 for (i = adap->retries; i >= 0; i--) { in i2c_pxa_pio_xfer()
897 dev_dbg(&adap->dev, "Retrying transmission\n"); in i2c_pxa_pio_xfer()
901 ret = -EREMOTEIO; in i2c_pxa_pio_xfer()
908 * i2c_pxa_master_complete - complete the message and wake up.
912 i2c->msg_ptr = 0; in i2c_pxa_master_complete()
913 i2c->msg = NULL; in i2c_pxa_master_complete()
914 i2c->msg_idx ++; in i2c_pxa_master_complete()
915 i2c->msg_num = 0; in i2c_pxa_master_complete()
917 i2c->msg_idx = ret; in i2c_pxa_master_complete()
918 if (!i2c->use_pio) in i2c_pxa_master_complete()
919 wake_up(&i2c->wait); in i2c_pxa_master_complete()
947 (!((i2c->msg->flags & I2C_M_IGNORE_NAK) && in i2c_pxa_irq_txempty()
952 * I2C bus error - either the device NAK'd us, or in i2c_pxa_irq_txempty()
957 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0) in i2c_pxa_irq_txempty()
968 if (i2c->msg_ptr == i2c->msg->len - 1 && in i2c_pxa_irq_txempty()
969 i2c->msg_idx == i2c->msg_num - 1) in i2c_pxa_irq_txempty()
973 } else if (i2c->msg_ptr < i2c->msg->len) { in i2c_pxa_irq_txempty()
977 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c)); in i2c_pxa_irq_txempty()
985 if ((i2c->msg_ptr == i2c->msg->len) && in i2c_pxa_irq_txempty()
986 ((i2c->msg->flags & I2C_M_STOP) || in i2c_pxa_irq_txempty()
987 (i2c->msg_idx == i2c->msg_num - 1))) in i2c_pxa_irq_txempty()
990 } else if (i2c->msg_idx < i2c->msg_num - 1) { in i2c_pxa_irq_txempty()
994 i2c->msg_ptr = 0; in i2c_pxa_irq_txempty()
995 i2c->msg_idx ++; in i2c_pxa_irq_txempty()
996 i2c->msg++; in i2c_pxa_irq_txempty()
1003 if (i2c->msg->flags & I2C_M_NOSTART) in i2c_pxa_irq_txempty()
1009 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c)); in i2c_pxa_irq_txempty()
1010 i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg); in i2c_pxa_irq_txempty()
1018 if (i2c->msg->len == 0) { in i2c_pxa_irq_txempty()
1029 i2c->icrlog[i2c->irqlogidx-1] = icr; in i2c_pxa_irq_txempty()
1042 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c)); in i2c_pxa_irq_rxfull()
1044 if (i2c->msg_ptr < i2c->msg->len) { in i2c_pxa_irq_rxfull()
1049 if (i2c->msg_ptr == i2c->msg->len - 1) in i2c_pxa_irq_rxfull()
1057 i2c->icrlog[i2c->irqlogidx-1] = icr; in i2c_pxa_irq_rxfull()
1073 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_handler()
1078 if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog)) in i2c_pxa_handler()
1079 i2c->isrlog[i2c->irqlogidx++] = isr; in i2c_pxa_handler()
1098 } else if (i2c->msg && (!i2c->highmode_enter)) { in i2c_pxa_handler()
1103 } else if ((isr & ISR_ITE) && i2c->highmode_enter) { in i2c_pxa_handler()
1104 i2c->highmode_enter = false; in i2c_pxa_handler()
1105 wake_up(&i2c->wait); in i2c_pxa_handler()
1116 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_xfer()
1119 for (i = adap->retries; i >= 0; i--) { in i2c_pxa_xfer()
1125 dev_dbg(&adap->dev, "Retrying transmission\n"); in i2c_pxa_xfer()
1129 ret = -EREMOTEIO; in i2c_pxa_xfer()
1152 { .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX },
1154 { .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA910 },
1155 { .compatible = "marvell,armada-3700-i2c", .data = (void *)REGS_A3700 },
1163 struct device_node *np = pdev->dev.of_node; in i2c_pxa_probe_dt()
1165 of_match_device(i2c_pxa_dt_ids, &pdev->dev); in i2c_pxa_probe_dt()
1170 /* For device tree we always use the dynamic or alias-assigned ID */ in i2c_pxa_probe_dt()
1171 i2c->adap.nr = -1; in i2c_pxa_probe_dt()
1173 if (of_get_property(np, "mrvl,i2c-polling", NULL)) in i2c_pxa_probe_dt()
1174 i2c->use_pio = 1; in i2c_pxa_probe_dt()
1175 if (of_get_property(np, "mrvl,i2c-fast-mode", NULL)) in i2c_pxa_probe_dt()
1176 i2c->fast_mode = 1; in i2c_pxa_probe_dt()
1178 *i2c_types = (enum pxa_i2c_types)(of_id->data); in i2c_pxa_probe_dt()
1187 struct i2c_pxa_platform_data *plat = dev_get_platdata(&pdev->dev); in i2c_pxa_probe_pdata()
1190 *i2c_types = id->driver_data; in i2c_pxa_probe_pdata()
1192 i2c->use_pio = plat->use_pio; in i2c_pxa_probe_pdata()
1193 i2c->fast_mode = plat->fast_mode; in i2c_pxa_probe_pdata()
1194 i2c->high_mode = plat->high_mode; in i2c_pxa_probe_pdata()
1195 i2c->master_code = plat->master_code; in i2c_pxa_probe_pdata()
1196 if (!i2c->master_code) in i2c_pxa_probe_pdata()
1197 i2c->master_code = 0xe; in i2c_pxa_probe_pdata()
1198 i2c->rate = plat->rate; in i2c_pxa_probe_pdata()
1205 struct i2c_pxa_platform_data *plat = dev_get_platdata(&dev->dev); in i2c_pxa_probe()
1211 i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); in i2c_pxa_probe()
1213 return -ENOMEM; in i2c_pxa_probe()
1216 i2c->reg_base = devm_ioremap_resource(&dev->dev, res); in i2c_pxa_probe()
1217 if (IS_ERR(i2c->reg_base)) in i2c_pxa_probe()
1218 return PTR_ERR(i2c->reg_base); in i2c_pxa_probe()
1222 dev_err(&dev->dev, "no irq resource: %d\n", irq); in i2c_pxa_probe()
1227 i2c->adap.nr = dev->id; in i2c_pxa_probe()
1235 i2c->adap.owner = THIS_MODULE; in i2c_pxa_probe()
1236 i2c->adap.retries = 5; in i2c_pxa_probe()
1238 spin_lock_init(&i2c->lock); in i2c_pxa_probe()
1239 init_waitqueue_head(&i2c->wait); in i2c_pxa_probe()
1241 strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); in i2c_pxa_probe()
1243 i2c->clk = devm_clk_get(&dev->dev, NULL); in i2c_pxa_probe()
1244 if (IS_ERR(i2c->clk)) { in i2c_pxa_probe()
1245 dev_err(&dev->dev, "failed to get the clk: %ld\n", PTR_ERR(i2c->clk)); in i2c_pxa_probe()
1246 return PTR_ERR(i2c->clk); in i2c_pxa_probe()
1249 i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; in i2c_pxa_probe()
1250 i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr; in i2c_pxa_probe()
1251 i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr; in i2c_pxa_probe()
1252 i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr; in i2c_pxa_probe()
1253 i2c->fm_mask = pxa_reg_layout[i2c_type].fm ? : ICR_FM; in i2c_pxa_probe()
1254 i2c->hs_mask = pxa_reg_layout[i2c_type].hs ? : ICR_HS; in i2c_pxa_probe()
1257 i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar; in i2c_pxa_probe()
1260 i2c->reg_ilcr = i2c->reg_base + pxa_reg_layout[i2c_type].ilcr; in i2c_pxa_probe()
1261 i2c->reg_iwcr = i2c->reg_base + pxa_reg_layout[i2c_type].iwcr; in i2c_pxa_probe()
1264 i2c->iobase = res->start; in i2c_pxa_probe()
1265 i2c->iosize = resource_size(res); in i2c_pxa_probe()
1267 i2c->irq = irq; in i2c_pxa_probe()
1269 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; in i2c_pxa_probe()
1270 i2c->highmode_enter = false; in i2c_pxa_probe()
1274 i2c->slave_addr = plat->slave_addr; in i2c_pxa_probe()
1275 i2c->slave = plat->slave; in i2c_pxa_probe()
1277 i2c->adap.class = plat->class; in i2c_pxa_probe()
1280 if (i2c->high_mode) { in i2c_pxa_probe()
1281 if (i2c->rate) { in i2c_pxa_probe()
1282 clk_set_rate(i2c->clk, i2c->rate); in i2c_pxa_probe()
1284 i2c->adap.name, clk_get_rate(i2c->clk)); in i2c_pxa_probe()
1287 i2c->adap.name); in i2c_pxa_probe()
1290 clk_prepare_enable(i2c->clk); in i2c_pxa_probe()
1292 if (i2c->use_pio) { in i2c_pxa_probe()
1293 i2c->adap.algo = &i2c_pxa_pio_algorithm; in i2c_pxa_probe()
1295 i2c->adap.algo = &i2c_pxa_algorithm; in i2c_pxa_probe()
1296 ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler, in i2c_pxa_probe()
1298 dev_name(&dev->dev), i2c); in i2c_pxa_probe()
1300 dev_err(&dev->dev, "failed to request irq: %d\n", ret); in i2c_pxa_probe()
1307 i2c->adap.algo_data = i2c; in i2c_pxa_probe()
1308 i2c->adap.dev.parent = &dev->dev; in i2c_pxa_probe()
1310 i2c->adap.dev.of_node = dev->dev.of_node; in i2c_pxa_probe()
1313 ret = i2c_add_numbered_adapter(&i2c->adap); in i2c_pxa_probe()
1320 dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n", in i2c_pxa_probe()
1321 i2c->slave_addr); in i2c_pxa_probe()
1323 dev_info(&i2c->adap.dev, " PXA I2C adapter\n"); in i2c_pxa_probe()
1328 clk_disable_unprepare(i2c->clk); in i2c_pxa_probe()
1336 i2c_del_adapter(&i2c->adap); in i2c_pxa_remove()
1338 clk_disable_unprepare(i2c->clk); in i2c_pxa_remove()
1348 clk_disable(i2c->clk); in i2c_pxa_suspend_noirq()
1357 clk_enable(i2c->clk); in i2c_pxa_resume_noirq()
1377 .name = "pxa2xx-i2c",
1395 MODULE_ALIAS("platform:pxa2xx-i2c");