HID: move samsung quirks
[linux-2.6/mini2440.git] / include / linux / pnp.h
blobbe764e514e35946eeced5615440769912da9e0fa
1 /*
2 * Linux Plug and Play Support
3 * Copyright by Adam Belay <ambx1@neo.rr.com>
4 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
6 */
8 #ifndef _LINUX_PNP_H
9 #define _LINUX_PNP_H
11 #include <linux/device.h>
12 #include <linux/list.h>
13 #include <linux/errno.h>
14 #include <linux/mod_devicetable.h>
16 #define PNP_NAME_LEN 50
18 struct pnp_protocol;
19 struct pnp_dev;
22 * Resource Management
24 #ifdef CONFIG_PNP
25 struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
26 #else
27 static inline struct resource *pnp_get_resource(struct pnp_dev *dev, unsigned int type, unsigned int num)
29 return NULL;
31 #endif
33 static inline int pnp_resource_valid(struct resource *res)
35 if (res)
36 return 1;
37 return 0;
40 static inline int pnp_resource_enabled(struct resource *res)
42 if (res && !(res->flags & IORESOURCE_DISABLED))
43 return 1;
44 return 0;
47 static inline resource_size_t pnp_resource_len(struct resource *res)
49 if (res->start == 0 && res->end == 0)
50 return 0;
51 return res->end - res->start + 1;
55 static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
56 unsigned int bar)
58 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
60 if (pnp_resource_valid(res))
61 return res->start;
62 return 0;
65 static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
66 unsigned int bar)
68 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
70 if (pnp_resource_valid(res))
71 return res->end;
72 return 0;
75 static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
76 unsigned int bar)
78 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
80 if (pnp_resource_valid(res))
81 return res->flags;
82 return IORESOURCE_IO | IORESOURCE_AUTO;
85 static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
87 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
90 static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
91 unsigned int bar)
93 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
95 if (pnp_resource_valid(res))
96 return pnp_resource_len(res);
97 return 0;
101 static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
102 unsigned int bar)
104 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
106 if (pnp_resource_valid(res))
107 return res->start;
108 return 0;
111 static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
112 unsigned int bar)
114 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
116 if (pnp_resource_valid(res))
117 return res->end;
118 return 0;
121 static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
123 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
125 if (pnp_resource_valid(res))
126 return res->flags;
127 return IORESOURCE_MEM | IORESOURCE_AUTO;
130 static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
132 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
135 static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
136 unsigned int bar)
138 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
140 if (pnp_resource_valid(res))
141 return pnp_resource_len(res);
142 return 0;
146 static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
148 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
150 if (pnp_resource_valid(res))
151 return res->start;
152 return -1;
155 static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
157 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
159 if (pnp_resource_valid(res))
160 return res->flags;
161 return IORESOURCE_IRQ | IORESOURCE_AUTO;
164 static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
166 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
170 static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
172 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
174 if (pnp_resource_valid(res))
175 return res->start;
176 return -1;
179 static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
181 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
183 if (pnp_resource_valid(res))
184 return res->flags;
185 return IORESOURCE_DMA | IORESOURCE_AUTO;
188 static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
190 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
195 * Device Management
198 struct pnp_card {
199 struct device dev; /* Driver Model device interface */
200 unsigned char number; /* used as an index, must be unique */
201 struct list_head global_list; /* node in global list of cards */
202 struct list_head protocol_list; /* node in protocol's list of cards */
203 struct list_head devices; /* devices attached to the card */
205 struct pnp_protocol *protocol;
206 struct pnp_id *id; /* contains supported EISA IDs */
208 char name[PNP_NAME_LEN]; /* contains a human-readable name */
209 unsigned char pnpver; /* Plug & Play version */
210 unsigned char productver; /* product version */
211 unsigned int serial; /* serial number */
212 unsigned char checksum; /* if zero - checksum passed */
213 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */
216 #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
217 #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
218 #define to_pnp_card(n) container_of(n, struct pnp_card, dev)
219 #define pnp_for_each_card(card) \
220 for((card) = global_to_pnp_card(pnp_cards.next); \
221 (card) != global_to_pnp_card(&pnp_cards); \
222 (card) = global_to_pnp_card((card)->global_list.next))
224 struct pnp_card_link {
225 struct pnp_card *card;
226 struct pnp_card_driver *driver;
227 void *driver_data;
228 pm_message_t pm_state;
231 static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard)
233 return pcard->driver_data;
236 static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data)
238 pcard->driver_data = data;
241 struct pnp_dev {
242 struct device dev; /* Driver Model device interface */
243 u64 dma_mask;
244 unsigned int number; /* used as an index, must be unique */
245 int status;
247 struct list_head global_list; /* node in global list of devices */
248 struct list_head protocol_list; /* node in list of device's protocol */
249 struct list_head card_list; /* node in card's list of devices */
250 struct list_head rdev_list; /* node in cards list of requested devices */
252 struct pnp_protocol *protocol;
253 struct pnp_card *card; /* card the device is attached to, none if NULL */
254 struct pnp_driver *driver;
255 struct pnp_card_link *card_link;
257 struct pnp_id *id; /* supported EISA IDs */
259 int active;
260 int capabilities;
261 unsigned int num_dependent_sets;
262 struct list_head resources;
263 struct list_head options;
265 char name[PNP_NAME_LEN]; /* contains a human-readable name */
266 int flags; /* used by protocols */
267 struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
268 void *data;
271 #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
272 #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
273 #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
274 #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
275 #define pnp_for_each_dev(dev) \
276 for((dev) = global_to_pnp_dev(pnp_global.next); \
277 (dev) != global_to_pnp_dev(&pnp_global); \
278 (dev) = global_to_pnp_dev((dev)->global_list.next))
279 #define card_for_each_dev(card,dev) \
280 for((dev) = card_to_pnp_dev((card)->devices.next); \
281 (dev) != card_to_pnp_dev(&(card)->devices); \
282 (dev) = card_to_pnp_dev((dev)->card_list.next))
283 #define pnp_dev_name(dev) (dev)->name
285 static inline void *pnp_get_drvdata(struct pnp_dev *pdev)
287 return dev_get_drvdata(&pdev->dev);
290 static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
292 dev_set_drvdata(&pdev->dev, data);
295 struct pnp_fixup {
296 char id[7];
297 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
300 /* config parameters */
301 #define PNP_CONFIG_NORMAL 0x0001
302 #define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */
304 /* capabilities */
305 #define PNP_READ 0x0001
306 #define PNP_WRITE 0x0002
307 #define PNP_DISABLE 0x0004
308 #define PNP_CONFIGURABLE 0x0008
309 #define PNP_REMOVABLE 0x0010
311 #define pnp_can_read(dev) (((dev)->protocol->get) && \
312 ((dev)->capabilities & PNP_READ))
313 #define pnp_can_write(dev) (((dev)->protocol->set) && \
314 ((dev)->capabilities & PNP_WRITE))
315 #define pnp_can_disable(dev) (((dev)->protocol->disable) && \
316 ((dev)->capabilities & PNP_DISABLE))
317 #define pnp_can_configure(dev) ((!(dev)->active) && \
318 ((dev)->capabilities & PNP_CONFIGURABLE))
320 #ifdef CONFIG_ISAPNP
321 extern struct pnp_protocol isapnp_protocol;
322 #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
323 #else
324 #define pnp_device_is_isapnp(dev) 0
325 #endif
326 extern struct mutex pnp_res_mutex;
328 #ifdef CONFIG_PNPBIOS
329 extern struct pnp_protocol pnpbios_protocol;
330 #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
331 #else
332 #define pnp_device_is_pnpbios(dev) 0
333 #endif
335 /* status */
336 #define PNP_READY 0x0000
337 #define PNP_ATTACHED 0x0001
338 #define PNP_BUSY 0x0002
339 #define PNP_FAULTY 0x0004
341 /* isapnp specific macros */
343 #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
344 #define isapnp_csn_number(dev) ((dev)->number)
347 * Driver Management
350 struct pnp_id {
351 char id[PNP_ID_LEN];
352 struct pnp_id *next;
355 struct pnp_driver {
356 char *name;
357 const struct pnp_device_id *id_table;
358 unsigned int flags;
359 int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
360 void (*remove) (struct pnp_dev *dev);
361 int (*suspend) (struct pnp_dev *dev, pm_message_t state);
362 int (*resume) (struct pnp_dev *dev);
363 struct device_driver driver;
366 #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
368 struct pnp_card_driver {
369 struct list_head global_list;
370 char *name;
371 const struct pnp_card_device_id *id_table;
372 unsigned int flags;
373 int (*probe) (struct pnp_card_link *card,
374 const struct pnp_card_device_id *card_id);
375 void (*remove) (struct pnp_card_link *card);
376 int (*suspend) (struct pnp_card_link *card, pm_message_t state);
377 int (*resume) (struct pnp_card_link *card);
378 struct pnp_driver link;
381 #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
383 /* pnp driver flags */
384 #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */
385 #define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */
388 * Protocol Management
391 struct pnp_protocol {
392 struct list_head protocol_list;
393 char *name;
395 /* resource control functions */
396 int (*get) (struct pnp_dev *dev);
397 int (*set) (struct pnp_dev *dev);
398 int (*disable) (struct pnp_dev *dev);
400 /* protocol specific suspend/resume */
401 int (*suspend) (struct pnp_dev * dev, pm_message_t state);
402 int (*resume) (struct pnp_dev * dev);
404 /* used by pnp layer only (look but don't touch) */
405 unsigned char number; /* protocol number */
406 struct device dev; /* link to driver model */
407 struct list_head cards;
408 struct list_head devices;
411 #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
412 #define protocol_for_each_card(protocol,card) \
413 for((card) = protocol_to_pnp_card((protocol)->cards.next); \
414 (card) != protocol_to_pnp_card(&(protocol)->cards); \
415 (card) = protocol_to_pnp_card((card)->protocol_list.next))
416 #define protocol_for_each_dev(protocol,dev) \
417 for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
418 (dev) != protocol_to_pnp_dev(&(protocol)->devices); \
419 (dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
421 extern struct bus_type pnp_bus_type;
423 #if defined(CONFIG_PNP)
425 /* device management */
426 int pnp_device_attach(struct pnp_dev *pnp_dev);
427 void pnp_device_detach(struct pnp_dev *pnp_dev);
428 extern struct list_head pnp_global;
429 extern int pnp_platform_devices;
431 /* multidevice card support */
432 struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
433 const char *id, struct pnp_dev *from);
434 void pnp_release_card_device(struct pnp_dev *dev);
435 int pnp_register_card_driver(struct pnp_card_driver *drv);
436 void pnp_unregister_card_driver(struct pnp_card_driver *drv);
437 extern struct list_head pnp_cards;
439 /* resource management */
440 int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base,
441 resource_size_t size);
442 int pnp_auto_config_dev(struct pnp_dev *dev);
443 int pnp_start_dev(struct pnp_dev *dev);
444 int pnp_stop_dev(struct pnp_dev *dev);
445 int pnp_activate_dev(struct pnp_dev *dev);
446 int pnp_disable_dev(struct pnp_dev *dev);
448 /* protocol helpers */
449 int pnp_is_active(struct pnp_dev *dev);
450 int compare_pnp_id(struct pnp_id *pos, const char *id);
451 int pnp_register_driver(struct pnp_driver *drv);
452 void pnp_unregister_driver(struct pnp_driver *drv);
454 #else
456 /* device management */
457 static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
458 static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
460 #define pnp_platform_devices 0
462 /* multidevice card support */
463 static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
464 static inline void pnp_release_card_device(struct pnp_dev *dev) { }
465 static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
466 static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
468 /* resource management */
469 static inline int pnp_possible_config(struct pnp_dev *dev, int type,
470 resource_size_t base,
471 resource_size_t size) { return 0; }
472 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
473 static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
474 static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
475 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
476 static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
478 /* protocol helpers */
479 static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
480 static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
481 static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
482 static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
484 #endif /* CONFIG_PNP */
486 #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg)
487 #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg)
488 #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg)
490 #ifdef CONFIG_PNP_DEBUG
491 #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg)
492 #else
493 #define pnp_dbg(format, arg...) do {} while (0)
494 #endif
496 #endif /* _LINUX_PNP_H */