[PATCH 4/8] USB: add slim framework for external transceivers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a proposal for a slim framework to abstract USB transceivers
from their actual hardware access methods. The idea is that processor
platforms provide accesor functions, the tranceiver drivers provide
higher level functions and the board support code connects them
together.

The design is kept as simple and slim as possible.

Signed-off-by: Daniel Mack <daniel@xxxxxxxx>
---
 include/linux/usb/xcvr.h |   71 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/usb/xcvr.h

diff --git a/include/linux/usb/xcvr.h b/include/linux/usb/xcvr.h
new file mode 100644
index 0000000..5d53e32
--- /dev/null
+++ b/include/linux/usb/xcvr.h
@@ -0,0 +1,71 @@
+#ifndef __LINUX_USB_XCVR_H
+#define __LINUX_USB_XCVR_H
+
+struct usb_xcvr;
+
+struct usb_xcvr_access_ops {
+	int (*read)(struct usb_xcvr *xcvr, u32 reg);
+	int (*write)(struct usb_xcvr *xcvr, u32 val, u32 reg);
+};
+
+struct usb_xcvr_driver {
+	int  (*init)(struct usb_xcvr *xcvr);
+	void (*shutdown)(struct usb_xcvr *xcvr);
+	int  (*set_vbus)(struct usb_xcvr *xcvr, bool en);
+};
+
+struct usb_xcvr {
+	struct usb_xcvr_access_ops 	*access;
+	struct usb_xcvr_driver		*driver;
+	void __iomem			*access_priv;
+
+	/* only set this if you don't want the lowlevel driver to
+	 * handle this */
+	int (*set_vbus)(struct usb_xcvr *xcvr, bool en);
+};
+
+static inline int usb_xcvr_init(struct usb_xcvr *xcvr)
+{
+	if (xcvr->driver && xcvr->driver->init)
+		return xcvr->driver->init(xcvr);
+
+	return -EINVAL;
+}
+
+static inline void usb_xcvr_shutdown(struct usb_xcvr *xcvr)
+{
+	if (xcvr->driver && xcvr->driver->shutdown)
+		xcvr->driver->shutdown(xcvr);
+}
+
+static inline int usb_xcvr_set_vbus(struct usb_xcvr *xcvr, bool en)
+{
+	if (xcvr->set_vbus)
+		return xcvr->set_vbus(xcvr, en);
+
+	if (xcvr->driver && xcvr->driver->set_vbus)
+		return xcvr->driver->set_vbus(xcvr, en);
+
+	return -EINVAL;
+}
+
+/* lowlowel access helpers */
+
+static inline int usb_xcvr_read(struct usb_xcvr *xcvr, u32 reg)
+{
+	if (xcvr->access->read)
+		return xcvr->access->read(xcvr, reg);
+
+	return -EINVAL;
+}
+
+static inline int usb_xcvr_write(struct usb_xcvr *xcvr, u32 val, u32 reg)
+{
+	if (xcvr->access->write)
+		return xcvr->access->write(xcvr, val, reg);
+
+	return -EINVAL;
+}
+
+#endif /* __LINUX_USB_XCVR_H */
+
-- 
1.6.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux