Prepare new maemo release
[maemo-rb.git] / firmware / usbstack / usb_class_driver.h
blob20ee26a3d0cbef609a6a976f1e8e23dd54ab43b3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 Frank Gevaerts
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 ****************************************************************************/
22 #ifndef _USB_CLASS_DRIVER_H_
23 #define _USB_CLASS_DRIVER_H_
25 /* Common api, implemented by all class drivers */
27 struct usb_class_driver {
28 /* First some runtime data */
29 bool enabled;
30 int first_interface;
31 int last_interface;
33 /* Driver api starts here */
35 /* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */
36 bool needs_exclusive_storage;
38 /* Let the driver request endpoints it need. Returns zero on success */
39 int (*request_endpoints)(struct usb_class_driver *);
41 /* Tells the driver what its first interface number will be. The driver
42 returns the number of the first available interface for the next driver
43 (i.e. a driver with one interface will return interface+1)
44 A driver must have at least one interface
45 Mandatory function */
46 int (*set_first_interface)(int interface);
48 /* Asks the driver to put the interface descriptor and all other
49 needed descriptor for this driver at dest.
50 Returns the number of bytes taken by these descriptors.
51 Mandatory function */
52 int (*get_config_descriptor)(unsigned char *dest, int max_packet_size);
54 /* Tells the driver that a usb connection has been set up and is now
55 ready to use.
56 Optional function */
57 void (*init_connection)(void);
59 /* Initialises the driver. This can be called multiple times,
60 and should not perform any action that can disturb other threads
61 (like getting the audio buffer)
62 Optional function */
63 void (*init)(void);
65 /* Tells the driver that the usb connection is no longer active
66 Optional function */
67 void (*disconnect)(void);
69 /* Tells the driver that a usb transfer has been completed. Note that "dir"
70 is relative to the host
71 Optional function */
72 void (*transfer_complete)(int ep,int dir, int status, int length);
74 /* Tells the driver that a control request has come in. If the driver is
75 able to handle it, it should ack the request, and return true. Otherwise
76 it should return false.
77 Optional function */
78 bool (*control_request)(struct usb_ctrlrequest* req, unsigned char *dest);
80 #ifdef HAVE_HOTSWAP
81 /* Tells the driver that a hotswappable disk/card was inserted or
82 extracted
83 Optional function */
84 void (*notify_hotswap)(int volume, bool inserted);
85 #endif
88 #define PACK_DATA(dest, data) pack_data(dest, &(data), sizeof(data))
89 static inline void pack_data(uint8_t **dest, const void *data, size_t size)
91 memcpy(*dest, data, size);
92 *dest += size;
94 #endif