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> |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 9 | |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 10 | struct clk_fixed_rate { |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 11 | struct clk clk; |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 12 | unsigned long fixed_rate; |
| 13 | }; |
| 14 | |
| 15 | #define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev)) |
| 16 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 17 | static ulong clk_fixed_rate_get_rate(struct clk *clk) |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 18 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 19 | return to_clk_fixed_rate(clk->dev)->fixed_rate; |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | const struct clk_ops clk_fixed_rate_ops = { |
| 23 | .get_rate = clk_fixed_rate_get_rate, |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev) |
| 27 | { |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 28 | struct clk *clk = &to_clk_fixed_rate(dev)->clk; |
Simon Glass | 589d915 | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 29 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Mario Six | a6a0463 | 2018-01-15 11:06:52 +0100 | [diff] [blame] | 30 | to_clk_fixed_rate(dev)->fixed_rate = |
| 31 | dev_read_u32_default(dev, "clock-frequency", 0); |
Simon Glass | 589d915 | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 32 | #endif |
Lukasz Majewski | 9ded46927 | 2019-06-24 15:50:40 +0200 | [diff] [blame] | 33 | /* Make fixed rate clock accessible from higher level struct clk */ |
| 34 | dev->uclass_priv = clk; |
| 35 | clk->dev = dev; |
Masahiro Yamada | 31adfc2 | 2016-01-19 13:55:28 +0900 | [diff] [blame] | 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static const struct udevice_id clk_fixed_rate_match[] = { |
| 41 | { |
| 42 | .compatible = "fixed-clock", |
| 43 | }, |
| 44 | { /* sentinel */ } |
| 45 | }; |
| 46 | |
| 47 | U_BOOT_DRIVER(clk_fixed_rate) = { |
| 48 | .name = "fixed_rate_clock", |
| 49 | .id = UCLASS_CLK, |
| 50 | .of_match = clk_fixed_rate_match, |
| 51 | .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata, |
| 52 | .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate), |
| 53 | .ops = &clk_fixed_rate_ops, |
| 54 | }; |