Blame view
drivers/clk/clk-rk808.c
5.02 KB
2025cf9e1 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
038b892aa clk: RK808: add c... |
2 3 4 5 6 7 |
/* * Clkout driver for Rockchip RK808 * * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd * * Author:Chris Zhong <zyw@rock-chips.com> |
038b892aa clk: RK808: add c... |
8 |
*/ |
038b892aa clk: RK808: add c... |
9 10 11 12 13 14 |
#include <linux/clk-provider.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/platform_device.h> #include <linux/mfd/rk808.h> #include <linux/i2c.h> |
038b892aa clk: RK808: add c... |
15 16 |
struct rk808_clkout { struct rk808 *rk808; |
038b892aa clk: RK808: add c... |
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
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); struct rk808 *rk808 = rk808_clkout->rk808; return regmap_update_bits(rk808->regmap, RK808_CLK32OUT_REG, 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); struct rk808 *rk808 = rk808_clkout->rk808; uint32_t val; int ret = regmap_read(rk808->regmap, RK808_CLK32OUT_REG, &val); 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, }; |
a8b6e85db clk: rk808: Migra... |
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
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 ", __func__, idx); return ERR_PTR(-EINVAL); } return idx ? &rk808_clkout->clkout2_hw : &rk808_clkout->clkout1_hw; } |
8ed144019 clk: RK808: Add R... |
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
static int rk817_clkout2_enable(struct clk_hw *hw, bool enable) { struct rk808_clkout *rk808_clkout = container_of(hw, struct rk808_clkout, clkout2_hw); struct rk808 *rk808 = rk808_clkout->rk808; return regmap_update_bits(rk808->regmap, RK817_SYS_CFG(1), 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); struct rk808 *rk808 = rk808_clkout->rk808; unsigned int val; int ret = regmap_read(rk808->regmap, RK817_SYS_CFG(1), &val); 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; } } |
038b892aa clk: RK808: add c... |
149 150 151 152 153 154 |
static int rk808_clkout_probe(struct platform_device *pdev) { struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); struct i2c_client *client = rk808->i2c; struct device_node *node = client->dev.of_node; struct clk_init_data init = {}; |
038b892aa clk: RK808: add c... |
155 |
struct rk808_clkout *rk808_clkout; |
a8b6e85db clk: rk808: Migra... |
156 |
int ret; |
038b892aa clk: RK808: add c... |
157 158 159 160 161 162 163 |
rk808_clkout = devm_kzalloc(&client->dev, sizeof(*rk808_clkout), GFP_KERNEL); if (!rk808_clkout) return -ENOMEM; rk808_clkout->rk808 = rk808; |
038b892aa clk: RK808: add c... |
164 165 166 167 168 169 170 171 172 |
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 */ of_property_read_string_index(node, "clock-output-names", 0, &init.name); |
a8b6e85db clk: rk808: Migra... |
173 174 175 |
ret = devm_clk_hw_register(&client->dev, &rk808_clkout->clkout1_hw); if (ret) return ret; |
038b892aa clk: RK808: add c... |
176 177 |
init.name = "rk808-clkout2"; |
8ed144019 clk: RK808: Add R... |
178 |
init.ops = rkpmic_get_ops(rk808->variant); |
038b892aa clk: RK808: add c... |
179 180 181 182 183 |
rk808_clkout->clkout2_hw.init = &init; /* optional override of the clockname */ of_property_read_string_index(node, "clock-output-names", 1, &init.name); |
a8b6e85db clk: rk808: Migra... |
184 185 186 |
ret = devm_clk_hw_register(&client->dev, &rk808_clkout->clkout2_hw); if (ret) return ret; |
038b892aa clk: RK808: add c... |
187 |
|
252246674 clk: rk808: use m... |
188 189 |
return devm_of_clk_add_hw_provider(&pdev->dev, of_clk_rk808_get, rk808_clkout); |
038b892aa clk: RK808: add c... |
190 191 192 193 |
} static struct platform_driver rk808_clkout_driver = { .probe = rk808_clkout_probe, |
038b892aa clk: RK808: add c... |
194 195 196 197 198 199 200 201 202 203 204 |
.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"); |