1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
5 * Driver for Amlogic hardware random number generator
14 struct meson_rng_plat {
20 * meson_rng_read() - fill buffer with random bytes
22 * @buffer: buffer to receive data
23 * @size: size of buffer
27 static int meson_rng_read(struct udevice *dev, void *data, size_t len)
29 struct meson_rng_plat *pdata = dev_get_plat(dev);
30 char *buffer = (char *)data;
33 u32 rand = readl(pdata->base);
40 memcpy(buffer, &rand, step);
48 * meson_rng_probe() - probe rng device
53 static int meson_rng_probe(struct udevice *dev)
55 struct meson_rng_plat *pdata = dev_get_plat(dev);
58 err = clk_enable(&pdata->clk);
66 * meson_rng_remove() - deinitialize rng device
71 static int meson_rng_remove(struct udevice *dev)
73 struct meson_rng_plat *pdata = dev_get_plat(dev);
75 return clk_disable(&pdata->clk);
79 * meson_rng_of_to_plat() - transfer device tree data to plaform data
84 static int meson_rng_of_to_plat(struct udevice *dev)
86 struct meson_rng_plat *pdata = dev_get_plat(dev);
89 pdata->base = dev_read_addr(dev);
93 /* Get optional "core" clock */
94 err = clk_get_by_name_optional(dev, "core", &pdata->clk);
101 static const struct dm_rng_ops meson_rng_ops = {
102 .read = meson_rng_read,
105 static const struct udevice_id meson_rng_match[] = {
107 .compatible = "amlogic,meson-rng",
112 U_BOOT_DRIVER(meson_rng) = {
115 .of_match = meson_rng_match,
116 .ops = &meson_rng_ops,
117 .probe = meson_rng_probe,
118 .remove = meson_rng_remove,
119 .plat_auto = sizeof(struct meson_rng_plat),
120 .of_to_plat = meson_rng_of_to_plat,