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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* |
Joe Perches | fd3f898 | 2008-02-03 17:45:46 +0200 | [diff] [blame] | 186 | * Device Management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | */ |
| 188 | |
| 189 | struct pnp_card { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 190 | struct device dev; /* Driver Model device interface */ |
| 191 | unsigned char number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | struct list_head global_list; /* node in global list of cards */ |
| 193 | struct list_head protocol_list; /* node in protocol's list of cards */ |
| 194 | struct list_head devices; /* devices attached to the card */ |
| 195 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 196 | struct pnp_protocol *protocol; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 197 | struct pnp_id *id; /* contains supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 200 | unsigned char pnpver; /* Plug & Play version */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 201 | unsigned char productver; /* product version */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 202 | unsigned int serial; /* serial number */ |
| 203 | unsigned char checksum; /* if zero - checksum passed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */ |
| 205 | }; |
| 206 | |
| 207 | #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list) |
| 208 | #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list) |
| 209 | #define to_pnp_card(n) container_of(n, struct pnp_card, dev) |
| 210 | #define pnp_for_each_card(card) \ |
| 211 | for((card) = global_to_pnp_card(pnp_cards.next); \ |
| 212 | (card) != global_to_pnp_card(&pnp_cards); \ |
| 213 | (card) = global_to_pnp_card((card)->global_list.next)) |
| 214 | |
| 215 | struct pnp_card_link { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 216 | struct pnp_card *card; |
| 217 | struct pnp_card_driver *driver; |
| 218 | void *driver_data; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 219 | pm_message_t pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 222 | static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
| 224 | return pcard->driver_data; |
| 225 | } |
| 226 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 227 | 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] | 228 | { |
| 229 | pcard->driver_data = data; |
| 230 | } |
| 231 | |
| 232 | struct pnp_dev { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 233 | struct device dev; /* Driver Model device interface */ |
David Brownell | 2e17c55 | 2007-05-08 00:25:29 -0700 | [diff] [blame] | 234 | u64 dma_mask; |
Bjorn Helgaas | 544451a | 2008-04-10 21:29:28 -0700 | [diff] [blame] | 235 | unsigned int number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | int status; |
| 237 | |
| 238 | struct list_head global_list; /* node in global list of devices */ |
| 239 | struct list_head protocol_list; /* node in list of device's protocol */ |
| 240 | struct list_head card_list; /* node in card's list of devices */ |
| 241 | struct list_head rdev_list; /* node in cards list of requested devices */ |
| 242 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 243 | struct pnp_protocol *protocol; |
| 244 | struct pnp_card *card; /* card the device is attached to, none if NULL */ |
| 245 | struct pnp_driver *driver; |
| 246 | struct pnp_card_link *card_link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 248 | struct pnp_id *id; /* supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | int active; |
| 251 | int capabilities; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 252 | struct pnp_option *independent; |
| 253 | struct pnp_option *dependent; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 254 | struct list_head resources; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 257 | int flags; /* used by protocols */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */ |
| 259 | void *data; |
| 260 | }; |
| 261 | |
| 262 | #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list) |
| 263 | #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list) |
| 264 | #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list) |
| 265 | #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev) |
| 266 | #define pnp_for_each_dev(dev) \ |
| 267 | for((dev) = global_to_pnp_dev(pnp_global.next); \ |
| 268 | (dev) != global_to_pnp_dev(&pnp_global); \ |
| 269 | (dev) = global_to_pnp_dev((dev)->global_list.next)) |
| 270 | #define card_for_each_dev(card,dev) \ |
| 271 | for((dev) = card_to_pnp_dev((card)->devices.next); \ |
| 272 | (dev) != card_to_pnp_dev(&(card)->devices); \ |
| 273 | (dev) = card_to_pnp_dev((dev)->card_list.next)) |
| 274 | #define pnp_dev_name(dev) (dev)->name |
| 275 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 276 | static inline void *pnp_get_drvdata(struct pnp_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | return dev_get_drvdata(&pdev->dev); |
| 279 | } |
| 280 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 281 | static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
| 283 | dev_set_drvdata(&pdev->dev, data); |
| 284 | } |
| 285 | |
| 286 | struct pnp_fixup { |
| 287 | char id[7]; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 288 | void (*quirk_function) (struct pnp_dev * dev); /* fixup function */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | /* config parameters */ |
| 292 | #define PNP_CONFIG_NORMAL 0x0001 |
| 293 | #define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */ |
| 294 | |
| 295 | /* capabilities */ |
| 296 | #define PNP_READ 0x0001 |
| 297 | #define PNP_WRITE 0x0002 |
| 298 | #define PNP_DISABLE 0x0004 |
| 299 | #define PNP_CONFIGURABLE 0x0008 |
| 300 | #define PNP_REMOVABLE 0x0010 |
| 301 | |
Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 302 | #define pnp_can_read(dev) (((dev)->protocol->get) && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | ((dev)->capabilities & PNP_READ)) |
Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 304 | #define pnp_can_write(dev) (((dev)->protocol->set) && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | ((dev)->capabilities & PNP_WRITE)) |
Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 306 | #define pnp_can_disable(dev) (((dev)->protocol->disable) && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | ((dev)->capabilities & PNP_DISABLE)) |
| 308 | #define pnp_can_configure(dev) ((!(dev)->active) && \ |
| 309 | ((dev)->capabilities & PNP_CONFIGURABLE)) |
| 310 | |
| 311 | #ifdef CONFIG_ISAPNP |
| 312 | extern struct pnp_protocol isapnp_protocol; |
| 313 | #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol)) |
| 314 | #else |
| 315 | #define pnp_device_is_isapnp(dev) 0 |
| 316 | #endif |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 317 | extern struct mutex pnp_res_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | #ifdef CONFIG_PNPBIOS |
| 320 | extern struct pnp_protocol pnpbios_protocol; |
| 321 | #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol)) |
| 322 | #else |
| 323 | #define pnp_device_is_pnpbios(dev) 0 |
| 324 | #endif |
| 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | /* status */ |
| 327 | #define PNP_READY 0x0000 |
| 328 | #define PNP_ATTACHED 0x0001 |
| 329 | #define PNP_BUSY 0x0002 |
| 330 | #define PNP_FAULTY 0x0004 |
| 331 | |
| 332 | /* isapnp specific macros */ |
| 333 | |
| 334 | #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1) |
| 335 | #define isapnp_csn_number(dev) ((dev)->number) |
| 336 | |
| 337 | /* |
| 338 | * Driver Management |
| 339 | */ |
| 340 | |
| 341 | struct pnp_id { |
| 342 | char id[PNP_ID_LEN]; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 343 | struct pnp_id *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | struct pnp_driver { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 347 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | const struct pnp_device_id *id_table; |
| 349 | unsigned int flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 350 | int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id); |
| 351 | void (*remove) (struct pnp_dev *dev); |
| 352 | int (*suspend) (struct pnp_dev *dev, pm_message_t state); |
| 353 | int (*resume) (struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | struct device_driver driver; |
| 355 | }; |
| 356 | |
| 357 | #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver) |
| 358 | |
| 359 | struct pnp_card_driver { |
| 360 | struct list_head global_list; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 361 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | const struct pnp_card_device_id *id_table; |
| 363 | unsigned int flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 364 | int (*probe) (struct pnp_card_link *card, |
| 365 | const struct pnp_card_device_id *card_id); |
| 366 | void (*remove) (struct pnp_card_link *card); |
| 367 | int (*suspend) (struct pnp_card_link *card, pm_message_t state); |
| 368 | int (*resume) (struct pnp_card_link *card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | struct pnp_driver link; |
| 370 | }; |
| 371 | |
| 372 | #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link) |
| 373 | |
| 374 | /* pnp driver flags */ |
| 375 | #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */ |
| 376 | #define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */ |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* |
| 379 | * Protocol Management |
| 380 | */ |
| 381 | |
| 382 | struct pnp_protocol { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 383 | struct list_head protocol_list; |
| 384 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | /* resource control functions */ |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 387 | int (*get) (struct pnp_dev *dev); |
| 388 | int (*set) (struct pnp_dev *dev); |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 389 | int (*disable) (struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 391 | /* protocol specific suspend/resume */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 392 | int (*suspend) (struct pnp_dev * dev, pm_message_t state); |
| 393 | int (*resume) (struct pnp_dev * dev); |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* used by pnp layer only (look but don't touch) */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 396 | unsigned char number; /* protocol number */ |
| 397 | struct device dev; /* link to driver model */ |
| 398 | struct list_head cards; |
| 399 | struct list_head devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list) |
| 403 | #define protocol_for_each_card(protocol,card) \ |
| 404 | for((card) = protocol_to_pnp_card((protocol)->cards.next); \ |
| 405 | (card) != protocol_to_pnp_card(&(protocol)->cards); \ |
| 406 | (card) = protocol_to_pnp_card((card)->protocol_list.next)) |
| 407 | #define protocol_for_each_dev(protocol,dev) \ |
| 408 | for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \ |
| 409 | (dev) != protocol_to_pnp_dev(&(protocol)->devices); \ |
| 410 | (dev) = protocol_to_pnp_dev((dev)->protocol_list.next)) |
| 411 | |
David Brownell | cbcdc1d | 2007-02-10 01:45:13 -0800 | [diff] [blame] | 412 | extern struct bus_type pnp_bus_type; |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | #if defined(CONFIG_PNP) |
| 415 | |
| 416 | /* device management */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | int pnp_device_attach(struct pnp_dev *pnp_dev); |
| 418 | void pnp_device_detach(struct pnp_dev *pnp_dev); |
| 419 | extern struct list_head pnp_global; |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 420 | extern int pnp_platform_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | /* multidevice card support */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 423 | struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, |
| 424 | const char *id, struct pnp_dev *from); |
| 425 | void pnp_release_card_device(struct pnp_dev *dev); |
| 426 | int pnp_register_card_driver(struct pnp_card_driver *drv); |
| 427 | void pnp_unregister_card_driver(struct pnp_card_driver *drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | extern struct list_head pnp_cards; |
| 429 | |
| 430 | /* resource management */ |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 431 | int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base, |
| 432 | resource_size_t size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | int pnp_auto_config_dev(struct pnp_dev *dev); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 434 | int pnp_start_dev(struct pnp_dev *dev); |
| 435 | int pnp_stop_dev(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | int pnp_activate_dev(struct pnp_dev *dev); |
| 437 | int pnp_disable_dev(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | /* protocol helpers */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 440 | int pnp_is_active(struct pnp_dev *dev); |
| 441 | int compare_pnp_id(struct pnp_id *pos, const char *id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | int pnp_register_driver(struct pnp_driver *drv); |
| 443 | void pnp_unregister_driver(struct pnp_driver *drv); |
| 444 | |
| 445 | #else |
| 446 | |
| 447 | /* device management */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 448 | static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } |
| 449 | static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 450 | |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 451 | #define pnp_platform_devices 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | /* multidevice card support */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 454 | static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; } |
| 455 | static inline void pnp_release_card_device(struct pnp_dev *dev) { } |
| 456 | static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; } |
| 457 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | /* resource management */ |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 460 | static inline int pnp_possible_config(struct pnp_dev *dev, int type, |
| 461 | resource_size_t base, |
| 462 | resource_size_t size) { return 0; } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 463 | 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] | 464 | static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 465 | static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 466 | static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 467 | static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | /* protocol helpers */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 470 | static inline int pnp_is_active(struct pnp_dev *dev) { return 0; } |
| 471 | 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] | 472 | static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; } |
| 473 | static inline void pnp_unregister_driver(struct pnp_driver *drv) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | #endif /* CONFIG_PNP */ |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg) |
| 478 | #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg) |
| 479 | #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg) |
| 480 | |
Bjorn Helgaas | e139aa5 | 2005-09-06 15:17:05 -0700 | [diff] [blame] | 481 | #ifdef CONFIG_PNP_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg) |
| 483 | #else |
| 484 | #define pnp_dbg(format, arg...) do {} while (0) |
| 485 | #endif |
| 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | #endif /* _LINUX_PNP_H */ |