blob: 132b205220ca6afe2af6faa581932bbaafd7481f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassaa5121f2014-06-02 22:04:48 -06002/*
3 *
4 * Common functions for OMAP4/5 based boards
5 *
6 * (C) Copyright 2010
7 * Texas Instruments, <www.ti.com>
8 *
9 * Author :
10 * Aneesh V <aneesh@ti.com>
11 * Steve Sakoman <steve@sakoman.com>
Simon Glassaa5121f2014-06-02 22:04:48 -060012 */
13
Simon Glass1d91ba72019-11-14 12:57:37 -070014#include <cpu_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060015#include <log.h>
Tom Riniefd9f332024-04-30 07:35:39 -060016#include <linux/string.h>
Simon Glassaa5121f2014-06-02 22:04:48 -060017#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Tom Riniefd9f332024-04-30 07:35:39 -060019#include <asm/u-boot.h>
Simon Glassaa5121f2014-06-02 22:04:48 -060020
21DECLARE_GLOBAL_DATA_PTR;
22
Keerthy711bb0b2016-09-14 10:43:29 +053023/*
24 * Without LPAE short descriptors are used
25 * Set C - Cache Bit3
26 * Set B - Buffer Bit2
27 * The last 2 bits set to 0b10
28 * Do Not set XN bit4
29 * So value is 0xe
30 *
31 * With LPAE cache configuration happens via MAIR0 register
32 * AttrIndx value is 0x3 for picking byte3 for MAIR0 which has 0xFF.
33 * 0xFF maps to Cache writeback with Read and Write Allocate set
34 * The bits[1:0] should have the value 0b01 for the first level
35 * descriptor.
36 * So the value is 0xd
37 */
38
39#ifdef CONFIG_ARMV7_LPAE
40#define ARMV7_DCACHE_POLICY DCACHE_WRITEALLOC
41#else
42#define ARMV7_DCACHE_POLICY DCACHE_WRITEBACK & ~TTB_SECT_XN_MASK
43#endif
44
Simon Glassaa5121f2014-06-02 22:04:48 -060045void enable_caches(void)
46{
Lokesh Vutlacb2accd2018-05-03 20:34:49 +053047
48 /* Enable I cache if not enabled */
49 if (!icache_status())
50 icache_enable();
51
Simon Glassaa5121f2014-06-02 22:04:48 -060052 dcache_enable();
53}
54
55void dram_bank_mmu_setup(int bank)
56{
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090057 struct bd_info *bd = gd->bd;
Simon Glassaa5121f2014-06-02 22:04:48 -060058 int i;
59
Keerthy708bc292016-09-14 10:43:28 +053060 u32 start = bd->bi_dram[bank].start >> MMU_SECTION_SHIFT;
61 u32 size = bd->bi_dram[bank].size >> MMU_SECTION_SHIFT;
Simon Glassaa5121f2014-06-02 22:04:48 -060062 u32 end = start + size;
63
64 debug("%s: bank: %d\n", __func__, bank);
65 for (i = start; i < end; i++)
Keerthy711bb0b2016-09-14 10:43:29 +053066 set_section_dcache(i, ARMV7_DCACHE_POLICY);
Simon Glassaa5121f2014-06-02 22:04:48 -060067}