Lines Matching +full:sc9860 +full:- +full:adi
4 * SPDX-License-Identifier: GPL-2.0
19 /* Registers definitions for ADI controller */
36 #define REG_ADI_CHN_ADDR(id) (0x44 + (id - 2) * 4)
53 * ADI slave devices include RTC, ADC, regulator, charger, thermal and so on.
54 * ADI supports 12/14bit address for r2p0, and additional 17bit for r3p0 or
72 * ADI controller has 50 channels including 2 software channels
157 if (reg >= sadi->data->slave_addr_size) { in sprd_adi_check_addr()
158 dev_err(sadi->dev, in sprd_adi_check_addr()
161 return -EINVAL; in sprd_adi_check_addr()
173 sts = readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS); in sprd_adi_drain_fifo()
178 } while (--timeout); in sprd_adi_drain_fifo()
181 dev_err(sadi->dev, "drain write fifo timeout\n"); in sprd_adi_drain_fifo()
182 return -EBUSY; in sprd_adi_drain_fifo()
190 return readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS) & BIT_FIFO_FULL; in sprd_adi_fifo_is_full()
200 pr_err("ADI read error, addr = 0x%x, val = 0x%x\n", addr, val); in sprd_adi_read_check()
201 return -EIO; in sprd_adi_read_check()
224 if (sadi->hwlock) { in sprd_adi_read()
225 ret = hwspin_lock_timeout_irqsave(sadi->hwlock, in sprd_adi_read()
229 dev_err(sadi->dev, "get the hw lock failed\n"); in sprd_adi_read()
240 * then ADI controller will start to transfer automatically. in sprd_adi_read()
242 writel_relaxed(reg, sadi->base + REG_ADI_RD_CMD); in sprd_adi_read()
251 val = readl_relaxed(sadi->base + REG_ADI_RD_DATA); in sprd_adi_read()
256 } while (--read_timeout); in sprd_adi_read()
259 dev_err(sadi->dev, "ADI read timeout\n"); in sprd_adi_read()
260 ret = -EBUSY; in sprd_adi_read()
265 * The return value before adi r5p0 includes data and read register in sprd_adi_read()
270 if (sadi->data->read_check) { in sprd_adi_read()
271 ret = sadi->data->read_check(val, reg); in sprd_adi_read()
279 if (sadi->hwlock) in sprd_adi_read()
280 hwspin_unlock_irqrestore(sadi->hwlock, &flags); in sprd_adi_read()
290 if (sadi->hwlock) { in sprd_adi_write()
291 ret = hwspin_lock_timeout_irqsave(sadi->hwlock, in sprd_adi_write()
295 dev_err(sadi->dev, "get the hw lock failed\n"); in sprd_adi_write()
315 writel_relaxed(val, (void __iomem *)(sadi->slave_vbase + reg)); in sprd_adi_write()
320 } while (--timeout); in sprd_adi_write()
323 dev_err(sadi->dev, "write fifo is full\n"); in sprd_adi_write()
324 ret = -EBUSY; in sprd_adi_write()
328 if (sadi->hwlock) in sprd_adi_write()
329 hwspin_unlock_irqrestore(sadi->hwlock, &flags); in sprd_adi_write()
341 if (t->rx_buf) { in sprd_adi_transfer_one()
342 reg = *(u32 *)t->rx_buf; in sprd_adi_transfer_one()
344 *(u32 *)t->rx_buf = val; in sprd_adi_transfer_one()
345 } else if (t->tx_buf) { in sprd_adi_transfer_one()
346 u32 *p = (u32 *)t->tx_buf; in sprd_adi_transfer_one()
351 dev_err(sadi->dev, "no buffer for transfer\n"); in sprd_adi_transfer_one()
352 ret = -EINVAL; in sprd_adi_transfer_one()
406 sprd_adi_read(sadi, wdg->rst_sts, &val); in sprd_adi_restart()
409 sprd_adi_write(sadi, wdg->rst_sts, val); in sprd_adi_restart()
412 sprd_adi_read(sadi, wdg->wdg_en, &val); in sprd_adi_restart()
414 sprd_adi_write(sadi, wdg->wdg_en, val); in sprd_adi_restart()
417 sprd_adi_read(sadi, wdg->wdg_clk, &val); in sprd_adi_restart()
419 sprd_adi_write(sadi, wdg->wdg_clk, val); in sprd_adi_restart()
422 sprd_adi_write(sadi, wdg->base + REG_WDG_LOCK, WDG_UNLOCK_KEY); in sprd_adi_restart()
424 sprd_adi_read(sadi, wdg->base + REG_WDG_CTRL, &val); in sprd_adi_restart()
426 sprd_adi_write(sadi, wdg->base + REG_WDG_CTRL, val); in sprd_adi_restart()
429 sprd_adi_write(sadi, wdg->base + REG_WDG_LOAD_HIGH, 0); in sprd_adi_restart()
430 sprd_adi_write(sadi, wdg->base + REG_WDG_LOAD_LOW, in sprd_adi_restart()
434 sprd_adi_read(sadi, wdg->base + REG_WDG_CTRL, &val); in sprd_adi_restart()
436 sprd_adi_write(sadi, wdg->base + REG_WDG_CTRL, val); in sprd_adi_restart()
439 sprd_adi_write(sadi, wdg->base + REG_WDG_LOCK, ~WDG_UNLOCK_KEY); in sprd_adi_restart()
443 dev_emerg(sadi->dev, "Unable to restart system\n"); in sprd_adi_restart()
456 return sprd_adi_restart(data->cb_data, data->mode, data->cmd, &wdg); in sprd_adi_restart_sc9860()
461 struct device_node *np = sadi->dev->of_node; in sprd_adi_hw_init()
467 writel_relaxed(0, sadi->base + REG_ADI_CHN_PRIL); in sprd_adi_hw_init()
468 writel_relaxed(0, sadi->base + REG_ADI_CHN_PRIH); in sprd_adi_hw_init()
471 tmp = readl_relaxed(sadi->base + REG_ADI_GSSI_CFG0); in sprd_adi_hw_init()
473 writel_relaxed(tmp, sadi->base + REG_ADI_GSSI_CFG0); in sprd_adi_hw_init()
476 list = of_get_property(np, "sprd,hw-channels", &size); in sprd_adi_hw_init()
478 dev_info(sadi->dev, "no hw channels setting in node\n"); in sprd_adi_hw_init()
492 writel_relaxed(chn_config, sadi->base + in sprd_adi_hw_init()
496 value = readl_relaxed(sadi->base + REG_ADI_CHN_EN); in sprd_adi_hw_init()
498 writel_relaxed(value, sadi->base + REG_ADI_CHN_EN); in sprd_adi_hw_init()
500 value = readl_relaxed(sadi->base + REG_ADI_CHN_EN1); in sprd_adi_hw_init()
501 value |= BIT(chn_id - 32); in sprd_adi_hw_init()
502 writel_relaxed(value, sadi->base + REG_ADI_CHN_EN1); in sprd_adi_hw_init()
509 struct device_node *np = pdev->dev.of_node; in sprd_adi_probe()
518 dev_err(&pdev->dev, "can not find the adi bus node\n"); in sprd_adi_probe()
519 return -ENODEV; in sprd_adi_probe()
522 data = of_device_get_match_data(&pdev->dev); in sprd_adi_probe()
524 dev_err(&pdev->dev, "no matching driver data found\n"); in sprd_adi_probe()
525 return -EINVAL; in sprd_adi_probe()
528 pdev->id = of_alias_get_id(np, "spi"); in sprd_adi_probe()
531 ctlr = spi_alloc_host(&pdev->dev, sizeof(struct sprd_adi)); in sprd_adi_probe()
533 return -ENOMEM; in sprd_adi_probe()
535 dev_set_drvdata(&pdev->dev, ctlr); in sprd_adi_probe()
538 sadi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in sprd_adi_probe()
539 if (IS_ERR(sadi->base)) { in sprd_adi_probe()
540 ret = PTR_ERR(sadi->base); in sprd_adi_probe()
544 sadi->slave_vbase = (unsigned long)sadi->base + in sprd_adi_probe()
545 data->slave_offset; in sprd_adi_probe()
546 sadi->slave_pbase = res->start + data->slave_offset; in sprd_adi_probe()
547 sadi->ctlr = ctlr; in sprd_adi_probe()
548 sadi->dev = &pdev->dev; in sprd_adi_probe()
549 sadi->data = data; in sprd_adi_probe()
552 sadi->hwlock = in sprd_adi_probe()
553 devm_hwspin_lock_request_specific(&pdev->dev, ret); in sprd_adi_probe()
554 if (!sadi->hwlock) { in sprd_adi_probe()
555 ret = -ENXIO; in sprd_adi_probe()
560 case -ENOENT: in sprd_adi_probe()
561 dev_info(&pdev->dev, "no hardware spinlock supplied\n"); in sprd_adi_probe()
564 dev_err_probe(&pdev->dev, ret, "failed to find hwlock id\n"); in sprd_adi_probe()
571 if (sadi->data->wdg_rst) in sprd_adi_probe()
572 sadi->data->wdg_rst(sadi); in sprd_adi_probe()
574 ctlr->dev.of_node = pdev->dev.of_node; in sprd_adi_probe()
575 ctlr->bus_num = pdev->id; in sprd_adi_probe()
576 ctlr->num_chipselect = num_chipselect; in sprd_adi_probe()
577 ctlr->flags = SPI_CONTROLLER_HALF_DUPLEX; in sprd_adi_probe()
578 ctlr->bits_per_word_mask = 0; in sprd_adi_probe()
579 ctlr->transfer_one = sprd_adi_transfer_one; in sprd_adi_probe()
581 ret = devm_spi_register_controller(&pdev->dev, ctlr); in sprd_adi_probe()
583 dev_err(&pdev->dev, "failed to register SPI controller\n"); in sprd_adi_probe()
587 if (sadi->data->restart) { in sprd_adi_probe()
588 ret = devm_register_restart_handler(&pdev->dev, in sprd_adi_probe()
589 sadi->data->restart, in sprd_adi_probe()
592 dev_err(&pdev->dev, "can not register restart handler\n"); in sprd_adi_probe()
626 .compatible = "sprd,sc9860-adi",
630 .compatible = "sprd,sc9863-adi",
634 .compatible = "sprd,ums512-adi",
643 .name = "sprd-adi",
650 MODULE_DESCRIPTION("Spreadtrum ADI Controller Driver");