Lines Matching +full:ctrl +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0
266 return readl(arb->base + arb->data->regs[reg]); in pmif_readl()
271 writel(val, arb->base + arb->data->regs[reg]); in pmif_writel()
276 writel(val, arb->spmimst_base + arb->data->spmimst_regs[reg]); in mtk_spmi_writel()
283 reg_rdata = pmif_readl(arb, arb->chan.ch_sta); in pmif_is_fsm_vldclr()
288 static int pmif_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) in pmif_arb_cmd() argument
290 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in pmif_arb_cmd()
296 return -EINVAL; in pmif_arb_cmd()
298 cmd = opc - SPMI_CMD_RESET; in pmif_arb_cmd()
301 ret = readl_poll_timeout_atomic(arb->spmimst_base + arb->data->spmimst_regs[SPMI_OP_ST_STA], in pmif_arb_cmd()
305 dev_err(&ctrl->dev, "timeout, err = %d\n", ret); in pmif_arb_cmd()
310 static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, in pmif_spmi_read_cmd() argument
311 u16 addr, u8 *buf, size_t len) in pmif_spmi_read_cmd() argument
313 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in pmif_spmi_read_cmd()
320 dev_err(&ctrl->dev, "exceed the max slv id\n"); in pmif_spmi_read_cmd()
321 return -EINVAL; in pmif_spmi_read_cmd()
324 if (len > 4) { in pmif_spmi_read_cmd()
325 dev_err(&ctrl->dev, "pmif supports 1..4 bytes per trans, but:%zu requested", len); in pmif_spmi_read_cmd()
327 return -EINVAL; in pmif_spmi_read_cmd()
335 return -EINVAL; in pmif_spmi_read_cmd()
338 inf_reg = &arb->chan; in pmif_spmi_read_cmd()
339 ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta], in pmif_spmi_read_cmd()
345 pmif_writel(arb, 1, inf_reg->ch_rdy); in pmif_spmi_read_cmd()
346 dev_err(&ctrl->dev, "failed to wait for SWINF_IDLE\n"); in pmif_spmi_read_cmd()
351 cmd = (opc << 30) | (sid << 24) | ((len - 1) << 16) | addr; in pmif_spmi_read_cmd()
352 pmif_writel(arb, cmd, inf_reg->ch_send); in pmif_spmi_read_cmd()
358 ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta], in pmif_spmi_read_cmd()
362 dev_err(&ctrl->dev, "failed to wait for SWINF_WFVLDCLR\n"); in pmif_spmi_read_cmd()
366 data = pmif_readl(arb, inf_reg->rdata); in pmif_spmi_read_cmd()
367 memcpy(buf, &data, len); in pmif_spmi_read_cmd()
368 pmif_writel(arb, 1, inf_reg->ch_rdy); in pmif_spmi_read_cmd()
373 static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, in pmif_spmi_write_cmd() argument
374 u16 addr, const u8 *buf, size_t len) in pmif_spmi_write_cmd() argument
376 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in pmif_spmi_write_cmd()
381 if (len > 4) { in pmif_spmi_write_cmd()
382 dev_err(&ctrl->dev, "pmif supports 1..4 bytes per trans, but:%zu requested", len); in pmif_spmi_write_cmd()
384 return -EINVAL; in pmif_spmi_write_cmd()
395 return -EINVAL; in pmif_spmi_write_cmd()
398 inf_reg = &arb->chan; in pmif_spmi_write_cmd()
399 ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta], in pmif_spmi_write_cmd()
405 pmif_writel(arb, 1, inf_reg->ch_rdy); in pmif_spmi_write_cmd()
406 dev_err(&ctrl->dev, "failed to wait for SWINF_IDLE\n"); in pmif_spmi_write_cmd()
411 memcpy(&data, buf, len); in pmif_spmi_write_cmd()
412 pmif_writel(arb, data, inf_reg->wdata); in pmif_spmi_write_cmd()
415 cmd = (opc << 30) | BIT(29) | (sid << 24) | ((len - 1) << 16) | addr; in pmif_spmi_write_cmd()
416 pmif_writel(arb, cmd, inf_reg->ch_send); in pmif_spmi_write_cmd()
436 struct spmi_controller *ctrl; in mtk_spmi_probe() local
440 ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*arb)); in mtk_spmi_probe()
441 if (!ctrl) in mtk_spmi_probe()
442 return -ENOMEM; in mtk_spmi_probe()
444 arb = spmi_controller_get_drvdata(ctrl); in mtk_spmi_probe()
445 arb->data = device_get_match_data(&pdev->dev); in mtk_spmi_probe()
446 if (!arb->data) { in mtk_spmi_probe()
447 err = -EINVAL; in mtk_spmi_probe()
448 dev_err(&pdev->dev, "Cannot get drv_data\n"); in mtk_spmi_probe()
452 arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif"); in mtk_spmi_probe()
453 if (IS_ERR(arb->base)) { in mtk_spmi_probe()
454 err = PTR_ERR(arb->base); in mtk_spmi_probe()
458 arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst"); in mtk_spmi_probe()
459 if (IS_ERR(arb->spmimst_base)) { in mtk_spmi_probe()
460 err = PTR_ERR(arb->spmimst_base); in mtk_spmi_probe()
464 arb->nclks = ARRAY_SIZE(pmif_clock_names); in mtk_spmi_probe()
465 for (i = 0; i < arb->nclks; i++) in mtk_spmi_probe()
466 arb->clks[i].id = pmif_clock_names[i]; in mtk_spmi_probe()
468 err = devm_clk_bulk_get(&pdev->dev, arb->nclks, arb->clks); in mtk_spmi_probe()
470 dev_err(&pdev->dev, "Failed to get clocks: %d\n", err); in mtk_spmi_probe()
474 err = clk_bulk_prepare_enable(arb->nclks, arb->clks); in mtk_spmi_probe()
476 dev_err(&pdev->dev, "Failed to enable clocks: %d\n", err); in mtk_spmi_probe()
480 ctrl->cmd = pmif_arb_cmd; in mtk_spmi_probe()
481 ctrl->read_cmd = pmif_spmi_read_cmd; in mtk_spmi_probe()
482 ctrl->write_cmd = pmif_spmi_write_cmd; in mtk_spmi_probe()
484 chan_offset = PMIF_CHAN_OFFSET * arb->data->soc_chan; in mtk_spmi_probe()
485 arb->chan.ch_sta = PMIF_SWINF_0_STA + chan_offset; in mtk_spmi_probe()
486 arb->chan.wdata = PMIF_SWINF_0_WDATA_31_0 + chan_offset; in mtk_spmi_probe()
487 arb->chan.rdata = PMIF_SWINF_0_RDATA_31_0 + chan_offset; in mtk_spmi_probe()
488 arb->chan.ch_send = PMIF_SWINF_0_ACC + chan_offset; in mtk_spmi_probe()
489 arb->chan.ch_rdy = PMIF_SWINF_0_VLD_CLR + chan_offset; in mtk_spmi_probe()
491 platform_set_drvdata(pdev, ctrl); in mtk_spmi_probe()
493 err = spmi_controller_add(ctrl); in mtk_spmi_probe()
500 clk_bulk_disable_unprepare(arb->nclks, arb->clks); in mtk_spmi_probe()
502 spmi_controller_put(ctrl); in mtk_spmi_probe()
508 struct spmi_controller *ctrl = platform_get_drvdata(pdev); in mtk_spmi_remove() local
509 struct pmif *arb = spmi_controller_get_drvdata(ctrl); in mtk_spmi_remove()
511 clk_bulk_disable_unprepare(arb->nclks, arb->clks); in mtk_spmi_remove()
512 spmi_controller_remove(ctrl); in mtk_spmi_remove()
513 spmi_controller_put(ctrl); in mtk_spmi_remove()
518 .compatible = "mediatek,mt6873-spmi",
521 .compatible = "mediatek,mt8195-spmi",
531 .name = "spmi-mtk",
539 MODULE_AUTHOR("Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>");