clk_fixed_rate.c 1.2 KB

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