2013-09-27 14:23:25 +08: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 17:55:45 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2013-09-27 14:23:25 +08:00
|
|
|
|
|
|
|
struct phy;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @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);
|
|
|
|
struct module *owner;
|
|
|
|
};
|
|
|
|
|
2013-12-19 22:23:02 +08:00
|
|
|
/**
|
|
|
|
* struct phy_attrs - represents phy attributes
|
|
|
|
* @bus_width: Data path width implemented by PHY
|
|
|
|
*/
|
|
|
|
struct phy_attrs {
|
|
|
|
u32 bus_width;
|
|
|
|
};
|
|
|
|
|
2013-09-27 14:23:25 +08: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
|
2013-12-19 22:23:02 +08:00
|
|
|
* @phy_attrs: used to specify PHY specific attributes
|
2013-09-27 14:23:25 +08: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 22:23:02 +08:00
|
|
|
struct phy_attrs attrs;
|
2014-07-04 17:55:45 +08:00
|
|
|
struct regulator *pwr;
|
2013-09-27 14:23:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct phy_provider - represents the phy provider
|
|
|
|
* @dev: phy provider device
|
|
|
|
* @owner: the module owner having of_xlate
|
|
|
|
* @of_xlate: function pointer to obtain phy instance from phy pointer
|
|
|
|
* @list: to maintain a linked list of PHY providers
|
|
|
|
*/
|
|
|
|
struct phy_provider {
|
|
|
|
struct device *dev;
|
2016-04-05 23:17:34 +08:00
|
|
|
struct device_node *children;
|
2013-09-27 14:23:25 +08:00
|
|
|
struct module *owner;
|
|
|
|
struct list_head list;
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args);
|
|
|
|
};
|
|
|
|
|
2014-11-19 23:28:18 +08:00
|
|
|
struct phy_lookup {
|
|
|
|
struct list_head node;
|
|
|
|
const char *dev_id;
|
|
|
|
const char *con_id;
|
|
|
|
struct phy *phy;
|
|
|
|
};
|
|
|
|
|
2014-11-19 23:28:17 +08:00
|
|
|
#define to_phy(a) (container_of((a), struct phy, dev))
|
2013-09-27 14:23:25 +08:00
|
|
|
|
|
|
|
#define of_phy_provider_register(dev, xlate) \
|
2016-04-05 23:17:34 +08:00
|
|
|
__of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
|
2013-09-27 14:23:25 +08:00
|
|
|
|
|
|
|
#define devm_of_phy_provider_register(dev, xlate) \
|
2016-04-05 23:17:34 +08: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 14:23:25 +08: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);
|
2013-12-19 22:23:02 +08: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 14:23:25 +08:00
|
|
|
struct phy *phy_get(struct device *dev, const char *string);
|
2014-02-05 01:33:12 +08:00
|
|
|
struct phy *phy_optional_get(struct device *dev, const char *string);
|
2013-09-27 14:23:25 +08:00
|
|
|
struct phy *devm_phy_get(struct device *dev, const char *string);
|
2014-02-05 01:33:12 +08:00
|
|
|
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
|
2014-03-06 19:16:47 +08:00
|
|
|
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
|
|
|
|
const char *con_id);
|
2015-04-23 07:04:11 +08:00
|
|
|
struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
|
|
|
|
int index);
|
2013-09-27 14:23:25 +08:00
|
|
|
void phy_put(struct phy *phy);
|
|
|
|
void devm_phy_put(struct device *dev, struct phy *phy);
|
2014-03-06 19:16:46 +08:00
|
|
|
struct phy *of_phy_get(struct device_node *np, const char *con_id);
|
2013-09-27 14:23:25 +08:00
|
|
|
struct phy *of_phy_simple_xlate(struct device *dev,
|
|
|
|
struct of_phandle_args *args);
|
2014-07-14 18:25:02 +08:00
|
|
|
struct phy *phy_create(struct device *dev, struct device_node *node,
|
2014-11-19 23:28:21 +08:00
|
|
|
const struct phy_ops *ops);
|
2014-07-14 18:25:02 +08:00
|
|
|
struct phy *devm_phy_create(struct device *dev, struct device_node *node,
|
2014-11-19 23:28:21 +08:00
|
|
|
const struct phy_ops *ops);
|
2013-09-27 14:23:25 +08: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 23:17:34 +08:00
|
|
|
struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args));
|
2013-09-27 14:23:25 +08:00
|
|
|
struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
|
2016-04-05 23:17:34 +08:00
|
|
|
struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args));
|
2013-09-27 14:23:25 +08: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 23:28:18 +08: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 14:23:25 +08:00
|
|
|
#else
|
|
|
|
static inline int phy_pm_runtime_get(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_pm_runtime_get_sync(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_pm_runtime_put(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_pm_runtime_put_sync(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08: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 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_exit(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_power_on(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int phy_power_off(struct phy *phy)
|
|
|
|
{
|
2014-04-19 11:21:44 +08:00
|
|
|
if (!phy)
|
|
|
|
return 0;
|
2013-09-27 14:23:25 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2013-12-19 22:23:02 +08: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 14:23:25 +08:00
|
|
|
static inline struct phy *phy_get(struct device *dev, const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:33:12 +08:00
|
|
|
static inline struct phy *phy_optional_get(struct device *dev,
|
|
|
|
const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2013-09-27 14:23:25 +08:00
|
|
|
static inline struct phy *devm_phy_get(struct device *dev, const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:33:12 +08:00
|
|
|
static inline struct phy *devm_phy_optional_get(struct device *dev,
|
|
|
|
const char *string)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2014-03-06 19:16:47 +08: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-23 07:04:11 +08: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 14:23:25 +08:00
|
|
|
static inline void phy_put(struct phy *phy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void devm_phy_put(struct device *dev, struct phy *phy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-06 19:16:46 +08:00
|
|
|
static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
|
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
2013-09-27 14:23:25 +08: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 18:25:02 +08:00
|
|
|
struct device_node *node,
|
2014-11-19 23:28:21 +08:00
|
|
|
const struct phy_ops *ops)
|
2013-09-27 14:23:25 +08:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct phy *devm_phy_create(struct device *dev,
|
2014-07-14 18:25:02 +08:00
|
|
|
struct device_node *node,
|
2014-11-19 23:28:21 +08:00
|
|
|
const struct phy_ops *ops)
|
2013-09-27 14:23:25 +08: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 23:17:34 +08: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 14:23:25 +08:00
|
|
|
{
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct phy_provider *__devm_of_phy_provider_register(struct device
|
2016-04-05 23:17:34 +08:00
|
|
|
*dev, struct device_node *children, struct module *owner,
|
|
|
|
struct phy * (*of_xlate)(struct device *dev,
|
|
|
|
struct of_phandle_args *args))
|
2013-09-27 14:23:25 +08: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 23:28:18 +08: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 14:23:25 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __DRIVERS_PHY_H */
|