blob: fcc80bb7bee7f9de3192d6309554e1b9642848e5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/kernel/cpu/sh3/probe.c
3 *
4 * CPU Subtype Probing for SH-3.
5 *
6 * Copyright (C) 1999, 2000 Niibe Yutaka
7 * Copyright (C) 2002 Paul Mundt
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13
14#include <linux/init.h>
15#include <asm/processor.h>
16#include <asm/cache.h>
17#include <asm/io.h>
18
Stuart Menefycbaa1182007-11-30 17:06:36 +090019int __uses_jump_to_uncached detect_cpu_and_cache_system(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
21 unsigned long addr0, addr1, data0, data1, data2, data3;
22
Stuart Menefycbaa1182007-11-30 17:06:36 +090023 jump_to_uncached();
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 /*
25 * Check if the entry shadows or not.
26 * When shadowed, it's 128-entry system.
27 * Otherwise, it's 256-entry system.
28 */
29 addr0 = CACHE_OC_ADDRESS_ARRAY + (3 << 12);
30 addr1 = CACHE_OC_ADDRESS_ARRAY + (1 << 12);
31
32 /* First, write back & invalidate */
33 data0 = ctrl_inl(addr0);
34 ctrl_outl(data0&~(SH_CACHE_VALID|SH_CACHE_UPDATED), addr0);
35 data1 = ctrl_inl(addr1);
36 ctrl_outl(data1&~(SH_CACHE_VALID|SH_CACHE_UPDATED), addr1);
37
38 /* Next, check if there's shadow or not */
39 data0 = ctrl_inl(addr0);
40 data0 ^= SH_CACHE_VALID;
41 ctrl_outl(data0, addr0);
42 data1 = ctrl_inl(addr1);
43 data2 = data1 ^ SH_CACHE_VALID;
44 ctrl_outl(data2, addr1);
45 data3 = ctrl_inl(addr0);
46
47 /* Lastly, invaliate them. */
48 ctrl_outl(data0&~SH_CACHE_VALID, addr0);
49 ctrl_outl(data2&~SH_CACHE_VALID, addr1);
50
Stuart Menefycbaa1182007-11-30 17:06:36 +090051 back_to_cached();
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Paul Mundtcb7af212007-09-27 18:18:39 +090053 boot_cpu_data.dcache.ways = 4;
54 boot_cpu_data.dcache.entry_shift = 4;
55 boot_cpu_data.dcache.linesz = L1_CACHE_BYTES;
56 boot_cpu_data.dcache.flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 /*
59 * 7709A/7729 has 16K cache (256-entry), while 7702 has only
60 * 2K(direct) 7702 is not supported (yet)
61 */
62 if (data0 == data1 && data2 == data3) { /* Shadow */
Paul Mundtcb7af212007-09-27 18:18:39 +090063 boot_cpu_data.dcache.way_incr = (1 << 11);
64 boot_cpu_data.dcache.entry_mask = 0x7f0;
65 boot_cpu_data.dcache.sets = 128;
66 boot_cpu_data.type = CPU_SH7708;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Paul Mundtcb7af212007-09-27 18:18:39 +090068 boot_cpu_data.flags |= CPU_HAS_MMU_PAGE_ASSOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 } else { /* 7709A or 7729 */
Paul Mundtcb7af212007-09-27 18:18:39 +090070 boot_cpu_data.dcache.way_incr = (1 << 12);
71 boot_cpu_data.dcache.entry_mask = 0xff0;
72 boot_cpu_data.dcache.sets = 256;
73 boot_cpu_data.type = CPU_SH7729;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Paul Mundte5723e02006-09-27 17:38:11 +090075#if defined(CONFIG_CPU_SUBTYPE_SH7706)
Paul Mundtcb7af212007-09-27 18:18:39 +090076 boot_cpu_data.type = CPU_SH7706;
Paul Mundte5723e02006-09-27 17:38:11 +090077#endif
78#if defined(CONFIG_CPU_SUBTYPE_SH7710)
Paul Mundtcb7af212007-09-27 18:18:39 +090079 boot_cpu_data.type = CPU_SH7710;
Paul Mundte5723e02006-09-27 17:38:11 +090080#endif
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +090081#if defined(CONFIG_CPU_SUBTYPE_SH7712)
Paul Mundtcb7af212007-09-27 18:18:39 +090082 boot_cpu_data.type = CPU_SH7712;
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +090083#endif
Markus Brunner3ea6bc32007-08-20 08:59:33 +090084#if defined(CONFIG_CPU_SUBTYPE_SH7720)
Paul Mundtcb7af212007-09-27 18:18:39 +090085 boot_cpu_data.type = CPU_SH7720;
Markus Brunner3ea6bc32007-08-20 08:59:33 +090086#endif
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +090087#if defined(CONFIG_CPU_SUBTYPE_SH7721)
88 boot_cpu_data.type = CPU_SH7721;
89#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#if defined(CONFIG_CPU_SUBTYPE_SH7705)
Paul Mundtcb7af212007-09-27 18:18:39 +090091 boot_cpu_data.type = CPU_SH7705;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#if defined(CONFIG_SH7705_CACHE_32KB)
Paul Mundtcb7af212007-09-27 18:18:39 +090094 boot_cpu_data.dcache.way_incr = (1 << 13);
95 boot_cpu_data.dcache.entry_mask = 0x1ff0;
96 boot_cpu_data.dcache.sets = 512;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 ctrl_outl(CCR_CACHE_32KB, CCR3);
98#else
99 ctrl_outl(CCR_CACHE_16KB, CCR3);
100#endif
101#endif
102 }
103
104 /*
105 * SH-3 doesn't have separate caches
106 */
Paul Mundtcb7af212007-09-27 18:18:39 +0900107 boot_cpu_data.dcache.flags |= SH_CACHE_COMBINED;
108 boot_cpu_data.icache = boot_cpu_data.dcache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 return 0;
111}