clk_fixed_rate.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <clk-uclass.h>
  8. #include <dm/device.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. struct clk_fixed_rate {
  11. unsigned long fixed_rate;
  12. };
  13. #define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev))
  14. static ulong clk_fixed_rate_get_rate(struct clk *clk)
  15. {
  16. if (clk->id != 0)
  17. return -EINVAL;
  18. return to_clk_fixed_rate(clk->dev)->fixed_rate;
  19. }
  20. const struct clk_ops clk_fixed_rate_ops = {
  21. .get_rate = clk_fixed_rate_get_rate,
  22. };
  23. static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
  24. {
  25. to_clk_fixed_rate(dev)->fixed_rate =
  26. fdtdec_get_int(gd->fdt_blob, dev->of_offset,
  27. "clock-frequency", 0);
  28. return 0;
  29. }
  30. static const struct udevice_id clk_fixed_rate_match[] = {
  31. {
  32. .compatible = "fixed-clock",
  33. },
  34. { /* sentinel */ }
  35. };
  36. U_BOOT_DRIVER(clk_fixed_rate) = {
  37. .name = "fixed_rate_clock",
  38. .id = UCLASS_CLK,
  39. .of_match = clk_fixed_rate_match,
  40. .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
  41. .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
  42. .ops = &clk_fixed_rate_ops,
  43. };