Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux Plug and Play Support |
| 3 | * Copyright by Adam Belay <ambx1@neo.rr.com> |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #ifndef _LINUX_PNP_H |
| 8 | #define _LINUX_PNP_H |
| 9 | |
| 10 | #ifdef __KERNEL__ |
| 11 | |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/mod_devicetable.h> |
| 16 | |
| 17 | #define PNP_MAX_PORT 8 |
| 18 | #define PNP_MAX_MEM 4 |
| 19 | #define PNP_MAX_IRQ 2 |
| 20 | #define PNP_MAX_DMA 2 |
| 21 | #define PNP_NAME_LEN 50 |
| 22 | |
| 23 | struct pnp_protocol; |
| 24 | struct pnp_dev; |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Resource Management |
| 28 | */ |
| 29 | |
| 30 | /* Use these instead of directly reading pnp_dev to get resource information */ |
| 31 | #define pnp_port_start(dev,bar) ((dev)->res.port_resource[(bar)].start) |
| 32 | #define pnp_port_end(dev,bar) ((dev)->res.port_resource[(bar)].end) |
| 33 | #define pnp_port_flags(dev,bar) ((dev)->res.port_resource[(bar)].flags) |
| 34 | #define pnp_port_valid(dev,bar) \ |
| 35 | ((pnp_port_flags((dev),(bar)) & (IORESOURCE_IO | IORESOURCE_UNSET)) \ |
| 36 | == IORESOURCE_IO) |
| 37 | #define pnp_port_len(dev,bar) \ |
| 38 | ((pnp_port_start((dev),(bar)) == 0 && \ |
| 39 | pnp_port_end((dev),(bar)) == \ |
| 40 | pnp_port_start((dev),(bar))) ? 0 : \ |
| 41 | \ |
| 42 | (pnp_port_end((dev),(bar)) - \ |
| 43 | pnp_port_start((dev),(bar)) + 1)) |
| 44 | |
| 45 | #define pnp_mem_start(dev,bar) ((dev)->res.mem_resource[(bar)].start) |
| 46 | #define pnp_mem_end(dev,bar) ((dev)->res.mem_resource[(bar)].end) |
| 47 | #define pnp_mem_flags(dev,bar) ((dev)->res.mem_resource[(bar)].flags) |
| 48 | #define pnp_mem_valid(dev,bar) \ |
| 49 | ((pnp_mem_flags((dev),(bar)) & (IORESOURCE_MEM | IORESOURCE_UNSET)) \ |
| 50 | == IORESOURCE_MEM) |
| 51 | #define pnp_mem_len(dev,bar) \ |
| 52 | ((pnp_mem_start((dev),(bar)) == 0 && \ |
| 53 | pnp_mem_end((dev),(bar)) == \ |
| 54 | pnp_mem_start((dev),(bar))) ? 0 : \ |
| 55 | \ |
| 56 | (pnp_mem_end((dev),(bar)) - \ |
| 57 | pnp_mem_start((dev),(bar)) + 1)) |
| 58 | |
| 59 | #define pnp_irq(dev,bar) ((dev)->res.irq_resource[(bar)].start) |
| 60 | #define pnp_irq_flags(dev,bar) ((dev)->res.irq_resource[(bar)].flags) |
| 61 | #define pnp_irq_valid(dev,bar) \ |
| 62 | ((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \ |
| 63 | == IORESOURCE_IRQ) |
| 64 | |
| 65 | #define pnp_dma(dev,bar) ((dev)->res.dma_resource[(bar)].start) |
| 66 | #define pnp_dma_flags(dev,bar) ((dev)->res.dma_resource[(bar)].flags) |
| 67 | #define pnp_dma_valid(dev,bar) \ |
| 68 | ((pnp_dma_flags((dev),(bar)) & (IORESOURCE_DMA | IORESOURCE_UNSET)) \ |
| 69 | == IORESOURCE_DMA) |
| 70 | |
| 71 | #define PNP_PORT_FLAG_16BITADDR (1<<0) |
| 72 | #define PNP_PORT_FLAG_FIXED (1<<1) |
| 73 | |
| 74 | struct pnp_port { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 75 | unsigned short min; /* min base number */ |
| 76 | unsigned short max; /* max base number */ |
| 77 | unsigned char align; /* align boundary */ |
| 78 | unsigned char size; /* size of range */ |
| 79 | unsigned char flags; /* port flags */ |
| 80 | unsigned char pad; /* pad */ |
| 81 | struct pnp_port *next; /* next port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #define PNP_IRQ_NR 256 |
| 85 | struct pnp_irq { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 86 | DECLARE_BITMAP(map, PNP_IRQ_NR); /* bitmaks for IRQ lines */ |
| 87 | unsigned char flags; /* IRQ flags */ |
| 88 | unsigned char pad; /* pad */ |
| 89 | struct pnp_irq *next; /* next IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct pnp_dma { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 93 | unsigned char map; /* bitmask for DMA channels */ |
| 94 | unsigned char flags; /* DMA flags */ |
| 95 | struct pnp_dma *next; /* next port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | struct pnp_mem { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 99 | unsigned int min; /* min base number */ |
| 100 | unsigned int max; /* max base number */ |
| 101 | unsigned int align; /* align boundary */ |
| 102 | unsigned int size; /* size of range */ |
| 103 | unsigned char flags; /* memory flags */ |
| 104 | unsigned char pad; /* pad */ |
| 105 | struct pnp_mem *next; /* next memory resource */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | #define PNP_RES_PRIORITY_PREFERRED 0 |
| 109 | #define PNP_RES_PRIORITY_ACCEPTABLE 1 |
| 110 | #define PNP_RES_PRIORITY_FUNCTIONAL 2 |
| 111 | #define PNP_RES_PRIORITY_INVALID 65535 |
| 112 | |
| 113 | struct pnp_option { |
| 114 | unsigned short priority; /* priority */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 115 | struct pnp_port *port; /* first port */ |
| 116 | struct pnp_irq *irq; /* first IRQ */ |
| 117 | struct pnp_dma *dma; /* first DMA */ |
| 118 | struct pnp_mem *mem; /* first memory resource */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | struct pnp_option *next; /* used to chain dependent resources */ |
| 120 | }; |
| 121 | |
| 122 | struct pnp_resource_table { |
| 123 | struct resource port_resource[PNP_MAX_PORT]; |
| 124 | struct resource mem_resource[PNP_MAX_MEM]; |
| 125 | struct resource dma_resource[PNP_MAX_DMA]; |
| 126 | struct resource irq_resource[PNP_MAX_IRQ]; |
| 127 | }; |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Device Managemnt |
| 131 | */ |
| 132 | |
| 133 | struct pnp_card { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 134 | struct device dev; /* Driver Model device interface */ |
| 135 | unsigned char number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | struct list_head global_list; /* node in global list of cards */ |
| 137 | struct list_head protocol_list; /* node in protocol's list of cards */ |
| 138 | struct list_head devices; /* devices attached to the card */ |
| 139 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 140 | struct pnp_protocol *protocol; |
| 141 | struct pnp_id *id; /* contains supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 144 | unsigned char pnpver; /* Plug & Play version */ |
| 145 | unsigned char productver; /* product version */ |
| 146 | unsigned int serial; /* serial number */ |
| 147 | unsigned char checksum; /* if zero - checksum passed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */ |
| 149 | }; |
| 150 | |
| 151 | #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list) |
| 152 | #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list) |
| 153 | #define to_pnp_card(n) container_of(n, struct pnp_card, dev) |
| 154 | #define pnp_for_each_card(card) \ |
| 155 | for((card) = global_to_pnp_card(pnp_cards.next); \ |
| 156 | (card) != global_to_pnp_card(&pnp_cards); \ |
| 157 | (card) = global_to_pnp_card((card)->global_list.next)) |
| 158 | |
| 159 | struct pnp_card_link { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 160 | struct pnp_card *card; |
| 161 | struct pnp_card_driver *driver; |
| 162 | void *driver_data; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 163 | pm_message_t pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 166 | static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
| 168 | return pcard->driver_data; |
| 169 | } |
| 170 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 171 | static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | pcard->driver_data = data; |
| 174 | } |
| 175 | |
| 176 | struct pnp_dev { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 177 | struct device dev; /* Driver Model device interface */ |
David Brownell | 2e17c55 | 2007-05-08 00:25:29 -0700 | [diff] [blame] | 178 | u64 dma_mask; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 179 | unsigned char number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | int status; |
| 181 | |
| 182 | struct list_head global_list; /* node in global list of devices */ |
| 183 | struct list_head protocol_list; /* node in list of device's protocol */ |
| 184 | struct list_head card_list; /* node in card's list of devices */ |
| 185 | struct list_head rdev_list; /* node in cards list of requested devices */ |
| 186 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 187 | struct pnp_protocol *protocol; |
| 188 | struct pnp_card *card; /* card the device is attached to, none if NULL */ |
| 189 | struct pnp_driver *driver; |
| 190 | struct pnp_card_link *card_link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 192 | struct pnp_id *id; /* supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | int active; |
| 195 | int capabilities; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 196 | struct pnp_option *independent; |
| 197 | struct pnp_option *dependent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | struct pnp_resource_table res; |
| 199 | |
| 200 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 201 | unsigned short regs; /* ISAPnP: supported registers */ |
| 202 | int flags; /* used by protocols */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */ |
| 204 | void *data; |
| 205 | }; |
| 206 | |
| 207 | #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list) |
| 208 | #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list) |
| 209 | #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list) |
| 210 | #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev) |
| 211 | #define pnp_for_each_dev(dev) \ |
| 212 | for((dev) = global_to_pnp_dev(pnp_global.next); \ |
| 213 | (dev) != global_to_pnp_dev(&pnp_global); \ |
| 214 | (dev) = global_to_pnp_dev((dev)->global_list.next)) |
| 215 | #define card_for_each_dev(card,dev) \ |
| 216 | for((dev) = card_to_pnp_dev((card)->devices.next); \ |
| 217 | (dev) != card_to_pnp_dev(&(card)->devices); \ |
| 218 | (dev) = card_to_pnp_dev((dev)->card_list.next)) |
| 219 | #define pnp_dev_name(dev) (dev)->name |
| 220 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 221 | static inline void *pnp_get_drvdata(struct pnp_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | return dev_get_drvdata(&pdev->dev); |
| 224 | } |
| 225 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 226 | static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | dev_set_drvdata(&pdev->dev, data); |
| 229 | } |
| 230 | |
| 231 | struct pnp_fixup { |
| 232 | char id[7]; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 233 | void (*quirk_function) (struct pnp_dev * dev); /* fixup function */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /* config parameters */ |
| 237 | #define PNP_CONFIG_NORMAL 0x0001 |
| 238 | #define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */ |
| 239 | |
| 240 | /* capabilities */ |
| 241 | #define PNP_READ 0x0001 |
| 242 | #define PNP_WRITE 0x0002 |
| 243 | #define PNP_DISABLE 0x0004 |
| 244 | #define PNP_CONFIGURABLE 0x0008 |
| 245 | #define PNP_REMOVABLE 0x0010 |
| 246 | |
| 247 | #define pnp_can_read(dev) (((dev)->protocol) && ((dev)->protocol->get) && \ |
| 248 | ((dev)->capabilities & PNP_READ)) |
| 249 | #define pnp_can_write(dev) (((dev)->protocol) && ((dev)->protocol->set) && \ |
| 250 | ((dev)->capabilities & PNP_WRITE)) |
| 251 | #define pnp_can_disable(dev) (((dev)->protocol) && ((dev)->protocol->disable) && \ |
| 252 | ((dev)->capabilities & PNP_DISABLE)) |
| 253 | #define pnp_can_configure(dev) ((!(dev)->active) && \ |
| 254 | ((dev)->capabilities & PNP_CONFIGURABLE)) |
| 255 | |
| 256 | #ifdef CONFIG_ISAPNP |
| 257 | extern struct pnp_protocol isapnp_protocol; |
| 258 | #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol)) |
| 259 | #else |
| 260 | #define pnp_device_is_isapnp(dev) 0 |
| 261 | #endif |
| 262 | |
| 263 | #ifdef CONFIG_PNPBIOS |
| 264 | extern struct pnp_protocol pnpbios_protocol; |
| 265 | #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol)) |
| 266 | #else |
| 267 | #define pnp_device_is_pnpbios(dev) 0 |
| 268 | #endif |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* status */ |
| 271 | #define PNP_READY 0x0000 |
| 272 | #define PNP_ATTACHED 0x0001 |
| 273 | #define PNP_BUSY 0x0002 |
| 274 | #define PNP_FAULTY 0x0004 |
| 275 | |
| 276 | /* isapnp specific macros */ |
| 277 | |
| 278 | #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1) |
| 279 | #define isapnp_csn_number(dev) ((dev)->number) |
| 280 | |
| 281 | /* |
| 282 | * Driver Management |
| 283 | */ |
| 284 | |
| 285 | struct pnp_id { |
| 286 | char id[PNP_ID_LEN]; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 287 | struct pnp_id *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | struct pnp_driver { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 291 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | const struct pnp_device_id *id_table; |
| 293 | unsigned int flags; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 294 | int (*probe) (struct pnp_dev * dev, |
| 295 | const struct pnp_device_id * dev_id); |
| 296 | void (*remove) (struct pnp_dev * dev); |
| 297 | int (*suspend) (struct pnp_dev * dev, pm_message_t state); |
| 298 | int (*resume) (struct pnp_dev * dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | struct device_driver driver; |
| 300 | }; |
| 301 | |
| 302 | #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver) |
| 303 | |
| 304 | struct pnp_card_driver { |
| 305 | struct list_head global_list; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 306 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | const struct pnp_card_device_id *id_table; |
| 308 | unsigned int flags; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 309 | int (*probe) (struct pnp_card_link * card, |
| 310 | const struct pnp_card_device_id * card_id); |
| 311 | void (*remove) (struct pnp_card_link * card); |
| 312 | int (*suspend) (struct pnp_card_link * card, pm_message_t state); |
| 313 | int (*resume) (struct pnp_card_link * card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | struct pnp_driver link; |
| 315 | }; |
| 316 | |
| 317 | #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link) |
| 318 | |
| 319 | /* pnp driver flags */ |
| 320 | #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */ |
| 321 | #define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */ |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Protocol Management |
| 325 | */ |
| 326 | |
| 327 | struct pnp_protocol { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 328 | struct list_head protocol_list; |
| 329 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | /* resource control functions */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 332 | int (*get) (struct pnp_dev * dev, struct pnp_resource_table * res); |
| 333 | int (*set) (struct pnp_dev * dev, struct pnp_resource_table * res); |
| 334 | int (*disable) (struct pnp_dev * dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 336 | /* protocol specific suspend/resume */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 337 | int (*suspend) (struct pnp_dev * dev, pm_message_t state); |
| 338 | int (*resume) (struct pnp_dev * dev); |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* used by pnp layer only (look but don't touch) */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 341 | unsigned char number; /* protocol number */ |
| 342 | struct device dev; /* link to driver model */ |
| 343 | struct list_head cards; |
| 344 | struct list_head devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list) |
| 348 | #define protocol_for_each_card(protocol,card) \ |
| 349 | for((card) = protocol_to_pnp_card((protocol)->cards.next); \ |
| 350 | (card) != protocol_to_pnp_card(&(protocol)->cards); \ |
| 351 | (card) = protocol_to_pnp_card((card)->protocol_list.next)) |
| 352 | #define protocol_for_each_dev(protocol,dev) \ |
| 353 | for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \ |
| 354 | (dev) != protocol_to_pnp_dev(&(protocol)->devices); \ |
| 355 | (dev) = protocol_to_pnp_dev((dev)->protocol_list.next)) |
| 356 | |
David Brownell | cbcdc1d | 2007-02-10 01:45:13 -0800 | [diff] [blame] | 357 | extern struct bus_type pnp_bus_type; |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | #if defined(CONFIG_PNP) |
| 360 | |
| 361 | /* device management */ |
| 362 | int pnp_register_protocol(struct pnp_protocol *protocol); |
| 363 | void pnp_unregister_protocol(struct pnp_protocol *protocol); |
| 364 | int pnp_add_device(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | int pnp_device_attach(struct pnp_dev *pnp_dev); |
| 366 | void pnp_device_detach(struct pnp_dev *pnp_dev); |
| 367 | extern struct list_head pnp_global; |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 368 | extern int pnp_platform_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | /* multidevice card support */ |
| 371 | int pnp_add_card(struct pnp_card *card); |
| 372 | void pnp_remove_card(struct pnp_card *card); |
| 373 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); |
| 374 | void pnp_remove_card_device(struct pnp_dev *dev); |
| 375 | int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 376 | struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, |
| 377 | const char *id, struct pnp_dev *from); |
| 378 | void pnp_release_card_device(struct pnp_dev *dev); |
| 379 | int pnp_register_card_driver(struct pnp_card_driver *drv); |
| 380 | void pnp_unregister_card_driver(struct pnp_card_driver *drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | extern struct list_head pnp_cards; |
| 382 | |
| 383 | /* resource management */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 384 | struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev); |
| 385 | struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, |
| 386 | int priority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data); |
| 388 | int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 389 | int pnp_register_port_resource(struct pnp_option *option, |
| 390 | struct pnp_port *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data); |
| 392 | void pnp_init_resource_table(struct pnp_resource_table *table); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 393 | int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, |
| 394 | int mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | int pnp_auto_config_dev(struct pnp_dev *dev); |
| 396 | int pnp_validate_config(struct pnp_dev *dev); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 397 | int pnp_start_dev(struct pnp_dev *dev); |
| 398 | int pnp_stop_dev(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | int pnp_activate_dev(struct pnp_dev *dev); |
| 400 | int pnp_disable_dev(struct pnp_dev *dev); |
Greg Kroah-Hartman | b60ba83 | 2006-06-12 17:07:07 -0700 | [diff] [blame] | 401 | void pnp_resource_change(struct resource *resource, resource_size_t start, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 402 | resource_size_t size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | /* protocol helpers */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 405 | int pnp_is_active(struct pnp_dev *dev); |
| 406 | int compare_pnp_id(struct pnp_id *pos, const char *id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev); |
| 408 | int pnp_register_driver(struct pnp_driver *drv); |
| 409 | void pnp_unregister_driver(struct pnp_driver *drv); |
| 410 | |
| 411 | #else |
| 412 | |
| 413 | /* device management */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 414 | static inline int pnp_register_protocol(struct pnp_protocol *protocol) |
| 415 | { |
| 416 | return -ENODEV; |
| 417 | } |
| 418 | static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) |
| 419 | { |
| 420 | } |
| 421 | static inline int pnp_init_device(struct pnp_dev *dev) |
| 422 | { |
| 423 | return -ENODEV; |
| 424 | } |
| 425 | static inline int pnp_add_device(struct pnp_dev *dev) |
| 426 | { |
| 427 | return -ENODEV; |
| 428 | } |
| 429 | static inline int pnp_device_attach(struct pnp_dev *pnp_dev) |
| 430 | { |
| 431 | return -ENODEV; |
| 432 | } |
| 433 | static inline void pnp_device_detach(struct pnp_dev *pnp_dev) |
| 434 | {; |
| 435 | } |
| 436 | |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 437 | #define pnp_platform_devices 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | /* multidevice card support */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 440 | static inline int pnp_add_card(struct pnp_card *card) |
| 441 | { |
| 442 | return -ENODEV; |
| 443 | } |
| 444 | static inline void pnp_remove_card(struct pnp_card *card) |
| 445 | {; |
| 446 | } |
| 447 | static inline int pnp_add_card_device(struct pnp_card *card, |
| 448 | struct pnp_dev *dev) |
| 449 | { |
| 450 | return -ENODEV; |
| 451 | } |
| 452 | static inline void pnp_remove_card_device(struct pnp_dev *dev) |
| 453 | {; |
| 454 | } |
| 455 | static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) |
| 456 | { |
| 457 | return -ENODEV; |
| 458 | } |
| 459 | static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link |
| 460 | *clink, const char *id, |
| 461 | struct pnp_dev *from) |
| 462 | { |
| 463 | return NULL; |
| 464 | } |
| 465 | static inline void pnp_release_card_device(struct pnp_dev *dev) |
| 466 | {; |
| 467 | } |
| 468 | static inline int pnp_register_card_driver(struct pnp_card_driver *drv) |
| 469 | { |
| 470 | return -ENODEV; |
| 471 | } |
| 472 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) |
| 473 | {; |
| 474 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | /* resource management */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 477 | static inline struct pnp_option *pnp_register_independent_option(struct pnp_dev |
| 478 | *dev) |
| 479 | { |
| 480 | return NULL; |
| 481 | } |
| 482 | static inline struct pnp_option *pnp_register_dependent_option(struct pnp_dev |
| 483 | *dev, |
| 484 | int priority) |
| 485 | { |
| 486 | return NULL; |
| 487 | } |
| 488 | static inline int pnp_register_irq_resource(struct pnp_option *option, |
| 489 | struct pnp_irq *data) |
| 490 | { |
| 491 | return -ENODEV; |
| 492 | } |
| 493 | static inline int pnp_register_dma_resource(struct pnp_option *option, |
| 494 | struct pnp_dma *data) |
| 495 | { |
| 496 | return -ENODEV; |
| 497 | } |
| 498 | static inline int pnp_register_port_resource(struct pnp_option *option, |
| 499 | struct pnp_port *data) |
| 500 | { |
| 501 | return -ENODEV; |
| 502 | } |
| 503 | static inline int pnp_register_mem_resource(struct pnp_option *option, |
| 504 | struct pnp_mem *data) |
| 505 | { |
| 506 | return -ENODEV; |
| 507 | } |
| 508 | static inline void pnp_init_resource_table(struct pnp_resource_table *table) |
| 509 | { |
| 510 | } |
| 511 | static inline int pnp_manual_config_dev(struct pnp_dev *dev, |
| 512 | struct pnp_resource_table *res, |
| 513 | int mode) |
| 514 | { |
| 515 | return -ENODEV; |
| 516 | } |
| 517 | static inline int pnp_auto_config_dev(struct pnp_dev *dev) |
| 518 | { |
| 519 | return -ENODEV; |
| 520 | } |
| 521 | static inline int pnp_validate_config(struct pnp_dev *dev) |
| 522 | { |
| 523 | return -ENODEV; |
| 524 | } |
| 525 | static inline int pnp_start_dev(struct pnp_dev *dev) |
| 526 | { |
| 527 | return -ENODEV; |
| 528 | } |
| 529 | static inline int pnp_stop_dev(struct pnp_dev *dev) |
| 530 | { |
| 531 | return -ENODEV; |
| 532 | } |
| 533 | static inline int pnp_activate_dev(struct pnp_dev *dev) |
| 534 | { |
| 535 | return -ENODEV; |
| 536 | } |
| 537 | static inline int pnp_disable_dev(struct pnp_dev *dev) |
| 538 | { |
| 539 | return -ENODEV; |
| 540 | } |
Greg Kroah-Hartman | b60ba83 | 2006-06-12 17:07:07 -0700 | [diff] [blame] | 541 | static inline void pnp_resource_change(struct resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 542 | resource_size_t start, |
| 543 | resource_size_t size) |
| 544 | { |
| 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* protocol helpers */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 548 | static inline int pnp_is_active(struct pnp_dev *dev) |
| 549 | { |
| 550 | return 0; |
| 551 | } |
| 552 | static inline int compare_pnp_id(struct pnp_id *pos, const char *id) |
| 553 | { |
| 554 | return -ENODEV; |
| 555 | } |
| 556 | static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) |
| 557 | { |
| 558 | return -ENODEV; |
| 559 | } |
| 560 | static inline int pnp_register_driver(struct pnp_driver *drv) |
| 561 | { |
| 562 | return -ENODEV; |
| 563 | } |
| 564 | static inline void pnp_unregister_driver(struct pnp_driver *drv) |
| 565 | {; |
| 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | #endif /* CONFIG_PNP */ |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg) |
| 571 | #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg) |
| 572 | #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg) |
| 573 | |
Bjorn Helgaas | e139aa5 | 2005-09-06 15:17:05 -0700 | [diff] [blame] | 574 | #ifdef CONFIG_PNP_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg) |
| 576 | #else |
| 577 | #define pnp_dbg(format, arg...) do {} while (0) |
| 578 | #endif |
| 579 | |
| 580 | #endif /* __KERNEL__ */ |
| 581 | |
| 582 | #endif /* _LINUX_PNP_H */ |