1 // SPDX-License-Identifier: GPL-2.0+
3 * Some functions are derived from:
4 * https://github.com/rockchip-linux/u-boot/blob/next-dev/drivers/rknand/rk_ftl_arm_v7.S
5 * Copyright (c) 2016-2018, Fuzhou Rockchip Electronics Co., Ltd
7 * Driver interface derived from:
8 * /drivers/block/host_dev.c
9 * /drivers/block/host-uclass.c
10 * Copyright 2022 Google LLC
24 #include <dm/device-internal.h>
25 #include <dm/devres.h>
28 #include <dm/uclass-internal.h>
29 #include <linux/mtd/mtd.h>
30 #if !IS_ENABLED(CONFIG_SANDBOX)
31 #include <linux/mtd/rawnand.h>
33 #include <u-boot/crc.h>
35 struct nand_para_info nand_para_tbl[] = {
36 {6, {0x2c, 0x64, 0x44, 0x4b, 0xa9, 0x00}, 4, 1, 16, 256, 2, 2, 2048, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
37 {6, {0x2c, 0x44, 0x44, 0x4b, 0xa9, 0x00}, 4, 1, 16, 256, 2, 2, 1064, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
38 {6, {0x2c, 0x68, 0x04, 0x4a, 0xa9, 0x00}, 4, 1, 8, 256, 2, 2, 2048, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
39 {5, {0x2c, 0x88, 0x04, 0x4b, 0xa9, 0x00}, 4, 1, 16, 256, 2, 2, 2048, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
40 {6, {0x2c, 0xa8, 0x05, 0xcb, 0xa9, 0x00}, 4, 2, 16, 256, 2, 2, 2048, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
41 {6, {0x2c, 0x68, 0x04, 0x46, 0x89, 0x00}, 4, 1, 8, 256, 2, 2, 2048, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
42 {6, {0x2c, 0x48, 0x04, 0x4a, 0xa5, 0x00}, 4, 1, 8, 256, 2, 2, 1024, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
43 {6, {0x2c, 0x84, 0x64, 0x3c, 0xa5, 0x00}, 4, 1, 32, 512, 2, 2, 1024, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
44 {5, {0x2c, 0x84, 0x64, 0x54, 0xa9, 0x00}, 4, 1, 32, 512, 2, 2, 1024, 0x01df, 4, 18, 60, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
45 {6, {0x2c, 0xd7, 0x94, 0x3e, 0x84, 0x00}, 4, 1, 8, 128, 2, 2, 4096, 0x0117, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
46 {6, {0x2c, 0x48, 0x04, 0x46, 0x85, 0x00}, 4, 1, 8, 256, 2, 2, 1024, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
47 {6, {0x2c, 0x88, 0x05, 0xc6, 0x89, 0x00}, 4, 2, 8, 256, 2, 2, 2048, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
48 {5, {0x2c, 0x88, 0x24, 0x4b, 0xa9, 0x00}, 4, 1, 16, 256, 2, 2, 2048, 0x011f, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
49 {6, {0x2c, 0x68, 0x00, 0x27, 0xa9, 0x00}, 4, 1, 16, 128, 1, 2, 2048, 0x011f, 0, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
50 {5, {0x2c, 0x64, 0x64, 0x56, 0xa5, 0x00}, 4, 1, 24, 512, 2, 2, 700, 0x01df, 4, 18, 60, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
51 {6, {0x2c, 0x84, 0xc5, 0x4b, 0xa9, 0x00}, 4, 2, 16, 256, 2, 2, 2048, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
52 {6, {0x2c, 0xd5, 0xd1, 0xa6, 0x68, 0x00}, 4, 2, 8, 64, 1, 2, 2048, 0x0117, 0, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
53 {6, {0x2c, 0xdc, 0x90, 0xa6, 0x54, 0x00}, 4, 1, 8, 64, 1, 2, 1024, 0x0117, 0, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
54 {5, {0x2c, 0x64, 0x64, 0x54, 0xa4, 0x00}, 4, 1, 32, 512, 2, 1, 1024, 0x01df, 4, 18, 60, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
55 {5, {0x2c, 0x84, 0x44, 0x32, 0xaa, 0x00}, 4, 1, 32, 512, 2, 1, 2184, 0x05c7, 5, 19, 60, 32, 1, 0, 1, 0, 1, {0, 0, 0, 0, 0}},
56 {5, {0x2c, 0x64, 0x44, 0x32, 0xa5, 0x00}, 4, 1, 32, 512, 2, 1, 1048, 0x05c7, 5, 19, 60, 32, 1, 0, 1, 0, 1, {0, 0, 0, 0, 0}},
57 {5, {0x2c, 0x64, 0x64, 0x3c, 0xa5, 0x00}, 4, 1, 32, 512, 2, 1, 1044, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
58 {5, {0x2c, 0x84, 0x44, 0x32, 0xaa, 0x00}, 4, 1, 32, 512, 2, 1, 2184, 0x05c7, 5, 19, 60, 32, 1, 0, 4, 0, 1, {0, 0, 0, 0, 0}},
59 {5, {0x2c, 0x84, 0x44, 0x34, 0xaa, 0x00}, 4, 1, 32, 512, 2, 1, 2184, 0x05c7, 5, 19, 60, 32, 1, 0, 4, 0, 1, {0, 0, 0, 0, 0}},
60 {5, {0x2c, 0x84, 0xc4, 0x34, 0xaa, 0x00}, 4, 1, 32, 512, 2, 1, 2184, 0x05c7, 5, 19, 60, 32, 1, 0, 1, 0, 1, {0, 0, 0, 0, 0}},
61 {5, {0x2c, 0x84, 0x44, 0x34, 0xa4, 0x00}, 4, 1, 32, 512, 2, 1, 2184, 0x05c7, 5, 19, 60, 32, 1, 0, 1, 0, 1, {0, 0, 0, 0, 0}},
62 {5, {0x2c, 0x84, 0x64, 0x3c, 0xa9, 0x00}, 4, 1, 32, 512, 2, 2, 1024, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
63 {6, {0x2c, 0xa4, 0x64, 0x32, 0xaa, 0x04}, 4, 1, 32, 1024, 2, 1, 2192, 0x05c7, 10, 19, 60, 32, 1, 0, 4, 0, 1, {0, 0, 0, 0, 0}},
64 {6, {0xad, 0xde, 0x94, 0xd2, 0x04, 0x43}, 2, 1, 16, 256, 2, 2, 2048, 0x01d9, 1, 1, 24, 32, 4, 0, 3, 0, 0, {0, 0, 0, 0, 0}},
65 {6, {0xad, 0xd7, 0x94, 0xda, 0x74, 0xc3}, 2, 1, 16, 256, 2, 2, 1024, 0x01d9, 1, 2, 40, 32, 4, 0, 3, 0, 0, {0, 0, 0, 0, 0}},
66 {6, {0xad, 0xd7, 0x94, 0x91, 0x60, 0x44}, 2, 1, 16, 256, 2, 2, 1046, 0x01d9, 1, 3, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
67 {6, {0xad, 0xde, 0x94, 0xda, 0x74, 0xc4}, 2, 1, 16, 256, 2, 2, 2090, 0x01d9, 1, 4, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
68 {6, {0xad, 0xde, 0x94, 0xeb, 0x74, 0x44}, 2, 1, 32, 256, 2, 2, 1066, 0x01d9, 1, 7, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
69 {6, {0xad, 0xd5, 0x94, 0xda, 0x74, 0xc4}, 2, 1, 16, 256, 2, 2, 530, 0x01d9, 1, 3, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
70 {6, {0xad, 0xd7, 0x94, 0x9a, 0x74, 0x42}, 2, 1, 16, 256, 2, 2, 1024, 0x0119, 1, 0, 24, 32, 4, 0, 3, 0, 0, {0, 0, 0, 0, 0}},
71 {6, {0xad, 0xde, 0x14, 0xa7, 0x42, 0x4a}, 2, 1, 32, 256, 2, 2, 1060, 0x01d9, 2, 5, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
72 {6, {0xad, 0xd7, 0x14, 0x9e, 0x34, 0x4a}, 2, 1, 16, 256, 2, 2, 1056, 0x01d9, 2, 5, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
73 {6, {0xad, 0xde, 0x94, 0xa7, 0x42, 0x48}, 2, 1, 32, 256, 2, 2, 1060, 0x01d9, 2, 5, 40, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
74 {6, {0xad, 0xde, 0x14, 0xab, 0x42, 0x4a}, 2, 1, 32, 256, 2, 2, 1056, 0x01d9, 2, 6, 40, 32, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
75 {6, {0xad, 0x3a, 0x14, 0xab, 0x42, 0x4a}, 2, 1, 32, 256, 2, 2, 2092, 0x01d9, 2, 5, 40, 32, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
76 {6, {0xad, 0xd5, 0x94, 0x9a, 0x74, 0x42}, 2, 1, 16, 256, 2, 1, 1024, 0x0111, 1, 0, 24, 32, 4, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
77 {6, {0xad, 0x3a, 0x14, 0x03, 0x08, 0x50}, 2, 1, 32, 388, 2, 2, 1362, 0x01d9, 9, 8, 40, 32, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
78 {6, {0x89, 0x64, 0x44, 0x4b, 0xa9, 0x00}, 7, 1, 16, 256, 2, 2, 2048, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
79 {6, {0x89, 0x88, 0x24, 0x4b, 0xa9, 0x84}, 7, 1, 16, 256, 2, 2, 2048, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
80 {6, {0x89, 0x88, 0x24, 0x4b, 0xa9, 0x00}, 7, 1, 16, 256, 2, 2, 2048, 0x0117, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
81 {6, {0x89, 0x68, 0x24, 0x4a, 0xa9, 0x00}, 7, 1, 8, 256, 2, 2, 2048, 0x0117, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
82 {6, {0x89, 0x68, 0x04, 0x4a, 0xa9, 0x00}, 7, 1, 8, 256, 2, 2, 2048, 0x0117, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
83 {6, {0x89, 0xd7, 0x94, 0x3e, 0x84, 0x00}, 7, 1, 8, 256, 2, 2, 2048, 0x0117, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
84 {6, {0x89, 0x68, 0x04, 0x46, 0xa9, 0x00}, 7, 1, 8, 256, 2, 2, 2048, 0x0117, 1, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
85 {5, {0x89, 0x64, 0x64, 0x3c, 0xa1, 0x00}, 7, 1, 32, 512, 2, 1, 1024, 0x01c7, 4, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
86 {5, {0x89, 0x84, 0x64, 0x3c, 0xa5, 0x00}, 7, 1, 32, 512, 2, 2, 1024, 0x01c7, 4, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
87 {6, {0x89, 0x88, 0x24, 0x3b, 0xa9, 0x00}, 7, 1, 16, 192, 2, 2, 2048, 0x0117, 12, 0, 24, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
88 {6, {0x98, 0xd7, 0x84, 0x93, 0x72, 0x57}, 1, 1, 32, 256, 2, 1, 1060, 0x05c1, 2, 33, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
89 {6, {0x98, 0xde, 0x84, 0x93, 0x72, 0x57}, 1, 1, 32, 256, 2, 1, 2092, 0x05c1, 2, 33, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
90 {6, {0x98, 0x3a, 0x85, 0x93, 0x76, 0x57}, 1, 2, 32, 256, 2, 1, 2092, 0x05e1, 2, 33, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
91 {6, {0x98, 0xd5, 0x84, 0x32, 0x72, 0x56}, 1, 1, 16, 128, 2, 1, 2056, 0x05c1, 2, 33, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
92 {6, {0x98, 0xd7, 0x94, 0x32, 0x76, 0x56}, 1, 1, 16, 128, 2, 2, 2058, 0x05d1, 2, 33, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
93 {6, {0x98, 0xde, 0x94, 0x82, 0x76, 0x56}, 1, 1, 16, 256, 2, 2, 2062, 0x05d1, 1, 33, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
94 {6, {0x98, 0xde, 0x94, 0x93, 0x76, 0x50}, 1, 1, 32, 256, 2, 2, 1066, 0x05d9, 2, 34, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
95 {6, {0x98, 0x3a, 0x95, 0x93, 0x7a, 0x50}, 1, 2, 32, 256, 2, 2, 1066, 0x05d9, 2, 34, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
96 {6, {0x98, 0xd7, 0x94, 0x32, 0x76, 0x55}, 1, 1, 16, 128, 2, 2, 2050, 0x0191, 2, 0, 24, 32, 1, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
97 {6, {0x98, 0xde, 0x94, 0x93, 0x76, 0x57}, 1, 1, 32, 256, 2, 2, 1058, 0x05d9, 2, 33, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
98 {6, {0x98, 0xd7, 0x84, 0x93, 0x72, 0x50}, 1, 1, 32, 256, 2, 1, 1060, 0x05c1, 2, 34, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
99 {6, {0x98, 0xde, 0x94, 0x93, 0x76, 0x51}, 1, 1, 32, 256, 2, 2, 1074, 0x05d9, 2, 35, 40, 32, 3, 1, 4, 0, 0, {0, 0, 0, 0, 0}},
100 {6, {0x98, 0x3a, 0x94, 0x93, 0x76, 0x51}, 1, 1, 32, 256, 2, 2, 2106, 0x05d9, 2, 35, 40, 32, 3, 1, 4, 0, 0, {0, 0, 0, 0, 0}},
101 {6, {0x98, 0xd7, 0x84, 0x93, 0x72, 0x51}, 1, 1, 32, 256, 2, 1, 1056, 0x05d9, 2, 35, 40, 32, 3, 1, 4, 0, 0, {0, 0, 0, 0, 0}},
102 {6, {0x98, 0xde, 0x94, 0x93, 0x76, 0xd1}, 1, 1, 32, 256, 2, 2, 1074, 0x05d9, 2, 35, 40, 32, 3, 1, 4, 0, 0, {0, 0, 0, 0, 0}},
103 {6, {0x45, 0xde, 0x94, 0x93, 0x76, 0x57}, 8, 1, 32, 256, 2, 2, 1058, 0x05d9, 2, 66, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
104 {6, {0x45, 0xd7, 0x84, 0x93, 0x72, 0x57}, 8, 1, 32, 256, 2, 1, 1060, 0x05c1, 2, 66, 40, 32, 2, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
105 {6, {0x45, 0xde, 0xa4, 0x82, 0x76, 0x56}, 8, 1, 16, 256, 2, 2, 2082, 0x01d9, 1, 65, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
106 {6, {0x45, 0xde, 0x94, 0x93, 0x76, 0x50}, 8, 1, 32, 256, 2, 2, 1066, 0x05d9, 2, 67, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
107 {6, {0x45, 0xd7, 0x84, 0x93, 0x72, 0x50}, 8, 1, 32, 256, 2, 1, 1060, 0x05c1, 2, 67, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
108 {6, {0x45, 0xde, 0xa4, 0x82, 0x76, 0xd7}, 8, 1, 16, 256, 2, 2, 2090, 0x04d9, 1, 66, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
109 {6, {0x45, 0xde, 0x84, 0x93, 0x72, 0x57}, 8, 1, 32, 256, 2, 1, 2092, 0x05c1, 2, 66, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
110 {6, {0x45, 0x3a, 0x94, 0x93, 0x76, 0x51}, 8, 1, 32, 256, 2, 2, 2106, 0x01d9, 2, 68, 40, 32, 3, 1, 4, 0, 0, {0, 0, 0, 0, 0}},
111 {6, {0x45, 0xde, 0x94, 0x93, 0x76, 0x51}, 8, 1, 32, 256, 2, 2, 1074, 0x01d9, 2, 68, 40, 32, 3, 1, 4, 0, 0, {0, 0, 0, 0, 0}},
112 {6, {0x45, 0x3a, 0xa4, 0x93, 0x7a, 0x50}, 8, 1, 32, 256, 2, 2, 2138, 0x05d9, 2, 0, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
113 {6, {0x45, 0xde, 0x94, 0x82, 0x76, 0x56}, 8, 1, 16, 256, 2, 2, 2062, 0x01d9, 1, 0, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
114 {6, {0x45, 0xde, 0x94, 0x93, 0x76, 0xd7}, 8, 1, 32, 256, 2, 2, 1058, 0x05d9, 2, 66, 40, 32, 3, 1, 1, 0, 0, {0, 0, 0, 0, 0}},
115 {6, {0xec, 0xd7, 0x94, 0x7e, 0x64, 0x44}, 0, 1, 16, 128, 2, 2, 2048, 0x01d9, 2, 49, 60, 36, 3, 0, 3, 0, 0, {0, 0, 0, 0, 0}},
116 {6, {0xec, 0xde, 0xd5, 0x7e, 0x68, 0x44}, 0, 2, 16, 128, 2, 2, 2048, 0x01f9, 2, 49, 60, 36, 3, 0, 3, 0, 0, {0, 0, 0, 0, 0}},
117 {6, {0xec, 0xd7, 0x94, 0x7a, 0x54, 0x43}, 0, 1, 16, 128, 2, 2, 2076, 0x0199, 2, 0, 40, 36, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
118 {6, {0xec, 0xde, 0xd5, 0x7a, 0x58, 0x43}, 0, 2, 16, 128, 2, 2, 2076, 0x01b9, 2, 0, 40, 36, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
119 {6, {0xec, 0xd5, 0x94, 0x76, 0x54, 0x43}, 0, 1, 16, 128, 2, 2, 1038, 0x0119, 2, 0, 24, 36, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
120 {6, {0xec, 0xd7, 0x14, 0x76, 0x54, 0xc2}, 0, 1, 16, 128, 2, 2, 2076, 0x0491, 2, 0, 24, 40, 3, 1, 3, 0, 0, {0, 0, 0, 0, 0}},
121 {6, {0xec, 0xde, 0x94, 0xc3, 0xa4, 0xca}, 0, 1, 32, 792, 2, 1, 688, 0x04c1, 11, 50, 40, 32, 3, 1, 1, 0, 1, {0, 0, 0, 0, 0}},
124 #if !IS_ENABLED(CONFIG_SANDBOX)
125 static int rkmtd_write_oob(struct rkmtd_dev *plat, ulong off, u_char *datbuf, u_char *oobbuf)
127 struct mtd_info *mtd = plat->mtd;
128 struct mtd_oob_ops ops;
132 off &= ~(mtd->writesize - 1);
135 memset(&ops, 0, sizeof(ops));
138 ops.len = mtd->writesize;
139 ops.ooblen = mtd->oobsize;
140 ops.mode = MTD_OPS_PLACE_OOB;
141 ret = mtd_write_oob(mtd, addr, &ops);
143 debug("Error (%d) writing page %08lx\n", ret, off);
150 static int rkmtd_read_oob(struct rkmtd_dev *plat, ulong off, u_char *datbuf, u_char *oobbuf)
152 struct mtd_info *mtd = plat->mtd;
153 struct mtd_oob_ops ops;
157 off &= ~(mtd->writesize - 1);
160 memset(&ops, 0, sizeof(ops));
163 ops.len = mtd->writesize;
164 ops.ooblen = mtd->oobsize;
165 ops.mode = MTD_OPS_PLACE_OOB;
166 ret = mtd_read_oob(mtd, addr, &ops);
168 debug("Error (%d) reading page %08lx\n", ret, off);
175 static int rkmtd_erase(struct rkmtd_dev *plat, ulong off)
177 struct mtd_info *mtd = plat->mtd;
178 struct erase_info info;
182 off &= ~(mtd->writesize - 1);
185 memset(&info, 0, sizeof(info));
188 info.len = mtd->erasesize;
190 ret = mtd_erase(mtd, &info);
192 debug("Error (%d) erasing page %08lx\n", ret, off);
199 void rkmtd_scan_block(struct rkmtd_dev *plat)
201 plat->blk_counter = 0;
203 #if !IS_ENABLED(CONFIG_SANDBOX)
206 for (blk = 0; blk < plat->boot_blks; blk++) {
207 rkmtd_read_oob(plat, blk * plat->mtd->erasesize, plat->datbuf, plat->oobbuf);
208 if (*(u32 *)plat->datbuf == RK_TAG) {
209 struct sector0 *sec0 = (struct sector0 *)plat->datbuf;
211 rkmtd_rc4(plat->datbuf, 512);
213 plat->idblock[plat->blk_counter].blk = blk;
214 plat->idblock[plat->blk_counter].offset = sec0->boot_code1_offset;
215 plat->idblock[plat->blk_counter].boot_size = sec0->flash_boot_size;
217 debug("\nblk : %d\n", plat->idblock[plat->blk_counter].blk);
218 debug("offset : %d\n", plat->idblock[plat->blk_counter].offset);
219 debug("boot_size : %d\n", plat->idblock[plat->blk_counter].boot_size);
221 plat->blk_counter += 1;
223 if (plat->blk_counter >= ARRAY_SIZE(plat->idblock))
230 void rkmtd_read_block(struct rkmtd_dev *plat, u32 idx, u8 *buf)
232 #if !IS_ENABLED(CONFIG_SANDBOX)
233 ulong off = plat->idblock[idx].blk * plat->mtd->erasesize;
234 struct nand_chip *chip = mtd_to_nand(plat->mtd);
235 struct nand_ecc_ctrl *ecc = &chip->ecc;
242 rkmtd_read_oob(plat, off,
243 plat->datbuf, plat->oobbuf);
245 memcpy(buf, plat->datbuf, BLK_SIZE);
247 while (counter < plat->idblock[idx].boot_size) {
249 page = (plat->idblock[idx].offset + spare0) / 4;
251 page = (plat->idblock[idx].offset + counter) / 4;
254 off + page * plat->mtd->writesize,
255 plat->datbuf, plat->oobbuf);
257 sector = plat->idblock[idx].offset + counter;
259 memcpy(&buf[(sector / 4) * BLK_SIZE], plat->datbuf, BLK_SIZE);
261 p_spare = (u32 *)&plat->oobbuf[(ecc->steps - 1) * NFC_SYS_DATA_SIZE];
272 void rkmtd_write_block(struct rkmtd_dev *plat, u32 idx, u8 *buf)
274 #if !IS_ENABLED(CONFIG_SANDBOX)
275 ulong off = plat->idblock[idx].blk * plat->mtd->erasesize;
276 struct nand_chip *chip = mtd_to_nand(plat->mtd);
277 struct nand_ecc_ctrl *ecc = &chip->ecc;
284 rkmtd_erase(plat, off);
286 memset(plat->datbuf, 0xff, plat->mtd->writesize);
287 memcpy(plat->datbuf, buf, BLK_SIZE);
288 memset(plat->oobbuf, 0xff, plat->mtd->oobsize);
290 rkmtd_write_oob(plat, off,
291 plat->datbuf, plat->oobbuf);
293 while (counter < plat->idblock[idx].boot_size) {
294 sector = plat->idblock[idx].offset + counter;
296 memset(plat->datbuf, 0xff, plat->mtd->writesize);
297 memcpy(plat->datbuf, &buf[(sector / 4) * BLK_SIZE], BLK_SIZE);
298 memset(plat->oobbuf, 0xff, plat->mtd->oobsize);
300 p_spare = (u32 *)&plat->oobbuf[(ecc->steps - 1) * NFC_SYS_DATA_SIZE];
302 *p_spare = (plat->page_table[sector / 4 + 1] - 1) * 4;
304 page = plat->page_table[sector / 4];
306 rkmtd_write_oob(plat,
307 off + page * plat->mtd->writesize,
308 plat->datbuf, plat->oobbuf);
313 memset(plat->check, 0, BUF_SIZE);
314 rkmtd_read_block(plat, idx, plat->check);
316 for (j = 0; j < BLK_SIZE; j++) {
318 r = *(plat->check + j);
324 for (j = 0; j < (plat->idblock[idx].boot_size * 512); j++) {
325 w = *(buf + plat->idblock[idx].offset * 512 + j);
326 r = *(plat->check + plat->idblock[idx].offset * 512 + j);
336 debug("write and check error:%x r=%x w=%x\n", j, r, w);
338 plat->idblock[idx].offset = 0;
339 plat->idblock[idx].boot_size = 0;
341 memset(plat->datbuf, 0xff, plat->mtd->writesize);
342 memset(plat->datbuf, 0, BLK_SIZE);
343 memset(plat->oobbuf, 0xff, plat->mtd->oobsize);
345 rkmtd_write_oob(plat, off, plat->datbuf, plat->oobbuf);
349 ulong rkmtd_bread(struct udevice *udev, lbaint_t start,
350 lbaint_t blkcnt, void *dst)
352 struct blk_desc *block_dev = dev_get_uclass_plat(udev);
353 struct udevice *parent_dev = dev_get_parent(udev);
354 struct rkmtd_dev *plat = dev_get_plat(parent_dev);
361 if (start > (block_dev->lba - 1) ||
362 (start + blkcnt) > block_dev->lba)
365 memset(dst, 0, blkcnt * block_dev->blksz);
367 for (i = start; i < (start + blkcnt); i++) {
369 debug("mbr : %d\n", i);
371 memcpy(&buf[(i - start) * block_dev->blksz],
372 plat->mbr, sizeof(legacy_mbr));
374 debug("gpt_h : %d\n", i);
376 memcpy(&buf[(i - start) * block_dev->blksz],
377 plat->gpt_h, sizeof(gpt_header));
378 } else if (i == (block_dev->lba - 1)) {
379 debug("gpt_h2 : %d\n", i);
381 memcpy(&buf[(i - start) * block_dev->blksz],
382 plat->gpt_h2, sizeof(gpt_header));
383 } else if (i == 2 || i == (block_dev->lba - 33)) {
384 debug("gpt_e : %d\n", i);
386 memcpy(&buf[(i - start) * block_dev->blksz],
387 plat->gpt_e, sizeof(gpt_entry));
388 } else if (i >= 64 && i < (block_dev->lba - 33)) {
389 debug("rd : %d\n", i);
391 memcpy(&buf[(i - start) * block_dev->blksz],
392 &plat->idb[(i - 64) * block_dev->blksz], block_dev->blksz);
399 ulong rkmtd_bwrite(struct udevice *udev, lbaint_t start,
400 lbaint_t blkcnt, const void *src)
402 struct blk_desc *block_dev = dev_get_uclass_plat(udev);
403 struct udevice *parent_dev = dev_get_parent(udev);
404 struct rkmtd_dev *plat = dev_get_plat(parent_dev);
405 struct sector0 *sec0;
411 if (start > (block_dev->lba - 1) ||
412 (start + blkcnt) > block_dev->lba)
415 for (i = start; i < (start + blkcnt); i++) {
416 debug("wr : %d\n", i);
418 if (i >= 64 && i < (block_dev->lba - 33)) {
420 debug("first block\n");
422 plat->idb_need_write_back = 1;
423 memset(plat->idb, 0, BUF_SIZE);
426 if (plat->idb_need_write_back) {
427 char *buf = (char *)src;
429 memcpy(&plat->idb[(i - 64) * block_dev->blksz],
430 &buf[(i - start) * block_dev->blksz],
434 memcpy(plat->check, plat->idb, 512);
436 if (*(u32 *)plat->check == RK_TAG) {
437 rkmtd_rc4(plat->check, 512);
439 sec0 = (struct sector0 *)plat->check;
440 plat->offset = sec0->boot_code1_offset;
441 plat->boot_size = sec0->flash_boot_size;
443 if (plat->offset + plat->boot_size > 512) {
444 debug("max size limit\n");
445 plat->idb_need_write_back = 0;
448 debug("no IDB block found\n");
449 plat->idb_need_write_back = 0;
453 if (i == (64 + plat->offset + plat->boot_size - 1)) {
454 debug("last block\n");
456 plat->idb_need_write_back = 0;
458 if (!plat->blk_counter) {
459 plat->idblock[0].blk = 2;
460 plat->idblock[1].blk = 3;
461 plat->idblock[2].blk = 4;
462 plat->idblock[3].blk = 5;
463 plat->idblock[4].blk = 6;
464 plat->blk_counter = 5;
467 for (j = 0; j < plat->blk_counter; j++) {
468 if (plat->idblock[j].blk < plat->boot_blks) {
469 plat->idblock[j].offset = plat->offset;
470 plat->idblock[j].boot_size = plat->boot_size;
471 rkmtd_write_block(plat, j, plat->idb);
475 rkmtd_scan_block(plat);
477 if (!IS_ENABLED(CONFIG_SANDBOX))
478 memset(plat->idb, 0, BUF_SIZE);
480 if (plat->blk_counter)
481 rkmtd_read_block(plat, 0, plat->idb);
484 } else if (plat->idb_need_write_back) {
485 plat->idb_need_write_back = 0;
487 memset(plat->idb, 0, BUF_SIZE);
489 if (plat->blk_counter)
490 rkmtd_read_block(plat, 0, plat->idb);
497 static const struct blk_ops rkmtd_blk_ops = {
499 .write = rkmtd_bwrite,
502 U_BOOT_DRIVER(rkmtd_blk) = {
505 .ops = &rkmtd_blk_ops,
508 void rkmtd_build_page_table(struct rkmtd_dev *plat)
513 switch (plat->lsb_mode) {
519 plat->page_table[counter++] = val;
520 } while (counter != 512);
534 val = 2 * counter - offset;
536 plat->page_table[counter++] = val;
537 } while (counter != 512);
545 val = 2 * counter - 1;
546 plat->page_table[counter++] = val;
547 } while (counter != 512);
561 val = 2 * counter - offset;
563 plat->page_table[counter++] = val;
564 } while (counter != 512);
568 plat->page_table[0] = 0;
569 plat->page_table[1] = 1;
570 plat->page_table[2] = 2;
571 plat->page_table[3] = 3;
572 plat->page_table[4] = 4;
573 plat->page_table[5] = 5;
574 plat->page_table[6] = 7;
575 plat->page_table[7] = 8;
584 val = 2 * counter - offset;
585 plat->page_table[counter++] = val;
586 } while (counter != 512);
594 plat->page_table[counter++] = val;
595 } while (counter != 16);
597 plat->page_table[counter++] = counter2;
598 counter2 = counter2 + 2;
599 } while (counter != 512);
614 val = counter2 - offset;
616 plat->page_table[counter++] = val;
617 counter2 = counter2 + 3;
618 } while (counter != 512);
623 plat->page_table[0] = 0;
624 plat->page_table[1] = 1;
625 plat->page_table[2] = 2;
627 plat->page_table[counter++] = counter2;
628 counter2 = counter2 + 2;
629 } while (counter != 512);
637 plat->page_table[counter++] = val;
638 } while (counter != 63);
640 plat->page_table[counter++] = counter2;
641 counter2 = counter2 + 2;
642 } while (counter != 512);
649 plat->page_table[counter++] = val;
650 } while (counter != 8);
659 val = 2 * counter - offset;
660 plat->page_table[counter++] = val;
661 } while (counter != 512);
665 plat->page_table[0] = 0;
666 plat->page_table[1] = 1;
667 plat->page_table[2] = 2;
668 plat->page_table[3] = 3;
670 u32 val = counter - 1 + (counter >> 1);
672 plat->page_table[counter++] = val;
673 } while (counter != 512);
678 static inline u32 efi_crc32(const void *buf, u32 len)
680 return crc32(0, buf, len);
683 int rkmtd_init_plat(struct udevice *dev)
685 static const efi_guid_t partition_basic_data_guid = PARTITION_BASIC_DATA_GUID;
686 struct rkmtd_dev *plat = dev_get_plat(dev);
687 size_t efiname_len, dosname_len;
688 uchar name[] = "loader1";
692 gen_rand_uuid_str(plat->uuid_disk_str, UUID_STR_FORMAT_GUID);
693 gen_rand_uuid_str(plat->uuid_part_str, UUID_STR_FORMAT_GUID);
695 debug("uuid_part_str : %s\n", plat->uuid_part_str);
696 debug("uuid_disk_str : %s\n", plat->uuid_disk_str);
698 plat->idb = devm_kzalloc(plat->dev, BUF_SIZE, GFP_KERNEL);
702 plat->check = devm_kzalloc(plat->dev, BUF_SIZE, GFP_KERNEL);
706 plat->mbr = devm_kzalloc(plat->dev, sizeof(legacy_mbr), GFP_KERNEL);
710 plat->gpt_e = devm_kzalloc(plat->dev, sizeof(gpt_entry), GFP_KERNEL);
714 plat->gpt_h = devm_kzalloc(plat->dev, sizeof(gpt_header), GFP_KERNEL);
718 plat->gpt_h2 = devm_kzalloc(plat->dev, sizeof(gpt_header), GFP_KERNEL);
723 plat->mbr->signature = MSDOS_MBR_SIGNATURE;
724 plat->mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT;
725 plat->mbr->partition_record[0].start_sect = 1;
726 plat->mbr->partition_record[0].nr_sects = LBA - 1;
729 plat->gpt_e->starting_lba = cpu_to_le64(64);
730 plat->gpt_e->ending_lba = cpu_to_le64(LBA - 34);
732 debug("starting_lba : %llu\n", le64_to_cpu(plat->gpt_e->starting_lba));
733 debug("ending_lba : %llu\n", le64_to_cpu(plat->gpt_e->ending_lba));
735 memcpy(plat->gpt_e->partition_type_guid.b, &partition_basic_data_guid, 16);
737 uuid_str_to_bin(plat->uuid_part_str, plat->gpt_e->unique_partition_guid.b,
738 UUID_STR_FORMAT_GUID);
740 efiname_len = sizeof(plat->gpt_e->partition_name) / sizeof(efi_char16_t);
741 dosname_len = sizeof(name);
743 for (k = 0; k < min(dosname_len, efiname_len); k++)
744 plat->gpt_e->partition_name[k] = (efi_char16_t)(name[k]);
747 plat->gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT);
748 plat->gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1);
749 plat->gpt_h->header_size = cpu_to_le32(sizeof(gpt_header));
750 plat->gpt_h->first_usable_lba = cpu_to_le64(64);
751 plat->gpt_h->last_usable_lba = cpu_to_le64(LBA - 34);
752 plat->gpt_h->num_partition_entries = cpu_to_le32(1);
753 plat->gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry));
755 uuid_str_to_bin(plat->uuid_disk_str, plat->gpt_h->disk_guid.b,
756 UUID_STR_FORMAT_GUID);
758 plat->gpt_h->partition_entry_array_crc32 = 0;
759 calc_crc32 = efi_crc32((const unsigned char *)plat->gpt_e,
760 le32_to_cpu(plat->gpt_h->num_partition_entries) *
761 le32_to_cpu(plat->gpt_h->sizeof_partition_entry));
762 plat->gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32);
764 debug("partition crc32 : 0x%08x\n", calc_crc32);
766 plat->gpt_h->my_lba = cpu_to_le64(1);
767 plat->gpt_h->partition_entry_lba = cpu_to_le64(2);
768 plat->gpt_h->alternate_lba = cpu_to_le64(LBA - 1);
770 plat->gpt_h->header_crc32 = 0;
771 calc_crc32 = efi_crc32((const unsigned char *)plat->gpt_h,
772 le32_to_cpu(plat->gpt_h->header_size));
773 plat->gpt_h->header_crc32 = cpu_to_le32(calc_crc32);
775 debug("header h1 crc32 : 0x%08x\n", calc_crc32);
778 memcpy(plat->gpt_h2, plat->gpt_h, sizeof(gpt_header));
780 plat->gpt_h2->my_lba = cpu_to_le64(LBA - 1);
781 plat->gpt_h2->partition_entry_lba =
782 cpu_to_le64(le64_to_cpu(plat->gpt_h2->last_usable_lba) + 1);
783 plat->gpt_h2->alternate_lba = cpu_to_le64(1);
785 plat->gpt_h2->header_crc32 = 0;
786 calc_crc32 = efi_crc32((const unsigned char *)plat->gpt_h2,
787 le32_to_cpu(plat->gpt_h2->header_size));
788 plat->gpt_h2->header_crc32 = cpu_to_le32(calc_crc32);
790 debug("header h2 crc32 : 0x%08x\n", calc_crc32);
792 part_init(plat->desc);
797 static int rkmtd_bind(struct udevice *dev)
799 struct rkmtd_dev *plat = dev_get_plat(dev);
800 struct blk_desc *desc;
801 struct udevice *bdev;
804 ret = blk_create_devicef(dev, "rkmtd_blk", "blk", UCLASS_RKMTD,
805 -1, 512, LBA, &bdev);
807 return log_msg_ret("blk", ret);
810 desc = dev_get_uclass_plat(bdev);
811 sprintf(desc->vendor, "0x%.4x", 0x2207);
812 memcpy(desc->product, "RKMTD", sizeof("RKMTD"));
813 memcpy(desc->revision, "V1.00", sizeof("V1.00"));
819 static int rkmtd_attach_mtd(struct udevice *dev)
821 struct rkmtd_dev *plat = dev_get_plat(dev);
822 struct mtd_info *mtd;
828 /* Sanity check that rkmtd_bind() has been used */
829 ret = blk_find_from_parent(dev, &blk);
833 #if IS_ENABLED(CONFIG_SANDBOX)
834 plat->mtd = devm_kzalloc(dev, sizeof(struct mtd_info), GFP_KERNEL);
839 mtd->erasesize = 2 ^ 3 * BLK_SIZE;
840 mtd->writesize = BLK_SIZE;
841 mtd->oobsize = BLK_SIZE / STEP_SIZE * NFC_SYS_DATA_SIZE;
845 struct nand_chip *chip;
850 mtd = get_nand_dev_by_index(0);
854 chip = mtd_to_nand(mtd);
856 ret = ofnode_read_u32(chip->flash_node, "rockchip,boot-blks", &tmp);
857 plat->boot_blks = ret ? 0 : tmp;
860 if (chip->select_chip)
861 chip->select_chip(mtd, 0);
863 nand_readid_op(chip, 0, id, 6);
865 if (chip->select_chip)
866 chip->select_chip(mtd, -1);
868 for (i = 0; i < ARRAY_SIZE(nand_para_tbl); i++) {
869 plat->info = (struct nand_para_info *)&nand_para_tbl[i];
870 for (j = 0; j < plat->info->id_bytes; j++) {
871 if (plat->info->nand_id[j] != id[j])
873 if (j == plat->info->id_bytes - 1)
878 debug("no nand_para_info found\n");
881 plat->lsb_mode = plat->info->lsb_mode;
885 for (j = 0; j < plat->info->id_bytes; j++)
891 rkmtd_build_page_table(plat);
893 plat->datbuf = devm_kzalloc(dev, mtd->writesize, GFP_KERNEL);
897 plat->oobbuf = devm_kzalloc(dev, mtd->oobsize, GFP_KERNEL);
901 debug("erasesize %8d\n", mtd->erasesize);
902 debug("writesize %8d\n", mtd->writesize);
903 debug("oobsize %8d\n", mtd->oobsize);
904 debug("boot_blks %8d\n", plat->boot_blks);
905 debug("lsb_mode %8d\n", plat->lsb_mode);
907 ret = rkmtd_init_plat(dev);
909 debug("rkmtd_init_plat failed\n");
913 rkmtd_scan_block(plat);
915 memset(plat->idb, 0, BUF_SIZE);
917 if (plat->blk_counter)
918 rkmtd_read_block(plat, 0, plat->idb);
923 int rkmtd_detach_mtd(struct udevice *dev)
927 ret = device_remove(dev, DM_REMOVE_NORMAL);
929 return log_msg_ret("rem", ret);
931 ret = device_chld_unbind(dev, NULL);
933 return log_msg_ret("unb", ret);
938 struct rkmtd_ops rkmtd_ops = {
939 .attach_mtd = rkmtd_attach_mtd,
940 .detach_mtd = rkmtd_detach_mtd,
943 U_BOOT_DRIVER(rkmtd_drv) = {
948 .plat_auto = sizeof(struct rkmtd_dev),
952 struct udevice *cur_dev;
955 void rkmtd_rc4(u8 *buf, u32 len)
957 u8 S[256], K[256], temp;
959 u8 key[16] = { 124, 78, 3, 4, 85, 5, 9, 7, 45, 44, 123, 56, 23, 13, 23, 17};
962 for (i = 0; i < 256; i++) {
970 for (i = 0; i < 256; i++) {
971 j = (j + S[i] + K[i]) % 256;
979 for (x = 0; x < len; x++) {
981 j = (j + S[i]) % 256;
985 t = (S[i] + (S[j] % 256)) % 256;
986 buf[x] = buf[x] ^ S[t];
990 struct udevice *rkmtd_get_cur_dev(void)
992 struct uclass *uc = uclass_find(UCLASS_RKMTD);
995 struct rkmtd_priv *priv = uclass_get_priv(uc);
997 return priv->cur_dev;
1003 void rkmtd_set_cur_dev(struct udevice *dev)
1005 struct uclass *uc = uclass_find(UCLASS_RKMTD);
1008 struct rkmtd_priv *priv = uclass_get_priv(uc);
1010 priv->cur_dev = dev;
1014 struct udevice *rkmtd_find_by_label(const char *label)
1016 struct udevice *dev;
1019 uclass_id_foreach_dev(UCLASS_RKMTD, dev, uc) {
1020 struct rkmtd_dev *plat = dev_get_plat(dev);
1022 if (plat->label && !strcmp(label, plat->label))
1029 int rkmtd_attach(struct udevice *dev)
1031 struct rkmtd_ops *ops = rkmtd_get_ops(dev);
1033 if (!ops->attach_mtd)
1036 return ops->attach_mtd(dev);
1039 int rkmtd_detach(struct udevice *dev)
1041 struct rkmtd_ops *ops = rkmtd_get_ops(dev);
1043 if (!ops->detach_mtd)
1046 if (dev == rkmtd_get_cur_dev())
1047 rkmtd_set_cur_dev(NULL);
1049 return ops->detach_mtd(dev);
1052 static void rkmtd_drv_kmalloc_release(struct udevice *dev, void *res)
1057 int rkmtd_create_device(const char *label, struct udevice **devp)
1059 char dev_name[30], *str, *label_new;
1060 struct udevice *dev, *blk;
1061 struct rkmtd_dev *plat;
1064 /* unbind any existing device with this label */
1065 dev = rkmtd_find_by_label(label);
1067 ret = rkmtd_detach(dev);
1069 return log_msg_ret("det", ret);
1071 ret = device_unbind(dev);
1073 return log_msg_ret("unb", ret);
1076 snprintf(dev_name, sizeof(dev_name), "rkmtd-%s", label);
1078 str = devres_alloc(rkmtd_drv_kmalloc_release, strlen(dev_name) + 1, GFP_KERNEL);
1082 strcpy(str, dev_name);
1084 ret = device_bind_driver(dm_root(), "rkmtd_drv", str, &dev);
1087 return log_msg_ret("drv", ret);
1090 devres_add(dev, str);
1092 if (!blk_find_from_parent(dev, &blk)) {
1093 struct blk_desc *desc = dev_get_uclass_plat(blk);
1095 desc->removable = true;
1098 label_new = devm_kzalloc(dev, strlen(label) + 1, GFP_KERNEL);
1102 strcpy(label_new, label);
1104 plat = dev_get_plat(dev);
1105 plat->label = label_new;
1111 int rkmtd_create_attach_mtd(const char *label, struct udevice **devp)
1113 struct udevice *dev;
1116 ret = rkmtd_create_device(label, &dev);
1118 return log_msg_ret("cre", ret);
1120 ret = rkmtd_attach(dev);
1123 return log_msg_ret("att", ret);
1130 UCLASS_DRIVER(rkmtd) = {
1133 .post_bind = dm_scan_fdt_dev,
1134 .priv_auto = sizeof(struct rkmtd_priv),