Lines Matching +full:bcm2711 +full:- +full:hdmi +full:- +full:i2c
1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/i2c.h>
20 * size. Cable modem and DSL SoCs with Peripheral i2c cores use 1 byte per
176 __bsc_readl(_dev->base + offsetof(struct bsc_regs, _reg))
179 __bsc_writel(_val, _dev->base + offsetof(struct bsc_regs, _reg))
183 return (N_DATA_REGS * dev->data_regsz); in brcmstb_i2c_get_xfersz()
188 return dev->data_regsz; in brcmstb_i2c_get_data_regsz()
197 dev->bsc_regmap->ctl_reg |= BSC_CTL_REG_INT_EN_MASK; in brcmstb_i2c_enable_disable_irq()
200 dev->bsc_regmap->ctl_reg &= ~BSC_CTL_REG_INT_EN_MASK; in brcmstb_i2c_enable_disable_irq()
203 bsc_writel(dev, dev->bsc_regmap->ctl_reg, ctl_reg); in brcmstb_i2c_enable_disable_irq()
212 dev_dbg(dev->device, "isr CTL_REG %x IIC_EN %x\n", in brcmstb_i2c_isr()
219 complete(&dev->done); in brcmstb_i2c_isr()
221 dev_dbg(dev->device, "isr handled"); in brcmstb_i2c_isr()
232 return -ETIMEDOUT; in brcmstb_i2c_wait_if_busy()
238 /* i2c xfer completion function, handles both irq and polling mode */
244 if (dev->irq >= 0 && !dev->atomic) { in brcmstb_i2c_wait_for_completion()
245 if (!wait_for_completion_timeout(&dev->done, timeout)) in brcmstb_i2c_wait_for_completion()
246 ret = -ETIMEDOUT; in brcmstb_i2c_wait_for_completion()
256 ret = -ETIMEDOUT; in brcmstb_i2c_wait_for_completion()
263 if (dev->irq < 0 || ret == -ETIMEDOUT) in brcmstb_i2c_wait_for_completion()
273 u32 regval = dev->bsc_regmap->iic_enable; in brcmstb_set_i2c_start_stop()
275 dev->bsc_regmap->iic_enable = (regval & ~COND_START_STOP) | cond_flag; in brcmstb_set_i2c_start_stop()
278 /* Send I2C request check completion */
283 struct bsc_regs *pi2creg = dev->bsc_regmap; in brcmstb_send_i2c_cmd()
291 if (dev->irq >= 0 && !dev->atomic) in brcmstb_send_i2c_cmd()
292 reinit_completion(&dev->done); in brcmstb_send_i2c_cmd()
298 pi2creg->iic_enable |= BSC_IIC_EN_ENABLE_MASK; in brcmstb_send_i2c_cmd()
299 bsc_writel(dev, pi2creg->iic_enable, iic_enable); in brcmstb_send_i2c_cmd()
304 dev_dbg(dev->device, "intr timeout for cmd %s\n", in brcmstb_send_i2c_cmd()
311 rc = -EREMOTEIO; in brcmstb_send_i2c_cmd()
312 dev_dbg(dev->device, "controller received NOACK intr for %s\n", in brcmstb_send_i2c_cmd()
331 struct bsc_regs *pi2creg = dev->bsc_regmap; in brcmstb_i2c_xfer_bsc_data()
332 int no_ack = pmsg->flags & I2C_M_IGNORE_NAK; in brcmstb_i2c_xfer_bsc_data()
337 cmd = (pmsg->flags & I2C_M_RD) ? CMD_RD_NOACK in brcmstb_i2c_xfer_bsc_data()
339 pi2creg->ctlhi_reg |= BSC_CTLHI_REG_IGNORE_ACK_MASK; in brcmstb_i2c_xfer_bsc_data()
341 cmd = (pmsg->flags & I2C_M_RD) ? CMD_RD : CMD_WR; in brcmstb_i2c_xfer_bsc_data()
342 pi2creg->ctlhi_reg &= ~BSC_CTLHI_REG_IGNORE_ACK_MASK; in brcmstb_i2c_xfer_bsc_data()
344 bsc_writel(dev, pi2creg->ctlhi_reg, ctlhi_reg); in brcmstb_i2c_xfer_bsc_data()
347 ctl_reg = pi2creg->ctl_reg & ~BSC_CTL_REG_DTF_MASK; in brcmstb_i2c_xfer_bsc_data()
349 pi2creg->ctl_reg = ctl_reg | DTF_WR_MASK; in brcmstb_i2c_xfer_bsc_data()
351 pi2creg->ctl_reg = ctl_reg | DTF_RD_MASK; in brcmstb_i2c_xfer_bsc_data()
367 (BITS_PER_BYTE * (data_regsz - 1)); in brcmstb_i2c_xfer_bsc_data()
377 dev_dbg(dev->device, "%s failure", cmd_string[cmd]); in brcmstb_i2c_xfer_bsc_data()
397 /* Write a single byte of data to the i2c bus */
409 /* Send i2c address */
415 if (msg->flags & I2C_M_TEN) { in brcmstb_i2c_do_addr()
417 addr = 0xF0 | ((msg->addr & 0x300) >> 7); in brcmstb_i2c_do_addr()
421 addr = msg->addr & 0xFF; in brcmstb_i2c_do_addr()
423 return -EREMOTEIO; in brcmstb_i2c_do_addr()
425 if (msg->flags & I2C_M_RD) { in brcmstb_i2c_do_addr()
429 /* Then re-send the first byte with the read bit set */ in brcmstb_i2c_do_addr()
430 addr = 0xF0 | ((msg->addr & 0x300) >> 7) | 0x01; in brcmstb_i2c_do_addr()
432 return -EREMOTEIO; in brcmstb_i2c_do_addr()
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()
493 if (i == (num - 1)) in brcmstb_i2c_xfer()
510 len -= bytes_to_xfer; in brcmstb_i2c_xfer()
529 if (dev->irq >= 0) in brcmstb_i2c_xfer_atomic()
530 disable_irq(dev->irq); in brcmstb_i2c_xfer_atomic()
531 dev->atomic = true; in brcmstb_i2c_xfer_atomic()
533 dev->atomic = false; in brcmstb_i2c_xfer_atomic()
534 if (dev->irq >= 0) in brcmstb_i2c_xfer_atomic()
535 enable_irq(dev->irq); in brcmstb_i2c_xfer_atomic()
555 u32 clk_freq_hz = dev->clk_freq_hz; in brcmstb_i2c_set_bus_speed()
559 dev->bsc_regmap->ctl_reg &= ~(BSC_CTL_REG_SCL_SEL_MASK in brcmstb_i2c_set_bus_speed()
561 dev->bsc_regmap->ctl_reg |= (bsc_clk[i].scl_mask | in brcmstb_i2c_set_bus_speed()
563 bsc_writel(dev, dev->bsc_regmap->ctl_reg, ctl_reg); in brcmstb_i2c_set_bus_speed()
572 dev_warn(dev->device, "leaving current clock-frequency @ %dHz\n", in brcmstb_i2c_set_bus_speed()
581 dev->bsc_regmap->ctlhi_reg = BSC_CTLHI_REG_DATAREG_SIZE_MASK; in brcmstb_i2c_set_bsc_reg_defaults()
583 dev->bsc_regmap->ctlhi_reg &= ~BSC_CTLHI_REG_DATAREG_SIZE_MASK; in brcmstb_i2c_set_bsc_reg_defaults()
585 bsc_writel(dev, dev->bsc_regmap->ctlhi_reg, ctlhi_reg); in brcmstb_i2c_set_bsc_reg_defaults()
595 struct platform_device *pdev = to_platform_device(dev->device); in bcm2711_release_bsc()
599 autoi2c = devm_platform_ioremap_resource_byname(pdev, "auto-i2c"); in bcm2711_release_bsc()
604 devm_iounmap(&pdev->dev, autoi2c); in bcm2711_release_bsc()
607 dev->bsc_regmap->iic_enable = 0; in bcm2711_release_bsc()
608 bsc_writel(dev, dev->bsc_regmap->iic_enable, iic_enable); in bcm2711_release_bsc()
621 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in brcmstb_i2c_probe()
623 return -ENOMEM; in brcmstb_i2c_probe()
625 dev->bsc_regmap = devm_kzalloc(&pdev->dev, sizeof(*dev->bsc_regmap), GFP_KERNEL); in brcmstb_i2c_probe()
626 if (!dev->bsc_regmap) in brcmstb_i2c_probe()
627 return -ENOMEM; in brcmstb_i2c_probe()
630 dev->device = &pdev->dev; in brcmstb_i2c_probe()
631 init_completion(&dev->done); in brcmstb_i2c_probe()
634 dev->base = devm_platform_ioremap_resource(pdev, 0); in brcmstb_i2c_probe()
635 if (IS_ERR(dev->base)) in brcmstb_i2c_probe()
636 return PTR_ERR(dev->base); in brcmstb_i2c_probe()
638 if (of_device_is_compatible(dev->device->of_node, in brcmstb_i2c_probe()
639 "brcm,bcm2711-hdmi-i2c")) { in brcmstb_i2c_probe()
645 rc = of_property_read_string(dev->device->of_node, "interrupt-names", in brcmstb_i2c_probe()
651 dev->irq = platform_get_irq_optional(pdev, 0); in brcmstb_i2c_probe()
657 if (dev->irq >= 0) { in brcmstb_i2c_probe()
658 rc = devm_request_irq(&pdev->dev, dev->irq, brcmstb_i2c_isr, in brcmstb_i2c_probe()
660 int_name ? int_name : pdev->name, in brcmstb_i2c_probe()
664 dev_dbg(dev->device, "falling back to polling mode"); in brcmstb_i2c_probe()
665 dev->irq = -1; in brcmstb_i2c_probe()
669 if (of_property_read_u32(dev->device->of_node, in brcmstb_i2c_probe()
670 "clock-frequency", &dev->clk_freq_hz)) { in brcmstb_i2c_probe()
671 dev_warn(dev->device, "setting clock-frequency@%dHz\n", in brcmstb_i2c_probe()
673 dev->clk_freq_hz = bsc_clk[0].hz; in brcmstb_i2c_probe()
677 if (of_device_is_compatible(dev->device->of_node, in brcmstb_i2c_probe()
678 "brcm,brcmper-i2c")) in brcmstb_i2c_probe()
679 dev->data_regsz = sizeof(u8); in brcmstb_i2c_probe()
681 dev->data_regsz = sizeof(u32); in brcmstb_i2c_probe()
685 /* Add the i2c adapter */ in brcmstb_i2c_probe()
686 adap = &dev->adapter; in brcmstb_i2c_probe()
688 adap->owner = THIS_MODULE; in brcmstb_i2c_probe()
689 strscpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); in brcmstb_i2c_probe()
690 adap->algo = &brcmstb_i2c_algo; in brcmstb_i2c_probe()
691 adap->dev.parent = &pdev->dev; in brcmstb_i2c_probe()
692 adap->dev.of_node = pdev->dev.of_node; in brcmstb_i2c_probe()
697 dev_info(dev->device, "%s@%dhz registered in %s mode\n", in brcmstb_i2c_probe()
698 int_name ? int_name : " ", dev->clk_freq_hz, in brcmstb_i2c_probe()
699 (dev->irq >= 0) ? "interrupt" : "polling"); in brcmstb_i2c_probe()
708 i2c_del_adapter(&dev->adapter); in brcmstb_i2c_remove()
715 i2c_mark_adapter_suspended(&i2c_dev->adapter); in brcmstb_i2c_suspend()
724 i2c_mark_adapter_resumed(&i2c_dev->adapter); in brcmstb_i2c_resume()
733 {.compatible = "brcm,brcmstb-i2c"},
734 {.compatible = "brcm,brcmper-i2c"},
735 {.compatible = "brcm,bcm2711-hdmi-i2c"},
742 .name = "brcmstb-i2c",
752 MODULE_DESCRIPTION("Broadcom Settop I2C Driver");