hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/clk/clk-pwm.c
....@@ -1,9 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2014 Philipp Zabel, Pengutronix
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
74 *
85 * PWM (mis)used as clock output
96 */
....@@ -47,16 +44,30 @@
4744 return clk_pwm->fixed_rate;
4845 }
4946
47
+static int clk_pwm_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
48
+{
49
+ struct clk_pwm *clk_pwm = to_clk_pwm(hw);
50
+ struct pwm_state state;
51
+
52
+ pwm_get_state(clk_pwm->pwm, &state);
53
+
54
+ duty->num = state.duty_cycle;
55
+ duty->den = state.period;
56
+
57
+ return 0;
58
+}
59
+
5060 static const struct clk_ops clk_pwm_ops = {
5161 .prepare = clk_pwm_prepare,
5262 .unprepare = clk_pwm_unprepare,
5363 .recalc_rate = clk_pwm_recalc_rate,
64
+ .get_duty_cycle = clk_pwm_get_duty_cycle,
5465 };
5566
5667 static int clk_pwm_probe(struct platform_device *pdev)
5768 {
5869 struct device_node *node = pdev->dev.of_node;
59
- struct clk_init_data init = {};
70
+ struct clk_init_data init;
6071 struct clk_pwm *clk_pwm;
6172 struct pwm_device *pwm;
6273 struct pwm_args pargs;
....@@ -80,6 +91,11 @@
8091 if (of_property_read_u32(node, "clock-frequency", &clk_pwm->fixed_rate))
8192 clk_pwm->fixed_rate = div64_u64(NSEC_PER_SEC, pargs.period);
8293
94
+ if (!clk_pwm->fixed_rate) {
95
+ dev_err(&pdev->dev, "fixed_rate cannot be zero\n");
96
+ return -EINVAL;
97
+ }
98
+
8399 if (pargs.period != NSEC_PER_SEC / clk_pwm->fixed_rate &&
84100 pargs.period != DIV_ROUND_UP(NSEC_PER_SEC, clk_pwm->fixed_rate)) {
85101 dev_err(&pdev->dev,
....@@ -101,7 +117,7 @@
101117
102118 init.name = clk_name;
103119 init.ops = &clk_pwm_ops;
104
- init.flags = CLK_IS_BASIC;
120
+ init.flags = 0;
105121 init.num_parents = 0;
106122
107123 clk_pwm->pwm = pwm;