2 * Copyright 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
3 * Copyright 2009 Daniel Mack <daniel@caiaq.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 #include <linux/module.h>
21 #include <linux/kernel.h>
23 #include <linux/delay.h>
24 #include <linux/usb/otg.h>
25 #include <linux/usb/ulpi.h>
27 #include <mach/ulpi.h>
29 /* ULPIVIEW register bits */
30 #define ULPIVW_WU (1 << 31) /* Wakeup */
31 #define ULPIVW_RUN (1 << 30) /* read/write run */
32 #define ULPIVW_WRITE (1 << 29) /* 0 = read 1 = write */
33 #define ULPIVW_SS (1 << 27) /* SyncState */
34 #define ULPIVW_PORT_MASK 0x07 /* Port field */
35 #define ULPIVW_PORT_SHIFT 24
36 #define ULPIVW_ADDR_MASK 0xff /* data address field */
37 #define ULPIVW_ADDR_SHIFT 16
38 #define ULPIVW_RDATA_MASK 0xff /* read data field */
39 #define ULPIVW_RDATA_SHIFT 8
40 #define ULPIVW_WDATA_MASK 0xff /* write data field */
41 #define ULPIVW_WDATA_SHIFT 0
43 static int ulpi_poll(void __iomem
*view
, u32 bit
)
48 u32 data
= __raw_readl(view
);
56 printk(KERN_WARNING
"timeout polling for ULPI device\n");
61 static int ulpi_read(struct otg_transceiver
*otg
, u32 reg
)
64 void __iomem
*view
= otg
->io_priv
;
66 /* make sure interface is running */
67 if (!(__raw_readl(view
) & ULPIVW_SS
)) {
68 __raw_writel(ULPIVW_WU
, view
);
71 ret
= ulpi_poll(view
, ULPIVW_WU
);
76 /* read the register */
77 __raw_writel((ULPIVW_RUN
| (reg
<< ULPIVW_ADDR_SHIFT
)), view
);
79 /* wait for completion */
80 ret
= ulpi_poll(view
, ULPIVW_RUN
);
84 return (__raw_readl(view
) >> ULPIVW_RDATA_SHIFT
) & ULPIVW_RDATA_MASK
;
87 static int ulpi_write(struct otg_transceiver
*otg
, u32 val
, u32 reg
)
90 void __iomem
*view
= otg
->io_priv
;
92 /* make sure the interface is running */
93 if (!(__raw_readl(view
) & ULPIVW_SS
)) {
94 __raw_writel(ULPIVW_WU
, view
);
96 ret
= ulpi_poll(view
, ULPIVW_WU
);
101 __raw_writel((ULPIVW_RUN
| ULPIVW_WRITE
|
102 (reg
<< ULPIVW_ADDR_SHIFT
) |
103 ((val
& ULPIVW_WDATA_MASK
) << ULPIVW_WDATA_SHIFT
)), view
);
105 /* wait for completion */
106 return ulpi_poll(view
, ULPIVW_RUN
);
109 struct otg_io_access_ops mxc_ulpi_access_ops
= {
113 EXPORT_SYMBOL_GPL(mxc_ulpi_access_ops
);
115 struct otg_transceiver
*imx_otg_ulpi_create(unsigned int flags
)
117 return otg_ulpi_create(&mxc_ulpi_access_ops
, flags
);