Lines Matching refs:rsb

202 static struct sunxi_rsb_device *sunxi_rsb_device_create(struct sunxi_rsb *rsb,  in sunxi_rsb_device_create()  argument
212 rdev->rsb = rsb; in sunxi_rsb_device_create()
216 rdev->dev.parent = rsb->dev; in sunxi_rsb_device_create()
273 static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) in _sunxi_rsb_run_xfer() argument
278 if (readl(rsb->regs + RSB_CTRL) & RSB_CTRL_START_TRANS) { in _sunxi_rsb_run_xfer()
279 dev_dbg(rsb->dev, "RSB transfer still in progress\n"); in _sunxi_rsb_run_xfer()
283 reinit_completion(&rsb->complete); in _sunxi_rsb_run_xfer()
286 writel(int_mask, rsb->regs + RSB_INTE); in _sunxi_rsb_run_xfer()
288 rsb->regs + RSB_CTRL); in _sunxi_rsb_run_xfer()
291 timeout = readl_poll_timeout_atomic(rsb->regs + RSB_INTS, in _sunxi_rsb_run_xfer()
294 writel(status, rsb->regs + RSB_INTS); in _sunxi_rsb_run_xfer()
296 timeout = !wait_for_completion_io_timeout(&rsb->complete, in _sunxi_rsb_run_xfer()
298 status = rsb->status; in _sunxi_rsb_run_xfer()
302 dev_dbg(rsb->dev, "RSB timeout\n"); in _sunxi_rsb_run_xfer()
305 writel(RSB_CTRL_ABORT_TRANS, rsb->regs + RSB_CTRL); in _sunxi_rsb_run_xfer()
308 writel(readl(rsb->regs + RSB_INTS), rsb->regs + RSB_INTS); in _sunxi_rsb_run_xfer()
314 dev_dbg(rsb->dev, "RSB busy\n"); in _sunxi_rsb_run_xfer()
320 dev_dbg(rsb->dev, "RSB slave nack\n"); in _sunxi_rsb_run_xfer()
325 dev_dbg(rsb->dev, "RSB transfer data error\n"); in _sunxi_rsb_run_xfer()
333 static int sunxi_rsb_read(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, in sunxi_rsb_read() argument
353 dev_err(rsb->dev, "Invalid access width: %zd\n", len); in sunxi_rsb_read()
357 ret = pm_runtime_resume_and_get(rsb->dev); in sunxi_rsb_read()
361 mutex_lock(&rsb->lock); in sunxi_rsb_read()
363 writel(addr, rsb->regs + RSB_ADDR); in sunxi_rsb_read()
364 writel(RSB_DAR_RTA(rtaddr), rsb->regs + RSB_DAR); in sunxi_rsb_read()
365 writel(cmd, rsb->regs + RSB_CMD); in sunxi_rsb_read()
367 ret = _sunxi_rsb_run_xfer(rsb); in sunxi_rsb_read()
371 *buf = readl(rsb->regs + RSB_DATA) & GENMASK(len * 8 - 1, 0); in sunxi_rsb_read()
374 mutex_unlock(&rsb->lock); in sunxi_rsb_read()
376 pm_runtime_mark_last_busy(rsb->dev); in sunxi_rsb_read()
377 pm_runtime_put_autosuspend(rsb->dev); in sunxi_rsb_read()
382 static int sunxi_rsb_write(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, in sunxi_rsb_write() argument
402 dev_err(rsb->dev, "Invalid access width: %zd\n", len); in sunxi_rsb_write()
406 ret = pm_runtime_resume_and_get(rsb->dev); in sunxi_rsb_write()
410 mutex_lock(&rsb->lock); in sunxi_rsb_write()
412 writel(addr, rsb->regs + RSB_ADDR); in sunxi_rsb_write()
413 writel(RSB_DAR_RTA(rtaddr), rsb->regs + RSB_DAR); in sunxi_rsb_write()
414 writel(*buf, rsb->regs + RSB_DATA); in sunxi_rsb_write()
415 writel(cmd, rsb->regs + RSB_CMD); in sunxi_rsb_write()
416 ret = _sunxi_rsb_run_xfer(rsb); in sunxi_rsb_write()
418 mutex_unlock(&rsb->lock); in sunxi_rsb_write()
420 pm_runtime_mark_last_busy(rsb->dev); in sunxi_rsb_write()
421 pm_runtime_put_autosuspend(rsb->dev); in sunxi_rsb_write()
441 return sunxi_rsb_read(rdev->rsb, rdev->rtaddr, reg, val, ctx->size); in regmap_sunxi_rsb_reg_read()
450 return sunxi_rsb_write(rdev->rsb, rdev->rtaddr, reg, &val, ctx->size); in regmap_sunxi_rsb_reg_write()
510 struct sunxi_rsb *rsb = dev_id; in sunxi_rsb_irq() local
513 status = readl(rsb->regs + RSB_INTS); in sunxi_rsb_irq()
514 rsb->status = status; in sunxi_rsb_irq()
519 writel(status, rsb->regs + RSB_INTS); in sunxi_rsb_irq()
521 complete(&rsb->complete); in sunxi_rsb_irq()
526 static int sunxi_rsb_init_device_mode(struct sunxi_rsb *rsb) in sunxi_rsb_init_device_mode() argument
533 RSB_DMCR_MODE_REG | RSB_DMCR_DEV_ADDR, rsb->regs + RSB_DMCR); in sunxi_rsb_init_device_mode()
535 readl_poll_timeout(rsb->regs + RSB_DMCR, reg, in sunxi_rsb_init_device_mode()
541 writel(readl(rsb->regs + RSB_INTS), rsb->regs + RSB_INTS); in sunxi_rsb_init_device_mode()
580 static int of_rsb_register_devices(struct sunxi_rsb *rsb) in of_rsb_register_devices() argument
582 struct device *dev = rsb->dev; in of_rsb_register_devices()
616 writel(RSB_CMD_STRA, rsb->regs + RSB_CMD); in of_rsb_register_devices()
618 rsb->regs + RSB_DAR); in of_rsb_register_devices()
621 ret = _sunxi_rsb_run_xfer(rsb); in of_rsb_register_devices()
641 rdev = sunxi_rsb_device_create(rsb, child, hwaddr, rtaddr); in of_rsb_register_devices()
650 static int sunxi_rsb_hw_init(struct sunxi_rsb *rsb) in sunxi_rsb_hw_init() argument
652 struct device *dev = rsb->dev; in sunxi_rsb_hw_init()
657 ret = clk_prepare_enable(rsb->clk); in sunxi_rsb_hw_init()
663 ret = reset_control_deassert(rsb->rstc); in sunxi_rsb_hw_init()
670 writel(RSB_CTRL_SOFT_RST, rsb->regs + RSB_CTRL); in sunxi_rsb_hw_init()
671 readl_poll_timeout(rsb->regs + RSB_CTRL, reg, in sunxi_rsb_hw_init()
681 p_clk_freq = clk_get_rate(rsb->clk); in sunxi_rsb_hw_init()
682 clk_div = p_clk_freq / rsb->clk_freq / 2; in sunxi_rsb_hw_init()
694 rsb->regs + RSB_CCR); in sunxi_rsb_hw_init()
699 clk_disable_unprepare(rsb->clk); in sunxi_rsb_hw_init()
704 static void sunxi_rsb_hw_exit(struct sunxi_rsb *rsb) in sunxi_rsb_hw_exit() argument
706 reset_control_assert(rsb->rstc); in sunxi_rsb_hw_exit()
709 if (!pm_runtime_status_suspended(rsb->dev)) in sunxi_rsb_hw_exit()
710 clk_disable_unprepare(rsb->clk); in sunxi_rsb_hw_exit()
715 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_runtime_suspend() local
717 clk_disable_unprepare(rsb->clk); in sunxi_rsb_runtime_suspend()
724 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_runtime_resume() local
726 return clk_prepare_enable(rsb->clk); in sunxi_rsb_runtime_resume()
731 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_suspend() local
733 sunxi_rsb_hw_exit(rsb); in sunxi_rsb_suspend()
740 struct sunxi_rsb *rsb = dev_get_drvdata(dev); in sunxi_rsb_resume() local
742 return sunxi_rsb_hw_init(rsb); in sunxi_rsb_resume()
749 struct sunxi_rsb *rsb; in sunxi_rsb_probe() local
761 rsb = devm_kzalloc(dev, sizeof(*rsb), GFP_KERNEL); in sunxi_rsb_probe()
762 if (!rsb) in sunxi_rsb_probe()
765 rsb->dev = dev; in sunxi_rsb_probe()
766 rsb->clk_freq = clk_freq; in sunxi_rsb_probe()
767 platform_set_drvdata(pdev, rsb); in sunxi_rsb_probe()
768 rsb->regs = devm_platform_ioremap_resource(pdev, 0); in sunxi_rsb_probe()
769 if (IS_ERR(rsb->regs)) in sunxi_rsb_probe()
770 return PTR_ERR(rsb->regs); in sunxi_rsb_probe()
776 rsb->clk = devm_clk_get(dev, NULL); in sunxi_rsb_probe()
777 if (IS_ERR(rsb->clk)) { in sunxi_rsb_probe()
778 ret = PTR_ERR(rsb->clk); in sunxi_rsb_probe()
783 rsb->rstc = devm_reset_control_get(dev, NULL); in sunxi_rsb_probe()
784 if (IS_ERR(rsb->rstc)) { in sunxi_rsb_probe()
785 ret = PTR_ERR(rsb->rstc); in sunxi_rsb_probe()
790 init_completion(&rsb->complete); in sunxi_rsb_probe()
791 mutex_init(&rsb->lock); in sunxi_rsb_probe()
793 ret = devm_request_irq(dev, irq, sunxi_rsb_irq, 0, RSB_CTRL_NAME, rsb); in sunxi_rsb_probe()
800 ret = sunxi_rsb_hw_init(rsb); in sunxi_rsb_probe()
805 ret = sunxi_rsb_init_device_mode(rsb); in sunxi_rsb_probe()
815 of_rsb_register_devices(rsb); in sunxi_rsb_probe()
822 struct sunxi_rsb *rsb = platform_get_drvdata(pdev); in sunxi_rsb_remove() local
824 device_for_each_child(rsb->dev, NULL, sunxi_rsb_remove_devices); in sunxi_rsb_remove()
826 sunxi_rsb_hw_exit(rsb); in sunxi_rsb_remove()