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