Blame view

include/linux/mcb.h 3.79 KB
3764e82e5   Johannes Thumshirn   drivers: Introduc...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   * MEN Chameleon Bus.
   *
   * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
   * Author: Johannes Thumshirn <johannes.thumshirn@men.de>
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the Free
   * Software Foundation; version 2 of the License.
   */
  #ifndef _LINUX_MCB_H
  #define _LINUX_MCB_H
  
  #include <linux/mod_devicetable.h>
  #include <linux/device.h>
  #include <linux/irqreturn.h>
803f1ca60   Johannes Thumshirn   mcb: export bus i...
17
  #define CHAMELEON_FILENAME_LEN 12
3764e82e5   Johannes Thumshirn   drivers: Introduc...
18
  struct mcb_driver;
4ec65b77c   Johannes Thumshirn   mcb: Add support ...
19
  struct mcb_device;
3764e82e5   Johannes Thumshirn   drivers: Introduc...
20
21
22
23
  
  /**
   * struct mcb_bus - MEN Chameleon Bus
   *
18d288198   Johannes Thumshirn   mcb: Correctly in...
24
25
   * @dev: bus device
   * @carrier: pointer to carrier device
3764e82e5   Johannes Thumshirn   drivers: Introduc...
26
   * @bus_nr: mcb bus number
4ec65b77c   Johannes Thumshirn   mcb: Add support ...
27
   * @get_irq: callback to get IRQ number
803f1ca60   Johannes Thumshirn   mcb: export bus i...
28
29
30
   * @revision: the FPGA's revision number
   * @model: the FPGA's model number
   * @filename: the FPGA's name
3764e82e5   Johannes Thumshirn   drivers: Introduc...
31
32
   */
  struct mcb_bus {
3764e82e5   Johannes Thumshirn   drivers: Introduc...
33
  	struct device dev;
4ec65b77c   Johannes Thumshirn   mcb: Add support ...
34
  	struct device *carrier;
3764e82e5   Johannes Thumshirn   drivers: Introduc...
35
  	int bus_nr;
803f1ca60   Johannes Thumshirn   mcb: export bus i...
36
37
38
39
  	u8 revision;
  	char model;
  	u8 minor;
  	char name[CHAMELEON_FILENAME_LEN + 1];
4ec65b77c   Johannes Thumshirn   mcb: Add support ...
40
  	int (*get_irq)(struct mcb_device *dev);
3764e82e5   Johannes Thumshirn   drivers: Introduc...
41
  };
68d9671a8   Johannes Thumshirn   mcb: Introduce ty...
42
43
44
45
46
  
  static inline struct mcb_bus *to_mcb_bus(struct device *dev)
  {
  	return container_of(dev, struct mcb_bus, dev);
  }
3764e82e5   Johannes Thumshirn   drivers: Introduc...
47
48
49
50
  
  /**
   * struct mcb_device - MEN Chameleon Bus device
   *
3764e82e5   Johannes Thumshirn   drivers: Introduc...
51
52
   * @dev: device in kernel representation
   * @bus: mcb bus the device is plugged to
3764e82e5   Johannes Thumshirn   drivers: Introduc...
53
54
55
56
57
58
59
60
61
62
63
64
   * @is_added: flag to check if device is added to bus
   * @driver: associated mcb_driver
   * @id: mcb device id
   * @inst: instance in Chameleon table
   * @group: group in Chameleon table
   * @var: variant in Chameleon table
   * @bar: BAR in Chameleon table
   * @rev: revision in Chameleon table
   * @irq: IRQ resource
   * @memory: memory resource
   */
  struct mcb_device {
3764e82e5   Johannes Thumshirn   drivers: Introduc...
65
66
  	struct device dev;
  	struct mcb_bus *bus;
3764e82e5   Johannes Thumshirn   drivers: Introduc...
67
68
69
70
71
72
73
74
75
76
  	bool is_added;
  	struct mcb_driver *driver;
  	u16 id;
  	int inst;
  	int group;
  	int var;
  	int bar;
  	int rev;
  	struct resource irq;
  	struct resource mem;
2d8784df1   Michael Moese   mcb: Add a dma_de...
77
  	struct device *dma_dev;
3764e82e5   Johannes Thumshirn   drivers: Introduc...
78
  };
68d9671a8   Johannes Thumshirn   mcb: Introduce ty...
79
80
81
82
83
  
  static inline struct mcb_device *to_mcb_device(struct device *dev)
  {
  	return container_of(dev, struct mcb_device, dev);
  }
3764e82e5   Johannes Thumshirn   drivers: Introduc...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  
  /**
   * struct mcb_driver - MEN Chameleon Bus device driver
   *
   * @driver: device_driver
   * @id_table: mcb id table
   * @probe: probe callback
   * @remove: remove callback
   * @shutdown: shutdown callback
   */
  struct mcb_driver {
  	struct device_driver driver;
  	const struct mcb_device_id *id_table;
  	int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id);
  	void (*remove)(struct mcb_device *mdev);
  	void (*shutdown)(struct mcb_device *mdev);
  };
68d9671a8   Johannes Thumshirn   mcb: Introduce ty...
101
102
103
104
105
  
  static inline struct mcb_driver *to_mcb_driver(struct device_driver *drv)
  {
  	return container_of(drv, struct mcb_driver, driver);
  }
3764e82e5   Johannes Thumshirn   drivers: Introduc...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  
  static inline void *mcb_get_drvdata(struct mcb_device *dev)
  {
  	return dev_get_drvdata(&dev->dev);
  }
  
  static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
  {
  	dev_set_drvdata(&dev->dev, data);
  }
  
  extern int __must_check __mcb_register_driver(struct mcb_driver *drv,
  					struct module *owner,
  					const char *mod_name);
  #define mcb_register_driver(driver)		\
  	__mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
  extern void mcb_unregister_driver(struct mcb_driver *driver);
  #define module_mcb_driver(__mcb_driver)		\
  	module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver);
  extern void mcb_bus_add_devices(const struct mcb_bus *bus);
  extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
4ec65b77c   Johannes Thumshirn   mcb: Add support ...
127
  extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
3764e82e5   Johannes Thumshirn   drivers: Introduc...
128
129
130
131
132
133
134
135
136
137
138
  extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
  extern void mcb_bus_put(struct mcb_bus *bus);
  extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
  extern void mcb_free_dev(struct mcb_device *dev);
  extern void mcb_release_bus(struct mcb_bus *bus);
  extern struct resource *mcb_request_mem(struct mcb_device *dev,
  					const char *name);
  extern void mcb_release_mem(struct resource *mem);
  extern int mcb_get_irq(struct mcb_device *dev);
  
  #endif /* _LINUX_MCB_H */