xref: /rk3399_rockchip-uboot/drivers/misc/misc-uclass.c (revision b647f55420310beb8f576e23f3b6a69745126f71)
14395e06eSThomas Chou /*
24395e06eSThomas Chou  * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
34395e06eSThomas Chou  *
44395e06eSThomas Chou  * SPDX-License-Identifier:	GPL-2.0+
54395e06eSThomas Chou  */
64395e06eSThomas Chou 
74395e06eSThomas Chou #include <common.h>
84395e06eSThomas Chou #include <dm.h>
94395e06eSThomas Chou #include <errno.h>
104395e06eSThomas Chou #include <misc.h>
114395e06eSThomas Chou 
124395e06eSThomas Chou /*
134395e06eSThomas Chou  * Implement a  miscellaneous uclass for those do not fit other more
144395e06eSThomas Chou  * general classes. A set of generic read, write and ioctl methods may
154395e06eSThomas Chou  * be used to access the device.
164395e06eSThomas Chou  */
174395e06eSThomas Chou 
184395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size)
194395e06eSThomas Chou {
204395e06eSThomas Chou 	const struct misc_ops *ops = device_get_ops(dev);
214395e06eSThomas Chou 
224395e06eSThomas Chou 	if (!ops->read)
234395e06eSThomas Chou 		return -ENOSYS;
244395e06eSThomas Chou 
254395e06eSThomas Chou 	return ops->read(dev, offset, buf, size);
264395e06eSThomas Chou }
274395e06eSThomas Chou 
284395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size)
294395e06eSThomas Chou {
304395e06eSThomas Chou 	const struct misc_ops *ops = device_get_ops(dev);
314395e06eSThomas Chou 
324395e06eSThomas Chou 	if (!ops->write)
334395e06eSThomas Chou 		return -ENOSYS;
344395e06eSThomas Chou 
354395e06eSThomas Chou 	return ops->write(dev, offset, buf, size);
364395e06eSThomas Chou }
374395e06eSThomas Chou 
384395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
394395e06eSThomas Chou {
404395e06eSThomas Chou 	const struct misc_ops *ops = device_get_ops(dev);
414395e06eSThomas Chou 
424395e06eSThomas Chou 	if (!ops->ioctl)
434395e06eSThomas Chou 		return -ENOSYS;
444395e06eSThomas Chou 
454395e06eSThomas Chou 	return ops->ioctl(dev, request, buf);
464395e06eSThomas Chou }
474395e06eSThomas Chou 
48*b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
49*b647f554SStephen Warren 	      void *rx_msg, int rx_size)
50*b647f554SStephen Warren {
51*b647f554SStephen Warren 	const struct misc_ops *ops = device_get_ops(dev);
52*b647f554SStephen Warren 
53*b647f554SStephen Warren 	if (!ops->call)
54*b647f554SStephen Warren 		return -ENOSYS;
55*b647f554SStephen Warren 
56*b647f554SStephen Warren 	return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size);
57*b647f554SStephen Warren }
58*b647f554SStephen Warren 
594395e06eSThomas Chou UCLASS_DRIVER(misc) = {
604395e06eSThomas Chou 	.id		= UCLASS_MISC,
614395e06eSThomas Chou 	.name		= "misc",
624395e06eSThomas Chou };
63