set_bit(code, sw->dev[i].absbit); sw->dev[i].absmax[code] = (1 << bits) - 1; sw->dev[i].absmin[code] = (bits == 1) ? -1 : 0; sw->dev[i].absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; 
set_bit(code, input_dev->absbit); input_dev->absmax[code] = (1 << bits) - 1; input_dev->absmin[code] = (bits == 1) ? -1 : 0; input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; 
static int sw_connect(struct gameport *gameport, struct gameport_driver *drv){	struct sw *sw;	int i, j, k, l;	int err;	unsigned char *buf = NULL;	/* [SW_LENGTH] */	unsigned char *idbuf = NULL;	/* [SW_LENGTH] */	unsigned char m = 1;	char comment[40];	comment[0] = 0;	sw = kzalloc(sizeof(struct sw), GFP_KERNEL);	buf = kmalloc(SW_LENGTH, GFP_KERNEL);	idbuf = kmalloc(SW_LENGTH, GFP_KERNEL);	if (!sw || !buf || !idbuf) {		err = -ENOMEM;		goto fail1;	}	sw->gameport = gameport;	gameport_set_drvdata(gameport, sw);	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);	if (err)		goto fail1;	dbg("Init 0: Opened %s, io %#x, speed %d",		gameport->phys, gameport->io, gameport->speed);	i = sw_read_packet(gameport, buf, SW_LENGTH, 0);		/* Read normal packet */	msleep(SW_TIMEOUT);	dbg("Init 1: Mode %d. Length %d.", m , i);	if (!i) {							/* No data. 3d Pro analog mode? */		sw_init_digital(gameport);				/* Switch to digital */		msleep(SW_TIMEOUT);		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Retry reading packet */		msleep(SW_TIMEOUT);		dbg("Init 1b: Length %d.", i);		if (!i) {						/* No data -> FAIL */			err = -ENODEV;			goto fail2;		}	}	j = sw_read_packet(gameport, idbuf, SW_LENGTH, i);		/* Read ID. This initializes the stick */	m |= sw_guess_mode(idbuf, j);					/* ID packet should carry mode info [3DP] */	dbg("Init 2: Mode %d. ID Length %d.", m, j);	if (j <= 0) {							/* Read ID failed. Happens in 1-bit mode on PP */		msleep(SW_TIMEOUT);		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Retry reading packet */		m |= sw_guess_mode(buf, i);		dbg("Init 2b: Mode %d. Length %d.", m, i);		if (!i) {			err = -ENODEV;			goto fail2;		}		msleep(SW_TIMEOUT);		j = sw_read_packet(gameport, idbuf, SW_LENGTH, i);	/* Retry reading ID */		dbg("Init 2c: ID Length %d.", j);	}	sw->type = -1;	k = SW_FAIL;							/* Try SW_FAIL times */	l = 0;	do {		k--;		msleep(SW_TIMEOUT);		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Read data packet */		dbg("Init 3: Mode %d. Length %d. Last %d. Tries %d.", m, i, l, k);		if (i > l) {						/* Longer? As we can only lose bits, it makes */									/* no sense to try detection for a packet shorter */			l = i;						/* than the previous one */			sw->number = 1;			sw->gameport = gameport;			sw->length = i;			sw->bits = m;			dbg("Init 3a: Case %d.\n", i * m);			switch (i * m) {				case 60:					sw->number++;				case 45:				/* Ambiguous packet length */					if (j <= 40) {			/* ID length less or eq 40 -> FSP */				case 43:						sw->type = SW_ID_FSP;						break;					}					sw->number++;				case 30:					sw->number++;				case 15:					sw->type = SW_ID_GP;					break;				case 33:				case 31:					sw->type = SW_ID_FFW;					break;				case 48:				/* Ambiguous */					if (j == 14) {			/* ID length 14*3 -> FFP */						sw->type = SW_ID_FFP;						sprintf(comment, " [AC %s]", sw_get_bits(idbuf,38,1,3) ? "off" : "on");					} else					sw->type = SW_ID_PP;					break;				case 66:					sw->bits = 3;				case 198:					sw->length = 22;				case 64:					sw->type = SW_ID_3DP;					if (j == 160) sw_3dp_id(idbuf, comment);					break;			}		}	} while (k && sw->type == -1);	if (sw->type == -1) {		printk(KERN_WARNING "sidewinder.c: unknown joystick device detected "			"on %s, contact <vojtech@ucw.cz>\n", gameport->phys);		sw_print_packet("ID", j * 3, idbuf, 3);		sw_print_packet("Data", i * m, buf, m);		err = -ENODEV;		goto fail2;	}#ifdef SW_DEBUG	sw_print_packet("ID", j * 3, idbuf, 3);	sw_print_packet("Data", i * m, buf, m);#endif	gameport_set_poll_handler(gameport, sw_poll);	gameport_set_poll_interval(gameport, 20);	k = i;	l = j;	for (i = 0; i < sw->number; i++) {		int bits, code;		sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]);		sprintf(sw->phys[i], "%s/input%d", gameport->phys, i);		sw->dev[i].private = sw;		sw->dev[i].open = sw_open;		sw->dev[i].close = sw_close;		sw->dev[i].name = sw->name;		sw->dev[i].phys = sw->phys[i];		sw->dev[i].id.bustype = BUS_GAMEPORT;		sw->dev[i].id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;		sw->dev[i].id.product = sw->type;		sw->dev[i].id.version = 0x0100;		sw->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);		for (j = 0; (bits = sw_bit[sw->type][j]); j++) {			code = sw_abs[sw->type][j];			set_bit(code, sw->dev[i].absbit);			sw->dev[i].absmax[code] = (1 << bits) - 1;			sw->dev[i].absmin[code] = (bits == 1) ? -1 : 0;			sw->dev[i].absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;			if (code != ABS_THROTTLE)				sw->dev[i].absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0;		}		for (j = 0; (code = sw_btn[sw->type][j]); j++)			set_bit(code, sw->dev[i].keybit);		input_register_device(sw->dev + i);		printk(KERN_INFO "input: %s%s on %s [%d-bit id %d data %d]\n",			sw->name, comment, gameport->phys, m, l, k);	}	return 0;fail2:	gameport_close(gameport);fail1:	gameport_set_drvdata(gameport, NULL);	kfree(sw);	kfree(buf);	kfree(idbuf);	return err;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/17dd3f0f7aa729a042af5d3318ff9b3e7781b45b/sidewinder.c/buggy/drivers/input/joystick/sidewinder.c