blob: a6733d3fe72bd6ddfe733550f07b9031f0b6ba79 [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
Johannes Thumshirn803f1ca2016-05-03 09:46:23 +020018#define CHAMELEON_FILENAME_LEN 12
19
Johannes Thumshirn3764e822014-02-26 17:29:05 +010020struct mcb_driver;
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020021struct mcb_device;
Johannes Thumshirn3764e822014-02-26 17:29:05 +010022
23/**
24 * struct mcb_bus - MEN Chameleon Bus
25 *
Johannes Thumshirn18d28812016-05-03 09:46:22 +020026 * @dev: bus device
27 * @carrier: pointer to carrier device
Johannes Thumshirn3764e822014-02-26 17:29:05 +010028 * @bus_nr: mcb bus number
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020029 * @get_irq: callback to get IRQ number
Johannes Thumshirn803f1ca2016-05-03 09:46:23 +020030 * @revision: the FPGA's revision number
31 * @model: the FPGA's model number
32 * @filename: the FPGA's name
Johannes Thumshirn3764e822014-02-26 17:29:05 +010033 */
34struct mcb_bus {
Johannes Thumshirn3764e822014-02-26 17:29:05 +010035 struct device dev;
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020036 struct device *carrier;
Johannes Thumshirn3764e822014-02-26 17:29:05 +010037 int bus_nr;
Johannes Thumshirn803f1ca2016-05-03 09:46:23 +020038 u8 revision;
39 char model;
40 u8 minor;
41 char name[CHAMELEON_FILENAME_LEN + 1];
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +020042 int (*get_irq)(struct mcb_device *dev);
Johannes Thumshirn3764e822014-02-26 17:29:05 +010043};
Johannes Thumshirn68d96712016-08-26 09:34:59 +020044
45static inline struct mcb_bus *to_mcb_bus(struct device *dev)
46{
47 return container_of(dev, struct mcb_bus, dev);
48}
Johannes Thumshirn3764e822014-02-26 17:29:05 +010049
50/**
51 * struct mcb_device - MEN Chameleon Bus device
52 *
53 * @bus_list: internal list handling for bus code
54 * @dev: device in kernel representation
55 * @bus: mcb bus the device is plugged to
56 * @subordinate: subordinate MCBus in case of bridge
57 * @is_added: flag to check if device is added to bus
58 * @driver: associated mcb_driver
59 * @id: mcb device id
60 * @inst: instance in Chameleon table
61 * @group: group in Chameleon table
62 * @var: variant in Chameleon table
63 * @bar: BAR in Chameleon table
64 * @rev: revision in Chameleon table
65 * @irq: IRQ resource
66 * @memory: memory resource
67 */
68struct mcb_device {
69 struct list_head bus_list;
70 struct device dev;
71 struct mcb_bus *bus;
72 struct mcb_bus *subordinate;
73 bool is_added;
74 struct mcb_driver *driver;
75 u16 id;
76 int inst;
77 int group;
78 int var;
79 int bar;
80 int rev;
81 struct resource irq;
82 struct resource mem;
83};
Johannes Thumshirn68d96712016-08-26 09:34:59 +020084
85static inline struct mcb_device *to_mcb_device(struct device *dev)
86{
87 return container_of(dev, struct mcb_device, dev);
88}
Johannes Thumshirn3764e822014-02-26 17:29:05 +010089
90/**
91 * struct mcb_driver - MEN Chameleon Bus device driver
92 *
93 * @driver: device_driver
94 * @id_table: mcb id table
95 * @probe: probe callback
96 * @remove: remove callback
97 * @shutdown: shutdown callback
98 */
99struct mcb_driver {
100 struct device_driver driver;
101 const struct mcb_device_id *id_table;
102 int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id);
103 void (*remove)(struct mcb_device *mdev);
104 void (*shutdown)(struct mcb_device *mdev);
105};
Johannes Thumshirn68d96712016-08-26 09:34:59 +0200106
107static inline struct mcb_driver *to_mcb_driver(struct device_driver *drv)
108{
109 return container_of(drv, struct mcb_driver, driver);
110}
Johannes Thumshirn3764e822014-02-26 17:29:05 +0100111
112static inline void *mcb_get_drvdata(struct mcb_device *dev)
113{
114 return dev_get_drvdata(&dev->dev);
115}
116
117static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
118{
119 dev_set_drvdata(&dev->dev, data);
120}
121
122extern int __must_check __mcb_register_driver(struct mcb_driver *drv,
123 struct module *owner,
124 const char *mod_name);
125#define mcb_register_driver(driver) \
126 __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
127extern void mcb_unregister_driver(struct mcb_driver *driver);
128#define module_mcb_driver(__mcb_driver) \
129 module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver);
130extern void mcb_bus_add_devices(const struct mcb_bus *bus);
131extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +0200132extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
Johannes Thumshirn3764e822014-02-26 17:29:05 +0100133extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
134extern void mcb_bus_put(struct mcb_bus *bus);
135extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
136extern void mcb_free_dev(struct mcb_device *dev);
137extern void mcb_release_bus(struct mcb_bus *bus);
138extern struct resource *mcb_request_mem(struct mcb_device *dev,
139 const char *name);
140extern void mcb_release_mem(struct resource *mem);
141extern int mcb_get_irq(struct mcb_device *dev);
142
143#endif /* _LINUX_MCB_H */