002-add_back_gpio_function_select.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. --- /dev/null
  2. +++ b/arch/mips/ath79/gpio.c
  3. @@ -0,0 +1,59 @@
  4. +/*
  5. + * Atheros AR71XX/AR724X/AR913X GPIO API support
  6. + *
  7. + * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  8. + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  9. + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10. + *
  11. + * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
  12. + *
  13. + * This program is free software; you can redistribute it and/or modify it
  14. + * under the terms of the GNU General Public License version 2 as published
  15. + * by the Free Software Foundation.
  16. + */
  17. +#include <linux/kernel.h>
  18. +#include <linux/module.h>
  19. +#include <linux/io.h>
  20. +#include <linux/gpio.h>
  21. +#include <asm/mach-ath79/ar71xx_regs.h>
  22. +#include <asm/mach-ath79/ath79.h>
  23. +#include "common.h"
  24. +
  25. +void __iomem *ath79_gpio_base;
  26. +EXPORT_SYMBOL_GPL(ath79_gpio_base);
  27. +
  28. +static void __iomem *ath79_gpio_get_function_reg(void)
  29. +{
  30. + u32 reg = 0;
  31. +
  32. + if (soc_is_ar71xx() ||
  33. + soc_is_ar724x() ||
  34. + soc_is_ar913x() ||
  35. + soc_is_ar933x())
  36. + reg = AR71XX_GPIO_REG_FUNC;
  37. + else if (soc_is_ar934x())
  38. + reg = AR934X_GPIO_REG_FUNC;
  39. + else
  40. + BUG();
  41. +
  42. + return ath79_gpio_base + reg;
  43. +}
  44. +
  45. +void ath79_gpio_function_setup(u32 set, u32 clear)
  46. +{
  47. + void __iomem *reg = ath79_gpio_get_function_reg();
  48. +
  49. + __raw_writel((__raw_readl(reg) & ~clear) | set, reg);
  50. + /* flush write */
  51. + __raw_readl(reg);
  52. +}
  53. +
  54. +void ath79_gpio_function_enable(u32 mask)
  55. +{
  56. + ath79_gpio_function_setup(mask, 0);
  57. +}
  58. +
  59. +void ath79_gpio_function_disable(u32 mask)
  60. +{
  61. + ath79_gpio_function_setup(0, mask);
  62. +}
  63. --- a/arch/mips/include/asm/mach-ath79/ath79.h
  64. +++ b/arch/mips/include/asm/mach-ath79/ath79.h
  65. @@ -118,6 +118,7 @@ static inline int soc_is_qca955x(void)
  66. void ath79_ddr_wb_flush(unsigned int reg);
  67. void ath79_ddr_set_pci_windows(void);
  68. +extern void __iomem *ath79_gpio_base;
  69. extern void __iomem *ath79_pll_base;
  70. extern void __iomem *ath79_reset_base;
  71. --- a/arch/mips/ath79/dev-common.c
  72. +++ b/arch/mips/ath79/dev-common.c
  73. @@ -156,4 +156,5 @@ void __init ath79_gpio_init(void)
  74. }
  75. platform_device_register(&ath79_gpio_device);
  76. + ath79_gpio_base = ioremap(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE);
  77. }
  78. --- a/arch/mips/ath79/common.h
  79. +++ b/arch/mips/ath79/common.h
  80. @@ -24,6 +24,9 @@ unsigned long ath79_get_sys_clk_rate(con
  81. void ath79_ddr_ctrl_init(void);
  82. +void ath79_gpio_function_enable(u32 mask);
  83. +void ath79_gpio_function_disable(u32 mask);
  84. +void ath79_gpio_function_setup(u32 set, u32 clear);
  85. void ath79_gpio_init(void);
  86. #endif /* __ATH79_COMMON_H */