PHY: Add support for SERDES in TI's AM654 platform
Subsystems (2)
v4 cover PHY: Add support for SERDES in TI's AM654 platform
This patch series
*) adds support for SERDES module in am654
*) modifies phy_reset API to invoke pm_runtime_get/pm_runtime_put since
the reset callback can access registers.
*) Add *release* phy_ops to be invoked when the consumer relinquishes
PHY
Changes from v3:
*) Moved SERDES driver to use regfield
*) Removed reg-names binding and updated Documentation for
power-domains
Changes from v2:
*) Fix typos pointed out by Roger
*) Add dt-binding Documentation in a new file ti,phy-am654-serdes.txt *) Add Roger's patch to support all CLKSEL values.
Changes from v1:
*) Add *release* phy ops
*) Populate release phy_ops in phy-am654-serdes to cleanup
initializations done in of_xlate
Kishon Vijay Abraham I (4):
phy: core: Add *release* phy_ops invoked when the consumer
relinquishes PHY
phy: core: Invoke pm_runtime_get_*/pm_runtime_put_* before invoking
reset callback
dt-bindings: phy: ti: Add dt binding documentation for SERDES in
AM654x SoC
phy: ti: Add a new SERDES driver for TI's AM654x SoC
Roger Quadros (1):
phy: ti: am654-serdes: Support all clksel values
.../bindings/phy/ti,phy-am654-serdes.txt | 82 +++ drivers/phy/phy-core.c | 11 + drivers/phy/ti/Kconfig | 12 + drivers/phy/ti/Makefile | 1 + drivers/phy/ti/phy-am654-serdes.c | 658 ++++++++++++++++++ include/dt-bindings/phy/phy-am654-serdes.h | 13 + include/linux/phy/phy.h | 2 + 7 files changed, 779 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/ti,phy-am654-serdes.txt create mode 100644 drivers/phy/ti/phy-am654-serdes.c create mode 100644 include/dt-bindings/phy/phy-am654-serdes.h
Signature · 1 line
2.17.1
PATCH v4 1/5 phy: core: Add *release* phy_ops invoked when the consumer relinquishes PHY
Add a new phy_ops *release* invoked when the consumer relinquishes the PHY using phy_put/devm_phy_put. The initializations done by the PHY driver in of_xlate call back can be can be cleaned up here.
--- drivers/phy/phy-core.c | 5 +++++ include/linux/phy/phy.h | 2 ++ 2 files changed, 7 insertions(+)
drivers/phy/phy-core.c +5 -0
@@ -564,6 +564,11 @@ void phy_put(struct phy *phy)if (!phy ||IS_ERR (phy))return ; +mutex_lock (&phy->mutex); +if (phy->ops->release) + phy->ops->release (phy); +mutex_unlock (&phy->mutex); +module_put (phy->ops->owner);put_device (&phy->dev); }
include/linux/phy/phy.h +2 -0
@@ -64,6 +64,7 @@ union phy_configure_opts {* @set_mode: set the mode of the phy * @reset: resetting the phy * @calibrate: calibrate the phy +* @release: ops to be performed while the consumer relinquishes the PHY * @owner: the module owner containing the ops */ struct phy_ops {
@@ -105,6 +106,7 @@ struct phy_ops { union phy_configure_opts *opts);int (*reset)(struct phy *phy);int (*calibrate)(struct phy *phy); +void (*release)(struct phy *phy);struct module *owner; };
Signature · 1 line
2.17.1
PATCH v4 2/5 phy: core: Invoke pm_runtime_get_*/pm_runtime_put_* before invoking reset callback
In reply to Kishon Vijay Abraham IPHY drivers may try to access PHY registers in the ->reset() callback. Invoke phy_pm_runtime_get_sync() before invoking the ->reset() callback so that the PHY drivers don't have to enable clocks by themselves before accessing PHY registers.
--- drivers/phy/phy-core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/phy/phy-core.c +6 -0
@@ -384,10 +384,16 @@ int phy_reset(struct phy *phy)if (!phy || !phy->ops->reset)return 0 ; + ret =phy_pm_runtime_get_sync (phy); +if (ret <0 && ret != -ENOTSUPP ) +return ret; +mutex_lock (&phy->mutex); ret = phy->ops->reset (phy);mutex_unlock (&phy->mutex); +phy_pm_runtime_put (phy); +return ret; }EXPORT_SYMBOL_GPL (phy_reset);
Signature · 1 line
2.17.1
PATCH v4 3/5 dt-bindings: phy: ti: Add dt binding documentation for SERDES in AM654x SoC
In reply to Kishon Vijay Abraham IAM654x has two SERDES instances. Each instance has three input clocks (left input, externel reference clock and right input) and two output clocks (left output and right output) in addition to a PLL mux clock which the SERDES uses for Clock Multiplier Unit (CMU refclock). The PLL mux clock can select from one of the three input clocks. The right output can select between left input and external reference clock while the left output can select between the right input and external reference clock.
The left and right input reference clock of SERDES0 and SERDES1 respectively are connected to the SoC clock. In the case of two lane SERDES personality card, the left input of SERDES1 is connected to the right output of SERDES0 in a chained fashion.
See section "Reference Clock Distribution" of AM65x Sitara Processors TRM (SPRUID7 – April 2018) for more details.
Add dt-binding documentation in order to represent all these different configurations in device tree.
--- .../bindings/phy/ti,phy-am654-serdes.txt | 82 +++++++++++++++++++ include/dt-bindings/phy/phy-am654-serdes.h | 13 +++ 2 files changed, 95 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/ti,phy-am654-serdes.txt create mode 100644 include/dt-bindings/phy/phy-am654-serdes.h
Documentation/devicetree/bindings/phy/ti,phy-am654-serdes.txt new file +82 -0
@@ -0,0 +1,82 @@ +TI AM654 SERDES + +Required properties: + - compatible: Should be "ti,phy-am654-serdes" + - reg : Address and length of the register set for the device. + - #phy-cells: determine the number of cells that should be given in the + phandle while referencing this phy. Should be "2". The 1st cell + corresponds to the phy type (should be one of the types specified in + include/dt-bindings/phy/phy.h) and the 2nd cell should be the serdes + lane function. + If SERDES0 is referenced 2nd cell should be: + 0 - USB3 + 1 - PCIe0 Lane0 + 2 - ICSS2 SGMII Lane0 + If SERDES1 is referenced 2nd cell should be: + 0 - PCIe1 Lane0 + 1 - PCIe0 Lane1 + 2 - ICSS2 SGMII Lane1 + - power-domains: As documented by the generic PM domain bindings in + Documentation/devicetree/bindings/power/power_domain.txt. + - clocks: List of clock-specifiers representing the input to the SERDES. + Should have 3 items representing the left input clock, external + reference clock and right input clock in that order. + - clock-output-names: List of clock names for each of the clock outputs of + SERDES. Should have 3 items for CMU reference clock, + left output clock and right output clock in that order. + - assigned-clocks: As defined in + Documentation/devicetree/bindings/clock/clock-bindings.txt + - assigned-clock-parents: As defined in + Documentation/devicetree/bindings/clock/clock-bindings.txt + - #clock-cells: Should be <1> to choose between the 3 output clocks. + Defined in Documentation/devicetree/bindings/clock/clock-bindings.txt + + The following macros are defined in dt-bindings/phy/phy-am654-serdes.h + for selecting the correct reference clock. This can be used while + specifying the clocks created by SERDES. + => AM654_SERDES_CMU_REFCLK + => AM654_SERDES_LO_REFCLK + => AM654_SERDES_RO_REFCLK + + - mux-controls: Phandle to the multiplexer that is used to select the lane + function. See #phy-cells above to see the multiplex values. + +Example: + +Example for SERDES0 is given below. It has 3 clock inputs; +left input reference clock as indicated by <&k3_clks 153 4>, external +reference clock as indicated by <&k3_clks 153 1> and right input +reference clock as indicated by <&serdes1 AM654_SERDES_LO_REFCLK>. (The +right input of SERDES0 is connected to the left output of SERDES1). + +SERDES0 registers 3 clock outputs as indicated in clock-output-names. The +first refers to the CMU reference clock, second refers to the left output +reference clock and the third refers to the right output reference clock. + +The assigned-clocks and assigned-clock-parents is used here to set the +parent of left input reference clock to MAINHSDIV_CLKOUT4 and parent of +CMU reference clock to left input reference clock. + +serdes0: serdes@900000 { + compatible = "ti,phy-am654-serdes"; + reg = <0x0 0x900000 0x0 0x2000>; + reg-names = "serdes"; + #phy-cells = <2>; + power-domains = <&k3_pds 153>; + clocks = <&k3_clks 153 4>, <&k3_clks 153 1>, + <&serdes1 AM654_SERDES_LO_REFCLK>; + clock-output-names = "serdes0_cmu_refclk", "serdes0_lo_refclk", + "serdes0_ro_refclk"; + assigned-clocks = <&k3_clks 153 4>, <&serdes0 AM654_SERDES_CMU_REFCLK>; + assigned-clock-parents = <&k3_clks 153 8>, <&k3_clks 153 4>; + ti,serdes-clk = <&serdes0_clk>; + mux-controls = <&serdes_mux 0>; + #clock-cells = <1>; +}; + +Example for PCIe consumer node using the SERDES PHY specifier is given below. +&pcie0_rc { + num-lanes = <2>; + phys = <&serdes0 PHY_TYPE_PCIE 1>, <&serdes1 PHY_TYPE_PCIE 1>; + phy-names = "pcie-phy0", "pcie-phy1"; +};
include/dt-bindings/phy/phy-am654-serdes.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* This header provides constants for AM654 SERDES. +*/ + +#ifndef _DT_BINDINGS_AM654_SERDES +#define _DT_BINDINGS_AM654_SERDES + +#define AM654_SERDES_CMU_REFCLK 0 +#define AM654_SERDES_LO_REFCLK 1 +#define AM654_SERDES_RO_REFCLK 2 + +#endif /* _DT_BINDINGS_AM654_SERDES */
Signature · 1 line
2.17.1
PATCH v4 4/5 phy: ti: Add a new SERDES driver for TI's AM654x SoC
In reply to Kishon Vijay Abraham IAdd a new SERDES driver for TI's AM654x SoC which configures the SERDES only for PCIe. Support fo USB3 will be added later.
SERDES in am654x has three input clocks (left input, externel reference clock and right input) and two output clocks (left output and right output) in addition to a PLL mux clock which the SERDES uses for Clock Multiplier Unit (CMU refclock).
The PLL mux clock can select from one of the three input clocks. The right output can select between left input and external reference clock while the left output can select between the right input and external reference clock.
The driver has support to select PLL mux and left/right output mux as specified in device tree.
[[email protected]: Fix boot lockup caused by accessing a structure member (hw->init) allocated in stack of probe() and accessed in get_parent]
--- drivers/phy/ti/Kconfig | 12 + drivers/phy/ti/Makefile | 1 + drivers/phy/ti/phy-am654-serdes.c | 624 ++++++++++++++++++++++++++++++ 3 files changed, 637 insertions(+) create mode 100644 drivers/phy/ti/phy-am654-serdes.c
drivers/phy/ti/Kconfig +12 -0
@@ -20,6 +20,18 @@ config PHY_DM816X_USB help Enable this for dm816x USB to work. +config PHY_AM654_SERDES + tristate "TI AM654 SERDES support" + depends on OF && ARCH_K3 || COMPILE_TEST + depends on COMMON_CLK + select GENERIC_PHY + select MULTIPLEXER + select REGMAP_MMIO + select MUX_MMIO + help + This option enables support for TI AM654 SerDes PHY used for + PCIe. + config OMAP_CONTROL_PHY tristate "OMAP CONTROL PHY Driver" depends on ARCH_OMAP2PLUS || COMPILE_TEST
drivers/phy/ti/Makefile +1 -0
@@ -6,5 +6,6 @@ obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o +obj-$(CONFIG_PHY_AM654_SERDES) += phy-am654-serdes.o obj-$(CONFIG_PHY_TI_GMII_SEL) += phy-gmii-sel.o obj-$(CONFIG_PHY_TI_KEYSTONE_SERDES) += phy-keystone-serdes.o
drivers/phy/ti/phy-am654-serdes.c new file +624 -0
624 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 5/5 phy: ti: am654-serdes: Support all clksel values
In reply to Kishon Vijay Abraham IFrom: Roger Quadros <[email protected]>
Add support to select all 16 CLKSEL combinations that are shown in "SerDes Reference Clock Distribution" in AM65 TRM.
--- drivers/phy/ti/phy-am654-serdes.c | 132 +++++++++++++++++++----------- 1 file changed, 83 insertions(+), 49 deletions(-)
drivers/phy/ti/phy-am654-serdes.c +83 -49
@@ -58,13 +58,14 @@#define SERDES_NUM_CLOCKS 3 +#define AM654_SERDES_CTRL_CLKSEL_MASK GENMASK(7, 4) +#define AM654_SERDES_CTRL_CLKSEL_SHIFT 4 +struct serdes_am654_clk_mux {struct clk_hw hw;struct regmap *regmap;unsigned int reg; -int *table; -u32 mask; -u8 shift; +int clk_id;struct clk_init_data clk_data; };
@@ -282,31 +283,52 @@ static const struct phy_ops ops = { .owner = THIS_MODULE, }; +#define SERDES_NUM_MUX_COMBINATIONS 16 + +#define LICLK 0 +#define EXT_REFCLK 1 +#define RICLK 2 + +static const int +serdes_am654_mux_table[SERDES_NUM_MUX_COMBINATIONS ][SERDES_NUM_CLOCKS ] = { +/* +* Each combination maps to one of +* "Figure 12-1986. SerDes Reference Clock Distribution" +* in TRM. +*/ +/* Parent of CMU refclk, Left output, Right output +* either of EXT_REFCLK, LICLK, RICLK +*/ + {EXT_REFCLK ,EXT_REFCLK ,EXT_REFCLK },/* 0000 */ + {RICLK ,EXT_REFCLK ,EXT_REFCLK },/* 0001 */ + {EXT_REFCLK ,RICLK ,LICLK },/* 0010 */ + {RICLK ,RICLK ,EXT_REFCLK },/* 0011 */ + {LICLK ,EXT_REFCLK ,EXT_REFCLK },/* 0100 */ + {EXT_REFCLK ,EXT_REFCLK ,EXT_REFCLK },/* 0101 */ + {LICLK ,RICLK ,LICLK },/* 0110 */ + {EXT_REFCLK ,RICLK ,LICLK },/* 0111 */ + {EXT_REFCLK ,EXT_REFCLK ,LICLK },/* 1000 */ + {RICLK ,EXT_REFCLK ,LICLK },/* 1001 */ + {EXT_REFCLK ,RICLK ,EXT_REFCLK },/* 1010 */ + {RICLK ,RICLK ,EXT_REFCLK },/* 1011 */ + {LICLK ,EXT_REFCLK ,LICLK },/* 1100 */ + {EXT_REFCLK ,EXT_REFCLK ,LICLK },/* 1101 */ + {LICLK ,RICLK ,EXT_REFCLK },/* 1110 */ + {EXT_REFCLK ,RICLK ,EXT_REFCLK },/* 1111 */ +}; +static u8 serdes_am654_clk_mux_get_parent (struct clk_hw *hw) {struct serdes_am654_clk_mux *mux =to_serdes_am654_clk_mux (hw); -unsigned int num_parents =clk_hw_get_num_parents (hw);struct regmap *regmap = mux->regmap;unsigned int reg = mux->reg;unsigned int val; -int i;regmap_read (regmap, reg, &val); - val >>= mux->shift; - val &= mux->mask; - -for (i =0 ; i < num_parents; i++) -if (mux->table[i] == val) -return i; - -/* -* No parent? This should never happen! -* Verify if we set a valid parent in serdes_am654_clk_register() -*/ -WARN (1 ,"Failed to find the parent of %s clock\n" , hw->init->name); + val &=AM654_SERDES_CTRL_CLKSEL_MASK ; + val >>=AM654_SERDES_CTRL_CLKSEL_SHIFT ; -/* Make the parent lookup to fail */ -return num_parents; +return serdes_am654_mux_table[val][mux->clk_id]; }static int serdes_am654_clk_mux_set_parent (struct clk_hw *hw,u8 index)
@@ -314,16 +336,52 @@ static int serdes_am654_clk_mux_set_parent(struct clk_hw *hw, u8 index)struct serdes_am654_clk_mux *mux =to_serdes_am654_clk_mux (hw);struct regmap *regmap = mux->regmap;unsigned int reg = mux->reg; -int val; +int clk_id = mux->clk_id; +int parents[SERDES_NUM_CLOCKS ]; +const int *p; +u32 val; +int found, i;int ret; - val = mux->table[index]; +/* get existing setting */ +regmap_read (regmap, reg, &val); + val &=AM654_SERDES_CTRL_CLKSEL_MASK ; + val >>=AM654_SERDES_CTRL_CLKSEL_SHIFT ; + +for (i =0 ; i <SERDES_NUM_CLOCKS ; i++) + parents[i] = serdes_am654_mux_table[val][i]; + +/* change parent of this clock. others left intact */ + parents[clk_id] = index; + +/* Find the match */ +for (val =0 ; val <SERDES_NUM_MUX_COMBINATIONS ; val++) { + p = serdes_am654_mux_table[val]; + found =1 ; +for (i =0 ; i <SERDES_NUM_CLOCKS ; i++) { +if (parents[i] != p[i]) { + found =0 ; +break ; + } + } + +if (found) +break ; + } -if (val ==-1 ) +if (!found) { +/* +* This can never happen, unless we missed +* a valid combination in serdes_am654_mux_table. +*/ +WARN (1 ,"Failed to find the parent of %s clock\n" , + hw->init->name);return -EINVAL ; + } - val <<= mux->shift; - ret =regmap_update_bits (regmap, reg, mux->mask << mux->shift, val); + val <<=AM654_SERDES_CTRL_CLKSEL_SHIFT ; + ret =regmap_update_bits (regmap, reg,AM654_SERDES_CTRL_CLKSEL_MASK , + val);return ret; }
@@ -333,21 +391,6 @@ static const struct clk_ops serdes_am654_clk_mux_ops = { .get_parent = serdes_am654_clk_mux_get_parent, }; -static int mux_table[SERDES_NUM_CLOCKS ][3 ] = { -/* -* The entries represent values for selecting between -* {left input, external reference clock, right input} -* Only one of Left Output or Right Output should be used since -* both left and right output clock uses the same bits and modifying -* one clock will impact the other. -*/ - {BIT (2 ),0 ,BIT (0 ) },/* Mux of CMU refclk */ - {-1 ,BIT (3 ),BIT (1 ) },/* Mux of Left Output */ - {BIT (1 ),BIT (3 ) |BIT (1 ),-1 },/* Mux of Right Output */ -}; - -static int mux_mask[SERDES_NUM_CLOCKS ] = {0x5 ,0xa ,0xa }; -static int serdes_am654_clk_register (struct serdes_am654 *am654_phy,const char *clock_name,int clock_num) {
@@ -407,20 +450,11 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, init->num_parents = num_parents; init->name = clock_name; - mux->table = mux_table[clock_num]; mux->regmap = regmap; mux->reg = reg; - mux->shift =4 ; - mux->mask = mux_mask[clock_num]; + mux->clk_id = clock_num; mux->hw.init = init; -/* -* setup a sane default so get_parent() call evaluates -* to a valid parent. Index 1 is the safest choice as -* the default as it is valid value for all of serdes's -* output clocks. -*/ -serdes_am654_clk_mux_set_parent (&mux->hw,1 ); clk =devm_clk_register (dev, &mux->hw);if (IS_ERR (clk))return PTR_ERR (clk);
Signature · 1 line
2.17.1
Kishon,
Quoted 22 lines · Kishon Vijay Abraham I
This patch series
*) adds support for SERDES module in am654
*) modifiesphy_resetAPI to invoke pm_runtime_get/pm_runtime_put since
the reset callback can access registers.
*) Add *release*phy_opsto be invoked when the consumer relinquishes
PHYChanges from v3:
*) Moved SERDES driver to use regfield
*) Removed reg-names binding and updated Documentation for
power-domainsChanges from v2:
*) Fix typos pointed out by Roger
*) Add dt-binding Documentation in a new file ti,phy-am654-serdes.txt *) Add Roger's patch to support all CLKSEL values.Changes from v1:
*) Add *release* phy ops
*) Populate releasephy_opsin phy-am654-serdes to cleanup
initializations done inof_xlate
Quoted 8 lines
Kishon Vijay Abraham I (4):
phy: core: Add *release*phy_opsinvoked when the consumer
relinquishes PHY
phy: core: Invoke pm_runtime_get_*/pm_runtime_put_* before invoking
reset callback
dt-bindings: phy: ti: Add dt binding documentation for SERDES inAM654x SoCphy: ti: Add a new SERDES driver for TI's AM654x SoC
For these patches,
Quoted 4 lines
Roger Quadros (1):
phy: ti: am654-serdes: Support all clksel values
Quoted 12 lines
.../bindings/phy/ti,phy-am654-serdes.txt | 82 +++ drivers/phy/phy-core.c | 11 + drivers/phy/ti/Kconfig | 12 + drivers/phy/ti/Makefile | 1 + drivers/phy/ti/phy-am654-serdes.c | 658 ++++++++++++++++++ include/dt-bindings/phy/phy-am654-serdes.h | 13 + include/linux/phy/phy.h | 2 + 7 files changed, 779 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/ti,phy-am654-serdes.txt create mode 100644 drivers/phy/ti/phy-am654-serdes.c create mode 100644 include/dt-bindings/phy/phy-am654-serdes.h
cheers,
-roger
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki