1
/* $Id: drv_USBHUB.c 1126 2010-07-13 03:25:44Z michael $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/drv_USBHUB.c $
6
* Copyright (C) 2006 Ernst Bachmann <e.bachmann@xebec.de>
7
* Copyright (C) 2004,2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* Based on the USBLCD driver Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
11
* This file is part of LCD4Linux.
13
* LCD4Linux is free software; you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation; either version 2, or (at your option)
18
* LCD4Linux is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program; if not, write to the Free Software
25
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33
* struct DRIVER drv_USBHUB
42
#error The USB-HUB driver only makes sense with USB support
50
#include "drv_generic_gpio.h"
54
#define HUB_CONTROL_PORT 0x23
55
#define HUB_SET_FEATURE 3
56
#define HUB_SET_INDICATOR 22
58
static char Name[] = "USBHUB";
60
/* TODO: Better not specify defaults here,
61
* instead look for the first suitable HUB arround if
62
* no Vendor/Product specified in config.
65
static unsigned int hubVendor = 0x0409;
66
static unsigned int hubProduct = 0x0058;
68
static usb_dev_handle *hub = NULL;
70
typedef struct _usb_hub_descriptor {
72
u_int8_t bDescriptorType;
74
u_int8_t wHubCharacteristicLow;
75
u_int8_t wHubCharacteristicHigh;
76
u_int8_t bPwrOn2PwrGood;
77
u_int8_t bHubContrCurrent;
78
u_int8_t deviceRemovable;
79
u_int8_t PortPwrCtrlMask[8];
82
/****************************************/
83
/*** hardware dependant functions ***/
84
/****************************************/
87
static int drv_UH_open(void)
89
struct usb_bus *busses, *bus;
90
struct usb_device *dev;
94
info("%s: scanning for an USB HUB (0x%04x:0x%04x)...", Name, hubVendor, hubProduct);
99
busses = usb_get_busses();
101
for (bus = busses; bus; bus = bus->next) {
102
for (dev = bus->devices; dev; dev = dev->next) {
103
if ((dev->descriptor.idVendor == hubVendor) && (dev->descriptor.idProduct == hubProduct)) {
105
unsigned int v = dev->descriptor.bcdDevice;
107
info("%s: found USBHUB V%1d%1d.%1d%1d on bus %s device %s", Name,
108
(v & 0xF000) >> 12, (v & 0xF00) >> 8, (v & 0xF0) >> 4, (v & 0xF), bus->dirname, dev->filename);
110
if (dev->descriptor.bDeviceClass != USB_CLASS_HUB) {
111
error("%s: the specified device claims to be no HUB", Name);
117
error("%s: usb_open() failed!", Name);
124
error("%s: could not find a USB HUB", Name);
129
static int drv_UH_close(void)
131
debug("closing USB handle");
140
* Set the Indicator status on port "num+1" to val.
141
* according to the USB Specification, the following values would be allowed:
143
* 0 : Automatic color (display link state etc)
151
static int drv_UH_set(const int num, const int val)
158
if (val < 0 || val > 3) {
159
info("%s: value %d out of range (0..3)", Name, val);
163
if ((ret = usb_control_msg(hub,
165
HUB_SET_FEATURE, HUB_SET_INDICATOR, (val << 8) | (num + 1), NULL, 0, 1000)) != 0) {
166
info("%s: usb_control_msg failed with %d", Name, ret);
174
static int drv_UH_start(const char *section, const __attribute__ ((unused))
179
usb_hub_descriptor hub_desc;
183
buf = cfg_get(section, "Vendor", NULL);
186
error("%s: Strange Vendor Specification", Name);
189
if (sscanf(buf, "0x%x", &hubVendor) != 1) {
190
error("%s: Strange Vendor Specification: [%s]", Name, buf);
195
buf = cfg_get(section, "Product", NULL);
198
error("%s: Strange Product Specification", Name);
201
if (sscanf(buf, "0x%x", &hubProduct) != 1) {
202
error("%s: Strange Product Specification: [%s]", Name, buf);
207
if (drv_UH_open() < 0) {
212
if ((ret = usb_control_msg(hub,
213
USB_ENDPOINT_IN | USB_TYPE_CLASS | USB_RECIP_DEVICE,
214
USB_REQ_GET_DESCRIPTOR, USB_DT_HUB << 8, 0, (char *) &hub_desc, sizeof(hub_desc),
216
error("%s: hub_get_descriptor failed with %d", Name, ret);
220
GPOS = hub_desc.nNbrPorts;
221
debug("%s: HUB claims to have %d ports. Configuring them as GPOs", Name, GPOS);
222
if (!(hub_desc.wHubCharacteristicLow & 0x80)) {
223
error("%s: HUB claims to have no Indicator LEDs (Characteristics 0x%04x). Bailing out.", Name,
224
(hub_desc.wHubCharacteristicHigh << 8) | hub_desc.wHubCharacteristicLow);
225
/* The HUB Tells us that there are no LEDs to control. Breaking? Maybe don't trust it and continue anyways? */
235
/****************************************/
237
/****************************************/
239
/* none at the moment... */
242
/****************************************/
243
/*** widget callbacks ***/
244
/****************************************/
247
/* using drv_generic_text_draw(W) */
248
/* using drv_generic_text_icon_draw(W) */
249
/* using drv_generic_text_bar_draw(W) */
252
/****************************************/
253
/*** exported functions ***/
254
/****************************************/
258
int drv_UH_list(void)
265
/* initialize driver & display */
266
int drv_UH_init(const char *section, const int quiet)
271
info("%s: %s", Name, "$Rev: 1126 $");
276
if ((ret = drv_UH_start(section, quiet)) != 0)
280
/* real worker functions */
281
drv_generic_gpio_real_set = drv_UH_set;
284
/* initialize generic GPIO driver */
285
if ((ret = drv_generic_gpio_init(section, Name)) != 0)
288
/* register gpio widget, done already by generic_gpio */
290
/* register plugins */
291
/* none at the moment... */
295
/* Light all LEDS green for a greeting */
296
for (i = 0; i < GPOS; ++i) {
300
for (i = 0; i < GPOS; ++i) {
301
drv_UH_set(i, 3); /* OFF */
310
/* close driver & display */
311
int drv_UH_quit(const int quiet)
314
debug("%s: shutting down.", Name);
318
/* Light all LEDS amber for a goodbye */
319
for (i = 0; i < GPOS; ++i) {
326
drv_generic_gpio_quit();
330
info("%s: shutdown complete.", Name);
335
DRIVER drv_USBHUB = {