Linux 3.9-rc4
[linux-2.6/cjktty.git] / include / linux / usb / phy.h
blob15847cbdb512b804347b3219d60c7b96563fd9bd
1 /* USB OTG (On The Go) defines */
2 /*
4 * These APIs may be used between USB controllers. USB device drivers
5 * (for either host or peripheral roles) don't use these calls; they
6 * continue to use just usb_device and usb_gadget.
7 */
9 #ifndef __LINUX_USB_PHY_H
10 #define __LINUX_USB_PHY_H
12 #include <linux/notifier.h>
13 #include <linux/usb.h>
15 enum usb_phy_events {
16 USB_EVENT_NONE, /* no events or cable disconnected */
17 USB_EVENT_VBUS, /* vbus valid event */
18 USB_EVENT_ID, /* id was grounded */
19 USB_EVENT_CHARGER, /* usb dedicated charger */
20 USB_EVENT_ENUMERATED, /* gadget driver enumerated */
23 /* associate a type with PHY */
24 enum usb_phy_type {
25 USB_PHY_TYPE_UNDEFINED,
26 USB_PHY_TYPE_USB2,
27 USB_PHY_TYPE_USB3,
30 /* OTG defines lots of enumeration states before device reset */
31 enum usb_otg_state {
32 OTG_STATE_UNDEFINED = 0,
34 /* single-role peripheral, and dual-role default-b */
35 OTG_STATE_B_IDLE,
36 OTG_STATE_B_SRP_INIT,
37 OTG_STATE_B_PERIPHERAL,
39 /* extra dual-role default-b states */
40 OTG_STATE_B_WAIT_ACON,
41 OTG_STATE_B_HOST,
43 /* dual-role default-a */
44 OTG_STATE_A_IDLE,
45 OTG_STATE_A_WAIT_VRISE,
46 OTG_STATE_A_WAIT_BCON,
47 OTG_STATE_A_HOST,
48 OTG_STATE_A_SUSPEND,
49 OTG_STATE_A_PERIPHERAL,
50 OTG_STATE_A_WAIT_VFALL,
51 OTG_STATE_A_VBUS_ERR,
54 struct usb_phy;
55 struct usb_otg;
57 /* for transceivers connected thru an ULPI interface, the user must
58 * provide access ops
60 struct usb_phy_io_ops {
61 int (*read)(struct usb_phy *x, u32 reg);
62 int (*write)(struct usb_phy *x, u32 val, u32 reg);
65 struct usb_phy {
66 struct device *dev;
67 const char *label;
68 unsigned int flags;
70 enum usb_phy_type type;
71 enum usb_otg_state state;
72 enum usb_phy_events last_event;
74 struct usb_otg *otg;
76 struct device *io_dev;
77 struct usb_phy_io_ops *io_ops;
78 void __iomem *io_priv;
80 /* for notification of usb_phy_events */
81 struct atomic_notifier_head notifier;
83 /* to pass extra port status to the root hub */
84 u16 port_status;
85 u16 port_change;
87 /* to support controllers that have multiple transceivers */
88 struct list_head head;
90 /* initialize/shutdown the OTG controller */
91 int (*init)(struct usb_phy *x);
92 void (*shutdown)(struct usb_phy *x);
94 /* effective for B devices, ignored for A-peripheral */
95 int (*set_power)(struct usb_phy *x,
96 unsigned mA);
98 /* for non-OTG B devices: set transceiver into suspend mode */
99 int (*set_suspend)(struct usb_phy *x,
100 int suspend);
102 /* notify phy connect status change */
103 int (*notify_connect)(struct usb_phy *x,
104 enum usb_device_speed speed);
105 int (*notify_disconnect)(struct usb_phy *x,
106 enum usb_device_speed speed);
110 * struct usb_phy_bind - represent the binding for the phy
111 * @dev_name: the device name of the device that will bind to the phy
112 * @phy_dev_name: the device name of the phy
113 * @index: used if a single controller uses multiple phys
114 * @phy: reference to the phy
115 * @list: to maintain a linked list of the binding information
117 struct usb_phy_bind {
118 const char *dev_name;
119 const char *phy_dev_name;
120 u8 index;
121 struct usb_phy *phy;
122 struct list_head list;
125 /* for board-specific init logic */
126 extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
127 extern int usb_add_phy_dev(struct usb_phy *);
128 extern void usb_remove_phy(struct usb_phy *);
130 /* helpers for direct access thru low-level io interface */
131 static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
133 if (x->io_ops && x->io_ops->read)
134 return x->io_ops->read(x, reg);
136 return -EINVAL;
139 static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
141 if (x->io_ops && x->io_ops->write)
142 return x->io_ops->write(x, val, reg);
144 return -EINVAL;
147 static inline int
148 usb_phy_init(struct usb_phy *x)
150 if (x->init)
151 return x->init(x);
153 return 0;
156 static inline void
157 usb_phy_shutdown(struct usb_phy *x)
159 if (x->shutdown)
160 x->shutdown(x);
163 /* for usb host and peripheral controller drivers */
164 #ifdef CONFIG_USB_OTG_UTILS
165 extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
166 extern struct usb_phy *devm_usb_get_phy(struct device *dev,
167 enum usb_phy_type type);
168 extern struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index);
169 extern struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index);
170 extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
171 const char *phandle, u8 index);
172 extern void usb_put_phy(struct usb_phy *);
173 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
174 extern int usb_bind_phy(const char *dev_name, u8 index,
175 const char *phy_dev_name);
176 #else
177 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
179 return NULL;
182 static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
183 enum usb_phy_type type)
185 return NULL;
188 static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
190 return NULL;
193 static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
195 return NULL;
198 static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
199 const char *phandle, u8 index)
201 return NULL;
204 static inline void usb_put_phy(struct usb_phy *x)
208 static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
212 static inline int usb_bind_phy(const char *dev_name, u8 index,
213 const char *phy_dev_name)
215 return -EOPNOTSUPP;
217 #endif
219 static inline int
220 usb_phy_set_power(struct usb_phy *x, unsigned mA)
222 if (x && x->set_power)
223 return x->set_power(x, mA);
224 return 0;
227 /* Context: can sleep */
228 static inline int
229 usb_phy_set_suspend(struct usb_phy *x, int suspend)
231 if (x->set_suspend != NULL)
232 return x->set_suspend(x, suspend);
233 else
234 return 0;
237 static inline int
238 usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed)
240 if (x->notify_connect)
241 return x->notify_connect(x, speed);
242 else
243 return 0;
246 static inline int
247 usb_phy_notify_disconnect(struct usb_phy *x, enum usb_device_speed speed)
249 if (x->notify_disconnect)
250 return x->notify_disconnect(x, speed);
251 else
252 return 0;
255 /* notifiers */
256 static inline int
257 usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
259 return atomic_notifier_chain_register(&x->notifier, nb);
262 static inline void
263 usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
265 atomic_notifier_chain_unregister(&x->notifier, nb);
268 static inline const char *usb_phy_type_string(enum usb_phy_type type)
270 switch (type) {
271 case USB_PHY_TYPE_USB2:
272 return "USB2 PHY";
273 case USB_PHY_TYPE_USB3:
274 return "USB3 PHY";
275 default:
276 return "UNKNOWN PHY TYPE";
279 #endif /* __LINUX_USB_PHY_H */