#!/bin/sh # # install - install a program, script, or datafile # This comes from X11R5 (mit/util/scripts/install.sh). # # Copyright 1991 by the Massachusetts Institute of Technology # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation, and that the name of M.I.T. not be used in advertising or # publicity pertaining to distribution of the software without specific, # written prior permission. M.I.T. makes no representations about the # suitability of this software for any purpose. It is provided "as is" # without express or implied warranty. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. It can only install one file at a time, a restriction # shared with many OS's install programs. # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit="${DOITPROG-}" # put in absolute paths if you don't have them in your path; or use env. vars. mvprog="${MVPROG-mv}" cpprog="${CPPROG-cp}" chmodprog="${CHMODPROG-chmod}" chownprog="${CHOWNPROG-chown}" chgrpprog="${CHGRPPROG-chgrp}" stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" transformbasename="" transform_arg="" instcmd="$mvprog" chmodcmd="$chmodprog 0755" chowncmd="" chgrpcmd="" stripcmd="" rmcmd="$rmprog -f" mvcmd="$mvprog" src="" dst="" dir_arg="" while [ x"$1" != x ]; do case $1 in -c) instcmd="$cpprog" shift continue;; -d) dir_arg=true shift continue;; -m) chmodcmd="$chmodprog $2" shift shift continue;; -o) chowncmd="$chownprog $2" shift shift continue;; -g) chgrpcmd="$chgrpprog $2" shift shift continue;; -s) stripcmd="$stripprog" shift continue;; -t=*) transformarg=`echo $1 | sed 's/-t=//'` shift continue;; -b=*) transformbasename=`echo $1 | sed 's/-b=//'` shift continue;; *) if [ x"$src" = x ] then src=$1 else # this colon is to work around a 386BSD /bin/sh bug : dst=$1 fi shift continue;; esac done if [ x"$src" = x ] then echo "install: no input file specified" exit 1 else true fi if [ x"$dir_arg" != x ]; then dst=$src src="" if [ -d $dst ]; then instcmd=: chmodcmd="" else instcmd=mkdir fi else # Waiting for this to be detected by the "$instcmd $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if [ -f $src -o -d $src ] then true else echo "install: $src does not exist" exit 1 fi if [ x"$dst" = x ] then echo "install: no destination specified" exit 1 else true fi # If destination is a directory, append the input filename; if your system # does not like double slashes in filenames, you may need to add some logic if [ -d $dst ] then dst="$dst"/`basename $src` else true fi fi ## this sed command emulates the dirname command dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` # Make sure that the destination directory exists. # this part is taken from Noah Friedman's mkinstalldirs script # Skip lots of stat calls in the usual case. if [ ! -d "$dstdir" ]; then defaultIFS=' ' IFS="${IFS-${defaultIFS}}" oIFS="${IFS}" # Some sh's can't handle IFS=/ for some reason. IFS='%' set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` IFS="${oIFS}" pathcomp='' while [ $# -ne 0 ] ; do pathcomp="${pathcomp}${1}" shift if [ ! -d "${pathcomp}" ] ; then $mkdirprog "${pathcomp}" else true fi pathcomp="${pathcomp}/" done fi if [ x"$dir_arg" != x ] then $doit $instcmd $dst && if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi else # If we're going to rename the final executable, determine the name now. if [ x"$transformarg" = x ] then dstfile=`basename $dst` else dstfile=`basename $dst $transformbasename | sed $transformarg`$transformbasename fi # don't allow the sed command to completely eliminate the filename if [ x"$dstfile" = x ] then dstfile=`basename $dst` else true fi # Make a temp file name in the proper directory. dsttmp=$dstdir/#inst.$$# # Move or copy the file name to the temp name $doit $instcmd $src $dsttmp && trap "rm -f ${dsttmp}" 0 && # and set any options; do chmod last to preserve setuid bits # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $instcmd $src $dsttmp" command. if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && # Now rename the file to the real destination. $doit $rmcmd -f $dstdir/$dstfile && $doit $mvcmd $dsttmp $dstdir/$dstfile fi && exit 0 '>96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
/* $Id: drv_USBHUB.c,v 1.1 2006/08/08 19:35:22 reinelt Exp $
*
* new style driver for USBLCD displays
*
* Copyright (C) 2006 Ernst Bachmann <e.bachmann@xebec.de>
* Copyright (C) 2004,2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
*
* Based on the USBLCD driver Copyright (C) 2003 Michael Reinelt <reinelt@eunet.at>
*
* This file is part of LCD4Linux.
*
* LCD4Linux is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LCD4Linux is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Log: drv_USBHUB.c,v $
* Revision 1.1 2006/08/08 19:35:22 reinelt
* USBHUB driver from Ernst Bachmann
*
*
*/
/*
*
* exported fuctions:
*
* struct DRIVER drv_USBHUB
*
*/
#include "config.h"
#ifdef HAVE_USB_H
# include <usb.h>
#else
# error The USB-HUB driver only makes sense with USB support
#endif
#include "debug.h"
#include "cfg.h"
#include "qprintf.h"
#include "udelay.h"
#include "drv.h"
#include "drv_generic_gpio.h"
#define HUB_CONTROL_PORT 0x23
#define HUB_SET_FEATURE 3
#define HUB_SET_INDICATOR 22
static char Name[] = "USBHUB";
/* TODO: Better not specify defaults here,
* instead look for the first suitable HUB arround if
* no Vendor/Product specified in config.
*/
static int hubVendor=0x0409;
static int hubProduct=0x0058;
static usb_dev_handle *hub=NULL;
typedef struct _usb_hub_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t nNbrPorts;
u_int8_t wHubCharacteristicLow;
u_int8_t wHubCharacteristicHigh;
u_int8_t bPwrOn2PwrGood;
u_int8_t bHubContrCurrent;
u_int8_t deviceRemovable;
u_int8_t PortPwrCtrlMask[8];
} usb_hub_descriptor;
/****************************************/
/*** hardware dependant functions ***/
/****************************************/
static int drv_UH_open(void)
{
struct usb_bus *busses, *bus;
struct usb_device *dev;
hub = NULL;
info("%s: scanning for an USB HUB (0x%04x:0x%04x)...", Name,hubVendor,hubProduct);
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
for (bus = busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if ((dev->descriptor.idVendor == hubVendor) &&
(dev->descriptor.idProduct == hubProduct)) {
unsigned int v = dev->descriptor.bcdDevice;
info("%s: found USBHUB V%1d%1d.%1d%1d on bus %s device %s", Name,
(v & 0xF000) >> 12, (v & 0xF00) >> 8, (v & 0xF0) >> 4, (v & 0xF), bus->dirname, dev->filename);
if (dev->descriptor.bDeviceClass != USB_CLASS_HUB) {
error("%s: the specified device claims to be no HUB");
return -1;
}
hub = usb_open(dev);
if (!hub) {
error("%s: usb_open() failed!", Name);
return -1;
}
return 0;
}
}
}
error("%s: could not find a USB HUB", Name);
return -1;
}
static int drv_UH_close(void)
{
debug("closing USB handle");
usb_close(hub);
return 0;
}
/*
* Set the Indicator status on port "num+1" to val.
* according to the USB Specification, the following values would be allowed:
*
* 0 : Automatic color (display link state etc)
* 1 : Amber
* 2 : Green
* 3 : Off
* 4..255: Reserved
*
*/
static int drv_UH_set(const int num, const int val) {
int ret;
if (!hub)
return -1;
if (val <0 || val > 3) {
info("%s: value %d out of range (0..3)",Name,val);
return -1;
}
if((ret=usb_control_msg(hub,
HUB_CONTROL_PORT,
HUB_SET_FEATURE,
HUB_SET_INDICATOR, (val << 8) | (num+1), NULL, 0, 1000)) != 0) {
info("%s: usb_control_msg failed with %d",Name,ret);
return -1;
}
return 0;
}
static int drv_UH_start(const char *section, const int quiet)
{
char * buf;
usb_hub_descriptor hub_desc;
int ret;
buf=cfg_get(section,"Vendor",NULL);
if (buf) {
if (!*buf) {
error("%s: Strange Vendor Specification");
return -1;
}
if (sscanf(buf,"0x%x",&hubVendor) != 1) {
error("%s: Strange Vendor Specification: [%s]",buf);
return -1;
}
}
buf=cfg_get(section,"Product",NULL);
if (buf) {
if (!*buf) {
error("%s: Strange Product Specification");
return -1;
}
if (sscanf(buf,"0x%x",&hubProduct) != 1) {
error("%s: Strange Product Specification: [%s]",buf);
return -1;
}
}
if (drv_UH_open() < 0) {
return -1;
}
if ((ret=usb_control_msg(hub,
USB_ENDPOINT_IN | USB_TYPE_CLASS | USB_RECIP_DEVICE,
USB_REQ_GET_DESCRIPTOR,USB_DT_HUB << 8,0,(char *)&hub_desc,sizeof(hub_desc),1000)) <= 8) {
error("%s: hub_get_descriptor failed with %d",Name,ret);
drv_UH_close();
return -1;
}
GPOS=hub_desc.nNbrPorts;
debug("%s: HUB claims to have %d ports. Configuring them as GPOs",Name,GPOS);
if (!(hub_desc.wHubCharacteristicLow & 0x80)) {
error("%s: HUB claims to have no Indicator LEDs (Characteristics 0x%04x). Bailing out.",Name,
(hub_desc.wHubCharacteristicHigh << 8) | hub_desc.wHubCharacteristicLow);
/* The HUB Tells us that there are no LEDs to control. Breaking? Maybe don't trust it and continue anyways? */
drv_UH_close();
return -1;
}
return 0;
}
/****************************************/
/*** plugins ***/
/****************************************/
/* none at the moment... */
/****************************************/
/*** widget callbacks ***/
/****************************************/
/* using drv_generic_text_draw(W) */
/* using drv_generic_text_icon_draw(W) */
/* using drv_generic_text_bar_draw(W) */
/****************************************/
/*** exported functions ***/
/****************************************/
/* list models */
int drv_UH_list(void)
{
printf("generic");
return 0;
}
/* initialize driver & display */
int drv_UH_init(const char *section, const int quiet)
{
int ret;
int i;
info("%s: %s", Name, "$Revision: 1.1 $");
/* start display */
if ((ret = drv_UH_start(section, quiet)) != 0)
return ret;
/* real worker functions */
drv_generic_gpio_real_set=drv_UH_set;
/* initialize generic GPIO driver */
if ((ret = drv_generic_gpio_init(section, Name)) != 0)
return ret;
/* register gpio widget, done already by generic_gpio */
/* register plugins */
/* none at the moment... */
/* greeting */
if (!quiet) {
/* Light all LEDS green for a greeting */
for (i=0; i < GPOS; ++i) {
drv_UH_set(i,2);
}
sleep(1);
for (i=0; i < GPOS; ++i) {
drv_UH_set(i,3); // OFF
}
}
return 0;
}
/* close driver & display */
int drv_UH_quit(const int quiet)
{
int i;
debug("%s: shutting down.", Name);
/* say goodbye... */
if (!quiet) {
/* Light all LEDS amber for a goodbye */
for (i=0; i < GPOS; ++i) {
drv_UH_set(i,1);
}
sleep(1);
}
drv_generic_gpio_quit();
drv_UH_close();
info("%s: shutdown complete.", Name);
return 0;
}
DRIVER drv_USBHUB = {
name:Name,
list:drv_UH_list,
init:drv_UH_init,
quit:drv_UH_quit,
};