2019-05-29 14:18:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-10-13 22:52:44 +00:00
|
|
|
/*
|
|
|
|
* Clkout driver for Rockchip RK808
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
|
|
|
|
*
|
|
|
|
* Author:Chris Zhong <zyw@rock-chips.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/mfd/rk808.h>
|
|
|
|
|
|
|
|
struct rk808_clkout {
|
2023-05-04 17:36:05 +00:00
|
|
|
struct regmap *regmap;
|
2014-10-13 22:52:44 +00:00
|
|
|
struct clk_hw clkout1_hw;
|
|
|
|
struct clk_hw clkout2_hw;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long rk808_clkout_recalc_rate(struct clk_hw *hw,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
return 32768;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rk808_clkout2_enable(struct clk_hw *hw, bool enable)
|
|
|
|
{
|
|
|
|
struct rk808_clkout *rk808_clkout = container_of(hw,
|
|
|
|
struct rk808_clkout,
|
|
|
|
clkout2_hw);
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
return regmap_update_bits(rk808_clkout->regmap, RK808_CLK32OUT_REG,
|
2014-10-13 22:52:44 +00:00
|
|
|
CLK32KOUT2_EN, enable ? CLK32KOUT2_EN : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rk808_clkout2_prepare(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
return rk808_clkout2_enable(hw, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rk808_clkout2_unprepare(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
rk808_clkout2_enable(hw, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rk808_clkout2_is_prepared(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct rk808_clkout *rk808_clkout = container_of(hw,
|
|
|
|
struct rk808_clkout,
|
|
|
|
clkout2_hw);
|
|
|
|
uint32_t val;
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
int ret = regmap_read(rk808_clkout->regmap, RK808_CLK32OUT_REG, &val);
|
2014-10-13 22:52:44 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return (val & CLK32KOUT2_EN) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clk_ops rk808_clkout1_ops = {
|
|
|
|
.recalc_rate = rk808_clkout_recalc_rate,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct clk_ops rk808_clkout2_ops = {
|
|
|
|
.prepare = rk808_clkout2_prepare,
|
|
|
|
.unprepare = rk808_clkout2_unprepare,
|
|
|
|
.is_prepared = rk808_clkout2_is_prepared,
|
|
|
|
.recalc_rate = rk808_clkout_recalc_rate,
|
|
|
|
};
|
|
|
|
|
2016-06-01 23:15:23 +00:00
|
|
|
static struct clk_hw *
|
|
|
|
of_clk_rk808_get(struct of_phandle_args *clkspec, void *data)
|
|
|
|
{
|
|
|
|
struct rk808_clkout *rk808_clkout = data;
|
|
|
|
unsigned int idx = clkspec->args[0];
|
|
|
|
|
|
|
|
if (idx >= 2) {
|
|
|
|
pr_err("%s: invalid index %u\n", __func__, idx);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx ? &rk808_clkout->clkout2_hw : &rk808_clkout->clkout1_hw;
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:34:55 +00:00
|
|
|
static int rk817_clkout2_enable(struct clk_hw *hw, bool enable)
|
|
|
|
{
|
|
|
|
struct rk808_clkout *rk808_clkout = container_of(hw,
|
|
|
|
struct rk808_clkout,
|
|
|
|
clkout2_hw);
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
return regmap_update_bits(rk808_clkout->regmap, RK817_SYS_CFG(1),
|
2019-06-21 10:34:55 +00:00
|
|
|
RK817_CLK32KOUT2_EN,
|
|
|
|
enable ? RK817_CLK32KOUT2_EN : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rk817_clkout2_prepare(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
return rk817_clkout2_enable(hw, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rk817_clkout2_unprepare(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
rk817_clkout2_enable(hw, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rk817_clkout2_is_prepared(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct rk808_clkout *rk808_clkout = container_of(hw,
|
|
|
|
struct rk808_clkout,
|
|
|
|
clkout2_hw);
|
|
|
|
unsigned int val;
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
int ret = regmap_read(rk808_clkout->regmap, RK817_SYS_CFG(1), &val);
|
2019-06-21 10:34:55 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (val & RK817_CLK32KOUT2_EN) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clk_ops rk817_clkout2_ops = {
|
|
|
|
.prepare = rk817_clkout2_prepare,
|
|
|
|
.unprepare = rk817_clkout2_unprepare,
|
|
|
|
.is_prepared = rk817_clkout2_is_prepared,
|
|
|
|
.recalc_rate = rk808_clkout_recalc_rate,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct clk_ops *rkpmic_get_ops(long variant)
|
|
|
|
{
|
|
|
|
switch (variant) {
|
|
|
|
case RK809_ID:
|
|
|
|
case RK817_ID:
|
|
|
|
return &rk817_clkout2_ops;
|
|
|
|
/*
|
|
|
|
* For the default case, it match the following PMIC type.
|
|
|
|
* RK805_ID
|
|
|
|
* RK808_ID
|
|
|
|
* RK818_ID
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
return &rk808_clkout2_ops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 22:52:44 +00:00
|
|
|
static int rk808_clkout_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
|
2023-05-04 17:36:05 +00:00
|
|
|
struct device *dev = &pdev->dev;
|
2014-10-13 22:52:44 +00:00
|
|
|
struct clk_init_data init = {};
|
|
|
|
struct rk808_clkout *rk808_clkout;
|
2016-06-01 23:15:23 +00:00
|
|
|
int ret;
|
2014-10-13 22:52:44 +00:00
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
dev->of_node = pdev->dev.parent->of_node;
|
|
|
|
|
|
|
|
rk808_clkout = devm_kzalloc(dev,
|
2014-10-13 22:52:44 +00:00
|
|
|
sizeof(*rk808_clkout), GFP_KERNEL);
|
|
|
|
if (!rk808_clkout)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
rk808_clkout->regmap = dev_get_regmap(pdev->dev.parent, NULL);
|
|
|
|
if (!rk808_clkout->regmap)
|
|
|
|
return -ENODEV;
|
2014-10-13 22:52:44 +00:00
|
|
|
|
|
|
|
init.parent_names = NULL;
|
|
|
|
init.num_parents = 0;
|
|
|
|
init.name = "rk808-clkout1";
|
|
|
|
init.ops = &rk808_clkout1_ops;
|
|
|
|
rk808_clkout->clkout1_hw.init = &init;
|
|
|
|
|
|
|
|
/* optional override of the clockname */
|
2023-05-04 17:36:05 +00:00
|
|
|
of_property_read_string_index(dev->of_node, "clock-output-names",
|
2014-10-13 22:52:44 +00:00
|
|
|
0, &init.name);
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
ret = devm_clk_hw_register(dev, &rk808_clkout->clkout1_hw);
|
2016-06-01 23:15:23 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-10-13 22:52:44 +00:00
|
|
|
|
|
|
|
init.name = "rk808-clkout2";
|
2019-06-21 10:34:55 +00:00
|
|
|
init.ops = rkpmic_get_ops(rk808->variant);
|
2014-10-13 22:52:44 +00:00
|
|
|
rk808_clkout->clkout2_hw.init = &init;
|
|
|
|
|
|
|
|
/* optional override of the clockname */
|
2023-05-04 17:36:05 +00:00
|
|
|
of_property_read_string_index(dev->of_node, "clock-output-names",
|
2014-10-13 22:52:44 +00:00
|
|
|
1, &init.name);
|
|
|
|
|
2023-05-04 17:36:05 +00:00
|
|
|
ret = devm_clk_hw_register(dev, &rk808_clkout->clkout2_hw);
|
2016-06-01 23:15:23 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-10-13 22:52:44 +00:00
|
|
|
|
2018-12-04 11:38:03 +00:00
|
|
|
return devm_of_clk_add_hw_provider(&pdev->dev, of_clk_rk808_get,
|
|
|
|
rk808_clkout);
|
2014-10-13 22:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver rk808_clkout_driver = {
|
|
|
|
.probe = rk808_clkout_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "rk808-clkout",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(rk808_clkout_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Clkout driver for the rk808 series PMICs");
|
|
|
|
MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:rk808-clkout");
|