44 *
55 * Copyright 2005, Broadcom Corporation
66 * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
7+ * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
78 *
89 * Licensed under the GNU/GPL. See COPYING for details.
910 */
1011
1112#include "bcma_private.h"
13+ #include <linux/bcm47xx_wdt.h>
1214#include <linux/export.h>
15+ #include <linux/platform_device.h>
1316#include <linux/bcma/bcma.h>
1417
1518static inline u32 bcma_cc_write32_masked (struct bcma_drv_cc * cc , u16 offset ,
@@ -22,6 +25,90 @@ static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
2225 return value ;
2326}
2427
28+ static u32 bcma_chipco_alp_clock (struct bcma_drv_cc * cc )
29+ {
30+ if (cc -> capabilities & BCMA_CC_CAP_PMU )
31+ return bcma_pmu_alp_clock (cc );
32+
33+ return 20000000 ;
34+ }
35+
36+ static u32 bcma_chipco_watchdog_get_max_timer (struct bcma_drv_cc * cc )
37+ {
38+ struct bcma_bus * bus = cc -> core -> bus ;
39+ u32 nb ;
40+
41+ if (cc -> capabilities & BCMA_CC_CAP_PMU ) {
42+ if (bus -> chipinfo .id == BCMA_CHIP_ID_BCM4706 )
43+ nb = 32 ;
44+ else if (cc -> core -> id .rev < 26 )
45+ nb = 16 ;
46+ else
47+ nb = (cc -> core -> id .rev >= 37 ) ? 32 : 24 ;
48+ } else {
49+ nb = 28 ;
50+ }
51+ if (nb == 32 )
52+ return 0xffffffff ;
53+ else
54+ return (1 << nb ) - 1 ;
55+ }
56+
57+ static u32 bcma_chipco_watchdog_timer_set_wdt (struct bcm47xx_wdt * wdt ,
58+ u32 ticks )
59+ {
60+ struct bcma_drv_cc * cc = bcm47xx_wdt_get_drvdata (wdt );
61+
62+ return bcma_chipco_watchdog_timer_set (cc , ticks );
63+ }
64+
65+ static u32 bcma_chipco_watchdog_timer_set_ms_wdt (struct bcm47xx_wdt * wdt ,
66+ u32 ms )
67+ {
68+ struct bcma_drv_cc * cc = bcm47xx_wdt_get_drvdata (wdt );
69+ u32 ticks ;
70+
71+ ticks = bcma_chipco_watchdog_timer_set (cc , cc -> ticks_per_ms * ms );
72+ return ticks / cc -> ticks_per_ms ;
73+ }
74+
75+ static int bcma_chipco_watchdog_ticks_per_ms (struct bcma_drv_cc * cc )
76+ {
77+ struct bcma_bus * bus = cc -> core -> bus ;
78+
79+ if (cc -> capabilities & BCMA_CC_CAP_PMU ) {
80+ if (bus -> chipinfo .id == BCMA_CHIP_ID_BCM4706 )
81+ /* 4706 CC and PMU watchdogs are clocked at 1/4 of ALP clock */
82+ return bcma_chipco_alp_clock (cc ) / 4000 ;
83+ else
84+ /* based on 32KHz ILP clock */
85+ return 32 ;
86+ } else {
87+ return bcma_chipco_alp_clock (cc ) / 1000 ;
88+ }
89+ }
90+
91+ int bcma_chipco_watchdog_register (struct bcma_drv_cc * cc )
92+ {
93+ struct bcm47xx_wdt wdt = {};
94+ struct platform_device * pdev ;
95+
96+ wdt .driver_data = cc ;
97+ wdt .timer_set = bcma_chipco_watchdog_timer_set_wdt ;
98+ wdt .timer_set_ms = bcma_chipco_watchdog_timer_set_ms_wdt ;
99+ wdt .max_timer_ms = bcma_chipco_watchdog_get_max_timer (cc ) / cc -> ticks_per_ms ;
100+
101+ pdev = platform_device_register_data (NULL , "bcm47xx-wdt" ,
102+ cc -> core -> bus -> num , & wdt ,
103+ sizeof (wdt ));
104+ if (IS_ERR (pdev ))
105+ return PTR_ERR (pdev );
106+
107+ cc -> watchdog = pdev ;
108+
109+ return 0 ;
110+ }
111+
25112void bcma_core_chipcommon_early_init (struct bcma_drv_cc * cc )
26113{
27114 if (cc -> early_setup_done )
@@ -69,15 +156,33 @@ void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
69156 ((leddc_on << BCMA_CC_GPIOTIMER_ONTIME_SHIFT ) |
70157 (leddc_off << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT )));
71158 }
159+ cc -> ticks_per_ms = bcma_chipco_watchdog_ticks_per_ms (cc );
72160
73161 cc -> setup_done = true;
74162}
75163
76164/* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
77- void bcma_chipco_watchdog_timer_set (struct bcma_drv_cc * cc , u32 ticks )
165+ u32 bcma_chipco_watchdog_timer_set (struct bcma_drv_cc * cc , u32 ticks )
78166{
79- /* instant NMI */
80- bcma_cc_write32 (cc , BCMA_CC_WATCHDOG , ticks );
167+ u32 maxt ;
168+ enum bcma_clkmode clkmode ;
169+
170+ maxt = bcma_chipco_watchdog_get_max_timer (cc );
171+ if (cc -> capabilities & BCMA_CC_CAP_PMU ) {
172+ if (ticks == 1 )
173+ ticks = 2 ;
174+ else if (ticks > maxt )
175+ ticks = maxt ;
176+ bcma_cc_write32 (cc , BCMA_CC_PMU_WATCHDOG , ticks );
177+ } else {
178+ clkmode = ticks ? BCMA_CLKMODE_FAST : BCMA_CLKMODE_DYNAMIC ;
179+ bcma_core_set_clockmode (cc -> core , clkmode );
180+ if (ticks > maxt )
181+ ticks = maxt ;
182+ /* instant NMI */
183+ bcma_cc_write32 (cc , BCMA_CC_WATCHDOG , ticks );
184+ }
185+ return ticks ;
81186}
82187
83188void bcma_chipco_irq_mask (struct bcma_drv_cc * cc , u32 mask , u32 value )
@@ -131,8 +236,7 @@ void bcma_chipco_serial_init(struct bcma_drv_cc *cc)
131236 struct bcma_serial_port * ports = cc -> serial_ports ;
132237
133238 if (ccrev >= 11 && ccrev != 15 ) {
134- /* Fixed ALP clock */
135- baud_base = bcma_pmu_alp_clock (cc );
239+ baud_base = bcma_chipco_alp_clock (cc );
136240 if (ccrev >= 21 ) {
137241 /* Turn off UART clock before switching clocksource. */
138242 bcma_cc_write32 (cc , BCMA_CC_CORECTL ,
0 commit comments