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.
14 #include <linux/mod_devicetable.h>
15 #include <linux/device.h>
16 #include <linux/irqreturn.h>
18 #define CHAMELEON_FILENAME_LEN 12
24 * struct mcb_bus - MEN Chameleon Bus
27 * @carrier: pointer to carrier device
28 * @bus_nr: mcb bus number
29 * @get_irq: callback to get IRQ number
30 * @revision: the FPGA's revision number
31 * @model: the FPGA's model number
32 * @filename: the FPGA's name
36 struct device
*carrier
;
41 char name
[CHAMELEON_FILENAME_LEN
+ 1];
42 int (*get_irq
)(struct mcb_device
*dev
);
45 static inline struct mcb_bus
*to_mcb_bus(struct device
*dev
)
47 return container_of(dev
, struct mcb_bus
, dev
);
51 * struct mcb_device - MEN Chameleon Bus device
53 * @dev: device in kernel representation
54 * @bus: mcb bus the device is plugged to
55 * @is_added: flag to check if device is added to bus
56 * @driver: associated mcb_driver
58 * @inst: instance in Chameleon table
59 * @group: group in Chameleon table
60 * @var: variant in Chameleon table
61 * @bar: BAR in Chameleon table
62 * @rev: revision in Chameleon table
64 * @memory: memory resource
70 struct mcb_driver
*driver
;
79 struct device
*dma_dev
;
82 static inline struct mcb_device
*to_mcb_device(struct device
*dev
)
84 return container_of(dev
, struct mcb_device
, dev
);
88 * struct mcb_driver - MEN Chameleon Bus device driver
90 * @driver: device_driver
91 * @id_table: mcb id table
92 * @probe: probe callback
93 * @remove: remove callback
94 * @shutdown: shutdown callback
97 struct device_driver driver
;
98 const struct mcb_device_id
*id_table
;
99 int (*probe
)(struct mcb_device
*mdev
, const struct mcb_device_id
*id
);
100 void (*remove
)(struct mcb_device
*mdev
);
101 void (*shutdown
)(struct mcb_device
*mdev
);
104 static inline struct mcb_driver
*to_mcb_driver(struct device_driver
*drv
)
106 return container_of(drv
, struct mcb_driver
, driver
);
109 static inline void *mcb_get_drvdata(struct mcb_device
*dev
)
111 return dev_get_drvdata(&dev
->dev
);
114 static inline void mcb_set_drvdata(struct mcb_device
*dev
, void *data
)
116 dev_set_drvdata(&dev
->dev
, data
);
119 extern int __must_check
__mcb_register_driver(struct mcb_driver
*drv
,
120 struct module
*owner
,
121 const char *mod_name
);
122 #define mcb_register_driver(driver) \
123 __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
124 extern void mcb_unregister_driver(struct mcb_driver
*driver
);
125 #define module_mcb_driver(__mcb_driver) \
126 module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver);
127 extern void mcb_bus_add_devices(const struct mcb_bus
*bus
);
128 extern int mcb_device_register(struct mcb_bus
*bus
, struct mcb_device
*dev
);
129 extern struct mcb_bus
*mcb_alloc_bus(struct device
*carrier
);
130 extern struct mcb_bus
*mcb_bus_get(struct mcb_bus
*bus
);
131 extern void mcb_bus_put(struct mcb_bus
*bus
);
132 extern struct mcb_device
*mcb_alloc_dev(struct mcb_bus
*bus
);
133 extern void mcb_free_dev(struct mcb_device
*dev
);
134 extern void mcb_release_bus(struct mcb_bus
*bus
);
135 extern struct resource
*mcb_request_mem(struct mcb_device
*dev
,
137 extern void mcb_release_mem(struct resource
*mem
);
138 extern int mcb_get_irq(struct mcb_device
*dev
);
139 extern struct resource
*mcb_get_resource(struct mcb_device
*dev
,
142 #endif /* _LINUX_MCB_H */