blob: 603b63032e93053d7fda6acf8eb76af3f88cecea [file] [log] [blame]
Michael Buesch61e115a2007-09-18 15:12:50 -04001/*
2 * Sonics Silicon Backplane
3 * Broadcom ChipCommon core driver
4 *
5 * Copyright 2005, Broadcom Corporation
Michael Büscheb032b92011-07-04 20:50:05 +02006 * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
Michael Buesch61e115a2007-09-18 15:12:50 -04007 *
8 * Licensed under the GNU/GPL. See COPYING for details.
9 */
10
11#include <linux/ssb/ssb.h>
12#include <linux/ssb/ssb_regs.h>
Paul Gortmaker1014c222011-07-27 22:07:02 -040013#include <linux/export.h>
Michael Buesch61e115a2007-09-18 15:12:50 -040014#include <linux/pci.h>
15
16#include "ssb_private.h"
17
18
19/* Clock sources */
20enum ssb_clksrc {
21 /* PCI clock */
22 SSB_CHIPCO_CLKSRC_PCI,
23 /* Crystal slow clock oscillator */
24 SSB_CHIPCO_CLKSRC_XTALOS,
25 /* Low power oscillator */
26 SSB_CHIPCO_CLKSRC_LOPWROS,
27};
28
29
Michael Bueschc2bcbe62008-02-19 14:53:35 +010030static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset,
31 u32 mask, u32 value)
Michael Buesch61e115a2007-09-18 15:12:50 -040032{
33 value &= mask;
34 value |= chipco_read32(cc, offset) & ~mask;
35 chipco_write32(cc, offset, value);
Michael Bueschc2bcbe62008-02-19 14:53:35 +010036
37 return value;
Michael Buesch61e115a2007-09-18 15:12:50 -040038}
39
40void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc,
41 enum ssb_clkmode mode)
42{
43 struct ssb_device *ccdev = cc->dev;
44 struct ssb_bus *bus;
45 u32 tmp;
46
47 if (!ccdev)
48 return;
49 bus = ccdev->bus;
Rafał Miłecki0ca69952011-04-27 17:40:11 +020050
51 /* We support SLOW only on 6..9 */
52 if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW)
53 mode = SSB_CLKMODE_DYNAMIC;
54
55 if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
56 return; /* PMU controls clockmode, separated function needed */
57 SSB_WARN_ON(ccdev->id.revision >= 20);
58
Michael Buesch61e115a2007-09-18 15:12:50 -040059 /* chipcommon cores prior to rev6 don't support dynamic clock control */
60 if (ccdev->id.revision < 6)
61 return;
Rafał Miłecki0ca69952011-04-27 17:40:11 +020062
63 /* ChipCommon cores rev10+ need testing */
Michael Buesch61e115a2007-09-18 15:12:50 -040064 if (ccdev->id.revision >= 10)
65 return;
Rafał Miłecki0ca69952011-04-27 17:40:11 +020066
Michael Buesch61e115a2007-09-18 15:12:50 -040067 if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
68 return;
69
70 switch (mode) {
Rafał Miłecki0ca69952011-04-27 17:40:11 +020071 case SSB_CLKMODE_SLOW: /* For revs 6..9 only */
Michael Buesch61e115a2007-09-18 15:12:50 -040072 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
73 tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW;
74 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
75 break;
76 case SSB_CLKMODE_FAST:
Rafał Miłecki0ca69952011-04-27 17:40:11 +020077 if (ccdev->id.revision < 10) {
78 ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */
79 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
80 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
81 tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL;
82 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
83 } else {
84 chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
85 (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) |
86 SSB_CHIPCO_SYSCLKCTL_FORCEHT));
87 /* udelay(150); TODO: not available in early init */
88 }
Michael Buesch61e115a2007-09-18 15:12:50 -040089 break;
90 case SSB_CLKMODE_DYNAMIC:
Rafał Miłecki0ca69952011-04-27 17:40:11 +020091 if (ccdev->id.revision < 10) {
92 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
93 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
94 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL;
95 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
96 if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) !=
97 SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL)
98 tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
99 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
Michael Buesch61e115a2007-09-18 15:12:50 -0400100
Rafał Miłecki0ca69952011-04-27 17:40:11 +0200101 /* For dynamic control, we have to release our xtal_pu
102 * "force on" */
103 if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL)
104 ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0);
105 } else {
106 chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
107 (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
108 ~SSB_CHIPCO_SYSCLKCTL_FORCEHT));
109 }
Michael Buesch61e115a2007-09-18 15:12:50 -0400110 break;
111 default:
112 SSB_WARN_ON(1);
113 }
114}
115
116/* Get the Slow Clock Source */
117static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc)
118{
119 struct ssb_bus *bus = cc->dev->bus;
120 u32 uninitialized_var(tmp);
121
122 if (cc->dev->id.revision < 6) {
123 if (bus->bustype == SSB_BUSTYPE_SSB ||
124 bus->bustype == SSB_BUSTYPE_PCMCIA)
125 return SSB_CHIPCO_CLKSRC_XTALOS;
126 if (bus->bustype == SSB_BUSTYPE_PCI) {
127 pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp);
128 if (tmp & 0x10)
129 return SSB_CHIPCO_CLKSRC_PCI;
130 return SSB_CHIPCO_CLKSRC_XTALOS;
131 }
132 }
133 if (cc->dev->id.revision < 10) {
134 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
135 tmp &= 0x7;
136 if (tmp == 0)
137 return SSB_CHIPCO_CLKSRC_LOPWROS;
138 if (tmp == 1)
139 return SSB_CHIPCO_CLKSRC_XTALOS;
140 if (tmp == 2)
141 return SSB_CHIPCO_CLKSRC_PCI;
142 }
143
144 return SSB_CHIPCO_CLKSRC_XTALOS;
145}
146
147/* Get maximum or minimum (depending on get_max flag) slowclock frequency. */
148static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max)
149{
150 int uninitialized_var(limit);
151 enum ssb_clksrc clocksrc;
152 int divisor = 1;
153 u32 tmp;
154
155 clocksrc = chipco_pctl_get_slowclksrc(cc);
156 if (cc->dev->id.revision < 6) {
157 switch (clocksrc) {
158 case SSB_CHIPCO_CLKSRC_PCI:
159 divisor = 64;
160 break;
161 case SSB_CHIPCO_CLKSRC_XTALOS:
162 divisor = 32;
163 break;
164 default:
165 SSB_WARN_ON(1);
166 }
167 } else if (cc->dev->id.revision < 10) {
168 switch (clocksrc) {
169 case SSB_CHIPCO_CLKSRC_LOPWROS:
170 break;
171 case SSB_CHIPCO_CLKSRC_XTALOS:
172 case SSB_CHIPCO_CLKSRC_PCI:
173 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
174 divisor = (tmp >> 16) + 1;
175 divisor *= 4;
176 break;
177 }
178 } else {
179 tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL);
180 divisor = (tmp >> 16) + 1;
181 divisor *= 4;
182 }
183
184 switch (clocksrc) {
185 case SSB_CHIPCO_CLKSRC_LOPWROS:
186 if (get_max)
187 limit = 43000;
188 else
189 limit = 25000;
190 break;
191 case SSB_CHIPCO_CLKSRC_XTALOS:
192 if (get_max)
193 limit = 20200000;
194 else
195 limit = 19800000;
196 break;
197 case SSB_CHIPCO_CLKSRC_PCI:
198 if (get_max)
199 limit = 34000000;
200 else
201 limit = 25000000;
202 break;
203 }
204 limit /= divisor;
205
206 return limit;
207}
208
209static void chipco_powercontrol_init(struct ssb_chipcommon *cc)
210{
211 struct ssb_bus *bus = cc->dev->bus;
212
213 if (bus->chip_id == 0x4321) {
214 if (bus->chip_rev == 0)
215 chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4);
216 else if (bus->chip_rev == 1)
217 chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4);
218 }
219
220 if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
221 return;
222
223 if (cc->dev->id.revision >= 10) {
224 /* Set Idle Power clock rate to 1Mhz */
225 chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
226 (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
227 0x0000FFFF) | 0x00040000);
228 } else {
229 int maxfreq;
230
231 maxfreq = chipco_pctl_clockfreqlimit(cc, 1);
232 chipco_write32(cc, SSB_CHIPCO_PLLONDELAY,
233 (maxfreq * 150 + 999999) / 1000000);
234 chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY,
235 (maxfreq * 15 + 999999) / 1000000);
236 }
237}
238
Rafał Miłeckifd515942010-05-24 21:50:24 +0200239/* http://bcm-v4.sipsolutions.net/802.11/PmuFastPwrupDelay */
240static u16 pmu_fast_powerup_delay(struct ssb_chipcommon *cc)
241{
242 struct ssb_bus *bus = cc->dev->bus;
243
244 switch (bus->chip_id) {
245 case 0x4312:
246 case 0x4322:
247 case 0x4328:
248 return 7000;
249 case 0x4325:
250 /* TODO: */
251 default:
252 return 15000;
253 }
254}
255
256/* http://bcm-v4.sipsolutions.net/802.11/ClkctlFastPwrupDelay */
Michael Buesch61e115a2007-09-18 15:12:50 -0400257static void calc_fast_powerup_delay(struct ssb_chipcommon *cc)
258{
259 struct ssb_bus *bus = cc->dev->bus;
260 int minfreq;
261 unsigned int tmp;
262 u32 pll_on_delay;
263
264 if (bus->bustype != SSB_BUSTYPE_PCI)
265 return;
Rafał Miłeckifd515942010-05-24 21:50:24 +0200266
267 if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
268 cc->fast_pwrup_delay = pmu_fast_powerup_delay(cc);
269 return;
270 }
271
Michael Buesch61e115a2007-09-18 15:12:50 -0400272 if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
273 return;
274
275 minfreq = chipco_pctl_clockfreqlimit(cc, 0);
276 pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY);
277 tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq;
278 SSB_WARN_ON(tmp & ~0xFFFF);
279
280 cc->fast_pwrup_delay = tmp;
281}
282
Hauke Mehrtensf924e1e2012-12-05 18:46:03 +0100283static u32 ssb_chipco_alp_clock(struct ssb_chipcommon *cc)
284{
285 if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
286 return ssb_pmu_get_alp_clock(cc);
287
288 return 20000000;
289}
290
Michael Buesch61e115a2007-09-18 15:12:50 -0400291void ssb_chipcommon_init(struct ssb_chipcommon *cc)
292{
293 if (!cc->dev)
294 return; /* We don't have a ChipCommon */
John W. Linvilled53cdbb2010-03-31 21:39:35 +0200295 if (cc->dev->id.revision >= 11)
296 cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT);
Larry Finger9d1ac342010-05-14 22:08:58 -0500297 ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status);
Rafał Miłecki9835a302011-04-24 11:04:19 +0200298
299 if (cc->dev->id.revision >= 20) {
300 chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0);
301 chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0);
302 }
303
Michael Bueschc9703142009-02-03 19:23:18 +0100304 ssb_pmu_init(cc);
Michael Buesch61e115a2007-09-18 15:12:50 -0400305 chipco_powercontrol_init(cc);
306 ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
307 calc_fast_powerup_delay(cc);
308}
309
Michael Buesch8fe2b652008-03-30 00:10:50 +0100310void ssb_chipco_suspend(struct ssb_chipcommon *cc)
Michael Buesch61e115a2007-09-18 15:12:50 -0400311{
312 if (!cc->dev)
313 return;
314 ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW);
315}
316
317void ssb_chipco_resume(struct ssb_chipcommon *cc)
318{
319 if (!cc->dev)
320 return;
321 chipco_powercontrol_init(cc);
322 ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
323}
324
325/* Get the processor clock */
326void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc,
327 u32 *plltype, u32 *n, u32 *m)
328{
329 *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N);
330 *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
331 switch (*plltype) {
332 case SSB_PLLTYPE_2:
333 case SSB_PLLTYPE_4:
334 case SSB_PLLTYPE_6:
335 case SSB_PLLTYPE_7:
336 *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS);
337 break;
338 case SSB_PLLTYPE_3:
339 /* 5350 uses m2 to control mips */
340 *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2);
341 break;
342 default:
343 *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB);
344 break;
345 }
346}
347
348/* Get the bus clock */
349void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc,
350 u32 *plltype, u32 *n, u32 *m)
351{
352 *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N);
353 *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
354 switch (*plltype) {
355 case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */
356 *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS);
357 break;
358 case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
359 if (cc->dev->bus->chip_id != 0x5365) {
360 *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2);
361 break;
362 }
363 /* Fallthough */
364 default:
365 *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB);
366 }
367}
368
369void ssb_chipco_timing_init(struct ssb_chipcommon *cc,
370 unsigned long ns)
371{
372 struct ssb_device *dev = cc->dev;
373 struct ssb_bus *bus = dev->bus;
374 u32 tmp;
375
376 /* set register for external IO to control LED. */
377 chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11);
378 tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */
379 tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */
380 tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */
381 chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */
382
383 /* Set timing for the flash */
384 tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */
385 tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */
386 tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */
387 if ((bus->chip_id == 0x5365) ||
388 (dev->id.revision < 9))
389 chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp);
390 if ((bus->chip_id == 0x5365) ||
391 (dev->id.revision < 9) ||
392 ((bus->chip_id == 0x5350) && (bus->chip_rev == 0)))
393 chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp);
394
395 if (bus->chip_id == 0x5350) {
396 /* Enable EXTIF */
397 tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */
398 tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */
399 tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */
400 tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */
401 chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */
402 }
403}
404
405/* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
Michael Buesch6b9bafe2007-09-19 18:55:12 +0200406void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks)
Michael Buesch61e115a2007-09-18 15:12:50 -0400407{
408 /* instant NMI */
409 chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks);
410}
411
Aurelien Jarno28de57d2008-02-22 16:14:58 +0100412void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value)
413{
414 chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value);
415}
416
417u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask)
418{
419 return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask;
420}
421
Michael Buesch61e115a2007-09-18 15:12:50 -0400422u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask)
423{
424 return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask;
425}
426
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100427u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value)
Michael Buesch61e115a2007-09-18 15:12:50 -0400428{
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100429 return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value);
Michael Buesch61e115a2007-09-18 15:12:50 -0400430}
431
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100432u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value)
Michael Buesch61e115a2007-09-18 15:12:50 -0400433{
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100434 return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value);
Michael Buesch61e115a2007-09-18 15:12:50 -0400435}
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100436
437u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value)
438{
439 return chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value);
440}
Larry Finger85373ee2010-03-10 10:41:32 -0600441EXPORT_SYMBOL(ssb_chipco_gpio_control);
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100442
443u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value)
444{
445 return chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value);
446}
Michael Bueschc2bcbe62008-02-19 14:53:35 +0100447
448u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value)
449{
450 return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value);
451}
Michael Buesch61e115a2007-09-18 15:12:50 -0400452
453#ifdef CONFIG_SSB_SERIAL
454int ssb_chipco_serial_init(struct ssb_chipcommon *cc,
455 struct ssb_serial_port *ports)
456{
457 struct ssb_bus *bus = cc->dev->bus;
458 int nr_ports = 0;
459 u32 plltype;
460 unsigned int irq;
461 u32 baud_base, div;
462 u32 i, n;
Michael Buesch58ff70d2008-02-18 21:44:39 +0100463 unsigned int ccrev = cc->dev->id.revision;
Michael Buesch61e115a2007-09-18 15:12:50 -0400464
465 plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
466 irq = ssb_mips_irq(cc->dev);
467
468 if (plltype == SSB_PLLTYPE_1) {
469 /* PLL clock */
470 baud_base = ssb_calc_clock_rate(plltype,
471 chipco_read32(cc, SSB_CHIPCO_CLOCK_N),
472 chipco_read32(cc, SSB_CHIPCO_CLOCK_M2));
473 div = 1;
474 } else {
Michael Buesch58ff70d2008-02-18 21:44:39 +0100475 if (ccrev == 20) {
476 /* BCM5354 uses constant 25MHz clock */
477 baud_base = 25000000;
478 div = 48;
Michael Buesch61e115a2007-09-18 15:12:50 -0400479 /* Set the override bit so we don't divide it */
480 chipco_write32(cc, SSB_CHIPCO_CORECTL,
Michael Buesch58ff70d2008-02-18 21:44:39 +0100481 chipco_read32(cc, SSB_CHIPCO_CORECTL)
482 | SSB_CHIPCO_CORECTL_UARTCLK0);
483 } else if ((ccrev >= 11) && (ccrev != 15)) {
Hauke Mehrtensf924e1e2012-12-05 18:46:03 +0100484 baud_base = ssb_chipco_alp_clock(cc);
Michael Buesch58ff70d2008-02-18 21:44:39 +0100485 div = 1;
486 if (ccrev >= 21) {
487 /* Turn off UART clock before switching clocksource. */
488 chipco_write32(cc, SSB_CHIPCO_CORECTL,
489 chipco_read32(cc, SSB_CHIPCO_CORECTL)
490 & ~SSB_CHIPCO_CORECTL_UARTCLKEN);
491 }
492 /* Set the override bit so we don't divide it */
493 chipco_write32(cc, SSB_CHIPCO_CORECTL,
494 chipco_read32(cc, SSB_CHIPCO_CORECTL)
495 | SSB_CHIPCO_CORECTL_UARTCLK0);
496 if (ccrev >= 21) {
497 /* Re-enable the UART clock. */
498 chipco_write32(cc, SSB_CHIPCO_CORECTL,
499 chipco_read32(cc, SSB_CHIPCO_CORECTL)
500 | SSB_CHIPCO_CORECTL_UARTCLKEN);
501 }
502 } else if (ccrev >= 3) {
Michael Buesch61e115a2007-09-18 15:12:50 -0400503 /* Internal backplane clock */
504 baud_base = ssb_clockspeed(bus);
505 div = chipco_read32(cc, SSB_CHIPCO_CLKDIV)
506 & SSB_CHIPCO_CLKDIV_UART;
507 } else {
508 /* Fixed internal backplane clock */
509 baud_base = 88000000;
510 div = 48;
511 }
512
513 /* Clock source depends on strapping if UartClkOverride is unset */
Michael Buesch58ff70d2008-02-18 21:44:39 +0100514 if ((ccrev > 0) &&
Michael Buesch61e115a2007-09-18 15:12:50 -0400515 !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) {
516 if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) ==
517 SSB_CHIPCO_CAP_UARTCLK_INT) {
518 /* Internal divided backplane clock */
519 baud_base /= div;
520 } else {
521 /* Assume external clock of 1.8432 MHz */
522 baud_base = 1843200;
523 }
524 }
525 }
526
527 /* Determine the registers of the UARTs */
528 n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART);
529 for (i = 0; i < n; i++) {
530 void __iomem *cc_mmio;
531 void __iomem *uart_regs;
532
533 cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE);
534 uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA;
535 /* Offset changed at after rev 0 */
Michael Buesch58ff70d2008-02-18 21:44:39 +0100536 if (ccrev == 0)
Michael Buesch61e115a2007-09-18 15:12:50 -0400537 uart_regs += (i * 8);
538 else
539 uart_regs += (i * 256);
540
541 nr_ports++;
542 ports[i].regs = uart_regs;
543 ports[i].irq = irq;
544 ports[i].baud_base = baud_base;
545 ports[i].reg_shift = 0;
546 }
547
548 return nr_ports;
549}
550#endif /* CONFIG_SSB_SERIAL */