1b21e20b2SMasahiro Yamada /* 2b21e20b2SMasahiro Yamada * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com> 3b21e20b2SMasahiro Yamada * 4b21e20b2SMasahiro Yamada * SPDX-License-Identifier: GPL-2.0+ 5b21e20b2SMasahiro Yamada */ 6b21e20b2SMasahiro Yamada 7b21e20b2SMasahiro Yamada #include <common.h> 8135aa950SStephen Warren #include <clk-uclass.h> 9b21e20b2SMasahiro Yamada #include <dm/device.h> 10b21e20b2SMasahiro Yamada 11b21e20b2SMasahiro Yamada DECLARE_GLOBAL_DATA_PTR; 12b21e20b2SMasahiro Yamada 13b21e20b2SMasahiro Yamada struct clk_fixed_rate { 14b21e20b2SMasahiro Yamada unsigned long fixed_rate; 15b21e20b2SMasahiro Yamada }; 16b21e20b2SMasahiro Yamada 17b21e20b2SMasahiro Yamada #define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev)) 18b21e20b2SMasahiro Yamada 19135aa950SStephen Warren static ulong clk_fixed_rate_get_rate(struct clk *clk) 20b21e20b2SMasahiro Yamada { 21135aa950SStephen Warren if (clk->id != 0) 22135aa950SStephen Warren return -EINVAL; 23b21e20b2SMasahiro Yamada 24135aa950SStephen Warren return to_clk_fixed_rate(clk->dev)->fixed_rate; 25b21e20b2SMasahiro Yamada } 26b21e20b2SMasahiro Yamada 27b21e20b2SMasahiro Yamada const struct clk_ops clk_fixed_rate_ops = { 28b21e20b2SMasahiro Yamada .get_rate = clk_fixed_rate_get_rate, 29b21e20b2SMasahiro Yamada }; 30b21e20b2SMasahiro Yamada 31b21e20b2SMasahiro Yamada static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev) 32b21e20b2SMasahiro Yamada { 33*7423daa6SSimon Glass #if !CONFIG_IS_ENABLED(OF_PLATDATA) 34b21e20b2SMasahiro Yamada to_clk_fixed_rate(dev)->fixed_rate = 35b21e20b2SMasahiro Yamada fdtdec_get_int(gd->fdt_blob, dev->of_offset, 36b21e20b2SMasahiro Yamada "clock-frequency", 0); 37*7423daa6SSimon Glass #endif 38b21e20b2SMasahiro Yamada 39b21e20b2SMasahiro Yamada return 0; 40b21e20b2SMasahiro Yamada } 41b21e20b2SMasahiro Yamada 42b21e20b2SMasahiro Yamada static const struct udevice_id clk_fixed_rate_match[] = { 43b21e20b2SMasahiro Yamada { 44b21e20b2SMasahiro Yamada .compatible = "fixed-clock", 45b21e20b2SMasahiro Yamada }, 46b21e20b2SMasahiro Yamada { /* sentinel */ } 47b21e20b2SMasahiro Yamada }; 48b21e20b2SMasahiro Yamada 49b21e20b2SMasahiro Yamada U_BOOT_DRIVER(clk_fixed_rate) = { 50b21e20b2SMasahiro Yamada .name = "fixed_rate_clock", 51b21e20b2SMasahiro Yamada .id = UCLASS_CLK, 52b21e20b2SMasahiro Yamada .of_match = clk_fixed_rate_match, 53b21e20b2SMasahiro Yamada .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata, 54b21e20b2SMasahiro Yamada .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate), 55b21e20b2SMasahiro Yamada .ops = &clk_fixed_rate_ops, 56b21e20b2SMasahiro Yamada }; 57