Linux 4.6-rc6
[cris-mirror.git] / include / linux / mcb.h
blobed06e15a36aa299c6110dc27870aadbc5987d650
1 /*
2 * MEN Chameleon Bus.
4 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
5 * Author: Johannes Thumshirn <johannes.thumshirn@men.de>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; version 2 of the License.
11 #ifndef _LINUX_MCB_H
12 #define _LINUX_MCB_H
14 #include <linux/mod_devicetable.h>
15 #include <linux/device.h>
16 #include <linux/irqreturn.h>
18 struct mcb_driver;
19 struct mcb_device;
21 /**
22 * struct mcb_bus - MEN Chameleon Bus
24 * @dev: pointer to carrier device
25 * @children: the child busses
26 * @bus_nr: mcb bus number
27 * @get_irq: callback to get IRQ number
29 struct mcb_bus {
30 struct list_head children;
31 struct device dev;
32 struct device *carrier;
33 int bus_nr;
34 int (*get_irq)(struct mcb_device *dev);
36 #define to_mcb_bus(b) container_of((b), struct mcb_bus, dev)
38 /**
39 * struct mcb_device - MEN Chameleon Bus device
41 * @bus_list: internal list handling for bus code
42 * @dev: device in kernel representation
43 * @bus: mcb bus the device is plugged to
44 * @subordinate: subordinate MCBus in case of bridge
45 * @is_added: flag to check if device is added to bus
46 * @driver: associated mcb_driver
47 * @id: mcb device id
48 * @inst: instance in Chameleon table
49 * @group: group in Chameleon table
50 * @var: variant in Chameleon table
51 * @bar: BAR in Chameleon table
52 * @rev: revision in Chameleon table
53 * @irq: IRQ resource
54 * @memory: memory resource
56 struct mcb_device {
57 struct list_head bus_list;
58 struct device dev;
59 struct mcb_bus *bus;
60 struct mcb_bus *subordinate;
61 bool is_added;
62 struct mcb_driver *driver;
63 u16 id;
64 int inst;
65 int group;
66 int var;
67 int bar;
68 int rev;
69 struct resource irq;
70 struct resource mem;
72 #define to_mcb_device(x) container_of((x), struct mcb_device, dev)
74 /**
75 * struct mcb_driver - MEN Chameleon Bus device driver
77 * @driver: device_driver
78 * @id_table: mcb id table
79 * @probe: probe callback
80 * @remove: remove callback
81 * @shutdown: shutdown callback
83 struct mcb_driver {
84 struct device_driver driver;
85 const struct mcb_device_id *id_table;
86 int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id);
87 void (*remove)(struct mcb_device *mdev);
88 void (*shutdown)(struct mcb_device *mdev);
90 #define to_mcb_driver(x) container_of((x), struct mcb_driver, driver)
92 static inline void *mcb_get_drvdata(struct mcb_device *dev)
94 return dev_get_drvdata(&dev->dev);
97 static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
99 dev_set_drvdata(&dev->dev, data);
102 extern int __must_check __mcb_register_driver(struct mcb_driver *drv,
103 struct module *owner,
104 const char *mod_name);
105 #define mcb_register_driver(driver) \
106 __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
107 extern void mcb_unregister_driver(struct mcb_driver *driver);
108 #define module_mcb_driver(__mcb_driver) \
109 module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver);
110 extern void mcb_bus_add_devices(const struct mcb_bus *bus);
111 extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
112 extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
113 extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
114 extern void mcb_bus_put(struct mcb_bus *bus);
115 extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
116 extern void mcb_free_dev(struct mcb_device *dev);
117 extern void mcb_release_bus(struct mcb_bus *bus);
118 extern struct resource *mcb_request_mem(struct mcb_device *dev,
119 const char *name);
120 extern void mcb_release_mem(struct resource *mem);
121 extern int mcb_get_irq(struct mcb_device *dev);
123 #endif /* _LINUX_MCB_H */