1*873e65bcSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2f58a9d17SGeoff Levand /* 3f58a9d17SGeoff Levand * PS3 time and rtc routines. 4f58a9d17SGeoff Levand * 5f58a9d17SGeoff Levand * Copyright (C) 2006 Sony Computer Entertainment Inc. 6f58a9d17SGeoff Levand * Copyright 2006 Sony Corp. 7f58a9d17SGeoff Levand */ 8f58a9d17SGeoff Levand 9f58a9d17SGeoff Levand #include <linux/kernel.h> 100b5f037aSGeert Uytterhoeven #include <linux/platform_device.h> 11835ea93eSArnd Bergmann #include <linux/rtc.h> 12f58a9d17SGeoff Levand 137b6a09f3SGeert Uytterhoeven #include <asm/firmware.h> 14f58a9d17SGeoff Levand #include <asm/lv1call.h> 15f58a9d17SGeoff Levand #include <asm/ps3.h> 16f58a9d17SGeoff Levand 17f58a9d17SGeoff Levand #include "platform.h" 18f58a9d17SGeoff Levand ps3_calibrate_decr(void)19f58a9d17SGeoff Levandvoid __init ps3_calibrate_decr(void) 20f58a9d17SGeoff Levand { 21f58a9d17SGeoff Levand int result; 22f58a9d17SGeoff Levand u64 tmp; 23f58a9d17SGeoff Levand 24f58a9d17SGeoff Levand result = ps3_repository_read_be_tb_freq(0, &tmp); 25f58a9d17SGeoff Levand BUG_ON(result); 26f58a9d17SGeoff Levand 27f58a9d17SGeoff Levand ppc_tb_freq = tmp; 28f58a9d17SGeoff Levand ppc_proc_freq = ppc_tb_freq * 40; 29f58a9d17SGeoff Levand } 30f58a9d17SGeoff Levand read_rtc(void)31f58a9d17SGeoff Levandstatic u64 read_rtc(void) 32f58a9d17SGeoff Levand { 33f58a9d17SGeoff Levand int result; 34f58a9d17SGeoff Levand u64 rtc_val; 35f58a9d17SGeoff Levand u64 tb_val; 36f58a9d17SGeoff Levand 37f58a9d17SGeoff Levand result = lv1_get_rtc(&rtc_val, &tb_val); 38f58a9d17SGeoff Levand BUG_ON(result); 39f58a9d17SGeoff Levand 40f58a9d17SGeoff Levand return rtc_val; 41f58a9d17SGeoff Levand } 42f58a9d17SGeoff Levand ps3_get_boot_time(void)435bfd6435SArnd Bergmanntime64_t __init ps3_get_boot_time(void) 44f58a9d17SGeoff Levand { 45d7b98e3dSGeoff Levand return read_rtc() + ps3_os_area_get_rtc_diff(); 46f58a9d17SGeoff Levand } 470b5f037aSGeert Uytterhoeven ps3_rtc_init(void)480b5f037aSGeert Uytterhoevenstatic int __init ps3_rtc_init(void) 490b5f037aSGeert Uytterhoeven { 500b5f037aSGeert Uytterhoeven struct platform_device *pdev; 510b5f037aSGeert Uytterhoeven 527b6a09f3SGeert Uytterhoeven if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) 537b6a09f3SGeert Uytterhoeven return -ENODEV; 547b6a09f3SGeert Uytterhoeven 550b5f037aSGeert Uytterhoeven pdev = platform_device_register_simple("rtc-ps3", -1, NULL, 0); 560b5f037aSGeert Uytterhoeven 578c6ffba0SRusty Russell return PTR_ERR_OR_ZERO(pdev); 580b5f037aSGeert Uytterhoeven } 598f6b9512SPaul Gortmaker device_initcall(ps3_rtc_init); 60