dev-common.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X common devices
  3. *
  4. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * Parts of this file are based on Atheros' 2.6.15 BSP
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/platform_data/gpio-ath79.h>
  17. #include <linux/serial_8250.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include <asm/mach-ath79/ar71xx_regs.h>
  22. #include "common.h"
  23. #include "dev-common.h"
  24. static struct resource ath79_uart_resources[] = {
  25. {
  26. .start = AR71XX_UART_BASE,
  27. .end = AR71XX_UART_BASE + AR71XX_UART_SIZE - 1,
  28. .flags = IORESOURCE_MEM,
  29. },
  30. };
  31. #define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
  32. static struct plat_serial8250_port ath79_uart_data[] = {
  33. {
  34. .mapbase = AR71XX_UART_BASE,
  35. .irq = ATH79_MISC_IRQ(3),
  36. .flags = AR71XX_UART_FLAGS,
  37. .iotype = UPIO_MEM32,
  38. .regshift = 2,
  39. }, {
  40. /* terminating entry */
  41. }
  42. };
  43. static struct platform_device ath79_uart_device = {
  44. .name = "serial8250",
  45. .id = PLAT8250_DEV_PLATFORM,
  46. .resource = ath79_uart_resources,
  47. .num_resources = ARRAY_SIZE(ath79_uart_resources),
  48. .dev = {
  49. .platform_data = ath79_uart_data
  50. },
  51. };
  52. static struct resource ar933x_uart_resources[] = {
  53. {
  54. .start = AR933X_UART_BASE,
  55. .end = AR933X_UART_BASE + AR71XX_UART_SIZE - 1,
  56. .flags = IORESOURCE_MEM,
  57. },
  58. {
  59. .start = ATH79_MISC_IRQ(3),
  60. .end = ATH79_MISC_IRQ(3),
  61. .flags = IORESOURCE_IRQ,
  62. },
  63. };
  64. static struct platform_device ar933x_uart_device = {
  65. .name = "ar933x-uart",
  66. .id = -1,
  67. .resource = ar933x_uart_resources,
  68. .num_resources = ARRAY_SIZE(ar933x_uart_resources),
  69. };
  70. void __init ath79_register_uart(void)
  71. {
  72. unsigned long uart_clk_rate;
  73. uart_clk_rate = ath79_get_sys_clk_rate("uart");
  74. if (soc_is_ar71xx() ||
  75. soc_is_ar724x() ||
  76. soc_is_ar913x() ||
  77. soc_is_ar934x() ||
  78. soc_is_qca955x()) {
  79. ath79_uart_data[0].uartclk = uart_clk_rate;
  80. platform_device_register(&ath79_uart_device);
  81. } else if (soc_is_ar933x()) {
  82. platform_device_register(&ar933x_uart_device);
  83. } else {
  84. BUG();
  85. }
  86. }
  87. void __init ath79_register_wdt(void)
  88. {
  89. struct resource res;
  90. memset(&res, 0, sizeof(res));
  91. res.flags = IORESOURCE_MEM;
  92. res.start = AR71XX_RESET_BASE + AR71XX_RESET_REG_WDOG_CTRL;
  93. res.end = res.start + 0x8 - 1;
  94. platform_device_register_simple("ath79-wdt", -1, &res, 1);
  95. }
  96. static struct ath79_gpio_platform_data ath79_gpio_pdata;
  97. static struct resource ath79_gpio_resources[] = {
  98. {
  99. .flags = IORESOURCE_MEM,
  100. .start = AR71XX_GPIO_BASE,
  101. .end = AR71XX_GPIO_BASE + AR71XX_GPIO_SIZE - 1,
  102. },
  103. {
  104. .start = ATH79_MISC_IRQ(2),
  105. .end = ATH79_MISC_IRQ(2),
  106. .flags = IORESOURCE_IRQ,
  107. },
  108. };
  109. static struct platform_device ath79_gpio_device = {
  110. .name = "ath79-gpio",
  111. .id = -1,
  112. .resource = ath79_gpio_resources,
  113. .num_resources = ARRAY_SIZE(ath79_gpio_resources),
  114. .dev = {
  115. .platform_data = &ath79_gpio_pdata
  116. },
  117. };
  118. void __init ath79_gpio_init(void)
  119. {
  120. if (soc_is_ar71xx()) {
  121. ath79_gpio_pdata.ngpios = AR71XX_GPIO_COUNT;
  122. } else if (soc_is_ar7240()) {
  123. ath79_gpio_pdata.ngpios = AR7240_GPIO_COUNT;
  124. } else if (soc_is_ar7241() || soc_is_ar7242()) {
  125. ath79_gpio_pdata.ngpios = AR7241_GPIO_COUNT;
  126. } else if (soc_is_ar913x()) {
  127. ath79_gpio_pdata.ngpios = AR913X_GPIO_COUNT;
  128. } else if (soc_is_ar933x()) {
  129. ath79_gpio_pdata.ngpios = AR933X_GPIO_COUNT;
  130. } else if (soc_is_ar934x()) {
  131. ath79_gpio_pdata.ngpios = AR934X_GPIO_COUNT;
  132. ath79_gpio_pdata.oe_inverted = 1;
  133. } else if (soc_is_qca955x()) {
  134. ath79_gpio_pdata.ngpios = QCA955X_GPIO_COUNT;
  135. ath79_gpio_pdata.oe_inverted = 1;
  136. } else {
  137. BUG();
  138. }
  139. platform_device_register(&ath79_gpio_device);
  140. }