blob: 2db284d140645308c72a0588f6ebd47a161b2f88 [file] [log] [blame]
Johannes Thumshirn3764e822014-02-26 17:29:05 +01001/*
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
18struct mcb_driver;
19
20/**
21 * struct mcb_bus - MEN Chameleon Bus
22 *
23 * @dev: pointer to carrier device
24 * @children: the child busses
25 * @bus_nr: mcb bus number
26 */
27struct mcb_bus {
28 struct list_head children;
29 struct device dev;
30 int bus_nr;
31};
32#define to_mcb_bus(b) container_of((b), struct mcb_bus, dev)
33
34/**
35 * struct mcb_device - MEN Chameleon Bus device
36 *
37 * @bus_list: internal list handling for bus code
38 * @dev: device in kernel representation
39 * @bus: mcb bus the device is plugged to
40 * @subordinate: subordinate MCBus in case of bridge
41 * @is_added: flag to check if device is added to bus
42 * @driver: associated mcb_driver
43 * @id: mcb device id
44 * @inst: instance in Chameleon table
45 * @group: group in Chameleon table
46 * @var: variant in Chameleon table
47 * @bar: BAR in Chameleon table
48 * @rev: revision in Chameleon table
49 * @irq: IRQ resource
50 * @memory: memory resource
51 */
52struct mcb_device {
53 struct list_head bus_list;
54 struct device dev;
55 struct mcb_bus *bus;
56 struct mcb_bus *subordinate;
57 bool is_added;
58 struct mcb_driver *driver;
59 u16 id;
60 int inst;
61 int group;
62 int var;
63 int bar;
64 int rev;
65 struct resource irq;
66 struct resource mem;
67};
68#define to_mcb_device(x) container_of((x), struct mcb_device, dev)
69
70/**
71 * struct mcb_driver - MEN Chameleon Bus device driver
72 *
73 * @driver: device_driver
74 * @id_table: mcb id table
75 * @probe: probe callback
76 * @remove: remove callback
77 * @shutdown: shutdown callback
78 */
79struct mcb_driver {
80 struct device_driver driver;
81 const struct mcb_device_id *id_table;
82 int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id);
83 void (*remove)(struct mcb_device *mdev);
84 void (*shutdown)(struct mcb_device *mdev);
85};
86#define to_mcb_driver(x) container_of((x), struct mcb_driver, driver)
87
88static inline void *mcb_get_drvdata(struct mcb_device *dev)
89{
90 return dev_get_drvdata(&dev->dev);
91}
92
93static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
94{
95 dev_set_drvdata(&dev->dev, data);
96}
97
98extern int __must_check __mcb_register_driver(struct mcb_driver *drv,
99 struct module *owner,
100 const char *mod_name);
101#define mcb_register_driver(driver) \
102 __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
103extern void mcb_unregister_driver(struct mcb_driver *driver);
104#define module_mcb_driver(__mcb_driver) \
105 module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver);
106extern void mcb_bus_add_devices(const struct mcb_bus *bus);
107extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
108extern struct mcb_bus *mcb_alloc_bus(void);
109extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
110extern void mcb_bus_put(struct mcb_bus *bus);
111extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
112extern void mcb_free_dev(struct mcb_device *dev);
113extern void mcb_release_bus(struct mcb_bus *bus);
114extern struct resource *mcb_request_mem(struct mcb_device *dev,
115 const char *name);
116extern void mcb_release_mem(struct resource *mem);
117extern int mcb_get_irq(struct mcb_device *dev);
118
119#endif /* _LINUX_MCB_H */