dev-common.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <asm/mach-ath79/ar933x_uart_platform.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_UART,
  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_UART,
  60. .end = ATH79_MISC_IRQ_UART,
  61. .flags = IORESOURCE_IRQ,
  62. },
  63. };
  64. static struct ar933x_uart_platform_data ar933x_uart_data;
  65. static struct platform_device ar933x_uart_device = {
  66. .name = "ar933x-uart",
  67. .id = -1,
  68. .resource = ar933x_uart_resources,
  69. .num_resources = ARRAY_SIZE(ar933x_uart_resources),
  70. .dev = {
  71. .platform_data = &ar933x_uart_data,
  72. },
  73. };
  74. void __init ath79_register_uart(void)
  75. {
  76. struct clk *clk;
  77. clk = clk_get(NULL, "uart");
  78. if (IS_ERR(clk))
  79. panic("unable to get UART clock, err=%ld", PTR_ERR(clk));
  80. if (soc_is_ar71xx() ||
  81. soc_is_ar724x() ||
  82. soc_is_ar913x()) {
  83. ath79_uart_data[0].uartclk = clk_get_rate(clk);
  84. platform_device_register(&ath79_uart_device);
  85. } else if (soc_is_ar933x()) {
  86. ar933x_uart_data.uartclk = clk_get_rate(clk);
  87. platform_device_register(&ar933x_uart_device);
  88. } else {
  89. BUG();
  90. }
  91. }
  92. static struct platform_device ath79_wdt_device = {
  93. .name = "ath79-wdt",
  94. .id = -1,
  95. };
  96. void __init ath79_register_wdt(void)
  97. {
  98. platform_device_register(&ath79_wdt_device);
  99. }