Lines Matching full:rsb

3  * RSB (Reduced Serial Bus) driver.
7 * The RSB controller looks like an SMBus controller which only supports
24 * RSB section of Allwinner's A80 user manual, which can be found at
49 #include <linux/sunxi-rsb.h>
52 /* RSB registers */
61 #define RSB_CMD 0x2c /* RSB Command */
112 #define RSB_CTRL_NAME "sunxi-rsb"
196 * sunxi_rsb_device_create() - allocate and add an RSB device
197 * @rsb: RSB controller
198 * @node: RSB slave device node
199 * @hwaddr: RSB slave hardware address
200 * @rtaddr: RSB slave runtime address
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()
240 * sunxi_rsb_device_unregister(): unregister an RSB device
259 * sunxi_rsb_driver_register() - Register device driver with RSB core
262 * This API will register the client driver with the RSB framework.
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()
426 /* RSB regmap functions */
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()
507 /* RSB controller driver functions */
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()
553 * No designs with 2 RSB slave devices sharing identical hardware
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()
692 dev_info(dev, "RSB running at %lu Hz\n", p_clk_freq / clk_div / 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
759 rsb = devm_kzalloc(dev, sizeof(*rsb), GFP_KERNEL); in sunxi_rsb_probe()
760 if (!rsb) in sunxi_rsb_probe()
763 rsb->dev = dev; in sunxi_rsb_probe()
764 rsb->clk_freq = clk_freq; in sunxi_rsb_probe()
765 platform_set_drvdata(pdev, rsb); in sunxi_rsb_probe()
766 rsb->regs = devm_platform_ioremap_resource(pdev, 0); in sunxi_rsb_probe()
767 if (IS_ERR(rsb->regs)) in sunxi_rsb_probe()
768 return PTR_ERR(rsb->regs); in sunxi_rsb_probe()
774 rsb->clk = devm_clk_get(dev, NULL); in sunxi_rsb_probe()
775 if (IS_ERR(rsb->clk)) in sunxi_rsb_probe()
776 return dev_err_probe(dev, PTR_ERR(rsb->clk), in sunxi_rsb_probe()
779 rsb->rstc = devm_reset_control_get(dev, NULL); in sunxi_rsb_probe()
780 if (IS_ERR(rsb->rstc)) in sunxi_rsb_probe()
781 return dev_err_probe(dev, PTR_ERR(rsb->rstc), in sunxi_rsb_probe()
784 init_completion(&rsb->complete); in sunxi_rsb_probe()
785 mutex_init(&rsb->lock); in sunxi_rsb_probe()
787 ret = devm_request_irq(dev, irq, sunxi_rsb_irq, 0, RSB_CTRL_NAME, rsb); in sunxi_rsb_probe()
792 ret = sunxi_rsb_hw_init(rsb); in sunxi_rsb_probe()
796 /* initialize all devices on the bus into RSB mode */ in sunxi_rsb_probe()
797 ret = sunxi_rsb_init_device_mode(rsb); in sunxi_rsb_probe()
807 of_rsb_register_devices(rsb); in sunxi_rsb_probe()
814 struct sunxi_rsb *rsb = platform_get_drvdata(pdev); in sunxi_rsb_remove() local
816 device_for_each_child(rsb->dev, NULL, sunxi_rsb_remove_devices); in sunxi_rsb_remove()
818 sunxi_rsb_hw_exit(rsb); in sunxi_rsb_remove()
828 { .compatible = "allwinner,sun8i-a23-rsb" },