Lines Matching refs:sadi
157 static int sprd_adi_check_addr(struct sprd_adi *sadi, u32 reg) in sprd_adi_check_addr() argument
159 if (reg >= sadi->data->slave_addr_size) { in sprd_adi_check_addr()
160 dev_err(sadi->dev, in sprd_adi_check_addr()
169 static int sprd_adi_drain_fifo(struct sprd_adi *sadi) in sprd_adi_drain_fifo() argument
175 sts = readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS); in sprd_adi_drain_fifo()
183 dev_err(sadi->dev, "drain write fifo timeout\n"); in sprd_adi_drain_fifo()
190 static int sprd_adi_fifo_is_full(struct sprd_adi *sadi) in sprd_adi_fifo_is_full() argument
192 return readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS) & BIT_FIFO_FULL; in sprd_adi_fifo_is_full()
219 static int sprd_adi_read(struct sprd_adi *sadi, u32 reg, u32 *read_val) in sprd_adi_read() argument
226 if (sadi->hwlock) { in sprd_adi_read()
227 ret = hwspin_lock_timeout_irqsave(sadi->hwlock, in sprd_adi_read()
231 dev_err(sadi->dev, "get the hw lock failed\n"); in sprd_adi_read()
236 ret = sprd_adi_check_addr(sadi, reg); in sprd_adi_read()
244 writel_relaxed(reg, sadi->base + REG_ADI_RD_CMD); in sprd_adi_read()
253 val = readl_relaxed(sadi->base + REG_ADI_RD_DATA); in sprd_adi_read()
261 dev_err(sadi->dev, "ADI read timeout\n"); in sprd_adi_read()
272 if (sadi->data->read_check) { in sprd_adi_read()
273 ret = sadi->data->read_check(val, reg); in sprd_adi_read()
281 if (sadi->hwlock) in sprd_adi_read()
282 hwspin_unlock_irqrestore(sadi->hwlock, &flags); in sprd_adi_read()
286 static int sprd_adi_write(struct sprd_adi *sadi, u32 reg, u32 val) in sprd_adi_write() argument
292 if (sadi->hwlock) { in sprd_adi_write()
293 ret = hwspin_lock_timeout_irqsave(sadi->hwlock, in sprd_adi_write()
297 dev_err(sadi->dev, "get the hw lock failed\n"); in sprd_adi_write()
302 ret = sprd_adi_check_addr(sadi, reg); in sprd_adi_write()
306 ret = sprd_adi_drain_fifo(sadi); in sprd_adi_write()
315 if (!sprd_adi_fifo_is_full(sadi)) { in sprd_adi_write()
317 writel_relaxed(val, (void __iomem *)(sadi->slave_vbase + reg)); in sprd_adi_write()
325 dev_err(sadi->dev, "write fifo is full\n"); in sprd_adi_write()
330 if (sadi->hwlock) in sprd_adi_write()
331 hwspin_unlock_irqrestore(sadi->hwlock, &flags); in sprd_adi_write()
339 struct sprd_adi *sadi = spi_controller_get_devdata(ctlr); in sprd_adi_transfer_one() local
345 ret = sprd_adi_read(sadi, reg, &val); in sprd_adi_transfer_one()
351 ret = sprd_adi_write(sadi, reg, val); in sprd_adi_transfer_one()
353 dev_err(sadi->dev, "no buffer for transfer\n"); in sprd_adi_transfer_one()
364 struct sprd_adi *sadi = (struct sprd_adi *)p; in sprd_adi_set_wdt_rst_mode() local
367 sprd_adi_read(sadi, PMIC_RST_STATUS, &val); in sprd_adi_set_wdt_rst_mode()
369 sprd_adi_write(sadi, PMIC_RST_STATUS, val); in sprd_adi_set_wdt_rst_mode()
376 struct sprd_adi *sadi = container_of(this, struct sprd_adi, in sprd_adi_restart() local
410 sprd_adi_read(sadi, wdg->rst_sts, &val); in sprd_adi_restart()
413 sprd_adi_write(sadi, wdg->rst_sts, val); in sprd_adi_restart()
416 sprd_adi_read(sadi, wdg->wdg_en, &val); in sprd_adi_restart()
418 sprd_adi_write(sadi, wdg->wdg_en, val); in sprd_adi_restart()
421 sprd_adi_read(sadi, wdg->wdg_clk, &val); in sprd_adi_restart()
423 sprd_adi_write(sadi, wdg->wdg_clk, val); in sprd_adi_restart()
426 sprd_adi_write(sadi, wdg->base + REG_WDG_LOCK, WDG_UNLOCK_KEY); in sprd_adi_restart()
428 sprd_adi_read(sadi, wdg->base + REG_WDG_CTRL, &val); in sprd_adi_restart()
430 sprd_adi_write(sadi, wdg->base + REG_WDG_CTRL, val); in sprd_adi_restart()
433 sprd_adi_write(sadi, wdg->base + REG_WDG_LOAD_HIGH, 0); in sprd_adi_restart()
434 sprd_adi_write(sadi, wdg->base + REG_WDG_LOAD_LOW, in sprd_adi_restart()
438 sprd_adi_read(sadi, wdg->base + REG_WDG_CTRL, &val); in sprd_adi_restart()
440 sprd_adi_write(sadi, wdg->base + REG_WDG_CTRL, val); in sprd_adi_restart()
443 sprd_adi_write(sadi, wdg->base + REG_WDG_LOCK, ~WDG_UNLOCK_KEY); in sprd_adi_restart()
447 dev_emerg(sadi->dev, "Unable to restart system\n"); in sprd_adi_restart()
464 static void sprd_adi_hw_init(struct sprd_adi *sadi) in sprd_adi_hw_init() argument
466 struct device_node *np = sadi->dev->of_node; in sprd_adi_hw_init()
472 writel_relaxed(0, sadi->base + REG_ADI_CHN_PRIL); in sprd_adi_hw_init()
473 writel_relaxed(0, sadi->base + REG_ADI_CHN_PRIH); in sprd_adi_hw_init()
476 tmp = readl_relaxed(sadi->base + REG_ADI_GSSI_CFG0); in sprd_adi_hw_init()
478 writel_relaxed(tmp, sadi->base + REG_ADI_GSSI_CFG0); in sprd_adi_hw_init()
483 dev_info(sadi->dev, "no hw channels setting in node\n"); in sprd_adi_hw_init()
497 writel_relaxed(chn_config, sadi->base + in sprd_adi_hw_init()
501 value = readl_relaxed(sadi->base + REG_ADI_CHN_EN); in sprd_adi_hw_init()
503 writel_relaxed(value, sadi->base + REG_ADI_CHN_EN); in sprd_adi_hw_init()
505 value = readl_relaxed(sadi->base + REG_ADI_CHN_EN1); in sprd_adi_hw_init()
507 writel_relaxed(value, sadi->base + REG_ADI_CHN_EN1); in sprd_adi_hw_init()
517 struct sprd_adi *sadi; in sprd_adi_probe() local
541 sadi = spi_controller_get_devdata(ctlr); in sprd_adi_probe()
543 sadi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in sprd_adi_probe()
544 if (IS_ERR(sadi->base)) { in sprd_adi_probe()
545 ret = PTR_ERR(sadi->base); in sprd_adi_probe()
549 sadi->slave_vbase = (unsigned long)sadi->base + in sprd_adi_probe()
551 sadi->slave_pbase = res->start + data->slave_offset; in sprd_adi_probe()
552 sadi->ctlr = ctlr; in sprd_adi_probe()
553 sadi->dev = &pdev->dev; in sprd_adi_probe()
554 sadi->data = data; in sprd_adi_probe()
557 sadi->hwlock = in sprd_adi_probe()
559 if (!sadi->hwlock) { in sprd_adi_probe()
574 sprd_adi_hw_init(sadi); in sprd_adi_probe()
576 if (sadi->data->wdg_rst) in sprd_adi_probe()
577 sadi->data->wdg_rst(sadi); in sprd_adi_probe()
592 if (sadi->data->restart) { in sprd_adi_probe()
593 sadi->restart_handler.notifier_call = sadi->data->restart; in sprd_adi_probe()
594 sadi->restart_handler.priority = 128; in sprd_adi_probe()
595 ret = register_restart_handler(&sadi->restart_handler); in sprd_adi_probe()
612 struct sprd_adi *sadi = spi_controller_get_devdata(ctlr); in sprd_adi_remove() local
614 unregister_restart_handler(&sadi->restart_handler); in sprd_adi_remove()