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