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