Lines Matching refs:dev
121 struct device *dev; member
169 static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) in i2c_davinci_calc_clk_dividers() argument
171 struct davinci_i2c_platform_data *pdata = dev->pdata; in i2c_davinci_calc_clk_dividers()
177 u32 input_clock = clk_get_rate(dev->clk); in i2c_davinci_calc_clk_dividers()
178 struct device_node *of_node = dev->dev->of_node; in i2c_davinci_calc_clk_dividers()
244 davinci_i2c_write_reg(dev, DAVINCI_I2C_PSC_REG, psc); in i2c_davinci_calc_clk_dividers()
245 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKH_REG, clkh); in i2c_davinci_calc_clk_dividers()
246 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl); in i2c_davinci_calc_clk_dividers()
248 dev_dbg(dev->dev, "input_clock = %d, CLK = %d\n", input_clock, clk); in i2c_davinci_calc_clk_dividers()
256 static int i2c_davinci_init(struct davinci_i2c_dev *dev) in i2c_davinci_init() argument
258 struct davinci_i2c_platform_data *pdata = dev->pdata; in i2c_davinci_init()
261 davinci_i2c_reset_ctrl(dev, 0); in i2c_davinci_init()
264 i2c_davinci_calc_clk_dividers(dev); in i2c_davinci_init()
269 davinci_i2c_write_reg(dev, DAVINCI_I2C_OAR_REG, DAVINCI_I2C_OWN_ADDRESS); in i2c_davinci_init()
271 dev_dbg(dev->dev, "PSC = %d\n", in i2c_davinci_init()
272 davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG)); in i2c_davinci_init()
273 dev_dbg(dev->dev, "CLKL = %d\n", in i2c_davinci_init()
274 davinci_i2c_read_reg(dev, DAVINCI_I2C_CLKL_REG)); in i2c_davinci_init()
275 dev_dbg(dev->dev, "CLKH = %d\n", in i2c_davinci_init()
276 davinci_i2c_read_reg(dev, DAVINCI_I2C_CLKH_REG)); in i2c_davinci_init()
277 dev_dbg(dev->dev, "bus_freq = %dkHz, bus_delay = %d\n", in i2c_davinci_init()
282 davinci_i2c_reset_ctrl(dev, 1); in i2c_davinci_init()
285 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, I2C_DAVINCI_INTR_ALL); in i2c_davinci_init()
296 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_prepare_recovery() local
299 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, 0); in davinci_i2c_prepare_recovery()
302 davinci_i2c_reset_ctrl(dev, 0); in davinci_i2c_prepare_recovery()
307 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_unprepare_recovery() local
309 i2c_davinci_init(dev); in davinci_i2c_unprepare_recovery()
320 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_set_scl() local
323 davinci_i2c_write_reg(dev, DAVINCI_I2C_DSET_REG, in davinci_i2c_set_scl()
326 davinci_i2c_write_reg(dev, DAVINCI_I2C_DCLR_REG, in davinci_i2c_set_scl()
332 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_get_scl() local
336 val = davinci_i2c_read_reg(dev, DAVINCI_I2C_DIN_REG); in davinci_i2c_get_scl()
342 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_get_sda() local
346 val = davinci_i2c_read_reg(dev, DAVINCI_I2C_DIN_REG); in davinci_i2c_get_sda()
352 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_scl_prepare_recovery() local
357 davinci_i2c_write_reg(dev, DAVINCI_I2C_DIR_REG, DAVINCI_I2C_DIR_PDIR0); in davinci_i2c_scl_prepare_recovery()
360 davinci_i2c_write_reg(dev, DAVINCI_I2C_FUNC_REG, in davinci_i2c_scl_prepare_recovery()
366 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in davinci_i2c_scl_unprepare_recovery() local
369 davinci_i2c_write_reg(dev, DAVINCI_I2C_FUNC_REG, 0); in davinci_i2c_scl_unprepare_recovery()
386 static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev) in i2c_davinci_wait_bus_not_busy() argument
388 unsigned long timeout = jiffies + dev->adapter.timeout; in i2c_davinci_wait_bus_not_busy()
391 if (!(davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) & DAVINCI_I2C_STR_BB)) in i2c_davinci_wait_bus_not_busy()
396 dev_warn(dev->dev, "timeout waiting for bus ready\n"); in i2c_davinci_wait_bus_not_busy()
397 i2c_recover_bus(&dev->adapter); in i2c_davinci_wait_bus_not_busy()
403 if (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) & DAVINCI_I2C_STR_BB) in i2c_davinci_wait_bus_not_busy()
416 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in i2c_davinci_xfer_msg() local
417 struct davinci_i2c_platform_data *pdata = dev->pdata; in i2c_davinci_xfer_msg()
423 dev_warn(dev->dev, "transfer to own address aborted\n"); in i2c_davinci_xfer_msg()
432 davinci_i2c_write_reg(dev, DAVINCI_I2C_SAR_REG, msg->addr); in i2c_davinci_xfer_msg()
434 dev->buf = msg->buf; in i2c_davinci_xfer_msg()
435 dev->buf_len = msg->len; in i2c_davinci_xfer_msg()
436 dev->stop = stop; in i2c_davinci_xfer_msg()
438 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); in i2c_davinci_xfer_msg()
440 reinit_completion(&dev->cmd_complete); in i2c_davinci_xfer_msg()
441 dev->cmd_err = 0; in i2c_davinci_xfer_msg()
455 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); in i2c_davinci_xfer_msg()
460 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); in i2c_davinci_xfer_msg()
462 dev->terminate = 0; in i2c_davinci_xfer_msg()
469 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); in i2c_davinci_xfer_msg()
478 if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) { in i2c_davinci_xfer_msg()
479 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++); in i2c_davinci_xfer_msg()
480 dev->buf_len--; in i2c_davinci_xfer_msg()
487 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); in i2c_davinci_xfer_msg()
489 time_left = wait_for_completion_timeout(&dev->cmd_complete, in i2c_davinci_xfer_msg()
490 dev->adapter.timeout); in i2c_davinci_xfer_msg()
492 dev_err(dev->dev, "controller timed out\n"); in i2c_davinci_xfer_msg()
494 dev->buf_len = 0; in i2c_davinci_xfer_msg()
497 if (dev->buf_len) { in i2c_davinci_xfer_msg()
501 dev_err(dev->dev, "abnormal termination buf_len=%zu\n", in i2c_davinci_xfer_msg()
502 dev->buf_len); in i2c_davinci_xfer_msg()
503 dev->terminate = 1; in i2c_davinci_xfer_msg()
505 dev->buf_len = 0; in i2c_davinci_xfer_msg()
510 if (likely(!dev->cmd_err)) in i2c_davinci_xfer_msg()
514 if (dev->cmd_err & DAVINCI_I2C_STR_AL) { in i2c_davinci_xfer_msg()
515 i2c_davinci_init(dev); in i2c_davinci_xfer_msg()
519 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) { in i2c_davinci_xfer_msg()
522 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); in i2c_davinci_xfer_msg()
524 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); in i2c_davinci_xfer_msg()
536 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); in i2c_davinci_xfer() local
540 dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); in i2c_davinci_xfer()
542 ret = pm_runtime_resume_and_get(dev->dev); in i2c_davinci_xfer()
544 dev_err(dev->dev, "Failed to runtime_get device: %d\n", ret); in i2c_davinci_xfer()
548 ret = i2c_davinci_wait_bus_not_busy(dev); in i2c_davinci_xfer()
550 dev_warn(dev->dev, "timeout waiting for bus ready\n"); in i2c_davinci_xfer()
556 dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num, in i2c_davinci_xfer()
565 pm_runtime_mark_last_busy(dev->dev); in i2c_davinci_xfer()
566 pm_runtime_put_autosuspend(dev->dev); in i2c_davinci_xfer()
576 static void terminate_read(struct davinci_i2c_dev *dev) in terminate_read() argument
578 u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); in terminate_read()
580 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); in terminate_read()
583 davinci_i2c_read_reg(dev, DAVINCI_I2C_DRR_REG); in terminate_read()
584 if (!dev->terminate) in terminate_read()
585 dev_err(dev->dev, "RDR IRQ while no data requested\n"); in terminate_read()
587 static void terminate_write(struct davinci_i2c_dev *dev) in terminate_write() argument
589 u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); in terminate_write()
591 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); in terminate_write()
593 if (!dev->terminate) in terminate_write()
594 dev_dbg(dev->dev, "TDR IRQ while no data to send\n"); in terminate_write()
603 struct davinci_i2c_dev *dev = dev_id; in i2c_davinci_isr() local
608 if (pm_runtime_suspended(dev->dev)) in i2c_davinci_isr()
611 while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) { in i2c_davinci_isr()
612 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); in i2c_davinci_isr()
614 dev_warn(dev->dev, "Too much work in one IRQ\n"); in i2c_davinci_isr()
621 dev->cmd_err |= DAVINCI_I2C_STR_AL; in i2c_davinci_isr()
622 dev->buf_len = 0; in i2c_davinci_isr()
623 complete(&dev->cmd_complete); in i2c_davinci_isr()
627 dev->cmd_err |= DAVINCI_I2C_STR_NACK; in i2c_davinci_isr()
628 dev->buf_len = 0; in i2c_davinci_isr()
629 complete(&dev->cmd_complete); in i2c_davinci_isr()
633 davinci_i2c_write_reg(dev, in i2c_davinci_isr()
635 if (((dev->buf_len == 0) && (dev->stop != 0)) || in i2c_davinci_isr()
636 (dev->cmd_err & DAVINCI_I2C_STR_NACK)) { in i2c_davinci_isr()
637 w = davinci_i2c_read_reg(dev, in i2c_davinci_isr()
640 davinci_i2c_write_reg(dev, in i2c_davinci_isr()
643 complete(&dev->cmd_complete); in i2c_davinci_isr()
647 if (dev->buf_len) { in i2c_davinci_isr()
648 *dev->buf++ = in i2c_davinci_isr()
649 davinci_i2c_read_reg(dev, in i2c_davinci_isr()
651 dev->buf_len--; in i2c_davinci_isr()
652 if (dev->buf_len) in i2c_davinci_isr()
655 davinci_i2c_write_reg(dev, in i2c_davinci_isr()
660 terminate_read(dev); in i2c_davinci_isr()
665 if (dev->buf_len) { in i2c_davinci_isr()
666 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, in i2c_davinci_isr()
667 *dev->buf++); in i2c_davinci_isr()
668 dev->buf_len--; in i2c_davinci_isr()
669 if (dev->buf_len) in i2c_davinci_isr()
672 w = davinci_i2c_read_reg(dev, in i2c_davinci_isr()
675 davinci_i2c_write_reg(dev, in i2c_davinci_isr()
680 terminate_write(dev); in i2c_davinci_isr()
685 davinci_i2c_write_reg(dev, in i2c_davinci_isr()
687 complete(&dev->cmd_complete); in i2c_davinci_isr()
691 dev_dbg(dev->dev, "Address as slave interrupt\n"); in i2c_davinci_isr()
695 dev_warn(dev->dev, "Unrecognized irq stat %d\n", stat); in i2c_davinci_isr()
707 struct davinci_i2c_dev *dev; in i2c_davinci_cpufreq_transition() local
709 dev = container_of(nb, struct davinci_i2c_dev, freq_transition); in i2c_davinci_cpufreq_transition()
711 i2c_lock_bus(&dev->adapter, I2C_LOCK_ROOT_ADAPTER); in i2c_davinci_cpufreq_transition()
713 davinci_i2c_reset_ctrl(dev, 0); in i2c_davinci_cpufreq_transition()
715 i2c_davinci_calc_clk_dividers(dev); in i2c_davinci_cpufreq_transition()
716 davinci_i2c_reset_ctrl(dev, 1); in i2c_davinci_cpufreq_transition()
718 i2c_unlock_bus(&dev->adapter, I2C_LOCK_ROOT_ADAPTER); in i2c_davinci_cpufreq_transition()
723 static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev) in i2c_davinci_cpufreq_register() argument
725 dev->freq_transition.notifier_call = i2c_davinci_cpufreq_transition; in i2c_davinci_cpufreq_register()
727 return cpufreq_register_notifier(&dev->freq_transition, in i2c_davinci_cpufreq_register()
731 static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev) in i2c_davinci_cpufreq_deregister() argument
733 cpufreq_unregister_notifier(&dev->freq_transition, in i2c_davinci_cpufreq_deregister()
737 static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev) in i2c_davinci_cpufreq_register() argument
742 static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev) in i2c_davinci_cpufreq_deregister() argument
761 struct davinci_i2c_dev *dev; in davinci_i2c_probe() local
770 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in davinci_i2c_probe()
771 if (!dev) in davinci_i2c_probe()
774 init_completion(&dev->cmd_complete); in davinci_i2c_probe()
776 dev->dev = &pdev->dev; in davinci_i2c_probe()
777 dev->irq = irq; in davinci_i2c_probe()
778 dev->pdata = dev_get_platdata(&pdev->dev); in davinci_i2c_probe()
779 platform_set_drvdata(pdev, dev); in davinci_i2c_probe()
781 if (!dev->pdata && pdev->dev.of_node) { in davinci_i2c_probe()
784 dev->pdata = devm_kzalloc(&pdev->dev, in davinci_i2c_probe()
786 if (!dev->pdata) in davinci_i2c_probe()
789 memcpy(dev->pdata, &davinci_i2c_platform_data_default, in davinci_i2c_probe()
791 if (!of_property_read_u32(pdev->dev.of_node, "clock-frequency", in davinci_i2c_probe()
793 dev->pdata->bus_freq = prop / 1000; in davinci_i2c_probe()
795 dev->pdata->has_pfunc = in davinci_i2c_probe()
796 of_property_read_bool(pdev->dev.of_node, in davinci_i2c_probe()
798 } else if (!dev->pdata) { in davinci_i2c_probe()
799 dev->pdata = &davinci_i2c_platform_data_default; in davinci_i2c_probe()
802 dev->clk = devm_clk_get(&pdev->dev, NULL); in davinci_i2c_probe()
803 if (IS_ERR(dev->clk)) in davinci_i2c_probe()
804 return PTR_ERR(dev->clk); in davinci_i2c_probe()
806 dev->base = devm_platform_ioremap_resource(pdev, 0); in davinci_i2c_probe()
807 if (IS_ERR(dev->base)) { in davinci_i2c_probe()
808 return PTR_ERR(dev->base); in davinci_i2c_probe()
811 pm_runtime_set_autosuspend_delay(dev->dev, in davinci_i2c_probe()
813 pm_runtime_use_autosuspend(dev->dev); in davinci_i2c_probe()
815 pm_runtime_enable(dev->dev); in davinci_i2c_probe()
817 r = pm_runtime_resume_and_get(dev->dev); in davinci_i2c_probe()
819 dev_err(dev->dev, "failed to runtime_get device: %d\n", r); in davinci_i2c_probe()
823 i2c_davinci_init(dev); in davinci_i2c_probe()
825 r = devm_request_irq(&pdev->dev, dev->irq, i2c_davinci_isr, 0, in davinci_i2c_probe()
826 pdev->name, dev); in davinci_i2c_probe()
828 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); in davinci_i2c_probe()
832 r = i2c_davinci_cpufreq_register(dev); in davinci_i2c_probe()
834 dev_err(&pdev->dev, "failed to register cpufreq\n"); in davinci_i2c_probe()
838 adap = &dev->adapter; in davinci_i2c_probe()
839 i2c_set_adapdata(adap, dev); in davinci_i2c_probe()
844 adap->dev.parent = &pdev->dev; in davinci_i2c_probe()
846 adap->dev.of_node = pdev->dev.of_node; in davinci_i2c_probe()
848 if (dev->pdata->has_pfunc) in davinci_i2c_probe()
850 else if (dev->pdata->gpio_recovery) { in davinci_i2c_probe()
853 rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", in davinci_i2c_probe()
859 rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); in davinci_i2c_probe()
871 pm_runtime_mark_last_busy(dev->dev); in davinci_i2c_probe()
872 pm_runtime_put_autosuspend(dev->dev); in davinci_i2c_probe()
877 pm_runtime_dont_use_autosuspend(dev->dev); in davinci_i2c_probe()
878 pm_runtime_put_sync(dev->dev); in davinci_i2c_probe()
880 pm_runtime_disable(dev->dev); in davinci_i2c_probe()
887 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); in davinci_i2c_remove() local
890 i2c_davinci_cpufreq_deregister(dev); in davinci_i2c_remove()
892 i2c_del_adapter(&dev->adapter); in davinci_i2c_remove()
894 ret = pm_runtime_get_sync(&pdev->dev); in davinci_i2c_remove()
896 dev_err(&pdev->dev, "Failed to resume device\n"); in davinci_i2c_remove()
898 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); in davinci_i2c_remove()
900 pm_runtime_dont_use_autosuspend(dev->dev); in davinci_i2c_remove()
901 pm_runtime_put_sync(dev->dev); in davinci_i2c_remove()
902 pm_runtime_disable(dev->dev); in davinci_i2c_remove()
905 static int davinci_i2c_suspend(struct device *dev) in davinci_i2c_suspend() argument
907 struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev); in davinci_i2c_suspend()
915 static int davinci_i2c_resume(struct device *dev) in davinci_i2c_resume() argument
917 struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev); in davinci_i2c_resume()