clk_fixed_rate.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.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. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  26. to_clk_fixed_rate(dev)->fixed_rate = dev_read_u32_default(dev,
  27. "clock-frequency", 0);
  28. #endif
  29. return 0;
  30. }
  31. static const struct udevice_id clk_fixed_rate_match[] = {
  32. {
  33. .compatible = "fixed-clock",
  34. },
  35. { /* sentinel */ }
  36. };
  37. U_BOOT_DRIVER(clk_fixed_rate) = {
  38. .name = "fixed_rate_clock",
  39. .id = UCLASS_CLK,
  40. .of_match = clk_fixed_rate_match,
  41. .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
  42. .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
  43. .ops = &clk_fixed_rate_ops,
  44. };