at91_cpu.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
  4. *
  5. * Author: Claudiu Beznea <claudiu.beznea@microchip.com>
  6. */
  7. #include <common.h>
  8. #include <cpu.h>
  9. #include <dm.h>
  10. #include <div64.h>
  11. #include <linux/clk-provider.h>
  12. struct at91_cpu_platdata {
  13. const char *name;
  14. ulong cpufreq_mhz;
  15. ulong mckfreq_mhz;
  16. ulong xtalfreq_mhz;
  17. };
  18. extern char *get_cpu_name(void);
  19. const char *at91_cpu_get_name(void)
  20. {
  21. return get_cpu_name();
  22. }
  23. int at91_cpu_get_desc(const struct udevice *dev, char *buf, int size)
  24. {
  25. struct at91_cpu_platdata *plat = dev_get_platdata(dev);
  26. snprintf(buf, size, "%s\n"
  27. "Crystal frequency: %8lu MHz\n"
  28. "CPU clock : %8lu MHz\n"
  29. "Master clock : %8lu MHz\n",
  30. plat->name, plat->xtalfreq_mhz, plat->cpufreq_mhz,
  31. plat->mckfreq_mhz);
  32. return 0;
  33. }
  34. static int at91_cpu_get_info(const struct udevice *dev, struct cpu_info *info)
  35. {
  36. struct at91_cpu_platdata *plat = dev_get_platdata(dev);
  37. info->cpu_freq = plat->cpufreq_mhz * 1000000;
  38. info->features = BIT(CPU_FEAT_L1_CACHE);
  39. return 0;
  40. }
  41. static int at91_cpu_get_count(const struct udevice *dev)
  42. {
  43. return 1;
  44. }
  45. static int at91_cpu_get_vendor(const struct udevice *dev, char *buf, int size)
  46. {
  47. snprintf(buf, size, "Microchip Technology Inc.");
  48. return 0;
  49. }
  50. static const struct cpu_ops at91_cpu_ops = {
  51. .get_desc = at91_cpu_get_desc,
  52. .get_info = at91_cpu_get_info,
  53. .get_count = at91_cpu_get_count,
  54. .get_vendor = at91_cpu_get_vendor,
  55. };
  56. static const struct udevice_id at91_cpu_ids[] = {
  57. { .compatible = "arm,cortex-a7" },
  58. { /* Sentinel. */ }
  59. };
  60. static int at91_cpu_probe(struct udevice *dev)
  61. {
  62. struct at91_cpu_platdata *plat = dev_get_platdata(dev);
  63. struct clk clk;
  64. ulong rate;
  65. int ret;
  66. ret = clk_get_by_index(dev, 0, &clk);
  67. if (ret)
  68. return ret;
  69. rate = clk_get_rate(&clk);
  70. if (!rate)
  71. return -ENOTSUPP;
  72. plat->cpufreq_mhz = DIV_ROUND_CLOSEST_ULL(rate, 1000000);
  73. ret = clk_get_by_index(dev, 1, &clk);
  74. if (ret)
  75. return ret;
  76. rate = clk_get_rate(&clk);
  77. if (!rate)
  78. return -ENOTSUPP;
  79. plat->mckfreq_mhz = DIV_ROUND_CLOSEST_ULL(rate, 1000000);
  80. ret = clk_get_by_index(dev, 2, &clk);
  81. if (ret)
  82. return ret;
  83. rate = clk_get_rate(&clk);
  84. if (!rate)
  85. return -ENOTSUPP;
  86. plat->xtalfreq_mhz = DIV_ROUND_CLOSEST_ULL(rate, 1000000);
  87. plat->name = get_cpu_name();
  88. return 0;
  89. }
  90. U_BOOT_DRIVER(cpu_at91_drv) = {
  91. .name = "at91-cpu",
  92. .id = UCLASS_CPU,
  93. .of_match = at91_cpu_ids,
  94. .ops = &at91_cpu_ops,
  95. .probe = at91_cpu_probe,
  96. .platdata_auto_alloc_size = sizeof(struct at91_cpu_platdata),
  97. .flags = DM_FLAG_PRE_RELOC,
  98. };