Lines Matching refs:i2c_dev
410 static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask) in stm32f7_i2c_disable_irq() argument
412 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); in stm32f7_i2c_disable_irq()
427 static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_compute_timing() argument
451 dev_err(i2c_dev->dev, "speed out of bound {%d}\n", in stm32f7_i2c_compute_timing()
458 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
466 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
494 dev_dbg(i2c_dev->dev, "SDADEL(min/max): %i/%i, SCLDEL(Min): %i\n", in stm32f7_i2c_compute_timing()
535 dev_err(i2c_dev->dev, "no Prescaler solution\n"); in stm32f7_i2c_compute_timing()
592 dev_err(i2c_dev->dev, "no solution at all\n"); in stm32f7_i2c_compute_timing()
603 dev_dbg(i2c_dev->dev, in stm32f7_i2c_compute_timing()
630 static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_setup_timing() argument
637 t->scl_rise_ns = i2c_dev->setup.rise_time; in stm32f7_i2c_setup_timing()
638 t->scl_fall_ns = i2c_dev->setup.fall_time; in stm32f7_i2c_setup_timing()
640 i2c_parse_fw_timings(i2c_dev->dev, t, false); in stm32f7_i2c_setup_timing()
643 dev_err(i2c_dev->dev, "Invalid bus speed (%i>%i)\n", in stm32f7_i2c_setup_timing()
649 i2c_dev->setup.rise_time = t->scl_rise_ns; in stm32f7_i2c_setup_timing()
650 i2c_dev->setup.fall_time = t->scl_fall_ns; in stm32f7_i2c_setup_timing()
651 setup->clock_src = clk_get_rate(i2c_dev->clk); in stm32f7_i2c_setup_timing()
654 dev_err(i2c_dev->dev, "clock rate is 0\n"); in stm32f7_i2c_setup_timing()
659 ret = stm32f7_i2c_compute_timing(i2c_dev, setup, in stm32f7_i2c_setup_timing()
660 &i2c_dev->timing); in stm32f7_i2c_setup_timing()
662 dev_err(i2c_dev->dev, in stm32f7_i2c_setup_timing()
668 dev_warn(i2c_dev->dev, in stm32f7_i2c_setup_timing()
675 dev_err(i2c_dev->dev, "Impossible to compute I2C timings.\n"); in stm32f7_i2c_setup_timing()
679 dev_dbg(i2c_dev->dev, "I2C Speed(%i), Clk Source(%i)\n", in stm32f7_i2c_setup_timing()
681 dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n", in stm32f7_i2c_setup_timing()
683 dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n", in stm32f7_i2c_setup_timing()
686 i2c_dev->bus_rate = setup->speed_freq; in stm32f7_i2c_setup_timing()
691 static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_dma_req() argument
693 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_dma_req()
701 struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg; in stm32f7_i2c_dma_callback() local
702 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_dma_callback()
705 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_dma_callback()
710 static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_hw_config() argument
712 struct stm32f7_i2c_timings *t = &i2c_dev->timing; in stm32f7_i2c_hw_config()
721 writel_relaxed(timing, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_hw_config()
724 if (i2c_dev->setup.analog_filter) in stm32f7_i2c_hw_config()
725 stm32f7_i2c_clr_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 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
734 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
735 STM32F7_I2C_CR1_DNF(i2c_dev->setup.dnf)); in stm32f7_i2c_hw_config()
737 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
741 static void stm32f7_i2c_write_tx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_write_tx_data() argument
743 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_write_tx_data()
744 void __iomem *base = i2c_dev->base; in stm32f7_i2c_write_tx_data()
752 static void stm32f7_i2c_read_rx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_read_rx_data() argument
754 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_read_rx_data()
755 void __iomem *base = i2c_dev->base; in stm32f7_i2c_read_rx_data()
766 static void stm32f7_i2c_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_reload() argument
768 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_reload()
771 if (i2c_dev->use_dma) in stm32f7_i2c_reload()
774 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
784 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
787 static void stm32f7_i2c_smbus_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_reload() argument
789 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_reload()
797 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_smbus_reload()
804 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
807 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
812 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_release_bus() local
814 dev_info(i2c_dev->dev, "Trying to recover bus\n"); in stm32f7_i2c_release_bus()
816 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_release_bus()
819 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_release_bus()
824 static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_wait_free_bus() argument
829 ret = readl_relaxed_poll_timeout(i2c_dev->base + STM32F7_I2C_ISR, in stm32f7_i2c_wait_free_bus()
836 dev_info(i2c_dev->dev, "bus busy\n"); in stm32f7_i2c_wait_free_bus()
838 ret = stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_wait_free_bus()
840 dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret); in stm32f7_i2c_wait_free_bus()
847 static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_xfer_msg() argument
850 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer_msg()
851 void __iomem *base = i2c_dev->base; in stm32f7_i2c_xfer_msg()
859 f7_msg->stop = (i2c_dev->msg_id >= i2c_dev->msg_num - 1); in stm32f7_i2c_xfer_msg()
861 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_xfer_msg()
900 i2c_dev->use_dma = false; in stm32f7_i2c_xfer_msg()
901 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_xfer_msg()
902 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_xfer_msg()
906 i2c_dev); in stm32f7_i2c_xfer_msg()
908 i2c_dev->use_dma = true; in stm32f7_i2c_xfer_msg()
910 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_xfer_msg()
913 if (!i2c_dev->use_dma) { in stm32f7_i2c_xfer_msg()
928 i2c_dev->master_mode = true; in stm32f7_i2c_xfer_msg()
935 static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_smbus_xfer_msg() argument
939 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer_msg()
940 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer_msg()
941 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_xfer_msg()
946 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_smbus_xfer_msg()
1066 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_xfer_msg()
1067 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_smbus_xfer_msg()
1068 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_xfer_msg()
1072 i2c_dev); in stm32f7_i2c_smbus_xfer_msg()
1074 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_xfer_msg()
1076 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_xfer_msg()
1079 if (!i2c_dev->use_dma) { in stm32f7_i2c_smbus_xfer_msg()
1094 i2c_dev->master_mode = true; in stm32f7_i2c_smbus_xfer_msg()
1103 static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_rep_start() argument
1105 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_rep_start()
1106 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_rep_start()
1156 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_rep_start()
1157 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN && in stm32f7_i2c_smbus_rep_start()
1160 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_rep_start()
1164 i2c_dev); in stm32f7_i2c_smbus_rep_start()
1167 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_rep_start()
1169 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_rep_start()
1172 if (!i2c_dev->use_dma) in stm32f7_i2c_smbus_rep_start()
1185 static int stm32f7_i2c_smbus_check_pec(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_check_pec() argument
1187 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_check_pec()
1190 internal_pec = readl_relaxed(i2c_dev->base + STM32F7_I2C_PECR); in stm32f7_i2c_smbus_check_pec()
1207 dev_err(i2c_dev->dev, "Unsupported smbus protocol for PEC\n"); in stm32f7_i2c_smbus_check_pec()
1212 dev_err(i2c_dev->dev, "Bad PEC 0x%02x vs. 0x%02x\n", in stm32f7_i2c_smbus_check_pec()
1246 static void stm32f7_i2c_slave_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_start() argument
1248 struct i2c_client *slave = i2c_dev->slave_running; in stm32f7_i2c_slave_start()
1249 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_start()
1253 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_start()
1294 static void stm32f7_i2c_slave_addr(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_addr() argument
1296 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_addr()
1300 isr = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_addr()
1305 if (stm32f7_i2c_is_addr_match(i2c_dev->slave[i], addcode)) { in stm32f7_i2c_slave_addr()
1306 i2c_dev->slave_running = i2c_dev->slave[i]; in stm32f7_i2c_slave_addr()
1307 i2c_dev->slave_dir = dir; in stm32f7_i2c_slave_addr()
1310 stm32f7_i2c_slave_start(i2c_dev); in stm32f7_i2c_slave_addr()
1320 static int stm32f7_i2c_get_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_slave_id() argument
1326 if (i2c_dev->slave[i] == slave) { in stm32f7_i2c_get_slave_id()
1332 dev_err(i2c_dev->dev, "Slave 0x%x not registered\n", slave->addr); in stm32f7_i2c_get_slave_id()
1337 static int stm32f7_i2c_get_free_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_free_slave_id() argument
1340 struct device *dev = i2c_dev->dev; in stm32f7_i2c_get_free_slave_id()
1348 if (i2c_dev->smbus_mode && (slave->addr == 0x08)) { in stm32f7_i2c_get_free_slave_id()
1349 if (i2c_dev->slave[STM32F7_SLAVE_HOSTNOTIFY]) in stm32f7_i2c_get_free_slave_id()
1359 if (!i2c_dev->slave[i]) { in stm32f7_i2c_get_free_slave_id()
1371 static bool stm32f7_i2c_is_slave_registered(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_registered() argument
1376 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_registered()
1383 static bool stm32f7_i2c_is_slave_busy(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_busy() argument
1389 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_busy()
1396 static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_isr_event() argument
1398 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_isr_event()
1403 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_isr_event()
1407 i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1421 val = readb_relaxed(i2c_dev->base + STM32F7_I2C_RXDR); in stm32f7_i2c_slave_isr_event()
1422 ret = i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1426 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1428 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1437 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); in stm32f7_i2c_slave_isr_event()
1444 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_XFER_IRQ_MASK); in stm32f7_i2c_slave_isr_event()
1446 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_isr_event()
1459 i2c_slave_event(i2c_dev->slave_running, I2C_SLAVE_STOP, &val); in stm32f7_i2c_slave_isr_event()
1461 i2c_dev->slave_running = NULL; in stm32f7_i2c_slave_isr_event()
1466 stm32f7_i2c_slave_addr(i2c_dev); in stm32f7_i2c_slave_isr_event()
1473 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event() local
1474 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event()
1475 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event()
1476 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_event()
1481 if (!i2c_dev->master_mode) { in stm32f7_i2c_isr_event()
1482 ret = stm32f7_i2c_slave_isr_event(i2c_dev); in stm32f7_i2c_isr_event()
1486 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event()
1490 stm32f7_i2c_write_tx_data(i2c_dev); in stm32f7_i2c_isr_event()
1494 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_isr_event()
1498 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK (addr %x)\n", in stm32f7_i2c_isr_event()
1501 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_event()
1502 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event()
1511 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_event()
1515 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_event()
1520 if (i2c_dev->use_dma && !f7_msg->result) { in stm32f7_i2c_isr_event()
1523 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event()
1524 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event()
1533 } else if (i2c_dev->use_dma && !f7_msg->result) { in stm32f7_i2c_isr_event()
1536 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event()
1538 i2c_dev->msg_id++; in stm32f7_i2c_isr_event()
1539 i2c_dev->msg++; in stm32f7_i2c_isr_event()
1540 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event()
1546 stm32f7_i2c_smbus_reload(i2c_dev); in stm32f7_i2c_isr_event()
1548 stm32f7_i2c_reload(i2c_dev); in stm32f7_i2c_isr_event()
1556 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event_thread() local
1557 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event_thread()
1558 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event_thread()
1566 ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ); in stm32f7_i2c_isr_event_thread()
1568 dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__); in stm32f7_i2c_isr_event_thread()
1569 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event_thread()
1574 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event_thread()
1578 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event_thread()
1580 i2c_dev->msg_id++; in stm32f7_i2c_isr_event_thread()
1581 i2c_dev->msg++; in stm32f7_i2c_isr_event_thread()
1582 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event_thread()
1585 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event_thread()
1586 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event_thread()
1594 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_error() local
1595 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_error()
1596 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_error()
1597 struct device *dev = i2c_dev->dev; in stm32f7_i2c_isr_error()
1598 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_error()
1601 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_error()
1607 stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_isr_error()
1624 if (!i2c_dev->slave_running) { in stm32f7_i2c_isr_error()
1627 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_error()
1631 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_error()
1635 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_error()
1636 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_error()
1640 i2c_dev->master_mode = false; in stm32f7_i2c_isr_error()
1641 complete(&i2c_dev->complete); in stm32f7_i2c_isr_error()
1649 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_xfer() local
1650 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer()
1651 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_xfer()
1655 i2c_dev->msg = msgs; in stm32f7_i2c_xfer()
1656 i2c_dev->msg_num = num; in stm32f7_i2c_xfer()
1657 i2c_dev->msg_id = 0; in stm32f7_i2c_xfer()
1660 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_xfer()
1664 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1668 stm32f7_i2c_xfer_msg(i2c_dev, msgs); in stm32f7_i2c_xfer()
1670 time_left = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_xfer()
1671 i2c_dev->adap.timeout); in stm32f7_i2c_xfer()
1680 i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_xfer()
1685 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n", in stm32f7_i2c_xfer()
1686 i2c_dev->msg->addr); in stm32f7_i2c_xfer()
1687 if (i2c_dev->use_dma) in stm32f7_i2c_xfer()
1689 stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1694 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_xfer()
1695 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_xfer()
1705 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adapter); in stm32f7_i2c_smbus_xfer() local
1706 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer()
1707 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_smbus_xfer()
1708 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer()
1721 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1725 ret = stm32f7_i2c_smbus_xfer_msg(i2c_dev, flags, command, data); in stm32f7_i2c_smbus_xfer()
1729 timeout = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_smbus_xfer()
1730 i2c_dev->adap.timeout); in stm32f7_i2c_smbus_xfer()
1739 i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_smbus_xfer()
1745 if (i2c_dev->use_dma) in stm32f7_i2c_smbus_xfer()
1747 stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1754 ret = stm32f7_i2c_smbus_check_pec(i2c_dev); in stm32f7_i2c_smbus_xfer()
1787 static void stm32f7_i2c_enable_wakeup(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_enable_wakeup() argument
1790 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_wakeup()
1793 if (!i2c_dev->wakeup_src) in stm32f7_i2c_enable_wakeup()
1797 device_set_wakeup_enable(i2c_dev->dev, true); in stm32f7_i2c_enable_wakeup()
1800 device_set_wakeup_enable(i2c_dev->dev, false); in stm32f7_i2c_enable_wakeup()
1807 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_reg_slave() local
1808 void __iomem *base = i2c_dev->base; in stm32f7_i2c_reg_slave()
1809 struct device *dev = i2c_dev->dev; in stm32f7_i2c_reg_slave()
1818 if (stm32f7_i2c_is_slave_busy(i2c_dev)) { in stm32f7_i2c_reg_slave()
1823 ret = stm32f7_i2c_get_free_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_reg_slave()
1831 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_reg_slave()
1832 stm32f7_i2c_enable_wakeup(i2c_dev, true); in stm32f7_i2c_reg_slave()
1837 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1842 oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1851 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1852 writel_relaxed(oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1857 oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1866 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1867 writel_relaxed(oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1886 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_reg_slave()
1887 stm32f7_i2c_enable_wakeup(i2c_dev, false); in stm32f7_i2c_reg_slave()
1897 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_unreg_slave() local
1898 void __iomem *base = i2c_dev->base; in stm32f7_i2c_unreg_slave()
1902 ret = stm32f7_i2c_get_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_unreg_slave()
1906 WARN_ON(!i2c_dev->slave[id]); in stm32f7_i2c_unreg_slave()
1908 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1920 i2c_dev->slave[id] = NULL; in stm32f7_i2c_unreg_slave()
1922 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { in stm32f7_i2c_unreg_slave()
1923 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); in stm32f7_i2c_unreg_slave()
1924 stm32f7_i2c_enable_wakeup(i2c_dev, false); in stm32f7_i2c_unreg_slave()
1927 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1928 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1933 static int stm32f7_i2c_write_fm_plus_bits(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_write_fm_plus_bits() argument
1938 if (i2c_dev->bus_rate <= I2C_MAX_FAST_MODE_FREQ || in stm32f7_i2c_write_fm_plus_bits()
1939 IS_ERR_OR_NULL(i2c_dev->regmap)) in stm32f7_i2c_write_fm_plus_bits()
1943 if (i2c_dev->fmp_sreg == i2c_dev->fmp_creg) in stm32f7_i2c_write_fm_plus_bits()
1944 ret = regmap_update_bits(i2c_dev->regmap, in stm32f7_i2c_write_fm_plus_bits()
1945 i2c_dev->fmp_sreg, in stm32f7_i2c_write_fm_plus_bits()
1946 i2c_dev->fmp_mask, in stm32f7_i2c_write_fm_plus_bits()
1947 enable ? i2c_dev->fmp_mask : 0); in stm32f7_i2c_write_fm_plus_bits()
1949 ret = regmap_write(i2c_dev->regmap, in stm32f7_i2c_write_fm_plus_bits()
1950 enable ? i2c_dev->fmp_sreg : in stm32f7_i2c_write_fm_plus_bits()
1951 i2c_dev->fmp_creg, in stm32f7_i2c_write_fm_plus_bits()
1952 i2c_dev->fmp_mask); in stm32f7_i2c_write_fm_plus_bits()
1958 struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_setup_fm_plus_bits() argument
1963 i2c_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg-fmp"); in stm32f7_i2c_setup_fm_plus_bits()
1964 if (IS_ERR(i2c_dev->regmap)) in stm32f7_i2c_setup_fm_plus_bits()
1969 &i2c_dev->fmp_sreg); in stm32f7_i2c_setup_fm_plus_bits()
1973 i2c_dev->fmp_creg = i2c_dev->fmp_sreg + in stm32f7_i2c_setup_fm_plus_bits()
1974 i2c_dev->setup.fmp_clr_offset; in stm32f7_i2c_setup_fm_plus_bits()
1977 &i2c_dev->fmp_mask); in stm32f7_i2c_setup_fm_plus_bits()
1980 static int stm32f7_i2c_enable_smbus_host(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_enable_smbus_host() argument
1982 struct i2c_adapter *adap = &i2c_dev->adap; in stm32f7_i2c_enable_smbus_host()
1983 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_smbus_host()
1990 i2c_dev->host_notify_client = client; in stm32f7_i2c_enable_smbus_host()
1998 static void stm32f7_i2c_disable_smbus_host(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_smbus_host() argument
2000 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_smbus_host()
2002 if (i2c_dev->host_notify_client) { in stm32f7_i2c_disable_smbus_host()
2006 i2c_free_slave_host_notify_device(i2c_dev->host_notify_client); in stm32f7_i2c_disable_smbus_host()
2012 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adap); in stm32f7_i2c_func() local
2021 if (i2c_dev->smbus_mode) in stm32f7_i2c_func()
2037 struct stm32f7_i2c_dev *i2c_dev; in stm32f7_i2c_probe() local
2045 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); in stm32f7_i2c_probe()
2046 if (!i2c_dev) in stm32f7_i2c_probe()
2049 i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in stm32f7_i2c_probe()
2050 if (IS_ERR(i2c_dev->base)) in stm32f7_i2c_probe()
2051 return PTR_ERR(i2c_dev->base); in stm32f7_i2c_probe()
2070 i2c_dev->wakeup_src = of_property_read_bool(pdev->dev.of_node, in stm32f7_i2c_probe()
2073 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); in stm32f7_i2c_probe()
2074 if (IS_ERR(i2c_dev->clk)) in stm32f7_i2c_probe()
2075 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->clk), in stm32f7_i2c_probe()
2078 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_probe()
2094 i2c_dev->dev = &pdev->dev; in stm32f7_i2c_probe()
2100 pdev->name, i2c_dev); in stm32f7_i2c_probe()
2108 pdev->name, i2c_dev); in stm32f7_i2c_probe()
2121 i2c_dev->setup = *setup; in stm32f7_i2c_probe()
2123 ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup); in stm32f7_i2c_probe()
2128 if (i2c_dev->bus_rate > I2C_MAX_FAST_MODE_FREQ) { in stm32f7_i2c_probe()
2129 ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev); in stm32f7_i2c_probe()
2132 ret = stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); in stm32f7_i2c_probe()
2137 adap = &i2c_dev->adap; in stm32f7_i2c_probe()
2138 i2c_set_adapdata(adap, i2c_dev); in stm32f7_i2c_probe()
2148 init_completion(&i2c_dev->complete); in stm32f7_i2c_probe()
2151 i2c_dev->dma = stm32_i2c_dma_request(i2c_dev->dev, phy_addr, in stm32f7_i2c_probe()
2154 if (IS_ERR(i2c_dev->dma)) { in stm32f7_i2c_probe()
2155 ret = PTR_ERR(i2c_dev->dma); in stm32f7_i2c_probe()
2159 dev_dbg(i2c_dev->dev, "No DMA option: fallback using interrupts\n"); in stm32f7_i2c_probe()
2160 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
2163 if (i2c_dev->wakeup_src) { in stm32f7_i2c_probe()
2164 device_set_wakeup_capable(i2c_dev->dev, true); in stm32f7_i2c_probe()
2166 ret = dev_pm_set_wake_irq(i2c_dev->dev, irq_event); in stm32f7_i2c_probe()
2168 dev_err(i2c_dev->dev, "Failed to set wake up irq\n"); in stm32f7_i2c_probe()
2173 platform_set_drvdata(pdev, i2c_dev); in stm32f7_i2c_probe()
2175 pm_runtime_set_autosuspend_delay(i2c_dev->dev, in stm32f7_i2c_probe()
2177 pm_runtime_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2178 pm_runtime_set_active(i2c_dev->dev); in stm32f7_i2c_probe()
2179 pm_runtime_enable(i2c_dev->dev); in stm32f7_i2c_probe()
2183 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_probe()
2185 i2c_dev->smbus_mode = of_property_read_bool(pdev->dev.of_node, "smbus"); in stm32f7_i2c_probe()
2191 if (i2c_dev->smbus_mode) { in stm32f7_i2c_probe()
2192 ret = stm32f7_i2c_enable_smbus_host(i2c_dev); in stm32f7_i2c_probe()
2194 dev_err(i2c_dev->dev, in stm32f7_i2c_probe()
2201 dev_info(i2c_dev->dev, "STM32F7 I2C-%d bus adapter\n", adap->nr); in stm32f7_i2c_probe()
2203 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_probe()
2204 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2212 pm_runtime_put_noidle(i2c_dev->dev); in stm32f7_i2c_probe()
2213 pm_runtime_disable(i2c_dev->dev); in stm32f7_i2c_probe()
2214 pm_runtime_set_suspended(i2c_dev->dev); in stm32f7_i2c_probe()
2215 pm_runtime_dont_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2217 if (i2c_dev->wakeup_src) in stm32f7_i2c_probe()
2218 dev_pm_clear_wake_irq(i2c_dev->dev); in stm32f7_i2c_probe()
2221 if (i2c_dev->wakeup_src) in stm32f7_i2c_probe()
2222 device_set_wakeup_capable(i2c_dev->dev, false); in stm32f7_i2c_probe()
2224 if (i2c_dev->dma) { in stm32f7_i2c_probe()
2225 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_probe()
2226 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
2230 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_probe()
2233 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_probe()
2240 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev); in stm32f7_i2c_remove() local
2242 stm32f7_i2c_disable_smbus_host(i2c_dev); in stm32f7_i2c_remove()
2244 i2c_del_adapter(&i2c_dev->adap); in stm32f7_i2c_remove()
2245 pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_remove()
2247 if (i2c_dev->wakeup_src) { in stm32f7_i2c_remove()
2248 dev_pm_clear_wake_irq(i2c_dev->dev); in stm32f7_i2c_remove()
2253 device_init_wakeup(i2c_dev->dev, false); in stm32f7_i2c_remove()
2256 pm_runtime_put_noidle(i2c_dev->dev); in stm32f7_i2c_remove()
2257 pm_runtime_disable(i2c_dev->dev); in stm32f7_i2c_remove()
2258 pm_runtime_set_suspended(i2c_dev->dev); in stm32f7_i2c_remove()
2259 pm_runtime_dont_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_remove()
2261 if (i2c_dev->dma) { in stm32f7_i2c_remove()
2262 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_remove()
2263 i2c_dev->dma = NULL; in stm32f7_i2c_remove()
2266 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_remove()
2268 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_remove()
2275 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_runtime_suspend() local
2277 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_runtime_suspend()
2278 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_runtime_suspend()
2285 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_runtime_resume() local
2288 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { in stm32f7_i2c_runtime_resume()
2289 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_runtime_resume()
2300 static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_regs_backup() argument
2303 struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; in stm32f7_i2c_regs_backup()
2305 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_regs_backup()
2309 backup_regs->cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_backup()
2310 backup_regs->cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_regs_backup()
2311 backup_regs->oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_regs_backup()
2312 backup_regs->oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_regs_backup()
2313 backup_regs->tmgr = readl_relaxed(i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_regs_backup()
2314 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_regs_backup()
2316 pm_runtime_put_sync(i2c_dev->dev); in stm32f7_i2c_regs_backup()
2321 static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_regs_restore() argument
2325 struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; in stm32f7_i2c_regs_restore()
2327 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_regs_restore()
2331 cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_restore()
2333 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_regs_restore()
2336 writel_relaxed(backup_regs->tmgr, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_regs_restore()
2338 i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_restore()
2340 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_regs_restore()
2342 writel_relaxed(backup_regs->cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_regs_restore()
2343 writel_relaxed(backup_regs->oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_regs_restore()
2344 writel_relaxed(backup_regs->oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_regs_restore()
2345 stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); in stm32f7_i2c_regs_restore()
2347 pm_runtime_put_sync(i2c_dev->dev); in stm32f7_i2c_regs_restore()
2354 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_suspend() local
2357 i2c_mark_adapter_suspended(&i2c_dev->adap); in stm32f7_i2c_suspend()
2360 ret = stm32f7_i2c_regs_backup(i2c_dev); in stm32f7_i2c_suspend()
2362 i2c_mark_adapter_resumed(&i2c_dev->adap); in stm32f7_i2c_suspend()
2375 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_resume() local
2384 ret = stm32f7_i2c_regs_restore(i2c_dev); in stm32f7_i2c_resume()
2389 i2c_mark_adapter_resumed(&i2c_dev->adap); in stm32f7_i2c_resume()