blob: ccb7a32ac4386942153a47a0490cbf70a97f547b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +09002/*
Nobuhiro Iwamatsu091bc062014-03-28 11:07:39 +09003 * arch/arm/cpu/armv7/rmobile/cpu_info-rcar.c
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +09004 *
Nobuhiro Iwamatsu091bc062014-03-28 11:07:39 +09005 * Copyright (C) 2013,2014 Renesas Electronics Corporation
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +09006 */
7#include <common.h>
8#include <asm/io.h>
9
Marek Vasut14cdf952017-05-13 15:57:38 +020010#define PRR_MASK 0x7fff
11#define R8A7796_REV_1_0 0x5200
12#define R8A7796_REV_1_1 0x5210
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +090013
Marek Vasutab7899b2017-11-09 21:49:48 +010014static u32 rmobile_get_prr(void);
15
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +090016u32 rmobile_get_cpu_type(void)
17{
Marek Vasutab7899b2017-11-09 21:49:48 +010018 return (rmobile_get_prr() & 0x00007F00) >> 8;
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +090019}
20
21u32 rmobile_get_cpu_rev_integer(void)
22{
Marek Vasutab7899b2017-11-09 21:49:48 +010023 const u32 prr = rmobile_get_prr();
Marek Vasut14cdf952017-05-13 15:57:38 +020024
25 if ((prr & PRR_MASK) == R8A7796_REV_1_1)
26 return 1;
27 else
28 return ((prr & 0x000000F0) >> 4) + 1;
Nobuhiro Iwamatsuc6ccb472013-11-21 17:06:45 +090029}
Nobuhiro Iwamatsu520d06d2014-03-28 11:15:59 +090030
31u32 rmobile_get_cpu_rev_fraction(void)
32{
Marek Vasutab7899b2017-11-09 21:49:48 +010033 const u32 prr = rmobile_get_prr();
Marek Vasut14cdf952017-05-13 15:57:38 +020034
35 if ((prr & PRR_MASK) == R8A7796_REV_1_1)
36 return 1;
37 else
38 return prr & 0x0000000F;
Nobuhiro Iwamatsu520d06d2014-03-28 11:15:59 +090039}
Marek Vasutab7899b2017-11-09 21:49:48 +010040
41#if !CONFIG_IS_ENABLED(DM) || !CONFIG_IS_ENABLED(SYSCON)
42static u32 rmobile_get_prr(void)
43{
44 /*
45 * On RCar/RMobile Gen2 and older systems, the PRR is always
46 * located at the address below. On newer systems, the PRR
47 * may be located at different address, but that information
48 * is obtained from DT. This code will be removed when all
49 * of the older systems get converted to DM and OF control.
50 */
51 return readl(0xFF000044);
52}
53#else
54
55#include <dm.h>
56#include <syscon.h>
57#include <regmap.h>
58
59struct renesas_prr_priv {
60 fdt_addr_t regs;
61};
62
63enum {
64 PRR_RCAR,
65};
66
67static u32 rmobile_get_prr(void)
68{
69 struct regmap *map;
70
71 map = syscon_get_regmap_by_driver_data(PRR_RCAR);
72 if (!map) {
73 printf("PRR regmap failed!\n");
74 hang();
75 }
76
Masahiro Yamada54c5ecb2018-04-19 12:14:01 +090077 return readl(map->ranges[0].start);
Marek Vasutab7899b2017-11-09 21:49:48 +010078}
79
80static const struct udevice_id renesas_prr_ids[] = {
81 { .compatible = "renesas,prr", .data = PRR_RCAR },
82 { }
83};
84
85U_BOOT_DRIVER(renesas_prr) = {
86 .name = "renesas_prr",
87 .id = UCLASS_SYSCON,
88 .of_match = renesas_prr_ids,
89 .flags = DM_FLAG_PRE_RELOC,
90};
91#endif