linux/drivers/staging/greybus/greybus.h
<<
>>
Prefs
   1/*
   2 * Greybus driver and device API
   3 *
   4 * Copyright 2014-2015 Google Inc.
   5 * Copyright 2014-2015 Linaro Ltd.
   6 *
   7 * Released under the GPLv2 only.
   8 */
   9
  10#ifndef __LINUX_GREYBUS_H
  11#define __LINUX_GREYBUS_H
  12
  13#ifdef __KERNEL__
  14
  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/pm_runtime.h>
  22#include <linux/idr.h>
  23
  24#include "greybus_id.h"
  25#include "greybus_manifest.h"
  26#include "greybus_protocols.h"
  27#include "manifest.h"
  28#include "hd.h"
  29#include "svc.h"
  30#include "control.h"
  31#include "module.h"
  32#include "interface.h"
  33#include "bundle.h"
  34#include "connection.h"
  35#include "operation.h"
  36#include "timesync.h"
  37
  38/* Matches up with the Greybus Protocol specification document */
  39#define GREYBUS_VERSION_MAJOR   0x00
  40#define GREYBUS_VERSION_MINOR   0x01
  41
  42#define GREYBUS_ID_MATCH_DEVICE \
  43        (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT)
  44
  45#define GREYBUS_DEVICE(v, p)                                    \
  46        .match_flags    = GREYBUS_ID_MATCH_DEVICE,              \
  47        .vendor         = (v),                                  \
  48        .product        = (p),
  49
  50#define GREYBUS_DEVICE_CLASS(c)                                 \
  51        .match_flags    = GREYBUS_ID_MATCH_CLASS,               \
  52        .class          = (c),
  53
  54/* Maximum number of CPorts */
  55#define CPORT_ID_MAX    4095            /* UniPro max id is 4095 */
  56#define CPORT_ID_BAD    U16_MAX
  57
  58struct greybus_driver {
  59        const char *name;
  60
  61        int (*probe)(struct gb_bundle *bundle,
  62                     const struct greybus_bundle_id *id);
  63        void (*disconnect)(struct gb_bundle *bundle);
  64
  65        const struct greybus_bundle_id *id_table;
  66
  67        struct device_driver driver;
  68};
  69#define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
  70
  71static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data)
  72{
  73        dev_set_drvdata(&bundle->dev, data);
  74}
  75
  76static inline void *greybus_get_drvdata(struct gb_bundle *bundle)
  77{
  78        return dev_get_drvdata(&bundle->dev);
  79}
  80
  81/* Don't call these directly, use the module_greybus_driver() macro instead */
  82int greybus_register_driver(struct greybus_driver *driver,
  83                            struct module *module, const char *mod_name);
  84void greybus_deregister_driver(struct greybus_driver *driver);
  85
  86/* define to get proper THIS_MODULE and KBUILD_MODNAME values */
  87#define greybus_register(driver) \
  88        greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
  89#define greybus_deregister(driver) \
  90        greybus_deregister_driver(driver)
  91
  92/**
  93 * module_greybus_driver() - Helper macro for registering a Greybus driver
  94 * @__greybus_driver: greybus_driver structure
  95 *
  96 * Helper macro for Greybus drivers to set up proper module init / exit
  97 * functions.  Replaces module_init() and module_exit() and keeps people from
  98 * printing pointless things to the kernel log when their driver is loaded.
  99 */
 100#define module_greybus_driver(__greybus_driver) \
 101        module_driver(__greybus_driver, greybus_register, greybus_deregister)
 102
 103int greybus_disabled(void);
 104
 105void gb_debugfs_init(void);
 106void gb_debugfs_cleanup(void);
 107struct dentry *gb_debugfs_get(void);
 108
 109extern struct bus_type greybus_bus_type;
 110
 111extern struct device_type greybus_hd_type;
 112extern struct device_type greybus_module_type;
 113extern struct device_type greybus_interface_type;
 114extern struct device_type greybus_control_type;
 115extern struct device_type greybus_bundle_type;
 116extern struct device_type greybus_svc_type;
 117
 118static inline int is_gb_host_device(const struct device *dev)
 119{
 120        return dev->type == &greybus_hd_type;
 121}
 122
 123static inline int is_gb_module(const struct device *dev)
 124{
 125        return dev->type == &greybus_module_type;
 126}
 127
 128static inline int is_gb_interface(const struct device *dev)
 129{
 130        return dev->type == &greybus_interface_type;
 131}
 132
 133static inline int is_gb_control(const struct device *dev)
 134{
 135        return dev->type == &greybus_control_type;
 136}
 137
 138static inline int is_gb_bundle(const struct device *dev)
 139{
 140        return dev->type == &greybus_bundle_type;
 141}
 142
 143static inline int is_gb_svc(const struct device *dev)
 144{
 145        return dev->type == &greybus_svc_type;
 146}
 147
 148static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id)
 149{
 150        return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports;
 151}
 152
 153#endif /* __KERNEL__ */
 154#endif /* __LINUX_GREYBUS_H */
 155