MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / include / linux / pnp.h
blobd728e2f5cf717da692715c55ce4ee14db33b694a
1 /*
2 * Linux Plug and Play Support
3 * Copyright by Adam Belay <ambx1@neo.rr.com>
5 */
7 #ifndef _LINUX_PNP_H
8 #define _LINUX_PNP_H
10 #ifdef __KERNEL__
12 #include <linux/device.h>
13 #include <linux/list.h>
14 #include <linux/errno.h>
15 #include <linux/mod_devicetable.h>
17 #define PNP_MAX_PORT 8
18 #define PNP_MAX_MEM 4
19 #define PNP_MAX_IRQ 2
20 #define PNP_MAX_DMA 2
21 #define PNP_NAME_LEN 50
23 struct pnp_protocol;
24 struct pnp_dev;
28 * Resource Management
31 /* Use these instead of directly reading pnp_dev to get resource information */
32 #define pnp_port_start(dev,bar) ((dev)->res.port_resource[(bar)].start)
33 #define pnp_port_end(dev,bar) ((dev)->res.port_resource[(bar)].end)
34 #define pnp_port_flags(dev,bar) ((dev)->res.port_resource[(bar)].flags)
35 #define pnp_port_valid(dev,bar) \
36 ((pnp_port_flags((dev),(bar)) & (IORESOURCE_IO | IORESOURCE_UNSET)) \
37 == IORESOURCE_IO)
38 #define pnp_port_len(dev,bar) \
39 ((pnp_port_start((dev),(bar)) == 0 && \
40 pnp_port_end((dev),(bar)) == \
41 pnp_port_start((dev),(bar))) ? 0 : \
43 (pnp_port_end((dev),(bar)) - \
44 pnp_port_start((dev),(bar)) + 1))
46 #define pnp_mem_start(dev,bar) ((dev)->res.mem_resource[(bar)].start)
47 #define pnp_mem_end(dev,bar) ((dev)->res.mem_resource[(bar)].end)
48 #define pnp_mem_flags(dev,bar) ((dev)->res.mem_resource[(bar)].flags)
49 #define pnp_mem_valid(dev,bar) \
50 ((pnp_mem_flags((dev),(bar)) & (IORESOURCE_MEM | IORESOURCE_UNSET)) \
51 == IORESOURCE_MEM)
52 #define pnp_mem_len(dev,bar) \
53 ((pnp_mem_start((dev),(bar)) == 0 && \
54 pnp_mem_end((dev),(bar)) == \
55 pnp_mem_start((dev),(bar))) ? 0 : \
57 (pnp_mem_end((dev),(bar)) - \
58 pnp_mem_start((dev),(bar)) + 1))
60 #define pnp_irq(dev,bar) ((dev)->res.irq_resource[(bar)].start)
61 #define pnp_irq_flags(dev,bar) ((dev)->res.irq_resource[(bar)].flags)
62 #define pnp_irq_valid(dev,bar) \
63 ((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \
64 == IORESOURCE_IRQ)
66 #define pnp_dma(dev,bar) ((dev)->res.dma_resource[(bar)].start)
67 #define pnp_dma_flags(dev,bar) ((dev)->res.dma_resource[(bar)].flags)
68 #define pnp_dma_valid(dev,bar) \
69 ((pnp_dma_flags((dev),(bar)) & (IORESOURCE_DMA | IORESOURCE_UNSET)) \
70 == IORESOURCE_DMA)
72 #define PNP_PORT_FLAG_16BITADDR (1<<0)
73 #define PNP_PORT_FLAG_FIXED (1<<1)
75 struct pnp_port {
76 unsigned short min; /* min base number */
77 unsigned short max; /* max base number */
78 unsigned char align; /* align boundary */
79 unsigned char size; /* size of range */
80 unsigned char flags; /* port flags */
81 unsigned char pad; /* pad */
82 struct pnp_port *next; /* next port */
85 struct pnp_irq {
86 unsigned short map; /* bitmaks for IRQ lines */
87 unsigned char flags; /* IRQ flags */
88 unsigned char pad; /* pad */
89 struct pnp_irq *next; /* next IRQ */
92 struct pnp_dma {
93 unsigned char map; /* bitmask for DMA channels */
94 unsigned char flags; /* DMA flags */
95 struct pnp_dma *next; /* next port */
98 struct pnp_mem {
99 unsigned int min; /* min base number */
100 unsigned int max; /* max base number */
101 unsigned int align; /* align boundary */
102 unsigned int size; /* size of range */
103 unsigned char flags; /* memory flags */
104 unsigned char pad; /* pad */
105 struct pnp_mem *next; /* next memory resource */
108 #define PNP_RES_PRIORITY_PREFERRED 0
109 #define PNP_RES_PRIORITY_ACCEPTABLE 1
110 #define PNP_RES_PRIORITY_FUNCTIONAL 2
111 #define PNP_RES_PRIORITY_INVALID 65535
113 struct pnp_option {
114 unsigned short priority; /* priority */
115 struct pnp_port *port; /* first port */
116 struct pnp_irq *irq; /* first IRQ */
117 struct pnp_dma *dma; /* first DMA */
118 struct pnp_mem *mem; /* first memory resource */
119 struct pnp_option *next; /* used to chain dependent resources */
122 struct pnp_resource_table {
123 struct resource port_resource[PNP_MAX_PORT];
124 struct resource mem_resource[PNP_MAX_MEM];
125 struct resource dma_resource[PNP_MAX_DMA];
126 struct resource irq_resource[PNP_MAX_IRQ];
131 * Device Managemnt
134 struct pnp_card {
135 struct device dev; /* Driver Model device interface */
136 unsigned char number; /* used as an index, must be unique */
137 struct list_head global_list; /* node in global list of cards */
138 struct list_head protocol_list; /* node in protocol's list of cards */
139 struct list_head devices; /* devices attached to the card */
141 struct pnp_protocol * protocol;
142 struct pnp_id * id; /* contains supported EISA IDs*/
144 char name[PNP_NAME_LEN]; /* contains a human-readable name */
145 unsigned char pnpver; /* Plug & Play version */
146 unsigned char productver; /* product version */
147 unsigned int serial; /* serial number */
148 unsigned char checksum; /* if zero - checksum passed */
149 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */
152 #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
153 #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
154 #define to_pnp_card(n) container_of(n, struct pnp_card, dev)
155 #define pnp_for_each_card(card) \
156 for((card) = global_to_pnp_card(pnp_cards.next); \
157 (card) != global_to_pnp_card(&pnp_cards); \
158 (card) = global_to_pnp_card((card)->global_list.next))
160 struct pnp_card_link {
161 struct pnp_card * card;
162 struct pnp_card_driver * driver;
163 void * driver_data;
166 static inline void *pnp_get_card_drvdata (struct pnp_card_link *pcard)
168 return pcard->driver_data;
171 static inline void pnp_set_card_drvdata (struct pnp_card_link *pcard, void *data)
173 pcard->driver_data = data;
176 struct pnp_dev {
177 struct device dev; /* Driver Model device interface */
178 unsigned char number; /* used as an index, must be unique */
179 int status;
181 struct list_head global_list; /* node in global list of devices */
182 struct list_head protocol_list; /* node in list of device's protocol */
183 struct list_head card_list; /* node in card's list of devices */
184 struct list_head rdev_list; /* node in cards list of requested devices */
186 struct pnp_protocol * protocol;
187 struct pnp_card * card; /* card the device is attached to, none if NULL */
188 struct pnp_driver * driver;
189 struct pnp_card_link * card_link;
191 struct pnp_id * id; /* supported EISA IDs*/
193 int active;
194 int capabilities;
195 struct pnp_option * independent;
196 struct pnp_option * dependent;
197 struct pnp_resource_table res;
199 char name[PNP_NAME_LEN]; /* contains a human-readable name */
200 unsigned short regs; /* ISAPnP: supported registers */
201 int flags; /* used by protocols */
202 struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
205 #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
206 #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
207 #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
208 #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
209 #define pnp_for_each_dev(dev) \
210 for((dev) = global_to_pnp_dev(pnp_global.next); \
211 (dev) != global_to_pnp_dev(&pnp_global); \
212 (dev) = global_to_pnp_dev((dev)->global_list.next))
213 #define card_for_each_dev(card,dev) \
214 for((dev) = card_to_pnp_dev((card)->devices.next); \
215 (dev) != card_to_pnp_dev(&(card)->devices); \
216 (dev) = card_to_pnp_dev((dev)->card_list.next))
217 #define pnp_dev_name(dev) (dev)->name
219 static inline void *pnp_get_drvdata (struct pnp_dev *pdev)
221 return dev_get_drvdata(&pdev->dev);
224 static inline void pnp_set_drvdata (struct pnp_dev *pdev, void *data)
226 dev_set_drvdata(&pdev->dev, data);
229 struct pnp_fixup {
230 char id[7];
231 void (*quirk_function)(struct pnp_dev *dev); /* fixup function */
234 /* config parameters */
235 #define PNP_CONFIG_NORMAL 0x0001
236 #define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */
238 /* capabilities */
239 #define PNP_READ 0x0001
240 #define PNP_WRITE 0x0002
241 #define PNP_DISABLE 0x0004
242 #define PNP_CONFIGURABLE 0x0008
243 #define PNP_REMOVABLE 0x0010
245 #define pnp_can_read(dev) (((dev)->protocol) && ((dev)->protocol->get) && \
246 ((dev)->capabilities & PNP_READ))
247 #define pnp_can_write(dev) (((dev)->protocol) && ((dev)->protocol->set) && \
248 ((dev)->capabilities & PNP_WRITE))
249 #define pnp_can_disable(dev) (((dev)->protocol) && ((dev)->protocol->disable) && \
250 ((dev)->capabilities & PNP_DISABLE))
251 #define pnp_can_configure(dev) ((!(dev)->active) && \
252 ((dev)->capabilities & PNP_CONFIGURABLE))
254 #ifdef CONFIG_ISAPNP
255 extern struct pnp_protocol isapnp_protocol;
256 #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
257 #else
258 #define pnp_device_is_isapnp(dev) 0
259 #endif
261 #ifdef CONFIG_PNPBIOS
262 extern struct pnp_protocol pnpbios_protocol;
263 #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
264 #else
265 #define pnp_device_is_pnpbios(dev) 0
266 #endif
269 /* status */
270 #define PNP_READY 0x0000
271 #define PNP_ATTACHED 0x0001
272 #define PNP_BUSY 0x0002
273 #define PNP_FAULTY 0x0004
275 /* isapnp specific macros */
277 #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
278 #define isapnp_csn_number(dev) ((dev)->number)
281 * Driver Management
284 struct pnp_id {
285 char id[PNP_ID_LEN];
286 struct pnp_id * next;
289 struct pnp_driver {
290 char * name;
291 const struct pnp_device_id *id_table;
292 unsigned int flags;
293 int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
294 void (*remove) (struct pnp_dev *dev);
295 struct device_driver driver;
298 #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
300 struct pnp_card_driver {
301 struct list_head global_list;
302 char * name;
303 const struct pnp_card_device_id *id_table;
304 unsigned int flags;
305 int (*probe) (struct pnp_card_link *card, const struct pnp_card_device_id *card_id);
306 void (*remove) (struct pnp_card_link *card);
307 struct pnp_driver link;
310 #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
312 /* pnp driver flags */
313 #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */
314 #define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */
318 * Protocol Management
321 struct pnp_protocol {
322 struct list_head protocol_list;
323 char * name;
325 /* resource control functions */
326 int (*get)(struct pnp_dev *dev, struct pnp_resource_table *res);
327 int (*set)(struct pnp_dev *dev, struct pnp_resource_table *res);
328 int (*disable)(struct pnp_dev *dev);
330 /* used by pnp layer only (look but don't touch) */
331 unsigned char number; /* protocol number*/
332 struct device dev; /* link to driver model */
333 struct list_head cards;
334 struct list_head devices;
337 #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
338 #define protocol_for_each_card(protocol,card) \
339 for((card) = protocol_to_pnp_card((protocol)->cards.next); \
340 (card) != protocol_to_pnp_card(&(protocol)->cards); \
341 (card) = protocol_to_pnp_card((card)->protocol_list.next))
342 #define protocol_for_each_dev(protocol,dev) \
343 for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
344 (dev) != protocol_to_pnp_dev(&(protocol)->devices); \
345 (dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
348 #if defined(CONFIG_PNP)
350 /* device management */
351 int pnp_register_protocol(struct pnp_protocol *protocol);
352 void pnp_unregister_protocol(struct pnp_protocol *protocol);
353 int pnp_add_device(struct pnp_dev *dev);
354 void pnp_remove_device(struct pnp_dev *dev);
355 int pnp_device_attach(struct pnp_dev *pnp_dev);
356 void pnp_device_detach(struct pnp_dev *pnp_dev);
357 extern struct list_head pnp_global;
359 /* multidevice card support */
360 int pnp_add_card(struct pnp_card *card);
361 void pnp_remove_card(struct pnp_card *card);
362 int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
363 void pnp_remove_card_device(struct pnp_dev *dev);
364 int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
365 struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from);
366 void pnp_release_card_device(struct pnp_dev * dev);
367 int pnp_register_card_driver(struct pnp_card_driver * drv);
368 void pnp_unregister_card_driver(struct pnp_card_driver * drv);
369 extern struct list_head pnp_cards;
371 /* resource management */
372 struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev);
373 struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority);
374 int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data);
375 int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data);
376 int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data);
377 int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
378 void pnp_init_resource_table(struct pnp_resource_table *table);
379 int pnp_assign_resources(struct pnp_dev *dev, int depnum);
380 int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode);
381 int pnp_auto_config_dev(struct pnp_dev *dev);
382 int pnp_validate_config(struct pnp_dev *dev);
383 int pnp_activate_dev(struct pnp_dev *dev);
384 int pnp_disable_dev(struct pnp_dev *dev);
385 void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size);
387 /* protocol helpers */
388 int pnp_is_active(struct pnp_dev * dev);
389 int compare_pnp_id(struct pnp_id * pos, const char * id);
390 int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
391 int pnp_register_driver(struct pnp_driver *drv);
392 void pnp_unregister_driver(struct pnp_driver *drv);
394 #else
396 /* device management */
397 static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; }
398 static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { }
399 static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; }
400 static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; }
401 static inline void pnp_remove_device(struct pnp_dev *dev) { }
402 static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
403 static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { ; }
405 /* multidevice card support */
406 static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; }
407 static inline void pnp_remove_card(struct pnp_card *card) { ; }
408 static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
409 static inline void pnp_remove_card_device(struct pnp_dev *dev) { ; }
410 static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
411 static inline struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from) { return NULL; }
412 static inline void pnp_release_card_device(struct pnp_dev * dev) { ; }
413 static inline int pnp_register_card_driver(struct pnp_card_driver * drv) { return -ENODEV; }
414 static inline void pnp_unregister_card_driver(struct pnp_card_driver * drv) { ; }
416 /* resource management */
417 static inline struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev) { return NULL; }
418 static inline struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority) { return NULL; }
419 static inline int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; }
420 static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; }
421 static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; }
422 static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; }
423 static inline void pnp_init_resource_table(struct pnp_resource_table *table) { }
424 static inline int pnp_assign_resources(struct pnp_dev *dev, int depnum) { return -ENODEV; }
425 static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; }
426 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
427 static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
428 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
429 static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
430 static inline void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size) { }
432 /* protocol helpers */
433 static inline int pnp_is_active(struct pnp_dev * dev) { return 0; }
434 static inline int compare_pnp_id(struct pnp_id * pos, const char * id) { return -ENODEV; }
435 static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) { return -ENODEV; }
436 static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
437 static inline void pnp_unregister_driver(struct pnp_driver *drv) { ; }
439 #endif /* CONFIG_PNP */
442 #define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg)
443 #define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg)
444 #define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg)
446 #ifdef DEBUG
447 #define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg)
448 #else
449 #define pnp_dbg(format, arg...) do {} while (0)
450 #endif
452 #endif /* __KERNEL__ */
454 #endif /* _LINUX_PNP_H */