Path: blob/master/arch/powerpc/platforms/ps3/time.c
10818 views
/*1* PS3 time and rtc routines.2*3* Copyright (C) 2006 Sony Computer Entertainment Inc.4* Copyright 2006 Sony Corp.5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; version 2 of the License.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920#include <linux/kernel.h>21#include <linux/platform_device.h>2223#include <asm/firmware.h>24#include <asm/rtc.h>25#include <asm/lv1call.h>26#include <asm/ps3.h>2728#include "platform.h"2930#define dump_tm(_a) _dump_tm(_a, __func__, __LINE__)31static void _dump_tm(const struct rtc_time *tm, const char* func, int line)32{33pr_debug("%s:%d tm_sec %d\n", func, line, tm->tm_sec);34pr_debug("%s:%d tm_min %d\n", func, line, tm->tm_min);35pr_debug("%s:%d tm_hour %d\n", func, line, tm->tm_hour);36pr_debug("%s:%d tm_mday %d\n", func, line, tm->tm_mday);37pr_debug("%s:%d tm_mon %d\n", func, line, tm->tm_mon);38pr_debug("%s:%d tm_year %d\n", func, line, tm->tm_year);39pr_debug("%s:%d tm_wday %d\n", func, line, tm->tm_wday);40}4142#define dump_time(_a) _dump_time(_a, __func__, __LINE__)43static void __maybe_unused _dump_time(int time, const char *func,44int line)45{46struct rtc_time tm;4748to_tm(time, &tm);4950pr_debug("%s:%d time %d\n", func, line, time);51_dump_tm(&tm, func, line);52}5354void __init ps3_calibrate_decr(void)55{56int result;57u64 tmp;5859result = ps3_repository_read_be_tb_freq(0, &tmp);60BUG_ON(result);6162ppc_tb_freq = tmp;63ppc_proc_freq = ppc_tb_freq * 40;64}6566static u64 read_rtc(void)67{68int result;69u64 rtc_val;70u64 tb_val;7172result = lv1_get_rtc(&rtc_val, &tb_val);73BUG_ON(result);7475return rtc_val;76}7778unsigned long __init ps3_get_boot_time(void)79{80return read_rtc() + ps3_os_area_get_rtc_diff();81}8283static int __init ps3_rtc_init(void)84{85struct platform_device *pdev;8687if (!firmware_has_feature(FW_FEATURE_PS3_LV1))88return -ENODEV;8990pdev = platform_device_register_simple("rtc-ps3", -1, NULL, 0);91if (IS_ERR(pdev))92return PTR_ERR(pdev);9394return 0;95}9697module_init(ps3_rtc_init);9899100