Lines Matching +full:ctrl +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0
267 return readl(arb->base + arb->data->regs[reg]); in pmif_readl()
272 writel(val, arb->base + arb->data->regs[reg]); in pmif_writel()
277 writel(val, arb->spmimst_base + arb->data->spmimst_regs[reg]); in mtk_spmi_writel()
284 reg_rdata = pmif_readl(arb, arb->chan.ch_sta); in pmif_is_fsm_vldclr()
289 static int pmif_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) in pmif_arb_cmd() argument
291 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in pmif_arb_cmd()
297 return -EINVAL; in pmif_arb_cmd()
299 cmd = opc - SPMI_CMD_RESET; in pmif_arb_cmd()
302 ret = readl_poll_timeout_atomic(arb->spmimst_base + arb->data->spmimst_regs[SPMI_OP_ST_STA], in pmif_arb_cmd()
306 dev_err(&ctrl->dev, "timeout, err = %d\n", ret); in pmif_arb_cmd()
311 static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, in pmif_spmi_read_cmd() argument
312 u16 addr, u8 *buf, size_t len) in pmif_spmi_read_cmd() argument
314 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in pmif_spmi_read_cmd()
322 dev_err(&ctrl->dev, "exceed the max slv id\n"); in pmif_spmi_read_cmd()
323 return -EINVAL; in pmif_spmi_read_cmd()
326 if (len > 4) { in pmif_spmi_read_cmd()
327 dev_err(&ctrl->dev, "pmif supports 1..4 bytes per trans, but:%zu requested", len); in pmif_spmi_read_cmd()
329 return -EINVAL; in pmif_spmi_read_cmd()
337 return -EINVAL; in pmif_spmi_read_cmd()
339 raw_spin_lock_irqsave(&arb->lock, flags); in pmif_spmi_read_cmd()
341 inf_reg = &arb->chan; in pmif_spmi_read_cmd()
342 ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta], in pmif_spmi_read_cmd()
348 pmif_writel(arb, 1, inf_reg->ch_rdy); in pmif_spmi_read_cmd()
349 raw_spin_unlock_irqrestore(&arb->lock, flags); in pmif_spmi_read_cmd()
350 dev_err(&ctrl->dev, "failed to wait for SWINF_IDLE\n"); in pmif_spmi_read_cmd()
355 cmd = (opc << 30) | (sid << 24) | ((len - 1) << 16) | addr; in pmif_spmi_read_cmd()
356 pmif_writel(arb, cmd, inf_reg->ch_send); in pmif_spmi_read_cmd()
357 raw_spin_unlock_irqrestore(&arb->lock, flags); in pmif_spmi_read_cmd()
363 ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta], in pmif_spmi_read_cmd()
367 dev_err(&ctrl->dev, "failed to wait for SWINF_WFVLDCLR\n"); in pmif_spmi_read_cmd()
371 data = pmif_readl(arb, inf_reg->rdata); in pmif_spmi_read_cmd()
372 memcpy(buf, &data, len); in pmif_spmi_read_cmd()
373 pmif_writel(arb, 1, inf_reg->ch_rdy); in pmif_spmi_read_cmd()
378 static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, in pmif_spmi_write_cmd() argument
379 u16 addr, const u8 *buf, size_t len) in pmif_spmi_write_cmd() argument
381 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in pmif_spmi_write_cmd()
389 dev_err(&ctrl->dev, "exceed the max slv id\n"); in pmif_spmi_write_cmd()
390 return -EINVAL; in pmif_spmi_write_cmd()
393 if (len > 4) { in pmif_spmi_write_cmd()
394 dev_err(&ctrl->dev, "pmif supports 1..4 bytes per trans, but:%zu requested", len); in pmif_spmi_write_cmd()
396 return -EINVAL; in pmif_spmi_write_cmd()
407 return -EINVAL; in pmif_spmi_write_cmd()
410 memcpy(&wdata, buf, len); in pmif_spmi_write_cmd()
412 raw_spin_lock_irqsave(&arb->lock, flags); in pmif_spmi_write_cmd()
414 inf_reg = &arb->chan; in pmif_spmi_write_cmd()
415 ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta], in pmif_spmi_write_cmd()
421 pmif_writel(arb, 1, inf_reg->ch_rdy); in pmif_spmi_write_cmd()
422 raw_spin_unlock_irqrestore(&arb->lock, flags); in pmif_spmi_write_cmd()
423 dev_err(&ctrl->dev, "failed to wait for SWINF_IDLE\n"); in pmif_spmi_write_cmd()
427 pmif_writel(arb, wdata, inf_reg->wdata); in pmif_spmi_write_cmd()
430 cmd = (opc << 30) | BIT(29) | (sid << 24) | ((len - 1) << 16) | addr; in pmif_spmi_write_cmd()
431 pmif_writel(arb, cmd, inf_reg->ch_send); in pmif_spmi_write_cmd()
432 raw_spin_unlock_irqrestore(&arb->lock, flags); in pmif_spmi_write_cmd()
452 struct spmi_controller *ctrl; in mtk_spmi_probe() local
456 ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*arb)); in mtk_spmi_probe()
457 if (IS_ERR(ctrl)) in mtk_spmi_probe()
458 return PTR_ERR(ctrl); in mtk_spmi_probe()
460 arb = spmi_controller_get_drvdata(ctrl); in mtk_spmi_probe()
461 arb->data = device_get_match_data(&pdev->dev); in mtk_spmi_probe()
462 if (!arb->data) { in mtk_spmi_probe()
463 dev_err(&pdev->dev, "Cannot get drv_data\n"); in mtk_spmi_probe()
464 return -EINVAL; in mtk_spmi_probe()
467 arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif"); in mtk_spmi_probe()
468 if (IS_ERR(arb->base)) in mtk_spmi_probe()
469 return PTR_ERR(arb->base); in mtk_spmi_probe()
471 arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst"); in mtk_spmi_probe()
472 if (IS_ERR(arb->spmimst_base)) in mtk_spmi_probe()
473 return PTR_ERR(arb->spmimst_base); in mtk_spmi_probe()
475 arb->nclks = ARRAY_SIZE(pmif_clock_names); in mtk_spmi_probe()
476 for (i = 0; i < arb->nclks; i++) in mtk_spmi_probe()
477 arb->clks[i].id = pmif_clock_names[i]; in mtk_spmi_probe()
479 err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks); in mtk_spmi_probe()
481 dev_err(&pdev->dev, "Failed to get clocks: %d\n", err); in mtk_spmi_probe()
485 err = clk_bulk_prepare_enable(arb->nclks, arb->clks); in mtk_spmi_probe()
487 dev_err(&pdev->dev, "Failed to enable clocks: %d\n", err); in mtk_spmi_probe()
491 ctrl->cmd = pmif_arb_cmd; in mtk_spmi_probe()
492 ctrl->read_cmd = pmif_spmi_read_cmd; in mtk_spmi_probe()
493 ctrl->write_cmd = pmif_spmi_write_cmd; in mtk_spmi_probe()
495 chan_offset = PMIF_CHAN_OFFSET * arb->data->soc_chan; in mtk_spmi_probe()
496 arb->chan.ch_sta = PMIF_SWINF_0_STA + chan_offset; in mtk_spmi_probe()
497 arb->chan.wdata = PMIF_SWINF_0_WDATA_31_0 + chan_offset; in mtk_spmi_probe()
498 arb->chan.rdata = PMIF_SWINF_0_RDATA_31_0 + chan_offset; in mtk_spmi_probe()
499 arb->chan.ch_send = PMIF_SWINF_0_ACC + chan_offset; in mtk_spmi_probe()
500 arb->chan.ch_rdy = PMIF_SWINF_0_VLD_CLR + chan_offset; in mtk_spmi_probe()
502 raw_spin_lock_init(&arb->lock); in mtk_spmi_probe()
504 platform_set_drvdata(pdev, ctrl); in mtk_spmi_probe()
506 err = spmi_controller_add(ctrl); in mtk_spmi_probe()
513 clk_bulk_disable_unprepare(arb->nclks, arb->clks); in mtk_spmi_probe()
515 clk_bulk_put(arb->nclks, arb->clks); in mtk_spmi_probe()
521 struct spmi_controller *ctrl = platform_get_drvdata(pdev); in mtk_spmi_remove() local
522 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in mtk_spmi_remove()
524 spmi_controller_remove(ctrl); in mtk_spmi_remove()
525 clk_bulk_disable_unprepare(arb->nclks, arb->clks); in mtk_spmi_remove()
526 clk_bulk_put(arb->nclks, arb->clks); in mtk_spmi_remove()
531 .compatible = "mediatek,mt6873-spmi",
534 .compatible = "mediatek,mt8195-spmi",
544 .name = "spmi-mtk",
552 MODULE_AUTHOR("Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>");