Lines Matching refs:i2c_dev

365 static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask)  in stm32f7_i2c_disable_irq()  argument
367 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); in stm32f7_i2c_disable_irq()
370 static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_compute_timing() argument
392 dev_err(i2c_dev->dev, "speed out of bound {%d/%d}\n", in stm32f7_i2c_compute_timing()
399 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
407 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
414 dev_err(i2c_dev->dev, "ERROR: Freq {%d/%d}\n", in stm32f7_i2c_compute_timing()
441 dev_dbg(i2c_dev->dev, "SDADEL(min/max): %i/%i, SCLDEL(Min): %i\n", in stm32f7_i2c_compute_timing()
478 dev_err(i2c_dev->dev, "no Prescaler solution\n"); in stm32f7_i2c_compute_timing()
535 dev_err(i2c_dev->dev, "no solution at all\n"); in stm32f7_i2c_compute_timing()
546 dev_dbg(i2c_dev->dev, in stm32f7_i2c_compute_timing()
562 static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_setup_timing() argument
567 setup->speed = i2c_dev->speed; in stm32f7_i2c_setup_timing()
569 setup->clock_src = clk_get_rate(i2c_dev->clk); in stm32f7_i2c_setup_timing()
572 dev_err(i2c_dev->dev, "clock rate is 0\n"); in stm32f7_i2c_setup_timing()
577 ret = stm32f7_i2c_compute_timing(i2c_dev, setup, in stm32f7_i2c_setup_timing()
578 &i2c_dev->timing); in stm32f7_i2c_setup_timing()
580 dev_err(i2c_dev->dev, in stm32f7_i2c_setup_timing()
582 if (i2c_dev->speed > STM32_I2C_SPEED_STANDARD) { in stm32f7_i2c_setup_timing()
583 i2c_dev->speed--; in stm32f7_i2c_setup_timing()
584 setup->speed = i2c_dev->speed; in stm32f7_i2c_setup_timing()
587 dev_warn(i2c_dev->dev, in stm32f7_i2c_setup_timing()
597 dev_err(i2c_dev->dev, "Impossible to compute I2C timings.\n"); in stm32f7_i2c_setup_timing()
601 dev_dbg(i2c_dev->dev, "I2C Speed(%i), Freq(%i), Clk Source(%i)\n", in stm32f7_i2c_setup_timing()
603 dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n", in stm32f7_i2c_setup_timing()
605 dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n", in stm32f7_i2c_setup_timing()
611 static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_dma_req() argument
613 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_dma_req()
621 struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg; in stm32f7_i2c_dma_callback() local
622 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_dma_callback()
625 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_dma_callback()
630 static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_hw_config() argument
632 struct stm32f7_i2c_timings *t = &i2c_dev->timing; in stm32f7_i2c_hw_config()
641 writel_relaxed(timing, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_hw_config()
644 if (i2c_dev->setup.analog_filter) in stm32f7_i2c_hw_config()
645 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
648 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
652 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
654 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
655 STM32F7_I2C_CR1_DNF(i2c_dev->setup.dnf)); in stm32f7_i2c_hw_config()
657 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
661 static void stm32f7_i2c_write_tx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_write_tx_data() argument
663 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_write_tx_data()
664 void __iomem *base = i2c_dev->base; in stm32f7_i2c_write_tx_data()
672 static void stm32f7_i2c_read_rx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_read_rx_data() argument
674 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_read_rx_data()
675 void __iomem *base = i2c_dev->base; in stm32f7_i2c_read_rx_data()
686 static void stm32f7_i2c_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_reload() argument
688 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_reload()
691 if (i2c_dev->use_dma) in stm32f7_i2c_reload()
694 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
704 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
707 static void stm32f7_i2c_smbus_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_reload() argument
709 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_reload()
717 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_smbus_reload()
724 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
727 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
732 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_release_bus() local
734 dev_info(i2c_dev->dev, "Trying to recover bus\n"); in stm32f7_i2c_release_bus()
736 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_release_bus()
739 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_release_bus()
744 static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_wait_free_bus() argument
749 ret = readl_relaxed_poll_timeout(i2c_dev->base + STM32F7_I2C_ISR, in stm32f7_i2c_wait_free_bus()
756 dev_info(i2c_dev->dev, "bus busy\n"); in stm32f7_i2c_wait_free_bus()
758 ret = stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_wait_free_bus()
760 dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret); in stm32f7_i2c_wait_free_bus()
767 static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_xfer_msg() argument
770 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer_msg()
771 void __iomem *base = i2c_dev->base; in stm32f7_i2c_xfer_msg()
779 f7_msg->stop = (i2c_dev->msg_id >= i2c_dev->msg_num - 1); in stm32f7_i2c_xfer_msg()
781 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_xfer_msg()
820 i2c_dev->use_dma = false; in stm32f7_i2c_xfer_msg()
821 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_xfer_msg()
822 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_xfer_msg()
826 i2c_dev); in stm32f7_i2c_xfer_msg()
828 i2c_dev->use_dma = true; in stm32f7_i2c_xfer_msg()
830 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_xfer_msg()
833 if (!i2c_dev->use_dma) { in stm32f7_i2c_xfer_msg()
848 i2c_dev->master_mode = true; in stm32f7_i2c_xfer_msg()
855 static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_smbus_xfer_msg() argument
859 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer_msg()
860 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer_msg()
861 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_xfer_msg()
866 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_smbus_xfer_msg()
983 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_xfer_msg()
984 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_smbus_xfer_msg()
985 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_xfer_msg()
989 i2c_dev); in stm32f7_i2c_smbus_xfer_msg()
991 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_xfer_msg()
993 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_xfer_msg()
996 if (!i2c_dev->use_dma) { in stm32f7_i2c_smbus_xfer_msg()
1011 i2c_dev->master_mode = true; in stm32f7_i2c_smbus_xfer_msg()
1020 static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_rep_start() argument
1022 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_rep_start()
1023 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_rep_start()
1073 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_rep_start()
1074 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN && in stm32f7_i2c_smbus_rep_start()
1077 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_rep_start()
1081 i2c_dev); in stm32f7_i2c_smbus_rep_start()
1084 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_rep_start()
1086 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_rep_start()
1089 if (!i2c_dev->use_dma) in stm32f7_i2c_smbus_rep_start()
1102 static int stm32f7_i2c_smbus_check_pec(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_check_pec() argument
1104 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_check_pec()
1107 internal_pec = readl_relaxed(i2c_dev->base + STM32F7_I2C_PECR); in stm32f7_i2c_smbus_check_pec()
1124 dev_err(i2c_dev->dev, "Unsupported smbus protocol for PEC\n"); in stm32f7_i2c_smbus_check_pec()
1129 dev_err(i2c_dev->dev, "Bad PEC 0x%02x vs. 0x%02x\n", in stm32f7_i2c_smbus_check_pec()
1163 static void stm32f7_i2c_slave_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_start() argument
1165 struct i2c_client *slave = i2c_dev->slave_running; in stm32f7_i2c_slave_start()
1166 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_start()
1170 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_start()
1211 static void stm32f7_i2c_slave_addr(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_addr() argument
1213 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_addr()
1217 isr = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_addr()
1222 if (stm32f7_i2c_is_addr_match(i2c_dev->slave[i], addcode)) { in stm32f7_i2c_slave_addr()
1223 i2c_dev->slave_running = i2c_dev->slave[i]; in stm32f7_i2c_slave_addr()
1224 i2c_dev->slave_dir = dir; in stm32f7_i2c_slave_addr()
1227 stm32f7_i2c_slave_start(i2c_dev); in stm32f7_i2c_slave_addr()
1237 static int stm32f7_i2c_get_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_slave_id() argument
1243 if (i2c_dev->slave[i] == slave) { in stm32f7_i2c_get_slave_id()
1249 dev_err(i2c_dev->dev, "Slave 0x%x not registered\n", slave->addr); in stm32f7_i2c_get_slave_id()
1254 static int stm32f7_i2c_get_free_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_free_slave_id() argument
1257 struct device *dev = i2c_dev->dev; in stm32f7_i2c_get_free_slave_id()
1267 if (!i2c_dev->slave[i]) { in stm32f7_i2c_get_free_slave_id()
1278 static bool stm32f7_i2c_is_slave_registered(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_registered() argument
1283 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_registered()
1290 static bool stm32f7_i2c_is_slave_busy(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_busy() argument
1296 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_busy()
1303 static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_isr_event() argument
1305 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_isr_event()
1310 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_isr_event()
1314 i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1328 val = readb_relaxed(i2c_dev->base + STM32F7_I2C_RXDR); in stm32f7_i2c_slave_isr_event()
1329 ret = i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1333 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1335 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1344 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); in stm32f7_i2c_slave_isr_event()
1351 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_XFER_IRQ_MASK); in stm32f7_i2c_slave_isr_event()
1353 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_isr_event()
1366 i2c_slave_event(i2c_dev->slave_running, I2C_SLAVE_STOP, &val); in stm32f7_i2c_slave_isr_event()
1368 i2c_dev->slave_running = NULL; in stm32f7_i2c_slave_isr_event()
1373 stm32f7_i2c_slave_addr(i2c_dev); in stm32f7_i2c_slave_isr_event()
1380 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event() local
1381 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event()
1382 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event()
1383 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_event()
1388 if (!i2c_dev->master_mode) { in stm32f7_i2c_isr_event()
1389 ret = stm32f7_i2c_slave_isr_event(i2c_dev); in stm32f7_i2c_isr_event()
1393 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event()
1397 stm32f7_i2c_write_tx_data(i2c_dev); in stm32f7_i2c_isr_event()
1401 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_isr_event()
1405 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); in stm32f7_i2c_isr_event()
1407 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_event()
1408 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event()
1417 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_event()
1421 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_event()
1426 if (i2c_dev->use_dma && !f7_msg->result) { in stm32f7_i2c_isr_event()
1429 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event()
1430 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event()
1439 } else if (i2c_dev->use_dma && !f7_msg->result) { in stm32f7_i2c_isr_event()
1442 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event()
1444 i2c_dev->msg_id++; in stm32f7_i2c_isr_event()
1445 i2c_dev->msg++; in stm32f7_i2c_isr_event()
1446 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event()
1452 stm32f7_i2c_smbus_reload(i2c_dev); in stm32f7_i2c_isr_event()
1454 stm32f7_i2c_reload(i2c_dev); in stm32f7_i2c_isr_event()
1462 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event_thread() local
1463 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event_thread()
1464 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event_thread()
1472 ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ); in stm32f7_i2c_isr_event_thread()
1474 dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__); in stm32f7_i2c_isr_event_thread()
1475 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event_thread()
1480 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event_thread()
1484 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event_thread()
1486 i2c_dev->msg_id++; in stm32f7_i2c_isr_event_thread()
1487 i2c_dev->msg++; in stm32f7_i2c_isr_event_thread()
1488 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event_thread()
1491 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event_thread()
1492 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event_thread()
1500 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_error() local
1501 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_error()
1502 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_error()
1503 struct device *dev = i2c_dev->dev; in stm32f7_i2c_isr_error()
1504 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_error()
1507 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_error()
1513 stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_isr_error()
1530 if (!i2c_dev->slave_running) { in stm32f7_i2c_isr_error()
1533 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_error()
1537 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_error()
1541 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_error()
1542 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_error()
1546 i2c_dev->master_mode = false; in stm32f7_i2c_isr_error()
1547 complete(&i2c_dev->complete); in stm32f7_i2c_isr_error()
1555 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_xfer() local
1556 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer()
1557 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_xfer()
1561 i2c_dev->msg = msgs; in stm32f7_i2c_xfer()
1562 i2c_dev->msg_num = num; in stm32f7_i2c_xfer()
1563 i2c_dev->msg_id = 0; in stm32f7_i2c_xfer()
1566 ret = clk_enable(i2c_dev->clk); in stm32f7_i2c_xfer()
1568 dev_err(i2c_dev->dev, "Failed to enable clock\n"); in stm32f7_i2c_xfer()
1572 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1576 stm32f7_i2c_xfer_msg(i2c_dev, msgs); in stm32f7_i2c_xfer()
1578 time_left = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_xfer()
1579 i2c_dev->adap.timeout); in stm32f7_i2c_xfer()
1583 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n", in stm32f7_i2c_xfer()
1584 i2c_dev->msg->addr); in stm32f7_i2c_xfer()
1585 if (i2c_dev->use_dma) in stm32f7_i2c_xfer()
1587 stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1592 clk_disable(i2c_dev->clk); in stm32f7_i2c_xfer()
1602 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adapter); in stm32f7_i2c_smbus_xfer() local
1603 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer()
1604 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_smbus_xfer()
1605 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer()
1614 ret = clk_enable(i2c_dev->clk); in stm32f7_i2c_smbus_xfer()
1616 dev_err(i2c_dev->dev, "Failed to enable clock\n"); in stm32f7_i2c_smbus_xfer()
1620 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1624 ret = stm32f7_i2c_smbus_xfer_msg(i2c_dev, flags, command, data); in stm32f7_i2c_smbus_xfer()
1628 timeout = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_smbus_xfer()
1629 i2c_dev->adap.timeout); in stm32f7_i2c_smbus_xfer()
1636 if (i2c_dev->use_dma) in stm32f7_i2c_smbus_xfer()
1638 stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1645 ret = stm32f7_i2c_smbus_check_pec(i2c_dev); in stm32f7_i2c_smbus_xfer()
1673 clk_disable(i2c_dev->clk); in stm32f7_i2c_smbus_xfer()
1679 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_reg_slave() local
1680 void __iomem *base = i2c_dev->base; in stm32f7_i2c_reg_slave()
1681 struct device *dev = i2c_dev->dev; in stm32f7_i2c_reg_slave()
1690 if (stm32f7_i2c_is_slave_busy(i2c_dev)) { in stm32f7_i2c_reg_slave()
1695 ret = stm32f7_i2c_get_free_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_reg_slave()
1699 if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) { in stm32f7_i2c_reg_slave()
1700 ret = clk_enable(i2c_dev->clk); in stm32f7_i2c_reg_slave()
1709 oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1718 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1719 writel_relaxed(oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1722 oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1731 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1732 writel_relaxed(oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1749 if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) in stm32f7_i2c_reg_slave()
1750 clk_disable(i2c_dev->clk); in stm32f7_i2c_reg_slave()
1757 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_unreg_slave() local
1758 void __iomem *base = i2c_dev->base; in stm32f7_i2c_unreg_slave()
1762 ret = stm32f7_i2c_get_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_unreg_slave()
1766 WARN_ON(!i2c_dev->slave[id]); in stm32f7_i2c_unreg_slave()
1776 i2c_dev->slave[id] = NULL; in stm32f7_i2c_unreg_slave()
1778 if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) { in stm32f7_i2c_unreg_slave()
1779 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); in stm32f7_i2c_unreg_slave()
1780 clk_disable(i2c_dev->clk); in stm32f7_i2c_unreg_slave()
1805 struct stm32f7_i2c_dev *i2c_dev; in stm32f7_i2c_probe() local
1814 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); in stm32f7_i2c_probe()
1815 if (!i2c_dev) in stm32f7_i2c_probe()
1819 i2c_dev->base = devm_ioremap_resource(&pdev->dev, res); in stm32f7_i2c_probe()
1820 if (IS_ERR(i2c_dev->base)) in stm32f7_i2c_probe()
1821 return PTR_ERR(i2c_dev->base); in stm32f7_i2c_probe()
1840 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); in stm32f7_i2c_probe()
1841 if (IS_ERR(i2c_dev->clk)) { in stm32f7_i2c_probe()
1843 return PTR_ERR(i2c_dev->clk); in stm32f7_i2c_probe()
1845 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_probe()
1851 i2c_dev->speed = STM32_I2C_SPEED_STANDARD; in stm32f7_i2c_probe()
1855 i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS; in stm32f7_i2c_probe()
1857 i2c_dev->speed = STM32_I2C_SPEED_FAST; in stm32f7_i2c_probe()
1859 i2c_dev->speed = STM32_I2C_SPEED_STANDARD; in stm32f7_i2c_probe()
1871 i2c_dev->dev = &pdev->dev; in stm32f7_i2c_probe()
1877 pdev->name, i2c_dev); in stm32f7_i2c_probe()
1885 pdev->name, i2c_dev); in stm32f7_i2c_probe()
1898 i2c_dev->setup = *setup; in stm32f7_i2c_probe()
1900 ret = device_property_read_u32(i2c_dev->dev, "i2c-scl-rising-time-ns", in stm32f7_i2c_probe()
1903 i2c_dev->setup.rise_time = rise_time; in stm32f7_i2c_probe()
1905 ret = device_property_read_u32(i2c_dev->dev, "i2c-scl-falling-time-ns", in stm32f7_i2c_probe()
1908 i2c_dev->setup.fall_time = fall_time; in stm32f7_i2c_probe()
1910 ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup); in stm32f7_i2c_probe()
1914 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_probe()
1916 adap = &i2c_dev->adap; in stm32f7_i2c_probe()
1917 i2c_set_adapdata(adap, i2c_dev); in stm32f7_i2c_probe()
1927 init_completion(&i2c_dev->complete); in stm32f7_i2c_probe()
1930 i2c_dev->dma = stm32_i2c_dma_request(i2c_dev->dev, phy_addr, in stm32f7_i2c_probe()
1933 if (PTR_ERR(i2c_dev->dma) == -ENODEV) in stm32f7_i2c_probe()
1934 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
1935 else if (IS_ERR(i2c_dev->dma)) { in stm32f7_i2c_probe()
1936 ret = PTR_ERR(i2c_dev->dma); in stm32f7_i2c_probe()
1947 platform_set_drvdata(pdev, i2c_dev); in stm32f7_i2c_probe()
1949 clk_disable(i2c_dev->clk); in stm32f7_i2c_probe()
1951 dev_info(i2c_dev->dev, "STM32F7 I2C-%d bus adapter\n", adap->nr); in stm32f7_i2c_probe()
1956 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_probe()
1963 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev); in stm32f7_i2c_remove() local
1965 if (i2c_dev->dma) { in stm32f7_i2c_remove()
1966 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_remove()
1967 i2c_dev->dma = NULL; in stm32f7_i2c_remove()
1970 i2c_del_adapter(&i2c_dev->adap); in stm32f7_i2c_remove()
1972 clk_unprepare(i2c_dev->clk); in stm32f7_i2c_remove()