clk-main.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2016 Atmel Corporation
  3. * Wenyou.Yang <wenyou.yang@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <clk-uclass.h>
  9. #include <dm/device.h>
  10. #include <linux/io.h>
  11. #include <mach/at91_pmc.h>
  12. #include "pmc.h"
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static int main_osc_clk_enable(struct clk *clk)
  15. {
  16. struct pmc_platdata *plat = dev_get_platdata(clk->dev);
  17. struct at91_pmc *pmc = plat->reg_base;
  18. if (readl(&pmc->sr) & AT91_PMC_MOSCSELS)
  19. return 0;
  20. return -EINVAL;
  21. }
  22. static ulong main_osc_clk_get_rate(struct clk *clk)
  23. {
  24. return gd->arch.main_clk_rate_hz;
  25. }
  26. static struct clk_ops main_osc_clk_ops = {
  27. .enable = main_osc_clk_enable,
  28. .get_rate = main_osc_clk_get_rate,
  29. };
  30. static int main_osc_clk_probe(struct udevice *dev)
  31. {
  32. return at91_pmc_core_probe(dev);
  33. }
  34. static const struct udevice_id main_osc_clk_match[] = {
  35. { .compatible = "atmel,at91sam9x5-clk-main" },
  36. {}
  37. };
  38. U_BOOT_DRIVER(at91sam9x5_main_osc_clk) = {
  39. .name = "at91sam9x5-main-osc-clk",
  40. .id = UCLASS_CLK,
  41. .of_match = main_osc_clk_match,
  42. .probe = main_osc_clk_probe,
  43. .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
  44. .ops = &main_osc_clk_ops,
  45. };