0045-MIPS-ralink-add-pinmux-driver.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. From c7107291df4035794c67d7a904fe7419fedc5922 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Mon, 22 Apr 2013 23:11:42 +0200
  4. Subject: [PATCH 45/79] MIPS: ralink: add pinmux driver
  5. Add code to setup the pinmux on ralonk SoC. The SoC has a single 32 bit register
  6. for this functionality with simple on/off bits. Building a full featured pinctrl
  7. driver would be overkill.
  8. Signed-off-by: John Crispin <[email protected]>
  9. ---
  10. arch/mips/ralink/Makefile | 2 +-
  11. arch/mips/ralink/common.h | 2 ++
  12. arch/mips/ralink/of.c | 2 ++
  13. arch/mips/ralink/pinmux.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
  14. 4 files changed, 82 insertions(+), 1 deletion(-)
  15. create mode 100644 arch/mips/ralink/pinmux.c
  16. diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
  17. index 38cf1a8..341b4de 100644
  18. --- a/arch/mips/ralink/Makefile
  19. +++ b/arch/mips/ralink/Makefile
  20. @@ -6,7 +6,7 @@
  21. # Copyright (C) 2009-2011 Gabor Juhos <[email protected]>
  22. # Copyright (C) 2013 John Crispin <[email protected]>
  23. -obj-y := prom.o of.o reset.o clk.o irq.o
  24. +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o
  25. obj-$(CONFIG_SOC_RT288X) += rt288x.o
  26. obj-$(CONFIG_SOC_RT305X) += rt305x.o
  27. diff --git a/arch/mips/ralink/common.h b/arch/mips/ralink/common.h
  28. index 83144c3..f113fd6 100644
  29. --- a/arch/mips/ralink/common.h
  30. +++ b/arch/mips/ralink/common.h
  31. @@ -50,4 +50,6 @@ extern void prom_soc_init(struct ralink_soc_info *soc_info);
  32. __iomem void *plat_of_remap_node(const char *node);
  33. +void ralink_pinmux(void);
  34. +
  35. #endif /* _RALINK_COMMON_H__ */
  36. diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
  37. index fb15695..f916774 100644
  38. --- a/arch/mips/ralink/of.c
  39. +++ b/arch/mips/ralink/of.c
  40. @@ -110,6 +110,8 @@ static int __init plat_of_setup(void)
  41. if (of_platform_populate(NULL, of_ids, NULL, NULL))
  42. panic("failed to populate DT\n");
  43. + ralink_pinmux();
  44. +
  45. return 0;
  46. }
  47. diff --git a/arch/mips/ralink/pinmux.c b/arch/mips/ralink/pinmux.c
  48. new file mode 100644
  49. index 0000000..1720216
  50. --- /dev/null
  51. +++ b/arch/mips/ralink/pinmux.c
  52. @@ -0,0 +1,77 @@
  53. +/*
  54. + * This program is free software; you can redistribute it and/or modify it
  55. + * under the terms of the GNU General Public License version 2 as published
  56. + * by the Free Software Foundation.
  57. + *
  58. + * Copyright (C) 2013 John Crispin <[email protected]>
  59. + */
  60. +
  61. +#include <linux/kernel.h>
  62. +#include <linux/of.h>
  63. +
  64. +#include <asm/mach-ralink/ralink_regs.h>
  65. +
  66. +#include "common.h"
  67. +
  68. +#define SYSC_REG_GPIO_MODE 0x60
  69. +
  70. +static int ralink_mux_mask(const char *name, struct ralink_pinmux_grp *grps, u32* mask)
  71. +{
  72. + for (; grps && grps->name; grps++)
  73. + if (!strcmp(grps->name, name)) {
  74. + *mask = grps->mask;
  75. + return 0;
  76. + }
  77. +
  78. + return -1;
  79. +}
  80. +
  81. +void ralink_pinmux(void)
  82. +{
  83. + const __be32 *wdt;
  84. + struct device_node *np;
  85. + struct property *prop;
  86. + const char *uart, *pin;
  87. + u32 mode = 0;
  88. + int m;
  89. +
  90. + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-sysc");
  91. + if (!np)
  92. + return;
  93. +
  94. + of_property_for_each_string(np, "ralink,gpiomux", prop, pin) {
  95. + if (!ralink_mux_mask(pin, rt_gpio_pinmux.mode, &m)) {
  96. + mode |= m;
  97. + pr_debug("pinmux: registered gpiomux \"%s\"\n", pin);
  98. + } else {
  99. + pr_err("pinmux: failed to load \"%s\"\n", pin);
  100. + }
  101. + }
  102. +
  103. + of_property_for_each_string(np, "ralink,pinmux", prop, pin) {
  104. + if (!ralink_mux_mask(pin, rt_gpio_pinmux.mode, &m)) {
  105. + mode &= ~m;
  106. + pr_debug("pinmux: registered pinmux \"%s\"\n", pin);
  107. + } else {
  108. + pr_err("pinmux: failed to load group \"%s\"\n", pin);
  109. + }
  110. + }
  111. +
  112. + of_property_read_string(np, "ralink,uartmux", &uart);
  113. + if (uart) {
  114. + mode &= ~(rt_gpio_pinmux.uart_mask << rt_gpio_pinmux.uart_shift);
  115. + if (ralink_mux_mask(uart, rt_gpio_pinmux.uart, &m)) {
  116. + pr_err("pinmux: failed to load uartmux \"%s\"\n", uart);
  117. + mode |= rt_gpio_pinmux.uart_mask << rt_gpio_pinmux.uart_shift;
  118. + } else {
  119. + mode |= m << rt_gpio_pinmux.uart_shift;
  120. + pr_debug("pinmux: registered uartmux \"%s\"\n", uart);
  121. + }
  122. + }
  123. +
  124. + wdt = of_get_property(np, "ralink,wdtmux", NULL);
  125. + if (wdt && *wdt && rt_gpio_pinmux.wdt_reset)
  126. + rt_gpio_pinmux.wdt_reset();
  127. +
  128. + rt_sysc_w32(mode, SYSC_REG_GPIO_MODE);
  129. +}
  130. --
  131. 1.7.10.4