2 * Greybus driver and device API
4 * Copyright 2014-2015 Google Inc.
5 * Copyright 2014-2015 Linaro Ltd.
7 * Released under the GPLv2 only.
10 #ifndef __LINUX_GREYBUS_H
11 #define __LINUX_GREYBUS_H
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/list.h>
18 #include <linux/slab.h>
19 #include <linux/device.h>
20 #include <linux/module.h>
21 #include <linux/idr.h>
23 #include "kernel_ver.h"
24 #include "greybus_id.h"
25 #include "greybus_manifest.h"
26 #include "greybus_protocols.h"
32 #include "interface.h"
34 #include "connection.h"
36 #include "operation.h"
39 /* Matches up with the Greybus Protocol specification document */
40 #define GREYBUS_VERSION_MAJOR 0x00
41 #define GREYBUS_VERSION_MINOR 0x01
43 #define GREYBUS_ID_MATCH_DEVICE \
44 (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT)
46 #define GREYBUS_DEVICE(v, p) \
47 .match_flags = GREYBUS_ID_MATCH_DEVICE, \
51 #define GREYBUS_DEVICE_CLASS(c) \
52 .match_flags = GREYBUS_ID_MATCH_CLASS, \
55 /* Maximum number of CPorts */
56 #define CPORT_ID_MAX 4095 /* UniPro max id is 4095 */
57 #define CPORT_ID_BAD U16_MAX
59 struct greybus_driver {
62 int (*probe)(struct gb_bundle *bundle,
63 const struct greybus_bundle_id *id);
64 void (*disconnect)(struct gb_bundle *bundle);
66 int (*suspend)(struct gb_bundle *bundle, pm_message_t message);
67 int (*resume)(struct gb_bundle *bundle);
69 const struct greybus_bundle_id *id_table;
71 struct device_driver driver;
73 #define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
75 static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data)
77 dev_set_drvdata(&bundle->dev, data);
80 static inline void *greybus_get_drvdata(struct gb_bundle *bundle)
82 return dev_get_drvdata(&bundle->dev);
85 /* Don't call these directly, use the module_greybus_driver() macro instead */
86 int greybus_register_driver(struct greybus_driver *driver,
87 struct module *module, const char *mod_name);
88 void greybus_deregister_driver(struct greybus_driver *driver);
90 /* define to get proper THIS_MODULE and KBUILD_MODNAME values */
91 #define greybus_register(driver) \
92 greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
93 #define greybus_deregister(driver) \
94 greybus_deregister_driver(driver)
97 * module_greybus_driver() - Helper macro for registering a Greybus driver
98 * @__greybus_driver: greybus_driver structure
100 * Helper macro for Greybus drivers to set up proper module init / exit
101 * functions. Replaces module_init() and module_exit() and keeps people from
102 * printing pointless things to the kernel log when their driver is loaded.
104 #define module_greybus_driver(__greybus_driver) \
105 module_driver(__greybus_driver, greybus_register, greybus_deregister)
107 int greybus_disabled(void);
109 void gb_debugfs_init(void);
110 void gb_debugfs_cleanup(void);
111 struct dentry *gb_debugfs_get(void);
113 extern struct bus_type greybus_bus_type;
115 extern struct device_type greybus_hd_type;
116 extern struct device_type greybus_interface_type;
117 extern struct device_type greybus_bundle_type;
118 extern struct device_type greybus_svc_type;
120 static inline int is_gb_host_device(const struct device *dev)
122 return dev->type == &greybus_hd_type;
125 static inline int is_gb_interface(const struct device *dev)
127 return dev->type == &greybus_interface_type;
130 static inline int is_gb_bundle(const struct device *dev)
132 return dev->type == &greybus_bundle_type;
135 static inline int is_gb_svc(const struct device *dev)
137 return dev->type == &greybus_svc_type;
140 static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id)
142 return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports;
145 #endif /* __KERNEL__ */
146 #endif /* __LINUX_GREYBUS_H */