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