18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Author: Alexander Shiyan <shc_work@mail.ru>, 2016 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/io.h> 78c2ecf20Sopenharmony_ci#include <linux/of_fdt.h> 88c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 98c2ecf20Sopenharmony_ci#include <linux/random.h> 108c2ecf20Sopenharmony_ci#include <linux/sizes.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/mfd/syscon/clps711x.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <asm/system_info.h> 158c2ecf20Sopenharmony_ci#include <asm/system_misc.h> 168c2ecf20Sopenharmony_ci#include <asm/mach/arch.h> 178c2ecf20Sopenharmony_ci#include <asm/mach/map.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define CLPS711X_VIRT_BASE IOMEM(0xfeff4000) 208c2ecf20Sopenharmony_ci#define CLPS711X_PHYS_BASE (0x80000000) 218c2ecf20Sopenharmony_ci# define SYSFLG1 (0x0140) 228c2ecf20Sopenharmony_ci# define HALT (0x0800) 238c2ecf20Sopenharmony_ci# define UNIQID (0x2440) 248c2ecf20Sopenharmony_ci# define RANDID0 (0x2700) 258c2ecf20Sopenharmony_ci# define RANDID1 (0x2704) 268c2ecf20Sopenharmony_ci# define RANDID2 (0x2708) 278c2ecf20Sopenharmony_ci# define RANDID3 (0x270c) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic struct map_desc clps711x_io_desc __initdata = { 308c2ecf20Sopenharmony_ci .virtual = (unsigned long)CLPS711X_VIRT_BASE, 318c2ecf20Sopenharmony_ci .pfn = __phys_to_pfn(CLPS711X_PHYS_BASE), 328c2ecf20Sopenharmony_ci .length = 48 * SZ_1K, 338c2ecf20Sopenharmony_ci .type = MT_DEVICE, 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic void __init clps711x_map_io(void) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci iotable_init(&clps711x_io_desc, 1); 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic const struct resource clps711x_cpuidle_res = 428c2ecf20Sopenharmony_ci DEFINE_RES_MEM(CLPS711X_PHYS_BASE + HALT, SZ_128); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic void __init clps711x_init(void) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci u32 id[5]; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci id[0] = readl(CLPS711X_VIRT_BASE + UNIQID); 498c2ecf20Sopenharmony_ci id[1] = readl(CLPS711X_VIRT_BASE + RANDID0); 508c2ecf20Sopenharmony_ci id[2] = readl(CLPS711X_VIRT_BASE + RANDID1); 518c2ecf20Sopenharmony_ci id[3] = readl(CLPS711X_VIRT_BASE + RANDID2); 528c2ecf20Sopenharmony_ci id[4] = readl(CLPS711X_VIRT_BASE + RANDID3); 538c2ecf20Sopenharmony_ci system_rev = SYSFLG1_VERID(readl(CLPS711X_VIRT_BASE + SYSFLG1)); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci add_device_randomness(id, sizeof(id)); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci system_serial_low = id[0]; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci platform_device_register_simple("clps711x-cpuidle", PLATFORM_DEVID_NONE, 608c2ecf20Sopenharmony_ci &clps711x_cpuidle_res, 1); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic void clps711x_restart(enum reboot_mode mode, const char *cmd) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci soft_restart(0); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic const char *const clps711x_compat[] __initconst = { 698c2ecf20Sopenharmony_ci "cirrus,ep7209", 708c2ecf20Sopenharmony_ci NULL 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciDT_MACHINE_START(CLPS711X_DT, "Cirrus Logic CLPS711X (Device Tree Support)") 748c2ecf20Sopenharmony_ci .dt_compat = clps711x_compat, 758c2ecf20Sopenharmony_ci .map_io = clps711x_map_io, 768c2ecf20Sopenharmony_ci .init_late = clps711x_init, 778c2ecf20Sopenharmony_ci .restart = clps711x_restart, 788c2ecf20Sopenharmony_ciMACHINE_END 79