Initial maemo platform support
[maemo-rb.git] / firmware / export / usb.h
bloba3425dae2f758bdbdb4067fd9932cc4d0052a869
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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 ****************************************************************************/
21 #ifndef _USB_H_
22 #define _USB_H_
24 #include "kernel.h"
25 #include "button.h"
27 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
28 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
29 #define USB_FIREWIRE_HANDLING
30 #endif
32 /* Messages from usb_tick and thread states */
33 enum {
34 USB_EXTRACTED = 0, /* Event+State */
35 USB_INSERTED, /* Event+State */
36 USB_POWERED, /* Event+State - transitional indicator if no power */
37 #if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
38 USB_UNPOWERED, /* Event */
39 #endif
40 #ifdef HAVE_LCD_BITMAP
41 USB_SCREENDUMP, /* State */
42 #endif
43 #if (CONFIG_STORAGE & STORAGE_MMC)
44 USB_REENABLE, /* Event */
45 #endif
46 #ifdef HAVE_USBSTACK
47 USB_TRANSFER_COMPLETION, /* Event */
48 #endif
49 #ifdef USB_FIREWIRE_HANDLING
50 USB_REQUEST_REBOOT, /* Event */
51 #endif
52 USB_QUIT, /* Event */
53 #if defined(HAVE_USB_CHARGING_ENABLE) && defined(HAVE_USBSTACK)
54 USB_CHARGER_UPDATE, /* Event */
55 #endif
56 #ifdef HAVE_BOOTLOADER_USB_MODE
57 USB_HANDLED, /* Bootloader status code */
58 #endif
61 #ifdef HAVE_USB_POWER
62 #if CONFIG_KEYPAD == RECORDER_PAD
63 #define USBPOWER_BUTTON BUTTON_F1
64 #define USBPOWER_BTN_IGNORE BUTTON_ON
65 #elif CONFIG_KEYPAD == ONDIO_PAD
66 #define USBPOWER_BUTTON BUTTON_MENU
67 #define USBPOWER_BTN_IGNORE BUTTON_OFF
68 #elif (CONFIG_KEYPAD == IPOD_4G_PAD)
69 #define USBPOWER_BUTTON BUTTON_MENU
70 #define USBPOWER_BTN_IGNORE BUTTON_PLAY
71 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
72 #define USBPOWER_BUTTON BUTTON_MODE
73 #define USBPOWER_BTN_IGNORE BUTTON_ON
74 #elif CONFIG_KEYPAD == GIGABEAT_PAD
75 #define USBPOWER_BUTTON BUTTON_MENU
76 #define USBPOWER_BTN_IGNORE BUTTON_POWER
77 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) || \
78 (CONFIG_KEYPAD == MROBE100_PAD)
79 #define USBPOWER_BUTTON BUTTON_RIGHT
80 #define USBPOWER_BTN_IGNORE BUTTON_POWER
81 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
82 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
83 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
84 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
85 #define USBPOWER_BUTTON BUTTON_SELECT
86 #define USBPOWER_BTN_IGNORE BUTTON_POWER
87 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
88 #define USBPOWER_BUTTON BUTTON_PLAY
89 #define USBPOWER_BTN_IGNORE BUTTON_POWER
90 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
91 #define USBPOWER_BUTTON BUTTON_PLAYLIST
92 #define USBPOWER_BTN_IGNORE BUTTON_POWER
93 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
94 #define USBPOWER_BUTTON BUTTON_LEFT
95 #define USBPOWER_BTN_IGNORE BUTTON_POWER
96 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
97 #define USBPOWER_BUTTON BUTTON_RIGHT
98 #define USBPOWER_BTN_IGNORE BUTTON_LEFT
99 #elif CONFIG_KEYPAD == COWON_D2_PAD
100 #define USBPOWER_BUTTON BUTTON_MENU
101 #define USBPOWER_BTN_IGNORE BUTTON_MINUS
102 #elif CONFIG_KEYPAD == ONDAVX747_PAD
103 #define USBPOWER_BUTTON BUTTON_VOL_UP
104 #define USBPOWER_BTN_IGNORE BUTTON_VOL_DOWN
105 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
106 #define USBPOWER_BUTTON BUTTON_REC
107 #define USBPOWER_BTN_IGNORE BUTTON_POWER
108 #endif
109 #endif /* HAVE_USB_POWER */
111 #ifdef HAVE_USBSTACK
112 /* USB class drivers */
113 enum {
114 #ifdef USB_ENABLE_STORAGE
115 USB_DRIVER_MASS_STORAGE,
116 #endif
117 #ifdef USB_ENABLE_SERIAL
118 USB_DRIVER_SERIAL,
119 #endif
120 #ifdef USB_ENABLE_CHARGING_ONLY
121 USB_DRIVER_CHARGING_ONLY,
122 #endif
123 #ifdef USB_ENABLE_HID
124 USB_DRIVER_HID,
125 #endif
126 USB_NUM_DRIVERS
129 struct usb_transfer_completion_event_data
131 unsigned char endpoint;
132 int dir;
133 int status;
134 int length;
135 void* data;
137 #endif /* HAVE_USBSTACK */
139 void usb_init(void) INIT_ATTR;
140 void usb_enable(bool on);
141 void usb_attach(void);
142 void usb_start_monitoring(void);
143 void usb_close(void);
144 void usb_acknowledge(long id);
145 void usb_wait_for_disconnect(struct event_queue *q);
146 int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks);
147 bool usb_inserted(void); /* return the official value, what's been reported to the threads */
148 int usb_detect(void); /* return the raw hardware value - nothing/pc/charger */
149 /* For tick-less USB monitoring (USB_STATUS_BY_EVENT) */
150 void usb_status_event(int current_status);
151 #ifdef HAVE_USB_POWER
152 bool usb_powered(void);
153 #ifdef HAVE_USB_CHARGING_ENABLE
154 enum {
155 USB_CHARGING_DISABLE,
156 USB_CHARGING_ENABLE,
157 USB_CHARGING_FORCE
159 /* called by app, implemented by usb_core on targets with rockbox usb
160 * or target-specific code on others
162 void usb_charging_enable(int state);
163 #ifdef HAVE_USBSTACK
164 void usb_charger_update(void);
165 #endif /* HAVE_USBSTACK */
166 #endif /* HAVE_USB_CHARGING_ENABLE */
167 #endif /* HAVE_USB_POWER */
168 #ifdef HAVE_USBSTACK
169 void usb_signal_transfer_completion(
170 struct usb_transfer_completion_event_data *event_data);
171 bool usb_driver_enabled(int driver);
172 bool usb_exclusive_storage(void); /* storage is available for usb */
173 void usb_storage_try_release_storage(void);
174 #endif
175 int usb_release_exclusive_storage(void);
177 #ifdef USB_FIREWIRE_HANDLING
178 bool firewire_detect(void);
179 void usb_firewire_connect_event(void);
180 #endif
182 #ifdef USB_ENABLE_HID
183 void usb_set_hid(bool enable);
184 #endif
186 #endif