blob: ed06e15a36aa299c6110dc27870aadbc5987d650 [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;
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020019struct mcb_device;
Johannes Thumshirn3764e822014-02-26 17:29:05 +010020
21/**
22 * struct mcb_bus - MEN Chameleon Bus
23 *
24 * @dev: pointer to carrier device
25 * @children: the child busses
26 * @bus_nr: mcb bus number
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020027 * @get_irq: callback to get IRQ number
Johannes Thumshirn3764e822014-02-26 17:29:05 +010028 */
29struct mcb_bus {
30 struct list_head children;
31 struct device dev;
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020032 struct device *carrier;
Johannes Thumshirn3764e822014-02-26 17:29:05 +010033 int bus_nr;
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020034 int (*get_irq)(struct mcb_device *dev);
Johannes Thumshirn3764e822014-02-26 17:29:05 +010035};
36#define to_mcb_bus(b) container_of((b), struct mcb_bus, dev)
37
38/**
39 * struct mcb_device - MEN Chameleon Bus device
40 *
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
55 */
56struct 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;
71};
72#define to_mcb_device(x) container_of((x), struct mcb_device, dev)
73
74/**
75 * struct mcb_driver - MEN Chameleon Bus device driver
76 *
77 * @driver: device_driver
78 * @id_table: mcb id table
79 * @probe: probe callback
80 * @remove: remove callback
81 * @shutdown: shutdown callback
82 */
83struct 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);
89};
90#define to_mcb_driver(x) container_of((x), struct mcb_driver, driver)
91
92static inline void *mcb_get_drvdata(struct mcb_device *dev)
93{
94 return dev_get_drvdata(&dev->dev);
95}
96
97static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
98{
99 dev_set_drvdata(&dev->dev, data);
100}
101
102extern 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)
107extern 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);
110extern void mcb_bus_add_devices(const struct mcb_bus *bus);
111extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +0200112extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
Johannes Thumshirn3764e822014-02-26 17:29:05 +0100113extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
114extern void mcb_bus_put(struct mcb_bus *bus);
115extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
116extern void mcb_free_dev(struct mcb_device *dev);
117extern void mcb_release_bus(struct mcb_bus *bus);
118extern struct resource *mcb_request_mem(struct mcb_device *dev,
119 const char *name);
120extern void mcb_release_mem(struct resource *mem);
121extern int mcb_get_irq(struct mcb_device *dev);
122
123#endif /* _LINUX_MCB_H */