forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/soc/rockchip/sdmmc_vendor_storage.c
....@@ -23,41 +23,16 @@
2323 #include <linux/soc/rockchip/rk_vendor_storage.h>
2424 #include <linux/kthread.h>
2525 #include <linux/delay.h>
26
+#include <misc/rkflash_vendor_storage.h>
27
+#include "../../mmc/host/rk_sdmmc_ops.h"
2628
2729 #define EMMC_IDB_PART_OFFSET 64
2830 #define EMMC_SYS_PART_OFFSET 8064
2931 #define EMMC_BOOT_PART_SIZE 1024
3032 #define EMMC_VENDOR_PART_START (1024 * 7)
31
-#define EMMC_VENDOR_PART_SIZE 128
33
+#define EMMC_VENDOR_PART_SIZE VENDOR_PART_SIZE
3234 #define EMMC_VENDOR_PART_NUM 4
33
-#define EMMC_VENDOR_TAG 0x524B5644
34
-
35
-struct rk_vendor_req {
36
- u32 tag;
37
- u16 id;
38
- u16 len;
39
- u8 data[1024];
40
-};
41
-
42
-struct vendor_item {
43
- u16 id;
44
- u16 offset;
45
- u16 size;
46
- u16 flag;
47
-};
48
-
49
-struct vendor_info {
50
- u32 tag;
51
- u32 version;
52
- u16 next_index;
53
- u16 item_num;
54
- u16 free_offset;
55
- u16 free_size;
56
- struct vendor_item item[126]; /* 126 * 8*/
57
- u8 data[EMMC_VENDOR_PART_SIZE * 512 - 1024 - 8];
58
- u32 hash;
59
- u32 version2;
60
-};
35
+#define EMMC_VENDOR_TAG VENDOR_HEAD_TAG
6136
6237 #ifdef CONFIG_ROCKCHIP_VENDOR_STORAGE_UPDATE_LOADER
6338 #define READ_SECTOR_IO _IOW('r', 0x04, unsigned int)
....@@ -68,24 +43,13 @@
6843 #define GET_LOCK_FLAG_IO _IOW('r', 0x53, unsigned int)
6944 #endif
7045
71
-#define VENDOR_REQ_TAG 0x56524551
72
-#define VENDOR_READ_IO _IOW('v', 0x01, unsigned int)
73
-#define VENDOR_WRITE_IO _IOW('v', 0x02, unsigned int)
74
-
7546 static u8 *g_idb_buffer;
7647 static struct vendor_info *g_vendor;
7748 static DEFINE_MUTEX(vendor_ops_mutex);
78
-extern int rk_emmc_transfer(u8 *buffer, unsigned addr, unsigned blksz,
79
- int write);
8049
8150 static int emmc_vendor_ops(u8 *buffer, u32 addr, u32 n_sec, int write)
8251 {
83
- u32 i, ret = 0;
84
-
85
- for (i = 0; i < n_sec; i++)
86
- ret = rk_emmc_transfer(buffer + i * 512, addr + i, 512, write);
87
-
88
- return ret;
52
+ return rk_emmc_transfer(buffer, addr, n_sec << 9, write);
8953 }
9054
9155 static int emmc_vendor_storage_init(void)
....@@ -241,34 +205,20 @@
241205 #ifdef CONFIG_ROCKCHIP_VENDOR_STORAGE_UPDATE_LOADER
242206 static int id_blk_read_data(u32 index, u32 n_sec, u8 *buf)
243207 {
244
- u32 i;
245
- u32 ret = 0;
246
-
247208 if (index + n_sec >= 1024 * 5)
248209 return 0;
249210 index = index + EMMC_IDB_PART_OFFSET;
250
- for (i = 0; i < n_sec; i++) {
251
- ret = rk_emmc_transfer(buf + i * 512, index + i, 512, 0);
252
- if (ret)
253
- return ret;
254
- }
255
- return ret;
211
+
212
+ return rk_emmc_transfer(buf, index, n_sec << 9, 0);
256213 }
257214
258215 static int id_blk_write_data(u32 index, u32 n_sec, u8 *buf)
259216 {
260
- u32 i;
261
- u32 ret = 0;
262
-
263217 if (index + n_sec >= 1024 * 5)
264218 return 0;
265219 index = index + EMMC_IDB_PART_OFFSET;
266
- for (i = 0; i < n_sec; i++) {
267
- ret = rk_emmc_transfer(buf + i * 512, index + i, 512, 1);
268
- if (ret)
269
- return ret;
270
- }
271
- return ret;
220
+
221
+ return rk_emmc_transfer(buf, index, n_sec << 9, 1);
272222 }
273223
274224 static int emmc_write_idblock(u32 size, u8 *buf, u32 *id_blk_tbl)
....@@ -406,7 +356,7 @@
406356 {
407357 long ret = -1;
408358 int size;
409
- struct rk_vendor_req *v_req;
359
+ struct RK_VENDOR_REQ *v_req;
410360 u32 *page_buf;
411361
412362 page_buf = kmalloc(4096, GFP_KERNEL);
....@@ -415,7 +365,7 @@
415365
416366 mutex_lock(&vendor_ops_mutex);
417367
418
- v_req = (struct rk_vendor_req *)page_buf;
368
+ v_req = (struct RK_VENDOR_REQ *)page_buf;
419369
420370 switch (cmd) {
421371 case VENDOR_READ_IO:
....@@ -574,7 +524,7 @@
574524 return ret;
575525 }
576526
577
-const struct file_operations vendor_storage_fops = {
527
+static const struct file_operations vendor_storage_fops = {
578528 .open = vendor_storage_open,
579529 .compat_ioctl = vendor_storage_ioctl,
580530 .unlocked_ioctl = vendor_storage_ioctl,