Skip to content

Commit 7ffbffe

Browse files
haukelinvjw
authored andcommitted
ssb: add methods for watchdog driver
The watchdog driver wants to set the watchdog timeout in ms and not in ticks, which is depending on the SoC type and the clock. Calculate the number of ticks per millisecond and provide two functions for the watchdog driver. Also return the ticks or millisecond the timer was set to in case the provided value was bigger than the max allowed value. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 2610730 commit 7ffbffe

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎drivers/ssb/driver_chipcommon.c‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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
*/
@@ -12,6 +13,7 @@
1213
#include <linux/ssb/ssb_regs.h>
1314
#include <linux/export.h>
1415
#include <linux/pci.h>
16+
#include <linux/bcm47xx_wdt.h>
1517

1618
#include "ssb_private.h"
1719

@@ -306,6 +308,43 @@ static u32 ssb_chipco_watchdog_get_max_timer(struct ssb_chipcommon *cc)
306308
return (1 << nb) - 1;
307309
}
308310

311+
u32 ssb_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt, u32 ticks)
312+
{
313+
struct ssb_chipcommon *cc = bcm47xx_wdt_get_drvdata(wdt);
314+
315+
if (cc->dev->bus->bustype != SSB_BUSTYPE_SSB)
316+
return 0;
317+
318+
return ssb_chipco_watchdog_timer_set(cc, ticks);
319+
}
320+
321+
u32 ssb_chipco_watchdog_timer_set_ms(struct bcm47xx_wdt *wdt, u32 ms)
322+
{
323+
struct ssb_chipcommon *cc = bcm47xx_wdt_get_drvdata(wdt);
324+
u32 ticks;
325+
326+
if (cc->dev->bus->bustype != SSB_BUSTYPE_SSB)
327+
return 0;
328+
329+
ticks = ssb_chipco_watchdog_timer_set(cc, cc->ticks_per_ms * ms);
330+
return ticks / cc->ticks_per_ms;
331+
}
332+
333+
static int ssb_chipco_watchdog_ticks_per_ms(struct ssb_chipcommon *cc)
334+
{
335+
struct ssb_bus *bus = cc->dev->bus;
336+
337+
if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
338+
/* based on 32KHz ILP clock */
339+
return 32;
340+
} else {
341+
if (cc->dev->id.revision < 18)
342+
return ssb_clockspeed(bus) / 1000;
343+
else
344+
return ssb_chipco_alp_clock(cc) / 1000;
345+
}
346+
}
347+
309348
void ssb_chipcommon_init(struct ssb_chipcommon *cc)
310349
{
311350
if (!cc->dev)
@@ -323,6 +362,11 @@ void ssb_chipcommon_init(struct ssb_chipcommon *cc)
323362
chipco_powercontrol_init(cc);
324363
ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
325364
calc_fast_powerup_delay(cc);
365+
366+
if (cc->dev->bus->bustype == SSB_BUSTYPE_SSB) {
367+
cc->ticks_per_ms = ssb_chipco_watchdog_ticks_per_ms(cc);
368+
cc->max_timer_ms = ssb_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms;
369+
}
326370
}
327371

328372
void ssb_chipco_suspend(struct ssb_chipcommon *cc)
@@ -421,7 +465,7 @@ void ssb_chipco_timing_init(struct ssb_chipcommon *cc,
421465
}
422466

423467
/* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
424-
void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks)
468+
u32 ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks)
425469
{
426470
u32 maxt;
427471
enum ssb_clkmode clkmode;
@@ -441,6 +485,7 @@ void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks)
441485
/* instant NMI */
442486
chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks);
443487
}
488+
return ticks;
444489
}
445490

446491
void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value)

‎drivers/ssb/ssb_private.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/ssb/ssb.h>
55
#include <linux/types.h>
6+
#include <linux/bcm47xx_wdt.h>
67

78

89
#define PFX "ssb: "
@@ -212,4 +213,8 @@ extern u32 ssb_pmu_get_cpu_clock(struct ssb_chipcommon *cc);
212213
extern u32 ssb_pmu_get_controlclock(struct ssb_chipcommon *cc);
213214
extern u32 ssb_pmu_get_alp_clock(struct ssb_chipcommon *cc);
214215

216+
extern u32 ssb_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt,
217+
u32 ticks);
218+
extern u32 ssb_chipco_watchdog_timer_set_ms(struct bcm47xx_wdt *wdt, u32 ms);
219+
215220
#endif /* LINUX_SSB_PRIVATE_H_ */

‎include/linux/ssb/ssb_driver_chipcommon.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ struct ssb_chipcommon {
591591
/* Fast Powerup Delay constant */
592592
u16 fast_pwrup_delay;
593593
struct ssb_chipcommon_pmu pmu;
594+
u32 ticks_per_ms;
595+
u32 max_timer_ms;
594596
};
595597

596598
static inline bool ssb_chipco_available(struct ssb_chipcommon *cc)
@@ -630,8 +632,7 @@ enum ssb_clkmode {
630632
extern void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc,
631633
enum ssb_clkmode mode);
632634

633-
extern void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc,
634-
u32 ticks);
635+
extern u32 ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks);
635636

636637
void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value);
637638

0 commit comments

Comments
 (0)