blob: a8c3db85bd04e2241486ea03cf5cc61d5b1a292b [file] [log] [blame]
Marcin Bukat28d54c62010-04-26 21:40:16 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Marcin Bukat082c7d32010-10-22 12:28:43 +00008 * $Id$
Marcin Bukat28d54c62010-04-26 21:40:16 +00009 *
10 * Copyright (C) 2010 Marcin Bukat
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include <stdbool.h>
23#include "cpu.h"
24#include "system.h"
25#include "kernel.h"
26#include "usb.h"
27
28void usb_init_device(void)
29{
30 /* GPIO42 is USB detect input
31 * but it also serves as MCLK2 for DAC
32 */
Marcin Bukat2d788742010-06-11 11:41:33 +000033 and_l(~(1<<4), &GPIO1_OUT); /* GPIO36 low */
34 or_l((1<<4), &GPIO1_ENABLE); /* GPIO36 */
35 or_l((1<<4)|(1<<5), &GPIO1_FUNCTION); /* GPIO36 GPIO37 */
Marcin Bukat28d54c62010-04-26 21:40:16 +000036
Marcin Bukat2d788742010-06-11 11:41:33 +000037 /* GPIO22 GPIO30 high */
Marcin Bukat28d54c62010-04-26 21:40:16 +000038 or_l((1<<22)|(1<<30), &GPIO_OUT);
Marcin Bukat2d788742010-06-11 11:41:33 +000039 or_l((1<<22)|(1<<30), &GPIO_ENABLE);
40 or_l((1<<22)|(1<<30), &GPIO_FUNCTION);
Marcin Bukat28d54c62010-04-26 21:40:16 +000041}
42
43int usb_detect(void)
44{
45 /* GPIO42 active low*/
46 return (GPIO1_READ & (1<<10)) ? USB_EXTRACTED : USB_INSERTED;
47}
48
49void usb_enable(bool on)
50{
Marcin Bukat59ded692010-07-17 11:38:47 +000051 /* one second timeout */
52 unsigned char timeout = 10;
Marcin Bukat28d54c62010-04-26 21:40:16 +000053
54 if(on)
55 {
Marcin Bukat28d54c62010-04-26 21:40:16 +000056 and_l(~(1<<30),&GPIO_OUT); /* GPIO30 low */
Marcin Bukatcc6747c2010-06-14 10:42:41 +000057 and_l(~(1<<22),&GPIO_OUT); /* GPIO22 low */
Marcin Bukat28d54c62010-04-26 21:40:16 +000058
Marcin Bukatcc6747c2010-06-14 10:42:41 +000059 or_l((1<<4),&GPIO1_OUT); /* GPIO36 high */
60
Marcin Bukat28d54c62010-04-26 21:40:16 +000061 }
62 else
63 {
Marcin Bukat28d54c62010-04-26 21:40:16 +000064 or_l((1<<22),&GPIO_OUT); /* GPIO22 high */
65 or_l((1<<30),&GPIO_OUT); /* GPIO30 high */
66
67 and_l(~(1<<4),&GPIO1_OUT); /* GPIO36 low */
68
Marcin Bukat59ded692010-07-17 11:38:47 +000069 while ( !(GPIO1_READ & (1<<5)) && timeout--)
70 {
71 sleep(HZ/10);
72 }
Marcin Bukatcc6747c2010-06-14 10:42:41 +000073 sleep(HZ);
Marcin Bukat28d54c62010-04-26 21:40:16 +000074 }
75}