0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __LINUX_GREYBUS_H
0010 #define __LINUX_GREYBUS_H
0011
0012 #ifdef __KERNEL__
0013
0014 #include <linux/kernel.h>
0015 #include <linux/types.h>
0016 #include <linux/list.h>
0017 #include <linux/slab.h>
0018 #include <linux/device.h>
0019 #include <linux/module.h>
0020 #include <linux/pm_runtime.h>
0021 #include <linux/idr.h>
0022
0023 #include <linux/greybus/greybus_id.h>
0024 #include <linux/greybus/greybus_manifest.h>
0025 #include <linux/greybus/greybus_protocols.h>
0026 #include <linux/greybus/manifest.h>
0027 #include <linux/greybus/hd.h>
0028 #include <linux/greybus/svc.h>
0029 #include <linux/greybus/control.h>
0030 #include <linux/greybus/module.h>
0031 #include <linux/greybus/interface.h>
0032 #include <linux/greybus/bundle.h>
0033 #include <linux/greybus/connection.h>
0034 #include <linux/greybus/operation.h>
0035
0036
0037 #define GREYBUS_VERSION_MAJOR 0x00
0038 #define GREYBUS_VERSION_MINOR 0x01
0039
0040 #define GREYBUS_ID_MATCH_DEVICE \
0041 (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT)
0042
0043 #define GREYBUS_DEVICE(v, p) \
0044 .match_flags = GREYBUS_ID_MATCH_DEVICE, \
0045 .vendor = (v), \
0046 .product = (p),
0047
0048 #define GREYBUS_DEVICE_CLASS(c) \
0049 .match_flags = GREYBUS_ID_MATCH_CLASS, \
0050 .class = (c),
0051
0052
0053 #define CPORT_ID_MAX 4095
0054 #define CPORT_ID_BAD U16_MAX
0055
0056 struct greybus_driver {
0057 const char *name;
0058
0059 int (*probe)(struct gb_bundle *bundle,
0060 const struct greybus_bundle_id *id);
0061 void (*disconnect)(struct gb_bundle *bundle);
0062
0063 const struct greybus_bundle_id *id_table;
0064
0065 struct device_driver driver;
0066 };
0067 #define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
0068
0069 static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data)
0070 {
0071 dev_set_drvdata(&bundle->dev, data);
0072 }
0073
0074 static inline void *greybus_get_drvdata(struct gb_bundle *bundle)
0075 {
0076 return dev_get_drvdata(&bundle->dev);
0077 }
0078
0079
0080 int greybus_register_driver(struct greybus_driver *driver,
0081 struct module *module, const char *mod_name);
0082 void greybus_deregister_driver(struct greybus_driver *driver);
0083
0084
0085 #define greybus_register(driver) \
0086 greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
0087 #define greybus_deregister(driver) \
0088 greybus_deregister_driver(driver)
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 #define module_greybus_driver(__greybus_driver) \
0099 module_driver(__greybus_driver, greybus_register, greybus_deregister)
0100
0101 int greybus_disabled(void);
0102
0103 void gb_debugfs_init(void);
0104 void gb_debugfs_cleanup(void);
0105 struct dentry *gb_debugfs_get(void);
0106
0107 extern struct bus_type greybus_bus_type;
0108
0109 extern struct device_type greybus_hd_type;
0110 extern struct device_type greybus_module_type;
0111 extern struct device_type greybus_interface_type;
0112 extern struct device_type greybus_control_type;
0113 extern struct device_type greybus_bundle_type;
0114 extern struct device_type greybus_svc_type;
0115
0116 static inline int is_gb_host_device(const struct device *dev)
0117 {
0118 return dev->type == &greybus_hd_type;
0119 }
0120
0121 static inline int is_gb_module(const struct device *dev)
0122 {
0123 return dev->type == &greybus_module_type;
0124 }
0125
0126 static inline int is_gb_interface(const struct device *dev)
0127 {
0128 return dev->type == &greybus_interface_type;
0129 }
0130
0131 static inline int is_gb_control(const struct device *dev)
0132 {
0133 return dev->type == &greybus_control_type;
0134 }
0135
0136 static inline int is_gb_bundle(const struct device *dev)
0137 {
0138 return dev->type == &greybus_bundle_type;
0139 }
0140
0141 static inline int is_gb_svc(const struct device *dev)
0142 {
0143 return dev->type == &greybus_svc_type;
0144 }
0145
0146 static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id)
0147 {
0148 return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports;
0149 }
0150
0151 #endif
0152 #endif