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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #define PNP_NAME_LEN 50 |
| 17 | |
| 18 | struct pnp_protocol; |
| 19 | struct pnp_dev; |
Bjorn Helgaas | 02d83b5 | 2008-04-28 16:34:28 -0600 | [diff] [blame^] | 20 | struct pnp_resource_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* |
| 23 | * Resource Management |
| 24 | */ |
Bjorn Helgaas | b90eca0 | 2008-04-28 16:34:14 -0600 | [diff] [blame] | 25 | struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 27 | static inline int pnp_resource_valid(struct resource *res) |
| 28 | { |
| 29 | if (res && !(res->flags & IORESOURCE_UNSET)) |
| 30 | return 1; |
| 31 | return 0; |
| 32 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 34 | static inline resource_size_t pnp_resource_len(struct resource *res) |
| 35 | { |
| 36 | if (res->start == 0 && res->end == 0) |
| 37 | return 0; |
| 38 | return res->end - res->start + 1; |
| 39 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 42 | static inline resource_size_t pnp_port_start(struct pnp_dev *dev, |
| 43 | unsigned int bar) |
| 44 | { |
| 45 | return pnp_get_resource(dev, IORESOURCE_IO, bar)->start; |
| 46 | } |
| 47 | |
| 48 | static inline resource_size_t pnp_port_end(struct pnp_dev *dev, |
| 49 | unsigned int bar) |
| 50 | { |
| 51 | return pnp_get_resource(dev, IORESOURCE_IO, bar)->end; |
| 52 | } |
| 53 | |
| 54 | static inline unsigned long pnp_port_flags(struct pnp_dev *dev, |
| 55 | unsigned int bar) |
| 56 | { |
| 57 | return pnp_get_resource(dev, IORESOURCE_IO, bar)->flags; |
| 58 | } |
| 59 | |
| 60 | static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar) |
| 61 | { |
| 62 | return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar)); |
| 63 | } |
| 64 | |
| 65 | static inline resource_size_t pnp_port_len(struct pnp_dev *dev, |
| 66 | unsigned int bar) |
| 67 | { |
| 68 | return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_IO, bar)); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | static inline resource_size_t pnp_mem_start(struct pnp_dev *dev, |
| 73 | unsigned int bar) |
| 74 | { |
| 75 | return pnp_get_resource(dev, IORESOURCE_MEM, bar)->start; |
| 76 | } |
| 77 | |
| 78 | static inline resource_size_t pnp_mem_end(struct pnp_dev *dev, |
| 79 | unsigned int bar) |
| 80 | { |
| 81 | return pnp_get_resource(dev, IORESOURCE_MEM, bar)->end; |
| 82 | } |
| 83 | |
| 84 | static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar) |
| 85 | { |
| 86 | return pnp_get_resource(dev, IORESOURCE_MEM, bar)->flags; |
| 87 | } |
| 88 | |
| 89 | static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar) |
| 90 | { |
| 91 | return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar)); |
| 92 | } |
| 93 | |
| 94 | static inline resource_size_t pnp_mem_len(struct pnp_dev *dev, |
| 95 | unsigned int bar) |
| 96 | { |
| 97 | return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_MEM, bar)); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar) |
| 102 | { |
| 103 | return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->start; |
| 104 | } |
| 105 | |
| 106 | static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar) |
| 107 | { |
| 108 | return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->flags; |
| 109 | } |
| 110 | |
| 111 | static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar) |
| 112 | { |
| 113 | return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar)); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar) |
| 118 | { |
| 119 | return pnp_get_resource(dev, IORESOURCE_DMA, bar)->start; |
| 120 | } |
| 121 | |
| 122 | static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar) |
| 123 | { |
| 124 | return pnp_get_resource(dev, IORESOURCE_DMA, bar)->flags; |
| 125 | } |
| 126 | |
| 127 | static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar) |
| 128 | { |
| 129 | return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar)); |
| 130 | } |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | #define PNP_PORT_FLAG_16BITADDR (1<<0) |
| 134 | #define PNP_PORT_FLAG_FIXED (1<<1) |
| 135 | |
| 136 | struct pnp_port { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 137 | unsigned short min; /* min base number */ |
| 138 | unsigned short max; /* max base number */ |
| 139 | unsigned char align; /* align boundary */ |
| 140 | unsigned char size; /* size of range */ |
| 141 | unsigned char flags; /* port flags */ |
| 142 | unsigned char pad; /* pad */ |
| 143 | struct pnp_port *next; /* next port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | #define PNP_IRQ_NR 256 |
| 147 | struct pnp_irq { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 148 | DECLARE_BITMAP(map, PNP_IRQ_NR); /* bitmask for IRQ lines */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 149 | unsigned char flags; /* IRQ flags */ |
| 150 | unsigned char pad; /* pad */ |
| 151 | struct pnp_irq *next; /* next IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct pnp_dma { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 155 | unsigned char map; /* bitmask for DMA channels */ |
| 156 | unsigned char flags; /* DMA flags */ |
| 157 | struct pnp_dma *next; /* next port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct pnp_mem { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 161 | unsigned int min; /* min base number */ |
| 162 | unsigned int max; /* max base number */ |
| 163 | unsigned int align; /* align boundary */ |
| 164 | unsigned int size; /* size of range */ |
| 165 | unsigned char flags; /* memory flags */ |
| 166 | unsigned char pad; /* pad */ |
| 167 | struct pnp_mem *next; /* next memory resource */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | #define PNP_RES_PRIORITY_PREFERRED 0 |
| 171 | #define PNP_RES_PRIORITY_ACCEPTABLE 1 |
| 172 | #define PNP_RES_PRIORITY_FUNCTIONAL 2 |
| 173 | #define PNP_RES_PRIORITY_INVALID 65535 |
| 174 | |
| 175 | struct pnp_option { |
| 176 | unsigned short priority; /* priority */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 177 | struct pnp_port *port; /* first port */ |
| 178 | struct pnp_irq *irq; /* first IRQ */ |
| 179 | struct pnp_dma *dma; /* first DMA */ |
| 180 | struct pnp_mem *mem; /* first memory resource */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | struct pnp_option *next; /* used to chain dependent resources */ |
| 182 | }; |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /* |
Joe Perches | fd3f898 | 2008-02-03 17:45:46 +0200 | [diff] [blame] | 185 | * Device Management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | */ |
| 187 | |
| 188 | struct pnp_card { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 189 | struct device dev; /* Driver Model device interface */ |
| 190 | unsigned char number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | struct list_head global_list; /* node in global list of cards */ |
| 192 | struct list_head protocol_list; /* node in protocol's list of cards */ |
| 193 | struct list_head devices; /* devices attached to the card */ |
| 194 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 195 | struct pnp_protocol *protocol; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 196 | struct pnp_id *id; /* contains supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 199 | unsigned char pnpver; /* Plug & Play version */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 200 | unsigned char productver; /* product version */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 201 | unsigned int serial; /* serial number */ |
| 202 | unsigned char checksum; /* if zero - checksum passed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */ |
| 204 | }; |
| 205 | |
| 206 | #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list) |
| 207 | #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list) |
| 208 | #define to_pnp_card(n) container_of(n, struct pnp_card, dev) |
| 209 | #define pnp_for_each_card(card) \ |
| 210 | for((card) = global_to_pnp_card(pnp_cards.next); \ |
| 211 | (card) != global_to_pnp_card(&pnp_cards); \ |
| 212 | (card) = global_to_pnp_card((card)->global_list.next)) |
| 213 | |
| 214 | struct pnp_card_link { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 215 | struct pnp_card *card; |
| 216 | struct pnp_card_driver *driver; |
| 217 | void *driver_data; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 218 | pm_message_t pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 221 | static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | return pcard->driver_data; |
| 224 | } |
| 225 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 226 | 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] | 227 | { |
| 228 | pcard->driver_data = data; |
| 229 | } |
| 230 | |
| 231 | struct pnp_dev { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 232 | struct device dev; /* Driver Model device interface */ |
David Brownell | 2e17c55 | 2007-05-08 00:25:29 -0700 | [diff] [blame] | 233 | u64 dma_mask; |
Bjorn Helgaas | 544451a | 2008-04-10 21:29:28 -0700 | [diff] [blame] | 234 | unsigned int number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | int status; |
| 236 | |
| 237 | struct list_head global_list; /* node in global list of devices */ |
| 238 | struct list_head protocol_list; /* node in list of device's protocol */ |
| 239 | struct list_head card_list; /* node in card's list of devices */ |
| 240 | struct list_head rdev_list; /* node in cards list of requested devices */ |
| 241 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 242 | struct pnp_protocol *protocol; |
| 243 | struct pnp_card *card; /* card the device is attached to, none if NULL */ |
| 244 | struct pnp_driver *driver; |
| 245 | struct pnp_card_link *card_link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 247 | struct pnp_id *id; /* supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | int active; |
| 250 | int capabilities; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 251 | struct pnp_option *independent; |
| 252 | struct pnp_option *dependent; |
Bjorn Helgaas | 02d83b5 | 2008-04-28 16:34:28 -0600 | [diff] [blame^] | 253 | struct pnp_resource_table *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 256 | unsigned short regs; /* ISAPnP: supported registers */ |
| 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 */ |
| 417 | int pnp_register_protocol(struct pnp_protocol *protocol); |
| 418 | void pnp_unregister_protocol(struct pnp_protocol *protocol); |
| 419 | int pnp_add_device(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | int pnp_device_attach(struct pnp_dev *pnp_dev); |
| 421 | void pnp_device_detach(struct pnp_dev *pnp_dev); |
| 422 | extern struct list_head pnp_global; |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 423 | extern int pnp_platform_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | /* multidevice card support */ |
| 426 | int pnp_add_card(struct pnp_card *card); |
| 427 | void pnp_remove_card(struct pnp_card *card); |
| 428 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); |
| 429 | void pnp_remove_card_device(struct pnp_dev *dev); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 430 | struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, |
| 431 | const char *id, struct pnp_dev *from); |
| 432 | void pnp_release_card_device(struct pnp_dev *dev); |
| 433 | int pnp_register_card_driver(struct pnp_card_driver *drv); |
| 434 | void pnp_unregister_card_driver(struct pnp_card_driver *drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | extern struct list_head pnp_cards; |
| 436 | |
| 437 | /* resource management */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 438 | struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev); |
| 439 | struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, |
| 440 | int priority); |
Bjorn Helgaas | c1caf06 | 2008-04-28 16:34:04 -0600 | [diff] [blame] | 441 | int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, |
| 442 | struct pnp_irq *data); |
| 443 | int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, |
| 444 | struct pnp_dma *data); |
| 445 | 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] | 446 | struct pnp_port *data); |
Bjorn Helgaas | c1caf06 | 2008-04-28 16:34:04 -0600 | [diff] [blame] | 447 | int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, |
| 448 | struct pnp_mem *data); |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 449 | void pnp_init_resources(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | int pnp_auto_config_dev(struct pnp_dev *dev); |
| 451 | int pnp_validate_config(struct pnp_dev *dev); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 452 | int pnp_start_dev(struct pnp_dev *dev); |
| 453 | int pnp_stop_dev(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | int pnp_activate_dev(struct pnp_dev *dev); |
| 455 | int pnp_disable_dev(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
| 457 | /* protocol helpers */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 458 | int pnp_is_active(struct pnp_dev *dev); |
| 459 | int compare_pnp_id(struct pnp_id *pos, const char *id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | int pnp_register_driver(struct pnp_driver *drv); |
| 461 | void pnp_unregister_driver(struct pnp_driver *drv); |
| 462 | |
| 463 | #else |
| 464 | |
| 465 | /* device management */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 466 | static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; } |
| 467 | static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { } |
| 468 | static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; } |
| 469 | static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; } |
| 470 | static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } |
| 471 | static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 472 | |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 473 | #define pnp_platform_devices 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* multidevice card support */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 476 | static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; } |
| 477 | static inline void pnp_remove_card(struct pnp_card *card) { } |
| 478 | static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; } |
| 479 | static inline void pnp_remove_card_device(struct pnp_dev *dev) { } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 480 | static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; } |
| 481 | static inline void pnp_release_card_device(struct pnp_dev *dev) { } |
| 482 | static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; } |
| 483 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | /* resource management */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 486 | static inline struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev) { return NULL; } |
| 487 | 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] | 488 | static inline int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; } |
| 489 | static inline int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; } |
| 490 | static inline int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, struct pnp_port *data) { return -ENODEV; } |
| 491 | 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] | 492 | static inline void pnp_init_resources(struct pnp_dev *dev) { } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 493 | static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 494 | static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; } |
| 495 | static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 496 | static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 497 | static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 498 | static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | /* protocol helpers */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 501 | static inline int pnp_is_active(struct pnp_dev *dev) { return 0; } |
| 502 | 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] | 503 | static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; } |
| 504 | static inline void pnp_unregister_driver(struct pnp_driver *drv) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | #endif /* CONFIG_PNP */ |
| 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg) |
| 509 | #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg) |
| 510 | #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg) |
| 511 | |
Bjorn Helgaas | e139aa5 | 2005-09-06 15:17:05 -0700 | [diff] [blame] | 512 | #ifdef CONFIG_PNP_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg) |
| 514 | #else |
| 515 | #define pnp_dbg(format, arg...) do {} while (0) |
| 516 | #endif |
| 517 | |
| 518 | #endif /* __KERNEL__ */ |
| 519 | |
| 520 | #endif /* _LINUX_PNP_H */ |