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