dev-common.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/serial_8250.h>
  17. #include <linux/clk.h>
  18. #include <linux/err.h>
  19. #include <asm/mach-ath79/ath79.h>
  20. #include <asm/mach-ath79/ar71xx_regs.h>
  21. #include "common.h"
  22. #include "dev-common.h"
  23. static struct resource ath79_uart_resources[] = {
  24. {
  25. .start = AR71XX_UART_BASE,
  26. .end = AR71XX_UART_BASE + AR71XX_UART_SIZE - 1,
  27. .flags = IORESOURCE_MEM,
  28. },
  29. };
  30. #define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
  31. static struct plat_serial8250_port ath79_uart_data[] = {
  32. {
  33. .mapbase = AR71XX_UART_BASE,
  34. .irq = ATH79_MISC_IRQ(3),
  35. .flags = AR71XX_UART_FLAGS,
  36. .iotype = UPIO_MEM32,
  37. .regshift = 2,
  38. }, {
  39. /* terminating entry */
  40. }
  41. };
  42. static struct platform_device ath79_uart_device = {
  43. .name = "serial8250",
  44. .id = PLAT8250_DEV_PLATFORM,
  45. .resource = ath79_uart_resources,
  46. .num_resources = ARRAY_SIZE(ath79_uart_resources),
  47. .dev = {
  48. .platform_data = ath79_uart_data
  49. },
  50. };
  51. static struct resource ar933x_uart_resources[] = {
  52. {
  53. .start = AR933X_UART_BASE,
  54. .end = AR933X_UART_BASE + AR71XX_UART_SIZE - 1,
  55. .flags = IORESOURCE_MEM,
  56. },
  57. {
  58. .start = ATH79_MISC_IRQ(3),
  59. .end = ATH79_MISC_IRQ(3),
  60. .flags = IORESOURCE_IRQ,
  61. },
  62. };
  63. static struct platform_device ar933x_uart_device = {
  64. .name = "ar933x-uart",
  65. .id = -1,
  66. .resource = ar933x_uart_resources,
  67. .num_resources = ARRAY_SIZE(ar933x_uart_resources),
  68. };
  69. void __init ath79_register_uart(void)
  70. {
  71. unsigned long uart_clk_rate;
  72. uart_clk_rate = ath79_get_sys_clk_rate("uart");
  73. if (soc_is_ar71xx() ||
  74. soc_is_ar724x() ||
  75. soc_is_ar913x() ||
  76. soc_is_ar934x() ||
  77. soc_is_qca955x()) {
  78. ath79_uart_data[0].uartclk = uart_clk_rate;
  79. platform_device_register(&ath79_uart_device);
  80. } else if (soc_is_ar933x()) {
  81. platform_device_register(&ar933x_uart_device);
  82. } else {
  83. BUG();
  84. }
  85. }
  86. void __init ath79_register_wdt(void)
  87. {
  88. struct resource res;
  89. memset(&res, 0, sizeof(res));
  90. res.flags = IORESOURCE_MEM;
  91. res.start = AR71XX_RESET_BASE + AR71XX_RESET_REG_WDOG_CTRL;
  92. res.end = res.start + 0x8 - 1;
  93. platform_device_register_simple("ath79-wdt", -1, &res, 1);
  94. }