hc
2024-08-12 0517ab8c70e05fc5877c0c6dae1a5f42a16dcf88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
/*
 * (C) Copyright 2019 Rockchip Electronics Co., Ltd.
 */
 
#include <common.h>
#include <asm/arch/sdram.h>
#include "io_map.h"
 
#define IO_TYPE_1_1_16        0    /* up1 1:1 mode 16bit */
#define IO_TYPE_1_1_32        1    /* up1 1:1 mode 32bit */
#define IO_TYPE_1_2        2    /* up1 1:2 mode */
#define IO_TYPE_2        3    /* up2 */
 
static u32 io_type;
 
/* len should be 16byte align */
int data_cpu_2_io(void *p, u32 len)
{
   uchar *val = p;
   uchar buf[CPU_2_IO_ALIGN_LEN];
   u32 i, j;
 
   if ((len % sizeof(buf)) || !len)
       return -1;
 
   if (io_type == IO_TYPE_1_2) {
       len /= sizeof(buf);
       for (j = 0; j < len; j++) {
           memset(buf, 0, sizeof(buf));
           for (i = 0; i < sizeof(buf); i++)
               buf[i] = val[(i % 4) * 4 + i / 4 + j * sizeof(buf)];
           memcpy(&val[j * sizeof(buf)], buf, sizeof(buf));
       }
   } else if (io_type == IO_TYPE_1_1_32) {
       len /= 8;
       for (j = 0; j < len; j++) {
           memset(buf, 0, sizeof(buf));
           for (i = 0; i < 8; i++)
               buf[i] = val[(i % 4) * 2 + i / 4 + j * 8];
           memcpy(&val[j * 8], buf, 8);
       }
   }
   /* IO_TYPE_2 and IO_TYPE_1_1_16 do nothing*/
   return 0;
}
 
void data_cpu_2_io_init(void)
{
#if defined(CONFIG_ROCKCHIP_RK3036)
   io_type = IO_TYPE_1_1_16;
#elif defined(CONFIG_ROCKCHIP_RK3228) ||    \
   defined(CONFIG_ROCKCHIP_RV1108) ||    \
   defined(CONFIG_ROCKCHIP_RK3368) ||    \
   defined(CONFIG_ROCKCHIP_RK3366)
   io_type = IO_TYPE_1_2;
#elif defined(CONFIG_ROCKCHIP_RK3128) || \
   defined(CONFIG_ROCKCHIP_RK3288) ||    \
   defined(CONFIG_ROCKCHIP_RK3288)
   u32 bw;
 
   bw = get_ddr_bw();
   if (bw == 2)
       io_type = IO_TYPE_1_1_32;
   else
       io_type = IO_TYPE_1_1_16;
#elif defined(CONFIG_ROCKCHIP_RK3328) || \
   defined(CONFIG_ROCKCHIP_PX30) ||    \
   defined(CONFIG_ROCKCHIP_RK1808)
   io_type = IO_TYPE_2;
#else
   io_type = IO_TYPE_2;
#endif
}