[RFC PATCH 02/17] usb: otg: Separate otg members from usb_transceiver

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

 



Introdusing struct otg and collecting otg specific members
to it from struct usb_transceiver. There are no changes to
struct usb_transceiver at this stage. This also renames
transceiver specific functions, and offers aliases for the
old otg ones.

Signed-off-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
---
 drivers/usb/otg/otg.c   |   18 ++++----
 include/linux/usb/otg.h |   98 ++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 90 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 8ae4252..12ed6e5 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -17,7 +17,7 @@
 static struct usb_transceiver *xceiv;
 
 /**
- * otg_get_transceiver - find the (single) OTG transceiver
+ * usb_get_transceiver - find the (single) OTG transceiver
  *
  * Returns the transceiver driver, after getting a refcount to it; or
  * null if there is no such transceiver.  The caller is responsible for
@@ -25,45 +25,45 @@ static struct usb_transceiver *xceiv;
  *
  * For use by USB host and peripheral drivers.
  */
-struct usb_transceiver *otg_get_transceiver(void)
+struct usb_transceiver *usb_get_transceiver(void)
 {
 	if (xceiv)
 		get_device(xceiv->dev);
 	return xceiv;
 }
-EXPORT_SYMBOL(otg_get_transceiver);
+EXPORT_SYMBOL(usb_get_transceiver);
 
 /**
- * otg_put_transceiver - release the (single) OTG transceiver
+ * usb_put_transceiver - release the (single) OTG transceiver
  * @x: the transceiver returned by otg_get_transceiver()
  *
  * Releases a refcount the caller received from otg_get_transceiver().
  *
  * For use by USB host and peripheral drivers.
  */
-void otg_put_transceiver(struct usb_transceiver *x)
+void usb_put_transceiver(struct usb_transceiver *x)
 {
 	if (x)
 		put_device(x->dev);
 }
-EXPORT_SYMBOL(otg_put_transceiver);
+EXPORT_SYMBOL(usb_put_transceiver);
 
 /**
- * otg_set_transceiver - declare the (single) OTG transceiver
+ * usb_set_transceiver - declare the (single) OTG transceiver
  * @x: the USB OTG transceiver to be used; or NULL
  *
  * This call is exclusively for use by transceiver drivers, which
  * coordinate the activities of drivers for host and peripheral
  * controllers, and in some cases for VBUS current regulation.
  */
-int otg_set_transceiver(struct usb_transceiver *x)
+int usb_set_transceiver(struct usb_transceiver *x)
 {
 	if (xceiv && x)
 		return -EBUSY;
 	xceiv = x;
 	return 0;
 }
-EXPORT_SYMBOL(otg_set_transceiver);
+EXPORT_SYMBOL(usb_set_transceiver);
 
 const char *otg_state_string(enum usb_otg_state state)
 {
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 6692df8..309f45c 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -48,11 +48,36 @@ struct usb_transceiver;
 /* for transceivers connected thru an ULPI interface, the user must
  * provide access ops
  */
-struct otg_io_access_ops {
+struct usb_phy_io_ops {
 	int (*read)(struct usb_transceiver *x, u32 reg);
 	int (*write)(struct usb_transceiver *x, u32 val, u32 reg);
 };
 
+struct otg {
+	u8			default_a;
+	enum usb_otg_state	state;
+
+	struct usb_transceiver  *xceiv;
+	struct usb_bus		*host;
+	struct usb_gadget	*gadget;
+
+	/* bind/unbind the host controller */
+	int	(*set_host)(struct otg *otg, struct usb_bus *host);
+
+	/* bind/unbind the peripheral controller */
+	int	(*set_peripheral)(struct otg *otg, struct usb_gadget *gadget);
+
+	/* effective for A-peripheral, ignored for B devices */
+	int	(*set_vbus)(struct otg *otg, bool enabled);
+
+	/* for B devices only:  start session with A-Host */
+	int	(*start_srp)(struct otg *otg);
+
+	/* start or continue HNP role switch */
+	int	(*start_hnp)(struct otg *otg);
+
+};
+
 /*
  * the otg driver needs to interact with both device side and host side
  * usb controllers.  it decides which controller is active at a given
@@ -68,11 +93,13 @@ struct usb_transceiver {
 	enum usb_otg_state	state;
 	enum usb_xceiv_events	last_event;
 
+	struct otg		*otg;
+
 	struct usb_bus		*host;
 	struct usb_gadget	*gadget;
 
-	struct otg_io_access_ops	*io_ops;
-	void __iomem			*io_priv;
+	struct usb_phy_io_ops	*io_ops;
+	void __iomem		*io_priv;
 
 	/* for notification of usb_xceiv_events */
 	struct atomic_notifier_head	notifier;
@@ -115,7 +142,7 @@ struct usb_transceiver {
 
 
 /* for board-specific init logic */
-extern int otg_set_transceiver(struct usb_transceiver *);
+extern int usb_set_transceiver(struct usb_transceiver *);
 
 #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
 /* sometimes transceivers are accessed only through e.g. ULPI */
@@ -132,7 +159,7 @@ static inline void usb_nop_xceiv_unregister(void)
 #endif
 
 /* helpers for direct access thru low-level io interface */
-static inline int otg_io_read(struct usb_transceiver *x, u32 reg)
+static inline int usb_transceiver_io_read(struct usb_transceiver *x, u32 reg)
 {
 	if (x->io_ops && x->io_ops->read)
 		return x->io_ops->read(x, reg);
@@ -140,7 +167,9 @@ static inline int otg_io_read(struct usb_transceiver *x, u32 reg)
 	return -EINVAL;
 }
 
-static inline int otg_io_write(struct usb_transceiver *x, u32 val, u32 reg)
+static inline int usb_transceiver_io_write(struct usb_transceiver *x,
+						u32 val,
+						u32 reg)
 {
 	if (x->io_ops && x->io_ops->write)
 		return x->io_ops->write(x, val, reg);
@@ -149,7 +178,7 @@ static inline int otg_io_write(struct usb_transceiver *x, u32 val, u32 reg)
 }
 
 static inline int
-otg_init(struct usb_transceiver *x)
+usb_transceiver_init(struct usb_transceiver *x)
 {
 	if (x->init)
 		return x->init(x);
@@ -158,7 +187,7 @@ otg_init(struct usb_transceiver *x)
 }
 
 static inline void
-otg_shutdown(struct usb_transceiver *x)
+usb_transceiver_shutdown(struct usb_transceiver *x)
 {
 	if (x->shutdown)
 		x->shutdown(x);
@@ -166,16 +195,16 @@ otg_shutdown(struct usb_transceiver *x)
 
 /* for usb host and peripheral controller drivers */
 #ifdef CONFIG_USB_OTG_UTILS
-extern struct usb_transceiver *otg_get_transceiver(void);
-extern void otg_put_transceiver(struct usb_transceiver *);
+extern struct usb_transceiver *usb_get_transceiver(void);
+extern void usb_put_transceiver(struct usb_transceiver *);
 extern const char *otg_state_string(enum usb_otg_state state);
 #else
-static inline struct usb_transceiver *otg_get_transceiver(void)
+static inline struct usb_transceiver *usb_get_transceiver(void)
 {
 	return NULL;
 }
 
-static inline void otg_put_transceiver(struct usb_transceiver *x)
+static inline void usb_put_transceiver(struct usb_transceiver *x)
 {
 }
 
@@ -189,6 +218,9 @@ static inline const char *otg_state_string(enum usb_otg_state state)
 static inline int
 otg_start_hnp(struct usb_transceiver *x)
 {
+	if (x->otg && x->otg->start_hnp)
+		return x->otg->start_hnp(x->otg);
+
 	return x->start_hnp(x);
 }
 
@@ -196,6 +228,9 @@ otg_start_hnp(struct usb_transceiver *x)
 static inline int
 otg_set_vbus(struct usb_transceiver *x, bool enabled)
 {
+	if (x->otg && x->otg->set_vbus)
+		return x->otg->set_vbus(x->otg, enabled);
+
 	return x->set_vbus(x, enabled);
 }
 
@@ -203,6 +238,9 @@ otg_set_vbus(struct usb_transceiver *x, bool enabled)
 static inline int
 otg_set_host(struct usb_transceiver *x, struct usb_bus *host)
 {
+	if (x->otg && x->otg->set_host)
+		return x->otg->set_host(x->otg, host);
+
 	return x->set_host(x, host);
 }
 
@@ -212,18 +250,23 @@ otg_set_host(struct usb_transceiver *x, struct usb_bus *host)
 static inline int
 otg_set_peripheral(struct usb_transceiver *x, struct usb_gadget *periph)
 {
+	if (x->otg && x->otg->set_peripheral)
+		return x->otg->set_peripheral(x->otg, periph);
+
 	return x->set_peripheral(x, periph);
 }
 
 static inline int
-otg_set_power(struct usb_transceiver *x, unsigned mA)
+usb_transceiver_set_power(struct usb_transceiver *x, unsigned mA)
 {
-	return x->set_power(x, mA);
+	if (x && x->set_power)
+		return x->set_power(x, mA);
+	return 0;
 }
 
 /* Context: can sleep */
 static inline int
-otg_set_suspend(struct usb_transceiver *x, int suspend)
+usb_transceiver_set_suspend(struct usb_transceiver *x, int suspend)
 {
 	if (x->set_suspend != NULL)
 		return x->set_suspend(x, suspend);
@@ -234,18 +277,21 @@ otg_set_suspend(struct usb_transceiver *x, int suspend)
 static inline int
 otg_start_srp(struct usb_transceiver *x)
 {
+	if (x->otg && x->otg->start_srp)
+		return x->otg->start_srp(x->otg);
+
 	return x->start_srp(x);
 }
 
 /* notifiers */
 static inline int
-otg_register_notifier(struct usb_transceiver *x, struct notifier_block *nb)
+usb_register_notifier(struct usb_transceiver *x, struct notifier_block *nb)
 {
 	return atomic_notifier_chain_register(&x->notifier, nb);
 }
 
 static inline void
-otg_unregister_notifier(struct usb_transceiver *x, struct notifier_block *nb)
+usb_unregister_notifier(struct usb_transceiver *x, struct notifier_block *nb)
 {
 	atomic_notifier_chain_unregister(&x->notifier, nb);
 }
@@ -253,4 +299,22 @@ otg_unregister_notifier(struct usb_transceiver *x, struct notifier_block *nb)
 /* for OTG controller drivers (and maybe other stuff) */
 extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
 
+/* Temporary aliases for transceiver functions */
+#define otg_set_transceiver(x) usb_set_transceiver(x)
+#define otg_get_transceiver() usb_get_transceiver()
+#define otg_put_transceiver(x) usb_put_transceiver(x)
+
+#define otg_io_read(x, a) usb_transceiver_io_read(x, a)
+#define otg_io_write(x, a, b) usb_transceiver_io_write(x, a, b)
+
+#define otg_init(x) usb_transceiver_init(x)
+#define otg_shutdown(x) usb_transceiver_shutdown(x)
+#define otg_set_power(x, a) usb_transceiver_set_power(x, a)
+#define otg_set_suspend(x, a) usb_transceiver_set_suspend(x, a)
+
+#define otg_register_notifier(x, a) usb_register_notifier(x, a)
+#define otg_unregister_notifier(x, a) usb_unregiser_notifier(x, a)
+
+#define otg_io_access_ops usb_phy_io_ops
+
 #endif /* __LINUX_USB_OTG_H */
-- 
1.7.4.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