1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Jens Arnold
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #define HC_DATA (*((volatile unsigned short*)0xc0000000))
27 #define HC_CMD (*((volatile unsigned short*)0xc0000002))
28 #define DC_DATA (*((volatile unsigned short*)0xc0000004))
29 #define DC_CMD (*((volatile unsigned short*)0xc0000006))
31 /* host controller access */
33 unsigned isp1362_read_hc_reg16(unsigned reg
)
37 asm ("nop\n nop\n nop\n nop\n");
38 asm ("nop\n nop\n nop\n nop\n");
39 asm ("nop\n nop\n nop\n nop\n");
44 unsigned isp1362_read_hc_reg32(unsigned reg
)
50 asm ("nop\n nop\n nop\n nop\n");
51 asm ("nop\n nop\n nop\n nop\n");
52 asm ("nop\n nop\n nop\n nop\n");
55 data
|= HC_DATA
<< 16;
59 void isp1362_write_hc_reg16(unsigned reg
, unsigned data
)
63 asm ("nop\n nop\n nop\n");
68 void isp1362_write_hc_reg32(unsigned reg
, unsigned data
)
72 asm ("nop\n nop\n nop\n");
78 /* device controller access */
80 unsigned isp1362_read_dc_reg16(unsigned reg
)
84 asm ("nop\n nop\n nop\n nop\n");
85 asm ("nop\n nop\n nop\n nop\n");
86 asm ("nop\n nop\n nop\n nop\n");
91 unsigned isp1362_read_dc_reg32(unsigned reg
)
97 asm ("nop\n nop\n nop\n nop\n");
98 asm ("nop\n nop\n nop\n nop\n");
99 asm ("nop\n nop\n nop\n nop\n");
102 data
|= DC_DATA
<< 16;
106 void isp1362_write_dc_reg16(unsigned reg
, unsigned data
)
110 asm ("nop\n nop\n nop\n");
115 void isp1362_write_dc_reg32(unsigned reg
, unsigned data
)
119 asm ("nop\n nop\n nop\n");
122 DC_DATA
= data
>> 16;
125 static void isp1362_suspend(void)
129 data
= isp1362_read_hc_reg16(ISP1362_OTG_CONTROL
);
130 data
&= ~0x0001; /* DRV_VBUS = 0 */
131 isp1362_write_hc_reg16(ISP1362_OTG_CONTROL
, data
);
134 data
= isp1362_read_dc_reg16(ISP1362_DC_HARDWARE_CONFIG_R
);
135 data
&= ~0x1008; /* CLKRUN = WKUPCS = 0. Wakeup is still possible via /D_WAKEUP */
136 isp1362_write_dc_reg16(ISP1362_DC_HARDWARE_CONFIG_W
, data
);
138 /* send the DC to sleep */
139 data
= isp1362_read_dc_reg16(ISP1362_DC_MODE_R
);
140 data
|= 0x20; /* GOSUSP = 1 */
141 isp1362_write_dc_reg16(ISP1362_DC_MODE_W
, data
);
142 data
&= ~0x20; /* GOSUSP = 0 */
143 isp1362_write_dc_reg16(ISP1362_DC_MODE_W
, data
);
146 data
= isp1362_read_hc_reg16(ISP1362_HC_HARDWARE_CONFIG
);
147 data
&= ~0x0800; /* SuspendClkNotStop = 0 */
148 data
|= 0x4001; /* GlobalPowerDown = InterruptPinEnable = 1 */
149 isp1362_write_hc_reg16(ISP1362_HC_HARDWARE_CONFIG
, data
);
151 /* TODO: OTG wake-up cfg */
152 /* TODO: Interrupt setup */
154 /* set the HC to operational */
155 isp1362_write_hc_reg32(ISP1362_HC_CONTROL
, 0x0680);
156 /* RWE = RWC = 1, HCFS = 0b10 (USBOperational) */
157 /* ..then send it to sleep */
158 isp1362_write_hc_reg32(ISP1362_HC_CONTROL
, 0x06c0);
159 /* RWE = RWC = 1, HCFS = 0b11 (USBSuspend) */
164 void isp1362_init(void)
166 and_l(~0x00200080, &GPIO1_OUT
); /* disable 5V USB host power and ??? */
167 or_l( 0x00200080, &GPIO1_ENABLE
);
168 or_l( 0x00200080, &GPIO1_FUNCTION
);
170 or_l( 0x20600000, &GPIO_OUT
); /* ID = D_SUSPEND = /OTGMODE = 1 */
171 and_l(~0x04000000, &GPIO_OUT
); /* ?R26? = 0 */
172 or_l( 0x24600000, &GPIO_ENABLE
); /* ID, ?R26?, D_SUSPEND, /OTGMODE outputs */
173 and_l(~0x000000a8, &GPIO_ENABLE
); /* /INT2, /INT1, /RESET inputs */
174 or_l( 0x246000a8, &GPIO_FUNCTION
); /* GPIO for these pins */