Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Mar 24-27, 2025, special US time zones
Register
Loading...
v3.15
 
 1/*
 2 * OMAP SRAM detection and management
 3 *
 4 * Copyright (C) 2005 Nokia Corporation
 5 * Written by Tony Lindgren <tony@atomide.com>
 6 *
 7 * This program is free software; you can redistribute it and/or modify
 8 * it under the terms of the GNU General Public License version 2 as
 9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/io.h>
 
16
17#include <asm/fncpy.h>
18#include <asm/tlb.h>
19#include <asm/cacheflush.h>
20
21#include <asm/mach/map.h>
22
23#include "soc.h"
24#include "sram.h"
25
26#define OMAP1_SRAM_PA		0x20000000
27#define SRAM_BOOTLOADER_SZ	0x80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
29/*
30 * The amount of SRAM depends on the core type.
31 * Note that we cannot try to test for SRAM here because writes
32 * to secure SRAM will hang the system. Also the SRAM is not
33 * yet mapped at this point.
 
34 */
35static void __init omap_detect_and_map_sram(void)
36{
37	unsigned long omap_sram_skip = SRAM_BOOTLOADER_SZ;
38	unsigned long omap_sram_start = OMAP1_SRAM_PA;
39	unsigned long omap_sram_size;
40
41	if (cpu_is_omap7xx())
42		omap_sram_size = 0x32000;	/* 200K */
43	else if (cpu_is_omap15xx())
44		omap_sram_size = 0x30000;	/* 192K */
45	else if (cpu_is_omap1610() || cpu_is_omap1611() ||
46			cpu_is_omap1621() || cpu_is_omap1710())
47		omap_sram_size = 0x4000;	/* 16K */
48	else {
49		pr_err("Could not detect SRAM size\n");
50		omap_sram_size = 0x4000;
51	}
52
53	omap_map_sram(omap_sram_start, omap_sram_size,
54		omap_sram_skip, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55}
56
57static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
58
59void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
60{
61	BUG_ON(!_omap_sram_reprogram_clock);
62	/* On 730, bit 13 must always be 1 */
63	if (cpu_is_omap7xx())
64		ckctl |= 0x2000;
65	_omap_sram_reprogram_clock(dpllctl, ckctl);
66}
67
68int __init omap_sram_init(void)
69{
70	omap_detect_and_map_sram();
71	_omap_sram_reprogram_clock =
72			omap_sram_push(omap1_sram_reprogram_clock,
73					omap1_sram_reprogram_clock_sz);
74
75	return 0;
76}
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * OMAP SRAM detection and management
  4 *
  5 * Copyright (C) 2005 Nokia Corporation
  6 * Written by Tony Lindgren <tony@atomide.com>
 
 
 
 
  7 */
  8
  9#include <linux/module.h>
 10#include <linux/kernel.h>
 11#include <linux/init.h>
 12#include <linux/io.h>
 13#include <linux/set_memory.h>
 14
 15#include <asm/fncpy.h>
 16#include <asm/tlb.h>
 17#include <asm/cacheflush.h>
 18
 19#include <asm/mach/map.h>
 20
 21#include "soc.h"
 22#include "sram.h"
 23
 24#define OMAP1_SRAM_PA		0x20000000
 25#define SRAM_BOOTLOADER_SZ	0x80
 26#define ROUND_DOWN(value, boundary)	((value) & (~((boundary) - 1)))
 27
 28static void __iomem *omap_sram_base;
 29static unsigned long omap_sram_start;
 30static unsigned long omap_sram_skip;
 31static unsigned long omap_sram_size;
 32static void __iomem *omap_sram_ceil;
 33
 34/*
 35 * Memory allocator for SRAM: calculates the new ceiling address
 36 * for pushing a function using the fncpy API.
 37 *
 38 * Note that fncpy requires the returned address to be aligned
 39 * to an 8-byte boundary.
 40 */
 41static void *omap_sram_push_address(unsigned long size)
 42{
 43	unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
 44
 45	available = omap_sram_ceil - (omap_sram_base + omap_sram_skip);
 46
 47	if (size > available) {
 48		pr_err("Not enough space in SRAM\n");
 49		return NULL;
 50	}
 51
 52	new_ceil -= size;
 53	new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
 54	omap_sram_ceil = IOMEM(new_ceil);
 55
 56	return (void __force *)omap_sram_ceil;
 57}
 58
 59void *omap_sram_push(void *funcp, unsigned long size)
 60{
 61	void *sram;
 62	unsigned long base;
 63	int pages;
 64	void *dst = NULL;
 65
 66	sram = omap_sram_push_address(size);
 67	if (!sram)
 68		return NULL;
 69
 70	base = (unsigned long)sram & PAGE_MASK;
 71	pages = PAGE_ALIGN(size) / PAGE_SIZE;
 72
 73	set_memory_rw(base, pages);
 74
 75	dst = fncpy(sram, funcp, size);
 76
 77	set_memory_rox(base, pages);
 78
 79	return dst;
 80}
 81
 82/*
 83 * The amount of SRAM depends on the core type.
 84 * Note that we cannot try to test for SRAM here because writes
 85 * to secure SRAM will hang the system. Also the SRAM is not
 86 * yet mapped at this point.
 87 * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
 88 */
 89static void __init omap_detect_and_map_sram(void)
 90{
 91	unsigned long base;
 92	int pages;
 93
 94	omap_sram_skip = SRAM_BOOTLOADER_SZ;
 95	omap_sram_start = OMAP1_SRAM_PA;
 96
 97	if (cpu_is_omap15xx())
 98		omap_sram_size = 0x30000;	/* 192K */
 99	else if (cpu_is_omap1610() || cpu_is_omap1611() ||
100			cpu_is_omap1621() || cpu_is_omap1710())
101		omap_sram_size = 0x4000;	/* 16K */
102	else {
103		pr_err("Could not detect SRAM size\n");
104		omap_sram_size = 0x4000;
105	}
106
107	omap_sram_start = ROUND_DOWN(omap_sram_start, PAGE_SIZE);
108	omap_sram_base = __arm_ioremap_exec(omap_sram_start, omap_sram_size, 1);
109	if (!omap_sram_base) {
110		pr_err("SRAM: Could not map\n");
111		return;
112	}
113
114	omap_sram_ceil = omap_sram_base + omap_sram_size;
115
116	/*
117	 * Looks like we need to preserve some bootloader code at the
118	 * beginning of SRAM for jumping to flash for reboot to work...
119	 */
120	memset_io(omap_sram_base + omap_sram_skip, 0,
121		  omap_sram_size - omap_sram_skip);
122
123	base = (unsigned long)omap_sram_base;
124	pages = PAGE_ALIGN(omap_sram_size) / PAGE_SIZE;
125
126	set_memory_rox(base, pages);
127}
128
129static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
130
131void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
132{
133	BUG_ON(!_omap_sram_reprogram_clock);
 
 
 
134	_omap_sram_reprogram_clock(dpllctl, ckctl);
135}
136
137int __init omap1_sram_init(void)
138{
139	omap_detect_and_map_sram();
140	_omap_sram_reprogram_clock =
141			omap_sram_push(omap1_sram_reprogram_clock,
142					omap1_sram_reprogram_clock_sz);
143
144	return 0;
145}