• Home
  • Raw
  • Download

Lines Matching full:i2c

2 /* linux/drivers/i2c/busses/i2c-s3c2410.c
7 * S3C2410 I2C Controller
13 #include <linux/i2c.h>
34 #include <linux/platform_data/i2c-s3c2410.h>
86 /* i2c controller state */
127 .name = "s3c2410-i2c",
130 .name = "s3c2440-i2c",
133 .name = "s3c2440-hdmiphy-i2c",
139 static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat);
143 { .compatible = "samsung,s3c2410-i2c", .data = (void *)0 },
144 { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 },
145 { .compatible = "samsung,s3c2440-hdmiphy-i2c",
147 { .compatible = "samsung,exynos5-sata-phy-i2c",
173 static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret) in s3c24xx_i2c_master_complete() argument
175 dev_dbg(i2c->dev, "master_complete %d\n", ret); in s3c24xx_i2c_master_complete()
177 i2c->msg_ptr = 0; in s3c24xx_i2c_master_complete()
178 i2c->msg = NULL; in s3c24xx_i2c_master_complete()
179 i2c->msg_idx++; in s3c24xx_i2c_master_complete()
180 i2c->msg_num = 0; in s3c24xx_i2c_master_complete()
182 i2c->msg_idx = ret; in s3c24xx_i2c_master_complete()
184 if (!(i2c->quirks & QUIRK_POLL)) in s3c24xx_i2c_master_complete()
185 wake_up(&i2c->wait); in s3c24xx_i2c_master_complete()
188 static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_disable_ack() argument
192 tmp = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_disable_ack()
193 writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_disable_ack()
196 static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_enable_ack() argument
200 tmp = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_enable_ack()
201 writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_enable_ack()
205 static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_disable_irq() argument
209 tmp = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_disable_irq()
210 writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_disable_irq()
213 static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_enable_irq() argument
217 tmp = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_enable_irq()
218 writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_enable_irq()
221 static bool is_ack(struct s3c24xx_i2c *i2c) in is_ack() argument
226 unsigned long tmp = readl(i2c->regs + S3C2410_IICCON); in is_ack()
237 if (!(readl(i2c->regs + S3C2410_IICSTAT) in is_ack()
243 dev_err(i2c->dev, "ack was not received\n"); in is_ack()
250 static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, in s3c24xx_i2c_message_start() argument
270 s3c24xx_i2c_enable_ack(i2c); in s3c24xx_i2c_message_start()
272 iiccon = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_message_start()
273 writel(stat, i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_message_start()
275 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); in s3c24xx_i2c_message_start()
276 writeb(addr, i2c->regs + S3C2410_IICDS); in s3c24xx_i2c_message_start()
282 ndelay(i2c->tx_setup); in s3c24xx_i2c_message_start()
284 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); in s3c24xx_i2c_message_start()
285 writel(iiccon, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_message_start()
288 writel(stat, i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_message_start()
291 static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) in s3c24xx_i2c_stop() argument
293 unsigned long iicstat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_stop()
295 dev_dbg(i2c->dev, "STOP\n"); in s3c24xx_i2c_stop()
331 if (i2c->quirks & QUIRK_HDMIPHY) { in s3c24xx_i2c_stop()
332 /* Stop driving the I2C pins */ in s3c24xx_i2c_stop()
338 writel(iicstat, i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_stop()
340 i2c->state = STATE_STOP; in s3c24xx_i2c_stop()
342 s3c24xx_i2c_master_complete(i2c, ret); in s3c24xx_i2c_stop()
343 s3c24xx_i2c_disable_irq(i2c); in s3c24xx_i2c_stop()
354 static inline int is_lastmsg(struct s3c24xx_i2c *i2c) in is_lastmsg() argument
356 return i2c->msg_idx >= (i2c->msg_num - 1); in is_lastmsg()
362 static inline int is_msglast(struct s3c24xx_i2c *i2c) in is_msglast() argument
369 if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1) in is_msglast()
372 return i2c->msg_ptr == i2c->msg->len-1; in is_msglast()
378 static inline int is_msgend(struct s3c24xx_i2c *i2c) in is_msgend() argument
380 return i2c->msg_ptr >= i2c->msg->len; in is_msgend()
386 static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) in i2c_s3c_irq_nextbyte() argument
392 switch (i2c->state) { in i2c_s3c_irq_nextbyte()
395 dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__); in i2c_s3c_irq_nextbyte()
399 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); in i2c_s3c_irq_nextbyte()
400 s3c24xx_i2c_disable_irq(i2c); in i2c_s3c_irq_nextbyte()
406 * bus, or started a new i2c message in i2c_s3c_irq_nextbyte()
409 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { in i2c_s3c_irq_nextbyte()
411 dev_dbg(i2c->dev, "ack was not received\n"); in i2c_s3c_irq_nextbyte()
412 s3c24xx_i2c_stop(i2c, -ENXIO); in i2c_s3c_irq_nextbyte()
416 if (i2c->msg->flags & I2C_M_RD) in i2c_s3c_irq_nextbyte()
417 i2c->state = STATE_READ; in i2c_s3c_irq_nextbyte()
419 i2c->state = STATE_WRITE; in i2c_s3c_irq_nextbyte()
423 * as this is used by the i2c probe to find devices. in i2c_s3c_irq_nextbyte()
425 if (is_lastmsg(i2c) && i2c->msg->len == 0) { in i2c_s3c_irq_nextbyte()
426 s3c24xx_i2c_stop(i2c, 0); in i2c_s3c_irq_nextbyte()
430 if (i2c->state == STATE_READ) in i2c_s3c_irq_nextbyte()
443 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) { in i2c_s3c_irq_nextbyte()
445 dev_dbg(i2c->dev, "WRITE: No Ack\n"); in i2c_s3c_irq_nextbyte()
447 s3c24xx_i2c_stop(i2c, -ECONNREFUSED); in i2c_s3c_irq_nextbyte()
454 if (!is_msgend(i2c)) { in i2c_s3c_irq_nextbyte()
455 byte = i2c->msg->buf[i2c->msg_ptr++]; in i2c_s3c_irq_nextbyte()
456 writeb(byte, i2c->regs + S3C2410_IICDS); in i2c_s3c_irq_nextbyte()
465 ndelay(i2c->tx_setup); in i2c_s3c_irq_nextbyte()
467 } else if (!is_lastmsg(i2c)) { in i2c_s3c_irq_nextbyte()
468 /* we need to go to the next i2c message */ in i2c_s3c_irq_nextbyte()
470 dev_dbg(i2c->dev, "WRITE: Next Message\n"); in i2c_s3c_irq_nextbyte()
472 i2c->msg_ptr = 0; in i2c_s3c_irq_nextbyte()
473 i2c->msg_idx++; in i2c_s3c_irq_nextbyte()
474 i2c->msg++; in i2c_s3c_irq_nextbyte()
477 if (i2c->msg->flags & I2C_M_NOSTART) { in i2c_s3c_irq_nextbyte()
479 if (i2c->msg->flags & I2C_M_RD) { in i2c_s3c_irq_nextbyte()
485 dev_dbg(i2c->dev, in i2c_s3c_irq_nextbyte()
487 s3c24xx_i2c_stop(i2c, -EINVAL); in i2c_s3c_irq_nextbyte()
494 s3c24xx_i2c_message_start(i2c, i2c->msg); in i2c_s3c_irq_nextbyte()
495 i2c->state = STATE_START; in i2c_s3c_irq_nextbyte()
500 s3c24xx_i2c_stop(i2c, 0); in i2c_s3c_irq_nextbyte()
510 byte = readb(i2c->regs + S3C2410_IICDS); in i2c_s3c_irq_nextbyte()
511 i2c->msg->buf[i2c->msg_ptr++] = byte; in i2c_s3c_irq_nextbyte()
514 if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1) in i2c_s3c_irq_nextbyte()
515 i2c->msg->len += byte; in i2c_s3c_irq_nextbyte()
517 if (is_msglast(i2c)) { in i2c_s3c_irq_nextbyte()
520 if (is_lastmsg(i2c)) in i2c_s3c_irq_nextbyte()
521 s3c24xx_i2c_disable_ack(i2c); in i2c_s3c_irq_nextbyte()
523 } else if (is_msgend(i2c)) { in i2c_s3c_irq_nextbyte()
528 if (is_lastmsg(i2c)) { in i2c_s3c_irq_nextbyte()
530 dev_dbg(i2c->dev, "READ: Send Stop\n"); in i2c_s3c_irq_nextbyte()
532 s3c24xx_i2c_stop(i2c, 0); in i2c_s3c_irq_nextbyte()
535 dev_dbg(i2c->dev, "READ: Next Transfer\n"); in i2c_s3c_irq_nextbyte()
537 i2c->msg_ptr = 0; in i2c_s3c_irq_nextbyte()
538 i2c->msg_idx++; in i2c_s3c_irq_nextbyte()
539 i2c->msg++; in i2c_s3c_irq_nextbyte()
549 tmp = readl(i2c->regs + S3C2410_IICCON); in i2c_s3c_irq_nextbyte()
551 writel(tmp, i2c->regs + S3C2410_IICCON); in i2c_s3c_irq_nextbyte()
561 struct s3c24xx_i2c *i2c = dev_id; in s3c24xx_i2c_irq() local
565 status = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_irq()
569 dev_err(i2c->dev, "deal with arbitration loss\n"); in s3c24xx_i2c_irq()
572 if (i2c->state == STATE_IDLE) { in s3c24xx_i2c_irq()
573 dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); in s3c24xx_i2c_irq()
575 tmp = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_irq()
577 writel(tmp, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_irq()
585 i2c_s3c_irq_nextbyte(i2c, status); in s3c24xx_i2c_irq()
597 * kernel boot time, we may not notice the event and the I2C controller
598 * will lock the bus with the I2C clock line low indefinitely.
600 static inline void s3c24xx_i2c_disable_bus(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_disable_bus() argument
604 /* Stop driving the I2C pins */ in s3c24xx_i2c_disable_bus()
605 tmp = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_disable_bus()
607 writel(tmp, i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_disable_bus()
610 tmp = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_disable_bus()
613 writel(tmp, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_disable_bus()
618 * get the i2c bus for a master transaction
620 static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_set_master() argument
626 iicstat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_set_master()
638 * wait for the i2c bus to become idle.
640 static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_wait_idle() argument
649 dev_dbg(i2c->dev, "waiting for bus idle\n"); in s3c24xx_i2c_wait_idle()
655 * end of a transaction. However, really slow i2c devices can stretch in s3c24xx_i2c_wait_idle()
662 iicstat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_wait_idle()
665 iicstat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_wait_idle()
682 iicstat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_wait_idle()
686 dev_warn(i2c->dev, "timeout waiting for bus idle\n"); in s3c24xx_i2c_wait_idle()
690 * this starts an i2c transfer
692 static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, in s3c24xx_i2c_doxfer() argument
698 ret = s3c24xx_i2c_set_master(i2c); in s3c24xx_i2c_doxfer()
700 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); in s3c24xx_i2c_doxfer()
705 i2c->msg = msgs; in s3c24xx_i2c_doxfer()
706 i2c->msg_num = num; in s3c24xx_i2c_doxfer()
707 i2c->msg_ptr = 0; in s3c24xx_i2c_doxfer()
708 i2c->msg_idx = 0; in s3c24xx_i2c_doxfer()
709 i2c->state = STATE_START; in s3c24xx_i2c_doxfer()
711 s3c24xx_i2c_enable_irq(i2c); in s3c24xx_i2c_doxfer()
712 s3c24xx_i2c_message_start(i2c, msgs); in s3c24xx_i2c_doxfer()
714 if (i2c->quirks & QUIRK_POLL) { in s3c24xx_i2c_doxfer()
715 while ((i2c->msg_num != 0) && is_ack(i2c)) { in s3c24xx_i2c_doxfer()
716 unsigned long stat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_doxfer()
718 i2c_s3c_irq_nextbyte(i2c, stat); in s3c24xx_i2c_doxfer()
720 stat = readl(i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_doxfer()
722 dev_err(i2c->dev, "deal with arbitration loss\n"); in s3c24xx_i2c_doxfer()
725 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); in s3c24xx_i2c_doxfer()
728 ret = i2c->msg_idx; in s3c24xx_i2c_doxfer()
735 dev_dbg(i2c->dev, "timeout\n"); in s3c24xx_i2c_doxfer()
737 dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret); in s3c24xx_i2c_doxfer()
740 if (i2c->quirks & QUIRK_HDMIPHY) in s3c24xx_i2c_doxfer()
743 s3c24xx_i2c_wait_idle(i2c); in s3c24xx_i2c_doxfer()
745 s3c24xx_i2c_disable_bus(i2c); in s3c24xx_i2c_doxfer()
748 i2c->state = STATE_IDLE; in s3c24xx_i2c_doxfer()
754 * first port of call from the i2c bus code when an message needs
755 * transferring across the i2c bus.
760 struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data; in s3c24xx_i2c_xfer() local
764 ret = clk_enable(i2c->clk); in s3c24xx_i2c_xfer()
770 ret = s3c24xx_i2c_doxfer(i2c, msgs, num); in s3c24xx_i2c_xfer()
773 clk_disable(i2c->clk); in s3c24xx_i2c_xfer()
777 dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry); in s3c24xx_i2c_xfer()
782 clk_disable(i2c->clk); in s3c24xx_i2c_xfer()
786 /* declare our i2c functionality */
793 /* i2c bus registration info */
832 static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) in s3c24xx_i2c_clockrate() argument
834 struct s3c2410_platform_i2c *pdata = i2c->pdata; in s3c24xx_i2c_clockrate()
835 unsigned long clkin = clk_get_rate(i2c->clk); in s3c24xx_i2c_clockrate()
841 i2c->clkrate = clkin; in s3c24xx_i2c_clockrate()
844 dev_dbg(i2c->dev, "pdata desired frequency %lu\n", pdata->frequency); in s3c24xx_i2c_clockrate()
853 dev_err(i2c->dev, in s3c24xx_i2c_clockrate()
861 iiccon = readl(i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_clockrate()
868 if (i2c->quirks & QUIRK_POLL) in s3c24xx_i2c_clockrate()
871 writel(iiccon, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_clockrate()
873 if (i2c->quirks & QUIRK_S3C2440) { in s3c24xx_i2c_clockrate()
886 dev_dbg(i2c->dev, "IICLC=%08lx\n", sda_delay); in s3c24xx_i2c_clockrate()
887 writel(sda_delay, i2c->regs + S3C2440_IICLC); in s3c24xx_i2c_clockrate()
900 struct s3c24xx_i2c *i2c = freq_to_i2c(nb); in s3c24xx_i2c_cpufreq_transition() local
905 delta_f = clk_get_rate(i2c->clk) - i2c->clkrate; in s3c24xx_i2c_cpufreq_transition()
914 i2c_lock_bus(&i2c->adap, I2C_LOCK_ROOT_ADAPTER); in s3c24xx_i2c_cpufreq_transition()
915 ret = s3c24xx_i2c_clockrate(i2c, &got); in s3c24xx_i2c_cpufreq_transition()
916 i2c_unlock_bus(&i2c->adap, I2C_LOCK_ROOT_ADAPTER); in s3c24xx_i2c_cpufreq_transition()
919 dev_err(i2c->dev, "cannot find frequency (%d)\n", ret); in s3c24xx_i2c_cpufreq_transition()
921 dev_info(i2c->dev, "setting freq %d\n", got); in s3c24xx_i2c_cpufreq_transition()
927 static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_register_cpufreq() argument
929 i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition; in s3c24xx_i2c_register_cpufreq()
931 return cpufreq_register_notifier(&i2c->freq_transition, in s3c24xx_i2c_register_cpufreq()
935 static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_deregister_cpufreq() argument
937 cpufreq_unregister_notifier(&i2c->freq_transition, in s3c24xx_i2c_deregister_cpufreq()
942 static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_register_cpufreq() argument
947 static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_deregister_cpufreq() argument
953 static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_parse_dt_gpio() argument
957 if (i2c->quirks & QUIRK_NO_GPIO) in s3c24xx_i2c_parse_dt_gpio()
961 i2c->gpios[i] = devm_gpiod_get_index(i2c->dev, NULL, in s3c24xx_i2c_parse_dt_gpio()
963 if (IS_ERR(i2c->gpios[i])) { in s3c24xx_i2c_parse_dt_gpio()
964 dev_err(i2c->dev, "i2c gpio invalid at index %d\n", i); in s3c24xx_i2c_parse_dt_gpio()
972 static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_parse_dt_gpio() argument
981 static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) in s3c24xx_i2c_init() argument
988 pdata = i2c->pdata; in s3c24xx_i2c_init()
992 writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); in s3c24xx_i2c_init()
994 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); in s3c24xx_i2c_init()
996 writel(0, i2c->regs + S3C2410_IICCON); in s3c24xx_i2c_init()
997 writel(0, i2c->regs + S3C2410_IICSTAT); in s3c24xx_i2c_init()
1001 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) { in s3c24xx_i2c_init()
1002 dev_err(i2c->dev, "cannot meet bus frequency required\n"); in s3c24xx_i2c_init()
1006 /* todo - check that the i2c lines aren't being dragged anywhere */ in s3c24xx_i2c_init()
1008 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); in s3c24xx_i2c_init()
1009 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02x\n", in s3c24xx_i2c_init()
1010 readl(i2c->regs + S3C2410_IICCON)); in s3c24xx_i2c_init()
1020 s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c) in s3c24xx_i2c_parse_dt() argument
1022 struct s3c2410_platform_i2c *pdata = i2c->pdata; in s3c24xx_i2c_parse_dt()
1028 pdata->bus_num = -1; /* i2c bus number is dynamically assigned */ in s3c24xx_i2c_parse_dt()
1029 of_property_read_u32(np, "samsung,i2c-sda-delay", &pdata->sda_delay); in s3c24xx_i2c_parse_dt()
1030 of_property_read_u32(np, "samsung,i2c-slave-addr", &pdata->slave_addr); in s3c24xx_i2c_parse_dt()
1031 of_property_read_u32(np, "samsung,i2c-max-bus-freq", in s3c24xx_i2c_parse_dt()
1034 * Exynos5's legacy i2c controller and new high speed i2c in s3c24xx_i2c_parse_dt()
1036 * interrupts for 4-channel HS-I2C controller are enabled. in s3c24xx_i2c_parse_dt()
1037 * If nodes for first four channels of legacy i2c controller in s3c24xx_i2c_parse_dt()
1041 id = of_alias_get_id(np, "i2c"); in s3c24xx_i2c_parse_dt()
1042 i2c->sysreg = syscon_regmap_lookup_by_phandle(np, in s3c24xx_i2c_parse_dt()
1044 if (IS_ERR(i2c->sysreg)) in s3c24xx_i2c_parse_dt()
1047 regmap_update_bits(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, BIT(id), 0); in s3c24xx_i2c_parse_dt()
1051 s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c) { } in s3c24xx_i2c_parse_dt() argument
1056 struct s3c24xx_i2c *i2c; in s3c24xx_i2c_probe() local
1069 i2c = devm_kzalloc(&pdev->dev, sizeof(struct s3c24xx_i2c), GFP_KERNEL); in s3c24xx_i2c_probe()
1070 if (!i2c) in s3c24xx_i2c_probe()
1073 i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in s3c24xx_i2c_probe()
1074 if (!i2c->pdata) in s3c24xx_i2c_probe()
1077 i2c->quirks = s3c24xx_get_device_quirks(pdev); in s3c24xx_i2c_probe()
1078 i2c->sysreg = ERR_PTR(-ENOENT); in s3c24xx_i2c_probe()
1080 memcpy(i2c->pdata, pdata, sizeof(*pdata)); in s3c24xx_i2c_probe()
1082 s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c); in s3c24xx_i2c_probe()
1084 strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name)); in s3c24xx_i2c_probe()
1085 i2c->adap.owner = THIS_MODULE; in s3c24xx_i2c_probe()
1086 i2c->adap.algo = &s3c24xx_i2c_algorithm; in s3c24xx_i2c_probe()
1087 i2c->adap.retries = 2; in s3c24xx_i2c_probe()
1088 i2c->adap.class = I2C_CLASS_DEPRECATED; in s3c24xx_i2c_probe()
1089 i2c->tx_setup = 50; in s3c24xx_i2c_probe()
1091 init_waitqueue_head(&i2c->wait); in s3c24xx_i2c_probe()
1094 i2c->dev = &pdev->dev; in s3c24xx_i2c_probe()
1095 i2c->clk = devm_clk_get(&pdev->dev, "i2c"); in s3c24xx_i2c_probe()
1096 if (IS_ERR(i2c->clk)) { in s3c24xx_i2c_probe()
1101 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); in s3c24xx_i2c_probe()
1105 i2c->regs = devm_ioremap_resource(&pdev->dev, res); in s3c24xx_i2c_probe()
1107 if (IS_ERR(i2c->regs)) in s3c24xx_i2c_probe()
1108 return PTR_ERR(i2c->regs); in s3c24xx_i2c_probe()
1111 i2c->regs, res); in s3c24xx_i2c_probe()
1113 /* setup info block for the i2c core */ in s3c24xx_i2c_probe()
1114 i2c->adap.algo_data = i2c; in s3c24xx_i2c_probe()
1115 i2c->adap.dev.parent = &pdev->dev; in s3c24xx_i2c_probe()
1116 i2c->pctrl = devm_pinctrl_get_select_default(i2c->dev); in s3c24xx_i2c_probe()
1118 /* inititalise the i2c gpio lines */ in s3c24xx_i2c_probe()
1119 if (i2c->pdata->cfg_gpio) in s3c24xx_i2c_probe()
1120 i2c->pdata->cfg_gpio(to_platform_device(i2c->dev)); in s3c24xx_i2c_probe()
1121 else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c)) in s3c24xx_i2c_probe()
1124 /* initialise the i2c controller */ in s3c24xx_i2c_probe()
1125 ret = clk_prepare_enable(i2c->clk); in s3c24xx_i2c_probe()
1127 dev_err(&pdev->dev, "I2C clock enable failed\n"); in s3c24xx_i2c_probe()
1131 ret = s3c24xx_i2c_init(i2c); in s3c24xx_i2c_probe()
1132 clk_disable(i2c->clk); in s3c24xx_i2c_probe()
1134 dev_err(&pdev->dev, "I2C controller init failed\n"); in s3c24xx_i2c_probe()
1135 clk_unprepare(i2c->clk); in s3c24xx_i2c_probe()
1143 if (!(i2c->quirks & QUIRK_POLL)) { in s3c24xx_i2c_probe()
1144 i2c->irq = ret = platform_get_irq(pdev, 0); in s3c24xx_i2c_probe()
1147 clk_unprepare(i2c->clk); in s3c24xx_i2c_probe()
1151 ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, in s3c24xx_i2c_probe()
1152 0, dev_name(&pdev->dev), i2c); in s3c24xx_i2c_probe()
1154 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); in s3c24xx_i2c_probe()
1155 clk_unprepare(i2c->clk); in s3c24xx_i2c_probe()
1160 ret = s3c24xx_i2c_register_cpufreq(i2c); in s3c24xx_i2c_probe()
1163 clk_unprepare(i2c->clk); in s3c24xx_i2c_probe()
1173 i2c->adap.nr = i2c->pdata->bus_num; in s3c24xx_i2c_probe()
1174 i2c->adap.dev.of_node = pdev->dev.of_node; in s3c24xx_i2c_probe()
1176 platform_set_drvdata(pdev, i2c); in s3c24xx_i2c_probe()
1180 ret = i2c_add_numbered_adapter(&i2c->adap); in s3c24xx_i2c_probe()
1183 s3c24xx_i2c_deregister_cpufreq(i2c); in s3c24xx_i2c_probe()
1184 clk_unprepare(i2c->clk); in s3c24xx_i2c_probe()
1188 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev)); in s3c24xx_i2c_probe()
1194 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); in s3c24xx_i2c_remove() local
1196 clk_unprepare(i2c->clk); in s3c24xx_i2c_remove()
1200 s3c24xx_i2c_deregister_cpufreq(i2c); in s3c24xx_i2c_remove()
1202 i2c_del_adapter(&i2c->adap); in s3c24xx_i2c_remove()
1210 struct s3c24xx_i2c *i2c = dev_get_drvdata(dev); in s3c24xx_i2c_suspend_noirq() local
1212 i2c_mark_adapter_suspended(&i2c->adap); in s3c24xx_i2c_suspend_noirq()
1214 if (!IS_ERR(i2c->sysreg)) in s3c24xx_i2c_suspend_noirq()
1215 regmap_read(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, &i2c->sys_i2c_cfg); in s3c24xx_i2c_suspend_noirq()
1222 struct s3c24xx_i2c *i2c = dev_get_drvdata(dev); in s3c24xx_i2c_resume_noirq() local
1225 if (!IS_ERR(i2c->sysreg)) in s3c24xx_i2c_resume_noirq()
1226 regmap_write(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, i2c->sys_i2c_cfg); in s3c24xx_i2c_resume_noirq()
1228 ret = clk_enable(i2c->clk); in s3c24xx_i2c_resume_noirq()
1231 s3c24xx_i2c_init(i2c); in s3c24xx_i2c_resume_noirq()
1232 clk_disable(i2c->clk); in s3c24xx_i2c_resume_noirq()
1233 i2c_mark_adapter_resumed(&i2c->adap); in s3c24xx_i2c_resume_noirq()
1255 .name = "s3c-i2c",
1273 MODULE_DESCRIPTION("S3C24XX I2C Bus driver");