Lines Matching refs:rsb
197 static struct sunxi_rsb_device *sunxi_rsb_device_create(struct sunxi_rsb *rsb, in sunxi_rsb_device_create() argument
207 rdev->rsb = rsb; in sunxi_rsb_device_create()
211 rdev->dev.parent = rsb->dev; in sunxi_rsb_device_create()
268 static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) in _sunxi_rsb_run_xfer() argument
273 if (readl(rsb->regs + RSB_CTRL) & RSB_CTRL_START_TRANS) { in _sunxi_rsb_run_xfer()
274 dev_dbg(rsb->dev, "RSB transfer still in progress\n"); in _sunxi_rsb_run_xfer()
278 reinit_completion(&rsb->complete); in _sunxi_rsb_run_xfer()
281 writel(int_mask, rsb->regs + RSB_INTE); in _sunxi_rsb_run_xfer()
283 rsb->regs + RSB_CTRL); in _sunxi_rsb_run_xfer()
286 timeout = readl_poll_timeout_atomic(rsb->regs + RSB_INTS, in _sunxi_rsb_run_xfer()
289 writel(status, rsb->regs + RSB_INTS); in _sunxi_rsb_run_xfer()
291 timeout = !wait_for_completion_io_timeout(&rsb->complete, in _sunxi_rsb_run_xfer()
293 status = rsb->status; in _sunxi_rsb_run_xfer()
297 dev_dbg(rsb->dev, "RSB timeout\n"); in _sunxi_rsb_run_xfer()
300 writel(RSB_CTRL_ABORT_TRANS, rsb->regs + RSB_CTRL); in _sunxi_rsb_run_xfer()
303 writel(readl(rsb->regs + RSB_INTS), rsb->regs + RSB_INTS); in _sunxi_rsb_run_xfer()
309 dev_dbg(rsb->dev, "RSB busy\n"); in _sunxi_rsb_run_xfer()
315 dev_dbg(rsb->dev, "RSB slave nack\n"); in _sunxi_rsb_run_xfer()
320 dev_dbg(rsb->dev, "RSB transfer data error\n"); in _sunxi_rsb_run_xfer()
328 static int sunxi_rsb_read(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, in sunxi_rsb_read() argument
348 dev_err(rsb->dev, "Invalid access width: %zd\n", len); in sunxi_rsb_read()
352 ret = pm_runtime_resume_and_get(rsb->dev); in sunxi_rsb_read()
356 mutex_lock(&rsb->lock); in sunxi_rsb_read()
358 writel(addr, rsb->regs + RSB_ADDR); in sunxi_rsb_read()
359 writel(RSB_DAR_RTA(rtaddr), rsb->regs + RSB_DAR); in sunxi_rsb_read()
360 writel(cmd, rsb->regs + RSB_CMD); in sunxi_rsb_read()
362 ret = _sunxi_rsb_run_xfer(rsb); in sunxi_rsb_read()
366 *buf = readl(rsb->regs + RSB_DATA) & GENMASK(len * 8 - 1, 0); in sunxi_rsb_read()
369 mutex_unlock(&rsb->lock); in sunxi_rsb_read()
371 pm_runtime_mark_last_busy(rsb->dev); in sunxi_rsb_read()
372 pm_runtime_put_autosuspend(rsb->dev); in sunxi_rsb_read()
377 static int sunxi_rsb_write(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, in sunxi_rsb_write() argument
397 dev_err(rsb->dev, "Invalid access width: %zd\n", len); in sunxi_rsb_write()
401 ret = pm_runtime_resume_and_get(rsb->dev); in sunxi_rsb_write()
405 mutex_lock(&rsb->lock); in sunxi_rsb_write()
407 writel(addr, rsb->regs + RSB_ADDR); in sunxi_rsb_write()
408 writel(RSB_DAR_RTA(rtaddr), rsb->regs + RSB_DAR); in sunxi_rsb_write()
409 writel(*buf, rsb->regs + RSB_DATA); in sunxi_rsb_write()
410 writel(cmd, rsb->regs + RSB_CMD); in sunxi_rsb_write()
411 ret = _sunxi_rsb_run_xfer(rsb); in sunxi_rsb_write()
413 mutex_unlock(&rsb->lock); in sunxi_rsb_write()
415 pm_runtime_mark_last_busy(rsb->dev); in sunxi_rsb_write()
416 pm_runtime_put_autosuspend(rsb->dev); in sunxi_rsb_write()
436 return sunxi_rsb_read(rdev->rsb, rdev->rtaddr, reg, val, ctx->size); in regmap_sunxi_rsb_reg_read()
445 return sunxi_rsb_write(rdev->rsb, rdev->rtaddr, reg, &val, ctx->size); in regmap_sunxi_rsb_reg_write()
505 struct sunxi_rsb *rsb = dev_id; in sunxi_rsb_irq() local
508 status = readl(rsb->regs + RSB_INTS); in sunxi_rsb_irq()
509 rsb->status = status; in sunxi_rsb_irq()
514 writel(status, rsb->regs + RSB_INTS); in sunxi_rsb_irq()
516 complete(&rsb->complete); in sunxi_rsb_irq()
521 static int sunxi_rsb_init_device_mode(struct sunxi_rsb *rsb) in sunxi_rsb_init_device_mode() argument
528 RSB_DMCR_MODE_REG | RSB_DMCR_DEV_ADDR, rsb->regs + RSB_DMCR); in sunxi_rsb_init_device_mode()
530 readl_poll_timeout(rsb->regs + RSB_DMCR, reg, in sunxi_rsb_init_device_mode()
536 writel(readl(rsb->regs + RSB_INTS), rsb->regs + RSB_INTS); in sunxi_rsb_init_device_mode()
575 static int of_rsb_register_devices(struct sunxi_rsb *rsb) in of_rsb_register_devices() argument
577 struct device *dev = rsb->dev; in of_rsb_register_devices()
611 writel(RSB_CMD_STRA, rsb->regs + RSB_CMD); in of_rsb_register_devices()
613 rsb->regs + RSB_DAR); in of_rsb_register_devices()
616 ret = _sunxi_rsb_run_xfer(rsb); in of_rsb_register_devices()
636 rdev = sunxi_rsb_device_create(rsb, child, hwaddr, rtaddr); in of_rsb_register_devices()
645 static int sunxi_rsb_hw_init(struct sunxi_rsb *rsb) in sunxi_rsb_hw_init() argument
647 struct device *dev = rsb->dev; in sunxi_rsb_hw_init()
652 ret = clk_prepare_enable(rsb->clk); in sunxi_rsb_hw_init()
658 ret = reset_control_deassert(rsb->rstc); in sunxi_rsb_hw_init()
665 writel(RSB_CTRL_SOFT_RST, rsb->regs + RSB_CTRL); in sunxi_rsb_hw_init()
666 readl_poll_timeout(rsb->regs + RSB_CTRL, reg, in sunxi_rsb_hw_init()
676 p_clk_freq = clk_get_rate(rsb->clk); in sunxi_rsb_hw_init()
677 clk_div = p_clk_freq / rsb->clk_freq / 2; in sunxi_rsb_hw_init()
689 rsb->regs + RSB_CCR); in sunxi_rsb_hw_init()
694 clk_disable_unprepare(rsb->clk); in sunxi_rsb_hw_init()
699 static void sunxi_rsb_hw_exit(struct sunxi_rsb *rsb) in sunxi_rsb_hw_exit() argument
701 reset_control_assert(rsb->rstc); in sunxi_rsb_hw_exit()
704 if (!pm_runtime_status_suspended(rsb->dev)) in sunxi_rsb_hw_exit()
705 clk_disable_unprepare(rsb->clk); in sunxi_rsb_hw_exit()
710 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_runtime_suspend() local
712 clk_disable_unprepare(rsb->clk); in sunxi_rsb_runtime_suspend()
719 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_runtime_resume() local
721 return clk_prepare_enable(rsb->clk); in sunxi_rsb_runtime_resume()
726 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_suspend() local
728 sunxi_rsb_hw_exit(rsb); in sunxi_rsb_suspend()
735 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_resume() local
737 return sunxi_rsb_hw_init(rsb); in sunxi_rsb_resume()
745 struct sunxi_rsb *rsb; in sunxi_rsb_probe() local
757 rsb = devm_kzalloc(dev, sizeof(*rsb), GFP_KERNEL); in sunxi_rsb_probe()
758 if (!rsb) in sunxi_rsb_probe()
761 rsb->dev = dev; in sunxi_rsb_probe()
762 rsb->clk_freq = clk_freq; in sunxi_rsb_probe()
763 platform_set_drvdata(pdev, rsb); in sunxi_rsb_probe()
765 rsb->regs = devm_ioremap_resource(dev, r); in sunxi_rsb_probe()
766 if (IS_ERR(rsb->regs)) in sunxi_rsb_probe()
767 return PTR_ERR(rsb->regs); in sunxi_rsb_probe()
773 rsb->clk = devm_clk_get(dev, NULL); in sunxi_rsb_probe()
774 if (IS_ERR(rsb->clk)) { in sunxi_rsb_probe()
775 ret = PTR_ERR(rsb->clk); in sunxi_rsb_probe()
780 rsb->rstc = devm_reset_control_get(dev, NULL); in sunxi_rsb_probe()
781 if (IS_ERR(rsb->rstc)) { in sunxi_rsb_probe()
782 ret = PTR_ERR(rsb->rstc); in sunxi_rsb_probe()
787 init_completion(&rsb->complete); in sunxi_rsb_probe()
788 mutex_init(&rsb->lock); in sunxi_rsb_probe()
790 ret = devm_request_irq(dev, irq, sunxi_rsb_irq, 0, RSB_CTRL_NAME, rsb); in sunxi_rsb_probe()
797 ret = sunxi_rsb_hw_init(rsb); in sunxi_rsb_probe()
802 ret = sunxi_rsb_init_device_mode(rsb); in sunxi_rsb_probe()
812 of_rsb_register_devices(rsb); in sunxi_rsb_probe()
819 struct sunxi_rsb *rsb = platform_get_drvdata(pdev); in sunxi_rsb_remove() local
821 device_for_each_child(rsb->dev, NULL, sunxi_rsb_remove_devices); in sunxi_rsb_remove()
823 sunxi_rsb_hw_exit(rsb); in sunxi_rsb_remove()