Lines Matching refs:i2c_dev

429 static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask)  in stm32f7_i2c_disable_irq()  argument
431 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); in stm32f7_i2c_disable_irq()
446 static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_compute_timing() argument
470 dev_err(i2c_dev->dev, "speed out of bound {%d}\n", in stm32f7_i2c_compute_timing()
477 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
484 i2c_dev->dnf = DIV_ROUND_CLOSEST(i2c_dev->dnf_dt, i2cclk); in stm32f7_i2c_compute_timing()
485 if (i2c_dev->dnf > STM32F7_I2C_DNF_MAX) { in stm32f7_i2c_compute_timing()
486 dev_err(i2c_dev->dev, in stm32f7_i2c_compute_timing()
488 i2c_dev->dnf * i2cclk, STM32F7_I2C_DNF_MAX * i2cclk); in stm32f7_i2c_compute_timing()
494 (i2c_dev->analog_filter ? in stm32f7_i2c_compute_timing()
497 (i2c_dev->analog_filter ? in stm32f7_i2c_compute_timing()
499 dnf_delay = i2c_dev->dnf * i2cclk; in stm32f7_i2c_compute_timing()
502 af_delay_min - (i2c_dev->dnf + 3) * i2cclk; in stm32f7_i2c_compute_timing()
505 af_delay_max - (i2c_dev->dnf + 4) * i2cclk; in stm32f7_i2c_compute_timing()
514 dev_dbg(i2c_dev->dev, "SDADEL(min/max): %i/%i, SCLDEL(Min): %i\n", in stm32f7_i2c_compute_timing()
555 dev_err(i2c_dev->dev, "no Prescaler solution\n"); in stm32f7_i2c_compute_timing()
612 dev_err(i2c_dev->dev, "no solution at all\n"); in stm32f7_i2c_compute_timing()
623 dev_dbg(i2c_dev->dev, in stm32f7_i2c_compute_timing()
650 static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_setup_timing() argument
657 t->scl_rise_ns = i2c_dev->setup.rise_time; in stm32f7_i2c_setup_timing()
658 t->scl_fall_ns = i2c_dev->setup.fall_time; in stm32f7_i2c_setup_timing()
660 i2c_parse_fw_timings(i2c_dev->dev, t, false); in stm32f7_i2c_setup_timing()
663 dev_err(i2c_dev->dev, "Invalid bus speed (%i>%i)\n", in stm32f7_i2c_setup_timing()
669 i2c_dev->setup.rise_time = t->scl_rise_ns; in stm32f7_i2c_setup_timing()
670 i2c_dev->setup.fall_time = t->scl_fall_ns; in stm32f7_i2c_setup_timing()
671 i2c_dev->dnf_dt = t->digital_filter_width_ns; in stm32f7_i2c_setup_timing()
672 setup->clock_src = clk_get_rate(i2c_dev->clk); in stm32f7_i2c_setup_timing()
675 dev_err(i2c_dev->dev, "clock rate is 0\n"); in stm32f7_i2c_setup_timing()
679 if (!of_property_read_bool(i2c_dev->dev->of_node, "i2c-digital-filter")) in stm32f7_i2c_setup_timing()
680 i2c_dev->dnf_dt = STM32F7_I2C_DNF_DEFAULT; in stm32f7_i2c_setup_timing()
683 ret = stm32f7_i2c_compute_timing(i2c_dev, setup, in stm32f7_i2c_setup_timing()
684 &i2c_dev->timing); in stm32f7_i2c_setup_timing()
686 dev_err(i2c_dev->dev, in stm32f7_i2c_setup_timing()
692 dev_warn(i2c_dev->dev, in stm32f7_i2c_setup_timing()
699 dev_err(i2c_dev->dev, "Impossible to compute I2C timings.\n"); in stm32f7_i2c_setup_timing()
703 i2c_dev->analog_filter = of_property_read_bool(i2c_dev->dev->of_node, in stm32f7_i2c_setup_timing()
706 dev_dbg(i2c_dev->dev, "I2C Speed(%i), Clk Source(%i)\n", in stm32f7_i2c_setup_timing()
708 dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n", in stm32f7_i2c_setup_timing()
710 dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n", in stm32f7_i2c_setup_timing()
711 (i2c_dev->analog_filter ? "On" : "Off"), i2c_dev->dnf); in stm32f7_i2c_setup_timing()
713 i2c_dev->bus_rate = setup->speed_freq; in stm32f7_i2c_setup_timing()
718 static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_dma_req() argument
720 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_dma_req()
728 struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg; in stm32f7_i2c_dma_callback() local
729 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_dma_callback()
732 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_dma_callback()
737 static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_hw_config() argument
739 struct stm32f7_i2c_timings *t = &i2c_dev->timing; in stm32f7_i2c_hw_config()
748 writel_relaxed(timing, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_hw_config()
751 if (i2c_dev->analog_filter) in stm32f7_i2c_hw_config()
752 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
755 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
759 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
761 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
762 STM32F7_I2C_CR1_DNF(i2c_dev->dnf)); in stm32f7_i2c_hw_config()
764 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_hw_config()
768 static void stm32f7_i2c_write_tx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_write_tx_data() argument
770 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_write_tx_data()
771 void __iomem *base = i2c_dev->base; in stm32f7_i2c_write_tx_data()
779 static void stm32f7_i2c_read_rx_data(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_read_rx_data() argument
781 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_read_rx_data()
782 void __iomem *base = i2c_dev->base; in stm32f7_i2c_read_rx_data()
793 static void stm32f7_i2c_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_reload() argument
795 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_reload()
798 if (i2c_dev->use_dma) in stm32f7_i2c_reload()
801 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
811 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_reload()
814 static void stm32f7_i2c_smbus_reload(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_reload() argument
816 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_reload()
824 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_smbus_reload()
831 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
834 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_smbus_reload()
839 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_release_bus() local
841 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_release_bus()
844 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_release_bus()
847 static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_wait_free_bus() argument
852 ret = readl_relaxed_poll_timeout(i2c_dev->base + STM32F7_I2C_ISR, in stm32f7_i2c_wait_free_bus()
859 stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_wait_free_bus()
864 static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_xfer_msg() argument
867 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer_msg()
868 void __iomem *base = i2c_dev->base; in stm32f7_i2c_xfer_msg()
876 f7_msg->stop = (i2c_dev->msg_id >= i2c_dev->msg_num - 1); in stm32f7_i2c_xfer_msg()
878 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_xfer_msg()
917 i2c_dev->use_dma = false; in stm32f7_i2c_xfer_msg()
918 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_xfer_msg()
919 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_xfer_msg()
923 i2c_dev); in stm32f7_i2c_xfer_msg()
925 i2c_dev->use_dma = true; in stm32f7_i2c_xfer_msg()
927 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_xfer_msg()
930 if (!i2c_dev->use_dma) { in stm32f7_i2c_xfer_msg()
945 i2c_dev->master_mode = true; in stm32f7_i2c_xfer_msg()
952 static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_smbus_xfer_msg() argument
956 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer_msg()
957 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer_msg()
958 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_xfer_msg()
963 reinit_completion(&i2c_dev->complete); in stm32f7_i2c_smbus_xfer_msg()
1083 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_xfer_msg()
1084 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { in stm32f7_i2c_smbus_xfer_msg()
1085 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_xfer_msg()
1089 i2c_dev); in stm32f7_i2c_smbus_xfer_msg()
1091 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_xfer_msg()
1093 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_xfer_msg()
1096 if (!i2c_dev->use_dma) { in stm32f7_i2c_smbus_xfer_msg()
1111 i2c_dev->master_mode = true; in stm32f7_i2c_smbus_xfer_msg()
1120 static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_rep_start() argument
1122 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_rep_start()
1123 void __iomem *base = i2c_dev->base; in stm32f7_i2c_smbus_rep_start()
1173 i2c_dev->use_dma = false; in stm32f7_i2c_smbus_rep_start()
1174 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN && in stm32f7_i2c_smbus_rep_start()
1177 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, in stm32f7_i2c_smbus_rep_start()
1181 i2c_dev); in stm32f7_i2c_smbus_rep_start()
1184 i2c_dev->use_dma = true; in stm32f7_i2c_smbus_rep_start()
1186 dev_warn(i2c_dev->dev, "can't use DMA\n"); in stm32f7_i2c_smbus_rep_start()
1189 if (!i2c_dev->use_dma) in stm32f7_i2c_smbus_rep_start()
1202 static int stm32f7_i2c_smbus_check_pec(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_smbus_check_pec() argument
1204 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_check_pec()
1207 internal_pec = readl_relaxed(i2c_dev->base + STM32F7_I2C_PECR); in stm32f7_i2c_smbus_check_pec()
1224 dev_err(i2c_dev->dev, "Unsupported smbus protocol for PEC\n"); in stm32f7_i2c_smbus_check_pec()
1229 dev_err(i2c_dev->dev, "Bad PEC 0x%02x vs. 0x%02x\n", in stm32f7_i2c_smbus_check_pec()
1263 static void stm32f7_i2c_slave_start(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_start() argument
1265 struct i2c_client *slave = i2c_dev->slave_running; in stm32f7_i2c_slave_start()
1266 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_start()
1270 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_start()
1311 static void stm32f7_i2c_slave_addr(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_addr() argument
1313 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_addr()
1317 isr = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_addr()
1322 if (stm32f7_i2c_is_addr_match(i2c_dev->slave[i], addcode)) { in stm32f7_i2c_slave_addr()
1323 i2c_dev->slave_running = i2c_dev->slave[i]; in stm32f7_i2c_slave_addr()
1324 i2c_dev->slave_dir = dir; in stm32f7_i2c_slave_addr()
1327 stm32f7_i2c_slave_start(i2c_dev); in stm32f7_i2c_slave_addr()
1337 static int stm32f7_i2c_get_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_slave_id() argument
1343 if (i2c_dev->slave[i] == slave) { in stm32f7_i2c_get_slave_id()
1349 dev_err(i2c_dev->dev, "Slave 0x%x not registered\n", slave->addr); in stm32f7_i2c_get_slave_id()
1354 static int stm32f7_i2c_get_free_slave_id(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_get_free_slave_id() argument
1357 struct device *dev = i2c_dev->dev; in stm32f7_i2c_get_free_slave_id()
1365 if (i2c_dev->smbus_mode && (slave->addr == 0x08)) { in stm32f7_i2c_get_free_slave_id()
1366 if (i2c_dev->slave[STM32F7_SLAVE_HOSTNOTIFY]) in stm32f7_i2c_get_free_slave_id()
1376 if (!i2c_dev->slave[i]) { in stm32f7_i2c_get_free_slave_id()
1388 static bool stm32f7_i2c_is_slave_registered(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_registered() argument
1393 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_registered()
1400 static bool stm32f7_i2c_is_slave_busy(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_is_slave_busy() argument
1406 if (i2c_dev->slave[i]) in stm32f7_i2c_is_slave_busy()
1413 static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_slave_isr_event() argument
1415 void __iomem *base = i2c_dev->base; in stm32f7_i2c_slave_isr_event()
1420 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_slave_isr_event()
1424 i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1438 val = readb_relaxed(i2c_dev->base + STM32F7_I2C_RXDR); in stm32f7_i2c_slave_isr_event()
1439 ret = i2c_slave_event(i2c_dev->slave_running, in stm32f7_i2c_slave_isr_event()
1443 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1445 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_slave_isr_event()
1454 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); in stm32f7_i2c_slave_isr_event()
1461 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_XFER_IRQ_MASK); in stm32f7_i2c_slave_isr_event()
1463 if (i2c_dev->slave_dir) { in stm32f7_i2c_slave_isr_event()
1476 i2c_slave_event(i2c_dev->slave_running, I2C_SLAVE_STOP, &val); in stm32f7_i2c_slave_isr_event()
1478 i2c_dev->slave_running = NULL; in stm32f7_i2c_slave_isr_event()
1483 stm32f7_i2c_slave_addr(i2c_dev); in stm32f7_i2c_slave_isr_event()
1490 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event() local
1491 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event()
1492 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event()
1493 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_event()
1498 if (!i2c_dev->master_mode) { in stm32f7_i2c_isr_event()
1499 ret = stm32f7_i2c_slave_isr_event(i2c_dev); in stm32f7_i2c_isr_event()
1503 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event()
1507 stm32f7_i2c_write_tx_data(i2c_dev); in stm32f7_i2c_isr_event()
1511 stm32f7_i2c_read_rx_data(i2c_dev); in stm32f7_i2c_isr_event()
1515 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK (addr %x)\n", in stm32f7_i2c_isr_event()
1518 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_event()
1519 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event()
1528 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_event()
1532 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_event()
1537 if (i2c_dev->use_dma && !f7_msg->result) { in stm32f7_i2c_isr_event()
1540 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event()
1541 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event()
1550 } else if (i2c_dev->use_dma && !f7_msg->result) { in stm32f7_i2c_isr_event()
1553 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event()
1555 i2c_dev->msg_id++; in stm32f7_i2c_isr_event()
1556 i2c_dev->msg++; in stm32f7_i2c_isr_event()
1557 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event()
1563 stm32f7_i2c_smbus_reload(i2c_dev); in stm32f7_i2c_isr_event()
1565 stm32f7_i2c_reload(i2c_dev); in stm32f7_i2c_isr_event()
1573 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_event_thread() local
1574 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_event_thread()
1575 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_event_thread()
1583 ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ); in stm32f7_i2c_isr_event_thread()
1585 dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__); in stm32f7_i2c_isr_event_thread()
1586 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_event_thread()
1591 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_event_thread()
1595 stm32f7_i2c_smbus_rep_start(i2c_dev); in stm32f7_i2c_isr_event_thread()
1597 i2c_dev->msg_id++; in stm32f7_i2c_isr_event_thread()
1598 i2c_dev->msg++; in stm32f7_i2c_isr_event_thread()
1599 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); in stm32f7_i2c_isr_event_thread()
1602 i2c_dev->master_mode = false; in stm32f7_i2c_isr_event_thread()
1603 complete(&i2c_dev->complete); in stm32f7_i2c_isr_event_thread()
1611 struct stm32f7_i2c_dev *i2c_dev = data; in stm32f7_i2c_isr_error() local
1612 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_isr_error()
1613 void __iomem *base = i2c_dev->base; in stm32f7_i2c_isr_error()
1614 struct device *dev = i2c_dev->dev; in stm32f7_i2c_isr_error()
1615 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_isr_error()
1618 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_isr_error()
1625 stm32f7_i2c_release_bus(&i2c_dev->adap); in stm32f7_i2c_isr_error()
1647 i2c_handle_smbus_alert(i2c_dev->alert->ara); in stm32f7_i2c_isr_error()
1651 if (!i2c_dev->slave_running) { in stm32f7_i2c_isr_error()
1654 if (stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_isr_error()
1658 stm32f7_i2c_disable_irq(i2c_dev, mask); in stm32f7_i2c_isr_error()
1662 if (i2c_dev->use_dma) { in stm32f7_i2c_isr_error()
1663 stm32f7_i2c_disable_dma_req(i2c_dev); in stm32f7_i2c_isr_error()
1667 i2c_dev->master_mode = false; in stm32f7_i2c_isr_error()
1668 complete(&i2c_dev->complete); in stm32f7_i2c_isr_error()
1676 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); in stm32f7_i2c_xfer() local
1677 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_xfer()
1678 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_xfer()
1682 i2c_dev->msg = msgs; in stm32f7_i2c_xfer()
1683 i2c_dev->msg_num = num; in stm32f7_i2c_xfer()
1684 i2c_dev->msg_id = 0; in stm32f7_i2c_xfer()
1687 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_xfer()
1691 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1695 stm32f7_i2c_xfer_msg(i2c_dev, msgs); in stm32f7_i2c_xfer()
1697 time_left = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_xfer()
1698 i2c_dev->adap.timeout); in stm32f7_i2c_xfer()
1701 if (i2c_dev->use_dma) in stm32f7_i2c_xfer()
1710 i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_xfer()
1715 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n", in stm32f7_i2c_xfer()
1716 i2c_dev->msg->addr); in stm32f7_i2c_xfer()
1717 if (i2c_dev->use_dma) in stm32f7_i2c_xfer()
1719 stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_xfer()
1724 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_xfer()
1725 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_xfer()
1735 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adapter); in stm32f7_i2c_smbus_xfer() local
1736 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; in stm32f7_i2c_smbus_xfer()
1737 struct stm32_i2c_dma *dma = i2c_dev->dma; in stm32f7_i2c_smbus_xfer()
1738 struct device *dev = i2c_dev->dev; in stm32f7_i2c_smbus_xfer()
1751 ret = stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1755 ret = stm32f7_i2c_smbus_xfer_msg(i2c_dev, flags, command, data); in stm32f7_i2c_smbus_xfer()
1759 timeout = wait_for_completion_timeout(&i2c_dev->complete, in stm32f7_i2c_smbus_xfer()
1760 i2c_dev->adap.timeout); in stm32f7_i2c_smbus_xfer()
1763 if (i2c_dev->use_dma) in stm32f7_i2c_smbus_xfer()
1772 i2c_dev->base + STM32F7_I2C_ISR); in stm32f7_i2c_smbus_xfer()
1778 if (i2c_dev->use_dma) in stm32f7_i2c_smbus_xfer()
1780 stm32f7_i2c_wait_free_bus(i2c_dev); in stm32f7_i2c_smbus_xfer()
1787 ret = stm32f7_i2c_smbus_check_pec(i2c_dev); in stm32f7_i2c_smbus_xfer()
1820 static void stm32f7_i2c_enable_wakeup(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_enable_wakeup() argument
1823 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_wakeup()
1826 if (!i2c_dev->wakeup_src) in stm32f7_i2c_enable_wakeup()
1830 device_set_wakeup_enable(i2c_dev->dev, true); in stm32f7_i2c_enable_wakeup()
1833 device_set_wakeup_enable(i2c_dev->dev, false); in stm32f7_i2c_enable_wakeup()
1840 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_reg_slave() local
1841 void __iomem *base = i2c_dev->base; in stm32f7_i2c_reg_slave()
1842 struct device *dev = i2c_dev->dev; in stm32f7_i2c_reg_slave()
1851 if (stm32f7_i2c_is_slave_busy(i2c_dev)) { in stm32f7_i2c_reg_slave()
1856 ret = stm32f7_i2c_get_free_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_reg_slave()
1864 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_reg_slave()
1865 stm32f7_i2c_enable_wakeup(i2c_dev, true); in stm32f7_i2c_reg_slave()
1870 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1875 oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1884 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1885 writel_relaxed(oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_reg_slave()
1890 oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1899 i2c_dev->slave[id] = slave; in stm32f7_i2c_reg_slave()
1900 writel_relaxed(oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_reg_slave()
1919 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_reg_slave()
1920 stm32f7_i2c_enable_wakeup(i2c_dev, false); in stm32f7_i2c_reg_slave()
1930 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); in stm32f7_i2c_unreg_slave() local
1931 void __iomem *base = i2c_dev->base; in stm32f7_i2c_unreg_slave()
1935 ret = stm32f7_i2c_get_slave_id(i2c_dev, slave, &id); in stm32f7_i2c_unreg_slave()
1939 WARN_ON(!i2c_dev->slave[id]); in stm32f7_i2c_unreg_slave()
1941 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1953 i2c_dev->slave[id] = NULL; in stm32f7_i2c_unreg_slave()
1955 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { in stm32f7_i2c_unreg_slave()
1956 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); in stm32f7_i2c_unreg_slave()
1957 stm32f7_i2c_enable_wakeup(i2c_dev, false); in stm32f7_i2c_unreg_slave()
1960 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1961 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_unreg_slave()
1966 static int stm32f7_i2c_write_fm_plus_bits(struct stm32f7_i2c_dev *i2c_dev, in stm32f7_i2c_write_fm_plus_bits() argument
1971 if (i2c_dev->bus_rate <= I2C_MAX_FAST_MODE_FREQ || in stm32f7_i2c_write_fm_plus_bits()
1972 IS_ERR_OR_NULL(i2c_dev->regmap)) in stm32f7_i2c_write_fm_plus_bits()
1976 if (i2c_dev->fmp_sreg == i2c_dev->fmp_creg) in stm32f7_i2c_write_fm_plus_bits()
1977 ret = regmap_update_bits(i2c_dev->regmap, in stm32f7_i2c_write_fm_plus_bits()
1978 i2c_dev->fmp_sreg, in stm32f7_i2c_write_fm_plus_bits()
1979 i2c_dev->fmp_mask, in stm32f7_i2c_write_fm_plus_bits()
1980 enable ? i2c_dev->fmp_mask : 0); in stm32f7_i2c_write_fm_plus_bits()
1982 ret = regmap_write(i2c_dev->regmap, in stm32f7_i2c_write_fm_plus_bits()
1983 enable ? i2c_dev->fmp_sreg : in stm32f7_i2c_write_fm_plus_bits()
1984 i2c_dev->fmp_creg, in stm32f7_i2c_write_fm_plus_bits()
1985 i2c_dev->fmp_mask); in stm32f7_i2c_write_fm_plus_bits()
1991 struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_setup_fm_plus_bits() argument
1996 i2c_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg-fmp"); in stm32f7_i2c_setup_fm_plus_bits()
1997 if (IS_ERR(i2c_dev->regmap)) in stm32f7_i2c_setup_fm_plus_bits()
2002 &i2c_dev->fmp_sreg); in stm32f7_i2c_setup_fm_plus_bits()
2006 i2c_dev->fmp_creg = i2c_dev->fmp_sreg + in stm32f7_i2c_setup_fm_plus_bits()
2007 i2c_dev->setup.fmp_clr_offset; in stm32f7_i2c_setup_fm_plus_bits()
2010 &i2c_dev->fmp_mask); in stm32f7_i2c_setup_fm_plus_bits()
2013 static int stm32f7_i2c_enable_smbus_host(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_enable_smbus_host() argument
2015 struct i2c_adapter *adap = &i2c_dev->adap; in stm32f7_i2c_enable_smbus_host()
2016 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_smbus_host()
2023 i2c_dev->host_notify_client = client; in stm32f7_i2c_enable_smbus_host()
2031 static void stm32f7_i2c_disable_smbus_host(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_smbus_host() argument
2033 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_smbus_host()
2035 if (i2c_dev->host_notify_client) { in stm32f7_i2c_disable_smbus_host()
2039 i2c_free_slave_host_notify_device(i2c_dev->host_notify_client); in stm32f7_i2c_disable_smbus_host()
2043 static int stm32f7_i2c_enable_smbus_alert(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_enable_smbus_alert() argument
2046 struct i2c_adapter *adap = &i2c_dev->adap; in stm32f7_i2c_enable_smbus_alert()
2047 struct device *dev = i2c_dev->dev; in stm32f7_i2c_enable_smbus_alert()
2048 void __iomem *base = i2c_dev->base; in stm32f7_i2c_enable_smbus_alert()
2058 i2c_dev->alert = alert; in stm32f7_i2c_enable_smbus_alert()
2066 static void stm32f7_i2c_disable_smbus_alert(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_disable_smbus_alert() argument
2068 struct stm32f7_i2c_alert *alert = i2c_dev->alert; in stm32f7_i2c_disable_smbus_alert()
2069 void __iomem *base = i2c_dev->base; in stm32f7_i2c_disable_smbus_alert()
2081 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adap); in stm32f7_i2c_func() local
2090 if (i2c_dev->smbus_mode) in stm32f7_i2c_func()
2106 struct stm32f7_i2c_dev *i2c_dev; in stm32f7_i2c_probe() local
2114 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); in stm32f7_i2c_probe()
2115 if (!i2c_dev) in stm32f7_i2c_probe()
2118 i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in stm32f7_i2c_probe()
2119 if (IS_ERR(i2c_dev->base)) in stm32f7_i2c_probe()
2120 return PTR_ERR(i2c_dev->base); in stm32f7_i2c_probe()
2131 i2c_dev->wakeup_src = of_property_read_bool(pdev->dev.of_node, in stm32f7_i2c_probe()
2134 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); in stm32f7_i2c_probe()
2135 if (IS_ERR(i2c_dev->clk)) in stm32f7_i2c_probe()
2136 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->clk), in stm32f7_i2c_probe()
2139 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_probe()
2155 i2c_dev->dev = &pdev->dev; in stm32f7_i2c_probe()
2161 pdev->name, i2c_dev); in stm32f7_i2c_probe()
2169 pdev->name, i2c_dev); in stm32f7_i2c_probe()
2182 i2c_dev->setup = *setup; in stm32f7_i2c_probe()
2184 ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup); in stm32f7_i2c_probe()
2189 if (i2c_dev->bus_rate > I2C_MAX_FAST_MODE_FREQ) { in stm32f7_i2c_probe()
2190 ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev); in stm32f7_i2c_probe()
2193 ret = stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); in stm32f7_i2c_probe()
2198 adap = &i2c_dev->adap; in stm32f7_i2c_probe()
2199 i2c_set_adapdata(adap, i2c_dev); in stm32f7_i2c_probe()
2209 init_completion(&i2c_dev->complete); in stm32f7_i2c_probe()
2212 i2c_dev->dma = stm32_i2c_dma_request(i2c_dev->dev, phy_addr, in stm32f7_i2c_probe()
2215 if (IS_ERR(i2c_dev->dma)) { in stm32f7_i2c_probe()
2216 ret = PTR_ERR(i2c_dev->dma); in stm32f7_i2c_probe()
2220 dev_dbg(i2c_dev->dev, "No DMA option: fallback using interrupts\n"); in stm32f7_i2c_probe()
2221 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
2224 if (i2c_dev->wakeup_src) { in stm32f7_i2c_probe()
2225 device_set_wakeup_capable(i2c_dev->dev, true); in stm32f7_i2c_probe()
2227 ret = dev_pm_set_wake_irq(i2c_dev->dev, irq_event); in stm32f7_i2c_probe()
2229 dev_err(i2c_dev->dev, "Failed to set wake up irq\n"); in stm32f7_i2c_probe()
2234 platform_set_drvdata(pdev, i2c_dev); in stm32f7_i2c_probe()
2236 pm_runtime_set_autosuspend_delay(i2c_dev->dev, in stm32f7_i2c_probe()
2238 pm_runtime_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2239 pm_runtime_set_active(i2c_dev->dev); in stm32f7_i2c_probe()
2240 pm_runtime_enable(i2c_dev->dev); in stm32f7_i2c_probe()
2244 stm32f7_i2c_hw_config(i2c_dev); in stm32f7_i2c_probe()
2246 i2c_dev->smbus_mode = of_property_read_bool(pdev->dev.of_node, "smbus"); in stm32f7_i2c_probe()
2252 if (i2c_dev->smbus_mode) { in stm32f7_i2c_probe()
2253 ret = stm32f7_i2c_enable_smbus_host(i2c_dev); in stm32f7_i2c_probe()
2255 dev_err(i2c_dev->dev, in stm32f7_i2c_probe()
2263 ret = stm32f7_i2c_enable_smbus_alert(i2c_dev); in stm32f7_i2c_probe()
2265 dev_err(i2c_dev->dev, in stm32f7_i2c_probe()
2272 dev_info(i2c_dev->dev, "STM32F7 I2C-%d bus adapter\n", adap->nr); in stm32f7_i2c_probe()
2274 pm_runtime_mark_last_busy(i2c_dev->dev); in stm32f7_i2c_probe()
2275 pm_runtime_put_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2280 stm32f7_i2c_disable_smbus_host(i2c_dev); in stm32f7_i2c_probe()
2286 pm_runtime_put_noidle(i2c_dev->dev); in stm32f7_i2c_probe()
2287 pm_runtime_disable(i2c_dev->dev); in stm32f7_i2c_probe()
2288 pm_runtime_set_suspended(i2c_dev->dev); in stm32f7_i2c_probe()
2289 pm_runtime_dont_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_probe()
2291 if (i2c_dev->wakeup_src) in stm32f7_i2c_probe()
2292 dev_pm_clear_wake_irq(i2c_dev->dev); in stm32f7_i2c_probe()
2295 if (i2c_dev->wakeup_src) in stm32f7_i2c_probe()
2296 device_set_wakeup_capable(i2c_dev->dev, false); in stm32f7_i2c_probe()
2298 if (i2c_dev->dma) { in stm32f7_i2c_probe()
2299 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_probe()
2300 i2c_dev->dma = NULL; in stm32f7_i2c_probe()
2304 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_probe()
2307 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_probe()
2314 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev); in stm32f7_i2c_remove() local
2316 stm32f7_i2c_disable_smbus_alert(i2c_dev); in stm32f7_i2c_remove()
2317 stm32f7_i2c_disable_smbus_host(i2c_dev); in stm32f7_i2c_remove()
2319 i2c_del_adapter(&i2c_dev->adap); in stm32f7_i2c_remove()
2320 pm_runtime_get_sync(i2c_dev->dev); in stm32f7_i2c_remove()
2322 if (i2c_dev->wakeup_src) { in stm32f7_i2c_remove()
2323 dev_pm_clear_wake_irq(i2c_dev->dev); in stm32f7_i2c_remove()
2328 device_init_wakeup(i2c_dev->dev, false); in stm32f7_i2c_remove()
2331 pm_runtime_put_noidle(i2c_dev->dev); in stm32f7_i2c_remove()
2332 pm_runtime_disable(i2c_dev->dev); in stm32f7_i2c_remove()
2333 pm_runtime_set_suspended(i2c_dev->dev); in stm32f7_i2c_remove()
2334 pm_runtime_dont_use_autosuspend(i2c_dev->dev); in stm32f7_i2c_remove()
2336 if (i2c_dev->dma) { in stm32f7_i2c_remove()
2337 stm32_i2c_dma_free(i2c_dev->dma); in stm32f7_i2c_remove()
2338 i2c_dev->dma = NULL; in stm32f7_i2c_remove()
2341 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_remove()
2343 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_remove()
2350 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_runtime_suspend() local
2352 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) in stm32f7_i2c_runtime_suspend()
2353 clk_disable_unprepare(i2c_dev->clk); in stm32f7_i2c_runtime_suspend()
2360 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_runtime_resume() local
2363 if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { in stm32f7_i2c_runtime_resume()
2364 ret = clk_prepare_enable(i2c_dev->clk); in stm32f7_i2c_runtime_resume()
2374 static int __maybe_unused stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_regs_backup() argument
2377 struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; in stm32f7_i2c_regs_backup()
2379 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_regs_backup()
2383 backup_regs->cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_backup()
2384 backup_regs->cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_regs_backup()
2385 backup_regs->oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_regs_backup()
2386 backup_regs->oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_regs_backup()
2387 backup_regs->tmgr = readl_relaxed(i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_regs_backup()
2388 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); in stm32f7_i2c_regs_backup()
2390 pm_runtime_put_sync(i2c_dev->dev); in stm32f7_i2c_regs_backup()
2395 static int __maybe_unused stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev) in stm32f7_i2c_regs_restore() argument
2399 struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs; in stm32f7_i2c_regs_restore()
2401 ret = pm_runtime_resume_and_get(i2c_dev->dev); in stm32f7_i2c_regs_restore()
2405 cr1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_restore()
2407 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_regs_restore()
2410 writel_relaxed(backup_regs->tmgr, i2c_dev->base + STM32F7_I2C_TIMINGR); in stm32f7_i2c_regs_restore()
2412 i2c_dev->base + STM32F7_I2C_CR1); in stm32f7_i2c_regs_restore()
2414 stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1, in stm32f7_i2c_regs_restore()
2416 writel_relaxed(backup_regs->cr2, i2c_dev->base + STM32F7_I2C_CR2); in stm32f7_i2c_regs_restore()
2417 writel_relaxed(backup_regs->oar1, i2c_dev->base + STM32F7_I2C_OAR1); in stm32f7_i2c_regs_restore()
2418 writel_relaxed(backup_regs->oar2, i2c_dev->base + STM32F7_I2C_OAR2); in stm32f7_i2c_regs_restore()
2419 stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); in stm32f7_i2c_regs_restore()
2421 pm_runtime_put_sync(i2c_dev->dev); in stm32f7_i2c_regs_restore()
2428 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_suspend() local
2431 i2c_mark_adapter_suspended(&i2c_dev->adap); in stm32f7_i2c_suspend()
2434 ret = stm32f7_i2c_regs_backup(i2c_dev); in stm32f7_i2c_suspend()
2436 i2c_mark_adapter_resumed(&i2c_dev->adap); in stm32f7_i2c_suspend()
2449 struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); in stm32f7_i2c_resume() local
2458 ret = stm32f7_i2c_regs_restore(i2c_dev); in stm32f7_i2c_resume()
2463 i2c_mark_adapter_resumed(&i2c_dev->adap); in stm32f7_i2c_resume()