Skip to content

Commit 86e2ed4

Browse files
Frank Wangvinodkoul
authored andcommitted
phy: rockchip: inno-usb2: convert clock management to bulk
Since some Rockchip SoCs (e.g RK3576) have more than one clock, this converts the clock management from single to bulk method to make the driver more flexible. Signed-off-by: Frank Wang <[email protected]> Reviewed-by: Heiko Stuebner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e592a65 commit 86e2ed4

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

drivers/phy/rockchip/phy-rockchip-inno-usb2.c

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,10 @@ struct rockchip_usb2phy_port {
229229
* @dev: pointer to device.
230230
* @grf: General Register Files regmap.
231231
* @usbgrf: USB General Register Files regmap.
232-
* @clk: clock struct of phy input clk.
232+
* @clks: array of phy input clocks.
233233
* @clk480m: clock struct of phy output clk.
234234
* @clk480m_hw: clock struct of phy output clk management.
235+
* @num_clks: number of phy input clocks.
235236
* @phy_reset: phy reset control.
236237
* @chg_state: states involved in USB charger detection.
237238
* @chg_type: USB charger types.
@@ -246,9 +247,10 @@ struct rockchip_usb2phy {
246247
struct device *dev;
247248
struct regmap *grf;
248249
struct regmap *usbgrf;
249-
struct clk *clk;
250+
struct clk_bulk_data *clks;
250251
struct clk *clk480m;
251252
struct clk_hw clk480m_hw;
253+
int num_clks;
252254
struct reset_control *phy_reset;
253255
enum usb_chg_state chg_state;
254256
enum power_supply_type chg_type;
@@ -310,6 +312,13 @@ static int rockchip_usb2phy_reset(struct rockchip_usb2phy *rphy)
310312
return 0;
311313
}
312314

315+
static void rockchip_usb2phy_clk_bulk_disable(void *data)
316+
{
317+
struct rockchip_usb2phy *rphy = data;
318+
319+
clk_bulk_disable_unprepare(rphy->num_clks, rphy->clks);
320+
}
321+
313322
static int rockchip_usb2phy_clk480m_prepare(struct clk_hw *hw)
314323
{
315324
struct rockchip_usb2phy *rphy =
@@ -376,7 +385,9 @@ rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy)
376385
{
377386
struct device_node *node = rphy->dev->of_node;
378387
struct clk_init_data init;
388+
struct clk *refclk = NULL;
379389
const char *clk_name;
390+
int i;
380391
int ret = 0;
381392

382393
init.flags = 0;
@@ -386,8 +397,15 @@ rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy)
386397
/* optional override of the clockname */
387398
of_property_read_string(node, "clock-output-names", &init.name);
388399

389-
if (rphy->clk) {
390-
clk_name = __clk_get_name(rphy->clk);
400+
for (i = 0; i < rphy->num_clks; i++) {
401+
if (!strncmp(rphy->clks[i].id, "phyclk", 6)) {
402+
refclk = rphy->clks[i].clk;
403+
break;
404+
}
405+
}
406+
407+
if (!IS_ERR(refclk)) {
408+
clk_name = __clk_get_name(refclk);
391409
init.parent_names = &clk_name;
392410
init.num_parents = 1;
393411
} else {
@@ -1399,15 +1417,26 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
13991417
if (IS_ERR(rphy->phy_reset))
14001418
return PTR_ERR(rphy->phy_reset);
14011419

1402-
rphy->clk = devm_clk_get_optional_enabled(dev, "phyclk");
1403-
if (IS_ERR(rphy->clk))
1404-
return dev_err_probe(&pdev->dev, PTR_ERR(rphy->clk),
1405-
"failed to get phyclk\n");
1420+
ret = devm_clk_bulk_get_all(dev, &rphy->clks);
1421+
if (ret == -EPROBE_DEFER)
1422+
return dev_err_probe(&pdev->dev, -EPROBE_DEFER,
1423+
"failed to get phy clock\n");
1424+
1425+
/* Clocks are optional */
1426+
rphy->num_clks = ret < 0 ? 0 : ret;
14061427

14071428
ret = rockchip_usb2phy_clk480m_register(rphy);
14081429
if (ret)
14091430
return dev_err_probe(dev, ret, "failed to register 480m output clock\n");
14101431

1432+
ret = clk_bulk_prepare_enable(rphy->num_clks, rphy->clks);
1433+
if (ret)
1434+
return dev_err_probe(dev, ret, "failed to enable phy clock\n");
1435+
1436+
ret = devm_add_action_or_reset(dev, rockchip_usb2phy_clk_bulk_disable, rphy);
1437+
if (ret)
1438+
return ret;
1439+
14111440
if (rphy->phy_cfg->phy_tuning) {
14121441
ret = rphy->phy_cfg->phy_tuning(rphy);
14131442
if (ret)

0 commit comments

Comments
 (0)