embox

Форк
0
/
omap_gpmc.c 
96 строк · 2.1 Кб
1
/**
2
 * @file
3
 * @brief OMAP3 General Purpose Memory Controller
4
 *
5
 * @date 30.10.13
6
 * @author Alexander Kalmuk
7
 */
8

9
#include <util/log.h>
10

11
#include <errno.h>
12
#include <sys/mman.h>
13

14
#include <drivers/common/memory.h>
15

16
#include <embox/unit.h>
17
#include <hal/reg.h>
18
#ifndef NOMMU
19
#include <mem/vmem.h>
20
#endif
21

22
#include <drivers/omap_gpmc.h>
23
#include <drivers/gpmc.h>
24

25
#define GPMC_MEMORY_START  0x00000000 /*0x1000000*/
26
#define GPMC_MEMORY_END    0x3fffffff
27
#define GPMC_CS_MEMORY_MAX 0x01000000
28

29
#define GPMC_BASE_ADDRESS 0x6E000000
30

31
EMBOX_UNIT_INIT(gpmc_init);
32

33
uint32_t gpmc_reg_read(int offset) {
34
	return REG_LOAD(GPMC_BASE_ADDRESS + offset);
35
}
36

37
void gpmc_reg_write(int offset, uint32_t val) {
38
	REG_STORE(GPMC_BASE_ADDRESS + offset, val);
39
}
40

41
uint32_t gpmc_cs_reg_read(int cs, int offset) {
42
	unsigned long reg_addr;
43
	reg_addr = GPMC_BASE_ADDRESS + offset + (cs * GPMC_CS_SIZE);
44
	return REG_LOAD(reg_addr);
45
}
46

47
void gpmc_cs_reg_write(int cs, int offset, uint32_t val) {
48
	unsigned long reg_addr;
49
	reg_addr = GPMC_BASE_ADDRESS + offset + (cs * GPMC_CS_SIZE);
50
	REG_STORE(reg_addr, val);
51
}
52

53
int gpmc_cs_enabled(int cs) {
54
	uint32_t l;
55
	l = gpmc_cs_reg_read(cs, GPMC_CS_CONFIG7);
56
	return l & GPMC_CONFIG7_CSVALID;
57
}
58

59
static int gpmc_cs_enable_mem(int cs, uint32_t base, uint32_t size) {
60
	uint32_t l;
61
	uint32_t mask;
62

63
	mask = (1 << GPMC_SECTION_SHIFT) - size;
64
	l = gpmc_cs_reg_read(cs, GPMC_CS_CONFIG7);
65
	l &= ~0x3f;
66
	l = (base >> GPMC_CHUNK_SHIFT) & 0x3f;
67
	l &= ~(0x0f << 8);
68
	l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8;
69
	l |= GPMC_CONFIG7_CSVALID;
70
	gpmc_cs_reg_write(cs, GPMC_CS_CONFIG7, l);
71

72
#ifndef NOMMU
73
	/* TODO use mmap instead of vmem_map_region */
74
	vmem_map_region(vmem_current_context(), base, base, size, PROT_WRITE | PROT_READ | PROT_NOCACHE);
75
#endif
76

77
	return 0;
78
}
79

80
int gpmc_cs_init(int cs, uint32_t *base, uint32_t size) {
81
	*base = GPMC_MEMORY_START + GPMC_CS_MEMORY_MAX * cs;
82

83
	return gpmc_cs_enable_mem(cs, *base, size);
84
}
85

86
static int gpmc_init(void) {
87
	uint32_t l;
88

89
	l = gpmc_reg_read(GPMC_REVISION);
90

91
	log_info("GPMC rev (major = %d minor = %d)", GPMC_REVISION_MAJOR(l), GPMC_REVISION_MINOR(l));
92

93
	return 0;
94
}
95

96
PERIPH_MEMORY_DEFINE(omap_gpmc, GPMC_BASE_ADDRESS, 0x200);
97

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.