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