Skip to content

Commit aeaac93

Browse files
mripardkishon
authored andcommitted
phy: Add configuration interface
The phy framework is only allowing to configure the power state of the PHY using the init and power_on hooks, and their power_off and exit counterparts. While it works for most, simple, PHYs supported so far, some more advanced PHYs need some configuration depending on runtime parameters. These PHYs have been supported by a number of means already, often by using ad-hoc drivers in their consumer drivers. That doesn't work too well however, when a consumer device needs to deal with multiple PHYs, or when multiple consumers need to deal with the same PHY (a DSI driver and a CSI driver for example). So we'll add a new interface, through two funtions, phy_validate and phy_configure. The first one will allow to check that a current configuration, for a given mode, is applicable. It will also allow the PHY driver to tune the settings given as parameters as it sees fit. phy_configure will actually apply that configuration in the phy itself. Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
1 parent c845782 commit aeaac93

2 files changed

Lines changed: 122 additions & 0 deletions

File tree

‎drivers/phy/phy-core.c‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,70 @@ int phy_calibrate(struct phy *phy)
407407
}
408408
EXPORT_SYMBOL_GPL(phy_calibrate);
409409

410+
/**
411+
* phy_configure() - Changes the phy parameters
412+
* @phy: the phy returned by phy_get()
413+
* @opts: New configuration to apply
414+
*
415+
* Used to change the PHY parameters. phy_init() must have been called
416+
* on the phy. The configuration will be applied on the current phy
417+
* mode, that can be changed using phy_set_mode().
418+
*
419+
* Returns: 0 if successful, an negative error code otherwise
420+
*/
421+
int phy_configure(struct phy *phy, union phy_configure_opts *opts)
422+
{
423+
int ret;
424+
425+
if (!phy)
426+
return -EINVAL;
427+
428+
if (!phy->ops->configure)
429+
return -EOPNOTSUPP;
430+
431+
mutex_lock(&phy->mutex);
432+
ret = phy->ops->configure(phy, opts);
433+
mutex_unlock(&phy->mutex);
434+
435+
return ret;
436+
}
437+
EXPORT_SYMBOL_GPL(phy_configure);
438+
439+
/**
440+
* phy_validate() - Checks the phy parameters
441+
* @phy: the phy returned by phy_get()
442+
* @mode: phy_mode the configuration is applicable to.
443+
* @submode: PHY submode the configuration is applicable to.
444+
* @opts: Configuration to check
445+
*
446+
* Used to check that the current set of parameters can be handled by
447+
* the phy. Implementations are free to tune the parameters passed as
448+
* arguments if needed by some implementation detail or
449+
* constraints. It will not change any actual configuration of the
450+
* PHY, so calling it as many times as deemed fit will have no side
451+
* effect.
452+
*
453+
* Returns: 0 if successful, an negative error code otherwise
454+
*/
455+
int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
456+
union phy_configure_opts *opts)
457+
{
458+
int ret;
459+
460+
if (!phy)
461+
return -EINVAL;
462+
463+
if (!phy->ops->validate)
464+
return -EOPNOTSUPP;
465+
466+
mutex_lock(&phy->mutex);
467+
ret = phy->ops->validate(phy, mode, submode, opts);
468+
mutex_unlock(&phy->mutex);
469+
470+
return ret;
471+
}
472+
EXPORT_SYMBOL_GPL(phy_validate);
473+
410474
/**
411475
* _of_phy_get() - lookup and obtain a reference to a phy by phandle
412476
* @np: device_node for which to get the phy

‎include/linux/phy/phy.h‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ enum phy_mode {
4242
PHY_MODE_MIPI_DPHY,
4343
};
4444

45+
/**
46+
* union phy_configure_opts - Opaque generic phy configuration
47+
*/
48+
union phy_configure_opts {
49+
};
50+
4551
/**
4652
* struct phy_ops - set of function pointers for performing phy operations
4753
* @init: operation to be performed for initializing phy
@@ -59,6 +65,37 @@ struct phy_ops {
5965
int (*power_on)(struct phy *phy);
6066
int (*power_off)(struct phy *phy);
6167
int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
68+
69+
/**
70+
* @configure:
71+
*
72+
* Optional.
73+
*
74+
* Used to change the PHY parameters. phy_init() must have
75+
* been called on the phy.
76+
*
77+
* Returns: 0 if successful, an negative error code otherwise
78+
*/
79+
int (*configure)(struct phy *phy, union phy_configure_opts *opts);
80+
81+
/**
82+
* @validate:
83+
*
84+
* Optional.
85+
*
86+
* Used to check that the current set of parameters can be
87+
* handled by the phy. Implementations are free to tune the
88+
* parameters passed as arguments if needed by some
89+
* implementation detail or constraints. It must not change
90+
* any actual configuration of the PHY, so calling it as many
91+
* times as deemed fit by the consumer must have no side
92+
* effect.
93+
*
94+
* Returns: 0 if the configuration can be applied, an negative
95+
* error code otherwise
96+
*/
97+
int (*validate)(struct phy *phy, enum phy_mode mode, int submode,
98+
union phy_configure_opts *opts);
6299
int (*reset)(struct phy *phy);
63100
int (*calibrate)(struct phy *phy);
64101
struct module *owner;
@@ -165,6 +202,9 @@ int phy_power_off(struct phy *phy);
165202
int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
166203
#define phy_set_mode(phy, mode) \
167204
phy_set_mode_ext(phy, mode, 0)
205+
int phy_configure(struct phy *phy, union phy_configure_opts *opts);
206+
int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
207+
union phy_configure_opts *opts);
168208

169209
static inline enum phy_mode phy_get_mode(struct phy *phy)
170210
{
@@ -309,6 +349,24 @@ static inline int phy_calibrate(struct phy *phy)
309349
return -ENOSYS;
310350
}
311351

352+
static inline int phy_configure(struct phy *phy,
353+
union phy_configure_opts *opts)
354+
{
355+
if (!phy)
356+
return 0;
357+
358+
return -ENOSYS;
359+
}
360+
361+
static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
362+
union phy_configure_opts *opts)
363+
{
364+
if (!phy)
365+
return 0;
366+
367+
return -ENOSYS;
368+
}
369+
312370
static inline int phy_get_bus_width(struct phy *phy)
313371
{
314372
return -ENOSYS;

0 commit comments

Comments
 (0)