clk-system.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #define SYSTEM_MAX_ID 31
  14. static inline int is_pck(int id)
  15. {
  16. return (id >= 8) && (id <= 15);
  17. }
  18. static int at91_system_clk_enable(struct clk *clk)
  19. {
  20. struct pmc_platdata *plat = dev_get_platdata(clk->dev);
  21. struct at91_pmc *pmc = plat->reg_base;
  22. u32 mask;
  23. if (clk->id > SYSTEM_MAX_ID)
  24. return -EINVAL;
  25. mask = BIT(clk->id);
  26. writel(mask, &pmc->scer);
  27. /**
  28. * For the programmable clocks the Ready status in the PMC
  29. * status register should be checked after enabling.
  30. * For other clocks this is unnecessary.
  31. */
  32. if (!is_pck(clk->id))
  33. return 0;
  34. while (!(readl(&pmc->sr) & mask))
  35. ;
  36. return 0;
  37. }
  38. static struct clk_ops at91_system_clk_ops = {
  39. .enable = at91_system_clk_enable,
  40. };
  41. static int at91_system_clk_bind(struct udevice *dev)
  42. {
  43. return at91_pmc_clk_node_bind(dev);
  44. }
  45. static int at91_system_clk_probe(struct udevice *dev)
  46. {
  47. return at91_pmc_core_probe(dev);
  48. }
  49. static const struct udevice_id at91_system_clk_match[] = {
  50. { .compatible = "atmel,at91rm9200-clk-system" },
  51. {}
  52. };
  53. U_BOOT_DRIVER(at91_system_clk) = {
  54. .name = "at91-system-clk",
  55. .id = UCLASS_CLK,
  56. .of_match = at91_system_clk_match,
  57. .bind = at91_system_clk_bind,
  58. .probe = at91_system_clk_probe,
  59. .platdata_auto_alloc_size = sizeof(struct pmc_platdata),
  60. .ops = &at91_system_clk_ops,
  61. };