]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/usb/otg/ulpi.c
USB: otg/ulpi: bail out on read errors
[net-next-2.6.git] / drivers / usb / otg / ulpi.c
CommitLineData
2d57a95f
DM
1/*
2 * Generic ULPI USB transceiver support
3 *
4 * Copyright (C) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 * Based on sources from
7 *
8 * Sascha Hauer <s.hauer@pengutronix.de>
9 * Freescale Semiconductors
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/kernel.h>
5a0e3ad6 27#include <linux/slab.h>
2d57a95f
DM
28#include <linux/usb.h>
29#include <linux/usb/otg.h>
30#include <linux/usb/ulpi.h>
31
2d57a95f
DM
32#define ULPI_ID(vendor, product) (((vendor) << 16) | (product))
33
34#define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0)
35
36/* ULPI hardcoded IDs, used for probing */
37static unsigned int ulpi_ids[] = {
38 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */
39};
40
41static int ulpi_set_flags(struct otg_transceiver *otg)
42{
43 unsigned int flags = 0;
44
45 if (otg->flags & USB_OTG_PULLUP_ID)
fc567f06 46 flags |= ULPI_OTG_CTRL_ID_PULLUP;
2d57a95f
DM
47
48 if (otg->flags & USB_OTG_PULLDOWN_DM)
fc567f06 49 flags |= ULPI_OTG_CTRL_DM_PULLDOWN;
2d57a95f
DM
50
51 if (otg->flags & USB_OTG_PULLDOWN_DP)
fc567f06 52 flags |= ULPI_OTG_CTRL_DP_PULLDOWN;
2d57a95f
DM
53
54 if (otg->flags & USB_OTG_EXT_VBUS_INDICATOR)
fc567f06 55 flags |= ULPI_OTG_CTRL_EXTVBUSIND;
2d57a95f 56
fc567f06 57 return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL));
2d57a95f
DM
58}
59
60static int ulpi_init(struct otg_transceiver *otg)
61{
7b4a0367
WS
62 int i, vid, pid, ret;
63 u32 ulpi_id = 0;
2d57a95f 64
7b4a0367
WS
65 for (i = 0; i < 4; i++) {
66 ret = otg_io_read(otg, ULPI_PRODUCT_ID_HIGH - i);
67 if (ret < 0)
68 return ret;
69 ulpi_id = (ulpi_id << 8) | ret;
70 }
71 vid = ulpi_id & 0xffff;
72 pid = ulpi_id >> 16;
2d57a95f
DM
73
74 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid);
75
76 for (i = 0; i < ARRAY_SIZE(ulpi_ids); i++)
77 if (ulpi_ids[i] == ULPI_ID(vid, pid))
78 return ulpi_set_flags(otg);
79
80 pr_err("ULPI ID does not match any known transceiver.\n");
81 return -ENODEV;
82}
83
84static int ulpi_set_vbus(struct otg_transceiver *otg, bool on)
85{
fc567f06 86 unsigned int flags = otg_io_read(otg, ULPI_OTG_CTRL);
2d57a95f 87
fc567f06 88 flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT);
2d57a95f
DM
89
90 if (on) {
91 if (otg->flags & USB_OTG_DRV_VBUS)
fc567f06 92 flags |= ULPI_OTG_CTRL_DRVVBUS;
2d57a95f
DM
93
94 if (otg->flags & USB_OTG_DRV_VBUS_EXT)
fc567f06 95 flags |= ULPI_OTG_CTRL_DRVVBUS_EXT;
2d57a95f
DM
96 }
97
fc567f06 98 return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL));
2d57a95f
DM
99}
100
101struct otg_transceiver *
102otg_ulpi_create(struct otg_io_access_ops *ops,
103 unsigned int flags)
104{
105 struct otg_transceiver *otg;
106
107 otg = kzalloc(sizeof(*otg), GFP_KERNEL);
108 if (!otg)
109 return NULL;
110
111 otg->label = "ULPI";
112 otg->flags = flags;
113 otg->io_ops = ops;
114 otg->init = ulpi_init;
115 otg->set_vbus = ulpi_set_vbus;
116
117 return otg;
118}
119EXPORT_SYMBOL_GPL(otg_ulpi_create);
120