• Home
  • Raw
  • Download

Lines Matching +full:iproc +full:- +full:i2c

15 #include <linux/i2c.h>
147 #define M_RX_FIFO_MAX_THLD_VALUE (M_TX_RX_FIFO_SIZE - 1)
247 if (iproc_i2c->idm_base) { in iproc_i2c_rd_reg()
248 spin_lock_irqsave(&iproc_i2c->idm_lock, flags); in iproc_i2c_rd_reg()
249 writel(iproc_i2c->ape_addr_mask, in iproc_i2c_rd_reg()
250 iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); in iproc_i2c_rd_reg()
251 val = readl(iproc_i2c->base + offset); in iproc_i2c_rd_reg()
252 spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags); in iproc_i2c_rd_reg()
254 val = readl(iproc_i2c->base + offset); in iproc_i2c_rd_reg()
265 if (iproc_i2c->idm_base) { in iproc_i2c_wr_reg()
266 spin_lock_irqsave(&iproc_i2c->idm_lock, flags); in iproc_i2c_wr_reg()
267 writel(iproc_i2c->ape_addr_mask, in iproc_i2c_wr_reg()
268 iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); in iproc_i2c_wr_reg()
269 writel(val, iproc_i2c->base + offset); in iproc_i2c_wr_reg()
270 spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags); in iproc_i2c_wr_reg()
272 writel(val, iproc_i2c->base + offset); in iproc_i2c_wr_reg()
281 iproc_i2c->tx_underrun = 0; in bcm_iproc_i2c_slave_init()
310 val |= (iproc_i2c->slave->addr << S_CFG_NIC_SMB_ADDR3_SHIFT); in bcm_iproc_i2c_slave_init()
322 iproc_i2c->slave_int_mask = val; in bcm_iproc_i2c_slave_init()
338 dev_err(iproc_i2c->device, "slave random stretch time timeout\n"); in bcm_iproc_i2c_check_slave_status()
340 /* re-initialize i2c for recovery */ in bcm_iproc_i2c_check_slave_status()
360 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_read()
362 iproc_i2c->rx_start_rcvd = true; in bcm_iproc_i2c_slave_read()
363 iproc_i2c->slave_read_complete = false; in bcm_iproc_i2c_slave_read()
365 iproc_i2c->rx_start_rcvd) { in bcm_iproc_i2c_slave_read()
367 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_read()
370 iproc_i2c->rx_start_rcvd) { in bcm_iproc_i2c_slave_read()
372 if (iproc_i2c->slave_rx_only) in bcm_iproc_i2c_slave_read()
373 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_read()
377 i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_STOP, in bcm_iproc_i2c_slave_read()
380 iproc_i2c->rx_start_rcvd = false; in bcm_iproc_i2c_slave_read()
381 iproc_i2c->slave_read_complete = true; in bcm_iproc_i2c_slave_read()
399 if (!iproc_i2c->slave_rx_only && iproc_i2c->slave_read_complete) { in slave_rx_tasklet_fn()
401 * In case of single byte master-read request, in slave_rx_tasklet_fn()
410 iproc_i2c->tx_underrun = 0; in slave_rx_tasklet_fn()
411 iproc_i2c->slave_int_mask |= BIT(IE_S_TX_UNDERRUN_SHIFT); in slave_rx_tasklet_fn()
420 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, iproc_i2c->slave_int_mask); in slave_rx_tasklet_fn()
430 * Slave events in case of master-write, master-write-read and, in bcm_iproc_i2c_slave_isr()
431 * master-read in bcm_iproc_i2c_slave_isr()
433 * Master-write : only IS_S_RX_EVENT_SHIFT event in bcm_iproc_i2c_slave_isr()
434 * Master-write-read: both IS_S_RX_EVENT_SHIFT and IS_S_RD_EVENT_SHIFT in bcm_iproc_i2c_slave_isr()
436 * Master-read : both IS_S_RX_EVENT_SHIFT and IS_S_RD_EVENT_SHIFT in bcm_iproc_i2c_slave_isr()
443 val &= ~iproc_i2c->slave_int_mask; in bcm_iproc_i2c_slave_isr()
447 /* Master-write-read request */ in bcm_iproc_i2c_slave_isr()
448 iproc_i2c->slave_rx_only = false; in bcm_iproc_i2c_slave_isr()
450 /* Master-write request only */ in bcm_iproc_i2c_slave_isr()
451 iproc_i2c->slave_rx_only = true; in bcm_iproc_i2c_slave_isr()
454 tasklet_schedule(&iproc_i2c->slave_rx_tasklet); in bcm_iproc_i2c_slave_isr()
462 iproc_i2c->tx_underrun++; in bcm_iproc_i2c_slave_isr()
463 if (iproc_i2c->tx_underrun == 1) in bcm_iproc_i2c_slave_isr()
465 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_isr()
470 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_isr()
490 iproc_i2c->slave_int_mask &= ~BIT(IE_S_TX_UNDERRUN_SHIFT); in bcm_iproc_i2c_slave_isr()
492 iproc_i2c->slave_int_mask); in bcm_iproc_i2c_slave_isr()
506 i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_STOP, &value); in bcm_iproc_i2c_slave_isr()
514 if (!iproc_i2c->slave_rx_only) in bcm_iproc_i2c_slave_isr()
522 struct i2c_msg *msg = iproc_i2c->msg; in bcm_iproc_i2c_read_valid_bytes()
526 while (iproc_i2c->rx_bytes < msg->len) { in bcm_iproc_i2c_read_valid_bytes()
533 msg->buf[iproc_i2c->rx_bytes] = in bcm_iproc_i2c_read_valid_bytes()
535 iproc_i2c->rx_bytes++; in bcm_iproc_i2c_read_valid_bytes()
541 struct i2c_msg *msg = iproc_i2c->msg; in bcm_iproc_i2c_send()
542 unsigned int tx_bytes = msg->len - iproc_i2c->tx_bytes; in bcm_iproc_i2c_send()
550 unsigned int idx = iproc_i2c->tx_bytes + i; in bcm_iproc_i2c_send()
552 val = msg->buf[idx]; in bcm_iproc_i2c_send()
555 if (idx == msg->len - 1) { in bcm_iproc_i2c_send()
558 if (iproc_i2c->irq) { in bcm_iproc_i2c_send()
577 iproc_i2c->tx_bytes += tx_bytes; in bcm_iproc_i2c_send()
582 struct i2c_msg *msg = iproc_i2c->msg; in bcm_iproc_i2c_read()
586 bytes_left = msg->len - iproc_i2c->rx_bytes; in bcm_iproc_i2c_read()
588 if (iproc_i2c->irq) { in bcm_iproc_i2c_read()
594 } else if (bytes_left < iproc_i2c->thld_bytes) { in bcm_iproc_i2c_read()
600 iproc_i2c->thld_bytes = bytes_left; in bcm_iproc_i2c_read()
603 * bytes_left >= iproc_i2c->thld_bytes, in bcm_iproc_i2c_read()
605 * It will remain as iproc_i2c->thld_bytes itself in bcm_iproc_i2c_read()
622 iproc_i2c->xfer_is_done = 1; in bcm_iproc_i2c_process_m_event()
623 if (iproc_i2c->irq) in bcm_iproc_i2c_process_m_event()
624 complete(&iproc_i2c->done); in bcm_iproc_i2c_process_m_event()
717 dev_dbg(iproc_i2c->device, "lost bus arbitration\n"); in bcm_iproc_i2c_check_status()
718 return -EAGAIN; in bcm_iproc_i2c_check_status()
721 dev_dbg(iproc_i2c->device, "NAK addr:0x%02x\n", msg->addr); in bcm_iproc_i2c_check_status()
722 return -ENXIO; in bcm_iproc_i2c_check_status()
725 dev_dbg(iproc_i2c->device, "NAK data\n"); in bcm_iproc_i2c_check_status()
726 return -ENXIO; in bcm_iproc_i2c_check_status()
729 dev_dbg(iproc_i2c->device, "bus timeout\n"); in bcm_iproc_i2c_check_status()
730 return -ETIMEDOUT; in bcm_iproc_i2c_check_status()
733 dev_dbg(iproc_i2c->device, "FIFO under-run\n"); in bcm_iproc_i2c_check_status()
734 return -ENXIO; in bcm_iproc_i2c_check_status()
737 dev_dbg(iproc_i2c->device, "RX FIFO full\n"); in bcm_iproc_i2c_check_status()
738 return -ETIMEDOUT; in bcm_iproc_i2c_check_status()
741 dev_dbg(iproc_i2c->device, "unknown error code=%d\n", val); in bcm_iproc_i2c_check_status()
743 /* re-initialize i2c for recovery */ in bcm_iproc_i2c_check_status()
748 return -EIO; in bcm_iproc_i2c_check_status()
762 if (iproc_i2c->irq) { in bcm_iproc_i2c_xfer_wait()
763 time_left = wait_for_completion_timeout(&iproc_i2c->done, in bcm_iproc_i2c_xfer_wait()
770 synchronize_irq(iproc_i2c->irq); in bcm_iproc_i2c_xfer_wait()
788 } while (!iproc_i2c->xfer_is_done); in bcm_iproc_i2c_xfer_wait()
791 if (!time_left && !iproc_i2c->xfer_is_done) { in bcm_iproc_i2c_xfer_wait()
792 dev_err(iproc_i2c->device, "transaction timed out\n"); in bcm_iproc_i2c_xfer_wait()
797 return -ETIMEDOUT; in bcm_iproc_i2c_xfer_wait()
812 * If 'process_call' is true, then this is a multi-msg transfer that requires
815 * The i2c quirks are set to enforce this rule.
829 dev_warn(iproc_i2c->device, "bus is busy\n"); in bcm_iproc_i2c_xfer_internal()
830 return -EBUSY; in bcm_iproc_i2c_xfer_internal()
833 iproc_i2c->msg = msg; in bcm_iproc_i2c_xfer_internal()
841 * loading up to TX FIFO size - 1 bytes of data since the first byte in bcm_iproc_i2c_xfer_internal()
844 tx_bytes = min_t(unsigned int, msg->len, M_TX_RX_FIFO_SIZE - 1); in bcm_iproc_i2c_xfer_internal()
845 if (!(msg->flags & I2C_M_RD)) { in bcm_iproc_i2c_xfer_internal()
847 val = msg->buf[i]; in bcm_iproc_i2c_xfer_internal()
850 if (!process_call && (i == msg->len - 1)) in bcm_iproc_i2c_xfer_internal()
855 iproc_i2c->tx_bytes = tx_bytes; in bcm_iproc_i2c_xfer_internal()
861 iproc_i2c->msg = msg; /* point to second msg */ in bcm_iproc_i2c_xfer_internal()
874 if (iproc_i2c->irq) in bcm_iproc_i2c_xfer_internal()
875 reinit_completion(&iproc_i2c->done); in bcm_iproc_i2c_xfer_internal()
877 iproc_i2c->xfer_is_done = 0; in bcm_iproc_i2c_xfer_internal()
891 if (!process_call && !(msg->flags & I2C_M_RD) && in bcm_iproc_i2c_xfer_internal()
892 msg->len > iproc_i2c->tx_bytes) in bcm_iproc_i2c_xfer_internal()
901 if (msg->len == 0) { in bcm_iproc_i2c_xfer_internal()
904 } else if (msg->flags & I2C_M_RD) { in bcm_iproc_i2c_xfer_internal()
907 iproc_i2c->rx_bytes = 0; in bcm_iproc_i2c_xfer_internal()
908 if (msg->len > M_RX_FIFO_MAX_THLD_VALUE) in bcm_iproc_i2c_xfer_internal()
909 iproc_i2c->thld_bytes = M_RX_FIFO_THLD_VALUE; in bcm_iproc_i2c_xfer_internal()
911 iproc_i2c->thld_bytes = msg->len; in bcm_iproc_i2c_xfer_internal()
916 tmp |= iproc_i2c->thld_bytes << M_FIFO_RX_THLD_SHIFT; in bcm_iproc_i2c_xfer_internal()
926 (msg->len << M_CMD_RD_CNT_SHIFT); in bcm_iproc_i2c_xfer_internal()
931 if (iproc_i2c->irq) in bcm_iproc_i2c_xfer_internal()
948 dev_err(iproc_i2c->device, "Invalid repeated start\n"); in bcm_iproc_i2c_xfer()
949 return -EOPNOTSUPP; in bcm_iproc_i2c_xfer()
955 dev_dbg(iproc_i2c->device, "xfer failed\n"); in bcm_iproc_i2c_xfer()
968 if (adap->algo->reg_slave) in bcm_iproc_i2c_functionality()
991 int ret = of_property_read_u32(iproc_i2c->device->of_node, in bcm_iproc_i2c_cfg_speed()
992 "clock-frequency", &bus_speed); in bcm_iproc_i2c_cfg_speed()
994 dev_info(iproc_i2c->device, in bcm_iproc_i2c_cfg_speed()
995 "unable to interpret clock-frequency DT property\n"); in bcm_iproc_i2c_cfg_speed()
1000 dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n", in bcm_iproc_i2c_cfg_speed()
1002 dev_err(iproc_i2c->device, in bcm_iproc_i2c_cfg_speed()
1004 return -EINVAL; in bcm_iproc_i2c_cfg_speed()
1011 iproc_i2c->bus_speed = bus_speed; in bcm_iproc_i2c_cfg_speed()
1017 dev_info(iproc_i2c->device, "bus set to %u Hz\n", bus_speed); in bcm_iproc_i2c_cfg_speed()
1029 iproc_i2c = devm_kzalloc(&pdev->dev, sizeof(*iproc_i2c), in bcm_iproc_i2c_probe()
1032 return -ENOMEM; in bcm_iproc_i2c_probe()
1035 iproc_i2c->device = &pdev->dev; in bcm_iproc_i2c_probe()
1036 iproc_i2c->type = in bcm_iproc_i2c_probe()
1037 (enum bcm_iproc_i2c_type)of_device_get_match_data(&pdev->dev); in bcm_iproc_i2c_probe()
1038 init_completion(&iproc_i2c->done); in bcm_iproc_i2c_probe()
1041 iproc_i2c->base = devm_ioremap_resource(iproc_i2c->device, res); in bcm_iproc_i2c_probe()
1042 if (IS_ERR(iproc_i2c->base)) in bcm_iproc_i2c_probe()
1043 return PTR_ERR(iproc_i2c->base); in bcm_iproc_i2c_probe()
1045 if (iproc_i2c->type == IPROC_I2C_NIC) { in bcm_iproc_i2c_probe()
1047 iproc_i2c->idm_base = devm_ioremap_resource(iproc_i2c->device, in bcm_iproc_i2c_probe()
1049 if (IS_ERR(iproc_i2c->idm_base)) in bcm_iproc_i2c_probe()
1050 return PTR_ERR(iproc_i2c->idm_base); in bcm_iproc_i2c_probe()
1052 ret = of_property_read_u32(iproc_i2c->device->of_node, in bcm_iproc_i2c_probe()
1053 "brcm,ape-hsls-addr-mask", in bcm_iproc_i2c_probe()
1054 &iproc_i2c->ape_addr_mask); in bcm_iproc_i2c_probe()
1056 dev_err(iproc_i2c->device, in bcm_iproc_i2c_probe()
1057 "'brcm,ape-hsls-addr-mask' missing\n"); in bcm_iproc_i2c_probe()
1058 return -EINVAL; in bcm_iproc_i2c_probe()
1061 spin_lock_init(&iproc_i2c->idm_lock); in bcm_iproc_i2c_probe()
1078 ret = devm_request_irq(iproc_i2c->device, irq, in bcm_iproc_i2c_probe()
1079 bcm_iproc_i2c_isr, 0, pdev->name, in bcm_iproc_i2c_probe()
1082 dev_err(iproc_i2c->device, in bcm_iproc_i2c_probe()
1087 iproc_i2c->irq = irq; in bcm_iproc_i2c_probe()
1089 dev_warn(iproc_i2c->device, in bcm_iproc_i2c_probe()
1095 adap = &iproc_i2c->adapter; in bcm_iproc_i2c_probe()
1097 snprintf(adap->name, sizeof(adap->name), in bcm_iproc_i2c_probe()
1098 "Broadcom iProc (%s)", in bcm_iproc_i2c_probe()
1099 of_node_full_name(iproc_i2c->device->of_node)); in bcm_iproc_i2c_probe()
1100 adap->algo = &bcm_iproc_algo; in bcm_iproc_i2c_probe()
1101 adap->quirks = &bcm_iproc_i2c_quirks; in bcm_iproc_i2c_probe()
1102 adap->dev.parent = &pdev->dev; in bcm_iproc_i2c_probe()
1103 adap->dev.of_node = pdev->dev.of_node; in bcm_iproc_i2c_probe()
1112 if (iproc_i2c->irq) { in bcm_iproc_i2c_remove()
1119 synchronize_irq(iproc_i2c->irq); in bcm_iproc_i2c_remove()
1122 i2c_del_adapter(&iproc_i2c->adapter); in bcm_iproc_i2c_remove()
1134 if (iproc_i2c->irq) { in bcm_iproc_i2c_suspend()
1141 synchronize_irq(iproc_i2c->irq); in bcm_iproc_i2c_suspend()
1158 * sleep, so re-initialize the block here in bcm_iproc_i2c_resume()
1167 val |= (iproc_i2c->bus_speed == I2C_MAX_FAST_MODE_FREQ) << TIM_CFG_MODE_400_SHIFT; in bcm_iproc_i2c_resume()
1188 struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); in bcm_iproc_i2c_reg_slave()
1190 if (iproc_i2c->slave) in bcm_iproc_i2c_reg_slave()
1191 return -EBUSY; in bcm_iproc_i2c_reg_slave()
1193 if (slave->flags & I2C_CLIENT_TEN) in bcm_iproc_i2c_reg_slave()
1194 return -EAFNOSUPPORT; in bcm_iproc_i2c_reg_slave()
1196 iproc_i2c->slave = slave; in bcm_iproc_i2c_reg_slave()
1198 tasklet_init(&iproc_i2c->slave_rx_tasklet, slave_rx_tasklet_fn, in bcm_iproc_i2c_reg_slave()
1208 struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); in bcm_iproc_i2c_unreg_slave()
1210 if (!iproc_i2c->slave) in bcm_iproc_i2c_unreg_slave()
1211 return -EINVAL; in bcm_iproc_i2c_unreg_slave()
1213 disable_irq(iproc_i2c->irq); in bcm_iproc_i2c_unreg_slave()
1221 tasklet_kill(&iproc_i2c->slave_rx_tasklet); in bcm_iproc_i2c_unreg_slave()
1235 iproc_i2c->slave = NULL; in bcm_iproc_i2c_unreg_slave()
1237 enable_irq(iproc_i2c->irq); in bcm_iproc_i2c_unreg_slave()
1244 .compatible = "brcm,iproc-i2c",
1247 .compatible = "brcm,iproc-nic-i2c",
1256 .name = "bcm-iproc-i2c",
1266 MODULE_DESCRIPTION("Broadcom iProc I2C Driver");