usb-serial: Add ThinkOptics WavIT
[linux-2.6/openmoko-kernel/knife-kernel.git] / include / linux / pnp.h
blob63b128d512fb5f413085b8b13d144d97cf41477f
1 /*
2 * Linux Plug and Play Support
3 * Copyright by Adam Belay <ambx1@neo.rr.com>
4 */
6 #ifndef _LINUX_PNP_H
7 #define _LINUX_PNP_H
9 #include <linux/device.h>
10 #include <linux/list.h>
11 #include <linux/errno.h>
12 #include <linux/mod_devicetable.h>
14 #define PNP_NAME_LEN 50
16 struct pnp_protocol;
17 struct pnp_dev;
18 struct pnp_resource_table;
21 * Resource Management
23 struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
25 static inline int pnp_resource_valid(struct resource *res)
27 if (res && !(res->flags & IORESOURCE_UNSET))
28 return 1;
29 return 0;
32 static inline resource_size_t pnp_resource_len(struct resource *res)
34 if (res->start == 0 && res->end == 0)
35 return 0;
36 return res->end - res->start + 1;
40 static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
41 unsigned int bar)
43 return pnp_get_resource(dev, IORESOURCE_IO, bar)->start;
46 static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
47 unsigned int bar)
49 return pnp_get_resource(dev, IORESOURCE_IO, bar)->end;
52 static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
53 unsigned int bar)
55 return pnp_get_resource(dev, IORESOURCE_IO, bar)->flags;
58 static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
60 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
63 static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
64 unsigned int bar)
66 return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_IO, bar));
70 static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
71 unsigned int bar)
73 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->start;
76 static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
77 unsigned int bar)
79 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->end;
82 static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
84 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->flags;
87 static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
89 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
92 static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
93 unsigned int bar)
95 return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_MEM, bar));
99 static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
101 return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->start;
104 static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
106 return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->flags;
109 static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
111 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
115 static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
117 return pnp_get_resource(dev, IORESOURCE_DMA, bar)->start;
120 static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
122 return pnp_get_resource(dev, IORESOURCE_DMA, bar)->flags;
125 static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
127 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
131 #define PNP_PORT_FLAG_16BITADDR (1<<0)
132 #define PNP_PORT_FLAG_FIXED (1<<1)
134 struct pnp_port {
135 unsigned short min; /* min base number */
136 unsigned short max; /* max base number */
137 unsigned char align; /* align boundary */
138 unsigned char size; /* size of range */
139 unsigned char flags; /* port flags */
140 unsigned char pad; /* pad */
141 struct pnp_port *next; /* next port */
144 #define PNP_IRQ_NR 256
145 struct pnp_irq {
146 DECLARE_BITMAP(map, PNP_IRQ_NR); /* bitmask for IRQ lines */
147 unsigned char flags; /* IRQ flags */
148 unsigned char pad; /* pad */
149 struct pnp_irq *next; /* next IRQ */
152 struct pnp_dma {
153 unsigned char map; /* bitmask for DMA channels */
154 unsigned char flags; /* DMA flags */
155 struct pnp_dma *next; /* next port */
158 struct pnp_mem {
159 unsigned int min; /* min base number */
160 unsigned int max; /* max base number */
161 unsigned int align; /* align boundary */
162 unsigned int size; /* size of range */
163 unsigned char flags; /* memory flags */
164 unsigned char pad; /* pad */
165 struct pnp_mem *next; /* next memory resource */
168 #define PNP_RES_PRIORITY_PREFERRED 0
169 #define PNP_RES_PRIORITY_ACCEPTABLE 1
170 #define PNP_RES_PRIORITY_FUNCTIONAL 2
171 #define PNP_RES_PRIORITY_INVALID 65535
173 struct pnp_option {
174 unsigned short priority; /* priority */
175 struct pnp_port *port; /* first port */
176 struct pnp_irq *irq; /* first IRQ */
177 struct pnp_dma *dma; /* first DMA */
178 struct pnp_mem *mem; /* first memory resource */
179 struct pnp_option *next; /* used to chain dependent resources */
183 * Device Management
186 struct pnp_card {
187 struct device dev; /* Driver Model device interface */
188 unsigned char number; /* used as an index, must be unique */
189 struct list_head global_list; /* node in global list of cards */
190 struct list_head protocol_list; /* node in protocol's list of cards */
191 struct list_head devices; /* devices attached to the card */
193 struct pnp_protocol *protocol;
194 struct pnp_id *id; /* contains supported EISA IDs */
196 char name[PNP_NAME_LEN]; /* contains a human-readable name */
197 unsigned char pnpver; /* Plug & Play version */
198 unsigned char productver; /* product version */
199 unsigned int serial; /* serial number */
200 unsigned char checksum; /* if zero - checksum passed */
201 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */
204 #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
205 #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
206 #define to_pnp_card(n) container_of(n, struct pnp_card, dev)
207 #define pnp_for_each_card(card) \
208 for((card) = global_to_pnp_card(pnp_cards.next); \
209 (card) != global_to_pnp_card(&pnp_cards); \
210 (card) = global_to_pnp_card((card)->global_list.next))
212 struct pnp_card_link {
213 struct pnp_card *card;
214 struct pnp_card_driver *driver;
215 void *driver_data;
216 pm_message_t pm_state;
219 static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard)
221 return pcard->driver_data;
224 static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data)
226 pcard->driver_data = data;
229 struct pnp_dev {
230 struct device dev; /* Driver Model device interface */
231 u64 dma_mask;
232 unsigned int number; /* used as an index, must be unique */
233 int status;
235 struct list_head global_list; /* node in global list of devices */
236 struct list_head protocol_list; /* node in list of device's protocol */
237 struct list_head card_list; /* node in card's list of devices */
238 struct list_head rdev_list; /* node in cards list of requested devices */
240 struct pnp_protocol *protocol;
241 struct pnp_card *card; /* card the device is attached to, none if NULL */
242 struct pnp_driver *driver;
243 struct pnp_card_link *card_link;
245 struct pnp_id *id; /* supported EISA IDs */
247 int active;
248 int capabilities;
249 struct pnp_option *independent;
250 struct pnp_option *dependent;
251 struct pnp_resource_table *res;
253 char name[PNP_NAME_LEN]; /* contains a human-readable name */
254 int flags; /* used by protocols */
255 struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
256 void *data;
259 #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
260 #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
261 #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
262 #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
263 #define pnp_for_each_dev(dev) \
264 for((dev) = global_to_pnp_dev(pnp_global.next); \
265 (dev) != global_to_pnp_dev(&pnp_global); \
266 (dev) = global_to_pnp_dev((dev)->global_list.next))
267 #define card_for_each_dev(card,dev) \
268 for((dev) = card_to_pnp_dev((card)->devices.next); \
269 (dev) != card_to_pnp_dev(&(card)->devices); \
270 (dev) = card_to_pnp_dev((dev)->card_list.next))
271 #define pnp_dev_name(dev) (dev)->name
273 static inline void *pnp_get_drvdata(struct pnp_dev *pdev)
275 return dev_get_drvdata(&pdev->dev);
278 static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
280 dev_set_drvdata(&pdev->dev, data);
283 struct pnp_fixup {
284 char id[7];
285 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
288 /* config parameters */
289 #define PNP_CONFIG_NORMAL 0x0001
290 #define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */
292 /* capabilities */
293 #define PNP_READ 0x0001
294 #define PNP_WRITE 0x0002
295 #define PNP_DISABLE 0x0004
296 #define PNP_CONFIGURABLE 0x0008
297 #define PNP_REMOVABLE 0x0010
299 #define pnp_can_read(dev) (((dev)->protocol->get) && \
300 ((dev)->capabilities & PNP_READ))
301 #define pnp_can_write(dev) (((dev)->protocol->set) && \
302 ((dev)->capabilities & PNP_WRITE))
303 #define pnp_can_disable(dev) (((dev)->protocol->disable) && \
304 ((dev)->capabilities & PNP_DISABLE))
305 #define pnp_can_configure(dev) ((!(dev)->active) && \
306 ((dev)->capabilities & PNP_CONFIGURABLE))
308 #ifdef CONFIG_ISAPNP
309 extern struct pnp_protocol isapnp_protocol;
310 #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
311 #else
312 #define pnp_device_is_isapnp(dev) 0
313 #endif
314 extern struct mutex pnp_res_mutex;
316 #ifdef CONFIG_PNPBIOS
317 extern struct pnp_protocol pnpbios_protocol;
318 #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
319 #else
320 #define pnp_device_is_pnpbios(dev) 0
321 #endif
323 /* status */
324 #define PNP_READY 0x0000
325 #define PNP_ATTACHED 0x0001
326 #define PNP_BUSY 0x0002
327 #define PNP_FAULTY 0x0004
329 /* isapnp specific macros */
331 #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
332 #define isapnp_csn_number(dev) ((dev)->number)
335 * Driver Management
338 struct pnp_id {
339 char id[PNP_ID_LEN];
340 struct pnp_id *next;
343 struct pnp_driver {
344 char *name;
345 const struct pnp_device_id *id_table;
346 unsigned int flags;
347 int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
348 void (*remove) (struct pnp_dev *dev);
349 int (*suspend) (struct pnp_dev *dev, pm_message_t state);
350 int (*resume) (struct pnp_dev *dev);
351 struct device_driver driver;
354 #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
356 struct pnp_card_driver {
357 struct list_head global_list;
358 char *name;
359 const struct pnp_card_device_id *id_table;
360 unsigned int flags;
361 int (*probe) (struct pnp_card_link *card,
362 const struct pnp_card_device_id *card_id);
363 void (*remove) (struct pnp_card_link *card);
364 int (*suspend) (struct pnp_card_link *card, pm_message_t state);
365 int (*resume) (struct pnp_card_link *card);
366 struct pnp_driver link;
369 #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
371 /* pnp driver flags */
372 #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */
373 #define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */
376 * Protocol Management
379 struct pnp_protocol {
380 struct list_head protocol_list;
381 char *name;
383 /* resource control functions */
384 int (*get) (struct pnp_dev *dev);
385 int (*set) (struct pnp_dev *dev);
386 int (*disable) (struct pnp_dev *dev);
388 /* protocol specific suspend/resume */
389 int (*suspend) (struct pnp_dev * dev, pm_message_t state);
390 int (*resume) (struct pnp_dev * dev);
392 /* used by pnp layer only (look but don't touch) */
393 unsigned char number; /* protocol number */
394 struct device dev; /* link to driver model */
395 struct list_head cards;
396 struct list_head devices;
399 #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
400 #define protocol_for_each_card(protocol,card) \
401 for((card) = protocol_to_pnp_card((protocol)->cards.next); \
402 (card) != protocol_to_pnp_card(&(protocol)->cards); \
403 (card) = protocol_to_pnp_card((card)->protocol_list.next))
404 #define protocol_for_each_dev(protocol,dev) \
405 for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
406 (dev) != protocol_to_pnp_dev(&(protocol)->devices); \
407 (dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
409 extern struct bus_type pnp_bus_type;
411 #if defined(CONFIG_PNP)
413 /* device management */
414 int pnp_device_attach(struct pnp_dev *pnp_dev);
415 void pnp_device_detach(struct pnp_dev *pnp_dev);
416 extern struct list_head pnp_global;
417 extern int pnp_platform_devices;
419 /* multidevice card support */
420 struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
421 const char *id, struct pnp_dev *from);
422 void pnp_release_card_device(struct pnp_dev *dev);
423 int pnp_register_card_driver(struct pnp_card_driver *drv);
424 void pnp_unregister_card_driver(struct pnp_card_driver *drv);
425 extern struct list_head pnp_cards;
427 /* resource management */
428 int pnp_auto_config_dev(struct pnp_dev *dev);
429 int pnp_start_dev(struct pnp_dev *dev);
430 int pnp_stop_dev(struct pnp_dev *dev);
431 int pnp_activate_dev(struct pnp_dev *dev);
432 int pnp_disable_dev(struct pnp_dev *dev);
434 /* protocol helpers */
435 int pnp_is_active(struct pnp_dev *dev);
436 int compare_pnp_id(struct pnp_id *pos, const char *id);
437 int pnp_register_driver(struct pnp_driver *drv);
438 void pnp_unregister_driver(struct pnp_driver *drv);
440 #else
442 /* device management */
443 static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
444 static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
446 #define pnp_platform_devices 0
448 /* multidevice card support */
449 static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
450 static inline void pnp_release_card_device(struct pnp_dev *dev) { }
451 static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
452 static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
454 /* resource management */
455 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
456 static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
457 static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
458 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
459 static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
461 /* protocol helpers */
462 static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
463 static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
464 static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
465 static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
467 #endif /* CONFIG_PNP */
469 #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg)
470 #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg)
471 #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg)
473 #ifdef CONFIG_PNP_DEBUG
474 #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg)
475 #else
476 #define pnp_dbg(format, arg...) do {} while (0)
477 #endif
479 #endif /* _LINUX_PNP_H */