Lines Matching +full:vf610 +full:- +full:i2c

1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2002 Motorola GSG-China
9 * Implementation of I2C Adapter/Algorithm Driver
10 * for I2C Bus integrated in Freescale i.MX/MXC processors
12 * Derived from Motorola GSG China I2C example driver
27 #include <linux/dma-mapping.h>
33 #include <linux/i2c.h>
44 #include <linux/platform_data/i2c-imx.h>
51 #define DRIVER_NAME "imx-i2c"
62 /* IMX I2C registers:
63 * the I2C register offset is different between SoCs,
70 #define IMX_I2C_IADR 0x00 /* i2c slave address */
71 #define IMX_I2C_IFDR 0x01 /* i2c frequency divider */
72 #define IMX_I2C_I2CR 0x02 /* i2c control */
73 #define IMX_I2C_I2SR 0x03 /* i2c status */
74 #define IMX_I2C_I2DR 0x04 /* i2c transfer data */
79 /* Bits of IMX I2C registers */
97 * - write zero to clear(w0c) INT flag on i.MX,
98 * - but write one to clear(w1c) INT flag on Vybrid.
99 * 2) I2CR: I2C module enable operation also differ between SoCs:
100 * - set I2CR_IEN bit enable the module on i.MX,
101 * - but clear I2CR_IEN bit enable the module on Vybrid.
112 * taken from table 26-5, p.26-9, Freescale i.MX
139 /* Vybrid VF610 clock divider, register value pairs */
238 .name = "imx1-i2c",
241 .name = "imx21-i2c",
250 { .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, },
251 { .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, },
252 { .compatible = "fsl,vf610-i2c", .data = &vf610_i2c_hwdata, },
265 return i2c_imx->hwdata->devtype == IMX1_I2C; in is_imx1_i2c()
271 writeb(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); in imx_i2c_write_reg()
277 return readb(i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); in imx_i2c_read_reg()
286 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_request()
293 dma->chan_tx = dma_request_chan(dev, "tx"); in i2c_imx_dma_request()
294 if (IS_ERR(dma->chan_tx)) { in i2c_imx_dma_request()
295 ret = PTR_ERR(dma->chan_tx); in i2c_imx_dma_request()
296 if (ret != -ENODEV && ret != -EPROBE_DEFER) in i2c_imx_dma_request()
302 (IMX_I2C_I2DR << i2c_imx->hwdata->regshift); in i2c_imx_dma_request()
306 ret = dmaengine_slave_config(dma->chan_tx, &dma_sconfig); in i2c_imx_dma_request()
312 dma->chan_rx = dma_request_chan(dev, "rx"); in i2c_imx_dma_request()
313 if (IS_ERR(dma->chan_rx)) { in i2c_imx_dma_request()
314 ret = PTR_ERR(dma->chan_rx); in i2c_imx_dma_request()
315 if (ret != -ENODEV && ret != -EPROBE_DEFER) in i2c_imx_dma_request()
321 (IMX_I2C_I2DR << i2c_imx->hwdata->regshift); in i2c_imx_dma_request()
325 ret = dmaengine_slave_config(dma->chan_rx, &dma_sconfig); in i2c_imx_dma_request()
331 i2c_imx->dma = dma; in i2c_imx_dma_request()
332 init_completion(&dma->cmd_complete); in i2c_imx_dma_request()
334 dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); in i2c_imx_dma_request()
339 dma_release_channel(dma->chan_rx); in i2c_imx_dma_request()
341 dma_release_channel(dma->chan_tx); in i2c_imx_dma_request()
349 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_callback()
351 dma_unmap_single(dma->chan_using->device->dev, dma->dma_buf, in i2c_imx_dma_callback()
352 dma->dma_len, dma->dma_data_dir); in i2c_imx_dma_callback()
353 complete(&dma->cmd_complete); in i2c_imx_dma_callback()
359 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_xfer()
361 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_xfer()
362 struct device *chan_dev = dma->chan_using->device->dev; in i2c_imx_dma_xfer()
364 dma->dma_buf = dma_map_single(chan_dev, msgs->buf, in i2c_imx_dma_xfer()
365 dma->dma_len, dma->dma_data_dir); in i2c_imx_dma_xfer()
366 if (dma_mapping_error(chan_dev, dma->dma_buf)) { in i2c_imx_dma_xfer()
371 txdesc = dmaengine_prep_slave_single(dma->chan_using, dma->dma_buf, in i2c_imx_dma_xfer()
372 dma->dma_len, dma->dma_transfer_dir, in i2c_imx_dma_xfer()
379 reinit_completion(&dma->cmd_complete); in i2c_imx_dma_xfer()
380 txdesc->callback = i2c_imx_dma_callback; in i2c_imx_dma_xfer()
381 txdesc->callback_param = i2c_imx; in i2c_imx_dma_xfer()
387 dma_async_issue_pending(dma->chan_using); in i2c_imx_dma_xfer()
391 dmaengine_terminate_all(dma->chan_using); in i2c_imx_dma_xfer()
393 dma_unmap_single(chan_dev, dma->dma_buf, in i2c_imx_dma_xfer()
394 dma->dma_len, dma->dma_data_dir); in i2c_imx_dma_xfer()
396 return -EINVAL; in i2c_imx_dma_xfer()
401 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_free()
403 dma->dma_buf = 0; in i2c_imx_dma_free()
404 dma->dma_len = 0; in i2c_imx_dma_free()
406 dma_release_channel(dma->chan_tx); in i2c_imx_dma_free()
407 dma->chan_tx = NULL; in i2c_imx_dma_free()
409 dma_release_channel(dma->chan_rx); in i2c_imx_dma_free()
410 dma->chan_rx = NULL; in i2c_imx_dma_free()
412 dma->chan_using = NULL; in i2c_imx_dma_free()
424 temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ bits; in i2c_imx_clear_irq()
433 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); in i2c_imx_bus_busy()
441 return -EAGAIN; in i2c_imx_bus_busy()
445 i2c_imx->stopped = 0; in i2c_imx_bus_busy()
449 i2c_imx->stopped = 1; in i2c_imx_bus_busy()
453 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_bus_busy()
454 "<%s> I2C bus is busy\n", __func__); in i2c_imx_bus_busy()
455 return -ETIMEDOUT; in i2c_imx_bus_busy()
469 void __iomem *addr = i2c_imx->base + (IMX_I2C_I2SR << i2c_imx->hwdata->regshift); in i2c_imx_trx_complete()
476 * Set the value hard as it is done for the non-atomic use-case. in i2c_imx_trx_complete()
483 i2c_imx->i2csr = regval; in i2c_imx_trx_complete()
486 wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10); in i2c_imx_trx_complete()
489 if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) { in i2c_imx_trx_complete()
490 dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__); in i2c_imx_trx_complete()
491 return -ETIMEDOUT; in i2c_imx_trx_complete()
495 if (i2c_imx->i2csr & I2SR_IAL) { in i2c_imx_trx_complete()
496 dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__); in i2c_imx_trx_complete()
499 i2c_imx->i2csr = 0; in i2c_imx_trx_complete()
500 return -EAGAIN; in i2c_imx_trx_complete()
503 dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__); in i2c_imx_trx_complete()
504 i2c_imx->i2csr = 0; in i2c_imx_trx_complete()
511 dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__); in i2c_imx_acked()
512 return -ENXIO; /* No ACK */ in i2c_imx_acked()
515 dev_dbg(&i2c_imx->adapter.dev, "<%s> ACK received\n", __func__); in i2c_imx_acked()
522 struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; in i2c_imx_set_clk()
527 if (i2c_imx->cur_clk == i2c_clk_rate) in i2c_imx_set_clk()
530 i2c_imx->cur_clk = i2c_clk_rate; in i2c_imx_set_clk()
532 div = (i2c_clk_rate + i2c_imx->bitrate - 1) / i2c_imx->bitrate; in i2c_imx_set_clk()
535 else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div) in i2c_imx_set_clk()
536 i = i2c_imx->hwdata->ndivs - 1; in i2c_imx_set_clk()
542 i2c_imx->ifdr = i2c_clk_div[i].val; in i2c_imx_set_clk()
546 * It should be about one I2C clock period long. in i2c_imx_set_clk()
547 * This delay is used in I2C bus disable function in i2c_imx_set_clk()
550 i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div in i2c_imx_set_clk()
551 + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); in i2c_imx_set_clk()
554 dev_dbg(&i2c_imx->adapter.dev, "I2C_CLK=%d, REQ DIV=%d\n", in i2c_imx_set_clk()
556 dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n", in i2c_imx_set_clk()
570 i2c_imx_set_clk(i2c_imx, ndata->new_rate); in i2c_imx_clk_notifier_call()
580 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); in i2c_imx_start()
582 imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR); in i2c_imx_start()
583 /* Enable I2C controller */ in i2c_imx_start()
584 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); in i2c_imx_start()
585 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode, i2c_imx, IMX_I2C_I2CR); in i2c_imx_start()
593 /* Start I2C transaction */ in i2c_imx_start()
614 if (!i2c_imx->stopped) { in i2c_imx_stop()
615 /* Stop I2C transaction */ in i2c_imx_stop()
616 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); in i2c_imx_stop()
619 i2c_imx->stopped = 1; in i2c_imx_stop()
621 if (i2c_imx->dma) in i2c_imx_stop()
630 udelay(i2c_imx->disable_delay); in i2c_imx_stop()
633 if (!i2c_imx->stopped) in i2c_imx_stop()
636 /* Disable I2C controller */ in i2c_imx_stop()
637 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, in i2c_imx_stop()
649 i2c_imx->i2csr = temp; in i2c_imx_isr()
651 wake_up(&i2c_imx->queue); in i2c_imx_isr()
665 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_write()
666 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_write()
668 dma->chan_using = dma->chan_tx; in i2c_imx_dma_write()
669 dma->dma_transfer_dir = DMA_MEM_TO_DEV; in i2c_imx_dma_write()
670 dma->dma_data_dir = DMA_TO_DEVICE; in i2c_imx_dma_write()
671 dma->dma_len = msgs->len - 1; in i2c_imx_dma_write()
686 &i2c_imx->dma->cmd_complete, in i2c_imx_dma_write()
689 dmaengine_terminate_all(dma->chan_using); in i2c_imx_dma_write()
690 return -ETIMEDOUT; in i2c_imx_dma_write()
701 return -ETIMEDOUT; in i2c_imx_dma_write()
711 imx_i2c_write_reg(msgs->buf[msgs->len-1], in i2c_imx_dma_write()
727 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_read()
728 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_read()
731 dma->chan_using = dma->chan_rx; in i2c_imx_dma_read()
732 dma->dma_transfer_dir = DMA_DEV_TO_MEM; in i2c_imx_dma_read()
733 dma->dma_data_dir = DMA_FROM_DEVICE; in i2c_imx_dma_read()
735 dma->dma_len = msgs->len - 2; in i2c_imx_dma_read()
741 &i2c_imx->dma->cmd_complete, in i2c_imx_dma_read()
744 dmaengine_terminate_all(dma->chan_using); in i2c_imx_dma_read()
745 return -ETIMEDOUT; in i2c_imx_dma_read()
756 return -ETIMEDOUT; in i2c_imx_dma_read()
765 /* read n-1 byte data */ in i2c_imx_dma_read()
770 msgs->buf[msgs->len-2] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_read()
784 i2c_imx->stopped = 1; in i2c_imx_dma_read()
787 if (!i2c_imx->stopped) in i2c_imx_dma_read()
791 * For i2c master receiver repeat restart operation like: in i2c_imx_dma_read()
792 * read -> repeat MSTA -> read/write in i2c_imx_dma_read()
801 msgs->buf[msgs->len-1] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_read()
811 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", in i2c_imx_write()
822 dev_dbg(&i2c_imx->adapter.dev, "<%s> write data\n", __func__); in i2c_imx_write()
825 for (i = 0; i < msgs->len; i++) { in i2c_imx_write()
826 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_write()
828 __func__, i, msgs->buf[i]); in i2c_imx_write()
829 imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR); in i2c_imx_write()
845 int block_data = msgs->flags & I2C_M_RECV_LEN; in i2c_imx_read()
846 int use_dma = i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data; in i2c_imx_read()
848 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
861 dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); in i2c_imx_read()
871 if ((msgs->len - 1) || block_data) in i2c_imx_read()
878 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); in i2c_imx_read()
884 for (i = 0; i < msgs->len; i++) { in i2c_imx_read()
893 * msgs->len. in i2c_imx_read()
898 return -EPROTO; in i2c_imx_read()
899 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
902 msgs->len += len; in i2c_imx_read()
904 if (i == (msgs->len - 1)) { in i2c_imx_read()
910 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
914 i2c_imx->stopped = 1; in i2c_imx_read()
917 if (!i2c_imx->stopped) in i2c_imx_read()
921 * For i2c master receiver repeat restart operation like: in i2c_imx_read()
922 * read -> repeat MSTA -> read/write in i2c_imx_read()
931 } else if (i == (msgs->len - 2)) { in i2c_imx_read()
932 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
939 msgs->buf[0] = len; in i2c_imx_read()
941 msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_read()
942 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
944 __func__, i, msgs->buf[i]); in i2c_imx_read()
957 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); in i2c_imx_xfer_common()
959 /* Start I2C transfer */ in i2c_imx_xfer_common()
966 if (!atomic && i2c_imx->adapter.bus_recovery_info) { in i2c_imx_xfer_common()
967 i2c_recover_bus(&i2c_imx->adapter); in i2c_imx_xfer_common()
977 if (i == num - 1) in i2c_imx_xfer_common()
981 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
990 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
995 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1002 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1014 i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD) in i2c_imx_xfer_common()
1024 /* Stop I2C transfer */ in i2c_imx_xfer_common()
1027 dev_dbg(&i2c_imx->adapter.dev, "<%s> exit with: %s: %d\n", __func__, in i2c_imx_xfer_common()
1039 result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1045 pm_runtime_mark_last_busy(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1046 pm_runtime_put_autosuspend(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1057 result = clk_enable(i2c_imx->clk); in i2c_imx_xfer_atomic()
1063 clk_disable(i2c_imx->clk); in i2c_imx_xfer_atomic()
1074 pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_gpio); in i2c_imx_prepare_recovery()
1083 pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default); in i2c_imx_unprepare_recovery()
1096 struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo; in i2c_imx_init_recovery_info()
1098 i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev); in i2c_imx_init_recovery_info()
1099 if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) { in i2c_imx_init_recovery_info()
1100 dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n"); in i2c_imx_init_recovery_info()
1101 return PTR_ERR(i2c_imx->pinctrl); in i2c_imx_init_recovery_info()
1104 i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl, in i2c_imx_init_recovery_info()
1106 i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, in i2c_imx_init_recovery_info()
1108 rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); in i2c_imx_init_recovery_info()
1109 rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN); in i2c_imx_init_recovery_info()
1111 if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || in i2c_imx_init_recovery_info()
1112 PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) { in i2c_imx_init_recovery_info()
1113 return -EPROBE_DEFER; in i2c_imx_init_recovery_info()
1114 } else if (IS_ERR(rinfo->sda_gpiod) || in i2c_imx_init_recovery_info()
1115 IS_ERR(rinfo->scl_gpiod) || in i2c_imx_init_recovery_info()
1116 IS_ERR(i2c_imx->pinctrl_pins_default) || in i2c_imx_init_recovery_info()
1117 IS_ERR(i2c_imx->pinctrl_pins_gpio)) { in i2c_imx_init_recovery_info()
1118 dev_dbg(&pdev->dev, "recovery information incomplete\n"); in i2c_imx_init_recovery_info()
1122 dev_dbg(&pdev->dev, "using scl%s for recovery\n", in i2c_imx_init_recovery_info()
1123 rinfo->sda_gpiod ? ",sda" : ""); in i2c_imx_init_recovery_info()
1125 rinfo->prepare_recovery = i2c_imx_prepare_recovery; in i2c_imx_init_recovery_info()
1126 rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; in i2c_imx_init_recovery_info()
1127 rinfo->recover_bus = i2c_generic_scl_recovery; in i2c_imx_init_recovery_info()
1128 i2c_imx->adapter.bus_recovery_info = rinfo; in i2c_imx_init_recovery_info()
1149 struct imxi2c_platform_data *pdata = dev_get_platdata(&pdev->dev); in i2c_imx_probe()
1155 dev_dbg(&pdev->dev, "<%s>\n", __func__); in i2c_imx_probe()
1162 base = devm_ioremap_resource(&pdev->dev, res); in i2c_imx_probe()
1166 phy_addr = (dma_addr_t)res->start; in i2c_imx_probe()
1167 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(*i2c_imx), GFP_KERNEL); in i2c_imx_probe()
1169 return -ENOMEM; in i2c_imx_probe()
1171 match = device_get_match_data(&pdev->dev); in i2c_imx_probe()
1173 i2c_imx->hwdata = match; in i2c_imx_probe()
1175 i2c_imx->hwdata = (struct imx_i2c_hwdata *) in i2c_imx_probe()
1176 platform_get_device_id(pdev)->driver_data; in i2c_imx_probe()
1179 strlcpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name)); in i2c_imx_probe()
1180 i2c_imx->adapter.owner = THIS_MODULE; in i2c_imx_probe()
1181 i2c_imx->adapter.algo = &i2c_imx_algo; in i2c_imx_probe()
1182 i2c_imx->adapter.dev.parent = &pdev->dev; in i2c_imx_probe()
1183 i2c_imx->adapter.nr = pdev->id; in i2c_imx_probe()
1184 i2c_imx->adapter.dev.of_node = pdev->dev.of_node; in i2c_imx_probe()
1185 i2c_imx->base = base; in i2c_imx_probe()
1186 ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev)); in i2c_imx_probe()
1188 /* Get I2C clock */ in i2c_imx_probe()
1189 i2c_imx->clk = devm_clk_get(&pdev->dev, NULL); in i2c_imx_probe()
1190 if (IS_ERR(i2c_imx->clk)) in i2c_imx_probe()
1191 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk), in i2c_imx_probe()
1192 "can't get I2C clock\n"); in i2c_imx_probe()
1194 ret = clk_prepare_enable(i2c_imx->clk); in i2c_imx_probe()
1196 dev_err(&pdev->dev, "can't enable I2C clock, ret=%d\n", ret); in i2c_imx_probe()
1201 init_waitqueue_head(&i2c_imx->queue); in i2c_imx_probe()
1204 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); in i2c_imx_probe()
1209 pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); in i2c_imx_probe()
1210 pm_runtime_use_autosuspend(&pdev->dev); in i2c_imx_probe()
1211 pm_runtime_set_active(&pdev->dev); in i2c_imx_probe()
1212 pm_runtime_enable(&pdev->dev); in i2c_imx_probe()
1214 ret = pm_runtime_get_sync(&pdev->dev); in i2c_imx_probe()
1220 pdev->name, i2c_imx); in i2c_imx_probe()
1222 dev_err(&pdev->dev, "can't claim irq %d\n", irq); in i2c_imx_probe()
1227 i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; in i2c_imx_probe()
1228 ret = of_property_read_u32(pdev->dev.of_node, in i2c_imx_probe()
1229 "clock-frequency", &i2c_imx->bitrate); in i2c_imx_probe()
1230 if (ret < 0 && pdata && pdata->bitrate) in i2c_imx_probe()
1231 i2c_imx->bitrate = pdata->bitrate; in i2c_imx_probe()
1232 i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call; in i2c_imx_probe()
1233 clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_probe()
1234 i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk)); in i2c_imx_probe()
1237 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, in i2c_imx_probe()
1239 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); in i2c_imx_probe()
1244 if (ret == -EPROBE_DEFER) in i2c_imx_probe()
1247 /* Add I2C adapter */ in i2c_imx_probe()
1248 ret = i2c_add_numbered_adapter(&i2c_imx->adapter); in i2c_imx_probe()
1252 pm_runtime_mark_last_busy(&pdev->dev); in i2c_imx_probe()
1253 pm_runtime_put_autosuspend(&pdev->dev); in i2c_imx_probe()
1255 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq); in i2c_imx_probe()
1256 dev_dbg(&i2c_imx->adapter.dev, "device resources: %pR\n", res); in i2c_imx_probe()
1257 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", in i2c_imx_probe()
1258 i2c_imx->adapter.name); in i2c_imx_probe()
1259 dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); in i2c_imx_probe()
1267 clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_probe()
1270 pm_runtime_put_noidle(&pdev->dev); in i2c_imx_probe()
1271 pm_runtime_disable(&pdev->dev); in i2c_imx_probe()
1272 pm_runtime_set_suspended(&pdev->dev); in i2c_imx_probe()
1273 pm_runtime_dont_use_autosuspend(&pdev->dev); in i2c_imx_probe()
1274 clk_disable_unprepare(i2c_imx->clk); in i2c_imx_probe()
1283 ret = pm_runtime_get_sync(&pdev->dev); in i2c_imx_remove()
1288 dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); in i2c_imx_remove()
1289 i2c_del_adapter(&i2c_imx->adapter); in i2c_imx_remove()
1291 if (i2c_imx->dma) in i2c_imx_remove()
1300 clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_remove()
1304 clk_disable_unprepare(i2c_imx->clk); in i2c_imx_remove()
1306 pm_runtime_put_noidle(&pdev->dev); in i2c_imx_remove()
1307 pm_runtime_disable(&pdev->dev); in i2c_imx_remove()
1316 clk_disable(i2c_imx->clk); in i2c_imx_runtime_suspend()
1326 ret = clk_enable(i2c_imx->clk); in i2c_imx_runtime_resume()
1328 dev_err(dev, "can't enable I2C clock, ret=%d\n", ret); in i2c_imx_runtime_resume()
1364 MODULE_DESCRIPTION("I2C adapter driver for IMX I2C bus");