Lines Matching refs:i2c

414 static void img_i2c_writel(struct img_i2c *i2c, u32 offset, u32 value)  in img_i2c_writel()  argument
416 writel(value, i2c->base + offset); in img_i2c_writel()
419 static u32 img_i2c_readl(struct img_i2c *i2c, u32 offset) in img_i2c_readl() argument
421 return readl(i2c->base + offset); in img_i2c_readl()
436 static void img_i2c_wr_rd_fence(struct img_i2c *i2c) in img_i2c_wr_rd_fence() argument
438 if (i2c->need_wr_rd_fence) { in img_i2c_wr_rd_fence()
439 img_i2c_writel(i2c, SCB_CORE_REV_REG, 0); in img_i2c_wr_rd_fence()
440 img_i2c_writel(i2c, SCB_CORE_REV_REG, 0); in img_i2c_wr_rd_fence()
444 static void img_i2c_switch_mode(struct img_i2c *i2c, enum img_i2c_mode mode) in img_i2c_switch_mode() argument
446 i2c->mode = mode; in img_i2c_switch_mode()
447 i2c->int_enable = img_i2c_int_enable_by_mode[mode]; in img_i2c_switch_mode()
448 i2c->line_status = 0; in img_i2c_switch_mode()
451 static void img_i2c_raw_op(struct img_i2c *i2c) in img_i2c_raw_op() argument
453 i2c->raw_timeout = 0; in img_i2c_raw_op()
454 img_i2c_writel(i2c, SCB_OVERRIDE_REG, in img_i2c_raw_op()
460 ((i2c->at_cur_cmd & OVERRIDE_CMD_MASK) << OVERRIDE_CMD_SHIFT) | in img_i2c_raw_op()
461 (i2c->at_cur_data << OVERRIDE_DATA_SHIFT)); in img_i2c_raw_op()
472 static void img_i2c_atomic_op(struct img_i2c *i2c, int cmd, u8 data) in img_i2c_atomic_op() argument
474 i2c->at_cur_cmd = cmd; in img_i2c_atomic_op()
475 i2c->at_cur_data = data; in img_i2c_atomic_op()
478 if (cmd == CMD_GEN_DATA && i2c->mode == MODE_ATOMIC) { in img_i2c_atomic_op()
479 u32 line_status = img_i2c_readl(i2c, SCB_STATUS_REG); in img_i2c_atomic_op()
483 img_i2c_switch_mode(i2c, MODE_RAW); in img_i2c_atomic_op()
484 img_i2c_raw_op(i2c); in img_i2c_atomic_op()
489 dev_dbg(i2c->adap.dev.parent, in img_i2c_atomic_op()
492 i2c->at_t_done = (cmd == CMD_RET_DATA || cmd == CMD_RET_ACK); in img_i2c_atomic_op()
493 i2c->at_slave_event = false; in img_i2c_atomic_op()
494 i2c->line_status = 0; in img_i2c_atomic_op()
496 img_i2c_writel(i2c, SCB_OVERRIDE_REG, in img_i2c_atomic_op()
504 static void img_i2c_atomic_start(struct img_i2c *i2c) in img_i2c_atomic_start() argument
506 img_i2c_switch_mode(i2c, MODE_ATOMIC); in img_i2c_atomic_start()
507 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_atomic_start()
508 img_i2c_atomic_op(i2c, CMD_GEN_START, 0x00); in img_i2c_atomic_start()
511 static void img_i2c_soft_reset(struct img_i2c *i2c) in img_i2c_soft_reset() argument
513 i2c->t_halt = false; in img_i2c_soft_reset()
514 img_i2c_writel(i2c, SCB_CONTROL_REG, 0); in img_i2c_soft_reset()
515 img_i2c_writel(i2c, SCB_CONTROL_REG, in img_i2c_soft_reset()
530 static void img_i2c_transaction_halt(struct img_i2c *i2c, bool t_halt) in img_i2c_transaction_halt() argument
534 if (i2c->t_halt == t_halt) in img_i2c_transaction_halt()
536 i2c->t_halt = t_halt; in img_i2c_transaction_halt()
537 val = img_i2c_readl(i2c, SCB_CONTROL_REG); in img_i2c_transaction_halt()
542 img_i2c_writel(i2c, SCB_CONTROL_REG, val); in img_i2c_transaction_halt()
546 static void img_i2c_read_fifo(struct img_i2c *i2c) in img_i2c_read_fifo() argument
548 while (i2c->msg.len) { in img_i2c_read_fifo()
552 img_i2c_wr_rd_fence(i2c); in img_i2c_read_fifo()
553 fifo_status = img_i2c_readl(i2c, SCB_FIFO_STATUS_REG); in img_i2c_read_fifo()
557 data = img_i2c_readl(i2c, SCB_READ_DATA_REG); in img_i2c_read_fifo()
558 *i2c->msg.buf = data; in img_i2c_read_fifo()
560 img_i2c_writel(i2c, SCB_READ_FIFO_REG, 0xff); in img_i2c_read_fifo()
561 i2c->msg.len--; in img_i2c_read_fifo()
562 i2c->msg.buf++; in img_i2c_read_fifo()
567 static void img_i2c_write_fifo(struct img_i2c *i2c) in img_i2c_write_fifo() argument
569 while (i2c->msg.len) { in img_i2c_write_fifo()
572 img_i2c_wr_rd_fence(i2c); in img_i2c_write_fifo()
573 fifo_status = img_i2c_readl(i2c, SCB_FIFO_STATUS_REG); in img_i2c_write_fifo()
577 img_i2c_writel(i2c, SCB_WRITE_DATA_REG, *i2c->msg.buf); in img_i2c_write_fifo()
578 i2c->msg.len--; in img_i2c_write_fifo()
579 i2c->msg.buf++; in img_i2c_write_fifo()
583 if (!i2c->msg.len) in img_i2c_write_fifo()
584 i2c->int_enable &= ~INT_FIFO_EMPTYING; in img_i2c_write_fifo()
588 static void img_i2c_read(struct img_i2c *i2c) in img_i2c_read() argument
590 img_i2c_switch_mode(i2c, MODE_AUTOMATIC); in img_i2c_read()
591 if (!i2c->last_msg) in img_i2c_read()
592 i2c->int_enable |= INT_SLAVE_EVENT; in img_i2c_read()
594 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_read()
595 img_i2c_writel(i2c, SCB_READ_ADDR_REG, i2c->msg.addr); in img_i2c_read()
596 img_i2c_writel(i2c, SCB_READ_COUNT_REG, i2c->msg.len); in img_i2c_read()
598 mod_timer(&i2c->check_timer, jiffies + msecs_to_jiffies(1)); in img_i2c_read()
602 static void img_i2c_write(struct img_i2c *i2c) in img_i2c_write() argument
604 img_i2c_switch_mode(i2c, MODE_AUTOMATIC); in img_i2c_write()
605 if (!i2c->last_msg) in img_i2c_write()
606 i2c->int_enable |= INT_SLAVE_EVENT; in img_i2c_write()
608 img_i2c_writel(i2c, SCB_WRITE_ADDR_REG, i2c->msg.addr); in img_i2c_write()
609 img_i2c_writel(i2c, SCB_WRITE_COUNT_REG, i2c->msg.len); in img_i2c_write()
611 mod_timer(&i2c->check_timer, jiffies + msecs_to_jiffies(1)); in img_i2c_write()
612 img_i2c_write_fifo(i2c); in img_i2c_write()
615 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_write()
623 static void img_i2c_complete_transaction(struct img_i2c *i2c, int status) in img_i2c_complete_transaction() argument
625 img_i2c_switch_mode(i2c, MODE_INACTIVE); in img_i2c_complete_transaction()
627 i2c->msg_status = status; in img_i2c_complete_transaction()
628 img_i2c_transaction_halt(i2c, false); in img_i2c_complete_transaction()
630 complete(&i2c->msg_complete); in img_i2c_complete_transaction()
633 static unsigned int img_i2c_raw_atomic_delay_handler(struct img_i2c *i2c, in img_i2c_raw_atomic_delay_handler() argument
637 img_i2c_atomic_op(i2c, i2c->at_cur_cmd, i2c->at_cur_data); in img_i2c_raw_atomic_delay_handler()
638 img_i2c_switch_mode(i2c, MODE_ATOMIC); in img_i2c_raw_atomic_delay_handler()
642 static unsigned int img_i2c_raw(struct img_i2c *i2c, u32 int_status, in img_i2c_raw() argument
646 if (i2c->raw_timeout == 0) in img_i2c_raw()
647 return img_i2c_raw_atomic_delay_handler(i2c, in img_i2c_raw()
649 --i2c->raw_timeout; in img_i2c_raw()
654 static unsigned int img_i2c_sequence(struct img_i2c *i2c, u32 int_status) in img_i2c_sequence() argument
667 i2c->at_slave_event = true; in img_i2c_sequence()
669 i2c->at_t_done = true; in img_i2c_sequence()
671 if (!i2c->at_slave_event || !i2c->at_t_done) in img_i2c_sequence()
675 if (i2c->at_cur_cmd >= 0 && in img_i2c_sequence()
676 i2c->at_cur_cmd < ARRAY_SIZE(continue_bits)) { in img_i2c_sequence()
677 unsigned int cont_bits = continue_bits[i2c->at_cur_cmd]; in img_i2c_sequence()
681 if (!(i2c->line_status & cont_bits)) in img_i2c_sequence()
687 next_cmd = *i2c->seq; in img_i2c_sequence()
690 img_i2c_writel(i2c, SCB_OVERRIDE_REG, 0); in img_i2c_sequence()
695 ++i2c->seq; in img_i2c_sequence()
696 next_data = *i2c->seq; in img_i2c_sequence()
698 ++i2c->seq; in img_i2c_sequence()
699 img_i2c_atomic_op(i2c, next_cmd, next_data); in img_i2c_sequence()
704 static void img_i2c_reset_start(struct img_i2c *i2c) in img_i2c_reset_start() argument
707 img_i2c_switch_mode(i2c, MODE_SEQUENCE); in img_i2c_reset_start()
708 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_reset_start()
709 i2c->seq = img_i2c_reset_seq; in img_i2c_reset_start()
710 i2c->at_slave_event = true; in img_i2c_reset_start()
711 i2c->at_t_done = true; in img_i2c_reset_start()
712 i2c->at_cur_cmd = -1; in img_i2c_reset_start()
715 img_i2c_sequence(i2c, 0); in img_i2c_reset_start()
718 static void img_i2c_stop_start(struct img_i2c *i2c) in img_i2c_stop_start() argument
721 img_i2c_switch_mode(i2c, MODE_SEQUENCE); in img_i2c_stop_start()
722 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_stop_start()
723 i2c->seq = img_i2c_stop_seq; in img_i2c_stop_start()
724 i2c->at_slave_event = true; in img_i2c_stop_start()
725 i2c->at_t_done = true; in img_i2c_stop_start()
726 i2c->at_cur_cmd = -1; in img_i2c_stop_start()
729 img_i2c_sequence(i2c, 0); in img_i2c_stop_start()
732 static unsigned int img_i2c_atomic(struct img_i2c *i2c, in img_i2c_atomic() argument
740 i2c->at_slave_event = true; in img_i2c_atomic()
742 i2c->at_t_done = true; in img_i2c_atomic()
744 if (!i2c->at_slave_event || !i2c->at_t_done) in img_i2c_atomic()
746 if (i2c->line_status & LINESTAT_ABORT_DET) { in img_i2c_atomic()
747 dev_dbg(i2c->adap.dev.parent, "abort condition detected\n"); in img_i2c_atomic()
749 i2c->msg_status = -EIO; in img_i2c_atomic()
754 switch (i2c->at_cur_cmd) { in img_i2c_atomic()
757 next_data = i2c_8bit_addr_from_msg(&i2c->msg); in img_i2c_atomic()
760 if (i2c->line_status & LINESTAT_INPUT_HELD_V) in img_i2c_atomic()
764 if (i2c->line_status & LINESTAT_ACK_DET || in img_i2c_atomic()
765 (i2c->line_status & LINESTAT_NACK_DET && in img_i2c_atomic()
766 i2c->msg.flags & I2C_M_IGNORE_NAK)) { in img_i2c_atomic()
767 if (i2c->msg.len == 0) { in img_i2c_atomic()
769 } else if (i2c->msg.flags & I2C_M_RD) { in img_i2c_atomic()
773 next_data = *i2c->msg.buf; in img_i2c_atomic()
774 --i2c->msg.len; in img_i2c_atomic()
775 ++i2c->msg.buf; in img_i2c_atomic()
777 } else if (i2c->line_status & LINESTAT_NACK_DET) { in img_i2c_atomic()
778 i2c->msg_status = -EIO; in img_i2c_atomic()
783 if (i2c->line_status & LINESTAT_INPUT_HELD_V) { in img_i2c_atomic()
784 *i2c->msg.buf = (i2c->line_status & in img_i2c_atomic()
787 --i2c->msg.len; in img_i2c_atomic()
788 ++i2c->msg.buf; in img_i2c_atomic()
789 if (i2c->msg.len) in img_i2c_atomic()
796 if (i2c->line_status & LINESTAT_ACK_DET) { in img_i2c_atomic()
799 i2c->msg_status = -EIO; in img_i2c_atomic()
807 img_i2c_writel(i2c, SCB_OVERRIDE_REG, 0); in img_i2c_atomic()
810 dev_err(i2c->adap.dev.parent, "bad atomic command %d\n", in img_i2c_atomic()
811 i2c->at_cur_cmd); in img_i2c_atomic()
812 i2c->msg_status = -EIO; in img_i2c_atomic()
820 if (next_cmd == CMD_GEN_STOP && !i2c->msg_status && in img_i2c_atomic()
821 !i2c->last_msg) in img_i2c_atomic()
823 img_i2c_atomic_op(i2c, next_cmd, next_data); in img_i2c_atomic()
834 struct img_i2c *i2c = from_timer(i2c, t, check_timer); in img_i2c_check_timer() local
838 spin_lock_irqsave(&i2c->lock, flags); in img_i2c_check_timer()
839 line_status = img_i2c_readl(i2c, SCB_STATUS_REG); in img_i2c_check_timer()
843 dev_dbg(i2c->adap.dev.parent, in img_i2c_check_timer()
846 img_i2c_writel(i2c, SCB_INT_MASK_REG, in img_i2c_check_timer()
847 i2c->int_enable | INT_SLAVE_EVENT); in img_i2c_check_timer()
850 spin_unlock_irqrestore(&i2c->lock, flags); in img_i2c_check_timer()
853 static unsigned int img_i2c_auto(struct img_i2c *i2c, in img_i2c_auto() argument
861 dev_dbg(i2c->adap.dev.parent, "abort condition detected\n"); in img_i2c_auto()
863 if ((i2c->msg.flags & I2C_M_RD) && in img_i2c_auto()
865 img_i2c_read_fifo(i2c); in img_i2c_auto()
867 i2c->msg_status = -EIO; in img_i2c_auto()
868 img_i2c_stop_start(i2c); in img_i2c_auto()
873 if (!i2c->last_msg && line_status & LINESTAT_START_BIT_DET) { in img_i2c_auto()
874 img_i2c_transaction_halt(i2c, !i2c->last_msg); in img_i2c_auto()
876 i2c->int_enable &= ~INT_SLAVE_EVENT; in img_i2c_auto()
879 mod_timer(&i2c->check_timer, jiffies + msecs_to_jiffies(1)); in img_i2c_auto()
883 if (i2c->msg.flags & I2C_M_RD) in img_i2c_auto()
884 img_i2c_read_fifo(i2c); in img_i2c_auto()
888 if (i2c->msg.flags & I2C_M_RD) { in img_i2c_auto()
890 img_i2c_read_fifo(i2c); in img_i2c_auto()
891 if (i2c->msg.len == 0) in img_i2c_auto()
897 i2c->msg.len == 0) in img_i2c_auto()
899 img_i2c_write_fifo(i2c); in img_i2c_auto()
907 img_i2c_transaction_halt(i2c, false); in img_i2c_auto()
908 img_i2c_transaction_halt(i2c, !i2c->last_msg); in img_i2c_auto()
916 struct img_i2c *i2c = dev_id; in img_i2c_isr() local
922 int_status = img_i2c_readl(i2c, SCB_INT_STATUS_REG); in img_i2c_isr()
924 img_i2c_writel(i2c, SCB_INT_CLEAR_REG, int_status); in img_i2c_isr()
930 line_status = img_i2c_readl(i2c, SCB_STATUS_REG); in img_i2c_isr()
932 img_i2c_writel(i2c, SCB_CLEAR_REG, in img_i2c_isr()
935 img_i2c_wr_rd_fence(i2c); in img_i2c_isr()
938 spin_lock(&i2c->lock); in img_i2c_isr()
941 i2c->line_status &= ~LINESTAT_INPUT_DATA; in img_i2c_isr()
942 i2c->line_status |= line_status; in img_i2c_isr()
952 dev_crit(i2c->adap.dev.parent, in img_i2c_isr()
954 (i2c->msg.flags & I2C_M_RD) ? "reading" : "writing", in img_i2c_isr()
955 i2c->msg.addr); in img_i2c_isr()
960 if (i2c->mode == MODE_ATOMIC) in img_i2c_isr()
961 hret = img_i2c_atomic(i2c, int_status, line_status); in img_i2c_isr()
962 else if (i2c->mode == MODE_AUTOMATIC) in img_i2c_isr()
963 hret = img_i2c_auto(i2c, int_status, line_status); in img_i2c_isr()
964 else if (i2c->mode == MODE_SEQUENCE) in img_i2c_isr()
965 hret = img_i2c_sequence(i2c, int_status); in img_i2c_isr()
966 else if (i2c->mode == MODE_WAITSTOP && (int_status & INT_SLAVE_EVENT) && in img_i2c_isr()
969 else if (i2c->mode == MODE_RAW) in img_i2c_isr()
970 hret = img_i2c_raw(i2c, int_status, line_status); in img_i2c_isr()
975 img_i2c_writel(i2c, SCB_INT_CLEAR_REG, int_status & INT_LEVEL); in img_i2c_isr()
983 if (!i2c->last_msg || i2c->line_status & LINESTAT_STOP_BIT_DET) in img_i2c_isr()
986 img_i2c_switch_mode(i2c, MODE_WAITSTOP); in img_i2c_isr()
993 img_i2c_complete_transaction(i2c, status); in img_i2c_isr()
995 img_i2c_switch_mode(i2c, MODE_FATAL); in img_i2c_isr()
999 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_isr()
1001 spin_unlock(&i2c->lock); in img_i2c_isr()
1007 static int img_i2c_reset_bus(struct img_i2c *i2c) in img_i2c_reset_bus() argument
1012 spin_lock_irqsave(&i2c->lock, flags); in img_i2c_reset_bus()
1013 reinit_completion(&i2c->msg_complete); in img_i2c_reset_bus()
1014 img_i2c_reset_start(i2c); in img_i2c_reset_bus()
1015 spin_unlock_irqrestore(&i2c->lock, flags); in img_i2c_reset_bus()
1017 time_left = wait_for_completion_timeout(&i2c->msg_complete, in img_i2c_reset_bus()
1027 struct img_i2c *i2c = i2c_get_adapdata(adap); in img_i2c_xfer() local
1032 if (i2c->mode == MODE_SUSPEND) { in img_i2c_xfer()
1037 if (i2c->mode == MODE_FATAL) in img_i2c_xfer()
1068 spin_lock_irqsave(&i2c->lock, flags); in img_i2c_xfer()
1074 i2c->msg = *msg; in img_i2c_xfer()
1075 i2c->msg_status = 0; in img_i2c_xfer()
1084 i2c->last_msg = (i == num - 1); in img_i2c_xfer()
1085 reinit_completion(&i2c->msg_complete); in img_i2c_xfer()
1093 img_i2c_writel(i2c, SCB_INT_CLEAR_REG, ~0); in img_i2c_xfer()
1094 img_i2c_writel(i2c, SCB_CLEAR_REG, ~0); in img_i2c_xfer()
1097 img_i2c_atomic_start(i2c); in img_i2c_xfer()
1103 img_i2c_transaction_halt(i2c, !i2c->last_msg); in img_i2c_xfer()
1106 img_i2c_read(i2c); in img_i2c_xfer()
1108 img_i2c_write(i2c); in img_i2c_xfer()
1118 img_i2c_transaction_halt(i2c, false); in img_i2c_xfer()
1119 img_i2c_transaction_halt(i2c, !i2c->last_msg); in img_i2c_xfer()
1121 spin_unlock_irqrestore(&i2c->lock, flags); in img_i2c_xfer()
1123 time_left = wait_for_completion_timeout(&i2c->msg_complete, in img_i2c_xfer()
1125 del_timer_sync(&i2c->check_timer); in img_i2c_xfer()
1129 i2c->msg_status = -ETIMEDOUT; in img_i2c_xfer()
1133 if (i2c->msg_status) in img_i2c_xfer()
1140 return i2c->msg_status ? i2c->msg_status : num; in img_i2c_xfer()
1153 static int img_i2c_init(struct img_i2c *i2c) in img_i2c_init() argument
1161 ret = pm_runtime_resume_and_get(i2c->adap.dev.parent); in img_i2c_init()
1165 rev = img_i2c_readl(i2c, SCB_CORE_REV_REG); in img_i2c_init()
1167 dev_info(i2c->adap.dev.parent, in img_i2c_init()
1171 pm_runtime_mark_last_busy(i2c->adap.dev.parent); in img_i2c_init()
1172 pm_runtime_put_autosuspend(i2c->adap.dev.parent); in img_i2c_init()
1177 i2c->need_wr_rd_fence = true; in img_i2c_init()
1182 if (i2c->bitrate <= timings[i].max_bitrate) { in img_i2c_init()
1187 if (i2c->bitrate > timings[ARRAY_SIZE(timings) - 1].max_bitrate) { in img_i2c_init()
1188 dev_warn(i2c->adap.dev.parent, in img_i2c_init()
1190 i2c->bitrate, in img_i2c_init()
1193 i2c->bitrate = timing.max_bitrate; in img_i2c_init()
1196 bitrate_khz = i2c->bitrate / 1000; in img_i2c_init()
1197 clk_khz = clk_get_rate(i2c->scb_clk) / 1000; in img_i2c_init()
1233 img_i2c_writel(i2c, SCB_CLK_SET_REG, data); in img_i2c_init()
1265 img_i2c_writel(i2c, SCB_TIME_TCKH_REG, tckh); in img_i2c_init()
1266 img_i2c_writel(i2c, SCB_TIME_TCKL_REG, tckl); in img_i2c_init()
1275 img_i2c_writel(i2c, SCB_TIME_TSDH_REG, data); in img_i2c_init()
1284 img_i2c_writel(i2c, SCB_TIME_TPL_REG, data); in img_i2c_init()
1290 img_i2c_writel(i2c, SCB_TIME_TPH_REG, data); in img_i2c_init()
1293 img_i2c_writel(i2c, SCB_TIME_TSDL_REG, data + tsdh + 2); in img_i2c_init()
1299 img_i2c_writel(i2c, SCB_TIME_TP2S_REG, data); in img_i2c_init()
1301 img_i2c_writel(i2c, SCB_TIME_TBI_REG, TIMEOUT_TBI); in img_i2c_init()
1302 img_i2c_writel(i2c, SCB_TIME_TSL_REG, TIMEOUT_TSL); in img_i2c_init()
1303 img_i2c_writel(i2c, SCB_TIME_TDL_REG, TIMEOUT_TDL); in img_i2c_init()
1306 img_i2c_soft_reset(i2c); in img_i2c_init()
1309 img_i2c_writel(i2c, SCB_INT_MASK_REG, 0); in img_i2c_init()
1312 img_i2c_writel(i2c, SCB_INT_CLEAR_REG, ~0); in img_i2c_init()
1315 img_i2c_writel(i2c, SCB_CLEAR_REG, ~0); in img_i2c_init()
1318 img_i2c_writel(i2c, SCB_INT_MASK_REG, i2c->int_enable); in img_i2c_init()
1321 ret = img_i2c_reset_bus(i2c); in img_i2c_init()
1323 pm_runtime_mark_last_busy(i2c->adap.dev.parent); in img_i2c_init()
1324 pm_runtime_put_autosuspend(i2c->adap.dev.parent); in img_i2c_init()
1332 struct img_i2c *i2c; in img_i2c_probe() local
1336 i2c = devm_kzalloc(&pdev->dev, sizeof(struct img_i2c), GFP_KERNEL); in img_i2c_probe()
1337 if (!i2c) in img_i2c_probe()
1340 i2c->base = devm_platform_ioremap_resource(pdev, 0); in img_i2c_probe()
1341 if (IS_ERR(i2c->base)) in img_i2c_probe()
1342 return PTR_ERR(i2c->base); in img_i2c_probe()
1348 i2c->sys_clk = devm_clk_get(&pdev->dev, "sys"); in img_i2c_probe()
1349 if (IS_ERR(i2c->sys_clk)) { in img_i2c_probe()
1351 return PTR_ERR(i2c->sys_clk); in img_i2c_probe()
1354 i2c->scb_clk = devm_clk_get(&pdev->dev, "scb"); in img_i2c_probe()
1355 if (IS_ERR(i2c->scb_clk)) { in img_i2c_probe()
1357 return PTR_ERR(i2c->scb_clk); in img_i2c_probe()
1361 pdev->name, i2c); in img_i2c_probe()
1368 timer_setup(&i2c->check_timer, img_i2c_check_timer, 0); in img_i2c_probe()
1370 i2c->bitrate = timings[0].max_bitrate; in img_i2c_probe()
1372 i2c->bitrate = val; in img_i2c_probe()
1374 i2c_set_adapdata(&i2c->adap, i2c); in img_i2c_probe()
1375 i2c->adap.dev.parent = &pdev->dev; in img_i2c_probe()
1376 i2c->adap.dev.of_node = node; in img_i2c_probe()
1377 i2c->adap.owner = THIS_MODULE; in img_i2c_probe()
1378 i2c->adap.algo = &img_i2c_algo; in img_i2c_probe()
1379 i2c->adap.retries = 5; in img_i2c_probe()
1380 i2c->adap.nr = pdev->id; in img_i2c_probe()
1381 snprintf(i2c->adap.name, sizeof(i2c->adap.name), "IMG SCB I2C"); in img_i2c_probe()
1383 img_i2c_switch_mode(i2c, MODE_INACTIVE); in img_i2c_probe()
1384 spin_lock_init(&i2c->lock); in img_i2c_probe()
1385 init_completion(&i2c->msg_complete); in img_i2c_probe()
1387 platform_set_drvdata(pdev, i2c); in img_i2c_probe()
1398 ret = img_i2c_init(i2c); in img_i2c_probe()
1402 ret = i2c_add_numbered_adapter(&i2c->adap); in img_i2c_probe()
1418 struct img_i2c *i2c = platform_get_drvdata(dev); in img_i2c_remove() local
1420 i2c_del_adapter(&i2c->adap); in img_i2c_remove()
1428 struct img_i2c *i2c = dev_get_drvdata(dev); in img_i2c_runtime_suspend() local
1430 clk_disable_unprepare(i2c->scb_clk); in img_i2c_runtime_suspend()
1431 clk_disable_unprepare(i2c->sys_clk); in img_i2c_runtime_suspend()
1438 struct img_i2c *i2c = dev_get_drvdata(dev); in img_i2c_runtime_resume() local
1441 ret = clk_prepare_enable(i2c->sys_clk); in img_i2c_runtime_resume()
1447 ret = clk_prepare_enable(i2c->scb_clk); in img_i2c_runtime_resume()
1450 clk_disable_unprepare(i2c->sys_clk); in img_i2c_runtime_resume()
1459 struct img_i2c *i2c = dev_get_drvdata(dev); in img_i2c_suspend() local
1466 img_i2c_switch_mode(i2c, MODE_SUSPEND); in img_i2c_suspend()
1473 struct img_i2c *i2c = dev_get_drvdata(dev); in img_i2c_resume() local
1480 img_i2c_init(i2c); in img_i2c_resume()