Skip to content

Commit 52c0624

Browse files
diandersUlf Hansson
authored andcommitted
phy: rockchip-emmc: Set phyctrl_frqsel based on card clock
The "phyctrl_frqsel" is described in the Arasan datasheet [1] as "the frequency range of DLL operation". Although the Rockchip variant of this PHY has different ranges than the reference Arasan PHY it appears as if the functionality is similar. We should set this phyctrl field properly. Note: as per Rockchip engineers, apparently the "phyctrl_frqsel" is actually only useful in HS200 / HS400 modes even though the DLL itself it used for some purposes in all modes. See the discussion in the earlier change in this series: ("mmc: sdhci-of-arasan: Always power the PHY off/on when clock changes"). In any case, it shouldn't hurt to set this always. Note that this change should allow boards to run at HS200 / HS400 speed modes while running at 100 MHz or 150 MHz. In fact, running HS400 at 150 MHz (giving 300 MB/s) is the main motivation of this series, since performance is still good but signal integrity problems are less prevelant at 150 MHz. [1]: https://arasan.com/wp-content/media/eMMC-5-1-Total-Solution_Rev-1-3.pdf Signed-off-by: Douglas Anderson <dianders@chromium.org> Acked-by: Kishon Vijay Abraham I <kishon@ti.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 352051e commit 52c0624

1 file changed

Lines changed: 89 additions & 12 deletions

File tree

‎drivers/phy/phy-rockchip-emmc.c‎

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* GNU General Public License for more details.
1515
*/
1616

17+
#include <linux/clk.h>
1718
#include <linux/delay.h>
1819
#include <linux/mfd/syscon.h>
1920
#include <linux/module.h>
@@ -78,15 +79,53 @@
7879
struct rockchip_emmc_phy {
7980
unsigned int reg_offset;
8081
struct regmap *reg_base;
82+
struct clk *emmcclk;
8183
};
8284

83-
static int rockchip_emmc_phy_power(struct rockchip_emmc_phy *rk_phy,
84-
bool on_off)
85+
static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
8586
{
87+
struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy);
8688
unsigned int caldone;
8789
unsigned int dllrdy;
90+
unsigned int freqsel = PHYCTRL_FREQSEL_200M;
8891
unsigned long timeout;
8992

93+
if (rk_phy->emmcclk != NULL) {
94+
unsigned long rate = clk_get_rate(rk_phy->emmcclk);
95+
unsigned long ideal_rate;
96+
unsigned long diff;
97+
98+
switch (rate) {
99+
case 0 ... 74999999:
100+
ideal_rate = 50000000;
101+
freqsel = PHYCTRL_FREQSEL_50M;
102+
break;
103+
case 75000000 ... 124999999:
104+
ideal_rate = 100000000;
105+
freqsel = PHYCTRL_FREQSEL_100M;
106+
break;
107+
case 125000000 ... 174999999:
108+
ideal_rate = 150000000;
109+
freqsel = PHYCTRL_FREQSEL_150M;
110+
break;
111+
default:
112+
ideal_rate = 200000000;
113+
break;
114+
};
115+
116+
diff = (rate > ideal_rate) ?
117+
rate - ideal_rate : ideal_rate - rate;
118+
119+
/*
120+
* In order for tuning delays to be accurate we need to be
121+
* pretty spot on for the DLL range, so warn if we're too
122+
* far off. Also warn if we're above the 200 MHz max. Don't
123+
* warn for really slow rates since we won't be tuning then.
124+
*/
125+
if ((rate > 50000000 && diff > 15000000) || (rate > 200000000))
126+
dev_warn(&phy->dev, "Unsupported rate: %lu\n", rate);
127+
}
128+
90129
/*
91130
* Keep phyctrl_pdb and phyctrl_endll low to allow
92131
* initialization of CALIO state M/C DFFs
@@ -132,6 +171,13 @@ static int rockchip_emmc_phy_power(struct rockchip_emmc_phy *rk_phy,
132171
return -ETIMEDOUT;
133172
}
134173

174+
/* Set the frequency of the DLL operation */
175+
regmap_write(rk_phy->reg_base,
176+
rk_phy->reg_offset + GRF_EMMCPHY_CON0,
177+
HIWORD_UPDATE(freqsel, PHYCTRL_FREQSEL_MASK,
178+
PHYCTRL_FREQSEL_SHIFT));
179+
180+
/* Turn on the DLL */
135181
regmap_write(rk_phy->reg_base,
136182
rk_phy->reg_offset + GRF_EMMCPHY_CON6,
137183
HIWORD_UPDATE(PHYCTRL_ENDLL_ENABLE,
@@ -166,25 +212,54 @@ static int rockchip_emmc_phy_power(struct rockchip_emmc_phy *rk_phy,
166212
return 0;
167213
}
168214

169-
static int rockchip_emmc_phy_power_off(struct phy *phy)
215+
static int rockchip_emmc_phy_init(struct phy *phy)
216+
{
217+
struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy);
218+
int ret = 0;
219+
220+
/*
221+
* We purposely get the clock here and not in probe to avoid the
222+
* circular dependency problem. We expect:
223+
* - PHY driver to probe
224+
* - SDHCI driver to start probe
225+
* - SDHCI driver to register it's clock
226+
* - SDHCI driver to get the PHY
227+
* - SDHCI driver to init the PHY
228+
*
229+
* The clock is optional, so upon any error we just set to NULL.
230+
*
231+
* NOTE: we don't do anything special for EPROBE_DEFER here. Given the
232+
* above expected use case, EPROBE_DEFER isn't sensible to expect, so
233+
* it's just like any other error.
234+
*/
235+
rk_phy->emmcclk = clk_get(&phy->dev, "emmcclk");
236+
if (IS_ERR(rk_phy->emmcclk)) {
237+
dev_dbg(&phy->dev, "Error getting emmcclk: %d\n", ret);
238+
rk_phy->emmcclk = NULL;
239+
}
240+
241+
return ret;
242+
}
243+
244+
static int rockchip_emmc_phy_exit(struct phy *phy)
170245
{
171246
struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy);
172247

248+
clk_put(rk_phy->emmcclk);
249+
250+
return 0;
251+
}
252+
253+
static int rockchip_emmc_phy_power_off(struct phy *phy)
254+
{
173255
/* Power down emmc phy analog blocks */
174-
return rockchip_emmc_phy_power(rk_phy, PHYCTRL_PDB_PWR_OFF);
256+
return rockchip_emmc_phy_power(phy, PHYCTRL_PDB_PWR_OFF);
175257
}
176258

177259
static int rockchip_emmc_phy_power_on(struct phy *phy)
178260
{
179261
struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy);
180262

181-
/* DLL operation: 200 MHz */
182-
regmap_write(rk_phy->reg_base,
183-
rk_phy->reg_offset + GRF_EMMCPHY_CON0,
184-
HIWORD_UPDATE(PHYCTRL_FREQSEL_200M,
185-
PHYCTRL_FREQSEL_MASK,
186-
PHYCTRL_FREQSEL_SHIFT));
187-
188263
/* Drive impedance: 50 Ohm */
189264
regmap_write(rk_phy->reg_base,
190265
rk_phy->reg_offset + GRF_EMMCPHY_CON6,
@@ -207,10 +282,12 @@ static int rockchip_emmc_phy_power_on(struct phy *phy)
207282
PHYCTRL_OTAPDLYSEL_SHIFT));
208283

209284
/* Power up emmc phy analog blocks */
210-
return rockchip_emmc_phy_power(rk_phy, PHYCTRL_PDB_PWR_ON);
285+
return rockchip_emmc_phy_power(phy, PHYCTRL_PDB_PWR_ON);
211286
}
212287

213288
static const struct phy_ops ops = {
289+
.init = rockchip_emmc_phy_init,
290+
.exit = rockchip_emmc_phy_exit,
214291
.power_on = rockchip_emmc_phy_power_on,
215292
.power_off = rockchip_emmc_phy_power_off,
216293
.owner = THIS_MODULE,

0 commit comments

Comments
 (0)