blob: 4097ac9ea13accda06500a7605a4ca8a3632112f [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 *
Johannes Thumshirn3764e822014-02-26 17:29:05 +010053 * @dev: device in kernel representation
54 * @bus: mcb bus the device is plugged to
Johannes Thumshirn3764e822014-02-26 17:29:05 +010055 * @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 */
66struct mcb_device {
Johannes Thumshirn3764e822014-02-26 17:29:05 +010067 struct device dev;
68 struct mcb_bus *bus;
Johannes Thumshirn3764e822014-02-26 17:29:05 +010069 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;
Michael Moese2d8784d2016-09-14 12:05:24 +020079 struct device *dma_dev;
Johannes Thumshirn3764e822014-02-26 17:29:05 +010080};
Johannes Thumshirn68d96712016-08-26 09:34:59 +020081
82static inline struct mcb_device *to_mcb_device(struct device *dev)
83{
84 return container_of(dev, struct mcb_device, dev);
85}
Johannes Thumshirn3764e822014-02-26 17:29:05 +010086
87/**
88 * struct mcb_driver - MEN Chameleon Bus device driver
89 *
90 * @driver: device_driver
91 * @id_table: mcb id table
92 * @probe: probe callback
93 * @remove: remove callback
94 * @shutdown: shutdown callback
95 */
96struct mcb_driver {
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);
102};
Johannes Thumshirn68d96712016-08-26 09:34:59 +0200103
104static inline struct mcb_driver *to_mcb_driver(struct device_driver *drv)
105{
106 return container_of(drv, struct mcb_driver, driver);
107}
Johannes Thumshirn3764e822014-02-26 17:29:05 +0100108
109static inline void *mcb_get_drvdata(struct mcb_device *dev)
110{
111 return dev_get_drvdata(&dev->dev);
112}
113
114static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
115{
116 dev_set_drvdata(&dev->dev, data);
117}
118
119extern 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)
124extern 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);
127extern void mcb_bus_add_devices(const struct mcb_bus *bus);
128extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
Johannes Thumshirn4ec65b72014-04-24 14:35:25 +0200129extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
Johannes Thumshirn3764e822014-02-26 17:29:05 +0100130extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
131extern void mcb_bus_put(struct mcb_bus *bus);
132extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
133extern void mcb_free_dev(struct mcb_device *dev);
134extern void mcb_release_bus(struct mcb_bus *bus);
135extern struct resource *mcb_request_mem(struct mcb_device *dev,
136 const char *name);
137extern void mcb_release_mem(struct resource *mem);
138extern int mcb_get_irq(struct mcb_device *dev);
139
140#endif /* _LINUX_MCB_H */