blob: b443611cbb33181530ca3ff4aa86f5730c0ba0bd [file] [log] [blame]
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +09001/*
Nobuhiro Iwamatsu9b7fa2f2014-03-28 11:07:39 +09002 * arch/arm/cpu/armv7/rmobile/cpu_info-rcar.c
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +09003 *
Nobuhiro Iwamatsu9b7fa2f2014-03-28 11:07:39 +09004 * Copyright (C) 2013,2014 Renesas Electronics Corporation
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +09005 *
6 * SPDX-License-Identifier: GPL-2.0
7 */
8#include <common.h>
9#include <asm/io.h>
10
Marek Vasute965c892017-05-13 15:57:38 +020011#define PRR_MASK 0x7fff
12#define R8A7796_REV_1_0 0x5200
13#define R8A7796_REV_1_1 0x5210
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +090014
Marek Vasutaff151e2017-11-09 21:49:48 +010015static u32 rmobile_get_prr(void);
16
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +090017u32 rmobile_get_cpu_type(void)
18{
Marek Vasutaff151e2017-11-09 21:49:48 +010019 return (rmobile_get_prr() & 0x00007F00) >> 8;
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +090020}
21
22u32 rmobile_get_cpu_rev_integer(void)
23{
Marek Vasutaff151e2017-11-09 21:49:48 +010024 const u32 prr = rmobile_get_prr();
Marek Vasute965c892017-05-13 15:57:38 +020025
26 if ((prr & PRR_MASK) == R8A7796_REV_1_1)
27 return 1;
28 else
29 return ((prr & 0x000000F0) >> 4) + 1;
Nobuhiro Iwamatsu1d0e9272013-11-21 17:06:45 +090030}
Nobuhiro Iwamatsua028abe2014-03-28 11:15:59 +090031
32u32 rmobile_get_cpu_rev_fraction(void)
33{
Marek Vasutaff151e2017-11-09 21:49:48 +010034 const u32 prr = rmobile_get_prr();
Marek Vasute965c892017-05-13 15:57:38 +020035
36 if ((prr & PRR_MASK) == R8A7796_REV_1_1)
37 return 1;
38 else
39 return prr & 0x0000000F;
Nobuhiro Iwamatsua028abe2014-03-28 11:15:59 +090040}
Marek Vasutaff151e2017-11-09 21:49:48 +010041
42#if !CONFIG_IS_ENABLED(DM) || !CONFIG_IS_ENABLED(SYSCON)
43static u32 rmobile_get_prr(void)
44{
45 /*
46 * On RCar/RMobile Gen2 and older systems, the PRR is always
47 * located at the address below. On newer systems, the PRR
48 * may be located at different address, but that information
49 * is obtained from DT. This code will be removed when all
50 * of the older systems get converted to DM and OF control.
51 */
52 return readl(0xFF000044);
53}
54#else
55
56#include <dm.h>
57#include <syscon.h>
58#include <regmap.h>
59
60struct renesas_prr_priv {
61 fdt_addr_t regs;
62};
63
64enum {
65 PRR_RCAR,
66};
67
68static u32 rmobile_get_prr(void)
69{
70 struct regmap *map;
71
72 map = syscon_get_regmap_by_driver_data(PRR_RCAR);
73 if (!map) {
74 printf("PRR regmap failed!\n");
75 hang();
76 }
77
78 return readl(map->base);
79}
80
81static const struct udevice_id renesas_prr_ids[] = {
82 { .compatible = "renesas,prr", .data = PRR_RCAR },
83 { }
84};
85
86U_BOOT_DRIVER(renesas_prr) = {
87 .name = "renesas_prr",
88 .id = UCLASS_SYSCON,
89 .of_match = renesas_prr_ids,
90 .flags = DM_FLAG_PRE_RELOC,
91};
92#endif