bd5f5e8f475891cbd32c5df3e6a9a9b85b027fad
[openwrt.git] / target / linux / brcm63xx / patches-4.4 / 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 @@ -258,9 +258,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,15 +8,24 @@
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/basic_mmio_gpio.h>
54  #include <linux/gpio.h>
55 +#include <linux/gpio/machine.h>
56  
57  #include <bcm63xx_cpu.h>
58  #include <bcm63xx_gpio.h>
59  #include <bcm63xx_regs.h>
60  
61 +/* for registering lookups; make them large enough to hold OF names */
62 +static char *gpio_chip_labels[] = {
63 +       "xxxxxxxx.gpio-controller",
64 +       "xxxxxxxx.gpio-controller",
65 +};
66 +
67  static void __init bcm63xx_gpio_init_one(int id, int dir, int data, int ngpio)
68  {
69         struct resource res[2];
70 @@ -40,6 +49,7 @@ static void __init bcm63xx_gpio_init_one
71         pdata.base = id * 32;
72         pdata.ngpio = ngpio;
73  
74 +       sprintf(gpio_chip_labels[id], "bcm63xx-gpio.%d", id);
75         platform_device_register_resndata(NULL, "bcm63xx-gpio", id, res, 2,
76                                           &pdata, sizeof(pdata));
77  }
78 @@ -64,3 +74,25 @@ int __init bcm63xx_gpio_init(void)
79         return 0;
80  
81  }
82 +
83 +static struct gpiod_lookup_table ephy_reset = {
84 +       .dev_id = "bcm63xx_enet_shared.0",
85 +       .table = {
86 +               { /* filled at runtime */ },
87 +               { },
88 +       },
89 +};
90 +
91 +
92 +void bcm63xx_gpio_ephy_reset(int hw_gpio, enum gpio_lookup_flags flags)
93 +{
94 +       if (ephy_reset.table[0].chip_label)
95 +               return;
96 +
97 +       ephy_reset.table[0].chip_label = gpio_chip_labels[hw_gpio / 32];
98 +       ephy_reset.table[0].chip_hwnum = hw_gpio % 32;
99 +       ephy_reset.table[0].con_id = "ephy-reset";
100 +       ephy_reset.table[0].flags = flags;
101 +
102 +       gpiod_add_lookup_table(&ephy_reset);
103 +}
104 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h
105 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h
106 @@ -2,9 +2,11 @@
107  #define BCM63XX_GPIO_H
108  
109  #include <linux/init.h>
110 +#include <linux/gpio/machine.h>
111  #include <bcm63xx_cpu.h>
112  
113  int __init bcm63xx_gpio_init(void);
114 +void bcm63xx_gpio_ephy_reset(int hw_gpio, enum gpio_lookup_flags flags);
115  
116  static inline unsigned long bcm63xx_gpio_count(void)
117  {
118 --- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
119 +++ b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
120 @@ -3,6 +3,7 @@
121  
122  #include <linux/types.h>
123  #include <linux/gpio.h>
124 +#include <linux/gpio/machine.h>
125  #include <linux/leds.h>
126  #include <bcm63xx_dev_enet.h>
127  #include <bcm63xx_dev_usb_usbd.h>
128 @@ -54,8 +55,8 @@ struct board_info {
129         /* External PHY reset GPIO */
130         unsigned int ephy_reset_gpio;
131  
132 -       /* External PHY reset GPIO flags from gpio.h */
133 -       unsigned long ephy_reset_gpio_flags;
134 +       /* External PHY reset GPIO flags from gpio/machine.h */
135 +       enum gpio_lookup_flags ephy_reset_gpio_flags;
136  
137         /* fallback sprom config */
138         struct fallback_sprom_data fallback_sprom;