phy.h 9.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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>
21
#include <linux/regulator/consumer.h>
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

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;
};

41 42 43 44 45 46 47 48
/**
 * struct phy_attrs - represents phy attributes
 * @bus_width: Data path width implemented by PHY
 */
struct phy_attrs {
	u32			bus_width;
};

49 50 51 52 53 54 55 56 57
/**
 * 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
58
 * @phy_attrs: used to specify PHY specific attributes
59 60 61 62 63 64 65 66
 */
struct phy {
	struct device		dev;
	int			id;
	const struct phy_ops	*ops;
	struct mutex		mutex;
	int			init_count;
	int			power_count;
67
	struct phy_attrs	attrs;
68
	struct regulator	*pwr;
69 70 71 72 73 74 75 76 77 78 79
};

/**
 * 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;
80
	struct device_node	*children;
81 82 83 84 85 86
	struct module		*owner;
	struct list_head	list;
	struct phy * (*of_xlate)(struct device *dev,
		struct of_phandle_args *args);
};

H
Heikki Krogerus 已提交
87 88 89 90 91 92 93
struct phy_lookup {
	struct list_head node;
	const char *dev_id;
	const char *con_id;
	struct phy *phy;
};

H
Heikki Krogerus 已提交
94
#define	to_phy(a)	(container_of((a), struct phy, dev))
95 96

#define	of_phy_provider_register(dev, xlate)	\
97
	__of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
98 99

#define	devm_of_phy_provider_register(dev, xlate)	\
100 101 102 103 104 105 106
	__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)
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

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);
129 130 131 132 133 134 135 136
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;
}
137
struct phy *phy_get(struct device *dev, const char *string);
138
struct phy *phy_optional_get(struct device *dev, const char *string);
139
struct phy *devm_phy_get(struct device *dev, const char *string);
140
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
141 142
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
			    const char *con_id);
143 144
struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
				     int index);
145 146
void phy_put(struct phy *phy);
void devm_phy_put(struct device *dev, struct phy *phy);
147
struct phy *of_phy_get(struct device_node *np, const char *con_id);
148 149
struct phy *of_phy_simple_xlate(struct device *dev,
	struct of_phandle_args *args);
150
struct phy *phy_create(struct device *dev, struct device_node *node,
151
		       const struct phy_ops *ops);
152
struct phy *devm_phy_create(struct device *dev, struct device_node *node,
153
			    const struct phy_ops *ops);
154 155 156
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,
157 158 159
	struct device_node *children, struct module *owner,
	struct phy * (*of_xlate)(struct device *dev,
				 struct of_phandle_args *args));
160
struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
161 162 163
	struct device_node *children, struct module *owner,
	struct phy * (*of_xlate)(struct device *dev,
				 struct of_phandle_args *args));
164 165 166
void of_phy_provider_unregister(struct phy_provider *phy_provider);
void devm_of_phy_provider_unregister(struct device *dev,
	struct phy_provider *phy_provider);
H
Heikki Krogerus 已提交
167 168
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);
169 170 171
#else
static inline int phy_pm_runtime_get(struct phy *phy)
{
172 173
	if (!phy)
		return 0;
174 175 176 177 178
	return -ENOSYS;
}

static inline int phy_pm_runtime_get_sync(struct phy *phy)
{
179 180
	if (!phy)
		return 0;
181 182 183 184 185
	return -ENOSYS;
}

static inline int phy_pm_runtime_put(struct phy *phy)
{
186 187
	if (!phy)
		return 0;
188 189 190 191 192
	return -ENOSYS;
}

static inline int phy_pm_runtime_put_sync(struct phy *phy)
{
193 194
	if (!phy)
		return 0;
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	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)
{
210 211
	if (!phy)
		return 0;
212 213 214 215 216
	return -ENOSYS;
}

static inline int phy_exit(struct phy *phy)
{
217 218
	if (!phy)
		return 0;
219 220 221 222 223
	return -ENOSYS;
}

static inline int phy_power_on(struct phy *phy)
{
224 225
	if (!phy)
		return 0;
226 227 228 229 230
	return -ENOSYS;
}

static inline int phy_power_off(struct phy *phy)
{
231 232
	if (!phy)
		return 0;
233 234 235
	return -ENOSYS;
}

236 237 238 239 240 241 242 243 244 245
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;
}

246 247 248 249 250
static inline struct phy *phy_get(struct device *dev, const char *string)
{
	return ERR_PTR(-ENOSYS);
}

251 252 253 254 255 256
static inline struct phy *phy_optional_get(struct device *dev,
					   const char *string)
{
	return ERR_PTR(-ENOSYS);
}

257 258 259 260 261
static inline struct phy *devm_phy_get(struct device *dev, const char *string)
{
	return ERR_PTR(-ENOSYS);
}

262 263 264 265 266 267
static inline struct phy *devm_phy_optional_get(struct device *dev,
						const char *string)
{
	return ERR_PTR(-ENOSYS);
}

268 269 270 271 272 273 274
static inline struct phy *devm_of_phy_get(struct device *dev,
					  struct device_node *np,
					  const char *con_id)
{
	return ERR_PTR(-ENOSYS);
}

275 276 277 278 279 280 281
static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
						   struct device_node *np,
						   int index)
{
	return ERR_PTR(-ENOSYS);
}

282 283 284 285 286 287 288 289
static inline void phy_put(struct phy *phy)
{
}

static inline void devm_phy_put(struct device *dev, struct phy *phy)
{
}

290 291 292 293 294
static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
{
	return ERR_PTR(-ENOSYS);
}

295 296 297 298 299 300 301
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,
302
				     struct device_node *node,
303
				     const struct phy_ops *ops)
304 305 306 307 308
{
	return ERR_PTR(-ENOSYS);
}

static inline struct phy *devm_phy_create(struct device *dev,
309
					  struct device_node *node,
310
					  const struct phy_ops *ops)
311 312 313 314 315 316 317 318 319 320 321 322 323
{
	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(
324 325 326
	struct device *dev, struct device_node *children, struct module *owner,
	struct phy * (*of_xlate)(struct device *dev,
				 struct of_phandle_args *args))
327 328 329 330 331
{
	return ERR_PTR(-ENOSYS);
}

static inline struct phy_provider *__devm_of_phy_provider_register(struct device
332 333 334
	*dev, struct device_node *children, struct module *owner,
	struct phy * (*of_xlate)(struct device *dev,
				 struct of_phandle_args *args))
335 336 337 338 339 340 341 342 343 344 345 346
{
	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)
{
}
H
Heikki Krogerus 已提交
347 348 349 350 351 352 353
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) { }
354 355 356
#endif

#endif /* __DRIVERS_PHY_H */