Lines Matching +full:i2c +full:- +full:lt +full:- +full:enable

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
17 * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt>
28 #include <linux/dma-mapping.h>
34 #include <linux/i2c.h>
46 #include <linux/platform_data/i2c-imx.h>
53 #define DRIVER_NAME "imx-i2c"
58 * Enable DMA if transfer byte size is bigger than this threshold.
66 /* IMX I2C registers:
67 * the I2C register offset is different between SoCs,
74 #define IMX_I2C_IADR 0x00 /* i2c slave address */
75 #define IMX_I2C_IFDR 0x01 /* i2c frequency divider */
76 #define IMX_I2C_I2CR 0x02 /* i2c control */
77 #define IMX_I2C_I2SR 0x03 /* i2c status */
78 #define IMX_I2C_I2DR 0x04 /* i2c transfer data */
83 #define IMX_I2C_IBIC 0x05 /* i2c bus interrupt config */
88 /* Bits of IMX I2C registers */
103 #define IBIC_BIIE 0x80 /* Bus idle interrupt enable */
107 * - write zero to clear(w0c) INT flag on i.MX,
108 * - but write one to clear(w1c) INT flag on Vybrid.
109 * 2) I2CR: I2C module enable operation also differ between SoCs:
110 * - set I2CR_IEN bit enable the module on i.MX,
111 * - but clear I2CR_IEN bit enable the module on Vybrid.
122 * taken from table 26-5, p.26-9, Freescale i.MX
183 * I2C: When the I2C clock speed is configured for 400 kHz,
184 * the SCL low period violates the I2C spec of 1.3 uS min.
266 .name = "imx1-i2c",
269 .name = "imx21-i2c",
278 { .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, },
279 { .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, },
280 { .compatible = "fsl,imx6q-i2c", .data = &imx6_i2c_hwdata, },
281 { .compatible = "fsl,imx6sl-i2c", .data = &imx6_i2c_hwdata, },
282 { .compatible = "fsl,imx6sll-i2c", .data = &imx6_i2c_hwdata, },
283 { .compatible = "fsl,imx6sx-i2c", .data = &imx6_i2c_hwdata, },
284 { .compatible = "fsl,imx6ul-i2c", .data = &imx6_i2c_hwdata, },
285 { .compatible = "fsl,imx7s-i2c", .data = &imx6_i2c_hwdata, },
286 { .compatible = "fsl,imx8mm-i2c", .data = &imx6_i2c_hwdata, },
287 { .compatible = "fsl,imx8mn-i2c", .data = &imx6_i2c_hwdata, },
288 { .compatible = "fsl,imx8mp-i2c", .data = &imx6_i2c_hwdata, },
289 { .compatible = "fsl,imx8mq-i2c", .data = &imx6_i2c_hwdata, },
290 { .compatible = "fsl,vf610-i2c", .data = &vf610_i2c_hwdata, },
303 return i2c_imx->hwdata->devtype == IMX1_I2C; in is_imx1_i2c()
308 return i2c_imx->hwdata->devtype == VF610_I2C; in is_vf610_i2c()
314 writeb(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); in imx_i2c_write_reg()
320 return readb(i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); in imx_i2c_read_reg()
332 temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ bits; in i2c_imx_clear_irq()
336 /* Set up i2c controller register and i2c status register to default value. */
339 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, in i2c_imx_reset_regs()
350 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_request()
357 dma->chan_tx = dma_request_chan(dev, "tx"); in i2c_imx_dma_request()
358 if (IS_ERR(dma->chan_tx)) { in i2c_imx_dma_request()
359 ret = PTR_ERR(dma->chan_tx); in i2c_imx_dma_request()
360 if (ret != -ENODEV && ret != -EPROBE_DEFER) in i2c_imx_dma_request()
366 (IMX_I2C_I2DR << i2c_imx->hwdata->regshift); in i2c_imx_dma_request()
370 ret = dmaengine_slave_config(dma->chan_tx, &dma_sconfig); in i2c_imx_dma_request()
376 dma->chan_rx = dma_request_chan(dev, "rx"); in i2c_imx_dma_request()
377 if (IS_ERR(dma->chan_rx)) { in i2c_imx_dma_request()
378 ret = PTR_ERR(dma->chan_rx); in i2c_imx_dma_request()
379 if (ret != -ENODEV && ret != -EPROBE_DEFER) in i2c_imx_dma_request()
385 (IMX_I2C_I2DR << i2c_imx->hwdata->regshift); in i2c_imx_dma_request()
389 ret = dmaengine_slave_config(dma->chan_rx, &dma_sconfig); in i2c_imx_dma_request()
395 i2c_imx->dma = dma; in i2c_imx_dma_request()
396 init_completion(&dma->cmd_complete); in i2c_imx_dma_request()
398 dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); in i2c_imx_dma_request()
403 dma_release_channel(dma->chan_rx); in i2c_imx_dma_request()
405 dma_release_channel(dma->chan_tx); in i2c_imx_dma_request()
413 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_callback()
415 dma_unmap_single(dma->chan_using->device->dev, dma->dma_buf, in i2c_imx_dma_callback()
416 dma->dma_len, dma->dma_data_dir); in i2c_imx_dma_callback()
417 complete(&dma->cmd_complete); in i2c_imx_dma_callback()
423 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_xfer()
425 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_xfer()
426 struct device *chan_dev = dma->chan_using->device->dev; in i2c_imx_dma_xfer()
428 dma->dma_buf = dma_map_single(chan_dev, msgs->buf, in i2c_imx_dma_xfer()
429 dma->dma_len, dma->dma_data_dir); in i2c_imx_dma_xfer()
430 if (dma_mapping_error(chan_dev, dma->dma_buf)) { in i2c_imx_dma_xfer()
435 txdesc = dmaengine_prep_slave_single(dma->chan_using, dma->dma_buf, in i2c_imx_dma_xfer()
436 dma->dma_len, dma->dma_transfer_dir, in i2c_imx_dma_xfer()
443 reinit_completion(&dma->cmd_complete); in i2c_imx_dma_xfer()
444 txdesc->callback = i2c_imx_dma_callback; in i2c_imx_dma_xfer()
445 txdesc->callback_param = i2c_imx; in i2c_imx_dma_xfer()
451 dma_async_issue_pending(dma->chan_using); in i2c_imx_dma_xfer()
455 dmaengine_terminate_sync(dma->chan_using); in i2c_imx_dma_xfer()
457 dma_unmap_single(chan_dev, dma->dma_buf, in i2c_imx_dma_xfer()
458 dma->dma_len, dma->dma_data_dir); in i2c_imx_dma_xfer()
460 return -EINVAL; in i2c_imx_dma_xfer()
465 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_free()
467 dma->dma_buf = 0; in i2c_imx_dma_free()
468 dma->dma_len = 0; in i2c_imx_dma_free()
470 dma_release_channel(dma->chan_tx); in i2c_imx_dma_free()
471 dma->chan_tx = NULL; in i2c_imx_dma_free()
473 dma_release_channel(dma->chan_rx); in i2c_imx_dma_free()
474 dma->chan_rx = NULL; in i2c_imx_dma_free()
476 dma->chan_using = NULL; in i2c_imx_dma_free()
490 return -EAGAIN; in i2c_imx_bus_busy()
494 i2c_imx->stopped = 0; in i2c_imx_bus_busy()
498 i2c_imx->stopped = 1; in i2c_imx_bus_busy()
502 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_bus_busy()
503 "<%s> I2C bus is busy\n", __func__); in i2c_imx_bus_busy()
504 return -ETIMEDOUT; in i2c_imx_bus_busy()
518 void __iomem *addr = i2c_imx->base + (IMX_I2C_I2SR << i2c_imx->hwdata->regshift); in i2c_imx_trx_complete()
525 * Set the value hard as it is done for the non-atomic use-case. in i2c_imx_trx_complete()
532 i2c_imx->i2csr = regval; in i2c_imx_trx_complete()
535 wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10); in i2c_imx_trx_complete()
538 if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) { in i2c_imx_trx_complete()
539 dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__); in i2c_imx_trx_complete()
540 return -ETIMEDOUT; in i2c_imx_trx_complete()
544 if (i2c_imx->i2csr & I2SR_IAL) { in i2c_imx_trx_complete()
545 dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__); in i2c_imx_trx_complete()
548 i2c_imx->i2csr = 0; in i2c_imx_trx_complete()
549 return -EAGAIN; in i2c_imx_trx_complete()
552 dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__); in i2c_imx_trx_complete()
553 i2c_imx->i2csr = 0; in i2c_imx_trx_complete()
560 dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__); in i2c_imx_acked()
561 return -ENXIO; /* No ACK */ in i2c_imx_acked()
564 dev_dbg(&i2c_imx->adapter.dev, "<%s> ACK received\n", __func__); in i2c_imx_acked()
571 struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; in i2c_imx_set_clk()
575 if (i2c_imx->hwdata->has_err007805 && i2c_imx->bitrate > 384000) { in i2c_imx_set_clk()
576 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_set_clk()
578 i2c_imx->bitrate); in i2c_imx_set_clk()
579 i2c_imx->bitrate = 384000; in i2c_imx_set_clk()
583 if (i2c_imx->cur_clk == i2c_clk_rate) in i2c_imx_set_clk()
586 i2c_imx->cur_clk = i2c_clk_rate; in i2c_imx_set_clk()
588 div = DIV_ROUND_UP(i2c_clk_rate, i2c_imx->bitrate); in i2c_imx_set_clk()
591 else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div) in i2c_imx_set_clk()
592 i = i2c_imx->hwdata->ndivs - 1; in i2c_imx_set_clk()
598 i2c_imx->ifdr = i2c_clk_div[i].val; in i2c_imx_set_clk()
602 * It should be about one I2C clock period long. in i2c_imx_set_clk()
603 * This delay is used in I2C bus disable function in i2c_imx_set_clk()
606 i2c_imx->disable_delay = DIV_ROUND_UP(500000U * i2c_clk_div[i].div, in i2c_imx_set_clk()
610 dev_dbg(&i2c_imx->adapter.dev, "I2C_CLK=%d, REQ DIV=%d\n", in i2c_imx_set_clk()
612 dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n", in i2c_imx_set_clk()
626 i2c_imx_set_clk(i2c_imx, ndata->new_rate); in i2c_imx_clk_notifier_call()
636 imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR); in i2c_imx_start()
637 /* Enable I2C controller */ in i2c_imx_start()
638 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); in i2c_imx_start()
639 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode, i2c_imx, IMX_I2C_I2CR); in i2c_imx_start()
647 /* Start I2C transaction */ in i2c_imx_start()
668 if (!i2c_imx->stopped) { in i2c_imx_stop()
669 /* Stop I2C transaction */ in i2c_imx_stop()
672 i2c_imx->stopped = 1; in i2c_imx_stop()
674 if (i2c_imx->dma) in i2c_imx_stop()
683 udelay(i2c_imx->disable_delay); in i2c_imx_stop()
686 if (!i2c_imx->stopped) in i2c_imx_stop()
689 /* Disable I2C controller */ in i2c_imx_stop()
690 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN; in i2c_imx_stop()
695 * Enable bus idle interrupts
696 * Note: IBIC register will be cleared after disabled i2c module.
713 i2c_slave_event(i2c_imx->slave, event, val); in i2c_imx_slave_event()
714 i2c_imx->last_slave_event = event; in i2c_imx_slave_event()
721 while (i2c_imx->last_slave_event != I2C_SLAVE_STOP) { in i2c_imx_slave_finish_op()
722 switch (i2c_imx->last_slave_event) { in i2c_imx_slave_finish_op()
765 dev_dbg(&i2c_imx->adapter.dev, "read requested"); in i2c_imx_slave_handle()
776 dev_dbg(&i2c_imx->adapter.dev, "write requested"); in i2c_imx_slave_handle()
814 * 1, then everything is fine. If it returns -1, then the in i2c_imx_slave_handle()
819 hrtimer_try_to_cancel(&i2c_imx->slave_timer); in i2c_imx_slave_handle()
820 hrtimer_forward_now(&i2c_imx->slave_timer, I2C_IMX_CHECK_DELAY); in i2c_imx_slave_handle()
821 hrtimer_restart(&i2c_imx->slave_timer); in i2c_imx_slave_handle()
832 spin_lock_irqsave(&i2c_imx->slave_lock, flags); in i2c_imx_slave_timeout()
836 spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); in i2c_imx_slave_timeout()
845 imx_i2c_write_reg((i2c_imx->slave->addr << 1), i2c_imx, IMX_I2C_IADR); in i2c_imx_slave_init()
849 /* Enable module */ in i2c_imx_slave_init()
850 temp = i2c_imx->hwdata->i2cr_ien_opcode; in i2c_imx_slave_init()
853 /* Enable interrupt from i2c module */ in i2c_imx_slave_init()
862 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(client->adapter); in i2c_imx_reg_slave()
865 if (i2c_imx->slave) in i2c_imx_reg_slave()
866 return -EBUSY; in i2c_imx_reg_slave()
868 i2c_imx->slave = client; in i2c_imx_reg_slave()
869 i2c_imx->last_slave_event = I2C_SLAVE_STOP; in i2c_imx_reg_slave()
872 ret = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); in i2c_imx_reg_slave()
874 dev_err(&i2c_imx->adapter.dev, "failed to resume i2c controller"); in i2c_imx_reg_slave()
885 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(client->adapter); in i2c_imx_unreg_slave()
888 if (!i2c_imx->slave) in i2c_imx_unreg_slave()
889 return -EINVAL; in i2c_imx_unreg_slave()
896 i2c_imx->slave = NULL; in i2c_imx_unreg_slave()
899 ret = pm_runtime_put_sync(i2c_imx->adapter.dev.parent); in i2c_imx_unreg_slave()
901 dev_err(&i2c_imx->adapter.dev, "failed to suspend i2c controller"); in i2c_imx_unreg_slave()
909 i2c_imx->i2csr = status; in i2c_imx_master_isr()
910 wake_up(&i2c_imx->queue); in i2c_imx_master_isr()
921 spin_lock_irqsave(&i2c_imx->slave_lock, flags); in i2c_imx_isr()
927 if (i2c_imx->slave) { in i2c_imx_isr()
933 spin_unlock_irqrestore(&i2c_imx->slave_lock, in i2c_imx_isr()
939 spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); in i2c_imx_isr()
942 spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); in i2c_imx_isr()
954 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_write()
955 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_write()
957 dma->chan_using = dma->chan_tx; in i2c_imx_dma_write()
958 dma->dma_transfer_dir = DMA_MEM_TO_DEV; in i2c_imx_dma_write()
959 dma->dma_data_dir = DMA_TO_DEVICE; in i2c_imx_dma_write()
960 dma->dma_len = msgs->len - 1; in i2c_imx_dma_write()
975 &i2c_imx->dma->cmd_complete, in i2c_imx_dma_write()
978 dmaengine_terminate_sync(dma->chan_using); in i2c_imx_dma_write()
979 return -ETIMEDOUT; in i2c_imx_dma_write()
990 return -ETIMEDOUT; in i2c_imx_dma_write()
1000 imx_i2c_write_reg(msgs->buf[msgs->len-1], in i2c_imx_dma_write()
1016 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_read()
1017 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_read()
1020 dma->chan_using = dma->chan_rx; in i2c_imx_dma_read()
1021 dma->dma_transfer_dir = DMA_DEV_TO_MEM; in i2c_imx_dma_read()
1022 dma->dma_data_dir = DMA_FROM_DEVICE; in i2c_imx_dma_read()
1024 dma->dma_len = msgs->len - 2; in i2c_imx_dma_read()
1030 &i2c_imx->dma->cmd_complete, in i2c_imx_dma_read()
1033 dmaengine_terminate_sync(dma->chan_using); in i2c_imx_dma_read()
1034 return -ETIMEDOUT; in i2c_imx_dma_read()
1045 return -ETIMEDOUT; in i2c_imx_dma_read()
1054 /* read n-1 byte data */ in i2c_imx_dma_read()
1059 msgs->buf[msgs->len-2] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_read()
1073 i2c_imx->stopped = 1; in i2c_imx_dma_read()
1076 if (!i2c_imx->stopped) in i2c_imx_dma_read()
1080 * For i2c master receiver repeat restart operation like: in i2c_imx_dma_read()
1081 * read -> repeat MSTA -> read/write in i2c_imx_dma_read()
1090 msgs->buf[msgs->len-1] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_read()
1100 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", in i2c_imx_write()
1111 dev_dbg(&i2c_imx->adapter.dev, "<%s> write data\n", __func__); in i2c_imx_write()
1114 for (i = 0; i < msgs->len; i++) { in i2c_imx_write()
1115 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_write()
1117 __func__, i, msgs->buf[i]); in i2c_imx_write()
1118 imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR); in i2c_imx_write()
1134 int block_data = msgs->flags & I2C_M_RECV_LEN; in i2c_imx_read()
1135 int use_dma = i2c_imx->dma && msgs->flags & I2C_M_DMA_SAFE && in i2c_imx_read()
1136 msgs->len >= DMA_THRESHOLD && !block_data; in i2c_imx_read()
1138 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1151 dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); in i2c_imx_read()
1161 if ((msgs->len - 1) || block_data) in i2c_imx_read()
1168 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); in i2c_imx_read()
1174 for (i = 0; i < msgs->len; i++) { in i2c_imx_read()
1183 * msgs->len. in i2c_imx_read()
1188 return -EPROTO; in i2c_imx_read()
1189 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1192 msgs->len += len; in i2c_imx_read()
1194 if (i == (msgs->len - 1)) { in i2c_imx_read()
1200 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1204 i2c_imx->stopped = 1; in i2c_imx_read()
1207 if (!i2c_imx->stopped) in i2c_imx_read()
1211 * For i2c master receiver repeat restart operation like: in i2c_imx_read()
1212 * read -> repeat MSTA -> read/write in i2c_imx_read()
1221 } else if (i == (msgs->len - 2)) { in i2c_imx_read()
1222 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1229 msgs->buf[0] = len; in i2c_imx_read()
1231 msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_read()
1232 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1234 __func__, i, msgs->buf[i]); in i2c_imx_read()
1247 /* Start I2C transfer */ in i2c_imx_xfer_common()
1254 if (!atomic && i2c_imx->adapter.bus_recovery_info) { in i2c_imx_xfer_common()
1255 i2c_recover_bus(&i2c_imx->adapter); in i2c_imx_xfer_common()
1265 if (i == num - 1) in i2c_imx_xfer_common()
1269 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1278 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1283 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1290 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1302 i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD && in i2c_imx_xfer_common()
1313 /* Stop I2C transfer */ in i2c_imx_xfer_common()
1316 dev_dbg(&i2c_imx->adapter.dev, "<%s> exit with: %s: %d\n", __func__, in i2c_imx_xfer_common()
1320 if (i2c_imx->slave) in i2c_imx_xfer_common()
1332 result = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1338 pm_runtime_mark_last_busy(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1339 pm_runtime_put_autosuspend(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1350 result = clk_enable(i2c_imx->clk); in i2c_imx_xfer_atomic()
1356 clk_disable(i2c_imx->clk); in i2c_imx_xfer_atomic()
1371 struct i2c_bus_recovery_info *bri = &i2c_imx->rinfo; in i2c_imx_init_recovery_info()
1373 bri->pinctrl = devm_pinctrl_get(&pdev->dev); in i2c_imx_init_recovery_info()
1374 if (IS_ERR(bri->pinctrl)) in i2c_imx_init_recovery_info()
1375 return PTR_ERR(bri->pinctrl); in i2c_imx_init_recovery_info()
1377 i2c_imx->adapter.bus_recovery_info = bri; in i2c_imx_init_recovery_info()
1400 struct imxi2c_platform_data *pdata = dev_get_platdata(&pdev->dev); in i2c_imx_probe()
1414 phy_addr = (dma_addr_t)res->start; in i2c_imx_probe()
1415 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(*i2c_imx), GFP_KERNEL); in i2c_imx_probe()
1417 return -ENOMEM; in i2c_imx_probe()
1419 spin_lock_init(&i2c_imx->slave_lock); in i2c_imx_probe()
1420 hrtimer_init(&i2c_imx->slave_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in i2c_imx_probe()
1421 i2c_imx->slave_timer.function = i2c_imx_slave_timeout; in i2c_imx_probe()
1423 match = device_get_match_data(&pdev->dev); in i2c_imx_probe()
1425 i2c_imx->hwdata = match; in i2c_imx_probe()
1427 i2c_imx->hwdata = (struct imx_i2c_hwdata *) in i2c_imx_probe()
1428 platform_get_device_id(pdev)->driver_data; in i2c_imx_probe()
1431 strscpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name)); in i2c_imx_probe()
1432 i2c_imx->adapter.owner = THIS_MODULE; in i2c_imx_probe()
1433 i2c_imx->adapter.algo = &i2c_imx_algo; in i2c_imx_probe()
1434 i2c_imx->adapter.dev.parent = &pdev->dev; in i2c_imx_probe()
1435 i2c_imx->adapter.nr = pdev->id; in i2c_imx_probe()
1436 i2c_imx->adapter.dev.of_node = pdev->dev.of_node; in i2c_imx_probe()
1437 i2c_imx->base = base; in i2c_imx_probe()
1438 ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev)); in i2c_imx_probe()
1440 /* Get I2C clock */ in i2c_imx_probe()
1441 i2c_imx->clk = devm_clk_get_enabled(&pdev->dev, NULL); in i2c_imx_probe()
1442 if (IS_ERR(i2c_imx->clk)) in i2c_imx_probe()
1443 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk), in i2c_imx_probe()
1444 "can't get I2C clock\n"); in i2c_imx_probe()
1447 init_waitqueue_head(&i2c_imx->queue); in i2c_imx_probe()
1450 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); in i2c_imx_probe()
1455 pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); in i2c_imx_probe()
1456 pm_runtime_use_autosuspend(&pdev->dev); in i2c_imx_probe()
1457 pm_runtime_set_active(&pdev->dev); in i2c_imx_probe()
1458 pm_runtime_enable(&pdev->dev); in i2c_imx_probe()
1460 ret = pm_runtime_get_sync(&pdev->dev); in i2c_imx_probe()
1465 ret = request_irq(irq, i2c_imx_isr, IRQF_SHARED, pdev->name, i2c_imx); in i2c_imx_probe()
1467 dev_err(&pdev->dev, "can't claim irq %d\n", irq); in i2c_imx_probe()
1472 i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; in i2c_imx_probe()
1473 ret = of_property_read_u32(pdev->dev.of_node, in i2c_imx_probe()
1474 "clock-frequency", &i2c_imx->bitrate); in i2c_imx_probe()
1475 if (ret < 0 && pdata && pdata->bitrate) in i2c_imx_probe()
1476 i2c_imx->bitrate = pdata->bitrate; in i2c_imx_probe()
1477 i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call; in i2c_imx_probe()
1478 clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_probe()
1479 i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk)); in i2c_imx_probe()
1486 if (ret == -EPROBE_DEFER) in i2c_imx_probe()
1489 /* Add I2C adapter */ in i2c_imx_probe()
1490 ret = i2c_add_numbered_adapter(&i2c_imx->adapter); in i2c_imx_probe()
1494 pm_runtime_mark_last_busy(&pdev->dev); in i2c_imx_probe()
1495 pm_runtime_put_autosuspend(&pdev->dev); in i2c_imx_probe()
1497 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq); in i2c_imx_probe()
1498 dev_dbg(&i2c_imx->adapter.dev, "device resources: %pR\n", res); in i2c_imx_probe()
1499 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", in i2c_imx_probe()
1500 i2c_imx->adapter.name); in i2c_imx_probe()
1501 dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); in i2c_imx_probe()
1509 clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_probe()
1512 pm_runtime_put_noidle(&pdev->dev); in i2c_imx_probe()
1513 pm_runtime_disable(&pdev->dev); in i2c_imx_probe()
1514 pm_runtime_set_suspended(&pdev->dev); in i2c_imx_probe()
1515 pm_runtime_dont_use_autosuspend(&pdev->dev); in i2c_imx_probe()
1524 ret = pm_runtime_get_sync(&pdev->dev); in i2c_imx_remove()
1526 hrtimer_cancel(&i2c_imx->slave_timer); in i2c_imx_remove()
1529 dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); in i2c_imx_remove()
1530 i2c_del_adapter(&i2c_imx->adapter); in i2c_imx_remove()
1532 if (i2c_imx->dma) in i2c_imx_remove()
1543 clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_remove()
1548 pm_runtime_put_noidle(&pdev->dev); in i2c_imx_remove()
1549 pm_runtime_disable(&pdev->dev); in i2c_imx_remove()
1556 clk_disable(i2c_imx->clk); in i2c_imx_runtime_suspend()
1566 ret = clk_enable(i2c_imx->clk); in i2c_imx_runtime_resume()
1568 dev_err(dev, "can't enable I2C clock, ret=%d\n", ret); in i2c_imx_runtime_resume()
1603 MODULE_DESCRIPTION("I2C adapter driver for IMX I2C bus");