9e2db8ca6370a4707c7fc946de609d76e03e2236
[openwrt/staging/ynezz.git] / target / linux / brcm63xx / patches-4.9 / 377-MIPS-BCM63XX-register-lookup-for-ephy-reset-gpio.patch
1 From d13bdf92ec885105cf107183f8464c40e5f3b93b Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Sat, 21 Feb 2015 17:21:59 +0100
4 Subject: [PATCH 4/6] MIPS: BCM63XX: register lookup for ephy-reset gpio
5
6
7 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
8 ---
9 arch/mips/bcm63xx/boards/board_bcm963xx.c | 2 +-
10 arch/mips/bcm63xx/boards/board_common.c | 7 +++--
11 arch/mips/bcm63xx/gpio.c | 32 ++++++++++++++++++++
12 arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h | 2 ++
13 .../mips/include/asm/mach-bcm63xx/board_bcm963xx.h | 5 +--
14 5 files changed, 42 insertions(+), 6 deletions(-)
15
16 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
17 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
18 @@ -55,7 +55,7 @@ static struct board_info __initdata boar
19 },
20
21 .ephy_reset_gpio = 36,
22 - .ephy_reset_gpio_flags = GPIOF_INIT_HIGH,
23 + .ephy_reset_gpio_flags = GPIO_ACTIVE_LOW,
24 };
25 #endif
26
27 --- a/arch/mips/bcm63xx/boards/board_common.c
28 +++ b/arch/mips/bcm63xx/boards/board_common.c
29 @@ -247,9 +247,10 @@ int __init board_register_devices(void)
30
31 platform_device_register(&bcm63xx_gpio_leds);
32
33 - if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags)
34 - gpio_request_one(board.ephy_reset_gpio,
35 - board.ephy_reset_gpio_flags, "ephy-reset");
36 + if (board.ephy_reset_gpio && board.ephy_reset_gpio_flags) {
37 + bcm63xx_gpio_ephy_reset(board.ephy_reset_gpio,
38 + board.ephy_reset_gpio_flags);
39 + }
40
41 return 0;
42 }
43 --- a/arch/mips/bcm63xx/gpio.c
44 +++ b/arch/mips/bcm63xx/gpio.c
45 @@ -8,14 +8,22 @@
46 * Copyright (C) Jonas Gorski <jogo@openwrt.org>
47 */
48
49 +#include <asm/addrspace.h>
50 +
51 #include <linux/kernel.h>
52 #include <linux/platform_device.h>
53 #include <linux/gpio/driver.h>
54 +#include <linux/gpio/machine.h>
55
56 #include <bcm63xx_cpu.h>
57 #include <bcm63xx_gpio.h>
58 #include <bcm63xx_regs.h>
59
60 +static const char * const gpio_chip_labels[] = {
61 + "bcm63xx-gpio.0",
62 + "bcm63xx-gpio.1",
63 +};
64 +
65 static void __init bcm63xx_gpio_init_one(int id, int dir, int data, int ngpio)
66 {
67 struct resource res[2];
68 @@ -63,3 +71,25 @@ int __init bcm63xx_gpio_init(void)
69 return 0;
70
71 }
72 +
73 +static struct gpiod_lookup_table ephy_reset = {
74 + .dev_id = "bcm63xx_enet-0",
75 + .table = {
76 + { /* filled at runtime */ },
77 + { },
78 + },
79 +};
80 +
81 +
82 +void bcm63xx_gpio_ephy_reset(int hw_gpio, enum gpio_lookup_flags flags)
83 +{
84 + if (ephy_reset.table[0].chip_label)
85 + return;
86 +
87 + ephy_reset.table[0].chip_label = gpio_chip_labels[hw_gpio / 32];
88 + ephy_reset.table[0].chip_hwnum = hw_gpio % 32;
89 + ephy_reset.table[0].con_id = "reset";
90 + ephy_reset.table[0].flags = flags;
91 +
92 + gpiod_add_lookup_table(&ephy_reset);
93 +}
94 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h
95 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h
96 @@ -2,9 +2,11 @@
97 #define BCM63XX_GPIO_H
98
99 #include <linux/init.h>
100 +#include <linux/gpio/machine.h>
101 #include <bcm63xx_cpu.h>
102
103 int __init bcm63xx_gpio_init(void);
104 +void bcm63xx_gpio_ephy_reset(int hw_gpio, enum gpio_lookup_flags flags);
105
106 static inline unsigned long bcm63xx_gpio_count(void)
107 {
108 --- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
109 +++ b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
110 @@ -3,6 +3,7 @@
111
112 #include <linux/types.h>
113 #include <linux/gpio.h>
114 +#include <linux/gpio/machine.h>
115 #include <linux/leds.h>
116 #include <bcm63xx_dev_enet.h>
117 #include <bcm63xx_dev_usb_usbd.h>
118 @@ -49,8 +50,8 @@ struct board_info {
119 /* External PHY reset GPIO */
120 unsigned int ephy_reset_gpio;
121
122 - /* External PHY reset GPIO flags from gpio.h */
123 - unsigned long ephy_reset_gpio_flags;
124 + /* External PHY reset GPIO flags from gpio/machine.h */
125 + enum gpio_lookup_flags ephy_reset_gpio_flags;
126
127 /* fallback sprom config */
128 struct fallback_sprom_data fallback_sprom;