devices.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * CLPS711X common devices definitions
  3. *
  4. * Author: Alexander Shiyan <shc_work@mail.ru>, 2013-2014
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/io.h>
  12. #include <linux/of_fdt.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/random.h>
  15. #include <linux/sizes.h>
  16. #include <linux/slab.h>
  17. #include <linux/sys_soc.h>
  18. #include <asm/system_info.h>
  19. #include <mach/hardware.h>
  20. static const struct resource clps711x_cpuidle_res __initconst =
  21. DEFINE_RES_MEM(CLPS711X_PHYS_BASE + HALT, SZ_128);
  22. static void __init clps711x_add_cpuidle(void)
  23. {
  24. platform_device_register_simple("clps711x-cpuidle", PLATFORM_DEVID_NONE,
  25. &clps711x_cpuidle_res, 1);
  26. }
  27. static const phys_addr_t clps711x_gpios[][2] __initconst = {
  28. { PADR, PADDR },
  29. { PBDR, PBDDR },
  30. { PCDR, PCDDR },
  31. { PDDR, PDDDR },
  32. { PEDR, PEDDR },
  33. };
  34. static void __init clps711x_add_gpio(void)
  35. {
  36. unsigned i;
  37. struct resource gpio_res[2];
  38. memset(gpio_res, 0, sizeof(gpio_res));
  39. gpio_res[0].flags = IORESOURCE_MEM;
  40. gpio_res[1].flags = IORESOURCE_MEM;
  41. for (i = 0; i < ARRAY_SIZE(clps711x_gpios); i++) {
  42. gpio_res[0].start = CLPS711X_PHYS_BASE + clps711x_gpios[i][0];
  43. gpio_res[0].end = gpio_res[0].start;
  44. gpio_res[1].start = CLPS711X_PHYS_BASE + clps711x_gpios[i][1];
  45. gpio_res[1].end = gpio_res[1].start;
  46. platform_device_register_simple("clps711x-gpio", i,
  47. gpio_res, ARRAY_SIZE(gpio_res));
  48. }
  49. }
  50. const struct resource clps711x_syscon_res[] __initconst = {
  51. /* SYSCON1, SYSFLG1 */
  52. DEFINE_RES_MEM(CLPS711X_PHYS_BASE + SYSCON1, SZ_128),
  53. /* SYSCON2, SYSFLG2 */
  54. DEFINE_RES_MEM(CLPS711X_PHYS_BASE + SYSCON2, SZ_128),
  55. /* SYSCON3 */
  56. DEFINE_RES_MEM(CLPS711X_PHYS_BASE + SYSCON3, SZ_64),
  57. };
  58. static void __init clps711x_add_syscon(void)
  59. {
  60. unsigned i;
  61. for (i = 0; i < ARRAY_SIZE(clps711x_syscon_res); i++)
  62. platform_device_register_simple("syscon", i + 1,
  63. &clps711x_syscon_res[i], 1);
  64. }
  65. static const struct resource clps711x_uart1_res[] __initconst = {
  66. DEFINE_RES_MEM(CLPS711X_PHYS_BASE + UARTDR1, SZ_128),
  67. DEFINE_RES_IRQ(IRQ_UTXINT1),
  68. DEFINE_RES_IRQ(IRQ_URXINT1),
  69. };
  70. static const struct resource clps711x_uart2_res[] __initconst = {
  71. DEFINE_RES_MEM(CLPS711X_PHYS_BASE + UARTDR2, SZ_128),
  72. DEFINE_RES_IRQ(IRQ_UTXINT2),
  73. DEFINE_RES_IRQ(IRQ_URXINT2),
  74. };
  75. static void __init clps711x_add_uart(void)
  76. {
  77. platform_device_register_simple("clps711x-uart", 0, clps711x_uart1_res,
  78. ARRAY_SIZE(clps711x_uart1_res));
  79. platform_device_register_simple("clps711x-uart", 1, clps711x_uart2_res,
  80. ARRAY_SIZE(clps711x_uart2_res));
  81. };
  82. static void __init clps711x_soc_init(void)
  83. {
  84. struct soc_device_attribute *soc_dev_attr;
  85. struct soc_device *soc_dev;
  86. void __iomem *base;
  87. u32 id[5];
  88. base = ioremap(CLPS711X_PHYS_BASE, SZ_32K);
  89. if (!base)
  90. return;
  91. id[0] = readl(base + UNIQID);
  92. id[1] = readl(base + RANDID0);
  93. id[2] = readl(base + RANDID1);
  94. id[3] = readl(base + RANDID2);
  95. id[4] = readl(base + RANDID3);
  96. system_rev = SYSFLG1_VERID(readl(base + SYSFLG1));
  97. add_device_randomness(id, sizeof(id));
  98. system_serial_low = id[0];
  99. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  100. if (!soc_dev_attr)
  101. goto out_unmap;
  102. soc_dev_attr->machine = of_flat_dt_get_machine_name();
  103. soc_dev_attr->family = "Cirrus Logic CLPS711X";
  104. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u", system_rev);
  105. soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%08x", id[0]);
  106. soc_dev = soc_device_register(soc_dev_attr);
  107. if (IS_ERR(soc_dev)) {
  108. kfree(soc_dev_attr->revision);
  109. kfree(soc_dev_attr->soc_id);
  110. kfree(soc_dev_attr);
  111. }
  112. out_unmap:
  113. iounmap(base);
  114. }
  115. void __init clps711x_devices_init(void)
  116. {
  117. clps711x_add_cpuidle();
  118. clps711x_add_gpio();
  119. clps711x_add_syscon();
  120. clps711x_add_uart();
  121. clps711x_soc_init();
  122. }