• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * drivers/amlogic/media/common/arch/chips/chips.c
3  *
4  * Copyright (C) 2016 Amlogic, Inc. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  */
17 
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/fs.h>
22 #include <linux/init.h>
23 #include <linux/device.h>
24 #include <linux/vmalloc.h>
25 #include <linux/mm.h>
26 
27 #include <linux/amlogic/media/utils/vformat.h>
28 #include <linux/amlogic/cpu_version.h>
29 #include "../../stream_input/amports/amports_priv.h"
30 #include "../../frame_provider/decoder/utils/vdec.h"
31 #include "chips.h"
32 #include <linux/amlogic/media/utils/log.h>
33 #include <linux/amlogic/media/utils/vdec_reg.h>
34 #include "decoder_cpu_ver_info.h"
35 
36 #define VIDEO_FIRMWARE_FATHER_NAME "video"
37 
38 /*
39  *#define MESON_CPU_MAJOR_ID_M6		0x16
40  *#define MESON_CPU_MAJOR_ID_M6TV		0x17
41  *#define MESON_CPU_MAJOR_ID_M6TVL	0x18
42  *#define MESON_CPU_MAJOR_ID_M8		0x19
43  *#define MESON_CPU_MAJOR_ID_MTVD		0x1A
44  *#define MESON_CPU_MAJOR_ID_M8B		0x1B
45  *#define MESON_CPU_MAJOR_ID_MG9TV	0x1C
46  *#define MESON_CPU_MAJOR_ID_M8M2		0x1D
47  *#define MESON_CPU_MAJOR_ID_GXBB		0x1F
48  *#define MESON_CPU_MAJOR_ID_GXTVBB		0x20
49  *#define MESON_CPU_MAJOR_ID_GXL		0x21
50  *#define MESON_CPU_MAJOR_ID_GXM		0x22
51  *#define MESON_CPU_MAJOR_ID_TXL		0x23
52  */
53 struct type_name {
54 
55 	int type;
56 
57 	const char *name;
58 };
59 static const struct type_name cpu_type_name[] = {
60 	{AM_MESON_CPU_MAJOR_ID_M6, "m6"},
61 	{AM_MESON_CPU_MAJOR_ID_M6TV, "m6tv"},
62 	{AM_MESON_CPU_MAJOR_ID_M6TVL, "m6tvl"},
63 	{AM_MESON_CPU_MAJOR_ID_M8, "m8"},
64 	{AM_MESON_CPU_MAJOR_ID_MTVD, "mtvd"},
65 	{AM_MESON_CPU_MAJOR_ID_M8B, "m8b"},
66 	{AM_MESON_CPU_MAJOR_ID_MG9TV, "mg9tv"},
67 	{AM_MESON_CPU_MAJOR_ID_M8M2, "m8"},
68 	{AM_MESON_CPU_MAJOR_ID_GXBB, "gxbb"},
69 	{AM_MESON_CPU_MAJOR_ID_GXTVBB, "gxtvbb"},
70 	{AM_MESON_CPU_MAJOR_ID_GXL, "gxl"},
71 	{AM_MESON_CPU_MAJOR_ID_GXM, "gxm"},
72 	{AM_MESON_CPU_MAJOR_ID_TXL, "txl"},
73 	{AM_MESON_CPU_MAJOR_ID_TXLX, "txlx"},
74 	{AM_MESON_CPU_MAJOR_ID_GXLX, "gxlx"},
75 	{AM_MESON_CPU_MAJOR_ID_G12A, "g12a"},
76 	{AM_MESON_CPU_MAJOR_ID_G12B, "g12b"},
77 	{AM_MESON_CPU_MAJOR_ID_SM1, "sm1"},
78 	{AM_MESON_CPU_MAJOR_ID_TL1, "tl1"},
79 	{AM_MESON_CPU_MAJOR_ID_TM2, "tm2"},
80 	{0, NULL},
81 };
82 
get_type_name(const struct type_name * typename,int size,int type)83 static const char *get_type_name(const struct type_name *typename, int size,
84 	int type)
85 {
86 
87 	const char *name = "unknown";
88 
89 	int i;
90 
91 	for (i = 0; i < size; i++) {
92 
93 		if (type == typename[i].type)
94 
95 			name = typename[i].name;
96 
97 	}
98 
99 	return name;
100 }
101 
get_cpu_type_name(void)102 const char *get_cpu_type_name(void)
103 {
104 
105 	return get_type_name(cpu_type_name,
106 		sizeof(cpu_type_name) / sizeof(struct type_name),
107 		get_cpu_major_id());
108 }
109 EXPORT_SYMBOL(get_cpu_type_name);
110 
111 /*
112  *enum vformat_e {
113  *	VFORMAT_MPEG12 = 0,
114  *	VFORMAT_MPEG4,
115  *	VFORMAT_H264,
116  *	VFORMAT_MJPEG,
117  *	VFORMAT_REAL,
118  *	VFORMAT_JPEG,
119  *	VFORMAT_VC1,
120  *	VFORMAT_AVS,
121  *	VFORMAT_YUV,
122  *	VFORMAT_H264MVC,
123  *	VFORMAT_H264_4K2K,
124  *	VFORMAT_HEVC,
125  *	VFORMAT_H264_ENC,
126  *	VFORMAT_JPEG_ENC,
127  *	VFORMAT_VP9,
128 *	VFORMAT_AVS2,
129  *	VFORMAT_MAX
130  *};
131  */
132 static const struct type_name vformat_type_name[] = {
133 	{VFORMAT_MPEG12, "mpeg12"},
134 	{VFORMAT_MPEG4, "mpeg4"},
135 	{VFORMAT_H264, "h264"},
136 	{VFORMAT_MJPEG, "mjpeg"},
137 	{VFORMAT_REAL, "real"},
138 	{VFORMAT_JPEG, "jpeg"},
139 	{VFORMAT_VC1, "vc1"},
140 	{VFORMAT_AVS, "avs"},
141 	{VFORMAT_YUV, "yuv"},
142 	{VFORMAT_H264MVC, "h264mvc"},
143 	{VFORMAT_H264_4K2K, "h264_4k"},
144 	{VFORMAT_HEVC, "hevc"},
145 	{VFORMAT_H264_ENC, "h264_enc"},
146 	{VFORMAT_JPEG_ENC, "jpeg_enc"},
147 	{VFORMAT_VP9, "vp9"},
148 	{VFORMAT_AVS2, "avs2"},
149 	{VFORMAT_AV1, "av1"},
150 	{VFORMAT_YUV, "yuv"},
151 	{0, NULL},
152 };
153 
get_video_format_name(enum vformat_e type)154 const char *get_video_format_name(enum vformat_e type)
155 {
156 
157 	return get_type_name(vformat_type_name,
158 		sizeof(vformat_type_name) / sizeof(struct type_name), type);
159 }
160 EXPORT_SYMBOL(get_video_format_name);
161 
162 static struct chip_vdec_info_s current_chip_info;
163 
get_current_vdec_chip(void)164 struct chip_vdec_info_s *get_current_vdec_chip(void)
165 {
166 
167 	return &current_chip_info;
168 }
169 EXPORT_SYMBOL(get_current_vdec_chip);
170 
check_efuse_chip(int vformat)171 bool check_efuse_chip(int vformat)
172 {
173 	unsigned int status, i = 0;
174 	int type[] = {15, 14, 11, 2}; /* avs2, vp9, h265, h264 */
175 
176 	status =  (READ_EFUSE_REG(EFUSE_LIC2) >> 8 & 0xf);
177 	if (!status)
178 		return false;
179 
180 	do {
181 		if ((status & 1) && (type[i] == vformat))
182 			return true;
183 		i++;
184 	} while (status >>= 1);
185 
186 	return false;
187 }
188 EXPORT_SYMBOL(check_efuse_chip);
189 
190