2 * Generic ULPI USB transceiver support
4 * Copyright (C) 2009 Daniel Mack <daniel@caiaq.de>
6 * Based on sources from
8 * Sascha Hauer <s.hauer@pengutronix.de>
9 * Freescale Semiconductors
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.
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.
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.
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/usb.h>
29 #include <linux/usb/otg.h>
30 #include <linux/usb/ulpi.h>
32 /* ULPI register addresses */
33 #define ULPI_VID_LOW 0x00 /* Vendor ID low */
34 #define ULPI_VID_HIGH 0x01 /* Vendor ID high */
35 #define ULPI_PID_LOW 0x02 /* Product ID low */
36 #define ULPI_PID_HIGH 0x03 /* Product ID high */
37 #define ULPI_ITFCTL 0x07 /* Interface Control */
38 #define ULPI_OTGCTL 0x0A /* OTG Control */
40 /* add to above register address to access Set/Clear functions */
41 #define ULPI_REG_SET 0x01
42 #define ULPI_REG_CLEAR 0x02
44 /* ULPI OTG Control Register bits */
45 #define ID_PULL_UP (1 << 0) /* enable ID Pull Up */
46 #define DP_PULL_DOWN (1 << 1) /* enable DP Pull Down */
47 #define DM_PULL_DOWN (1 << 2) /* enable DM Pull Down */
48 #define DISCHRG_VBUS (1 << 3) /* Discharge Vbus */
49 #define CHRG_VBUS (1 << 4) /* Charge Vbus */
50 #define DRV_VBUS (1 << 5) /* Drive Vbus */
51 #define DRV_VBUS_EXT (1 << 6) /* Drive Vbus external */
52 #define USE_EXT_VBUS_IND (1 << 7) /* Use ext. Vbus indicator */
54 #define ULPI_ID(vendor, product) (((vendor) << 16) | (product))
56 #define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0)
58 /* ULPI hardcoded IDs, used for probing */
59 static unsigned int ulpi_ids
[] = {
60 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */
63 static int ulpi_set_flags(struct otg_transceiver
*otg
)
65 unsigned int flags
= 0;
67 if (otg
->flags
& USB_OTG_PULLUP_ID
)
70 if (otg
->flags
& USB_OTG_PULLDOWN_DM
)
71 flags
|= DM_PULL_DOWN
;
73 if (otg
->flags
& USB_OTG_PULLDOWN_DP
)
74 flags
|= DP_PULL_DOWN
;
76 if (otg
->flags
& USB_OTG_EXT_VBUS_INDICATOR
)
77 flags
|= USE_EXT_VBUS_IND
;
79 return otg_io_write(otg
, flags
, ULPI_OTGCTL
+ ULPI_REG_SET
);
82 static int ulpi_init(struct otg_transceiver
*otg
)
86 vid
= (otg_io_read(otg
, ULPI_VID_HIGH
) << 8) |
87 otg_io_read(otg
, ULPI_VID_LOW
);
88 pid
= (otg_io_read(otg
, ULPI_PID_HIGH
) << 8) |
89 otg_io_read(otg
, ULPI_PID_LOW
);
91 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid
, pid
);
93 for (i
= 0; i
< ARRAY_SIZE(ulpi_ids
); i
++)
94 if (ulpi_ids
[i
] == ULPI_ID(vid
, pid
))
95 return ulpi_set_flags(otg
);
97 pr_err("ULPI ID does not match any known transceiver.\n");
101 static int ulpi_set_vbus(struct otg_transceiver
*otg
, bool on
)
103 unsigned int flags
= otg_io_read(otg
, ULPI_OTGCTL
);
105 flags
&= ~(DRV_VBUS
| DRV_VBUS_EXT
);
108 if (otg
->flags
& USB_OTG_DRV_VBUS
)
111 if (otg
->flags
& USB_OTG_DRV_VBUS_EXT
)
112 flags
|= DRV_VBUS_EXT
;
115 return otg_io_write(otg
, flags
, ULPI_OTGCTL
+ ULPI_REG_SET
);
118 struct otg_transceiver
*
119 otg_ulpi_create(struct otg_io_access_ops
*ops
,
122 struct otg_transceiver
*otg
;
124 otg
= kzalloc(sizeof(*otg
), GFP_KERNEL
);
131 otg
->init
= ulpi_init
;
132 otg
->set_vbus
= ulpi_set_vbus
;
136 EXPORT_SYMBOL_GPL(otg_ulpi_create
);