blob: 13a6ea508b14a37c83c99131c4eefbd1460c6fd0 [file] [log] [blame]
Thomas Chou4395e062015-10-07 20:20:51 +08001/*
2 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
10#include <misc.h>
11
12/*
13 * Implement a miscellaneous uclass for those do not fit other more
14 * general classes. A set of generic read, write and ioctl methods may
15 * be used to access the device.
16 */
17
18int misc_read(struct udevice *dev, int offset, void *buf, int size)
19{
20 const struct misc_ops *ops = device_get_ops(dev);
21
22 if (!ops->read)
23 return -ENOSYS;
24
25 return ops->read(dev, offset, buf, size);
26}
27
28int misc_write(struct udevice *dev, int offset, void *buf, int size)
29{
30 const struct misc_ops *ops = device_get_ops(dev);
31
32 if (!ops->write)
33 return -ENOSYS;
34
35 return ops->write(dev, offset, buf, size);
36}
37
38int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
39{
40 const struct misc_ops *ops = device_get_ops(dev);
41
42 if (!ops->ioctl)
43 return -ENOSYS;
44
45 return ops->ioctl(dev, request, buf);
46}
47
48UCLASS_DRIVER(misc) = {
49 .id = UCLASS_MISC,
50 .name = "misc",
51};