Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 7 | #include <clk-uclass.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 9 | #include <dm/device-internal.h> |
Peng Fan | ec424a7 | 2019-07-31 07:01:39 +0000 | [diff] [blame] | 10 | #include <linux/clk-provider.h> |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 11 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 12 | static ulong clk_fixed_rate_get_rate(struct clk *clk) |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 13 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 14 | return to_clk_fixed_rate(clk->dev)->fixed_rate; |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 15 | } |
| 16 | |
developer | cdb0efd | 2020-01-09 11:35:08 +0800 | [diff] [blame] | 17 | /* avoid clk_enable() return -ENOSYS */ |
| 18 | static int dummy_enable(struct clk *clk) |
| 19 | { |
| 20 | return 0; |
| 21 | } |
| 22 | |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 23 | const struct clk_ops clk_fixed_rate_ops = { |
| 24 | .get_rate = clk_fixed_rate_get_rate, |
developer | cdb0efd | 2020-01-09 11:35:08 +0800 | [diff] [blame] | 25 | .enable = dummy_enable, |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 26 | }; |
| 27 | |
Simon Glass | b95c7b9 | 2021-03-15 17:25:23 +1300 | [diff] [blame] | 28 | void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev, |
| 29 | struct clk_fixed_rate *plat) |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 30 | { |
Simon Glass | b95c7b9 | 2021-03-15 17:25:23 +1300 | [diff] [blame] | 31 | struct clk *clk = &plat->clk; |
Simon Glass | 589d915 | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 32 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | b95c7b9 | 2021-03-15 17:25:23 +1300 | [diff] [blame] | 33 | plat->fixed_rate = dev_read_u32_default(dev, "clock-frequency", 0); |
Simon Glass | 589d915 | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 34 | #endif |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 35 | /* Make fixed rate clock accessible from higher level struct clk */ |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 36 | /* FIXME: This is not allowed */ |
| 37 | dev_set_uclass_priv(dev, clk); |
Simon Glass | b95c7b9 | 2021-03-15 17:25:23 +1300 | [diff] [blame] | 38 | |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 39 | clk->dev = dev; |
Peng Fan | 30a6ebc | 2019-08-21 13:35:03 +0000 | [diff] [blame] | 40 | clk->enable_count = 0; |
Simon Glass | b95c7b9 | 2021-03-15 17:25:23 +1300 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static int clk_fixed_rate_of_to_plat(struct udevice *dev) |
| 44 | { |
| 45 | clk_fixed_rate_ofdata_to_plat_(dev, to_clk_fixed_rate(dev)); |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static const struct udevice_id clk_fixed_rate_match[] = { |
| 51 | { |
| 52 | .compatible = "fixed-clock", |
| 53 | }, |
| 54 | { /* sentinel */ } |
| 55 | }; |
| 56 | |
Simon Glass | 6b927b1 | 2020-10-03 11:31:32 -0600 | [diff] [blame] | 57 | U_BOOT_DRIVER(fixed_clock) = { |
| 58 | .name = "fixed_clock", |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 59 | .id = UCLASS_CLK, |
| 60 | .of_match = clk_fixed_rate_match, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 61 | .of_to_plat = clk_fixed_rate_of_to_plat, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 62 | .plat_auto = sizeof(struct clk_fixed_rate), |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 63 | .ops = &clk_fixed_rate_ops, |
Michal Simek | 34f6781 | 2020-09-16 13:20:55 +0200 | [diff] [blame] | 64 | .flags = DM_FLAG_PRE_RELOC, |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 65 | }; |