1 /* 2 * phy.h -- generic phy header file 3 * 4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 * 6 * Author: Kishon Vijay Abraham I <[email protected]> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 */ 13 14 #ifndef __DRIVERS_PHY_H 15 #define __DRIVERS_PHY_H 16 17 #include <linux/err.h> 18 #include <linux/of.h> 19 #include <linux/device.h> 20 #include <linux/pm_runtime.h> 21 22 struct phy; 23 24 /** 25 * struct phy_ops - set of function pointers for performing phy operations 26 * @init: operation to be performed for initializing phy 27 * @exit: operation to be performed while exiting 28 * @power_on: powering on the phy 29 * @power_off: powering off the phy 30 * @owner: the module owner containing the ops 31 */ 32 struct phy_ops { 33 int (*init)(struct phy *phy); 34 int (*exit)(struct phy *phy); 35 int (*power_on)(struct phy *phy); 36 int (*power_off)(struct phy *phy); 37 struct module *owner; 38 }; 39 40 /** 41 * struct phy - represents the phy device 42 * @dev: phy device 43 * @id: id of the phy device 44 * @ops: function pointers for performing phy operations 45 * @init_data: list of PHY consumers (non-dt only) 46 * @mutex: mutex to protect phy_ops 47 * @init_count: used to protect when the PHY is used by multiple consumers 48 * @power_count: used to protect when the PHY is used by multiple consumers 49 */ 50 struct phy { 51 struct device dev; 52 int id; 53 const struct phy_ops *ops; 54 struct phy_init_data *init_data; 55 struct mutex mutex; 56 int init_count; 57 int power_count; 58 }; 59 60 /** 61 * struct phy_provider - represents the phy provider 62 * @dev: phy provider device 63 * @owner: the module owner having of_xlate 64 * @of_xlate: function pointer to obtain phy instance from phy pointer 65 * @list: to maintain a linked list of PHY providers 66 */ 67 struct phy_provider { 68 struct device *dev; 69 struct module *owner; 70 struct list_head list; 71 struct phy * (*of_xlate)(struct device *dev, 72 struct of_phandle_args *args); 73 }; 74 75 /** 76 * struct phy_consumer - represents the phy consumer 77 * @dev_name: the device name of the controller that will use this PHY device 78 * @port: name given to the consumer port 79 */ 80 struct phy_consumer { 81 const char *dev_name; 82 const char *port; 83 }; 84 85 /** 86 * struct phy_init_data - contains the list of PHY consumers 87 * @num_consumers: number of consumers for this PHY device 88 * @consumers: list of PHY consumers 89 */ 90 struct phy_init_data { 91 unsigned int num_consumers; 92 struct phy_consumer *consumers; 93 }; 94 95 #define PHY_CONSUMER(_dev_name, _port) \ 96 { \ 97 .dev_name = _dev_name, \ 98 .port = _port, \ 99 } 100 101 #define to_phy(dev) (container_of((dev), struct phy, dev)) 102 103 #define of_phy_provider_register(dev, xlate) \ 104 __of_phy_provider_register((dev), THIS_MODULE, (xlate)) 105 106 #define devm_of_phy_provider_register(dev, xlate) \ 107 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) 108 109 static inline void phy_set_drvdata(struct phy *phy, void *data) 110 { 111 dev_set_drvdata(&phy->dev, data); 112 } 113 114 static inline void *phy_get_drvdata(struct phy *phy) 115 { 116 return dev_get_drvdata(&phy->dev); 117 } 118 119 #if IS_ENABLED(CONFIG_GENERIC_PHY) 120 int phy_pm_runtime_get(struct phy *phy); 121 int phy_pm_runtime_get_sync(struct phy *phy); 122 int phy_pm_runtime_put(struct phy *phy); 123 int phy_pm_runtime_put_sync(struct phy *phy); 124 void phy_pm_runtime_allow(struct phy *phy); 125 void phy_pm_runtime_forbid(struct phy *phy); 126 int phy_init(struct phy *phy); 127 int phy_exit(struct phy *phy); 128 int phy_power_on(struct phy *phy); 129 int phy_power_off(struct phy *phy); 130 struct phy *phy_get(struct device *dev, const char *string); 131 struct phy *devm_phy_get(struct device *dev, const char *string); 132 void phy_put(struct phy *phy); 133 void devm_phy_put(struct device *dev, struct phy *phy); 134 struct phy *of_phy_simple_xlate(struct device *dev, 135 struct of_phandle_args *args); 136 struct phy *phy_create(struct device *dev, const struct phy_ops *ops, 137 struct phy_init_data *init_data); 138 struct phy *devm_phy_create(struct device *dev, 139 const struct phy_ops *ops, struct phy_init_data *init_data); 140 void phy_destroy(struct phy *phy); 141 void devm_phy_destroy(struct device *dev, struct phy *phy); 142 struct phy_provider *__of_phy_provider_register(struct device *dev, 143 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 144 struct of_phandle_args *args)); 145 struct phy_provider *__devm_of_phy_provider_register(struct device *dev, 146 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 147 struct of_phandle_args *args)); 148 void of_phy_provider_unregister(struct phy_provider *phy_provider); 149 void devm_of_phy_provider_unregister(struct device *dev, 150 struct phy_provider *phy_provider); 151 #else 152 static inline int phy_pm_runtime_get(struct phy *phy) 153 { 154 return -ENOSYS; 155 } 156 157 static inline int phy_pm_runtime_get_sync(struct phy *phy) 158 { 159 return -ENOSYS; 160 } 161 162 static inline int phy_pm_runtime_put(struct phy *phy) 163 { 164 return -ENOSYS; 165 } 166 167 static inline int phy_pm_runtime_put_sync(struct phy *phy) 168 { 169 return -ENOSYS; 170 } 171 172 static inline void phy_pm_runtime_allow(struct phy *phy) 173 { 174 return; 175 } 176 177 static inline void phy_pm_runtime_forbid(struct phy *phy) 178 { 179 return; 180 } 181 182 static inline int phy_init(struct phy *phy) 183 { 184 return -ENOSYS; 185 } 186 187 static inline int phy_exit(struct phy *phy) 188 { 189 return -ENOSYS; 190 } 191 192 static inline int phy_power_on(struct phy *phy) 193 { 194 return -ENOSYS; 195 } 196 197 static inline int phy_power_off(struct phy *phy) 198 { 199 return -ENOSYS; 200 } 201 202 static inline struct phy *phy_get(struct device *dev, const char *string) 203 { 204 return ERR_PTR(-ENOSYS); 205 } 206 207 static inline struct phy *devm_phy_get(struct device *dev, const char *string) 208 { 209 return ERR_PTR(-ENOSYS); 210 } 211 212 static inline void phy_put(struct phy *phy) 213 { 214 } 215 216 static inline void devm_phy_put(struct device *dev, struct phy *phy) 217 { 218 } 219 220 static inline struct phy *of_phy_simple_xlate(struct device *dev, 221 struct of_phandle_args *args) 222 { 223 return ERR_PTR(-ENOSYS); 224 } 225 226 static inline struct phy *phy_create(struct device *dev, 227 const struct phy_ops *ops, struct phy_init_data *init_data) 228 { 229 return ERR_PTR(-ENOSYS); 230 } 231 232 static inline struct phy *devm_phy_create(struct device *dev, 233 const struct phy_ops *ops, struct phy_init_data *init_data) 234 { 235 return ERR_PTR(-ENOSYS); 236 } 237 238 static inline void phy_destroy(struct phy *phy) 239 { 240 } 241 242 static inline void devm_phy_destroy(struct device *dev, struct phy *phy) 243 { 244 } 245 246 static inline struct phy_provider *__of_phy_provider_register( 247 struct device *dev, struct module *owner, struct phy * (*of_xlate)( 248 struct device *dev, struct of_phandle_args *args)) 249 { 250 return ERR_PTR(-ENOSYS); 251 } 252 253 static inline struct phy_provider *__devm_of_phy_provider_register(struct device 254 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev, 255 struct of_phandle_args *args)) 256 { 257 return ERR_PTR(-ENOSYS); 258 } 259 260 static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) 261 { 262 } 263 264 static inline void devm_of_phy_provider_unregister(struct device *dev, 265 struct phy_provider *phy_provider) 266 { 267 } 268 #endif 269 270 #endif /* __DRIVERS_PHY_H */ 271