2013-09-27 06:23:25 +00:00
|
|
|
/*
|
|
|
|
* phy.h -- generic phy header file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
|
|
|
|
*
|
|
|
|
* Author: Kishon Vijay Abraham I <kishon@ti.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DRIVERS_PHY_H
|
|
|
|
#define __DRIVERS_PHY_H
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
2014-07-04 09:55:45 +00:00
|
|
|
#include <linux/regulator/consumer.h>
|
2013-09-27 06:23:25 +00:00
|
|
|
|
|
|
|
struct phy;
|
|
|
|
|
2016-05-09 23:39:59 +00:00
|
|
|
enum phy_mode {
|
|
|
|
PHY_MODE_INVALID,
|
|
|
|
PHY_MODE_USB_HOST,
|
2018-01-16 10:57:09 +00:00
|
|
|
PHY_MODE_USB_HOST_LS,
|
|
|
|
PHY_MODE_USB_HOST_FS,
|
|
|
|
PHY_MODE_USB_HOST_HS,
|
|
|
|
PHY_MODE_USB_HOST_SS,
|
2016-05-09 23:39:59 +00:00
|
|
|
PHY_MODE_USB_DEVICE,
|
2018-01-16 10:57:09 +00:00
|
|
|
PHY_MODE_USB_DEVICE_LS,
|
|
|
|
PHY_MODE_USB_DEVICE_FS,
|
|
|
|
PHY_MODE_USB_DEVICE_HS,
|
|
|
|
PHY_MODE_USB_DEVICE_SS,
|
2016-05-09 23:39:59 +00:00
|
|
|
PHY_MODE_USB_OTG,
|
2017-08-30 08:29:12 +00:00
|
|
|
PHY_MODE_SGMII,
|
|
|
|
PHY_MODE_10GKR,
|
2017-10-12 06:19:33 +00:00
|
|
|
PHY_MODE_UFS_HS_A,
|
|
|
|
PHY_MODE_UFS_HS_B,
|
2016-05-09 23:39:59 +00:00
|
|
|
};
|
|
|
|
|
2013-09-27 06:23:25 +00:00
|
|
|
/**
|
|
|
|
* struct phy_ops - set of function pointers for performing phy operations
|
|
|
|
* @init: operation to be performed for initializing phy
|
|
|
|
* @exit: operation to be performed while exiting
|
|
|
|
* @power_on: powering on the phy
|
|
|
|
* @power_off: powering off the phy
|
2016-05-09 23:39:59 +00:00
|
|
|
* @set_mode: set the mode of the phy
|
2016-09-09 18:59:37 +00:00
|
|
|
* @reset: resetting the phy
|
2017-10-09 12:00:50 +00:00
|
|
|
* @calibrate: calibrate the phy
|
2013-09-27 06:23:25 +00:00
|
|
|
* @owner: the module owner containing the ops
|
|
|
|
*/
|
|
|
|
struct phy_ops {
|
|
|
|
int (*init)(struct phy *phy);
|
|
|
|
int (*exit)(struct phy *phy);
|
|
|
|
int (*power_on)(struct phy *phy);
|
|
|
|
int (*power_off)(struct phy *phy);
|
2016-05-09 23:39:59 +00:00
|
|
|
int (*set_mode)(struct phy *phy, enum phy_mode mode);
|
2016-09-09 18:59:37 +00:00
|
|
|
int (*reset)(struct phy *phy);
|
2017-10-09 12:00:50 +00:00
|
|
|
int (*calibrate)(struct phy *phy);
|
2013-09-27 06:23:25 +00:00
|
|
|
struct module *owner;
|
|
|
|
};
|
|
|
|
|
2013-12-19 14:23:02 +00:00
|
|
|
/**
|
|
|
|
* struct phy_attrs - represents phy attributes
|
|
|
|
* @bus_width: Data path width implemented by PHY
|
|
|
|
*/
|
|
|
|
struct phy_attrs {
|
|
|
|
u32 bus_width;
|
2018-01-16 10:57:09 +00:00
|
|
|
enum phy_mode mode;
|
2013-12-19 14:23:02 +00:00
|
|
|
};
|
|
|
|
|
2013-09-27 06:23:25 +00:00
|
|
|
/**
|
|
|
|
* struct phy - represents the phy device
|
|
|
|
* @dev: phy device
|
|
|
|
* @id: id of the phy device
|
|
|
|
* @ops: function pointers for performing phy operations
|
|
|
|
* @init_data: list of PHY consumers (non-dt only)
|
|
|
|
* @mutex: mutex to protect phy_ops
|
|
|
|
* @init_count: used to protect when the PHY is used by multiple consumers
|
|
|
|
* @power_count: used to protect when the PHY is used by multiple consumers
|
2018-02-02 16:34:50 +00:00
|
|
|
* @attrs: used to specify PHY specific attributes
|
|
|
|
* @pwr: power regulator associated with the phy
|
2013-09-27 06:23:25 +00:00
|
|
|
*/
|
|
|
|
struct phy {
|
|
|
|
struct device dev;
|
|
|
|
int id;
|
|
|
|
const struct phy_ops *ops;
|
|
|
|
struct mutex mutex;
|
|
|
|
int init_count;
|
|
|
|
int power_count;
|
2013-12-19 14:23:02 +00:00
|
|
|
struct phy_attrs attrs;
|
2014-07-04 09:55:45 +00:00
|
|
|
struct regulator *pwr;
|
2013-09-27 06:23:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct phy_provider - represents the phy provider
|
|
|
|
* @dev: phy provider device
|
2018-02-02 16:34:50 +00:00
|
|
|
* @children: can be used to override the default (dev->of_node) child node
|
2013-09-27 06:23:25 +00:00
|
|
|
* @owner: the module owner having of_xlate
|
|
|
|
* @list: to maintain a linked list of PHY providers
|
2018-02-02 16:34:50 +00:00
|
|
|
* @of_xlate: function pointer to obtain phy instance from phy pointer
|
2013-09-27 06:23:25 +00:00
|
|
|
*/
|
|
|
|
struct phy_provider {
|
|
|
|
struct device *dev;
|
2016-04-05 15:17:34 +00:00
|
|
|
struct device_node *children;
|
2013-09-27 06:23:25 +00:00
|
|
|
struct module *owner;
|
|
|
|
struct list_head list;
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args);
|
|
|
|
};
|
|
|
|
|
2018-02-02 16:34:50 +00:00
|
|
|
/**
|
|
|
|
* struct phy_lookup - PHY association in list of phys managed by the phy driver
|
|
|
|
* @node: list node
|
|
|
|
* @dev_id: the device of the association
|
|
|
|
* @con_id: connection ID string on device
|
|
|
|
* @phy: the phy of the association
|
|
|
|
*/
|
2014-11-19 15:28:18 +00:00
|
|
|
struct phy_lookup {
|
|
|
|
struct list_head node;
|
|
|
|
const char *dev_id;
|
|
|
|
const char *con_id;
|
|
|
|
struct phy *phy;
|
|
|
|
};
|
|
|
|
|
2014-11-19 15:28:17 +00:00
|
|
|
#define to_phy(a) (container_of((a), struct phy, dev))
|
2013-09-27 06:23:25 +00:00
|
|
|
|
|
|
|
#define of_phy_provider_register(dev, xlate) \
|
2016-04-05 15:17:34 +00:00
|
|
|
__of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
|
2013-09-27 06:23:25 +00:00
|
|
|
|
|
|
|
#define devm_of_phy_provider_register(dev, xlate) \
|
2016-04-05 15:17:34 +00:00
|
|
|
__devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
|
|
|
|
|
|
|
|
#define of_phy_provider_register_full(dev, children, xlate) \
|
|
|
|
__of_phy_provider_register(dev, children, THIS_MODULE, xlate)
|
|
|
|
|
|
|
|
#define devm_of_phy_provider_register_full(dev, children, xlate) \
|
|
|
|
__devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
|
2013-09-27 06:23:25 +00:00
|
|
|
|
|
|
|
static inline void phy_set_drvdata(struct phy *phy, void *data)
|
|
|
|
{
|
|
|
|
dev_set_drvdata(&phy->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *phy_get_drvdata(struct phy *phy)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(&phy->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_GENERIC_PHY)
|
|
|
|
int phy_pm_runtime_get(struct phy *phy);
|
|
|
|
int phy_pm_runtime_get_sync(struct phy *phy);
|
|
|
|
int phy_pm_runtime_put(struct phy *phy);
|
|
|
|
int phy_pm_runtime_put_sync(struct phy *phy);
|
|
|
|
void phy_pm_runtime_allow(struct phy *phy);
|
|
|
|
void phy_pm_runtime_forbid(struct phy *phy);
|
|
|
|
int phy_init(struct phy *phy);
|
|
|
|
int phy_exit(struct phy *phy);
|
|
|
|
int phy_power_on(struct phy *phy);
|
|
|
|
int phy_power_off(struct phy *phy);
|
2016-05-09 23:39:59 +00:00
|
|
|
int phy_set_mode(struct phy *phy, enum phy_mode mode);
|
2018-01-16 10:57:09 +00:00
|
|
|
static inline enum phy_mode phy_get_mode(struct phy *phy)
|
|
|
|
{
|
|
|
|
return phy->attrs.mode;
|
|
|
|
}
|
2016-09-09 18:59:37 +00:00
|
|
|
int phy_reset(struct phy *phy);
|
2017-10-09 12:00:50 +00:00
|
|
|
int phy_calibrate(struct phy *phy);
|
2013-12-19 14:23:02 +00:00
|
|
|
static inline int phy_get_bus_width(struct phy *phy)
|
|
|
|
{
|
|
|
|
return phy->attrs.bus_width;
|
|
|
|
}
|
|
|
|
static inline void phy_set_bus_width(struct phy *phy, int bus_width)
|
|
|
|
{
|
|
|
|
phy->attrs.bus_width = bus_width;
|
|
|
|
}
|
2013-09-27 06:23:25 +00:00
|
|
|
struct phy *phy_get(struct device *dev, const char *string);
|
2014-02-04 17:33:12 +00:00
|
|
|
struct phy *phy_optional_get(struct device *dev, const char *string);
|
2013-09-27 06:23:25 +00:00
|
|
|
struct phy *devm_phy_get(struct device *dev, const char *string);
|
2014-02-04 17:33:12 +00:00
|
|
|
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
|
2014-03-06 11:16:47 +00:00
|
|
|
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
|
|
|
|
const char *con_id);
|
2015-04-22 23:04:11 +00:00
|
|
|
struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
|
|
|
|
int index);
|
2013-09-27 06:23:25 +00:00
|
|
|
void phy_put(struct phy *phy);
|
|
|
|
void devm_phy_put(struct device *dev, struct phy *phy);
|
2014-03-06 11:16:46 +00:00
|
|
|
struct phy *of_phy_get(struct device_node *np, const char *con_id);
|
2013-09-27 06:23:25 +00:00
|
|
|
struct phy *of_phy_simple_xlate(struct device *dev,
|
|
|
|
struct of_phandle_args *args);
|
2014-07-14 10:25:02 +00:00
|
|
|
struct phy *phy_create(struct device *dev, struct device_node *node,
|
2014-11-19 15:28:21 +00:00
|
|
|
const struct phy_ops *ops);
|
2014-07-14 10:25:02 +00:00
|
|
|
struct phy *devm_phy_create(struct device *dev, struct device_node *node,
|
2014-11-19 15:28:21 +00:00
|
|
|
const struct phy_ops *ops);
|
2013-09-27 06:23:25 +00:00
|
|
|
void phy_destroy(struct phy *phy);
|
|
|
|
void devm_phy_destroy(struct device *dev, struct phy *phy);
|
|
|
|
struct phy_provider *__of_phy_provider_register(struct device *dev,
|
2016-04-05 15:17:34 +00:00
|
|
|
struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args));
|
2013-09-27 06:23:25 +00:00
|
|
|
struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
|
2016-04-05 15:17:34 +00:00
|
|
|
struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args));
|
2013-09-27 06:23:25 +00:00
|
|
|
void of_phy_provider_unregister(struct phy_provider *phy_provider);
|
|
|
|
void devm_of_phy_provider_unregister(struct device *dev,
|
|
|
|
struct phy_provider *phy_provider);
|
2014-11-19 15:28:18 +00:00
|
|
|
int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
|
|
|
|
void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
|
2013-09-27 06:23:25 +00:00
|
|
|
#else
|
|
|
|
static inline int phy_pm_runtime_get(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_pm_runtime_get_sync(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_pm_runtime_put(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_pm_runtime_put_sync(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void phy_pm_runtime_allow(struct phy *phy)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void phy_pm_runtime_forbid(struct phy *phy)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_init(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_exit(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_power_on(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_power_off(struct phy *phy)
|
|
|
|
{
|
2014-04-19 03:21:44 +00:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 06:23:25 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:39:59 +00:00
|
|
|
static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
|
|
|
|
{
|
|
|
|
if (!phy)
|
|
|
|
return 0;
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2018-01-16 10:57:09 +00:00
|
|
|
static inline enum phy_mode phy_get_mode(struct phy *phy)
|
|
|
|
{
|
|
|
|
return PHY_MODE_INVALID;
|
|
|
|
}
|
|
|
|
|
2016-10-25 14:15:34 +00:00
|
|
|
static inline int phy_reset(struct phy *phy)
|
|
|
|
{
|
|
|
|
if (!phy)
|
|
|
|
return 0;
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2017-10-09 12:00:50 +00:00
|
|
|
static inline int phy_calibrate(struct phy *phy)
|
|
|
|
{
|
|
|
|
if (!phy)
|
|
|
|
return 0;
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2013-12-19 14:23:02 +00:00
|
|
|
static inline int phy_get_bus_width(struct phy *phy)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void phy_set_bus_width(struct phy *phy, int bus_width)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-27 06:23:25 +00:00
|
|
|
static inline struct phy *phy_get(struct device *dev, const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2014-02-04 17:33:12 +00:00
|
|
|
static inline struct phy *phy_optional_get(struct device *dev,
|
|
|
|
const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2013-09-27 06:23:25 +00:00
|
|
|
static inline struct phy *devm_phy_get(struct device *dev, const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2014-02-04 17:33:12 +00:00
|
|
|
static inline struct phy *devm_phy_optional_get(struct device *dev,
|
|
|
|
const char *string)
|
|
|
|
{
|
2017-09-04 12:53:13 +00:00
|
|
|
return NULL;
|
2014-02-04 17:33:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 11:16:47 +00:00
|
|
|
static inline struct phy *devm_of_phy_get(struct device *dev,
|
|
|
|
struct device_node *np,
|
|
|
|
const char *con_id)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2015-04-22 23:04:11 +00:00
|
|
|
static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
|
|
|
|
struct device_node *np,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2013-09-27 06:23:25 +00:00
|
|
|
static inline void phy_put(struct phy *phy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void devm_phy_put(struct device *dev, struct phy *phy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-06 11:16:46 +00:00
|
|
|
static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2013-09-27 06:23:25 +00:00
|
|
|
static inline struct phy *of_phy_simple_xlate(struct device *dev,
|
|
|
|
struct of_phandle_args *args)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct phy *phy_create(struct device *dev,
|
2014-07-14 10:25:02 +00:00
|
|
|
struct device_node *node,
|
2014-11-19 15:28:21 +00:00
|
|
|
const struct phy_ops *ops)
|
2013-09-27 06:23:25 +00:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct phy *devm_phy_create(struct device *dev,
|
2014-07-14 10:25:02 +00:00
|
|
|
struct device_node *node,
|
2014-11-19 15:28:21 +00:00
|
|
|
const struct phy_ops *ops)
|
2013-09-27 06:23:25 +00:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void phy_destroy(struct phy *phy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct phy_provider *__of_phy_provider_register(
|
2016-04-05 15:17:34 +00:00
|
|
|
struct device *dev, struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args))
|
2013-09-27 06:23:25 +00:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct phy_provider *__devm_of_phy_provider_register(struct device
|
2016-04-05 15:17:34 +00:00
|
|
|
*dev, struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args))
|
2013-09-27 06:23:25 +00:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void devm_of_phy_provider_unregister(struct device *dev,
|
|
|
|
struct phy_provider *phy_provider)
|
|
|
|
{
|
|
|
|
}
|
2014-11-19 15:28:18 +00:00
|
|
|
static inline int
|
|
|
|
phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
|
|
|
|
const char *dev_id) { }
|
2013-09-27 06:23:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __DRIVERS_PHY_H */
|