Commit FS#12096 by Stephan Grossklass. Increases the maximum ID3v2 field length...
[kugel-rb.git] / firmware / drivers / isp1362.c
blob7c2cd6f745e0a0ed440f0ee2cce815cad5247241
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "system.h"
23 #include "kernel.h"
24 #include "isp1362.h"
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)
35 HC_CMD = 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");
41 return HC_DATA;
44 unsigned isp1362_read_hc_reg32(unsigned reg)
46 unsigned data;
48 HC_CMD = 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");
54 data = HC_DATA;
55 data |= HC_DATA << 16;
56 return data;
59 void isp1362_write_hc_reg16(unsigned reg, unsigned data)
61 HC_CMD = reg | 0x80;
63 asm ("nop\n nop\n nop\n");
65 HC_DATA = data;
68 void isp1362_write_hc_reg32(unsigned reg, unsigned data)
70 HC_CMD = reg | 0x80;
72 asm ("nop\n nop\n nop\n");
74 HC_DATA = data;
75 HC_DATA = data >> 16;
78 /* device controller access */
80 unsigned isp1362_read_dc_reg16(unsigned reg)
82 DC_CMD = 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");
88 return DC_DATA;
91 unsigned isp1362_read_dc_reg32(unsigned reg)
93 unsigned data;
95 DC_CMD = 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");
101 data = DC_DATA;
102 data |= DC_DATA << 16;
103 return data;
106 void isp1362_write_dc_reg16(unsigned reg, unsigned data)
108 DC_CMD = reg;
110 asm ("nop\n nop\n nop\n");
112 DC_DATA = data;
115 void isp1362_write_dc_reg32(unsigned reg, unsigned data)
117 DC_CMD = reg;
119 asm ("nop\n nop\n nop\n");
121 DC_DATA = data;
122 DC_DATA = data >> 16;
125 static void isp1362_suspend(void)
127 unsigned data;
129 data = isp1362_read_hc_reg16(ISP1362_OTG_CONTROL);
130 data &= ~0x0001; /* DRV_VBUS = 0 */
131 isp1362_write_hc_reg16(ISP1362_OTG_CONTROL, data);
133 /* prepare the DC */
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);
145 /* prepare the HC */
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) */
162 /* init */
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 */
176 sleep(HZ/5);
178 isp1362_suspend();