18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci *  This program is free software; you can redistribute  it and/or modify it
58c2ecf20Sopenharmony_ci *  under  the terms of  the GNU General  Public License as published by the
68c2ecf20Sopenharmony_ci *  Free Software Foundation;  either version 2 of the  License, or (at your
78c2ecf20Sopenharmony_ci *  option) any later version.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
108c2ecf20Sopenharmony_ci *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
118c2ecf20Sopenharmony_ci *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
128c2ecf20Sopenharmony_ci *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
138c2ecf20Sopenharmony_ci *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
148c2ecf20Sopenharmony_ci *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
158c2ecf20Sopenharmony_ci *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
168c2ecf20Sopenharmony_ci *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
178c2ecf20Sopenharmony_ci *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
188c2ecf20Sopenharmony_ci *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *  You should have received a copy of the  GNU General Public License along
218c2ecf20Sopenharmony_ci *  with this program; if not, write  to the Free Software Foundation, Inc.,
228c2ecf20Sopenharmony_ci *  675 Mass Ave, Cambridge, MA 02139, USA.
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include <linux/init.h>
268c2ecf20Sopenharmony_ci#include <linux/ssb/ssb.h>
278c2ecf20Sopenharmony_ci#include <asm/time.h>
288c2ecf20Sopenharmony_ci#include <bcm47xx.h>
298c2ecf20Sopenharmony_ci#include <bcm47xx_board.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_civoid __init plat_time_init(void)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	unsigned long hz = 0;
348c2ecf20Sopenharmony_ci	u16 chip_id = 0;
358c2ecf20Sopenharmony_ci	char buf[10];
368c2ecf20Sopenharmony_ci	int len;
378c2ecf20Sopenharmony_ci	enum bcm47xx_board board = bcm47xx_board_get();
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	/*
408c2ecf20Sopenharmony_ci	 * Use deterministic values for initial counter interrupt
418c2ecf20Sopenharmony_ci	 * so that calibrate delay avoids encountering a counter wrap.
428c2ecf20Sopenharmony_ci	 */
438c2ecf20Sopenharmony_ci	write_c0_count(0);
448c2ecf20Sopenharmony_ci	write_c0_compare(0xffff);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	switch (bcm47xx_bus_type) {
478c2ecf20Sopenharmony_ci#ifdef CONFIG_BCM47XX_SSB
488c2ecf20Sopenharmony_ci	case BCM47XX_BUS_TYPE_SSB:
498c2ecf20Sopenharmony_ci		hz = ssb_cpu_clock(&bcm47xx_bus.ssb.mipscore) / 2;
508c2ecf20Sopenharmony_ci		chip_id = bcm47xx_bus.ssb.chip_id;
518c2ecf20Sopenharmony_ci		break;
528c2ecf20Sopenharmony_ci#endif
538c2ecf20Sopenharmony_ci#ifdef CONFIG_BCM47XX_BCMA
548c2ecf20Sopenharmony_ci	case BCM47XX_BUS_TYPE_BCMA:
558c2ecf20Sopenharmony_ci		hz = bcma_cpu_clock(&bcm47xx_bus.bcma.bus.drv_mips) / 2;
568c2ecf20Sopenharmony_ci		chip_id = bcm47xx_bus.bcma.bus.chipinfo.id;
578c2ecf20Sopenharmony_ci		break;
588c2ecf20Sopenharmony_ci#endif
598c2ecf20Sopenharmony_ci	}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	if (chip_id == 0x5354) {
628c2ecf20Sopenharmony_ci		len = bcm47xx_nvram_getenv("clkfreq", buf, sizeof(buf));
638c2ecf20Sopenharmony_ci		if (len >= 0 && !strncmp(buf, "200", 4))
648c2ecf20Sopenharmony_ci			hz = 100000000;
658c2ecf20Sopenharmony_ci	}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	switch (board) {
688c2ecf20Sopenharmony_ci	case BCM47XX_BOARD_ASUS_WL520GC:
698c2ecf20Sopenharmony_ci	case BCM47XX_BOARD_ASUS_WL520GU:
708c2ecf20Sopenharmony_ci		hz = 100000000;
718c2ecf20Sopenharmony_ci		break;
728c2ecf20Sopenharmony_ci	default:
738c2ecf20Sopenharmony_ci		break;
748c2ecf20Sopenharmony_ci	}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	if (!hz)
778c2ecf20Sopenharmony_ci		hz = 100000000;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	/* Set MIPS counter frequency for fixed_rate_gettimeoffset() */
808c2ecf20Sopenharmony_ci	mips_hpt_frequency = hz;
818c2ecf20Sopenharmony_ci}
82