xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/pnp.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=================================
2*4882a593SmuzhiyunLinux Plug and Play Documentation
3*4882a593Smuzhiyun=================================
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun:Author: Adam Belay <ambx1@neo.rr.com>
6*4882a593Smuzhiyun:Last updated: Oct. 16, 2002
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunOverview
10*4882a593Smuzhiyun--------
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunPlug and Play provides a means of detecting and setting resources for legacy or
13*4882a593Smuzhiyunotherwise unconfigurable devices.  The Linux Plug and Play Layer provides these
14*4882a593Smuzhiyunservices to compatible drivers.
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunThe User Interface
18*4882a593Smuzhiyun------------------
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunThe Linux Plug and Play user interface provides a means to activate PnP devices
21*4882a593Smuzhiyunfor legacy and user level drivers that do not support Linux Plug and Play.  The
22*4882a593Smuzhiyunuser interface is integrated into sysfs.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunIn addition to the standard sysfs file the following are created in each
25*4882a593Smuzhiyundevice's directory:
26*4882a593Smuzhiyun- id - displays a list of support EISA IDs
27*4882a593Smuzhiyun- options - displays possible resource configurations
28*4882a593Smuzhiyun- resources - displays currently allocated resources and allows resource changes
29*4882a593Smuzhiyun
30*4882a593Smuzhiyunactivating a device
31*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun::
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun	# echo "auto" > resources
36*4882a593Smuzhiyun
37*4882a593Smuzhiyunthis will invoke the automatic resource config system to activate the device
38*4882a593Smuzhiyun
39*4882a593Smuzhiyunmanually activating a device
40*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun::
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun	# echo "manual <depnum> <mode>" > resources
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun	<depnum> - the configuration number
47*4882a593Smuzhiyun	<mode> - static or dynamic
48*4882a593Smuzhiyun		 static = for next boot
49*4882a593Smuzhiyun		 dynamic = now
50*4882a593Smuzhiyun
51*4882a593Smuzhiyundisabling a device
52*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun::
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun	# echo "disable" > resources
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunEXAMPLE:
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunSuppose you need to activate the floppy disk controller.
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun1. change to the proper directory, in my case it is
64*4882a593Smuzhiyun   /driver/bus/pnp/devices/00:0f::
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun	# cd /driver/bus/pnp/devices/00:0f
67*4882a593Smuzhiyun	# cat name
68*4882a593Smuzhiyun	PC standard floppy disk controller
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun2. check if the device is already active::
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun	# cat resources
73*4882a593Smuzhiyun	DISABLED
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun  - Notice the string "DISABLED".  This means the device is not active.
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun3. check the device's possible configurations (optional)::
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun	# cat options
80*4882a593Smuzhiyun	Dependent: 01 - Priority acceptable
81*4882a593Smuzhiyun	    port 0x3f0-0x3f0, align 0x7, size 0x6, 16-bit address decoding
82*4882a593Smuzhiyun	    port 0x3f7-0x3f7, align 0x0, size 0x1, 16-bit address decoding
83*4882a593Smuzhiyun	    irq 6
84*4882a593Smuzhiyun	    dma 2 8-bit compatible
85*4882a593Smuzhiyun	Dependent: 02 - Priority acceptable
86*4882a593Smuzhiyun	    port 0x370-0x370, align 0x7, size 0x6, 16-bit address decoding
87*4882a593Smuzhiyun	    port 0x377-0x377, align 0x0, size 0x1, 16-bit address decoding
88*4882a593Smuzhiyun	    irq 6
89*4882a593Smuzhiyun	    dma 2 8-bit compatible
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun4. now activate the device::
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun	# echo "auto" > resources
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun5. finally check if the device is active::
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun	# cat resources
98*4882a593Smuzhiyun	io 0x3f0-0x3f5
99*4882a593Smuzhiyun	io 0x3f7-0x3f7
100*4882a593Smuzhiyun	irq 6
101*4882a593Smuzhiyun	dma 2
102*4882a593Smuzhiyun
103*4882a593Smuzhiyunalso there are a series of kernel parameters::
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun	pnp_reserve_irq=irq1[,irq2] ....
106*4882a593Smuzhiyun	pnp_reserve_dma=dma1[,dma2] ....
107*4882a593Smuzhiyun	pnp_reserve_io=io1,size1[,io2,size2] ....
108*4882a593Smuzhiyun	pnp_reserve_mem=mem1,size1[,mem2,size2] ....
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunThe Unified Plug and Play Layer
113*4882a593Smuzhiyun-------------------------------
114*4882a593Smuzhiyun
115*4882a593SmuzhiyunAll Plug and Play drivers, protocols, and services meet at a central location
116*4882a593Smuzhiyuncalled the Plug and Play Layer.  This layer is responsible for the exchange of
117*4882a593Smuzhiyuninformation between PnP drivers and PnP protocols.  Thus it automatically
118*4882a593Smuzhiyunforwards commands to the proper protocol.  This makes writing PnP drivers
119*4882a593Smuzhiyunsignificantly easier.
120*4882a593Smuzhiyun
121*4882a593SmuzhiyunThe following functions are available from the Plug and Play Layer:
122*4882a593Smuzhiyun
123*4882a593Smuzhiyunpnp_get_protocol
124*4882a593Smuzhiyun  increments the number of uses by one
125*4882a593Smuzhiyun
126*4882a593Smuzhiyunpnp_put_protocol
127*4882a593Smuzhiyun  deincrements the number of uses by one
128*4882a593Smuzhiyun
129*4882a593Smuzhiyunpnp_register_protocol
130*4882a593Smuzhiyun  use this to register a new PnP protocol
131*4882a593Smuzhiyun
132*4882a593Smuzhiyunpnp_unregister_protocol
133*4882a593Smuzhiyun  use this function to remove a PnP protocol from the Plug and Play Layer
134*4882a593Smuzhiyun
135*4882a593Smuzhiyunpnp_register_driver
136*4882a593Smuzhiyun  adds a PnP driver to the Plug and Play Layer
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun  this includes driver model integration
139*4882a593Smuzhiyun  returns zero for success or a negative error number for failure; count
140*4882a593Smuzhiyun  calls to the .add() method if you need to know how many devices bind to
141*4882a593Smuzhiyun  the driver
142*4882a593Smuzhiyun
143*4882a593Smuzhiyunpnp_unregister_driver
144*4882a593Smuzhiyun  removes a PnP driver from the Plug and Play Layer
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun
148*4882a593SmuzhiyunPlug and Play Protocols
149*4882a593Smuzhiyun-----------------------
150*4882a593Smuzhiyun
151*4882a593SmuzhiyunThis section contains information for PnP protocol developers.
152*4882a593Smuzhiyun
153*4882a593SmuzhiyunThe following Protocols are currently available in the computing world:
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun- PNPBIOS:
156*4882a593Smuzhiyun    used for system devices such as serial and parallel ports.
157*4882a593Smuzhiyun- ISAPNP:
158*4882a593Smuzhiyun    provides PnP support for the ISA bus
159*4882a593Smuzhiyun- ACPI:
160*4882a593Smuzhiyun    among its many uses, ACPI provides information about system level
161*4882a593Smuzhiyun    devices.
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunIt is meant to replace the PNPBIOS.  It is not currently supported by Linux
164*4882a593SmuzhiyunPlug and Play but it is planned to be in the near future.
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunRequirements for a Linux PnP protocol:
168*4882a593Smuzhiyun1. the protocol must use EISA IDs
169*4882a593Smuzhiyun2. the protocol must inform the PnP Layer of a device's current configuration
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun- the ability to set resources is optional but preferred.
172*4882a593Smuzhiyun
173*4882a593SmuzhiyunThe following are PnP protocol related functions:
174*4882a593Smuzhiyun
175*4882a593Smuzhiyunpnp_add_device
176*4882a593Smuzhiyun  use this function to add a PnP device to the PnP layer
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun  only call this function when all wanted values are set in the pnp_dev
179*4882a593Smuzhiyun  structure
180*4882a593Smuzhiyun
181*4882a593Smuzhiyunpnp_init_device
182*4882a593Smuzhiyun  call this to initialize the PnP structure
183*4882a593Smuzhiyun
184*4882a593Smuzhiyunpnp_remove_device
185*4882a593Smuzhiyun  call this to remove a device from the Plug and Play Layer.
186*4882a593Smuzhiyun  it will fail if the device is still in use.
187*4882a593Smuzhiyun  automatically will free mem used by the device and related structures
188*4882a593Smuzhiyun
189*4882a593Smuzhiyunpnp_add_id
190*4882a593Smuzhiyun  adds an EISA ID to the list of supported IDs for the specified device
191*4882a593Smuzhiyun
192*4882a593SmuzhiyunFor more information consult the source of a protocol such as
193*4882a593Smuzhiyun/drivers/pnp/pnpbios/core.c.
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun
197*4882a593SmuzhiyunLinux Plug and Play Drivers
198*4882a593Smuzhiyun---------------------------
199*4882a593Smuzhiyun
200*4882a593SmuzhiyunThis section contains information for Linux PnP driver developers.
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunThe New Way
203*4882a593Smuzhiyun^^^^^^^^^^^
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun1. first make a list of supported EISA IDS
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun   ex::
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun	static const struct pnp_id pnp_dev_table[] = {
210*4882a593Smuzhiyun		/* Standard LPT Printer Port */
211*4882a593Smuzhiyun		{.id = "PNP0400", .driver_data = 0},
212*4882a593Smuzhiyun		/* ECP Printer Port */
213*4882a593Smuzhiyun		{.id = "PNP0401", .driver_data = 0},
214*4882a593Smuzhiyun		{.id = ""}
215*4882a593Smuzhiyun	};
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun   Please note that the character 'X' can be used as a wild card in the function
218*4882a593Smuzhiyun   portion (last four characters).
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun   ex::
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun	/* Unknown PnP modems */
223*4882a593Smuzhiyun	{	"PNPCXXX",		UNKNOWN_DEV	},
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun   Supported PnP card IDs can optionally be defined.
226*4882a593Smuzhiyun   ex::
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun	static const struct pnp_id pnp_card_table[] = {
229*4882a593Smuzhiyun		{	"ANYDEVS",		0	},
230*4882a593Smuzhiyun		{	"",			0	}
231*4882a593Smuzhiyun	};
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun2. Optionally define probe and remove functions.  It may make sense not to
234*4882a593Smuzhiyun   define these functions if the driver already has a reliable method of detecting
235*4882a593Smuzhiyun   the resources, such as the parport_pc driver.
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun   ex::
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun	static int
240*4882a593Smuzhiyun	serial_pnp_probe(struct pnp_dev * dev, const struct pnp_id *card_id, const
241*4882a593Smuzhiyun			struct pnp_id *dev_id)
242*4882a593Smuzhiyun	{
243*4882a593Smuzhiyun	. . .
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun   ex::
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun	static void serial_pnp_remove(struct pnp_dev * dev)
248*4882a593Smuzhiyun	{
249*4882a593Smuzhiyun	. . .
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun   consult /drivers/serial/8250_pnp.c for more information.
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun3. create a driver structure
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun   ex::
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun	static struct pnp_driver serial_pnp_driver = {
258*4882a593Smuzhiyun		.name		= "serial",
259*4882a593Smuzhiyun		.card_id_table	= pnp_card_table,
260*4882a593Smuzhiyun		.id_table	= pnp_dev_table,
261*4882a593Smuzhiyun		.probe		= serial_pnp_probe,
262*4882a593Smuzhiyun		.remove		= serial_pnp_remove,
263*4882a593Smuzhiyun	};
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun   * name and id_table cannot be NULL.
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun4. register the driver
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun   ex::
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun	static int __init serial8250_pnp_init(void)
272*4882a593Smuzhiyun	{
273*4882a593Smuzhiyun		return pnp_register_driver(&serial_pnp_driver);
274*4882a593Smuzhiyun	}
275*4882a593Smuzhiyun
276*4882a593SmuzhiyunThe Old Way
277*4882a593Smuzhiyun^^^^^^^^^^^
278*4882a593Smuzhiyun
279*4882a593SmuzhiyunA series of compatibility functions have been created to make it easy to convert
280*4882a593SmuzhiyunISAPNP drivers.  They should serve as a temporary solution only.
281*4882a593Smuzhiyun
282*4882a593SmuzhiyunThey are as follows::
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun	struct pnp_dev *pnp_find_dev(struct pnp_card *card,
285*4882a593Smuzhiyun				     unsigned short vendor,
286*4882a593Smuzhiyun				     unsigned short function,
287*4882a593Smuzhiyun				     struct pnp_dev *from)
288*4882a593Smuzhiyun
289