Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 1 | /* |
| 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 Thumshirn | 803f1ca | 2016-05-03 09:46:23 +0200 | [diff] [blame] | 18 | #define CHAMELEON_FILENAME_LEN 12 |
| 19 | |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 20 | struct mcb_driver; |
Johannes Thumshirn | 4ec65b7 | 2014-04-24 14:35:25 +0200 | [diff] [blame] | 21 | struct mcb_device; |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * struct mcb_bus - MEN Chameleon Bus |
| 25 | * |
Johannes Thumshirn | 18d2881 | 2016-05-03 09:46:22 +0200 | [diff] [blame] | 26 | * @dev: bus device |
| 27 | * @carrier: pointer to carrier device |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 28 | * @bus_nr: mcb bus number |
Johannes Thumshirn | 4ec65b7 | 2014-04-24 14:35:25 +0200 | [diff] [blame] | 29 | * @get_irq: callback to get IRQ number |
Johannes Thumshirn | 803f1ca | 2016-05-03 09:46:23 +0200 | [diff] [blame] | 30 | * @revision: the FPGA's revision number |
| 31 | * @model: the FPGA's model number |
| 32 | * @filename: the FPGA's name |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 33 | */ |
| 34 | struct mcb_bus { |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 35 | struct device dev; |
Johannes Thumshirn | 4ec65b7 | 2014-04-24 14:35:25 +0200 | [diff] [blame] | 36 | struct device *carrier; |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 37 | int bus_nr; |
Johannes Thumshirn | 803f1ca | 2016-05-03 09:46:23 +0200 | [diff] [blame] | 38 | u8 revision; |
| 39 | char model; |
| 40 | u8 minor; |
| 41 | char name[CHAMELEON_FILENAME_LEN + 1]; |
Johannes Thumshirn | 4ec65b7 | 2014-04-24 14:35:25 +0200 | [diff] [blame] | 42 | int (*get_irq)(struct mcb_device *dev); |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 43 | }; |
| 44 | #define to_mcb_bus(b) container_of((b), struct mcb_bus, dev) |
| 45 | |
| 46 | /** |
| 47 | * struct mcb_device - MEN Chameleon Bus device |
| 48 | * |
| 49 | * @bus_list: internal list handling for bus code |
| 50 | * @dev: device in kernel representation |
| 51 | * @bus: mcb bus the device is plugged to |
| 52 | * @subordinate: subordinate MCBus in case of bridge |
| 53 | * @is_added: flag to check if device is added to bus |
| 54 | * @driver: associated mcb_driver |
| 55 | * @id: mcb device id |
| 56 | * @inst: instance in Chameleon table |
| 57 | * @group: group in Chameleon table |
| 58 | * @var: variant in Chameleon table |
| 59 | * @bar: BAR in Chameleon table |
| 60 | * @rev: revision in Chameleon table |
| 61 | * @irq: IRQ resource |
| 62 | * @memory: memory resource |
| 63 | */ |
| 64 | struct mcb_device { |
| 65 | struct list_head bus_list; |
| 66 | struct device dev; |
| 67 | struct mcb_bus *bus; |
| 68 | struct mcb_bus *subordinate; |
| 69 | 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; |
| 79 | }; |
| 80 | #define to_mcb_device(x) container_of((x), struct mcb_device, dev) |
| 81 | |
| 82 | /** |
| 83 | * struct mcb_driver - MEN Chameleon Bus device driver |
| 84 | * |
| 85 | * @driver: device_driver |
| 86 | * @id_table: mcb id table |
| 87 | * @probe: probe callback |
| 88 | * @remove: remove callback |
| 89 | * @shutdown: shutdown callback |
| 90 | */ |
| 91 | struct mcb_driver { |
| 92 | struct device_driver driver; |
| 93 | const struct mcb_device_id *id_table; |
| 94 | int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id); |
| 95 | void (*remove)(struct mcb_device *mdev); |
| 96 | void (*shutdown)(struct mcb_device *mdev); |
| 97 | }; |
| 98 | #define to_mcb_driver(x) container_of((x), struct mcb_driver, driver) |
| 99 | |
| 100 | static inline void *mcb_get_drvdata(struct mcb_device *dev) |
| 101 | { |
| 102 | return dev_get_drvdata(&dev->dev); |
| 103 | } |
| 104 | |
| 105 | static inline void mcb_set_drvdata(struct mcb_device *dev, void *data) |
| 106 | { |
| 107 | dev_set_drvdata(&dev->dev, data); |
| 108 | } |
| 109 | |
| 110 | extern int __must_check __mcb_register_driver(struct mcb_driver *drv, |
| 111 | struct module *owner, |
| 112 | const char *mod_name); |
| 113 | #define mcb_register_driver(driver) \ |
| 114 | __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) |
| 115 | extern void mcb_unregister_driver(struct mcb_driver *driver); |
| 116 | #define module_mcb_driver(__mcb_driver) \ |
| 117 | module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver); |
| 118 | extern void mcb_bus_add_devices(const struct mcb_bus *bus); |
| 119 | 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] | 120 | extern struct mcb_bus *mcb_alloc_bus(struct device *carrier); |
Johannes Thumshirn | 3764e82 | 2014-02-26 17:29:05 +0100 | [diff] [blame] | 121 | extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus); |
| 122 | extern void mcb_bus_put(struct mcb_bus *bus); |
| 123 | extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus); |
| 124 | extern void mcb_free_dev(struct mcb_device *dev); |
| 125 | extern void mcb_release_bus(struct mcb_bus *bus); |
| 126 | extern struct resource *mcb_request_mem(struct mcb_device *dev, |
| 127 | const char *name); |
| 128 | extern void mcb_release_mem(struct resource *mem); |
| 129 | extern int mcb_get_irq(struct mcb_device *dev); |
| 130 | |
| 131 | #endif /* _LINUX_MCB_H */ |