xref: /openbmc/u-boot/drivers/misc/misc-uclass.c (revision e35171e9)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
24395e06eSThomas Chou /*
34395e06eSThomas Chou  * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
44395e06eSThomas Chou  */
54395e06eSThomas Chou 
64395e06eSThomas Chou #include <common.h>
74395e06eSThomas Chou #include <dm.h>
84395e06eSThomas Chou #include <errno.h>
94395e06eSThomas Chou #include <misc.h>
104395e06eSThomas Chou 
114395e06eSThomas Chou /*
124395e06eSThomas Chou  * Implement a  miscellaneous uclass for those do not fit other more
134395e06eSThomas Chou  * general classes. A set of generic read, write and ioctl methods may
144395e06eSThomas Chou  * be used to access the device.
154395e06eSThomas Chou  */
164395e06eSThomas Chou 
misc_read(struct udevice * dev,int offset,void * buf,int size)174395e06eSThomas Chou int misc_read(struct udevice *dev, int offset, void *buf, int size)
184395e06eSThomas Chou {
194395e06eSThomas Chou 	const struct misc_ops *ops = device_get_ops(dev);
204395e06eSThomas Chou 
214395e06eSThomas Chou 	if (!ops->read)
224395e06eSThomas Chou 		return -ENOSYS;
234395e06eSThomas Chou 
244395e06eSThomas Chou 	return ops->read(dev, offset, buf, size);
254395e06eSThomas Chou }
264395e06eSThomas Chou 
misc_write(struct udevice * dev,int offset,void * buf,int size)274395e06eSThomas Chou int misc_write(struct udevice *dev, int offset, void *buf, int size)
284395e06eSThomas Chou {
294395e06eSThomas Chou 	const struct misc_ops *ops = device_get_ops(dev);
304395e06eSThomas Chou 
314395e06eSThomas Chou 	if (!ops->write)
324395e06eSThomas Chou 		return -ENOSYS;
334395e06eSThomas Chou 
344395e06eSThomas Chou 	return ops->write(dev, offset, buf, size);
354395e06eSThomas Chou }
364395e06eSThomas Chou 
misc_ioctl(struct udevice * dev,unsigned long request,void * buf)374395e06eSThomas Chou int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
384395e06eSThomas Chou {
394395e06eSThomas Chou 	const struct misc_ops *ops = device_get_ops(dev);
404395e06eSThomas Chou 
414395e06eSThomas Chou 	if (!ops->ioctl)
424395e06eSThomas Chou 		return -ENOSYS;
434395e06eSThomas Chou 
444395e06eSThomas Chou 	return ops->ioctl(dev, request, buf);
454395e06eSThomas Chou }
464395e06eSThomas Chou 
misc_call(struct udevice * dev,int msgid,void * tx_msg,int tx_size,void * rx_msg,int rx_size)47b647f554SStephen Warren int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
48b647f554SStephen Warren 	      void *rx_msg, int rx_size)
49b647f554SStephen Warren {
50b647f554SStephen Warren 	const struct misc_ops *ops = device_get_ops(dev);
51b647f554SStephen Warren 
52b647f554SStephen Warren 	if (!ops->call)
53b647f554SStephen Warren 		return -ENOSYS;
54b647f554SStephen Warren 
55b647f554SStephen Warren 	return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size);
56b647f554SStephen Warren }
57b647f554SStephen Warren 
misc_set_enabled(struct udevice * dev,bool val)58440bc11fSMario Six int misc_set_enabled(struct udevice *dev, bool val)
59440bc11fSMario Six {
60440bc11fSMario Six 	const struct misc_ops *ops = device_get_ops(dev);
61440bc11fSMario Six 
62440bc11fSMario Six 	if (!ops->set_enabled)
63440bc11fSMario Six 		return -ENOSYS;
64440bc11fSMario Six 
65440bc11fSMario Six 	return ops->set_enabled(dev, val);
66440bc11fSMario Six }
67440bc11fSMario Six 
684395e06eSThomas Chou UCLASS_DRIVER(misc) = {
694395e06eSThomas Chou 	.id		= UCLASS_MISC,
704395e06eSThomas Chou 	.name		= "misc",
71*e5d61167SSimon Glass #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
72*e5d61167SSimon Glass 	.post_bind	= dm_scan_fdt_dev,
73*e5d61167SSimon Glass #endif
744395e06eSThomas Chou };
75