clk_fixed_rate.c 1.1 KB

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