Loading...
1/*
2 * otg.c -- USB OTG utility code
3 *
4 * Copyright (C) 2004 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/device.h>
14
15#include <linux/usb/otg.h>
16
17static struct otg_transceiver *xceiv;
18
19/**
20 * otg_get_transceiver - find the (single) OTG transceiver
21 *
22 * Returns the transceiver driver, after getting a refcount to it; or
23 * null if there is no such transceiver. The caller is responsible for
24 * calling otg_put_transceiver() to release that count.
25 *
26 * For use by USB host and peripheral drivers.
27 */
28struct otg_transceiver *otg_get_transceiver(void)
29{
30 if (xceiv)
31 get_device(xceiv->dev);
32 return xceiv;
33}
34EXPORT_SYMBOL(otg_get_transceiver);
35
36/**
37 * otg_put_transceiver - release the (single) OTG transceiver
38 * @x: the transceiver returned by otg_get_transceiver()
39 *
40 * Releases a refcount the caller received from otg_get_transceiver().
41 *
42 * For use by USB host and peripheral drivers.
43 */
44void otg_put_transceiver(struct otg_transceiver *x)
45{
46 if (x)
47 put_device(x->dev);
48}
49EXPORT_SYMBOL(otg_put_transceiver);
50
51/**
52 * otg_set_transceiver - declare the (single) OTG transceiver
53 * @x: the USB OTG transceiver to be used; or NULL
54 *
55 * This call is exclusively for use by transceiver drivers, which
56 * coordinate the activities of drivers for host and peripheral
57 * controllers, and in some cases for VBUS current regulation.
58 */
59int otg_set_transceiver(struct otg_transceiver *x)
60{
61 if (xceiv && x)
62 return -EBUSY;
63 xceiv = x;
64 return 0;
65}
66EXPORT_SYMBOL(otg_set_transceiver);
67
68const char *otg_state_string(enum usb_otg_state state)
69{
70 switch (state) {
71 case OTG_STATE_A_IDLE:
72 return "a_idle";
73 case OTG_STATE_A_WAIT_VRISE:
74 return "a_wait_vrise";
75 case OTG_STATE_A_WAIT_BCON:
76 return "a_wait_bcon";
77 case OTG_STATE_A_HOST:
78 return "a_host";
79 case OTG_STATE_A_SUSPEND:
80 return "a_suspend";
81 case OTG_STATE_A_PERIPHERAL:
82 return "a_peripheral";
83 case OTG_STATE_A_WAIT_VFALL:
84 return "a_wait_vfall";
85 case OTG_STATE_A_VBUS_ERR:
86 return "a_vbus_err";
87 case OTG_STATE_B_IDLE:
88 return "b_idle";
89 case OTG_STATE_B_SRP_INIT:
90 return "b_srp_init";
91 case OTG_STATE_B_PERIPHERAL:
92 return "b_peripheral";
93 case OTG_STATE_B_WAIT_ACON:
94 return "b_wait_acon";
95 case OTG_STATE_B_HOST:
96 return "b_host";
97 default:
98 return "UNDEFINED";
99 }
100}
101EXPORT_SYMBOL(otg_state_string);
1/*
2 * otg.c -- USB OTG utility code
3 *
4 * Copyright (C) 2004 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/export.h>
14#include <linux/device.h>
15
16#include <linux/usb/otg.h>
17
18static struct usb_phy *phy;
19
20/**
21 * usb_get_transceiver - find the (single) USB transceiver
22 *
23 * Returns the transceiver driver, after getting a refcount to it; or
24 * null if there is no such transceiver. The caller is responsible for
25 * calling usb_put_transceiver() to release that count.
26 *
27 * For use by USB host and peripheral drivers.
28 */
29struct usb_phy *usb_get_transceiver(void)
30{
31 if (phy)
32 get_device(phy->dev);
33 return phy;
34}
35EXPORT_SYMBOL(usb_get_transceiver);
36
37/**
38 * usb_put_transceiver - release the (single) USB transceiver
39 * @x: the transceiver returned by usb_get_transceiver()
40 *
41 * Releases a refcount the caller received from usb_get_transceiver().
42 *
43 * For use by USB host and peripheral drivers.
44 */
45void usb_put_transceiver(struct usb_phy *x)
46{
47 if (x)
48 put_device(x->dev);
49}
50EXPORT_SYMBOL(usb_put_transceiver);
51
52/**
53 * usb_set_transceiver - declare the (single) USB transceiver
54 * @x: the USB transceiver to be used; or NULL
55 *
56 * This call is exclusively for use by transceiver drivers, which
57 * coordinate the activities of drivers for host and peripheral
58 * controllers, and in some cases for VBUS current regulation.
59 */
60int usb_set_transceiver(struct usb_phy *x)
61{
62 if (phy && x)
63 return -EBUSY;
64 phy = x;
65 return 0;
66}
67EXPORT_SYMBOL(usb_set_transceiver);
68
69const char *otg_state_string(enum usb_otg_state state)
70{
71 switch (state) {
72 case OTG_STATE_A_IDLE:
73 return "a_idle";
74 case OTG_STATE_A_WAIT_VRISE:
75 return "a_wait_vrise";
76 case OTG_STATE_A_WAIT_BCON:
77 return "a_wait_bcon";
78 case OTG_STATE_A_HOST:
79 return "a_host";
80 case OTG_STATE_A_SUSPEND:
81 return "a_suspend";
82 case OTG_STATE_A_PERIPHERAL:
83 return "a_peripheral";
84 case OTG_STATE_A_WAIT_VFALL:
85 return "a_wait_vfall";
86 case OTG_STATE_A_VBUS_ERR:
87 return "a_vbus_err";
88 case OTG_STATE_B_IDLE:
89 return "b_idle";
90 case OTG_STATE_B_SRP_INIT:
91 return "b_srp_init";
92 case OTG_STATE_B_PERIPHERAL:
93 return "b_peripheral";
94 case OTG_STATE_B_WAIT_ACON:
95 return "b_wait_acon";
96 case OTG_STATE_B_HOST:
97 return "b_host";
98 default:
99 return "UNDEFINED";
100 }
101}
102EXPORT_SYMBOL(otg_state_string);