Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 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 "cpu.h" |
| 23 | #include "system.h" |
| 24 | #include "kernel.h" |
| 25 | #include "ata.h" |
Michael Sevakis | 1cc949c | 2008-04-01 07:26:24 +0000 | [diff] [blame] | 26 | #include "usb.h" |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 27 | #include "usb_core.h" |
Michael Sevakis | 0e71c58 | 2008-04-20 03:35:21 +0000 | [diff] [blame] | 28 | #include "usb_drv.h" |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 29 | #include "clkctl-imx31.h" |
| 30 | #include "mc13783.h" |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 31 | |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 32 | static int usb_status = USB_EXTRACTED; |
| 33 | |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 34 | static void enable_transceiver(bool enable) |
| 35 | { |
| 36 | if (enable) |
| 37 | { |
| 38 | if (GPIO1_DR & (1 << 30)) |
| 39 | { |
Michael Sevakis | 86680e7 | 2008-05-08 09:03:19 +0000 | [diff] [blame] | 40 | imx31_regmod32(&GPIO3_DR, 0, (1 << 16)); /* Reset ISP1504 */ |
| 41 | sleep(HZ/100); |
| 42 | imx31_regmod32(&GPIO3_DR, (1 << 16), (1 << 16)); |
| 43 | sleep(HZ/10); |
| 44 | imx31_regmod32(&GPIO1_DR, 0, (1 << 30)); /* Select ISP1504 */ |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | else |
| 48 | { |
Michael Sevakis | 86680e7 | 2008-05-08 09:03:19 +0000 | [diff] [blame] | 49 | imx31_regmod32(&GPIO1_DR, (1 << 30), (1 << 30)); /* Deselect ISP1504 */ |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
Michael Sevakis | a9c20f5 | 2008-05-21 08:42:11 +0000 | [diff] [blame] | 53 | void usb_connect_event(void) |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 54 | { |
Michael Sevakis | a9c20f5 | 2008-05-21 08:42:11 +0000 | [diff] [blame] | 55 | uint32_t status = mc13783_read(MC13783_INTERRUPT_SENSE0); |
| 56 | usb_status = (status & MC13783_USB4V4S) ? USB_INSERTED : USB_EXTRACTED; |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | int usb_detect(void) |
| 60 | { |
| 61 | return usb_status; |
| 62 | } |
| 63 | |
| 64 | /* Read the immediate state of the cable from the PMIC */ |
| 65 | bool usb_plugged(void) |
| 66 | { |
Michael Sevakis | cda664b | 2008-05-16 06:21:11 +0000 | [diff] [blame] | 67 | return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void usb_init_device(void) |
| 71 | { |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 72 | imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL); |
| 73 | |
| 74 | enable_transceiver(true); |
| 75 | |
| 76 | /* Module will be turned off later after firmware init */ |
| 77 | usb_drv_startup(); |
| 78 | |
Michael Sevakis | a9c20f5 | 2008-05-21 08:42:11 +0000 | [diff] [blame] | 79 | /* Initially poll */ |
| 80 | usb_connect_event(); |
| 81 | |
| 82 | /* Enable PMIC event */ |
| 83 | mc13783_enable_event(MC13783_USB4V4_EVENT); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void usb_enable(bool on) |
| 87 | { |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 88 | if (on) |
| 89 | { |
| 90 | imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL); |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 91 | enable_transceiver(true); |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 92 | usb_core_init(); |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | /* Module clock should be on since this could be called first */ |
| 97 | imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL); |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 98 | enable_transceiver(true); |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 99 | usb_core_exit(); |
Michael Sevakis | 9003dbe | 2008-04-20 03:30:57 +0000 | [diff] [blame] | 100 | enable_transceiver(false); |
Michael Sevakis | 94f7d0f | 2008-04-18 16:42:50 +0000 | [diff] [blame] | 101 | imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_OFF); |
| 102 | } |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 103 | } |