rt3883.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Parts of this file are based on Ralink's 2.6.21 BSP
  5. *
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  8. * Copyright (C) 2013 John Crispin <john@phrozen.org>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <linux/sys_soc.h>
  14. #include <asm/mipsregs.h>
  15. #include <asm/mach-ralink/ralink_regs.h>
  16. #include <asm/mach-ralink/rt3883.h>
  17. #include "common.h"
  18. static struct ralink_soc_info *soc_info_ptr;
  19. static unsigned int __init rt3883_get_soc_name0(void)
  20. {
  21. return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3);
  22. }
  23. static unsigned int __init rt3883_get_soc_name1(void)
  24. {
  25. return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID4_7);
  26. }
  27. static bool __init rt3883_soc_valid(void)
  28. {
  29. if (rt3883_get_soc_name0() == RT3883_CHIP_NAME0 &&
  30. rt3883_get_soc_name1() == RT3883_CHIP_NAME1)
  31. return true;
  32. else
  33. return false;
  34. }
  35. static const char __init *rt3883_get_soc_name(void)
  36. {
  37. if (rt3883_soc_valid())
  38. return "RT3883";
  39. else
  40. return "invalid";
  41. }
  42. static unsigned int __init rt3883_get_soc_id(void)
  43. {
  44. return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_REVID);
  45. }
  46. static unsigned int __init rt3883_get_soc_ver(void)
  47. {
  48. return (rt3883_get_soc_id() >> RT3883_REVID_VER_ID_SHIFT) & RT3883_REVID_VER_ID_MASK;
  49. }
  50. static unsigned int __init rt3883_get_soc_rev(void)
  51. {
  52. return (rt3883_get_soc_id() & RT3883_REVID_ECO_ID_MASK);
  53. }
  54. static int __init rt3883_soc_dev_init(void)
  55. {
  56. struct soc_device *soc_dev;
  57. struct soc_device_attribute *soc_dev_attr;
  58. soc_dev_attr = kzalloc_obj(*soc_dev_attr);
  59. if (!soc_dev_attr)
  60. return -ENOMEM;
  61. soc_dev_attr->family = "Ralink";
  62. soc_dev_attr->soc_id = rt3883_get_soc_name();
  63. soc_dev_attr->data = soc_info_ptr;
  64. soc_dev = soc_device_register(soc_dev_attr);
  65. if (IS_ERR(soc_dev)) {
  66. kfree(soc_dev_attr);
  67. return PTR_ERR(soc_dev);
  68. }
  69. return 0;
  70. }
  71. device_initcall(rt3883_soc_dev_init);
  72. void __init prom_soc_init(struct ralink_soc_info *soc_info)
  73. {
  74. if (rt3883_soc_valid())
  75. soc_info->compatible = "ralink,rt3883-soc";
  76. else
  77. panic("rt3883: unknown SoC, n0:%08x n1:%08x",
  78. rt3883_get_soc_name0(), rt3883_get_soc_name1());
  79. snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
  80. "Ralink %s ver:%u eco:%u",
  81. rt3883_get_soc_name(),
  82. rt3883_get_soc_ver(),
  83. rt3883_get_soc_rev());
  84. soc_info->mem_base = RT3883_SDRAM_BASE;
  85. soc_info->mem_size_min = RT3883_MEM_SIZE_MIN;
  86. soc_info->mem_size_max = RT3883_MEM_SIZE_MAX;
  87. ralink_soc = RT3883_SOC;
  88. soc_info_ptr = soc_info;
  89. }