Lines Matching +full:smbus +full:- +full:timeout +full:- +full:disable

1 // SPDX-License-Identifier: GPL-2.0-only
138 #define M_RX_FIFO_MAX_THLD_VALUE (M_TX_RX_FIFO_SIZE - 1)
238 if (iproc_i2c->idm_base) { in iproc_i2c_rd_reg()
239 spin_lock_irqsave(&iproc_i2c->idm_lock, flags); in iproc_i2c_rd_reg()
240 writel(iproc_i2c->ape_addr_mask, in iproc_i2c_rd_reg()
241 iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); in iproc_i2c_rd_reg()
242 val = readl(iproc_i2c->base + offset); in iproc_i2c_rd_reg()
243 spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags); in iproc_i2c_rd_reg()
245 val = readl(iproc_i2c->base + offset); in iproc_i2c_rd_reg()
256 if (iproc_i2c->idm_base) { in iproc_i2c_wr_reg()
257 spin_lock_irqsave(&iproc_i2c->idm_lock, flags); in iproc_i2c_wr_reg()
258 writel(iproc_i2c->ape_addr_mask, in iproc_i2c_wr_reg()
259 iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); in iproc_i2c_wr_reg()
260 writel(val, iproc_i2c->base + offset); in iproc_i2c_wr_reg()
261 spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags); in iproc_i2c_wr_reg()
263 writel(val, iproc_i2c->base + offset); in iproc_i2c_wr_reg()
272 iproc_i2c->tx_underrun = 0; in bcm_iproc_i2c_slave_init()
301 val |= (iproc_i2c->slave->addr << S_CFG_NIC_SMB_ADDR3_SHIFT); in bcm_iproc_i2c_slave_init()
315 iproc_i2c->slave_int_mask = val; in bcm_iproc_i2c_slave_init()
326 if (!iproc_i2c->slave_rx_only) { in bcm_iproc_i2c_check_slave_status()
333 dev_warn(iproc_i2c->device, in bcm_iproc_i2c_check_slave_status()
335 "slave random stretch time timeout\n" : in bcm_iproc_i2c_check_slave_status()
345 dev_warn(iproc_i2c->device, "Slave aborted read transaction\n"); in bcm_iproc_i2c_check_slave_status()
350 /* re-initialize i2c for recovery */ in bcm_iproc_i2c_check_slave_status()
371 /* Start of SMBUS Master write */ in bcm_iproc_i2c_slave_read()
372 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_read()
374 iproc_i2c->rx_start_rcvd = true; in bcm_iproc_i2c_slave_read()
375 iproc_i2c->slave_read_complete = false; in bcm_iproc_i2c_slave_read()
377 iproc_i2c->rx_start_rcvd) { in bcm_iproc_i2c_slave_read()
378 /* Middle of SMBUS Master write */ in bcm_iproc_i2c_slave_read()
379 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_read()
382 iproc_i2c->rx_start_rcvd) { in bcm_iproc_i2c_slave_read()
383 /* End of SMBUS Master write */ in bcm_iproc_i2c_slave_read()
384 if (iproc_i2c->slave_rx_only) in bcm_iproc_i2c_slave_read()
385 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_read()
389 i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_STOP, in bcm_iproc_i2c_slave_read()
392 iproc_i2c->rx_start_rcvd = false; in bcm_iproc_i2c_slave_read()
393 iproc_i2c->slave_read_complete = true; in bcm_iproc_i2c_slave_read()
411 if (!iproc_i2c->slave_rx_only && iproc_i2c->slave_read_complete) { in slave_rx_tasklet_fn()
413 * In case of single byte master-read request, in slave_rx_tasklet_fn()
422 iproc_i2c->tx_underrun = 0; in slave_rx_tasklet_fn()
423 iproc_i2c->slave_int_mask |= BIT(IE_S_TX_UNDERRUN_SHIFT); in slave_rx_tasklet_fn()
432 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, iproc_i2c->slave_int_mask); in slave_rx_tasklet_fn()
443 iproc_i2c->tx_underrun++; in bcm_iproc_i2c_slave_isr()
444 if (iproc_i2c->tx_underrun == 1) in bcm_iproc_i2c_slave_isr()
445 /* Start of SMBUS for Master Read */ in bcm_iproc_i2c_slave_isr()
446 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_isr()
451 i2c_slave_event(iproc_i2c->slave, in bcm_iproc_i2c_slave_isr()
468 * Disable interrupt for TX FIFO becomes empty and in bcm_iproc_i2c_slave_isr()
469 * less than PKT_LENGTH bytes were output on the SMBUS in bcm_iproc_i2c_slave_isr()
471 iproc_i2c->slave_int_mask &= ~BIT(IE_S_TX_UNDERRUN_SHIFT); in bcm_iproc_i2c_slave_isr()
476 /* End of SMBUS for Master Read */ in bcm_iproc_i2c_slave_isr()
488 i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_STOP, &value); in bcm_iproc_i2c_slave_isr()
500 * Slave events in case of master-write, master-write-read and, in bcm_iproc_i2c_slave_isr()
501 * master-read in bcm_iproc_i2c_slave_isr()
503 * Master-write : only IS_S_RX_EVENT_SHIFT event in bcm_iproc_i2c_slave_isr()
504 * Master-write-read: both IS_S_RX_EVENT_SHIFT and IS_S_RD_EVENT_SHIFT in bcm_iproc_i2c_slave_isr()
506 * Master-read : both IS_S_RX_EVENT_SHIFT and IS_S_RD_EVENT_SHIFT in bcm_iproc_i2c_slave_isr()
517 /* disable slave interrupts */ in bcm_iproc_i2c_slave_isr()
519 val &= ~iproc_i2c->slave_int_mask; in bcm_iproc_i2c_slave_isr()
523 /* Master-write-read request */ in bcm_iproc_i2c_slave_isr()
524 iproc_i2c->slave_rx_only = false; in bcm_iproc_i2c_slave_isr()
526 /* Master-write request only */ in bcm_iproc_i2c_slave_isr()
527 iproc_i2c->slave_rx_only = true; in bcm_iproc_i2c_slave_isr()
530 tasklet_schedule(&iproc_i2c->slave_rx_tasklet); in bcm_iproc_i2c_slave_isr()
544 struct i2c_msg *msg = iproc_i2c->msg; in bcm_iproc_i2c_read_valid_bytes()
548 while (iproc_i2c->rx_bytes < msg->len) { in bcm_iproc_i2c_read_valid_bytes()
555 msg->buf[iproc_i2c->rx_bytes] = in bcm_iproc_i2c_read_valid_bytes()
557 iproc_i2c->rx_bytes++; in bcm_iproc_i2c_read_valid_bytes()
563 struct i2c_msg *msg = iproc_i2c->msg; in bcm_iproc_i2c_send()
564 unsigned int tx_bytes = msg->len - iproc_i2c->tx_bytes; in bcm_iproc_i2c_send()
572 unsigned int idx = iproc_i2c->tx_bytes + i; in bcm_iproc_i2c_send()
574 val = msg->buf[idx]; in bcm_iproc_i2c_send()
577 if (idx == msg->len - 1) { in bcm_iproc_i2c_send()
580 if (iproc_i2c->irq) { in bcm_iproc_i2c_send()
585 * disable TX FIFO underrun interrupt in bcm_iproc_i2c_send()
599 iproc_i2c->tx_bytes += tx_bytes; in bcm_iproc_i2c_send()
604 struct i2c_msg *msg = iproc_i2c->msg; in bcm_iproc_i2c_read()
608 bytes_left = msg->len - iproc_i2c->rx_bytes; in bcm_iproc_i2c_read()
610 if (iproc_i2c->irq) { in bcm_iproc_i2c_read()
611 /* finished reading all data, disable rx thld event */ in bcm_iproc_i2c_read()
616 } else if (bytes_left < iproc_i2c->thld_bytes) { in bcm_iproc_i2c_read()
622 iproc_i2c->thld_bytes = bytes_left; in bcm_iproc_i2c_read()
625 * bytes_left >= iproc_i2c->thld_bytes, in bcm_iproc_i2c_read()
627 * It will remain as iproc_i2c->thld_bytes itself in bcm_iproc_i2c_read()
644 iproc_i2c->xfer_is_done = 1; in bcm_iproc_i2c_process_m_event()
645 if (iproc_i2c->irq) in bcm_iproc_i2c_process_m_event()
646 complete(&iproc_i2c->done); in bcm_iproc_i2c_process_m_event()
701 /* disable all interrupts */ in bcm_iproc_i2c_init()
739 dev_dbg(iproc_i2c->device, "lost bus arbitration\n"); in bcm_iproc_i2c_check_status()
740 return -EAGAIN; in bcm_iproc_i2c_check_status()
743 dev_dbg(iproc_i2c->device, "NAK addr:0x%02x\n", msg->addr); in bcm_iproc_i2c_check_status()
744 return -ENXIO; in bcm_iproc_i2c_check_status()
747 dev_dbg(iproc_i2c->device, "NAK data\n"); in bcm_iproc_i2c_check_status()
748 return -ENXIO; in bcm_iproc_i2c_check_status()
751 dev_dbg(iproc_i2c->device, "bus timeout\n"); in bcm_iproc_i2c_check_status()
752 return -ETIMEDOUT; in bcm_iproc_i2c_check_status()
755 dev_dbg(iproc_i2c->device, "FIFO under-run\n"); in bcm_iproc_i2c_check_status()
756 return -ENXIO; in bcm_iproc_i2c_check_status()
759 dev_dbg(iproc_i2c->device, "RX FIFO full\n"); in bcm_iproc_i2c_check_status()
760 return -ETIMEDOUT; in bcm_iproc_i2c_check_status()
763 dev_dbg(iproc_i2c->device, "unknown error code=%d\n", val); in bcm_iproc_i2c_check_status()
765 /* re-initialize i2c for recovery */ in bcm_iproc_i2c_check_status()
770 return -EIO; in bcm_iproc_i2c_check_status()
784 if (iproc_i2c->irq) { in bcm_iproc_i2c_xfer_wait()
785 time_left = wait_for_completion_timeout(&iproc_i2c->done, in bcm_iproc_i2c_xfer_wait()
787 /* disable all interrupts */ in bcm_iproc_i2c_xfer_wait()
792 synchronize_irq(iproc_i2c->irq); in bcm_iproc_i2c_xfer_wait()
795 unsigned long timeout = jiffies + time_left; in bcm_iproc_i2c_xfer_wait() local
803 if (time_after(jiffies, timeout)) { in bcm_iproc_i2c_xfer_wait()
810 } while (!iproc_i2c->xfer_is_done); in bcm_iproc_i2c_xfer_wait()
813 if (!time_left && !iproc_i2c->xfer_is_done) { in bcm_iproc_i2c_xfer_wait()
817 return -ETIMEDOUT; in bcm_iproc_i2c_xfer_wait()
832 * If 'process_call' is true, then this is a multi-msg transfer that requires
849 dev_warn(iproc_i2c->device, "bus is busy\n"); in bcm_iproc_i2c_xfer_internal()
850 return -EBUSY; in bcm_iproc_i2c_xfer_internal()
853 iproc_i2c->msg = msg; in bcm_iproc_i2c_xfer_internal()
861 * loading up to TX FIFO size - 1 bytes of data since the first byte in bcm_iproc_i2c_xfer_internal()
864 tx_bytes = min_t(unsigned int, msg->len, M_TX_RX_FIFO_SIZE - 1); in bcm_iproc_i2c_xfer_internal()
865 if (!(msg->flags & I2C_M_RD)) { in bcm_iproc_i2c_xfer_internal()
867 val = msg->buf[i]; in bcm_iproc_i2c_xfer_internal()
870 if (!process_call && (i == msg->len - 1)) in bcm_iproc_i2c_xfer_internal()
875 iproc_i2c->tx_bytes = tx_bytes; in bcm_iproc_i2c_xfer_internal()
881 iproc_i2c->msg = msg; /* point to second msg */ in bcm_iproc_i2c_xfer_internal()
894 if (iproc_i2c->irq) in bcm_iproc_i2c_xfer_internal()
895 reinit_completion(&iproc_i2c->done); in bcm_iproc_i2c_xfer_internal()
897 iproc_i2c->xfer_is_done = 0; in bcm_iproc_i2c_xfer_internal()
911 if (!process_call && !(msg->flags & I2C_M_RD) && in bcm_iproc_i2c_xfer_internal()
912 msg->len > iproc_i2c->tx_bytes) in bcm_iproc_i2c_xfer_internal()
921 if (msg->len == 0) { in bcm_iproc_i2c_xfer_internal()
922 /* SMBUS QUICK Command (Read/Write) */ in bcm_iproc_i2c_xfer_internal()
924 } else if (msg->flags & I2C_M_RD) { in bcm_iproc_i2c_xfer_internal()
927 iproc_i2c->rx_bytes = 0; in bcm_iproc_i2c_xfer_internal()
928 if (msg->len > M_RX_FIFO_MAX_THLD_VALUE) in bcm_iproc_i2c_xfer_internal()
929 iproc_i2c->thld_bytes = M_RX_FIFO_THLD_VALUE; in bcm_iproc_i2c_xfer_internal()
931 iproc_i2c->thld_bytes = msg->len; in bcm_iproc_i2c_xfer_internal()
936 tmp |= iproc_i2c->thld_bytes << M_FIFO_RX_THLD_SHIFT; in bcm_iproc_i2c_xfer_internal()
946 (msg->len << M_CMD_RD_CNT_SHIFT); in bcm_iproc_i2c_xfer_internal()
951 if (iproc_i2c->irq) in bcm_iproc_i2c_xfer_internal()
968 dev_err(iproc_i2c->device, "Invalid repeated start\n"); in bcm_iproc_i2c_xfer()
969 return -EOPNOTSUPP; in bcm_iproc_i2c_xfer()
975 dev_dbg(iproc_i2c->device, "xfer failed\n"); in bcm_iproc_i2c_xfer()
988 if (adap->algo->reg_slave) in bcm_iproc_i2c_functionality()
1011 int ret = of_property_read_u32(iproc_i2c->device->of_node, in bcm_iproc_i2c_cfg_speed()
1012 "clock-frequency", &bus_speed); in bcm_iproc_i2c_cfg_speed()
1014 dev_info(iproc_i2c->device, in bcm_iproc_i2c_cfg_speed()
1015 "unable to interpret clock-frequency DT property\n"); in bcm_iproc_i2c_cfg_speed()
1020 dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n", in bcm_iproc_i2c_cfg_speed()
1022 dev_err(iproc_i2c->device, in bcm_iproc_i2c_cfg_speed()
1024 return -EINVAL; in bcm_iproc_i2c_cfg_speed()
1031 iproc_i2c->bus_speed = bus_speed; in bcm_iproc_i2c_cfg_speed()
1037 dev_info(iproc_i2c->device, "bus set to %u Hz\n", bus_speed); in bcm_iproc_i2c_cfg_speed()
1048 iproc_i2c = devm_kzalloc(&pdev->dev, sizeof(*iproc_i2c), in bcm_iproc_i2c_probe()
1051 return -ENOMEM; in bcm_iproc_i2c_probe()
1054 iproc_i2c->device = &pdev->dev; in bcm_iproc_i2c_probe()
1055 iproc_i2c->type = in bcm_iproc_i2c_probe()
1056 (enum bcm_iproc_i2c_type)of_device_get_match_data(&pdev->dev); in bcm_iproc_i2c_probe()
1057 init_completion(&iproc_i2c->done); in bcm_iproc_i2c_probe()
1059 iproc_i2c->base = devm_platform_ioremap_resource(pdev, 0); in bcm_iproc_i2c_probe()
1060 if (IS_ERR(iproc_i2c->base)) in bcm_iproc_i2c_probe()
1061 return PTR_ERR(iproc_i2c->base); in bcm_iproc_i2c_probe()
1063 if (iproc_i2c->type == IPROC_I2C_NIC) { in bcm_iproc_i2c_probe()
1064 iproc_i2c->idm_base = devm_platform_ioremap_resource(pdev, 1); in bcm_iproc_i2c_probe()
1065 if (IS_ERR(iproc_i2c->idm_base)) in bcm_iproc_i2c_probe()
1066 return PTR_ERR(iproc_i2c->idm_base); in bcm_iproc_i2c_probe()
1068 ret = of_property_read_u32(iproc_i2c->device->of_node, in bcm_iproc_i2c_probe()
1069 "brcm,ape-hsls-addr-mask", in bcm_iproc_i2c_probe()
1070 &iproc_i2c->ape_addr_mask); in bcm_iproc_i2c_probe()
1072 dev_err(iproc_i2c->device, in bcm_iproc_i2c_probe()
1073 "'brcm,ape-hsls-addr-mask' missing\n"); in bcm_iproc_i2c_probe()
1074 return -EINVAL; in bcm_iproc_i2c_probe()
1077 spin_lock_init(&iproc_i2c->idm_lock); in bcm_iproc_i2c_probe()
1094 ret = devm_request_irq(iproc_i2c->device, irq, in bcm_iproc_i2c_probe()
1095 bcm_iproc_i2c_isr, 0, pdev->name, in bcm_iproc_i2c_probe()
1098 dev_err(iproc_i2c->device, in bcm_iproc_i2c_probe()
1103 iproc_i2c->irq = irq; in bcm_iproc_i2c_probe()
1105 dev_warn(iproc_i2c->device, in bcm_iproc_i2c_probe()
1111 adap = &iproc_i2c->adapter; in bcm_iproc_i2c_probe()
1113 snprintf(adap->name, sizeof(adap->name), in bcm_iproc_i2c_probe()
1115 of_node_full_name(iproc_i2c->device->of_node)); in bcm_iproc_i2c_probe()
1116 adap->algo = &bcm_iproc_algo; in bcm_iproc_i2c_probe()
1117 adap->quirks = &bcm_iproc_i2c_quirks; in bcm_iproc_i2c_probe()
1118 adap->dev.parent = &pdev->dev; in bcm_iproc_i2c_probe()
1119 adap->dev.of_node = pdev->dev.of_node; in bcm_iproc_i2c_probe()
1128 if (iproc_i2c->irq) { in bcm_iproc_i2c_remove()
1135 synchronize_irq(iproc_i2c->irq); in bcm_iproc_i2c_remove()
1138 i2c_del_adapter(&iproc_i2c->adapter); in bcm_iproc_i2c_remove()
1146 if (iproc_i2c->irq) { in bcm_iproc_i2c_suspend()
1153 synchronize_irq(iproc_i2c->irq); in bcm_iproc_i2c_suspend()
1156 /* now disable the controller */ in bcm_iproc_i2c_suspend()
1170 * sleep, so re-initialize the block here in bcm_iproc_i2c_resume()
1179 val |= (iproc_i2c->bus_speed == I2C_MAX_FAST_MODE_FREQ) << TIM_CFG_MODE_400_SHIFT; in bcm_iproc_i2c_resume()
1194 struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); in bcm_iproc_i2c_reg_slave()
1196 if (iproc_i2c->slave) in bcm_iproc_i2c_reg_slave()
1197 return -EBUSY; in bcm_iproc_i2c_reg_slave()
1199 if (slave->flags & I2C_CLIENT_TEN) in bcm_iproc_i2c_reg_slave()
1200 return -EAFNOSUPPORT; in bcm_iproc_i2c_reg_slave()
1202 iproc_i2c->slave = slave; in bcm_iproc_i2c_reg_slave()
1204 tasklet_init(&iproc_i2c->slave_rx_tasklet, slave_rx_tasklet_fn, in bcm_iproc_i2c_reg_slave()
1214 struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); in bcm_iproc_i2c_unreg_slave()
1216 if (!iproc_i2c->slave) in bcm_iproc_i2c_unreg_slave()
1217 return -EINVAL; in bcm_iproc_i2c_unreg_slave()
1219 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()
1223 /* disable all slave interrupts */ in bcm_iproc_i2c_unreg_slave()
1241 iproc_i2c->slave = NULL; in bcm_iproc_i2c_unreg_slave()
1243 enable_irq(iproc_i2c->irq); in bcm_iproc_i2c_unreg_slave()
1250 .compatible = "brcm,iproc-i2c",
1253 .compatible = "brcm,iproc-nic-i2c",
1262 .name = "bcm-iproc-i2c",