Lines Matching +full:num +full:- +full:transfer +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0-only
21 * data register whereas STB SoCs use 4 byte per data register transfer,
52 /* Condition mask used for non combined transfer */
58 /* BSC data transfer direction */
61 /* BSC data transfer direction combined format */
175 __bsc_readl(_dev->base + offsetof(struct bsc_regs, _reg))
178 __bsc_writel(_val, _dev->base + offsetof(struct bsc_regs, _reg))
182 return (N_DATA_REGS * dev->data_regsz); in brcmstb_i2c_get_xfersz()
187 return dev->data_regsz; in brcmstb_i2c_get_data_regsz()
196 dev->bsc_regmap->ctl_reg |= BSC_CTL_REG_INT_EN_MASK; in brcmstb_i2c_enable_disable_irq()
199 dev->bsc_regmap->ctl_reg &= ~BSC_CTL_REG_INT_EN_MASK; in brcmstb_i2c_enable_disable_irq()
202 bsc_writel(dev, dev->bsc_regmap->ctl_reg, ctl_reg); in brcmstb_i2c_enable_disable_irq()
211 dev_dbg(dev->device, "isr CTL_REG %x IIC_EN %x\n", in brcmstb_i2c_isr()
218 complete(&dev->done); in brcmstb_i2c_isr()
220 dev_dbg(dev->device, "isr handled"); in brcmstb_i2c_isr()
231 return -ETIMEDOUT; in brcmstb_i2c_wait_if_busy()
243 if (dev->irq >= 0) { in brcmstb_i2c_wait_for_completion()
244 if (!wait_for_completion_timeout(&dev->done, timeout)) in brcmstb_i2c_wait_for_completion()
245 ret = -ETIMEDOUT; in brcmstb_i2c_wait_for_completion()
255 ret = -ETIMEDOUT; in brcmstb_i2c_wait_for_completion()
262 if (dev->irq < 0 || ret == -ETIMEDOUT) in brcmstb_i2c_wait_for_completion()
268 /* Set xfer START/STOP conditions for subsequent transfer */
272 u32 regval = dev->bsc_regmap->iic_enable; in brcmstb_set_i2c_start_stop()
274 dev->bsc_regmap->iic_enable = (regval & ~COND_START_STOP) | cond_flag; in brcmstb_set_i2c_start_stop()
282 struct bsc_regs *pi2creg = dev->bsc_regmap; in brcmstb_send_i2c_cmd()
290 if (dev->irq >= 0) in brcmstb_send_i2c_cmd()
291 reinit_completion(&dev->done); in brcmstb_send_i2c_cmd()
296 /* initiate transfer by setting iic_enable */ in brcmstb_send_i2c_cmd()
297 pi2creg->iic_enable |= BSC_IIC_EN_ENABLE_MASK; in brcmstb_send_i2c_cmd()
298 bsc_writel(dev, pi2creg->iic_enable, iic_enable); in brcmstb_send_i2c_cmd()
303 dev_dbg(dev->device, "intr timeout for cmd %s\n", in brcmstb_send_i2c_cmd()
310 rc = -EREMOTEIO; in brcmstb_send_i2c_cmd()
311 dev_dbg(dev->device, "controller received NOACK intr for %s\n", in brcmstb_send_i2c_cmd()
322 /* Actual data transfer through the BSC master */
330 struct bsc_regs *pi2creg = dev->bsc_regmap; in brcmstb_i2c_xfer_bsc_data()
331 int no_ack = pmsg->flags & I2C_M_IGNORE_NAK; in brcmstb_i2c_xfer_bsc_data()
336 cmd = (pmsg->flags & I2C_M_RD) ? CMD_RD_NOACK in brcmstb_i2c_xfer_bsc_data()
338 pi2creg->ctlhi_reg |= BSC_CTLHI_REG_IGNORE_ACK_MASK; in brcmstb_i2c_xfer_bsc_data()
340 cmd = (pmsg->flags & I2C_M_RD) ? CMD_RD : CMD_WR; in brcmstb_i2c_xfer_bsc_data()
341 pi2creg->ctlhi_reg &= ~BSC_CTLHI_REG_IGNORE_ACK_MASK; in brcmstb_i2c_xfer_bsc_data()
343 bsc_writel(dev, pi2creg->ctlhi_reg, ctlhi_reg); in brcmstb_i2c_xfer_bsc_data()
345 /* set data transfer direction */ in brcmstb_i2c_xfer_bsc_data()
346 ctl_reg = pi2creg->ctl_reg & ~BSC_CTL_REG_DTF_MASK; in brcmstb_i2c_xfer_bsc_data()
348 pi2creg->ctl_reg = ctl_reg | DTF_WR_MASK; in brcmstb_i2c_xfer_bsc_data()
350 pi2creg->ctl_reg = ctl_reg | DTF_RD_MASK; in brcmstb_i2c_xfer_bsc_data()
366 (BITS_PER_BYTE * (data_regsz - 1)); in brcmstb_i2c_xfer_bsc_data()
376 dev_dbg(dev->device, "%s failure", cmd_string[cmd]); in brcmstb_i2c_xfer_bsc_data()
414 if (msg->flags & I2C_M_TEN) { in brcmstb_i2c_do_addr()
415 /* First byte is 11110XX0 where XX is upper 2 bits */ in brcmstb_i2c_do_addr()
416 addr = 0xF0 | ((msg->addr & 0x300) >> 7); in brcmstb_i2c_do_addr()
419 /* Second byte is the remaining 8 bits */ in brcmstb_i2c_do_addr()
420 addr = msg->addr & 0xFF; in brcmstb_i2c_do_addr()
422 return -EREMOTEIO; in brcmstb_i2c_do_addr()
424 if (msg->flags & I2C_M_RD) { in brcmstb_i2c_do_addr()
428 /* Then re-send the first byte with the read bit set */ in brcmstb_i2c_do_addr()
429 addr = 0xF0 | ((msg->addr & 0x300) >> 7) | 0x01; in brcmstb_i2c_do_addr()
431 return -EREMOTEIO; in brcmstb_i2c_do_addr()
443 /* Master transfer function */
445 struct i2c_msg msgs[], int num) in brcmstb_i2c_xfer() argument
458 for (i = 0; i < num; i++) { in brcmstb_i2c_xfer()
460 len = pmsg->len; in brcmstb_i2c_xfer()
461 tmp_buf = pmsg->buf; in brcmstb_i2c_xfer()
463 dev_dbg(dev->device, in brcmstb_i2c_xfer()
465 num - 1, pmsg->flags, in brcmstb_i2c_xfer()
466 pmsg->buf ? pmsg->buf[0] : '0', pmsg->len); in brcmstb_i2c_xfer()
468 if (i < (num - 1) && (msgs[i + 1].flags & I2C_M_NOSTART)) in brcmstb_i2c_xfer()
476 if (!(pmsg->flags & I2C_M_NOSTART)) { in brcmstb_i2c_xfer()
479 dev_dbg(dev->device, in brcmstb_i2c_xfer()
481 pmsg->addr, i, rc); in brcmstb_i2c_xfer()
488 /* Perform data transfer */ in brcmstb_i2c_xfer()
493 if (i == (num - 1)) in brcmstb_i2c_xfer()
510 len -= bytes_to_xfer; in brcmstb_i2c_xfer()
517 rc = num; in brcmstb_i2c_xfer()
537 u32 clk_freq_hz = dev->clk_freq_hz; in brcmstb_i2c_set_bus_speed()
541 dev->bsc_regmap->ctl_reg &= ~(BSC_CTL_REG_SCL_SEL_MASK in brcmstb_i2c_set_bus_speed()
543 dev->bsc_regmap->ctl_reg |= (bsc_clk[i].scl_mask | in brcmstb_i2c_set_bus_speed()
545 bsc_writel(dev, dev->bsc_regmap->ctl_reg, ctl_reg); in brcmstb_i2c_set_bus_speed()
554 dev_warn(dev->device, "leaving current clock-frequency @ %dHz\n", in brcmstb_i2c_set_bus_speed()
563 dev->bsc_regmap->ctlhi_reg = BSC_CTLHI_REG_DATAREG_SIZE_MASK; in brcmstb_i2c_set_bsc_reg_defaults()
565 dev->bsc_regmap->ctlhi_reg &= ~BSC_CTLHI_REG_DATAREG_SIZE_MASK; in brcmstb_i2c_set_bsc_reg_defaults()
567 bsc_writel(dev, dev->bsc_regmap->ctlhi_reg, ctlhi_reg); in brcmstb_i2c_set_bsc_reg_defaults()
577 struct platform_device *pdev = to_platform_device(dev->device); in bcm2711_release_bsc()
582 iomem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "auto-i2c"); in bcm2711_release_bsc()
583 autoi2c = devm_ioremap_resource(&pdev->dev, iomem); in bcm2711_release_bsc()
588 devm_iounmap(&pdev->dev, autoi2c); in bcm2711_release_bsc()
591 dev->bsc_regmap->iic_enable = 0; in bcm2711_release_bsc()
592 bsc_writel(dev, dev->bsc_regmap->iic_enable, iic_enable); in bcm2711_release_bsc()
606 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in brcmstb_i2c_probe()
608 return -ENOMEM; in brcmstb_i2c_probe()
610 dev->bsc_regmap = devm_kzalloc(&pdev->dev, sizeof(*dev->bsc_regmap), GFP_KERNEL); in brcmstb_i2c_probe()
611 if (!dev->bsc_regmap) in brcmstb_i2c_probe()
612 return -ENOMEM; in brcmstb_i2c_probe()
615 dev->device = &pdev->dev; in brcmstb_i2c_probe()
616 init_completion(&dev->done); in brcmstb_i2c_probe()
620 dev->base = devm_ioremap_resource(dev->device, iomem); in brcmstb_i2c_probe()
621 if (IS_ERR(dev->base)) { in brcmstb_i2c_probe()
622 rc = -ENOMEM; in brcmstb_i2c_probe()
626 if (of_device_is_compatible(dev->device->of_node, in brcmstb_i2c_probe()
627 "brcm,bcm2711-hdmi-i2c")) { in brcmstb_i2c_probe()
633 rc = of_property_read_string(dev->device->of_node, "interrupt-names", in brcmstb_i2c_probe()
639 dev->irq = platform_get_irq_optional(pdev, 0); in brcmstb_i2c_probe()
645 if (dev->irq >= 0) { in brcmstb_i2c_probe()
646 rc = devm_request_irq(&pdev->dev, dev->irq, brcmstb_i2c_isr, in brcmstb_i2c_probe()
648 int_name ? int_name : pdev->name, in brcmstb_i2c_probe()
652 dev_dbg(dev->device, "falling back to polling mode"); in brcmstb_i2c_probe()
653 dev->irq = -1; in brcmstb_i2c_probe()
657 if (of_property_read_u32(dev->device->of_node, in brcmstb_i2c_probe()
658 "clock-frequency", &dev->clk_freq_hz)) { in brcmstb_i2c_probe()
659 dev_warn(dev->device, "setting clock-frequency@%dHz\n", in brcmstb_i2c_probe()
661 dev->clk_freq_hz = bsc_clk[0].hz; in brcmstb_i2c_probe()
665 if (of_device_is_compatible(dev->device->of_node, in brcmstb_i2c_probe()
666 "brcm,brcmper-i2c")) in brcmstb_i2c_probe()
667 dev->data_regsz = sizeof(u8); in brcmstb_i2c_probe()
669 dev->data_regsz = sizeof(u32); in brcmstb_i2c_probe()
674 adap = &dev->adapter; in brcmstb_i2c_probe()
676 adap->owner = THIS_MODULE; in brcmstb_i2c_probe()
677 strscpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); in brcmstb_i2c_probe()
678 adap->algo = &brcmstb_i2c_algo; in brcmstb_i2c_probe()
679 adap->dev.parent = &pdev->dev; in brcmstb_i2c_probe()
680 adap->dev.of_node = pdev->dev.of_node; in brcmstb_i2c_probe()
685 dev_info(dev->device, "%s@%dhz registered in %s mode\n", in brcmstb_i2c_probe()
686 int_name ? int_name : " ", dev->clk_freq_hz, in brcmstb_i2c_probe()
687 (dev->irq >= 0) ? "interrupt" : "polling"); in brcmstb_i2c_probe()
699 i2c_del_adapter(&dev->adapter); in brcmstb_i2c_remove()
708 i2c_mark_adapter_suspended(&i2c_dev->adapter); in brcmstb_i2c_suspend()
717 i2c_mark_adapter_resumed(&i2c_dev->adapter); in brcmstb_i2c_resume()
727 {.compatible = "brcm,brcmstb-i2c"},
728 {.compatible = "brcm,brcmper-i2c"},
729 {.compatible = "brcm,bcm2711-hdmi-i2c"},
736 .name = "brcmstb-i2c",