Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 7 | #include <clk-uclass.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Peng Fan | 4f305bf | 2019-07-31 07:01:39 +0000 | [diff] [blame] | 9 | #include <linux/clk-provider.h> |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 10 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 11 | static ulong clk_fixed_rate_get_rate(struct clk *clk) |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 12 | { |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 13 | return to_clk_fixed_rate(clk->dev)->fixed_rate; |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 14 | } |
| 15 | |
Chunfeng Yun | 6bf6d81 | 2020-01-09 11:35:08 +0800 | [diff] [blame] | 16 | /* avoid clk_enable() return -ENOSYS */ |
| 17 | static int dummy_enable(struct clk *clk) |
| 18 | { |
| 19 | return 0; |
| 20 | } |
| 21 | |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 22 | const struct clk_ops clk_fixed_rate_ops = { |
| 23 | .get_rate = clk_fixed_rate_get_rate, |
Chunfeng Yun | 6bf6d81 | 2020-01-09 11:35:08 +0800 | [diff] [blame] | 24 | .enable = dummy_enable, |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev) |
| 28 | { |
Lukasz Majewski | 36bac0a | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 29 | struct clk *clk = &to_clk_fixed_rate(dev)->clk; |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 30 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mario Six | e2db9e7 | 2018-01-15 11:06:52 +0100 | [diff] [blame] | 31 | to_clk_fixed_rate(dev)->fixed_rate = |
| 32 | dev_read_u32_default(dev, "clock-frequency", 0); |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 33 | #endif |
Lukasz Majewski | 36bac0a | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 34 | /* Make fixed rate clock accessible from higher level struct clk */ |
| 35 | dev->uclass_priv = clk; |
| 36 | clk->dev = dev; |
Peng Fan | e6849e2 | 2019-08-21 13:35:03 +0000 | [diff] [blame] | 37 | clk->enable_count = 0; |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static const struct udevice_id clk_fixed_rate_match[] = { |
| 43 | { |
| 44 | .compatible = "fixed-clock", |
| 45 | }, |
| 46 | { /* sentinel */ } |
| 47 | }; |
| 48 | |
Simon Glass | 8828052 | 2020-10-03 11:31:32 -0600 | [diff] [blame] | 49 | U_BOOT_DRIVER(fixed_clock) = { |
| 50 | .name = "fixed_clock", |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 51 | .id = UCLASS_CLK, |
| 52 | .of_match = clk_fixed_rate_match, |
| 53 | .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 54 | .plat_auto = sizeof(struct clk_fixed_rate), |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 55 | .ops = &clk_fixed_rate_ops, |
Michal Simek | 4ab3817 | 2020-09-16 13:20:55 +0200 | [diff] [blame] | 56 | .flags = DM_FLAG_PRE_RELOC, |
Masahiro Yamada | b21e20b | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 57 | }; |