clk-utmi.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #define UTMI_FIXED_MUL 40
  15. static int utmi_clk_enable(struct clk *clk)
  16. {
  17. struct pmc_platdata *plat = dev_get_platdata(clk->dev);
  18. struct at91_pmc *pmc = plat->reg_base;
  19. u32 tmp;
  20. if (readl(&pmc->sr) & AT91_PMC_LOCKU)
  21. return 0;
  22. tmp = readl(&pmc->uckr);
  23. tmp |= AT91_PMC_UPLLEN |
  24. AT91_PMC_UPLLCOUNT |
  25. AT91_PMC_BIASEN;
  26. writel(tmp, &pmc->uckr);
  27. while (!(readl(&pmc->sr) & AT91_PMC_LOCKU))
  28. ;
  29. return 0;
  30. }
  31. static ulong utmi_clk_get_rate(struct clk *clk)
  32. {
  33. return gd->arch.main_clk_rate_hz * UTMI_FIXED_MUL;
  34. }
  35. static struct clk_ops utmi_clk_ops = {
  36. .enable = utmi_clk_enable,
  37. .get_rate = utmi_clk_get_rate,
  38. };
  39. static int utmi_clk_probe(struct udevice *dev)
  40. {
  41. return at91_pmc_core_probe(dev);
  42. }
  43. static const struct udevice_id utmi_clk_match[] = {
  44. { .compatible = "atmel,at91sam9x5-clk-utmi" },
  45. {}
  46. };
  47. U_BOOT_DRIVER(at91sam9x5_utmi_clk) = {
  48. .name = "at91sam9x5-utmi-clk",
  49. .id = UCLASS_CLK,
  50. .of_match = utmi_clk_match,
  51. .probe = utmi_clk_probe,
  52. .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
  53. .ops = &utmi_clk_ops,
  54. };