blob: 036cd7782831cb2976711130e728cddb3700e1e1 [file] [log] [blame]
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +000016 *
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"
Dave Chapman16723502007-09-04 08:03:07 +000025#include "usb.h"
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +000026
27void usb_init_device(void)
28{
Linus Nielsen Feltzingd543bd42006-10-18 20:56:29 +000029 or_l(0x00800010, &GPIO_OUT); /* RESET deasserted, VBUS powered */
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +000030 or_l(0x00800010, &GPIO_ENABLE);
Linus Nielsen Feltzingd543bd42006-10-18 20:56:29 +000031 or_l(0x00800010, &GPIO_FUNCTION);
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +000032
33 or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */
34}
35
Dave Chapman16723502007-09-04 08:03:07 +000036int usb_detect(void)
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +000037{
Dave Chapman16723502007-09-04 08:03:07 +000038 return (GPIO1_READ & 0x00800000) ? USB_INSERTED : USB_EXTRACTED;
Linus Nielsen Feltzing8f186802006-03-22 11:06:45 +000039}
40
41void usb_enable(bool on)
42{
43 if(on) {
44 or_l(0x00000008, &GPIO1_OUT);
45 } else {
46 and_l(~0x00000008, &GPIO1_OUT);
47 }
48}