at v3.17 8.8 kB view raw
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 <kishon@ti.com> 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#include <linux/regulator/consumer.h> 22 23struct phy; 24 25/** 26 * struct phy_ops - set of function pointers for performing phy operations 27 * @init: operation to be performed for initializing phy 28 * @exit: operation to be performed while exiting 29 * @power_on: powering on the phy 30 * @power_off: powering off the phy 31 * @owner: the module owner containing the ops 32 */ 33struct phy_ops { 34 int (*init)(struct phy *phy); 35 int (*exit)(struct phy *phy); 36 int (*power_on)(struct phy *phy); 37 int (*power_off)(struct phy *phy); 38 struct module *owner; 39}; 40 41/** 42 * struct phy_attrs - represents phy attributes 43 * @bus_width: Data path width implemented by PHY 44 */ 45struct phy_attrs { 46 u32 bus_width; 47}; 48 49/** 50 * struct phy - represents the phy device 51 * @dev: phy device 52 * @id: id of the phy device 53 * @ops: function pointers for performing phy operations 54 * @init_data: list of PHY consumers (non-dt only) 55 * @mutex: mutex to protect phy_ops 56 * @init_count: used to protect when the PHY is used by multiple consumers 57 * @power_count: used to protect when the PHY is used by multiple consumers 58 * @phy_attrs: used to specify PHY specific attributes 59 */ 60struct phy { 61 struct device dev; 62 int id; 63 const struct phy_ops *ops; 64 struct phy_init_data *init_data; 65 struct mutex mutex; 66 int init_count; 67 int power_count; 68 struct phy_attrs attrs; 69 struct regulator *pwr; 70}; 71 72/** 73 * struct phy_provider - represents the phy provider 74 * @dev: phy provider device 75 * @owner: the module owner having of_xlate 76 * @of_xlate: function pointer to obtain phy instance from phy pointer 77 * @list: to maintain a linked list of PHY providers 78 */ 79struct phy_provider { 80 struct device *dev; 81 struct module *owner; 82 struct list_head list; 83 struct phy * (*of_xlate)(struct device *dev, 84 struct of_phandle_args *args); 85}; 86 87/** 88 * struct phy_consumer - represents the phy consumer 89 * @dev_name: the device name of the controller that will use this PHY device 90 * @port: name given to the consumer port 91 */ 92struct phy_consumer { 93 const char *dev_name; 94 const char *port; 95}; 96 97/** 98 * struct phy_init_data - contains the list of PHY consumers 99 * @num_consumers: number of consumers for this PHY device 100 * @consumers: list of PHY consumers 101 */ 102struct phy_init_data { 103 unsigned int num_consumers; 104 struct phy_consumer *consumers; 105}; 106 107#define PHY_CONSUMER(_dev_name, _port) \ 108{ \ 109 .dev_name = _dev_name, \ 110 .port = _port, \ 111} 112 113#define to_phy(dev) (container_of((dev), struct phy, dev)) 114 115#define of_phy_provider_register(dev, xlate) \ 116 __of_phy_provider_register((dev), THIS_MODULE, (xlate)) 117 118#define devm_of_phy_provider_register(dev, xlate) \ 119 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) 120 121static inline void phy_set_drvdata(struct phy *phy, void *data) 122{ 123 dev_set_drvdata(&phy->dev, data); 124} 125 126static inline void *phy_get_drvdata(struct phy *phy) 127{ 128 return dev_get_drvdata(&phy->dev); 129} 130 131#if IS_ENABLED(CONFIG_GENERIC_PHY) 132int phy_pm_runtime_get(struct phy *phy); 133int phy_pm_runtime_get_sync(struct phy *phy); 134int phy_pm_runtime_put(struct phy *phy); 135int phy_pm_runtime_put_sync(struct phy *phy); 136void phy_pm_runtime_allow(struct phy *phy); 137void phy_pm_runtime_forbid(struct phy *phy); 138int phy_init(struct phy *phy); 139int phy_exit(struct phy *phy); 140int phy_power_on(struct phy *phy); 141int phy_power_off(struct phy *phy); 142static inline int phy_get_bus_width(struct phy *phy) 143{ 144 return phy->attrs.bus_width; 145} 146static inline void phy_set_bus_width(struct phy *phy, int bus_width) 147{ 148 phy->attrs.bus_width = bus_width; 149} 150struct phy *phy_get(struct device *dev, const char *string); 151struct phy *phy_optional_get(struct device *dev, const char *string); 152struct phy *devm_phy_get(struct device *dev, const char *string); 153struct phy *devm_phy_optional_get(struct device *dev, const char *string); 154struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, 155 const char *con_id); 156void phy_put(struct phy *phy); 157void devm_phy_put(struct device *dev, struct phy *phy); 158struct phy *of_phy_get(struct device_node *np, const char *con_id); 159struct phy *of_phy_simple_xlate(struct device *dev, 160 struct of_phandle_args *args); 161struct phy *phy_create(struct device *dev, struct device_node *node, 162 const struct phy_ops *ops, 163 struct phy_init_data *init_data); 164struct phy *devm_phy_create(struct device *dev, struct device_node *node, 165 const struct phy_ops *ops, struct phy_init_data *init_data); 166void phy_destroy(struct phy *phy); 167void devm_phy_destroy(struct device *dev, struct phy *phy); 168struct phy_provider *__of_phy_provider_register(struct device *dev, 169 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 170 struct of_phandle_args *args)); 171struct phy_provider *__devm_of_phy_provider_register(struct device *dev, 172 struct module *owner, struct phy * (*of_xlate)(struct device *dev, 173 struct of_phandle_args *args)); 174void of_phy_provider_unregister(struct phy_provider *phy_provider); 175void devm_of_phy_provider_unregister(struct device *dev, 176 struct phy_provider *phy_provider); 177#else 178static inline int phy_pm_runtime_get(struct phy *phy) 179{ 180 if (!phy) 181 return 0; 182 return -ENOSYS; 183} 184 185static inline int phy_pm_runtime_get_sync(struct phy *phy) 186{ 187 if (!phy) 188 return 0; 189 return -ENOSYS; 190} 191 192static inline int phy_pm_runtime_put(struct phy *phy) 193{ 194 if (!phy) 195 return 0; 196 return -ENOSYS; 197} 198 199static inline int phy_pm_runtime_put_sync(struct phy *phy) 200{ 201 if (!phy) 202 return 0; 203 return -ENOSYS; 204} 205 206static inline void phy_pm_runtime_allow(struct phy *phy) 207{ 208 return; 209} 210 211static inline void phy_pm_runtime_forbid(struct phy *phy) 212{ 213 return; 214} 215 216static inline int phy_init(struct phy *phy) 217{ 218 if (!phy) 219 return 0; 220 return -ENOSYS; 221} 222 223static inline int phy_exit(struct phy *phy) 224{ 225 if (!phy) 226 return 0; 227 return -ENOSYS; 228} 229 230static inline int phy_power_on(struct phy *phy) 231{ 232 if (!phy) 233 return 0; 234 return -ENOSYS; 235} 236 237static inline int phy_power_off(struct phy *phy) 238{ 239 if (!phy) 240 return 0; 241 return -ENOSYS; 242} 243 244static inline int phy_get_bus_width(struct phy *phy) 245{ 246 return -ENOSYS; 247} 248 249static inline void phy_set_bus_width(struct phy *phy, int bus_width) 250{ 251 return; 252} 253 254static inline struct phy *phy_get(struct device *dev, const char *string) 255{ 256 return ERR_PTR(-ENOSYS); 257} 258 259static inline struct phy *phy_optional_get(struct device *dev, 260 const char *string) 261{ 262 return ERR_PTR(-ENOSYS); 263} 264 265static inline struct phy *devm_phy_get(struct device *dev, const char *string) 266{ 267 return ERR_PTR(-ENOSYS); 268} 269 270static inline struct phy *devm_phy_optional_get(struct device *dev, 271 const char *string) 272{ 273 return ERR_PTR(-ENOSYS); 274} 275 276static inline struct phy *devm_of_phy_get(struct device *dev, 277 struct device_node *np, 278 const char *con_id) 279{ 280 return ERR_PTR(-ENOSYS); 281} 282 283static inline void phy_put(struct phy *phy) 284{ 285} 286 287static inline void devm_phy_put(struct device *dev, struct phy *phy) 288{ 289} 290 291static inline struct phy *of_phy_get(struct device_node *np, const char *con_id) 292{ 293 return ERR_PTR(-ENOSYS); 294} 295 296static inline struct phy *of_phy_simple_xlate(struct device *dev, 297 struct of_phandle_args *args) 298{ 299 return ERR_PTR(-ENOSYS); 300} 301 302static inline struct phy *phy_create(struct device *dev, 303 struct device_node *node, 304 const struct phy_ops *ops, 305 struct phy_init_data *init_data) 306{ 307 return ERR_PTR(-ENOSYS); 308} 309 310static inline struct phy *devm_phy_create(struct device *dev, 311 struct device_node *node, 312 const struct phy_ops *ops, 313 struct phy_init_data *init_data) 314{ 315 return ERR_PTR(-ENOSYS); 316} 317 318static inline void phy_destroy(struct phy *phy) 319{ 320} 321 322static inline void devm_phy_destroy(struct device *dev, struct phy *phy) 323{ 324} 325 326static inline struct phy_provider *__of_phy_provider_register( 327 struct device *dev, struct module *owner, struct phy * (*of_xlate)( 328 struct device *dev, struct of_phandle_args *args)) 329{ 330 return ERR_PTR(-ENOSYS); 331} 332 333static inline struct phy_provider *__devm_of_phy_provider_register(struct device 334 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev, 335 struct of_phandle_args *args)) 336{ 337 return ERR_PTR(-ENOSYS); 338} 339 340static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) 341{ 342} 343 344static inline void devm_of_phy_provider_unregister(struct device *dev, 345 struct phy_provider *phy_provider) 346{ 347} 348#endif 349 350#endif /* __DRIVERS_PHY_H */