mtk_cpu.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  4. *
  5. * Author: Weijie Gao <weijie.gao@mediatek.com>
  6. */
  7. #include <linux/types.h>
  8. #include <cpu.h>
  9. #include <dm.h>
  10. #include <regmap.h>
  11. #include <syscon.h>
  12. #include <asm/global_data.h>
  13. #include <linux/err.h>
  14. #include <linux/io.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. struct mtk_cpu_plat {
  17. struct regmap *hwver;
  18. };
  19. static int mtk_cpu_get_desc(const struct udevice *dev, char *buf, int size)
  20. {
  21. struct mtk_cpu_plat *plat = dev_get_plat(dev);
  22. uint val;
  23. regmap_read(plat->hwver, 0, &val);
  24. snprintf(buf, size, "MediaTek MT%04X", val);
  25. return 0;
  26. }
  27. static int mtk_cpu_get_count(const struct udevice *dev)
  28. {
  29. return 1;
  30. }
  31. static int mtk_cpu_get_vendor(const struct udevice *dev, char *buf, int size)
  32. {
  33. snprintf(buf, size, "MediaTek");
  34. return 0;
  35. }
  36. static int mtk_cpu_probe(struct udevice *dev)
  37. {
  38. struct mtk_cpu_plat *plat = dev_get_plat(dev);
  39. struct ofnode_phandle_args args;
  40. int ret;
  41. ret = dev_read_phandle_with_args(dev, "mediatek,hwver", NULL, 0, 0,
  42. &args);
  43. if (ret)
  44. return ret;
  45. plat->hwver = syscon_node_to_regmap(args.node);
  46. if (IS_ERR(plat->hwver))
  47. return PTR_ERR(plat->hwver);
  48. return 0;
  49. }
  50. static const struct cpu_ops mtk_cpu_ops = {
  51. .get_desc = mtk_cpu_get_desc,
  52. .get_count = mtk_cpu_get_count,
  53. .get_vendor = mtk_cpu_get_vendor,
  54. };
  55. static const struct udevice_id mtk_cpu_ids[] = {
  56. { .compatible = "arm,cortex-a7" },
  57. { .compatible = "arm,cortex-a53" },
  58. { .compatible = "arm,cortex-a73" },
  59. { /* sentinel */ }
  60. };
  61. U_BOOT_DRIVER(cpu_mtk) = {
  62. .name = "mtk-cpu",
  63. .id = UCLASS_CPU,
  64. .of_match = mtk_cpu_ids,
  65. .ops = &mtk_cpu_ops,
  66. .probe = mtk_cpu_probe,
  67. .plat_auto = sizeof(struct mtk_cpu_plat),
  68. .flags = DM_FLAG_PRE_RELOC,
  69. };