Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 2 | /* |
Nobuhiro Iwamatsu | 091bc06 | 2014-03-28 11:07:39 +0900 | [diff] [blame] | 3 | * arch/arm/cpu/armv7/rmobile/cpu_info-rcar.c |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 4 | * |
Nobuhiro Iwamatsu | 091bc06 | 2014-03-28 11:07:39 +0900 | [diff] [blame] | 5 | * Copyright (C) 2013,2014 Renesas Electronics Corporation |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | |
Marek Vasut | 14cdf95 | 2017-05-13 15:57:38 +0200 | [diff] [blame] | 10 | #define PRR_MASK 0x7fff |
| 11 | #define R8A7796_REV_1_0 0x5200 |
| 12 | #define R8A7796_REV_1_1 0x5210 |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 13 | |
Marek Vasut | ab7899b | 2017-11-09 21:49:48 +0100 | [diff] [blame] | 14 | static u32 rmobile_get_prr(void); |
| 15 | |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 16 | u32 rmobile_get_cpu_type(void) |
| 17 | { |
Marek Vasut | ab7899b | 2017-11-09 21:49:48 +0100 | [diff] [blame] | 18 | return (rmobile_get_prr() & 0x00007F00) >> 8; |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | u32 rmobile_get_cpu_rev_integer(void) |
| 22 | { |
Marek Vasut | ab7899b | 2017-11-09 21:49:48 +0100 | [diff] [blame] | 23 | const u32 prr = rmobile_get_prr(); |
Marek Vasut | 14cdf95 | 2017-05-13 15:57:38 +0200 | [diff] [blame] | 24 | |
| 25 | if ((prr & PRR_MASK) == R8A7796_REV_1_1) |
| 26 | return 1; |
| 27 | else |
| 28 | return ((prr & 0x000000F0) >> 4) + 1; |
Nobuhiro Iwamatsu | c6ccb47 | 2013-11-21 17:06:45 +0900 | [diff] [blame] | 29 | } |
Nobuhiro Iwamatsu | 520d06d | 2014-03-28 11:15:59 +0900 | [diff] [blame] | 30 | |
| 31 | u32 rmobile_get_cpu_rev_fraction(void) |
| 32 | { |
Marek Vasut | ab7899b | 2017-11-09 21:49:48 +0100 | [diff] [blame] | 33 | const u32 prr = rmobile_get_prr(); |
Marek Vasut | 14cdf95 | 2017-05-13 15:57:38 +0200 | [diff] [blame] | 34 | |
| 35 | if ((prr & PRR_MASK) == R8A7796_REV_1_1) |
| 36 | return 1; |
| 37 | else |
| 38 | return prr & 0x0000000F; |
Nobuhiro Iwamatsu | 520d06d | 2014-03-28 11:15:59 +0900 | [diff] [blame] | 39 | } |
Marek Vasut | ab7899b | 2017-11-09 21:49:48 +0100 | [diff] [blame] | 40 | |
| 41 | #if !CONFIG_IS_ENABLED(DM) || !CONFIG_IS_ENABLED(SYSCON) |
| 42 | static 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 | |
| 59 | struct renesas_prr_priv { |
| 60 | fdt_addr_t regs; |
| 61 | }; |
| 62 | |
| 63 | enum { |
| 64 | PRR_RCAR, |
| 65 | }; |
| 66 | |
| 67 | static 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 Yamada | 54c5ecb | 2018-04-19 12:14:01 +0900 | [diff] [blame] | 77 | return readl(map->ranges[0].start); |
Marek Vasut | ab7899b | 2017-11-09 21:49:48 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static const struct udevice_id renesas_prr_ids[] = { |
| 81 | { .compatible = "renesas,prr", .data = PRR_RCAR }, |
| 82 | { } |
| 83 | }; |
| 84 | |
| 85 | U_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 |