blob: ef6855398b86be184200e7d24d8c44c16c7bf5b2 [file] [log] [blame]
Rafał Miłecki8369ae32011-05-09 18:56:46 +02001/*
2 * Broadcom specific AMBA
3 * 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>
Hauke Mehrtens56fd5f02012-12-05 18:45:59 +01007 * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
Rafał Miłecki8369ae32011-05-09 18:56:46 +02008 *
9 * Licensed under the GNU/GPL. See COPYING for details.
10 */
11
12#include "bcma_private.h"
Paul Gortmaker44a8e372011-07-27 21:21:04 -040013#include <linux/export.h>
Rafał Miłecki8369ae32011-05-09 18:56:46 +020014#include <linux/bcma/bcma.h>
15
16static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
17 u32 mask, u32 value)
18{
19 value &= mask;
20 value |= bcma_cc_read32(cc, offset) & ~mask;
21 bcma_cc_write32(cc, offset, value);
22
23 return value;
24}
25
Hauke Mehrtens56fd5f02012-12-05 18:45:59 +010026static u32 bcma_chipco_alp_clock(struct bcma_drv_cc *cc)
27{
28 if (cc->capabilities & BCMA_CC_CAP_PMU)
29 return bcma_pmu_alp_clock(cc);
30
31 return 20000000;
32}
33
Hauke Mehrtens49655bb2012-09-29 20:29:49 +020034void bcma_core_chipcommon_early_init(struct bcma_drv_cc *cc)
35{
36 if (cc->early_setup_done)
37 return;
38
39 if (cc->core->id.rev >= 11)
40 cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
41 cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP);
42 if (cc->core->id.rev >= 35)
43 cc->capabilities_ext = bcma_cc_read32(cc, BCMA_CC_CAP_EXT);
44
45 if (cc->capabilities & BCMA_CC_CAP_PMU)
46 bcma_pmu_early_init(cc);
47
48 cc->early_setup_done = true;
49}
50
Rafał Miłecki8369ae32011-05-09 18:56:46 +020051void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
52{
Rafał Miłecki18dfa492011-07-14 21:49:19 +020053 u32 leddc_on = 10;
54 u32 leddc_off = 90;
55
Hauke Mehrtens517f43e2011-07-23 01:20:07 +020056 if (cc->setup_done)
57 return;
58
Hauke Mehrtens49655bb2012-09-29 20:29:49 +020059 bcma_core_chipcommon_early_init(cc);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020060
Rafał Miłecki1073e4e2011-05-11 02:08:09 +020061 if (cc->core->id.rev >= 20) {
62 bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, 0);
63 bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, 0);
64 }
Rafał Miłecki8369ae32011-05-09 18:56:46 +020065
66 if (cc->capabilities & BCMA_CC_CAP_PMU)
67 bcma_pmu_init(cc);
68 if (cc->capabilities & BCMA_CC_CAP_PCTL)
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +020069 bcma_err(cc->core->bus, "Power control not implemented!\n");
Rafał Miłecki18dfa492011-07-14 21:49:19 +020070
71 if (cc->core->id.rev >= 16) {
72 if (cc->core->bus->sprom.leddc_on_time &&
73 cc->core->bus->sprom.leddc_off_time) {
74 leddc_on = cc->core->bus->sprom.leddc_on_time;
75 leddc_off = cc->core->bus->sprom.leddc_off_time;
76 }
77 bcma_cc_write32(cc, BCMA_CC_GPIOTIMER,
78 ((leddc_on << BCMA_CC_GPIOTIMER_ONTIME_SHIFT) |
79 (leddc_off << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT)));
80 }
Hauke Mehrtens517f43e2011-07-23 01:20:07 +020081
82 cc->setup_done = true;
Rafał Miłecki8369ae32011-05-09 18:56:46 +020083}
84
85/* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
86void bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
87{
88 /* instant NMI */
89 bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks);
90}
91
92void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value)
93{
94 bcma_cc_write32_masked(cc, BCMA_CC_IRQMASK, mask, value);
95}
96
97u32 bcma_chipco_irq_status(struct bcma_drv_cc *cc, u32 mask)
98{
99 return bcma_cc_read32(cc, BCMA_CC_IRQSTAT) & mask;
100}
101
102u32 bcma_chipco_gpio_in(struct bcma_drv_cc *cc, u32 mask)
103{
104 return bcma_cc_read32(cc, BCMA_CC_GPIOIN) & mask;
105}
106
107u32 bcma_chipco_gpio_out(struct bcma_drv_cc *cc, u32 mask, u32 value)
108{
109 return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value);
110}
111
112u32 bcma_chipco_gpio_outen(struct bcma_drv_cc *cc, u32 mask, u32 value)
113{
114 return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value);
115}
116
117u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value)
118{
119 return bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value);
120}
121EXPORT_SYMBOL_GPL(bcma_chipco_gpio_control);
122
123u32 bcma_chipco_gpio_intmask(struct bcma_drv_cc *cc, u32 mask, u32 value)
124{
125 return bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value);
126}
127
128u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value)
129{
130 return bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value);
131}
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200132
133#ifdef CONFIG_BCMA_DRIVER_MIPS
134void bcma_chipco_serial_init(struct bcma_drv_cc *cc)
135{
136 unsigned int irq;
137 u32 baud_base;
138 u32 i;
139 unsigned int ccrev = cc->core->id.rev;
140 struct bcma_serial_port *ports = cc->serial_ports;
141
142 if (ccrev >= 11 && ccrev != 15) {
Hauke Mehrtens56fd5f02012-12-05 18:45:59 +0100143 baud_base = bcma_chipco_alp_clock(cc);
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200144 if (ccrev >= 21) {
145 /* Turn off UART clock before switching clocksource. */
146 bcma_cc_write32(cc, BCMA_CC_CORECTL,
147 bcma_cc_read32(cc, BCMA_CC_CORECTL)
148 & ~BCMA_CC_CORECTL_UARTCLKEN);
149 }
150 /* Set the override bit so we don't divide it */
151 bcma_cc_write32(cc, BCMA_CC_CORECTL,
152 bcma_cc_read32(cc, BCMA_CC_CORECTL)
153 | BCMA_CC_CORECTL_UARTCLK0);
154 if (ccrev >= 21) {
155 /* Re-enable the UART clock. */
156 bcma_cc_write32(cc, BCMA_CC_CORECTL,
157 bcma_cc_read32(cc, BCMA_CC_CORECTL)
158 | BCMA_CC_CORECTL_UARTCLKEN);
159 }
160 } else {
Rafał Miłecki9a89c3a2012-07-09 19:34:59 +0200161 bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n", ccrev);
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200162 return;
163 }
164
165 irq = bcma_core_mips_irq(cc->core);
166
167 /* Determine the registers of the UARTs */
168 cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
169 for (i = 0; i < cc->nr_serial_ports; i++) {
170 ports[i].regs = cc->core->io_addr + BCMA_CC_UART0_DATA +
171 (i * 256);
172 ports[i].irq = irq;
173 ports[i].baud_base = baud_base;
174 ports[i].reg_shift = 0;
175 }
176}
177#endif /* CONFIG_BCMA_DRIVER_MIPS */