Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Marcin Bukat | 082c7d3 | 2010-10-22 12:28:43 +0000 | [diff] [blame^] | 8 | * $Id$ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 9 | * |
| 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 | |
| 28 | void usb_init_device(void) |
| 29 | { |
| 30 | /* GPIO42 is USB detect input |
| 31 | * but it also serves as MCLK2 for DAC |
| 32 | */ |
Marcin Bukat | 2d78874 | 2010-06-11 11:41:33 +0000 | [diff] [blame] | 33 | 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 Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 36 | |
Marcin Bukat | 2d78874 | 2010-06-11 11:41:33 +0000 | [diff] [blame] | 37 | /* GPIO22 GPIO30 high */ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 38 | or_l((1<<22)|(1<<30), &GPIO_OUT); |
Marcin Bukat | 2d78874 | 2010-06-11 11:41:33 +0000 | [diff] [blame] | 39 | or_l((1<<22)|(1<<30), &GPIO_ENABLE); |
| 40 | or_l((1<<22)|(1<<30), &GPIO_FUNCTION); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int usb_detect(void) |
| 44 | { |
| 45 | /* GPIO42 active low*/ |
| 46 | return (GPIO1_READ & (1<<10)) ? USB_EXTRACTED : USB_INSERTED; |
| 47 | } |
| 48 | |
| 49 | void usb_enable(bool on) |
| 50 | { |
Marcin Bukat | 59ded69 | 2010-07-17 11:38:47 +0000 | [diff] [blame] | 51 | /* one second timeout */ |
| 52 | unsigned char timeout = 10; |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 53 | |
| 54 | if(on) |
| 55 | { |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 56 | and_l(~(1<<30),&GPIO_OUT); /* GPIO30 low */ |
Marcin Bukat | cc6747c | 2010-06-14 10:42:41 +0000 | [diff] [blame] | 57 | and_l(~(1<<22),&GPIO_OUT); /* GPIO22 low */ |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 58 | |
Marcin Bukat | cc6747c | 2010-06-14 10:42:41 +0000 | [diff] [blame] | 59 | or_l((1<<4),&GPIO1_OUT); /* GPIO36 high */ |
| 60 | |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 61 | } |
| 62 | else |
| 63 | { |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 64 | 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 Bukat | 59ded69 | 2010-07-17 11:38:47 +0000 | [diff] [blame] | 69 | while ( !(GPIO1_READ & (1<<5)) && timeout--) |
| 70 | { |
| 71 | sleep(HZ/10); |
| 72 | } |
Marcin Bukat | cc6747c | 2010-06-14 10:42:41 +0000 | [diff] [blame] | 73 | sleep(HZ); |
Marcin Bukat | 28d54c6 | 2010-04-26 21:40:16 +0000 | [diff] [blame] | 74 | } |
| 75 | } |