Lines Matching +full:reg +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0-or-later
19 #include "fsi-master.h"
97 static int __opb_write(struct fsi_master_aspeed *aspeed, u32 addr, in __opb_write() argument
100 void __iomem *base = aspeed->base; in __opb_write()
101 u32 reg, status; in __opb_write() local
110 writel_relaxed(addr, base + OPB0_FSI_ADDR); in __opb_write()
115 ret = readl_poll_timeout(base + OPB_IRQ_STATUS, reg, in __opb_write()
116 (reg & OPB0_XFER_ACK_EN) != 0, in __opb_write()
121 trace_fsi_master_aspeed_opb_write(addr, val, transfer_size, status, reg); in __opb_write()
129 return -EIO; in __opb_write()
134 static int opb_writeb(struct fsi_master_aspeed *aspeed, u32 addr, u8 val) in opb_writeb() argument
136 return __opb_write(aspeed, addr, val, XFER_BYTE); in opb_writeb()
139 static int opb_writew(struct fsi_master_aspeed *aspeed, u32 addr, __be16 val) in opb_writew() argument
141 return __opb_write(aspeed, addr, (__force u16)val, XFER_HALFWORD); in opb_writew()
144 static int opb_writel(struct fsi_master_aspeed *aspeed, u32 addr, __be32 val) in opb_writel() argument
146 return __opb_write(aspeed, addr, (__force u32)val, XFER_FULLWORD); in opb_writel()
149 static int __opb_read(struct fsi_master_aspeed *aspeed, uint32_t addr, in __opb_read() argument
152 void __iomem *base = aspeed->base; in __opb_read()
153 u32 result, reg; in __opb_read() local
162 writel_relaxed(addr, base + OPB0_FSI_ADDR); in __opb_read()
166 ret = readl_poll_timeout(base + OPB_IRQ_STATUS, reg, in __opb_read()
167 (reg & OPB0_XFER_ACK_EN) != 0, in __opb_read()
174 trace_fsi_master_aspeed_opb_read(addr, transfer_size, result, in __opb_read()
176 reg); in __opb_read()
184 return -EIO; in __opb_read()
198 return -EINVAL; in __opb_read()
206 static int opb_readl(struct fsi_master_aspeed *aspeed, uint32_t addr, __be32 *out) in opb_readl() argument
208 return __opb_read(aspeed, addr, XFER_FULLWORD, out); in opb_readl()
211 static int opb_readw(struct fsi_master_aspeed *aspeed, uint32_t addr, __be16 *out) in opb_readw() argument
213 return __opb_read(aspeed, addr, XFER_HALFWORD, (void *)out); in opb_readw()
216 static int opb_readb(struct fsi_master_aspeed *aspeed, uint32_t addr, u8 *out) in opb_readb() argument
218 return __opb_read(aspeed, addr, XFER_BYTE, (void *)out); in opb_readb()
238 if (err == -EIO) { in check_errors()
256 uint8_t id, uint32_t addr, void *val, size_t size) in aspeed_master_read() argument
262 return -EINVAL; in aspeed_master_read()
264 addr |= id << 21; in aspeed_master_read()
265 addr += link * FSI_HUB_LINK_SIZE; in aspeed_master_read()
267 mutex_lock(&aspeed->lock); in aspeed_master_read()
271 ret = opb_readb(aspeed, fsi_base + addr, val); in aspeed_master_read()
274 ret = opb_readw(aspeed, fsi_base + addr, val); in aspeed_master_read()
277 ret = opb_readl(aspeed, fsi_base + addr, val); in aspeed_master_read()
280 ret = -EINVAL; in aspeed_master_read()
286 mutex_unlock(&aspeed->lock); in aspeed_master_read()
291 uint8_t id, uint32_t addr, const void *val, size_t size) in aspeed_master_write() argument
297 return -EINVAL; in aspeed_master_write()
299 addr |= id << 21; in aspeed_master_write()
300 addr += link * FSI_HUB_LINK_SIZE; in aspeed_master_write()
302 mutex_lock(&aspeed->lock); in aspeed_master_write()
306 ret = opb_writeb(aspeed, fsi_base + addr, *(u8 *)val); in aspeed_master_write()
309 ret = opb_writew(aspeed, fsi_base + addr, *(__be16 *)val); in aspeed_master_write()
312 ret = opb_writel(aspeed, fsi_base + addr, *(__be32 *)val); in aspeed_master_write()
315 ret = -EINVAL; in aspeed_master_write()
321 mutex_unlock(&aspeed->lock); in aspeed_master_write()
330 __be32 reg; in aspeed_master_link_enable() local
335 reg = cpu_to_be32(0x80000000 >> bit); in aspeed_master_link_enable()
337 mutex_lock(&aspeed->lock); in aspeed_master_link_enable()
340 ret = opb_writel(aspeed, ctrl_base + FSI_MCENP0 + (4 * idx), reg); in aspeed_master_link_enable()
344 ret = opb_writel(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx), reg); in aspeed_master_link_enable()
350 mutex_unlock(&aspeed->lock); in aspeed_master_link_enable()
356 uint32_t addr; in aspeed_master_term() local
359 addr = 0x4; in aspeed_master_term()
362 return aspeed_master_write(master, link, id, addr, &cmd, 4); in aspeed_master_term()
367 uint32_t addr; in aspeed_master_break() local
370 addr = 0x0; in aspeed_master_break()
373 return aspeed_master_write(master, link, 0, addr, &cmd, 4); in aspeed_master_break()
397 __be32 reg; in aspeed_master_init() local
399 reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK in aspeed_master_init()
401 opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg); in aspeed_master_init()
404 reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK in aspeed_master_init()
406 opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg); in aspeed_master_init()
408 reg = cpu_to_be32(FSI_MECTRL_EOAE | FSI_MECTRL_P8_AUTO_TERM); in aspeed_master_init()
409 opb_writel(aspeed, ctrl_base + FSI_MECTRL, reg); in aspeed_master_init()
411 reg = cpu_to_be32(FSI_MMODE_ECRC | FSI_MMODE_EPC | FSI_MMODE_RELA in aspeed_master_init()
415 dev_info(aspeed->dev, "mmode set to %08x (divisor %d)\n", in aspeed_master_init()
416 be32_to_cpu(reg), aspeed_fsi_divisor); in aspeed_master_init()
417 opb_writel(aspeed, ctrl_base + FSI_MMODE, reg); in aspeed_master_init()
419 reg = cpu_to_be32(0xffff0000); in aspeed_master_init()
420 opb_writel(aspeed, ctrl_base + FSI_MDLYR, reg); in aspeed_master_init()
422 reg = cpu_to_be32(~0); in aspeed_master_init()
423 opb_writel(aspeed, ctrl_base + FSI_MSENP0, reg); in aspeed_master_init()
428 opb_writel(aspeed, ctrl_base + FSI_MCENP0, reg); in aspeed_master_init()
432 reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK); in aspeed_master_init()
433 opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg); in aspeed_master_init()
438 reg = cpu_to_be32(FSI_MRESB_RST_GEN); in aspeed_master_init()
439 opb_writel(aspeed, ctrl_base + FSI_MRESB0, reg); in aspeed_master_init()
441 reg = cpu_to_be32(FSI_MRESB_RST_ERR); in aspeed_master_init()
442 opb_writel(aspeed, ctrl_base + FSI_MRESB0, reg); in aspeed_master_init()
453 mutex_lock(&aspeed->lock); in cfam_reset_store()
454 gpiod_set_value(aspeed->cfam_reset_gpio, 1); in cfam_reset_store()
456 gpiod_set_value(aspeed->cfam_reset_gpio, 0); in cfam_reset_store()
459 mutex_unlock(&aspeed->lock); in cfam_reset_store()
469 struct device *dev = aspeed->dev; in setup_cfam_reset()
473 gpio = devm_gpiod_get_optional(dev, "cfam-reset", GPIOD_OUT_LOW); in setup_cfam_reset()
479 aspeed->cfam_reset_gpio = gpio; in setup_cfam_reset()
499 routing_gpio = devm_gpiod_get_optional(dev, "fsi-routing", in tacoma_cabled_fsi_fixup()
506 mux_gpio = devm_gpiod_get_optional(dev, "fsi-mux", GPIOD_ASIS); in tacoma_cabled_fsi_fixup()
540 int rc, links, reg; in fsi_master_aspeed_probe() local
543 rc = tacoma_cabled_fsi_fixup(&pdev->dev); in fsi_master_aspeed_probe()
545 dev_err(&pdev->dev, "Tacoma FSI cable fixup failed\n"); in fsi_master_aspeed_probe()
551 return -ENOMEM; in fsi_master_aspeed_probe()
553 aspeed->dev = &pdev->dev; in fsi_master_aspeed_probe()
555 aspeed->base = devm_platform_ioremap_resource(pdev, 0); in fsi_master_aspeed_probe()
556 if (IS_ERR(aspeed->base)) { in fsi_master_aspeed_probe()
557 rc = PTR_ERR(aspeed->base); in fsi_master_aspeed_probe()
561 aspeed->clk = devm_clk_get(aspeed->dev, NULL); in fsi_master_aspeed_probe()
562 if (IS_ERR(aspeed->clk)) { in fsi_master_aspeed_probe()
563 dev_err(aspeed->dev, "couldn't get clock\n"); in fsi_master_aspeed_probe()
564 rc = PTR_ERR(aspeed->clk); in fsi_master_aspeed_probe()
567 rc = clk_prepare_enable(aspeed->clk); in fsi_master_aspeed_probe()
569 dev_err(aspeed->dev, "couldn't enable clock\n"); in fsi_master_aspeed_probe()
575 dev_err(&pdev->dev, "CFAM reset GPIO setup failed\n"); in fsi_master_aspeed_probe()
578 writel(0x1, aspeed->base + OPB_CLK_SYNC); in fsi_master_aspeed_probe()
580 aspeed->base + OPB_IRQ_MASK); in fsi_master_aspeed_probe()
583 writel(0x10, aspeed->base + OPB_RETRY_COUNTER); in fsi_master_aspeed_probe()
585 writel(ctrl_base, aspeed->base + OPB_CTRL_BASE); in fsi_master_aspeed_probe()
586 writel(fsi_base, aspeed->base + OPB_FSI_BASE); in fsi_master_aspeed_probe()
589 writel(0x00030b1b, aspeed->base + OPB0_READ_ORDER1); in fsi_master_aspeed_probe()
592 writel(0x0011101b, aspeed->base + OPB0_WRITE_ORDER1); in fsi_master_aspeed_probe()
593 writel(0x0c330f3f, aspeed->base + OPB0_WRITE_ORDER2); in fsi_master_aspeed_probe()
600 writel(0x1, aspeed->base + OPB0_SELECT); in fsi_master_aspeed_probe()
604 dev_err(&pdev->dev, "failed to read hub version\n"); in fsi_master_aspeed_probe()
608 reg = be32_to_cpu(raw); in fsi_master_aspeed_probe()
609 links = (reg >> 8) & 0xff; in fsi_master_aspeed_probe()
610 dev_info(&pdev->dev, "hub version %08x (%d links)\n", reg, links); in fsi_master_aspeed_probe()
612 aspeed->master.dev.parent = &pdev->dev; in fsi_master_aspeed_probe()
613 aspeed->master.dev.release = aspeed_master_release; in fsi_master_aspeed_probe()
614 aspeed->master.dev.of_node = of_node_get(dev_of_node(&pdev->dev)); in fsi_master_aspeed_probe()
616 aspeed->master.n_links = links; in fsi_master_aspeed_probe()
617 aspeed->master.read = aspeed_master_read; in fsi_master_aspeed_probe()
618 aspeed->master.write = aspeed_master_write; in fsi_master_aspeed_probe()
619 aspeed->master.send_break = aspeed_master_break; in fsi_master_aspeed_probe()
620 aspeed->master.term = aspeed_master_term; in fsi_master_aspeed_probe()
621 aspeed->master.link_enable = aspeed_master_link_enable; in fsi_master_aspeed_probe()
623 dev_set_drvdata(&pdev->dev, aspeed); in fsi_master_aspeed_probe()
625 mutex_init(&aspeed->lock); in fsi_master_aspeed_probe()
628 rc = fsi_master_register(&aspeed->master); in fsi_master_aspeed_probe()
634 * will be freed (via ->release) during any subsequent call to in fsi_master_aspeed_probe()
639 get_device(&aspeed->master.dev); in fsi_master_aspeed_probe()
643 clk_disable_unprepare(aspeed->clk); in fsi_master_aspeed_probe()
653 fsi_master_unregister(&aspeed->master); in fsi_master_aspeed_remove()
654 clk_disable_unprepare(aspeed->clk); in fsi_master_aspeed_remove()
658 { .compatible = "aspeed,ast2600-fsi-master" },
665 .name = "fsi-master-aspeed",