⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daisy.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 *	@daisy. * *	If there is no device with the specified device number, -ENXIO *	is returned.  Otherwise, the values pointed to by @parport, *	@mux, and @daisy are set to the coordinates of the device, *	with -1 for coordinates with no value. * *	This function is not actually very useful, but this interface *	was suggested by IEEE 1284.3. **/int parport_device_coords (int devnum, int *parport, int *mux, int *daisy){	struct daisydev *dev = topology;	while (dev && dev->devnum != devnum)		dev = dev->next;	if (!dev)		return -ENXIO;	if (parport) *parport = dev->port->portnum;	if (mux) *mux = dev->port->muxport;	if (daisy) *daisy = dev->daisy;	return 0;}/* Send a daisy-chain-style CPP command packet. */static int cpp_daisy (struct parport *port, int cmd){	unsigned char s;	parport_data_forward (port);	parport_write_data (port, 0xaa); udelay (2);	parport_write_data (port, 0x55); udelay (2);	parport_write_data (port, 0x00); udelay (2);	parport_write_data (port, 0xff); udelay (2);	s = parport_read_status (port) & (PARPORT_STATUS_BUSY					  | PARPORT_STATUS_PAPEROUT					  | PARPORT_STATUS_SELECT					  | PARPORT_STATUS_ERROR);	if (s != (PARPORT_STATUS_BUSY		  | PARPORT_STATUS_PAPEROUT		  | PARPORT_STATUS_SELECT		  | PARPORT_STATUS_ERROR)) {		DPRINTK (KERN_DEBUG "%s: cpp_daisy: aa5500ff(%02x)\n",			 port->name, s);		return -ENXIO;	}	parport_write_data (port, 0x87); udelay (2);	s = parport_read_status (port) & (PARPORT_STATUS_BUSY					  | PARPORT_STATUS_PAPEROUT					  | PARPORT_STATUS_SELECT					  | PARPORT_STATUS_ERROR);	if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) {		DPRINTK (KERN_DEBUG "%s: cpp_daisy: aa5500ff87(%02x)\n",			 port->name, s);		return -ENXIO;	}	parport_write_data (port, 0x78); udelay (2);	parport_write_data (port, cmd); udelay (2);	parport_frob_control (port,			      PARPORT_CONTROL_STROBE,			      PARPORT_CONTROL_STROBE);	udelay (1);	parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);	udelay (1);	s = parport_read_status (port);	parport_write_data (port, 0xff); udelay (2);	return s;}/* Send a mux-style CPP command packet. */static int cpp_mux (struct parport *port, int cmd){	unsigned char s;	int rc;	parport_data_forward (port);	parport_write_data (port, 0xaa); udelay (2);	parport_write_data (port, 0x55); udelay (2);	parport_write_data (port, 0xf0); udelay (2);	parport_write_data (port, 0x0f); udelay (2);	parport_write_data (port, 0x52); udelay (2);	parport_write_data (port, 0xad); udelay (2);	parport_write_data (port, cmd); udelay (2);	s = parport_read_status (port);	if (!(s & PARPORT_STATUS_ACK)) {		DPRINTK (KERN_DEBUG "%s: cpp_mux: aa55f00f52ad%02x(%02x)\n",			 port->name, cmd, s);		return -EIO;	}	rc = (((s & PARPORT_STATUS_SELECT   ? 1 : 0) << 0) |	      ((s & PARPORT_STATUS_PAPEROUT ? 1 : 0) << 1) |	      ((s & PARPORT_STATUS_BUSY     ? 0 : 1) << 2) |	      ((s & PARPORT_STATUS_ERROR    ? 0 : 1) << 3));	return rc;}void parport_daisy_deselect_all (struct parport *port){	cpp_daisy (port, 0x30);}int parport_daisy_select (struct parport *port, int daisy, int mode){	/* mode is currently ignored. FIXME? */	return cpp_daisy (port, 0xe0 + daisy) & PARPORT_STATUS_ERROR;}static int mux_present (struct parport *port){	return cpp_mux (port, 0x51) == 3;}static int num_mux_ports (struct parport *port){	return cpp_mux (port, 0x58);}static int select_port (struct parport *port){	int muxport = port->muxport;	return cpp_mux (port, 0x60 + muxport) == muxport;}static int assign_addrs (struct parport *port){	unsigned char s, last_dev;	unsigned char daisy;	int thisdev = numdevs;	int detected;	char *deviceid;	parport_data_forward (port);	parport_write_data (port, 0xaa); udelay (2);	parport_write_data (port, 0x55); udelay (2);	parport_write_data (port, 0x00); udelay (2);	parport_write_data (port, 0xff); udelay (2);	s = parport_read_status (port) & (PARPORT_STATUS_BUSY					  | PARPORT_STATUS_PAPEROUT					  | PARPORT_STATUS_SELECT					  | PARPORT_STATUS_ERROR);	if (s != (PARPORT_STATUS_BUSY		  | PARPORT_STATUS_PAPEROUT		  | PARPORT_STATUS_SELECT		  | PARPORT_STATUS_ERROR)) {		DPRINTK (KERN_DEBUG "%s: assign_addrs: aa5500ff(%02x)\n",			 port->name, s);		return 0;	}	parport_write_data (port, 0x87); udelay (2);	s = parport_read_status (port) & (PARPORT_STATUS_BUSY					  | PARPORT_STATUS_PAPEROUT					  | PARPORT_STATUS_SELECT					  | PARPORT_STATUS_ERROR);	if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) {		DPRINTK (KERN_DEBUG "%s: assign_addrs: aa5500ff87(%02x)\n",			 port->name, s);		return 0;	}	parport_write_data (port, 0x78); udelay (2);	last_dev = 0; /* We've just been speaking to a device, so we			 know there must be at least _one_ out there. */	for (daisy = 0; daisy < 4; daisy++) {		parport_write_data (port, daisy);		udelay (2);		parport_frob_control (port,				      PARPORT_CONTROL_STROBE,				      PARPORT_CONTROL_STROBE);		udelay (1);		parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);		udelay (1);		if (last_dev)			/* No more devices. */			break;		last_dev = !(parport_read_status (port)			     & PARPORT_STATUS_BUSY);		add_dev (numdevs++, port, daisy);	}	parport_write_data (port, 0xff); udelay (2);	detected = numdevs - thisdev;	DPRINTK (KERN_DEBUG "%s: Found %d daisy-chained devices\n", port->name,		 detected);	/* Ask the new devices to introduce themselves. */	deviceid = kmalloc (1000, GFP_KERNEL);	if (!deviceid) return 0;	for (daisy = 0; thisdev < numdevs; thisdev++, daisy++)		parport_device_id (thisdev, deviceid, 1000);	kfree (deviceid);	return detected;}/* Find a device with a particular manufacturer and model string,   starting from a given device number.  Like the PCI equivalent,   'from' itself is skipped. *//** *	parport_find_device - find a specific device *	@mfg: required manufacturer string *	@mdl: required model string *	@from: previous device number found in search, or %NULL for *	       new search * *	This walks through the list of parallel port devices looking *	for a device whose 'MFG' string matches @mfg and whose 'MDL' *	string matches @mdl in their IEEE 1284 Device ID. * *	When a device is found matching those requirements, its device *	number is returned; if there is no matching device, a negative *	value is returned. * *	A new search it initiated by passing %NULL as the @from *	argument.  If @from is not %NULL, the search continues from *	that device. **/int parport_find_device (const char *mfg, const char *mdl, int from){	struct daisydev *d = topology; /* sorted by devnum */	/* Find where to start. */	while (d && d->devnum <= from)		d = d->next;	/* Search. */	while (d) {		struct parport_device_info *info;		info = &d->port->probe_info[1 + d->daisy];		if ((!mfg || !strcmp (mfg, info->mfr)) &&		    (!mdl || !strcmp (mdl, info->model)))			break;		d = d->next;	}	if (d)		return d->devnum;	return -1;}/** *	parport_find_class - find a device in a specified class *	@cls: required class *	@from: previous device number found in search, or %NULL for *	       new search * *	This walks through the list of parallel port devices looking *	for a device whose 'CLS' string matches @cls in their IEEE *	1284 Device ID. * *	When a device is found matching those requirements, its device *	number is returned; if there is no matching device, a negative *	value is returned. * *	A new search it initiated by passing %NULL as the @from *	argument.  If @from is not %NULL, the search continues from *	that device. **/int parport_find_class (parport_device_class cls, int from){	struct daisydev *d = topology; /* sorted by devnum */	/* Find where to start. */	while (d && d->devnum <= from)		d = d->next;	/* Search. */	while (d && d->port->probe_info[1 + d->daisy].class != cls)		d = d->next;	if (d)		return d->devnum;	return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -