clk-main.c 1.1 KB

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