1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
11 struct misc_sandbox_priv {
17 int misc_sandbox_read(struct udevice *dev, int offset, void *buf, int size)
19 struct misc_sandbox_priv *priv = dev_get_priv(dev);
21 memcpy(buf, priv->mem + offset, size);
26 int misc_sandbox_write(struct udevice *dev, int offset, const void *buf,
29 struct misc_sandbox_priv *priv = dev_get_priv(dev);
31 memcpy(priv->mem + offset, buf, size);
36 int misc_sandbox_ioctl(struct udevice *dev, unsigned long request, void *buf)
38 struct misc_sandbox_priv *priv = dev_get_priv(dev);
40 priv->last_ioctl = request;
45 int misc_sandbox_call(struct udevice *dev, int msgid, void *tx_msg,
46 int tx_size, void *rx_msg, int rx_size)
48 struct misc_sandbox_priv *priv = dev_get_priv(dev);
51 int num = *(int *)tx_msg;
55 strncpy(rx_msg, "Zero", rx_size);
58 strncpy(rx_msg, "One", rx_size);
61 strncpy(rx_msg, "Two", rx_size);
69 int num = *(int *)tx_msg;
73 strncpy(rx_msg, "Forty", rx_size);
76 strncpy(rx_msg, "Forty-one", rx_size);
79 strncpy(rx_msg, "Forty-two", rx_size);
87 memcpy(rx_msg, &priv->last_ioctl, sizeof(priv->last_ioctl));
90 memcpy(rx_msg, &priv->enabled, sizeof(priv->enabled));
95 int misc_sandbox_set_enabled(struct udevice *dev, bool val)
97 struct misc_sandbox_priv *priv = dev_get_priv(dev);
99 priv->enabled = !priv->enabled;
104 static const struct misc_ops misc_sandbox_ops = {
105 .read = misc_sandbox_read,
106 .write = misc_sandbox_write,
107 .ioctl = misc_sandbox_ioctl,
108 .call = misc_sandbox_call,
109 .set_enabled = misc_sandbox_set_enabled,
112 int misc_sandbox_probe(struct udevice *dev)
114 struct misc_sandbox_priv *priv = dev_get_priv(dev);
116 priv->enabled = true;
121 static const struct udevice_id misc_sandbox_ids[] = {
122 { .compatible = "sandbox,misc_sandbox" },
126 U_BOOT_DRIVER(misc_sandbox) = {
127 .name = "misc_sandbox",
129 .ops = &misc_sandbox_ops,
130 .of_match = misc_sandbox_ids,
131 .probe = misc_sandbox_probe,
132 .priv_auto = sizeof(struct misc_sandbox_priv),