bcm53xx: add support for the PCIe controller
[openwrt/svn-archive/archive.git] / target / linux / bcm53xx / patches-3.14 / 142-bcma-add-support-for-chipcommon-B-core.patch
1 From 6c0df4a483e41ef129caa8948b3bcde7f91de197 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Mon, 12 May 2014 20:33:15 +0200
4 Subject: [PATCH 11/15] bcma: add support for chipcommon B core
5
6 This core is used on BCM4708 to configure the PCIe and USB3 PHYs and it
7 contains the addresses to the Device Management unit. This will be used
8 by the PCIe driver first.
9
10 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
11 ---
12 drivers/bcma/Makefile | 1 +
13 drivers/bcma/bcma_private.h | 4 ++
14 drivers/bcma/driver_chipcommon_b.c | 59 +++++++++++++++++++++++++++++
15 drivers/bcma/main.c | 10 +++++
16 drivers/bcma/scan.c | 1 +
17 include/linux/bcma/bcma.h | 1 +
18 include/linux/bcma/bcma_driver_chipcommon.h | 8 ++++
19 7 files changed, 84 insertions(+)
20 create mode 100644 drivers/bcma/driver_chipcommon_b.c
21
22 --- a/drivers/bcma/Makefile
23 +++ b/drivers/bcma/Makefile
24 @@ -1,5 +1,6 @@
25 bcma-y += main.o scan.o core.o sprom.o
26 bcma-y += driver_chipcommon.o driver_chipcommon_pmu.o
27 +bcma-y += driver_chipcommon_b.o
28 bcma-$(CONFIG_BCMA_SFLASH) += driver_chipcommon_sflash.o
29 bcma-$(CONFIG_BCMA_NFLASH) += driver_chipcommon_nflash.o
30 bcma-y += driver_pci.o
31 --- a/drivers/bcma/bcma_private.h
32 +++ b/drivers/bcma/bcma_private.h
33 @@ -50,6 +50,10 @@ void bcma_chipco_serial_init(struct bcma
34 extern struct platform_device bcma_pflash_dev;
35 #endif /* CONFIG_BCMA_DRIVER_MIPS */
36
37 +/* driver_chipcommon_b.c */
38 +int bcma_core_chipcommon_b_init(struct bcma_drv_cc_b *ccb);
39 +void bcma_core_chipcommon_b_free(struct bcma_drv_cc_b *ccb);
40 +
41 /* driver_chipcommon_pmu.c */
42 u32 bcma_pmu_get_alp_clock(struct bcma_drv_cc *cc);
43 u32 bcma_pmu_get_cpu_clock(struct bcma_drv_cc *cc);
44 --- /dev/null
45 +++ b/drivers/bcma/driver_chipcommon_b.c
46 @@ -0,0 +1,59 @@
47 +/*
48 + * Broadcom specific AMBA
49 + * ChipCommon B Unit driver
50 + *
51 + * Copyright 2011, 2014, Hauke Mehrtens <hauke@hauke-m.de>
52 + *
53 + * Licensed under the GNU/GPL. See COPYING for details.
54 + */
55 +
56 +#include "bcma_private.h"
57 +#include <linux/export.h>
58 +#include <linux/bcma/bcma.h>
59 +
60 +static bool bcma_wait_reg(void __iomem *addr, u32 mask, u32 value,
61 + int timeout)
62 +{
63 + unsigned long deadline = jiffies + timeout;
64 + u32 val;
65 +
66 + do {
67 + val = readl(addr);
68 + if ((val & mask) == value)
69 + return true;
70 + cpu_relax();
71 + udelay(10);
72 + } while (!time_after_eq(jiffies, deadline));
73 +
74 + pr_warn("Timeout waiting for register %p!\n", addr);
75 +
76 + return false;
77 +}
78 +
79 +void bcma_chipco_b_mii_write(struct bcma_drv_cc_b *ccb, u32 offset, u32 value)
80 +{
81 + writel(offset, ccb->mii + 0x00);
82 + bcma_wait_reg(ccb->mii + 0x00, 0x0100, 0x0000, 100);
83 + writel(value, ccb->mii + 0x04);
84 + bcma_wait_reg(ccb->mii + 0x00, 0x0100, 0x0000, 100);
85 +}
86 +EXPORT_SYMBOL_GPL(bcma_chipco_b_mii_write);
87 +
88 +int bcma_core_chipcommon_b_init(struct bcma_drv_cc_b *ccb)
89 +{
90 + if (ccb->setup_done)
91 + return 0;
92 +
93 + ccb->setup_done = 1;
94 + ccb->mii = ioremap_nocache(ccb->core->addr_s[1], BCMA_CORE_SIZE);
95 + if (!ccb->mii)
96 + return -ENOMEM;
97 +
98 + return 0;
99 +}
100 +
101 +void bcma_core_chipcommon_b_free(struct bcma_drv_cc_b *ccb)
102 +{
103 + if (ccb->mii)
104 + iounmap(ccb->mii);
105 +}
106 --- a/drivers/bcma/main.c
107 +++ b/drivers/bcma/main.c
108 @@ -164,6 +164,7 @@ static int bcma_register_cores(struct bc
109 switch (core->id.id) {
110 case BCMA_CORE_4706_CHIPCOMMON:
111 case BCMA_CORE_CHIPCOMMON:
112 + case BCMA_CORE_CHIPCOMMON_B:
113 case BCMA_CORE_PCI:
114 case BCMA_CORE_PCIE:
115 case BCMA_CORE_MIPS_74K:
116 @@ -300,6 +301,13 @@ int bcma_bus_register(struct bcma_bus *b
117 bcma_core_chipcommon_init(&bus->drv_cc);
118 }
119
120 + /* Init CC core */
121 + core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON_B);
122 + if (core) {
123 + bus->drv_cc_b.core = core;
124 + bcma_core_chipcommon_b_init(&bus->drv_cc_b);
125 + }
126 +
127 /* Init MIPS core */
128 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
129 if (core) {
130 @@ -347,6 +355,8 @@ void bcma_bus_unregister(struct bcma_bus
131 else if (err)
132 bcma_err(bus, "Can not unregister GPIO driver: %i\n", err);
133
134 + bcma_core_chipcommon_b_free(&bus->drv_cc_b);
135 +
136 cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
137 cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE);
138 cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
139 --- a/drivers/bcma/scan.c
140 +++ b/drivers/bcma/scan.c
141 @@ -314,6 +314,7 @@ static int bcma_get_next_core(struct bcm
142 /* Some specific cores don't need wrappers */
143 switch (core->id.id) {
144 case BCMA_CORE_4706_MAC_GBIT_COMMON:
145 + case BCMA_CORE_CHIPCOMMON_B:
146 /* Not used yet: case BCMA_CORE_OOB_ROUTER: */
147 break;
148 default:
149 --- a/include/linux/bcma/bcma.h
150 +++ b/include/linux/bcma/bcma.h
151 @@ -334,6 +334,7 @@ struct bcma_bus {
152 u8 num;
153
154 struct bcma_drv_cc drv_cc;
155 + struct bcma_drv_cc_b drv_cc_b;
156 struct bcma_drv_pci drv_pci[2];
157 struct bcma_drv_mips drv_mips;
158 struct bcma_drv_gmac_cmn drv_gmac_cmn;
159 --- a/include/linux/bcma/bcma_driver_chipcommon.h
160 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
161 @@ -644,6 +644,12 @@ struct bcma_drv_cc {
162 #endif
163 };
164
165 +struct bcma_drv_cc_b {
166 + struct bcma_device *core;
167 + u8 setup_done:1;
168 + void __iomem *mii;
169 +};
170 +
171 /* Register access */
172 #define bcma_cc_read32(cc, offset) \
173 bcma_read32((cc)->core, offset)
174 @@ -699,4 +705,6 @@ extern void bcma_pmu_spuravoid_pllupdate
175
176 extern u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc);
177
178 +void bcma_chipco_b_mii_write(struct bcma_drv_cc_b *ccb, u32 offset, u32 value);
179 +
180 #endif /* LINUX_BCMA_DRIVER_CC_H_ */