2 * Broadcom specific AMBA
3 * ChipCommon core driver
5 * Copyright 2005, Broadcom Corporation
6 * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
7 * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
9 * Licensed under the GNU/GPL. See COPYING for details.
12 #include "bcma_private.h"
13 #include <linux/bcm47xx_wdt.h>
14 #include <linux/export.h>
15 #include <linux/platform_device.h>
16 #include <linux/bcma/bcma.h>
18 static inline u32
bcma_cc_write32_masked(struct bcma_drv_cc
*cc
, u16 offset
,
22 value
|= bcma_cc_read32(cc
, offset
) & ~mask
;
23 bcma_cc_write32(cc
, offset
, value
);
28 u32
bcma_chipco_get_alp_clock(struct bcma_drv_cc
*cc
)
30 if (cc
->capabilities
& BCMA_CC_CAP_PMU
)
31 return bcma_pmu_get_alp_clock(cc
);
35 EXPORT_SYMBOL_GPL(bcma_chipco_get_alp_clock
);
37 static u32
bcma_chipco_watchdog_get_max_timer(struct bcma_drv_cc
*cc
)
39 struct bcma_bus
*bus
= cc
->core
->bus
;
42 if (cc
->capabilities
& BCMA_CC_CAP_PMU
) {
43 if (bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM4706
)
45 else if (cc
->core
->id
.rev
< 26)
48 nb
= (cc
->core
->id
.rev
>= 37) ? 32 : 24;
58 static u32
bcma_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt
*wdt
,
61 struct bcma_drv_cc
*cc
= bcm47xx_wdt_get_drvdata(wdt
);
63 return bcma_chipco_watchdog_timer_set(cc
, ticks
);
66 static u32
bcma_chipco_watchdog_timer_set_ms_wdt(struct bcm47xx_wdt
*wdt
,
69 struct bcma_drv_cc
*cc
= bcm47xx_wdt_get_drvdata(wdt
);
72 ticks
= bcma_chipco_watchdog_timer_set(cc
, cc
->ticks_per_ms
* ms
);
73 return ticks
/ cc
->ticks_per_ms
;
76 static int bcma_chipco_watchdog_ticks_per_ms(struct bcma_drv_cc
*cc
)
78 struct bcma_bus
*bus
= cc
->core
->bus
;
80 if (cc
->capabilities
& BCMA_CC_CAP_PMU
) {
81 if (bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM4706
)
82 /* 4706 CC and PMU watchdogs are clocked at 1/4 of ALP
85 return bcma_chipco_get_alp_clock(cc
) / 4000;
87 /* based on 32KHz ILP clock */
90 return bcma_chipco_get_alp_clock(cc
) / 1000;
94 int bcma_chipco_watchdog_register(struct bcma_drv_cc
*cc
)
96 struct bcm47xx_wdt wdt
= {};
97 struct platform_device
*pdev
;
100 wdt
.timer_set
= bcma_chipco_watchdog_timer_set_wdt
;
101 wdt
.timer_set_ms
= bcma_chipco_watchdog_timer_set_ms_wdt
;
103 bcma_chipco_watchdog_get_max_timer(cc
) / cc
->ticks_per_ms
;
105 pdev
= platform_device_register_data(NULL
, "bcm47xx-wdt",
106 cc
->core
->bus
->num
, &wdt
,
109 return PTR_ERR(pdev
);
116 void bcma_core_chipcommon_early_init(struct bcma_drv_cc
*cc
)
118 if (cc
->early_setup_done
)
121 spin_lock_init(&cc
->gpio_lock
);
123 if (cc
->core
->id
.rev
>= 11)
124 cc
->status
= bcma_cc_read32(cc
, BCMA_CC_CHIPSTAT
);
125 cc
->capabilities
= bcma_cc_read32(cc
, BCMA_CC_CAP
);
126 if (cc
->core
->id
.rev
>= 35)
127 cc
->capabilities_ext
= bcma_cc_read32(cc
, BCMA_CC_CAP_EXT
);
129 if (cc
->capabilities
& BCMA_CC_CAP_PMU
)
130 bcma_pmu_early_init(cc
);
132 cc
->early_setup_done
= true;
135 void bcma_core_chipcommon_init(struct bcma_drv_cc
*cc
)
143 bcma_core_chipcommon_early_init(cc
);
145 if (cc
->core
->id
.rev
>= 20) {
146 u32 pullup
= 0, pulldown
= 0;
148 if (cc
->core
->bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM43142
) {
153 bcma_cc_write32(cc
, BCMA_CC_GPIOPULLUP
, pullup
);
154 bcma_cc_write32(cc
, BCMA_CC_GPIOPULLDOWN
, pulldown
);
157 if (cc
->capabilities
& BCMA_CC_CAP_PMU
)
159 if (cc
->capabilities
& BCMA_CC_CAP_PCTL
)
160 bcma_err(cc
->core
->bus
, "Power control not implemented!\n");
162 if (cc
->core
->id
.rev
>= 16) {
163 if (cc
->core
->bus
->sprom
.leddc_on_time
&&
164 cc
->core
->bus
->sprom
.leddc_off_time
) {
165 leddc_on
= cc
->core
->bus
->sprom
.leddc_on_time
;
166 leddc_off
= cc
->core
->bus
->sprom
.leddc_off_time
;
168 bcma_cc_write32(cc
, BCMA_CC_GPIOTIMER
,
169 ((leddc_on
<< BCMA_CC_GPIOTIMER_ONTIME_SHIFT
) |
170 (leddc_off
<< BCMA_CC_GPIOTIMER_OFFTIME_SHIFT
)));
172 cc
->ticks_per_ms
= bcma_chipco_watchdog_ticks_per_ms(cc
);
174 cc
->setup_done
= true;
177 /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
178 u32
bcma_chipco_watchdog_timer_set(struct bcma_drv_cc
*cc
, u32 ticks
)
182 maxt
= bcma_chipco_watchdog_get_max_timer(cc
);
183 if (cc
->capabilities
& BCMA_CC_CAP_PMU
) {
186 else if (ticks
> maxt
)
188 bcma_cc_write32(cc
, BCMA_CC_PMU_WATCHDOG
, ticks
);
190 struct bcma_bus
*bus
= cc
->core
->bus
;
192 if (bus
->chipinfo
.id
!= BCMA_CHIP_ID_BCM4707
&&
193 bus
->chipinfo
.id
!= BCMA_CHIP_ID_BCM53018
)
194 bcma_core_set_clockmode(cc
->core
,
195 ticks
? BCMA_CLKMODE_FAST
: BCMA_CLKMODE_DYNAMIC
);
200 bcma_cc_write32(cc
, BCMA_CC_WATCHDOG
, ticks
);
205 void bcma_chipco_irq_mask(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
207 bcma_cc_write32_masked(cc
, BCMA_CC_IRQMASK
, mask
, value
);
210 u32
bcma_chipco_irq_status(struct bcma_drv_cc
*cc
, u32 mask
)
212 return bcma_cc_read32(cc
, BCMA_CC_IRQSTAT
) & mask
;
215 u32
bcma_chipco_gpio_in(struct bcma_drv_cc
*cc
, u32 mask
)
217 return bcma_cc_read32(cc
, BCMA_CC_GPIOIN
) & mask
;
220 u32
bcma_chipco_gpio_out(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
225 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
226 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOOUT
, mask
, value
);
227 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
231 EXPORT_SYMBOL_GPL(bcma_chipco_gpio_out
);
233 u32
bcma_chipco_gpio_outen(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
238 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
239 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOOUTEN
, mask
, value
);
240 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
244 EXPORT_SYMBOL_GPL(bcma_chipco_gpio_outen
);
247 * If the bit is set to 0, chipcommon controlls this GPIO,
248 * if the bit is set to 1, it is used by some part of the chip and not our code.
250 u32
bcma_chipco_gpio_control(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
255 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
256 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOCTL
, mask
, value
);
257 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
261 EXPORT_SYMBOL_GPL(bcma_chipco_gpio_control
);
263 u32
bcma_chipco_gpio_intmask(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
268 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
269 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOIRQ
, mask
, value
);
270 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
275 u32
bcma_chipco_gpio_polarity(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
280 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
281 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOPOL
, mask
, value
);
282 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
287 u32
bcma_chipco_gpio_pullup(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
292 if (cc
->core
->id
.rev
< 20)
295 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
296 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOPULLUP
, mask
, value
);
297 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
302 u32
bcma_chipco_gpio_pulldown(struct bcma_drv_cc
*cc
, u32 mask
, u32 value
)
307 if (cc
->core
->id
.rev
< 20)
310 spin_lock_irqsave(&cc
->gpio_lock
, flags
);
311 res
= bcma_cc_write32_masked(cc
, BCMA_CC_GPIOPULLDOWN
, mask
, value
);
312 spin_unlock_irqrestore(&cc
->gpio_lock
, flags
);
317 #ifdef CONFIG_BCMA_DRIVER_MIPS
318 void bcma_chipco_serial_init(struct bcma_drv_cc
*cc
)
323 unsigned int ccrev
= cc
->core
->id
.rev
;
324 struct bcma_serial_port
*ports
= cc
->serial_ports
;
326 if (ccrev
>= 11 && ccrev
!= 15) {
327 baud_base
= bcma_chipco_get_alp_clock(cc
);
329 /* Turn off UART clock before switching clocksource. */
330 bcma_cc_write32(cc
, BCMA_CC_CORECTL
,
331 bcma_cc_read32(cc
, BCMA_CC_CORECTL
)
332 & ~BCMA_CC_CORECTL_UARTCLKEN
);
334 /* Set the override bit so we don't divide it */
335 bcma_cc_write32(cc
, BCMA_CC_CORECTL
,
336 bcma_cc_read32(cc
, BCMA_CC_CORECTL
)
337 | BCMA_CC_CORECTL_UARTCLK0
);
339 /* Re-enable the UART clock. */
340 bcma_cc_write32(cc
, BCMA_CC_CORECTL
,
341 bcma_cc_read32(cc
, BCMA_CC_CORECTL
)
342 | BCMA_CC_CORECTL_UARTCLKEN
);
345 bcma_err(cc
->core
->bus
, "serial not supported on this device ccrev: 0x%x\n",
350 irq
= bcma_core_irq(cc
->core
, 0);
352 /* Determine the registers of the UARTs */
353 cc
->nr_serial_ports
= (cc
->capabilities
& BCMA_CC_CAP_NRUART
);
354 for (i
= 0; i
< cc
->nr_serial_ports
; i
++) {
355 ports
[i
].regs
= cc
->core
->io_addr
+ BCMA_CC_UART0_DATA
+
358 ports
[i
].baud_base
= baud_base
;
359 ports
[i
].reg_shift
= 0;
362 #endif /* CONFIG_BCMA_DRIVER_MIPS */