Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Greybus Bridged-Phy Bus driver
0004  *
0005  * Copyright 2016 Google Inc.
0006  */
0007 
0008 #ifndef __GBPHY_H
0009 #define __GBPHY_H
0010 
0011 struct gbphy_device {
0012     u32 id;
0013     struct greybus_descriptor_cport *cport_desc;
0014     struct gb_bundle *bundle;
0015     struct list_head list;
0016     struct device dev;
0017 };
0018 #define to_gbphy_dev(d) container_of(d, struct gbphy_device, dev)
0019 
0020 static inline void *gb_gbphy_get_data(struct gbphy_device *gdev)
0021 {
0022     return dev_get_drvdata(&gdev->dev);
0023 }
0024 
0025 static inline void gb_gbphy_set_data(struct gbphy_device *gdev, void *data)
0026 {
0027     dev_set_drvdata(&gdev->dev, data);
0028 }
0029 
0030 struct gbphy_device_id {
0031     __u8 protocol_id;
0032 };
0033 
0034 #define GBPHY_PROTOCOL(p)       \
0035     .protocol_id    = (p),
0036 
0037 struct gbphy_driver {
0038     const char *name;
0039     int (*probe)(struct gbphy_device *device,
0040              const struct gbphy_device_id *id);
0041     void (*remove)(struct gbphy_device *device);
0042     const struct gbphy_device_id *id_table;
0043 
0044     struct device_driver driver;
0045 };
0046 #define to_gbphy_driver(d) container_of(d, struct gbphy_driver, driver)
0047 
0048 int gb_gbphy_register_driver(struct gbphy_driver *driver,
0049                  struct module *owner, const char *mod_name);
0050 void gb_gbphy_deregister_driver(struct gbphy_driver *driver);
0051 
0052 #define gb_gbphy_register(driver) \
0053     gb_gbphy_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
0054 #define gb_gbphy_deregister(driver) \
0055     gb_gbphy_deregister_driver(driver)
0056 
0057 /**
0058  * module_gbphy_driver() - Helper macro for registering a gbphy driver
0059  * @__gbphy_driver: gbphy_driver structure
0060  *
0061  * Helper macro for gbphy drivers to set up proper module init / exit
0062  * functions.  Replaces module_init() and module_exit() and keeps people from
0063  * printing pointless things to the kernel log when their driver is loaded.
0064  */
0065 #define module_gbphy_driver(__gbphy_driver) \
0066     module_driver(__gbphy_driver, gb_gbphy_register, gb_gbphy_deregister)
0067 
0068 #ifdef CONFIG_PM
0069 static inline int gbphy_runtime_get_sync(struct gbphy_device *gbphy_dev)
0070 {
0071     struct device *dev = &gbphy_dev->dev;
0072     int ret;
0073 
0074     ret = pm_runtime_get_sync(dev);
0075     if (ret < 0) {
0076         dev_err(dev, "pm_runtime_get_sync failed: %d\n", ret);
0077         pm_runtime_put_noidle(dev);
0078         return ret;
0079     }
0080 
0081     return 0;
0082 }
0083 
0084 static inline void gbphy_runtime_put_autosuspend(struct gbphy_device *gbphy_dev)
0085 {
0086     struct device *dev = &gbphy_dev->dev;
0087 
0088     pm_runtime_mark_last_busy(dev);
0089     pm_runtime_put_autosuspend(dev);
0090 }
0091 
0092 static inline void gbphy_runtime_get_noresume(struct gbphy_device *gbphy_dev)
0093 {
0094     pm_runtime_get_noresume(&gbphy_dev->dev);
0095 }
0096 
0097 static inline void gbphy_runtime_put_noidle(struct gbphy_device *gbphy_dev)
0098 {
0099     pm_runtime_put_noidle(&gbphy_dev->dev);
0100 }
0101 #else
0102 static inline int gbphy_runtime_get_sync(struct gbphy_device *gbphy_dev) { return 0; }
0103 static inline void gbphy_runtime_put_autosuspend(struct gbphy_device *gbphy_dev) {}
0104 static inline void gbphy_runtime_get_noresume(struct gbphy_device *gbphy_dev) {}
0105 static inline void gbphy_runtime_put_noidle(struct gbphy_device *gbphy_dev) {}
0106 #endif
0107 
0108 #endif /* __GBPHY_H */
0109