Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Alchemy: Clean up GPIO registers and accessors

remove au_readl/au_writel, remove the predefined GPIO1/2 KSEG1 register
addresses and fix the fallout in all boards and drivers.

This also fixes a bug in the mtx-1_wdt driver which was introduced by
commit 6ea8115bb6f359df4f45152f2b40e1d4d1891392
("Convert mtx1 wdt to be a platform device and use generic GPIO API")
before this patch mtx-1_wdt only modified GPIO215, the patch then
used the gpio resource information as bit index into the GPIO2 register
but the conversion to the GPIO API didn't realize that.
With this patch the drivers original behaviour is restored and GPIO15
is left alone.

Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>
Cc: Florian Fainelli <florian@openwrt.org>
To: Linux-MIPS <linux-mips@linux-mips.org>
Cc: linux-watchdog@vger.kernel.org
Cc: Wim Van Sebroeck <wim@iguana.be>
Patchwork: https://patchwork.linux-mips.org/patch/2381/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org

authored by

Manuel Lauss and committed by
Ralf Baechle
b7f720d6 5d4ddcb4

+70 -62
+1 -1
arch/mips/alchemy/devboards/pb1000/board_setup.c
··· 65 65 66 66 /* Set AUX clock to 12 MHz * 8 = 96 MHz */ 67 67 au_writel(8, SYS_AUXPLL); 68 - au_writel(0, SYS_PINSTATERD); 68 + alchemy_gpio1_input_enable(); 69 69 udelay(100); 70 70 71 71 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
+1 -1
arch/mips/alchemy/devboards/pb1500/board_setup.c
··· 56 56 sys_clksrc = sys_freqctrl = pin_func = 0; 57 57 /* Set AUX clock to 12 MHz * 8 = 96 MHz */ 58 58 au_writel(8, SYS_AUXPLL); 59 - au_writel(0, SYS_PINSTATERD); 59 + alchemy_gpio1_input_enable(); 60 60 udelay(100); 61 61 62 62 /* GPIO201 is input for PCMCIA card detect */
+1 -1
arch/mips/alchemy/mtx-1/board_setup.c
··· 87 87 au_writel(SYS_PF_NI2, SYS_PINFUNC); 88 88 89 89 /* Initialize GPIO */ 90 - au_writel(0xFFFFFFFF, SYS_TRIOUTCLR); 90 + au_writel(~0, KSEG1ADDR(AU1000_SYS_PHYS_ADDR) + SYS_TRIOUTCLR); 91 91 alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */ 92 92 alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */ 93 93 alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
+2 -2
arch/mips/alchemy/mtx-1/platform.c
··· 53 53 54 54 static struct resource mtx1_wdt_res[] = { 55 55 [0] = { 56 - .start = 15, 57 - .end = 15, 56 + .start = 215, 57 + .end = 215, 58 58 .name = "mtx1-wdt-gpio", 59 59 .flags = IORESOURCE_IRQ, 60 60 }
+2 -25
arch/mips/include/asm/mach-au1x00/au1000.h
··· 702 702 #define AU1000_UART1_PHYS_ADDR 0x11200000 /* 0234 */ 703 703 #define AU1000_UART2_PHYS_ADDR 0x11300000 /* 0 */ 704 704 #define AU1000_UART3_PHYS_ADDR 0x11400000 /* 0123 */ 705 + #define AU1500_GPIO2_PHYS_ADDR 0x11700000 /* 1234 */ 705 706 #define AU1000_IC1_PHYS_ADDR 0x11800000 /* 01234 */ 707 + #define AU1000_SYS_PHYS_ADDR 0x11900000 /* 01234 */ 706 708 #define AU1000_DMA_PHYS_ADDR 0x14002000 /* 012 */ 707 709 #define AU1550_DBDMA_PHYS_ADDR 0x14002000 /* 34 */ 708 710 #define AU1550_DBDMA_CONF_PHYS_ADDR 0x14003000 /* 34 */ ··· 719 717 #define IRDA_PHYS_ADDR 0x10300000 720 718 #define SSI0_PHYS_ADDR 0x11600000 721 719 #define SSI1_PHYS_ADDR 0x11680000 722 - #define SYS_PHYS_ADDR 0x11900000 723 720 #define PCMCIA_IO_PHYS_ADDR 0xF00000000ULL 724 721 #define PCMCIA_ATTR_PHYS_ADDR 0xF40000000ULL 725 722 #define PCMCIA_MEM_PHYS_ADDR 0xF80000000ULL ··· 731 730 #define STATIC_MEM_PHYS_ADDR 0x14001000 732 731 #define USBH_PHYS_ADDR 0x10100000 733 732 #define PCI_PHYS_ADDR 0x14005000 734 - #define GPIO2_PHYS_ADDR 0x11700000 735 - #define SYS_PHYS_ADDR 0x11900000 736 733 #define PCI_MEM_PHYS_ADDR 0x400000000ULL 737 734 #define PCI_IO_PHYS_ADDR 0x500000000ULL 738 735 #define PCI_CONFIG0_PHYS_ADDR 0x600000000ULL ··· 749 750 #define IRDA_PHYS_ADDR 0x10300000 750 751 #define SSI0_PHYS_ADDR 0x11600000 751 752 #define SSI1_PHYS_ADDR 0x11680000 752 - #define GPIO2_PHYS_ADDR 0x11700000 753 - #define SYS_PHYS_ADDR 0x11900000 754 753 #define LCD_PHYS_ADDR 0x15000000 755 754 #define PCMCIA_IO_PHYS_ADDR 0xF00000000ULL 756 755 #define PCMCIA_ATTR_PHYS_ADDR 0xF40000000ULL ··· 762 765 #define STATIC_MEM_PHYS_ADDR 0x14001000 763 766 #define USBH_PHYS_ADDR 0x14020000 764 767 #define PCI_PHYS_ADDR 0x14005000 765 - #define GPIO2_PHYS_ADDR 0x11700000 766 - #define SYS_PHYS_ADDR 0x11900000 767 768 #define PE_PHYS_ADDR 0x14008000 768 769 #define PSC0_PHYS_ADDR 0x11A00000 769 770 #define PSC1_PHYS_ADDR 0x11B00000 ··· 785 790 #define CIM_PHYS_ADDR 0x14004000 786 791 #define USBM_PHYS_ADDR 0x14020000 787 792 #define USBH_PHYS_ADDR 0x14020100 788 - #define GPIO2_PHYS_ADDR 0x11700000 789 - #define SYS_PHYS_ADDR 0x11900000 790 793 #define PSC0_PHYS_ADDR 0x11A00000 791 794 #define PSC1_PHYS_ADDR 0x11B00000 792 795 #define LCD_PHYS_ADDR 0x15000000 ··· 1351 1358 #define SYS_PINFUNC_U0T (1 << 3) 1352 1359 #define SYS_PINFUNC_S1B (1 << 2) 1353 1360 #endif 1354 - 1355 - #define SYS_TRIOUTRD 0xB1900100 1356 - #define SYS_TRIOUTCLR 0xB1900100 1357 - #define SYS_OUTPUTRD 0xB1900108 1358 - #define SYS_OUTPUTSET 0xB1900108 1359 - #define SYS_OUTPUTCLR 0xB190010C 1360 - #define SYS_PINSTATERD 0xB1900110 1361 - #define SYS_PININPUTEN 0xB1900110 1362 - 1363 - /* GPIO2, Au1500, Au1550 only */ 1364 - #define GPIO2_BASE 0xB1700000 1365 - #define GPIO2_DIR (GPIO2_BASE + 0) 1366 - #define GPIO2_OUTPUT (GPIO2_BASE + 8) 1367 - #define GPIO2_PINSTATE (GPIO2_BASE + 0xC) 1368 - #define GPIO2_INTENABLE (GPIO2_BASE + 0x10) 1369 - #define GPIO2_ENABLE (GPIO2_BASE + 0x14) 1370 1361 1371 1362 /* Power Management */ 1372 1363 #define SYS_SCRATCH0 0xB1900018
+49 -22
arch/mips/include/asm/mach-au1x00/gpio-au1000.h
··· 24 24 25 25 #define MAKE_IRQ(intc, off) (AU1000_INTC##intc##_INT_BASE + (off)) 26 26 27 + /* GPIO1 registers within SYS_ area */ 28 + #define SYS_TRIOUTRD 0x100 29 + #define SYS_TRIOUTCLR 0x100 30 + #define SYS_OUTPUTRD 0x108 31 + #define SYS_OUTPUTSET 0x108 32 + #define SYS_OUTPUTCLR 0x10C 33 + #define SYS_PINSTATERD 0x110 34 + #define SYS_PININPUTEN 0x110 35 + 36 + /* register offsets within GPIO2 block */ 37 + #define GPIO2_DIR 0x00 38 + #define GPIO2_OUTPUT 0x08 39 + #define GPIO2_PINSTATE 0x0C 40 + #define GPIO2_INTENABLE 0x10 41 + #define GPIO2_ENABLE 0x14 42 + 27 43 struct gpio; 28 44 29 45 static inline int au1000_gpio1_to_irq(int gpio) ··· 217 201 */ 218 202 static inline void alchemy_gpio1_set_value(int gpio, int v) 219 203 { 204 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR); 220 205 unsigned long mask = 1 << (gpio - ALCHEMY_GPIO1_BASE); 221 206 unsigned long r = v ? SYS_OUTPUTSET : SYS_OUTPUTCLR; 222 - au_writel(mask, r); 223 - au_sync(); 207 + __raw_writel(mask, base + r); 208 + wmb(); 224 209 } 225 210 226 211 static inline int alchemy_gpio1_get_value(int gpio) 227 212 { 213 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR); 228 214 unsigned long mask = 1 << (gpio - ALCHEMY_GPIO1_BASE); 229 - return au_readl(SYS_PINSTATERD) & mask; 215 + return __raw_readl(base + SYS_PINSTATERD) & mask; 230 216 } 231 217 232 218 static inline int alchemy_gpio1_direction_input(int gpio) 233 219 { 220 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR); 234 221 unsigned long mask = 1 << (gpio - ALCHEMY_GPIO1_BASE); 235 - au_writel(mask, SYS_TRIOUTCLR); 236 - au_sync(); 222 + __raw_writel(mask, base + SYS_TRIOUTCLR); 223 + wmb(); 237 224 return 0; 238 225 } 239 226 ··· 277 258 */ 278 259 static inline void __alchemy_gpio2_mod_dir(int gpio, int to_out) 279 260 { 261 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); 280 262 unsigned long mask = 1 << (gpio - ALCHEMY_GPIO2_BASE); 281 - unsigned long d = au_readl(GPIO2_DIR); 263 + unsigned long d = __raw_readl(base + GPIO2_DIR); 264 + 282 265 if (to_out) 283 266 d |= mask; 284 267 else 285 268 d &= ~mask; 286 - au_writel(d, GPIO2_DIR); 287 - au_sync(); 269 + __raw_writel(d, base + GPIO2_DIR); 270 + wmb(); 288 271 } 289 272 290 273 static inline void alchemy_gpio2_set_value(int gpio, int v) 291 274 { 275 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); 292 276 unsigned long mask; 293 277 mask = ((v) ? 0x00010001 : 0x00010000) << (gpio - ALCHEMY_GPIO2_BASE); 294 - au_writel(mask, GPIO2_OUTPUT); 295 - au_sync(); 278 + __raw_writel(mask, base + GPIO2_OUTPUT); 279 + wmb(); 296 280 } 297 281 298 282 static inline int alchemy_gpio2_get_value(int gpio) 299 283 { 300 - return au_readl(GPIO2_PINSTATE) & (1 << (gpio - ALCHEMY_GPIO2_BASE)); 284 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); 285 + return __raw_readl(base + GPIO2_PINSTATE) & (1 << (gpio - ALCHEMY_GPIO2_BASE)); 301 286 } 302 287 303 288 static inline int alchemy_gpio2_direction_input(int gpio) ··· 353 330 */ 354 331 static inline void alchemy_gpio1_input_enable(void) 355 332 { 356 - au_writel(0, SYS_PININPUTEN); /* the write op is key */ 357 - au_sync(); 333 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR); 334 + __raw_writel(0, base + SYS_PININPUTEN); /* the write op is key */ 335 + wmb(); 358 336 } 359 337 360 338 /* GPIO2 shared interrupts and control */ 361 339 362 340 static inline void __alchemy_gpio2_mod_int(int gpio2, int en) 363 341 { 364 - unsigned long r = au_readl(GPIO2_INTENABLE); 342 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); 343 + unsigned long r = __raw_readl(base + GPIO2_INTENABLE); 365 344 if (en) 366 345 r |= 1 << gpio2; 367 346 else 368 347 r &= ~(1 << gpio2); 369 - au_writel(r, GPIO2_INTENABLE); 370 - au_sync(); 348 + __raw_writel(r, base + GPIO2_INTENABLE); 349 + wmb(); 371 350 } 372 351 373 352 /** ··· 444 419 */ 445 420 static inline void alchemy_gpio2_enable(void) 446 421 { 447 - au_writel(3, GPIO2_ENABLE); /* reset, clock enabled */ 448 - au_sync(); 449 - au_writel(1, GPIO2_ENABLE); /* clock enabled */ 450 - au_sync(); 422 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); 423 + __raw_writel(3, base + GPIO2_ENABLE); /* reset, clock enabled */ 424 + wmb(); 425 + __raw_writel(1, base + GPIO2_ENABLE); /* clock enabled */ 426 + wmb(); 451 427 } 452 428 453 429 /** ··· 458 432 */ 459 433 static inline void alchemy_gpio2_disable(void) 460 434 { 461 - au_writel(2, GPIO2_ENABLE); /* reset, clock disabled */ 462 - au_sync(); 435 + void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); 436 + __raw_writel(2, base + GPIO2_ENABLE); /* reset, clock disabled */ 437 + wmb(); 463 438 } 464 439 465 440 /**********************************************************************/
+2 -1
drivers/mtd/nand/au1550nd.c
··· 10 10 */ 11 11 12 12 #include <linux/slab.h> 13 + #include <linux/gpio.h> 13 14 #include <linux/init.h> 14 15 #include <linux/module.h> 15 16 #include <linux/interrupt.h> ··· 471 470 472 471 #ifdef CONFIG_MIPS_PB1550 473 472 /* set gpio206 high */ 474 - au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); 473 + gpio_direction_input(206); 475 474 476 475 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1); 477 476
+12 -9
drivers/watchdog/mtx-1_wdt.c
··· 66 66 int default_ticks; 67 67 unsigned long inuse; 68 68 unsigned gpio; 69 + int gstate; 69 70 } mtx1_wdt_device; 70 71 71 72 static void mtx1_wdt_trigger(unsigned long unused) ··· 76 75 spin_lock(&mtx1_wdt_device.lock); 77 76 if (mtx1_wdt_device.running) 78 77 ticks--; 79 - /* 80 - * toggle GPIO2_15 81 - */ 82 - tmp = au_readl(GPIO2_DIR); 83 - tmp = (tmp & ~(1 << mtx1_wdt_device.gpio)) | 84 - ((~tmp) & (1 << mtx1_wdt_device.gpio)); 85 - au_writel(tmp, GPIO2_DIR); 78 + 79 + /* toggle wdt gpio */ 80 + mtx1_wdt_device.gstate = ~mtx1_wdt_device.gstate; 81 + if (mtx1_wdt_device.gstate) 82 + gpio_direction_output(mtx1_wdt_device.gpio, 1); 83 + else 84 + gpio_direction_input(mtx1_wdt_device.gpio); 86 85 87 86 if (mtx1_wdt_device.queue && ticks) 88 87 mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); ··· 104 103 spin_lock_irqsave(&mtx1_wdt_device.lock, flags); 105 104 if (!mtx1_wdt_device.queue) { 106 105 mtx1_wdt_device.queue = 1; 107 - gpio_set_value(mtx1_wdt_device.gpio, 1); 106 + mtx1_wdt_device.gstate = 1; 107 + gpio_direction_output(mtx1_wdt_device.gpio, 1); 108 108 mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); 109 109 } 110 110 mtx1_wdt_device.running++; ··· 119 117 spin_lock_irqsave(&mtx1_wdt_device.lock, flags); 120 118 if (mtx1_wdt_device.queue) { 121 119 mtx1_wdt_device.queue = 0; 122 - gpio_set_value(mtx1_wdt_device.gpio, 0); 120 + mtx1_wdt_device.gstate = 0; 121 + gpio_direction_output(mtx1_wdt_device.gpio, 0); 123 122 } 124 123 ticks = mtx1_wdt_device.default_ticks; 125 124 spin_unlock_irqrestore(&mtx1_wdt_device.lock, flags);