blob: 0a43a7db750f6dc445ea4fedc771722dd07a02e3 [file] [log] [blame]
Tony Lindgren3cb22d62008-11-24 12:02:21 -08001/*
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{
Robert Jarzmikecf85e42009-04-21 20:33:10 -070046 if (x)
47 put_device(x->dev);
Tony Lindgren3cb22d62008-11-24 12:02:21 -080048}
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);