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>
26 #include <mach/ulpi.h>
28 /* ULPIVIEW register bits */
29 #define ULPIVW_WU (1 << 31) /* Wakeup */
30 #define ULPIVW_RUN (1 << 30) /* read/write run */
31 #define ULPIVW_WRITE (1 << 29) /* 0 = read 1 = write */
32 #define ULPIVW_SS (1 << 27) /* SyncState */
33 #define ULPIVW_PORT_MASK 0x07 /* Port field */
34 #define ULPIVW_PORT_SHIFT 24
35 #define ULPIVW_ADDR_MASK 0xff /* data address field */
36 #define ULPIVW_ADDR_SHIFT 16
37 #define ULPIVW_RDATA_MASK 0xff /* read data field */
38 #define ULPIVW_RDATA_SHIFT 8
39 #define ULPIVW_WDATA_MASK 0xff /* write data field */
40 #define ULPIVW_WDATA_SHIFT 0
42 static int ulpi_poll(void __iomem
*view
, u32 bit
)
47 u32 data
= __raw_readl(view
);
55 printk(KERN_WARNING
"timeout polling for ULPI device\n");
60 static int ulpi_read(struct otg_transceiver
*otg
, u32 reg
)
63 void __iomem
*view
= otg
->io_priv
;
65 /* make sure interface is running */
66 if (!(__raw_readl(view
) & ULPIVW_SS
)) {
67 __raw_writel(ULPIVW_WU
, view
);
70 ret
= ulpi_poll(view
, ULPIVW_WU
);
75 /* read the register */
76 __raw_writel((ULPIVW_RUN
| (reg
<< ULPIVW_ADDR_SHIFT
)), view
);
78 /* wait for completion */
79 ret
= ulpi_poll(view
, ULPIVW_RUN
);
83 return (__raw_readl(view
) >> ULPIVW_RDATA_SHIFT
) & ULPIVW_RDATA_MASK
;
86 static int ulpi_write(struct otg_transceiver
*otg
, u32 val
, u32 reg
)
89 void __iomem
*view
= otg
->io_priv
;
91 /* make sure the interface is running */
92 if (!(__raw_readl(view
) & ULPIVW_SS
)) {
93 __raw_writel(ULPIVW_WU
, view
);
95 ret
= ulpi_poll(view
, ULPIVW_WU
);
100 __raw_writel((ULPIVW_RUN
| ULPIVW_WRITE
|
101 (reg
<< ULPIVW_ADDR_SHIFT
) |
102 ((val
& ULPIVW_WDATA_MASK
) << ULPIVW_WDATA_SHIFT
)), view
);
104 /* wait for completion */
105 return ulpi_poll(view
, ULPIVW_RUN
);
108 struct otg_io_access_ops mxc_ulpi_access_ops
= {
112 EXPORT_SYMBOL_GPL(mxc_ulpi_access_ops
);