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 | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 28 | static int clk_fixed_rate_of_to_plat(struct udevice *dev) |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 29 | { |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 30 | struct clk *clk = &to_clk_fixed_rate(dev)->clk; |
Simon Glass | 589d915 | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 31 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mario Six | a6a0463 | 2018-01-15 11:06:52 +0100 | [diff] [blame] | 32 | to_clk_fixed_rate(dev)->fixed_rate = |
| 33 | 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); |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 38 | clk->dev = dev; |
Peng Fan | 30a6ebc | 2019-08-21 13:35:03 +0000 | [diff] [blame] | 39 | clk->enable_count = 0; |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static const struct udevice_id clk_fixed_rate_match[] = { |
| 45 | { |
| 46 | .compatible = "fixed-clock", |
| 47 | }, |
| 48 | { /* sentinel */ } |
| 49 | }; |
| 50 | |
Simon Glass | 6b927b1 | 2020-10-03 11:31:32 -0600 | [diff] [blame] | 51 | U_BOOT_DRIVER(fixed_clock) = { |
| 52 | .name = "fixed_clock", |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 53 | .id = UCLASS_CLK, |
| 54 | .of_match = clk_fixed_rate_match, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 55 | .of_to_plat = clk_fixed_rate_of_to_plat, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 56 | .plat_auto = sizeof(struct clk_fixed_rate), |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 57 | .ops = &clk_fixed_rate_ops, |
Michal Simek | 34f6781 | 2020-09-16 13:20:55 +0200 | [diff] [blame] | 58 | .flags = DM_FLAG_PRE_RELOC, |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 59 | }; |