[PATCH 1/2] nvmem: Add Rockchip OTP controller driver
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Oct 6 03:04:05 PDT 2023
Hi Alexander,
On 06.10.23 07:48, Alexander Shiyan wrote:
> +static __maybe_unused const struct of_device_id rockchip_otp_match[] = {
> + {
> + .compatible = "rockchip,px30-otp",
> + .data = &px30_data,
> + },
> + {
> + .compatible = "rockchip,rk3308-otp",
> + .data = &px30_data,
> + },
> + {
> + .compatible = "rockchip,rk3568-otp",
> + .data = &rk3568_data,
> + },
> + {
> + .compatible = "rockchip,rk3588-otp",
> + .data = &rk3588_data,
> + },
Just out of curiosity: Which SoC of these are you using?
Cheers,
Ahmad
> + { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, rockchip_otp_match);
> +
> +static int rockchip_otp_probe(struct device *dev)
> +{
> + struct rockchip_otp *otp;
> + const struct rockchip_data *data;
> + struct nvmem_device *nvmem;
> + struct resource *res;
> + int ret, i;
> +
> + data = of_device_get_match_data(dev);
> + if (!data)
> + return dev_err_probe(dev, -EINVAL, "failed to get match data\n");
> +
> + otp = kzalloc(sizeof(*otp), GFP_KERNEL);
> + if (!otp)
> + return -ENOMEM;
> +
> + res = dev_request_mem_resource(dev, 0);
> + if (IS_ERR(res)) {
> + ret = PTR_ERR(res);
> + goto err_free;
> + }
> +
> + otp->data = data;
> + otp->dev = dev;
> + otp->base = IOMEM(res->start);
> +
> + otp->clks = kcalloc(data->num_clks, sizeof(*otp->clks), GFP_KERNEL);
> + if (!otp->clks) {
> + ret = -ENOMEM;
> + goto err_free;
> + }
> +
> + for (i = 0; i < data->num_clks; ++i)
> + otp->clks[i].id = data->clks[i];
> +
> + ret = clk_bulk_get_optional(dev, data->num_clks, otp->clks);
> + if (ret)
> + goto err_clk;
> +
> + otp->rst = reset_control_get(dev, NULL);
> + if (IS_ERR(otp->rst)) {
> + ret = PTR_ERR(otp->rst);
> + goto err_rst;
> + }
> +
> + otp_config.size = data->size;
> + otp_config.priv = otp;
> + otp_config.dev = dev;
> +
> + nvmem = nvmem_register(&otp_config);
> + if (!IS_ERR(nvmem))
> + return 0;
> +
> + ret = PTR_ERR(nvmem);
> +
> + reset_control_put(otp->rst);
> +
> +err_rst:
> + clk_bulk_put_all(data->num_clks, otp->clks);
> +
> +err_clk:
> + kfree(otp->clks);
> +
> +err_free:
> + kfree(otp);
> +
> + return ret;
> +}
> +
> +static struct driver rockchip_otp_driver = {
> + .name = "rockchip-otp",
> + .probe = rockchip_otp_probe,
> + .of_compatible = DRV_OF_COMPAT(rockchip_otp_match),
> +};
> +device_platform_driver(rockchip_otp_driver);
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list