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