-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clk: rockchip: implement linked gate clock support
Recent Rockchip SoCs have a new hardware block called Native Interface Unit (NIU), which gates clocks to devices behind them. These clock gates will only have a running output clock when all of the following conditions are met: 1. the parent clock is enabled 2. the enable bit is set correctly 3. the linked clock is enabled To handle them this code registers them as a normal gate type clock, which takes care of condition 1 + 2. The linked clock is handled by using runtime PM clocks. Handling it via runtime PM requires setting up a struct device for each of these clocks with a driver attached to use the correct runtime PM operations. Thus the complete handling of these clocks has been moved into its own driver. Signed-off-by: Sebastian Reichel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Stuebner <[email protected]>
- Loading branch information
Showing
5 changed files
with
165 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2024 Collabora Ltd. | ||
* Author: Sebastian Reichel <[email protected]> | ||
*/ | ||
|
||
#include <linux/clk.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/pm_clock.h> | ||
#include <linux/pm_runtime.h> | ||
#include <linux/property.h> | ||
#include "clk.h" | ||
|
||
static int rk_clk_gate_link_register(struct device *dev, | ||
struct rockchip_clk_provider *ctx, | ||
struct rockchip_clk_branch *clkbr) | ||
{ | ||
unsigned long flags = clkbr->flags | CLK_SET_RATE_PARENT; | ||
struct clk *clk; | ||
|
||
clk = clk_register_gate(dev, clkbr->name, clkbr->parent_names[0], | ||
flags, ctx->reg_base + clkbr->gate_offset, | ||
clkbr->gate_shift, clkbr->gate_flags, | ||
&ctx->lock); | ||
|
||
if (IS_ERR(clk)) | ||
return PTR_ERR(clk); | ||
|
||
rockchip_clk_set_lookup(ctx, clk, clkbr->id); | ||
return 0; | ||
} | ||
|
||
static int rk_clk_gate_link_probe(struct platform_device *pdev) | ||
{ | ||
struct rockchip_gate_link_platdata *pdata; | ||
struct device *dev = &pdev->dev; | ||
struct clk *linked_clk; | ||
int ret; | ||
|
||
pdata = dev_get_platdata(dev); | ||
if (!pdata) | ||
return dev_err_probe(dev, -ENODEV, "missing platform data"); | ||
|
||
ret = devm_pm_runtime_enable(dev); | ||
if (ret) | ||
return ret; | ||
|
||
ret = devm_pm_clk_create(dev); | ||
if (ret) | ||
return ret; | ||
|
||
linked_clk = rockchip_clk_get_lookup(pdata->ctx, pdata->clkbr->linked_clk_id); | ||
ret = pm_clk_add_clk(dev, linked_clk); | ||
if (ret) | ||
return ret; | ||
|
||
ret = rk_clk_gate_link_register(dev, pdata->ctx, pdata->clkbr); | ||
if (ret) | ||
goto err; | ||
|
||
return 0; | ||
|
||
err: | ||
pm_clk_remove_clk(dev, linked_clk); | ||
return ret; | ||
} | ||
|
||
static const struct dev_pm_ops rk_clk_gate_link_pm_ops = { | ||
SET_RUNTIME_PM_OPS(pm_clk_suspend, pm_clk_resume, NULL) | ||
}; | ||
|
||
static struct platform_driver rk_clk_gate_link_driver = { | ||
.probe = rk_clk_gate_link_probe, | ||
.driver = { | ||
.name = "rockchip-gate-link-clk", | ||
.pm = &rk_clk_gate_link_pm_ops, | ||
.suppress_bind_attrs = true, | ||
}, | ||
}; | ||
|
||
static int __init rk_clk_gate_link_drv_register(void) | ||
{ | ||
return platform_driver_register(&rk_clk_gate_link_driver); | ||
} | ||
core_initcall(rk_clk_gate_link_drv_register); |