]>
Commit | Line | Data |
---|---|---|
3764e82e JT |
1 | /* |
2 | * MEN Chameleon Bus. | |
3 | * | |
4 | * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de) | |
5 | * Author: Johannes Thumshirn <johannes.thumshirn@men.de> | |
6 | * | |
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. | |
10 | */ | |
11 | #ifndef _LINUX_MCB_H | |
12 | #define _LINUX_MCB_H | |
13 | ||
14 | #include <linux/mod_devicetable.h> | |
15 | #include <linux/device.h> | |
16 | #include <linux/irqreturn.h> | |
17 | ||
803f1ca6 JT |
18 | #define CHAMELEON_FILENAME_LEN 12 |
19 | ||
3764e82e | 20 | struct mcb_driver; |
4ec65b77 | 21 | struct mcb_device; |
3764e82e JT |
22 | |
23 | /** | |
24 | * struct mcb_bus - MEN Chameleon Bus | |
25 | * | |
18d28819 JT |
26 | * @dev: bus device |
27 | * @carrier: pointer to carrier device | |
3764e82e | 28 | * @bus_nr: mcb bus number |
4ec65b77 | 29 | * @get_irq: callback to get IRQ number |
803f1ca6 JT |
30 | * @revision: the FPGA's revision number |
31 | * @model: the FPGA's model number | |
32 | * @filename: the FPGA's name | |
3764e82e JT |
33 | */ |
34 | struct mcb_bus { | |
3764e82e | 35 | struct device dev; |
4ec65b77 | 36 | struct device *carrier; |
3764e82e | 37 | int bus_nr; |
803f1ca6 JT |
38 | u8 revision; |
39 | char model; | |
40 | u8 minor; | |
41 | char name[CHAMELEON_FILENAME_LEN + 1]; | |
4ec65b77 | 42 | int (*get_irq)(struct mcb_device *dev); |
3764e82e | 43 | }; |
68d9671a JT |
44 | |
45 | static inline struct mcb_bus *to_mcb_bus(struct device *dev) | |
46 | { | |
47 | return container_of(dev, struct mcb_bus, dev); | |
48 | } | |
3764e82e JT |
49 | |
50 | /** | |
51 | * struct mcb_device - MEN Chameleon Bus device | |
52 | * | |
3764e82e JT |
53 | * @dev: device in kernel representation |
54 | * @bus: mcb bus the device is plugged to | |
3764e82e JT |
55 | * @is_added: flag to check if device is added to bus |
56 | * @driver: associated mcb_driver | |
57 | * @id: mcb device id | |
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 | |
63 | * @irq: IRQ resource | |
64 | * @memory: memory resource | |
65 | */ | |
66 | struct mcb_device { | |
3764e82e JT |
67 | struct device dev; |
68 | struct mcb_bus *bus; | |
3764e82e JT |
69 | bool is_added; |
70 | struct mcb_driver *driver; | |
71 | u16 id; | |
72 | int inst; | |
73 | int group; | |
74 | int var; | |
75 | int bar; | |
76 | int rev; | |
77 | struct resource irq; | |
78 | struct resource mem; | |
79 | }; | |
68d9671a JT |
80 | |
81 | static inline struct mcb_device *to_mcb_device(struct device *dev) | |
82 | { | |
83 | return container_of(dev, struct mcb_device, dev); | |
84 | } | |
3764e82e JT |
85 | |
86 | /** | |
87 | * struct mcb_driver - MEN Chameleon Bus device driver | |
88 | * | |
89 | * @driver: device_driver | |
90 | * @id_table: mcb id table | |
91 | * @probe: probe callback | |
92 | * @remove: remove callback | |
93 | * @shutdown: shutdown callback | |
94 | */ | |
95 | struct mcb_driver { | |
96 | struct device_driver driver; | |
97 | const struct mcb_device_id *id_table; | |
98 | int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id); | |
99 | void (*remove)(struct mcb_device *mdev); | |
100 | void (*shutdown)(struct mcb_device *mdev); | |
101 | }; | |
68d9671a JT |
102 | |
103 | static inline struct mcb_driver *to_mcb_driver(struct device_driver *drv) | |
104 | { | |
105 | return container_of(drv, struct mcb_driver, driver); | |
106 | } | |
3764e82e JT |
107 | |
108 | static inline void *mcb_get_drvdata(struct mcb_device *dev) | |
109 | { | |
110 | return dev_get_drvdata(&dev->dev); | |
111 | } | |
112 | ||
113 | static inline void mcb_set_drvdata(struct mcb_device *dev, void *data) | |
114 | { | |
115 | dev_set_drvdata(&dev->dev, data); | |
116 | } | |
117 | ||
118 | extern int __must_check __mcb_register_driver(struct mcb_driver *drv, | |
119 | struct module *owner, | |
120 | const char *mod_name); | |
121 | #define mcb_register_driver(driver) \ | |
122 | __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) | |
123 | extern void mcb_unregister_driver(struct mcb_driver *driver); | |
124 | #define module_mcb_driver(__mcb_driver) \ | |
125 | module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver); | |
126 | extern void mcb_bus_add_devices(const struct mcb_bus *bus); | |
127 | extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev); | |
4ec65b77 | 128 | extern struct mcb_bus *mcb_alloc_bus(struct device *carrier); |
3764e82e JT |
129 | extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus); |
130 | extern void mcb_bus_put(struct mcb_bus *bus); | |
131 | extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus); | |
132 | extern void mcb_free_dev(struct mcb_device *dev); | |
133 | extern void mcb_release_bus(struct mcb_bus *bus); | |
134 | extern struct resource *mcb_request_mem(struct mcb_device *dev, | |
135 | const char *name); | |
136 | extern void mcb_release_mem(struct resource *mem); | |
137 | extern int mcb_get_irq(struct mcb_device *dev); | |
138 | ||
139 | #endif /* _LINUX_MCB_H */ |