Lines Matching refs:i2c_dev

408 static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask)  in stm32f7_i2c_disable_irq()  argument
410 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); in stm32f7_i2c_disable_irq()
425 static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_compute_timing() argument
449 dev_err(i2c_dev->dev, "speed out of bound {%d}\n", in stm32f7_i2c_compute_timing()
456 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
464 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
492 dev_dbg(i2c_dev->dev, "SDADEL(min/max): %i/%i, SCLDEL(Min): %i\n", in stm32f7_i2c_compute_timing()
533 dev_err(i2c_dev->dev, "no Prescaler solution\n"); in stm32f7_i2c_compute_timing()
590 dev_err(i2c_dev->dev, "no solution at all\n"); in stm32f7_i2c_compute_timing()
601 dev_dbg(i2c_dev->dev, in stm32f7_i2c_compute_timing()
628 static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_setup_timing() argument
635 t->scl_rise_ns = i2c_dev->setup.rise_time; in stm32f7_i2c_setup_timing()
636 t->scl_fall_ns = i2c_dev->setup.fall_time; in stm32f7_i2c_setup_timing()
638 i2c_parse_fw_timings(i2c_dev->dev, t, false); in stm32f7_i2c_setup_timing()
641 dev_err(i2c_dev->dev, "Invalid bus speed (%i>%i)\n", in stm32f7_i2c_setup_timing()
647 i2c_dev->setup.rise_time = t->scl_rise_ns; in stm32f7_i2c_setup_timing()
648 i2c_dev->setup.fall_time = t->scl_fall_ns; in stm32f7_i2c_setup_timing()
649 setup->clock_src = clk_get_rate(i2c_dev->clk); in stm32f7_i2c_setup_timing()
652 dev_err(i2c_dev->dev, "clock rate is 0\n"); in stm32f7_i2c_setup_timing()
657 ret = stm32f7_i2c_compute_timing(i2c_dev, setup, in stm32f7_i2c_setup_timing()
658 &i2c_dev->timing); in stm32f7_i2c_setup_timing()
660 dev_err(i2c_dev->dev, in stm32f7_i2c_setup_timing()
666 dev_warn(i2c_dev->dev, in stm32f7_i2c_setup_timing()
673 dev_err(i2c_dev->dev, "Impossible to compute I2C timings.\n"); in stm32f7_i2c_setup_timing()
677 dev_dbg(i2c_dev->dev, "I2C Speed(%i), Clk Source(%i)\n", in stm32f7_i2c_setup_timing()
679 dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n", in stm32f7_i2c_setup_timing()
681 dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n", in stm32f7_i2c_setup_timing()
684 i2c_dev->bus_rate = setup->speed_freq; in stm32f7_i2c_setup_timing()
689 static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_dma_req() argument
691 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_dma_req()
699 struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg; in stm32f7_i2c_dma_callback() local
700 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_dma_callback()
703 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_dma_callback()
708 static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_hw_config() argument
710 struct stm32f7_i2c_timings *t = &i2c_dev->timing; in stm32f7_i2c_hw_config()
719 writel_relaxed(timing, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_hw_config()
722 if (i2c_dev->setup.analog_filter) in stm32f7_i2c_hw_config()
723 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
726 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
728 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
732 static void stm32f7_i2c_write_tx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_write_tx_data() argument
734 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_write_tx_data()
735 void __iomem *base = i2c_dev->base; in stm32f7_i2c_write_tx_data()
743 static void stm32f7_i2c_read_rx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_read_rx_data() argument
745 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_read_rx_data()
746 void __iomem *base = i2c_dev->base; in stm32f7_i2c_read_rx_data()
757 static void stm32f7_i2c_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_reload() argument
759 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_reload()
762 if (i2c_dev->use_dma) in stm32f7_i2c_reload()
765 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
775 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
778 static void stm32f7_i2c_smbus_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_reload() argument
780 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_reload()
788 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_smbus_reload()
795 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
798 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
803 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_release_bus() local
805 dev_info(i2c_dev->dev, "Trying to recover bus\n"); in stm32f7_i2c_release_bus()
807 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_release_bus()
810 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_release_bus()
815 static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_wait_free_bus() argument
820 ret = readl_relaxed_poll_timeout(i2c_dev->base + STM32F7_I2C_ISR, in stm32f7_i2c_wait_free_bus()
827 dev_info(i2c_dev->dev, "bus busy\n"); in stm32f7_i2c_wait_free_bus()
829 ret = stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_wait_free_bus()
831 dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret); in stm32f7_i2c_wait_free_bus()
838 static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_xfer_msg() argument
841 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer_msg()
842 void __iomem *base = i2c_dev->base; in stm32f7_i2c_xfer_msg()
850 f7_msg->stop = (i2c_dev->msg_id >= i2c_dev->msg_num - 1); in stm32f7_i2c_xfer_msg()
852 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_xfer_msg()
891 i2c_dev->use_dma = false; in stm32f7_i2c_xfer_msg()
892 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_xfer_msg()
893 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_xfer_msg()
897 i2c_dev); in stm32f7_i2c_xfer_msg()
899 i2c_dev->use_dma = true; in stm32f7_i2c_xfer_msg()
901 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_xfer_msg()
904 if (!i2c_dev->use_dma) { in stm32f7_i2c_xfer_msg()
919 i2c_dev->master_mode = true; in stm32f7_i2c_xfer_msg()
926 static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_smbus_xfer_msg() argument
930 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer_msg()
931 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer_msg()
932 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_xfer_msg()
937 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_smbus_xfer_msg()
1057 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_xfer_msg()
1058 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_smbus_xfer_msg()
1059 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_xfer_msg()
1063 i2c_dev); in stm32f7_i2c_smbus_xfer_msg()
1065 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_xfer_msg()
1067 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_xfer_msg()
1070 if (!i2c_dev->use_dma) { in stm32f7_i2c_smbus_xfer_msg()
1085 i2c_dev->master_mode = true; in stm32f7_i2c_smbus_xfer_msg()
1094 static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_rep_start() argument
1096 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_rep_start()
1097 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_rep_start()
1147 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_rep_start()
1148 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN && in stm32f7_i2c_smbus_rep_start()
1151 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_rep_start()
1155 i2c_dev); in stm32f7_i2c_smbus_rep_start()
1158 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_rep_start()
1160 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_rep_start()
1163 if (!i2c_dev->use_dma) in stm32f7_i2c_smbus_rep_start()
1176 static int stm32f7_i2c_smbus_check_pec(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_check_pec() argument
1178 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_check_pec()
1181 internal_pec = readl_relaxed(i2c_dev->base + STM32F7_I2C_PECR); in stm32f7_i2c_smbus_check_pec()
1198 dev_err(i2c_dev->dev, "Unsupported smbus protocol for PEC\n"); in stm32f7_i2c_smbus_check_pec()
1203 dev_err(i2c_dev->dev, "Bad PEC 0x%02x vs. 0x%02x\n", in stm32f7_i2c_smbus_check_pec()
1237 static void stm32f7_i2c_slave_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_start() argument
1239 struct i2c_client *slave = i2c_dev->slave_running; in stm32f7_i2c_slave_start()
1240 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_start()
1244 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_start()
1285 static void stm32f7_i2c_slave_addr(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_addr() argument
1287 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_addr()
1291 isr = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_addr()
1296 if (stm32f7_i2c_is_addr_match(i2c_dev->slave[i], addcode)) { in stm32f7_i2c_slave_addr()
1297 i2c_dev->slave_running = i2c_dev->slave[i]; in stm32f7_i2c_slave_addr()
1298 i2c_dev->slave_dir = dir; in stm32f7_i2c_slave_addr()
1301 stm32f7_i2c_slave_start(i2c_dev); in stm32f7_i2c_slave_addr()
1311 static int stm32f7_i2c_get_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_slave_id() argument
1317 if (i2c_dev->slave[i] == slave) { in stm32f7_i2c_get_slave_id()
1323 dev_err(i2c_dev->dev, "Slave 0x%x not registered\n", slave->addr); in stm32f7_i2c_get_slave_id()
1328 static int stm32f7_i2c_get_free_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_free_slave_id() argument
1331 struct device *dev = i2c_dev->dev; in stm32f7_i2c_get_free_slave_id()
1339 if (i2c_dev->smbus_mode && (slave->addr == 0x08)) { in stm32f7_i2c_get_free_slave_id()
1340 if (i2c_dev->slave[STM32F7_SLAVE_HOSTNOTIFY]) in stm32f7_i2c_get_free_slave_id()
1350 if (!i2c_dev->slave[i]) { in stm32f7_i2c_get_free_slave_id()
1362 static bool stm32f7_i2c_is_slave_registered(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_registered() argument
1367 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_registered()
1374 static bool stm32f7_i2c_is_slave_busy(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_busy() argument
1380 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_busy()
1387 static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_isr_event() argument
1389 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_isr_event()
1394 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_isr_event()
1398 i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1412 val = readb_relaxed(i2c_dev->base + STM32F7_I2C_RXDR); in stm32f7_i2c_slave_isr_event()
1413 ret = i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1417 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1419 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1428 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); in stm32f7_i2c_slave_isr_event()
1435 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_XFER_IRQ_MASK); in stm32f7_i2c_slave_isr_event()
1437 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_isr_event()
1450 i2c_slave_event(i2c_dev->slave_running, I2C_SLAVE_STOP, &val); in stm32f7_i2c_slave_isr_event()
1452 i2c_dev->slave_running = NULL; in stm32f7_i2c_slave_isr_event()
1457 stm32f7_i2c_slave_addr(i2c_dev); in stm32f7_i2c_slave_isr_event()
1464 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event() local
1465 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event()
1466 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_event()
1471 if (!i2c_dev->master_mode) { in stm32f7_i2c_isr_event()
1472 ret = stm32f7_i2c_slave_isr_event(i2c_dev); in stm32f7_i2c_isr_event()
1476 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event()
1480 stm32f7_i2c_write_tx_data(i2c_dev); in stm32f7_i2c_isr_event()
1484 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_isr_event()
1488 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK (addr %x)\n", in stm32f7_i2c_isr_event()
1497 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_event()
1501 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_event()
1506 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_event()
1509 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event()
1510 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event()
1519 } else if (i2c_dev->use_dma) { in stm32f7_i2c_isr_event()
1522 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event()
1524 i2c_dev->msg_id++; in stm32f7_i2c_isr_event()
1525 i2c_dev->msg++; in stm32f7_i2c_isr_event()
1526 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event()
1532 stm32f7_i2c_smbus_reload(i2c_dev); in stm32f7_i2c_isr_event()
1534 stm32f7_i2c_reload(i2c_dev); in stm32f7_i2c_isr_event()
1542 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event_thread() local
1543 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event_thread()
1544 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event_thread()
1552 ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ); in stm32f7_i2c_isr_event_thread()
1554 dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__); in stm32f7_i2c_isr_event_thread()
1555 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event_thread()
1560 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event_thread()
1564 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event_thread()
1566 i2c_dev->msg_id++; in stm32f7_i2c_isr_event_thread()
1567 i2c_dev->msg++; in stm32f7_i2c_isr_event_thread()
1568 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event_thread()
1571 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event_thread()
1572 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event_thread()
1580 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_error() local
1581 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_error()
1582 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_error()
1583 struct device *dev = i2c_dev->dev; in stm32f7_i2c_isr_error()
1584 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_error()
1587 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_error()
1593 stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_isr_error()
1610 if (!i2c_dev->slave_running) { in stm32f7_i2c_isr_error()
1613 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_error()
1617 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_error()
1621 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_error()
1622 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_error()
1626 i2c_dev->master_mode = false; in stm32f7_i2c_isr_error()
1627 complete(&i2c_dev->complete); in stm32f7_i2c_isr_error()
1635 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_xfer() local
1636 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer()
1637 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_xfer()
1641 i2c_dev->msg = msgs; in stm32f7_i2c_xfer()
1642 i2c_dev->msg_num = num; in stm32f7_i2c_xfer()
1643 i2c_dev->msg_id = 0; in stm32f7_i2c_xfer()
1646 ret = pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_xfer()
1650 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1654 stm32f7_i2c_xfer_msg(i2c_dev, msgs); in stm32f7_i2c_xfer()
1656 time_left = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_xfer()
1657 i2c_dev->adap.timeout); in stm32f7_i2c_xfer()
1661 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n", in stm32f7_i2c_xfer()
1662 i2c_dev->msg->addr); in stm32f7_i2c_xfer()
1663 if (i2c_dev->use_dma) in stm32f7_i2c_xfer()
1669 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_xfer()
1670 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_xfer()
1680 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adapter); in stm32f7_i2c_smbus_xfer() local
1681 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer()
1682 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_smbus_xfer()
1683 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer()
1696 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1700 ret = stm32f7_i2c_smbus_xfer_msg(i2c_dev, flags, command, data); in stm32f7_i2c_smbus_xfer()
1704 timeout = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_smbus_xfer()
1705 i2c_dev->adap.timeout); in stm32f7_i2c_smbus_xfer()
1712 if (i2c_dev->use_dma) in stm32f7_i2c_smbus_xfer()
1720 ret = stm32f7_i2c_smbus_check_pec(i2c_dev); in stm32f7_i2c_smbus_xfer()
1753 static void stm32f7_i2c_enable_wakeup(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_enable_wakeup() argument
1756 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_wakeup()
1759 if (!i2c_dev->wakeup_src) in stm32f7_i2c_enable_wakeup()
1763 device_set_wakeup_enable(i2c_dev->dev, true); in stm32f7_i2c_enable_wakeup()
1766 device_set_wakeup_enable(i2c_dev->dev, false); in stm32f7_i2c_enable_wakeup()
1773 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_reg_slave() local
1774 void __iomem *base = i2c_dev->base; in stm32f7_i2c_reg_slave()
1775 struct device *dev = i2c_dev->dev; in stm32f7_i2c_reg_slave()
1784 if (stm32f7_i2c_is_slave_busy(i2c_dev)) { in stm32f7_i2c_reg_slave()
1789 ret = stm32f7_i2c_get_free_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_reg_slave()
1797 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_reg_slave()
1798 stm32f7_i2c_enable_wakeup(i2c_dev, true); in stm32f7_i2c_reg_slave()
1803 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1808 oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1817 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1818 writel_relaxed(oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1823 oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1832 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1833 writel_relaxed(oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1852 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_reg_slave()
1853 stm32f7_i2c_enable_wakeup(i2c_dev, false); in stm32f7_i2c_reg_slave()
1863 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_unreg_slave() local
1864 void __iomem *base = i2c_dev->base; in stm32f7_i2c_unreg_slave()
1868 ret = stm32f7_i2c_get_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_unreg_slave()
1872 WARN_ON(!i2c_dev->slave[id]); in stm32f7_i2c_unreg_slave()
1874 ret = pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1886 i2c_dev->slave[id] = NULL; in stm32f7_i2c_unreg_slave()
1888 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { in stm32f7_i2c_unreg_slave()
1889 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); in stm32f7_i2c_unreg_slave()
1890 stm32f7_i2c_enable_wakeup(i2c_dev, false); in stm32f7_i2c_unreg_slave()
1893 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1894 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1899 static int stm32f7_i2c_write_fm_plus_bits(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_write_fm_plus_bits() argument
1904 if (i2c_dev->bus_rate <= I2C_MAX_FAST_MODE_FREQ || in stm32f7_i2c_write_fm_plus_bits()
1905 IS_ERR_OR_NULL(i2c_dev->regmap)) in stm32f7_i2c_write_fm_plus_bits()
1909 if (i2c_dev->fmp_sreg == i2c_dev->fmp_creg) in stm32f7_i2c_write_fm_plus_bits()
1910 ret = regmap_update_bits(i2c_dev->regmap, in stm32f7_i2c_write_fm_plus_bits()
1911 i2c_dev->fmp_sreg, in stm32f7_i2c_write_fm_plus_bits()
1912 i2c_dev->fmp_mask, in stm32f7_i2c_write_fm_plus_bits()
1913 enable ? i2c_dev->fmp_mask : 0); in stm32f7_i2c_write_fm_plus_bits()
1915 ret = regmap_write(i2c_dev->regmap, in stm32f7_i2c_write_fm_plus_bits()
1916 enable ? i2c_dev->fmp_sreg : in stm32f7_i2c_write_fm_plus_bits()
1917 i2c_dev->fmp_creg, in stm32f7_i2c_write_fm_plus_bits()
1918 i2c_dev->fmp_mask); in stm32f7_i2c_write_fm_plus_bits()
1924 struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_setup_fm_plus_bits() argument
1929 i2c_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg-fmp"); in stm32f7_i2c_setup_fm_plus_bits()
1930 if (IS_ERR(i2c_dev->regmap)) in stm32f7_i2c_setup_fm_plus_bits()
1935 &i2c_dev->fmp_sreg); in stm32f7_i2c_setup_fm_plus_bits()
1939 i2c_dev->fmp_creg = i2c_dev->fmp_sreg + in stm32f7_i2c_setup_fm_plus_bits()
1940 i2c_dev->setup.fmp_clr_offset; in stm32f7_i2c_setup_fm_plus_bits()
1943 &i2c_dev->fmp_mask); in stm32f7_i2c_setup_fm_plus_bits()
1946 static int stm32f7_i2c_enable_smbus_host(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_enable_smbus_host() argument
1948 struct i2c_adapter *adap = &i2c_dev->adap; in stm32f7_i2c_enable_smbus_host()
1949 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_smbus_host()
1956 i2c_dev->host_notify_client = client; in stm32f7_i2c_enable_smbus_host()
1964 static void stm32f7_i2c_disable_smbus_host(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_smbus_host() argument
1966 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_smbus_host()
1968 if (i2c_dev->host_notify_client) { in stm32f7_i2c_disable_smbus_host()
1972 i2c_free_slave_host_notify_device(i2c_dev->host_notify_client); in stm32f7_i2c_disable_smbus_host()
1978 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adap); in stm32f7_i2c_func() local
1987 if (i2c_dev->smbus_mode) in stm32f7_i2c_func()
2003 struct stm32f7_i2c_dev *i2c_dev; in stm32f7_i2c_probe() local
2011 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); in stm32f7_i2c_probe()
2012 if (!i2c_dev) in stm32f7_i2c_probe()
2015 i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in stm32f7_i2c_probe()
2016 if (IS_ERR(i2c_dev->base)) in stm32f7_i2c_probe()
2017 return PTR_ERR(i2c_dev->base); in stm32f7_i2c_probe()
2036 i2c_dev->wakeup_src = of_property_read_bool(pdev->dev.of_node, in stm32f7_i2c_probe()
2039 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); in stm32f7_i2c_probe()
2040 if (IS_ERR(i2c_dev->clk)) in stm32f7_i2c_probe()
2041 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->clk), in stm32f7_i2c_probe()
2044 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_probe()
2060 i2c_dev->dev = &pdev->dev; in stm32f7_i2c_probe()
2066 pdev->name, i2c_dev); in stm32f7_i2c_probe()
2074 pdev->name, i2c_dev); in stm32f7_i2c_probe()
2087 i2c_dev->setup = *setup; in stm32f7_i2c_probe()
2089 ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup); in stm32f7_i2c_probe()
2094 if (i2c_dev->bus_rate > I2C_MAX_FAST_MODE_FREQ) { in stm32f7_i2c_probe()
2095 ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev); in stm32f7_i2c_probe()
2098 ret = stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); in stm32f7_i2c_probe()
2103 adap = &i2c_dev->adap; in stm32f7_i2c_probe()
2104 i2c_set_adapdata(adap, i2c_dev); in stm32f7_i2c_probe()
2114 init_completion(&i2c_dev->complete); in stm32f7_i2c_probe()
2117 i2c_dev->dma = stm32_i2c_dma_request(i2c_dev->dev, phy_addr, in stm32f7_i2c_probe()
2120 if (IS_ERR(i2c_dev->dma)) { in stm32f7_i2c_probe()
2121 ret = PTR_ERR(i2c_dev->dma); in stm32f7_i2c_probe()
2125 dev_dbg(i2c_dev->dev, "No DMA option: fallback using interrupts\n"); in stm32f7_i2c_probe()
2126 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
2129 if (i2c_dev->wakeup_src) { in stm32f7_i2c_probe()
2130 device_set_wakeup_capable(i2c_dev->dev, true); in stm32f7_i2c_probe()
2132 ret = dev_pm_set_wake_irq(i2c_dev->dev, irq_event); in stm32f7_i2c_probe()
2134 dev_err(i2c_dev->dev, "Failed to set wake up irq\n"); in stm32f7_i2c_probe()
2139 platform_set_drvdata(pdev, i2c_dev); in stm32f7_i2c_probe()
2141 pm_runtime_set_autosuspend_delay(i2c_dev->dev, in stm32f7_i2c_probe()
2143 pm_runtime_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2144 pm_runtime_set_active(i2c_dev->dev); in stm32f7_i2c_probe()
2145 pm_runtime_enable(i2c_dev->dev); in stm32f7_i2c_probe()
2149 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_probe()
2151 i2c_dev->smbus_mode = of_property_read_bool(pdev->dev.of_node, "smbus"); in stm32f7_i2c_probe()
2157 if (i2c_dev->smbus_mode) { in stm32f7_i2c_probe()
2158 ret = stm32f7_i2c_enable_smbus_host(i2c_dev); in stm32f7_i2c_probe()
2160 dev_err(i2c_dev->dev, in stm32f7_i2c_probe()
2167 dev_info(i2c_dev->dev, "STM32F7 I2C-%d bus adapter\n", adap->nr); in stm32f7_i2c_probe()
2169 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_probe()
2170 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2178 pm_runtime_put_noidle(i2c_dev->dev); in stm32f7_i2c_probe()
2179 pm_runtime_disable(i2c_dev->dev); in stm32f7_i2c_probe()
2180 pm_runtime_set_suspended(i2c_dev->dev); in stm32f7_i2c_probe()
2181 pm_runtime_dont_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2183 if (i2c_dev->wakeup_src) in stm32f7_i2c_probe()
2184 dev_pm_clear_wake_irq(i2c_dev->dev); in stm32f7_i2c_probe()
2187 if (i2c_dev->wakeup_src) in stm32f7_i2c_probe()
2188 device_set_wakeup_capable(i2c_dev->dev, false); in stm32f7_i2c_probe()
2190 if (i2c_dev->dma) { in stm32f7_i2c_probe()
2191 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_probe()
2192 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
2196 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_probe()
2199 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_probe()
2206 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev); in stm32f7_i2c_remove() local
2208 stm32f7_i2c_disable_smbus_host(i2c_dev); in stm32f7_i2c_remove()
2210 i2c_del_adapter(&i2c_dev->adap); in stm32f7_i2c_remove()
2211 pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_remove()
2213 if (i2c_dev->wakeup_src) { in stm32f7_i2c_remove()
2214 dev_pm_clear_wake_irq(i2c_dev->dev); in stm32f7_i2c_remove()
2219 device_init_wakeup(i2c_dev->dev, false); in stm32f7_i2c_remove()
2222 pm_runtime_put_noidle(i2c_dev->dev); in stm32f7_i2c_remove()
2223 pm_runtime_disable(i2c_dev->dev); in stm32f7_i2c_remove()
2224 pm_runtime_set_suspended(i2c_dev->dev); in stm32f7_i2c_remove()
2225 pm_runtime_dont_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_remove()
2227 if (i2c_dev->dma) { in stm32f7_i2c_remove()
2228 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_remove()
2229 i2c_dev->dma = NULL; in stm32f7_i2c_remove()
2232 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_remove()
2234 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_remove()
2241 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_runtime_suspend() local
2243 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_runtime_suspend()
2244 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_runtime_suspend()
2251 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_runtime_resume() local
2254 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { in stm32f7_i2c_runtime_resume()
2255 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_runtime_resume()
2266 static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_regs_backup() argument
2269 struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; in stm32f7_i2c_regs_backup()
2271 ret = pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_regs_backup()
2275 backup_regs->cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_backup()
2276 backup_regs->cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_regs_backup()
2277 backup_regs->oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_regs_backup()
2278 backup_regs->oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_regs_backup()
2279 backup_regs->tmgr = readl_relaxed(i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_regs_backup()
2280 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_regs_backup()
2282 pm_runtime_put_sync(i2c_dev->dev); in stm32f7_i2c_regs_backup()
2287 static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_regs_restore() argument
2291 struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; in stm32f7_i2c_regs_restore()
2293 ret = pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_regs_restore()
2297 cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_restore()
2299 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_regs_restore()
2302 writel_relaxed(backup_regs->tmgr, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_regs_restore()
2304 i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_restore()
2306 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_regs_restore()
2308 writel_relaxed(backup_regs->cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_regs_restore()
2309 writel_relaxed(backup_regs->oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_regs_restore()
2310 writel_relaxed(backup_regs->oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_regs_restore()
2311 stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); in stm32f7_i2c_regs_restore()
2313 pm_runtime_put_sync(i2c_dev->dev); in stm32f7_i2c_regs_restore()
2320 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_suspend() local
2323 i2c_mark_adapter_suspended(&i2c_dev->adap); in stm32f7_i2c_suspend()
2326 ret = stm32f7_i2c_regs_backup(i2c_dev); in stm32f7_i2c_suspend()
2328 i2c_mark_adapter_resumed(&i2c_dev->adap); in stm32f7_i2c_suspend()
2341 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_resume() local
2350 ret = stm32f7_i2c_regs_restore(i2c_dev); in stm32f7_i2c_resume()
2355 i2c_mark_adapter_resumed(&i2c_dev->adap); in stm32f7_i2c_resume()