Blame view

include/linux/greybus.h 4.14 KB
baeeb02cc   Greg Kroah-Hartman   staging: greybus:...
1
  /* SPDX-License-Identifier: GPL-2.0 */
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
2
3
4
  /*
   * Greybus driver and device API
   *
4441f4759   Alex Elder   greybus: update c...
5
6
   * Copyright 2014-2015 Google Inc.
   * Copyright 2014-2015 Linaro Ltd.
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
7
8
9
10
11
12
   */
  
  #ifndef __LINUX_GREYBUS_H
  #define __LINUX_GREYBUS_H
  
  #ifdef __KERNEL__
e1e9dbddf   Alex Elder   greybus: isolate ...
13
  #include <linux/kernel.h>
6dca7b97c   Greg Kroah-Hartman   greybus: get fiel...
14
  #include <linux/types.h>
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
15
  #include <linux/list.h>
e1e9dbddf   Alex Elder   greybus: isolate ...
16
  #include <linux/slab.h>
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
17
18
  #include <linux/device.h>
  #include <linux/module.h>
30a3bf7b3   David Lin   greybus: interfac...
19
  #include <linux/pm_runtime.h>
177404bd2   Alex Elder   greybus: use ida ...
20
  #include <linux/idr.h>
e1e9dbddf   Alex Elder   greybus: isolate ...
21

ec0ad8681   Greg Kroah-Hartman   staging: greybus:...
22
23
24
25
26
27
28
29
30
31
32
33
  #include <linux/greybus/greybus_id.h>
  #include <linux/greybus/greybus_manifest.h>
  #include <linux/greybus/greybus_protocols.h>
  #include <linux/greybus/manifest.h>
  #include <linux/greybus/hd.h>
  #include <linux/greybus/svc.h>
  #include <linux/greybus/control.h>
  #include <linux/greybus/module.h>
  #include <linux/greybus/interface.h>
  #include <linux/greybus/bundle.h>
  #include <linux/greybus/connection.h>
  #include <linux/greybus/operation.h>
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
34

8c53e073f   Greg Kroah-Hartman   greybus: AP: move...
35
  /* Matches up with the Greybus Protocol specification document */
52adb5634   Matt Porter   greybus: update G...
36
37
  #define GREYBUS_VERSION_MAJOR	0x00
  #define GREYBUS_VERSION_MINOR	0x01
8c53e073f   Greg Kroah-Hartman   greybus: AP: move...
38

358e9400f   Johan Hovold   greybus: fix bund...
39
40
  #define GREYBUS_ID_MATCH_DEVICE \
  	(GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT)
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
41

6dca7b97c   Greg Kroah-Hartman   greybus: get fiel...
42
  #define GREYBUS_DEVICE(v, p)					\
358e9400f   Johan Hovold   greybus: fix bund...
43
  	.match_flags	= GREYBUS_ID_MATCH_DEVICE,		\
6dca7b97c   Greg Kroah-Hartman   greybus: get fiel...
44
45
  	.vendor		= (v),					\
  	.product	= (p),
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
46

3823c6147   Johan Hovold   greybus: add clas...
47
48
49
  #define GREYBUS_DEVICE_CLASS(c)					\
  	.match_flags	= GREYBUS_ID_MATCH_CLASS,		\
  	.class		= (c),
1dc539226   Johan Hovold   greybus: fix cpor...
50
51
52
  /* Maximum number of CPorts */
  #define CPORT_ID_MAX	4095		/* UniPro max id is 4095 */
  #define CPORT_ID_BAD	U16_MAX
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
53

c8a797a98   Greg Kroah-Hartman   greybus: Import m...
54
55
  struct greybus_driver {
  	const char *name;
9f5f30e71   Viresh Kumar   greybus: driver c...
56
57
58
  	int (*probe)(struct gb_bundle *bundle,
  		     const struct greybus_bundle_id *id);
  	void (*disconnect)(struct gb_bundle *bundle);
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
59

9f5f30e71   Viresh Kumar   greybus: driver c...
60
  	const struct greybus_bundle_id *id_table;
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
61
62
63
64
  
  	struct device_driver driver;
  };
  #define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
13da9e11e   Johan Hovold   greybus: core: ad...
65
66
67
68
69
70
71
72
73
  static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data)
  {
  	dev_set_drvdata(&bundle->dev, data);
  }
  
  static inline void *greybus_get_drvdata(struct gb_bundle *bundle)
  {
  	return dev_get_drvdata(&bundle->dev);
  }
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
74
75
76
  /* Don't call these directly, use the module_greybus_driver() macro instead */
  int greybus_register_driver(struct greybus_driver *driver,
  			    struct module *module, const char *mod_name);
fd1c2e541   Alex Elder   greybus: core: re...
77
  void greybus_deregister_driver(struct greybus_driver *driver);
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
78
79
80
81
  
  /* define to get proper THIS_MODULE and KBUILD_MODNAME values */
  #define greybus_register(driver) \
  	greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
fd1c2e541   Alex Elder   greybus: core: re...
82
83
  #define greybus_deregister(driver) \
  	greybus_deregister_driver(driver)
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
84
85
86
87
88
89
90
91
92
93
94
  
  /**
   * module_greybus_driver() - Helper macro for registering a Greybus driver
   * @__greybus_driver: greybus_driver structure
   *
   * Helper macro for Greybus drivers to set up proper module init / exit
   * functions.  Replaces module_init() and module_exit() and keeps people from
   * printing pointless things to the kernel log when their driver is loaded.
   */
  #define module_greybus_driver(__greybus_driver)	\
  	module_driver(__greybus_driver, greybus_register, greybus_deregister)
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
95
  int greybus_disabled(void);
3d0421e0a   Greg Kroah-Hartman   greybus: remove _...
96
  void gb_debugfs_init(void);
de536e309   Greg Kroah-Hartman   greybus: ap messa...
97
  void gb_debugfs_cleanup(void);
e8f824b65   Alexandre Bailon   greybus: Export g...
98
  struct dentry *gb_debugfs_get(void);
de536e309   Greg Kroah-Hartman   greybus: ap messa...
99

f0f61b904   Greg Kroah-Hartman   greybus: hook up ...
100
  extern struct bus_type greybus_bus_type;
06340efb7   Greg Kroah-Hartman   greybus: split sy...
101

2adaefb14   Johan Hovold   greybus: hd: make...
102
  extern struct device_type greybus_hd_type;
b15d97d77   Johan Hovold   greybus: core: ad...
103
  extern struct device_type greybus_module_type;
4ab9b3c24   Greg Kroah-Hartman   greybus: interfac...
104
  extern struct device_type greybus_interface_type;
a6e5b014b   Johan Hovold   greybus: core: ma...
105
  extern struct device_type greybus_control_type;
1db0a5ff3   Greg Kroah-Hartman   greybus: bundle: ...
106
  extern struct device_type greybus_bundle_type;
88f7b96da   Johan Hovold   greybus: svc: reg...
107
  extern struct device_type greybus_svc_type;
0ac5a8388   Greg Kroah-Hartman   greybus: skeleton...
108

2adaefb14   Johan Hovold   greybus: hd: make...
109
110
111
112
  static inline int is_gb_host_device(const struct device *dev)
  {
  	return dev->type == &greybus_hd_type;
  }
b15d97d77   Johan Hovold   greybus: core: ad...
113
114
115
116
  static inline int is_gb_module(const struct device *dev)
  {
  	return dev->type == &greybus_module_type;
  }
4ab9b3c24   Greg Kroah-Hartman   greybus: interfac...
117
  static inline int is_gb_interface(const struct device *dev)
0ac5a8388   Greg Kroah-Hartman   greybus: skeleton...
118
  {
4ab9b3c24   Greg Kroah-Hartman   greybus: interfac...
119
  	return dev->type == &greybus_interface_type;
0ac5a8388   Greg Kroah-Hartman   greybus: skeleton...
120
  }
a6e5b014b   Johan Hovold   greybus: core: ma...
121
122
123
124
  static inline int is_gb_control(const struct device *dev)
  {
  	return dev->type == &greybus_control_type;
  }
1db0a5ff3   Greg Kroah-Hartman   greybus: bundle: ...
125
  static inline int is_gb_bundle(const struct device *dev)
0ac5a8388   Greg Kroah-Hartman   greybus: skeleton...
126
  {
1db0a5ff3   Greg Kroah-Hartman   greybus: bundle: ...
127
  	return dev->type == &greybus_bundle_type;
0ac5a8388   Greg Kroah-Hartman   greybus: skeleton...
128
  }
88f7b96da   Johan Hovold   greybus: svc: reg...
129
130
131
132
  static inline int is_gb_svc(const struct device *dev)
  {
  	return dev->type == &greybus_svc_type;
  }
2537636ab   Johan Hovold   greybus: hd: rena...
133
  static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id)
821c620af   Alex Elder   greybus: introduc...
134
  {
144670c2a   Fabien Parent   greybus: add num_...
135
  	return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports;
821c620af   Alex Elder   greybus: introduc...
136
  }
c8a797a98   Greg Kroah-Hartman   greybus: Import m...
137
138
  #endif /* __KERNEL__ */
  #endif /* __LINUX_GREYBUS_H */