developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 1 | #define _GNU_SOURCE |
| 2 | #include <fcntl.h> |
| 3 | #include <sys/mman.h> |
| 4 | #include <sys/stat.h> |
| 5 | #include <sys/wait.h> |
| 6 | |
| 7 | #include "atenl.h" |
| 8 | |
| 9 | #define EEPROM_PART_SIZE 20480 |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 10 | char *eeprom_file; |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 11 | |
| 12 | static FILE *mtd_open(const char *mtd) |
| 13 | { |
| 14 | char line[128], name[64]; |
| 15 | FILE *fp; |
| 16 | int i; |
| 17 | |
| 18 | fp = fopen("/proc/mtd", "r"); |
| 19 | if (!fp) |
| 20 | return NULL; |
| 21 | |
| 22 | snprintf(name, sizeof(name), "\"%s\"", mtd); |
| 23 | while (fgets(line, sizeof(line), fp)) { |
| 24 | if (!sscanf(line, "mtd%d:", &i) || !strstr(line, name)) |
| 25 | continue; |
| 26 | |
| 27 | snprintf(line, sizeof(line), "/dev/mtd%d", i); |
| 28 | fclose(fp); |
| 29 | return fopen(line, "r"); |
| 30 | } |
| 31 | fclose(fp); |
| 32 | |
| 33 | return NULL; |
| 34 | } |
| 35 | |
| 36 | static int |
| 37 | atenl_flash_create_file(struct atenl *an) |
| 38 | { |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 39 | #define READ_LEN_LIMIT 20000 |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 40 | char buf[1024]; |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 41 | ssize_t len, limit = 0; |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 42 | FILE *f; |
| 43 | int fd, ret; |
| 44 | |
| 45 | f = mtd_open(an->mtd_part); |
| 46 | if (!f) { |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 47 | atenl_err("Failed to open MTD device\n"); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 48 | return -1; |
| 49 | } |
| 50 | |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 51 | fd = open(eeprom_file, O_RDWR | O_CREAT | O_EXCL, 00644); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 52 | if (fd < 0) |
| 53 | goto out; |
| 54 | |
| 55 | while ((len = fread(buf, 1, sizeof(buf), f)) > 0) { |
| 56 | ssize_t w; |
| 57 | |
| 58 | retry: |
| 59 | w = write(fd, buf, len); |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 60 | if (w > 0) { |
| 61 | limit += len; |
| 62 | |
| 63 | if (limit >= READ_LEN_LIMIT) |
| 64 | break; |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 65 | continue; |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 66 | } |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 67 | |
| 68 | if (errno == EINTR) |
| 69 | goto retry; |
| 70 | |
| 71 | perror("write"); |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 72 | unlink(eeprom_file); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 73 | close(fd); |
| 74 | fd = -1; |
| 75 | goto out; |
| 76 | } |
| 77 | |
| 78 | ret = lseek(fd, 0, SEEK_SET); |
| 79 | if (ret) { |
| 80 | fclose(f); |
| 81 | close(fd); |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | out: |
| 86 | fclose(f); |
| 87 | return fd; |
| 88 | } |
| 89 | |
| 90 | static int |
| 91 | atenl_efuse_create_file(struct atenl *an) |
| 92 | { |
| 93 | char fname[64], buf[1024]; |
| 94 | ssize_t len; |
| 95 | int fd_ori, fd, ret; |
| 96 | |
| 97 | snprintf(fname, sizeof(fname), |
| 98 | "/sys/kernel/debug/ieee80211/phy%d/mt76/eeprom", get_band_val(an, 0, phy_idx)); |
| 99 | fd_ori = open(fname, O_RDONLY); |
| 100 | if (fd_ori < 0) |
| 101 | return -1; |
| 102 | |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 103 | fd = open(eeprom_file, O_RDWR | O_CREAT | O_EXCL, 00644); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 104 | if (fd < 0) |
| 105 | goto out; |
| 106 | |
| 107 | while ((len = read(fd_ori, buf, sizeof(buf))) > 0) { |
| 108 | ssize_t w; |
| 109 | |
| 110 | retry: |
| 111 | w = write(fd, buf, len); |
| 112 | if (w > 0) |
| 113 | continue; |
| 114 | |
| 115 | if (errno == EINTR) |
| 116 | goto retry; |
| 117 | |
| 118 | perror("write"); |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 119 | unlink(eeprom_file); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 120 | close(fd); |
| 121 | fd = -1; |
| 122 | goto out; |
| 123 | } |
| 124 | |
| 125 | ret = lseek(fd, 0, SEEK_SET); |
| 126 | if (ret) { |
| 127 | close(fd_ori); |
| 128 | close(fd); |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | out: |
| 133 | close(fd_ori); |
| 134 | return fd; |
| 135 | } |
| 136 | |
| 137 | static bool |
| 138 | atenl_eeprom_file_exists(void) |
| 139 | { |
| 140 | struct stat st; |
| 141 | |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 142 | return stat(eeprom_file, &st) == 0; |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static int |
| 146 | atenl_eeprom_init_file(struct atenl *an, bool flash_mode) |
| 147 | { |
| 148 | int fd; |
| 149 | |
| 150 | if (!atenl_eeprom_file_exists()) { |
| 151 | if (flash_mode) |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 152 | atenl_dbg("%s: init eeprom with flash mode\n", __func__); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 153 | else |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 154 | atenl_dbg("%s: init eeprom with efuse mode\n", __func__); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 155 | |
| 156 | if (flash_mode) |
| 157 | return atenl_flash_create_file(an); |
| 158 | |
| 159 | return atenl_efuse_create_file(an); |
| 160 | } |
| 161 | |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 162 | fd = open(eeprom_file, O_RDWR); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 163 | if (fd < 0) |
| 164 | perror("open"); |
| 165 | |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 166 | return fd; |
| 167 | } |
| 168 | |
| 169 | static void |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 170 | atenl_eeprom_init_chip_id(struct atenl *an) |
| 171 | { |
| 172 | an->chip_id = *(u16 *)an->eeprom_data; |
| 173 | |
| 174 | if (is_mt7915(an)) { |
| 175 | an->adie_id = 0x7975; |
| 176 | } else if (is_mt7916(an)) { |
| 177 | an->adie_id = 0x7976; |
| 178 | } else if (is_mt7986(an)) { |
| 179 | bool is_7975 = false; |
| 180 | u32 val; |
| 181 | u8 sub_id; |
| 182 | |
| 183 | atenl_reg_read(an, 0x18050000, &val); |
| 184 | |
| 185 | switch (val & 0xf) { |
| 186 | case MT7975_ONE_ADIE_SINGLE_BAND: |
| 187 | is_7975 = true; |
| 188 | /* fallthrough */ |
| 189 | case MT7976_ONE_ADIE_SINGLE_BAND: |
| 190 | sub_id = 0xa; |
| 191 | break; |
| 192 | case MT7976_ONE_ADIE_DBDC: |
| 193 | sub_id = 0x7; |
| 194 | break; |
| 195 | case MT7975_DUAL_ADIE_DBDC: |
| 196 | is_7975 = true; |
| 197 | /* fallthrough */ |
| 198 | case MT7976_DUAL_ADIE_DBDC: |
| 199 | default: |
| 200 | sub_id = 0xf; |
| 201 | break; |
| 202 | } |
| 203 | |
| 204 | an->sub_chip_id = sub_id; |
| 205 | an->adie_id = is_7975 ? 0x7975 : 0x7976; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | static void |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 210 | atenl_eeprom_init_max_size(struct atenl *an) |
| 211 | { |
| 212 | switch (an->chip_id) { |
| 213 | case 0x7915: |
| 214 | an->eeprom_size = 3584; |
| 215 | break; |
| 216 | case 0x7906: |
| 217 | case 0x7916: |
| 218 | case 0x7986: |
| 219 | an->eeprom_size = 4096; |
| 220 | break; |
| 221 | default: |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | static void |
| 227 | atenl_eeprom_init_band_cap(struct atenl *an) |
| 228 | { |
| 229 | u8 *eeprom = an->eeprom_data; |
| 230 | |
| 231 | if (is_mt7915(an)) { |
| 232 | u8 val = eeprom[MT_EE_WIFI_CONF]; |
| 233 | u8 band_sel = FIELD_GET(MT_EE_WIFI_CONF0_BAND_SEL, val); |
| 234 | struct atenl_band *anb = &an->anb[0]; |
| 235 | |
| 236 | /* MT7915A */ |
| 237 | if (band_sel == MT_EE_BAND_SEL_DEFAULT) { |
| 238 | anb->valid = true; |
| 239 | anb->cap = BAND_TYPE_2G_5G; |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | /* MT7915D */ |
| 244 | if (band_sel == MT_EE_BAND_SEL_2GHZ) { |
| 245 | anb->valid = true; |
| 246 | anb->cap = BAND_TYPE_2G; |
| 247 | } |
| 248 | |
| 249 | val = eeprom[MT_EE_WIFI_CONF + 1]; |
| 250 | band_sel = FIELD_GET(MT_EE_WIFI_CONF0_BAND_SEL, val); |
| 251 | anb++; |
| 252 | |
| 253 | if (band_sel == MT_EE_BAND_SEL_5GHZ) { |
| 254 | anb->valid = true; |
| 255 | anb->cap = BAND_TYPE_5G; |
| 256 | } |
| 257 | } else if (is_mt7916(an) || is_mt7986(an)) { |
| 258 | struct atenl_band *anb; |
| 259 | u8 val, band_sel; |
| 260 | int i; |
| 261 | |
| 262 | for (i = 0; i < 2; i++) { |
| 263 | val = eeprom[MT_EE_WIFI_CONF + i]; |
| 264 | band_sel = FIELD_GET(MT_EE_WIFI_CONF0_BAND_SEL, val); |
| 265 | anb = &an->anb[i]; |
| 266 | |
| 267 | anb->valid = true; |
| 268 | switch (band_sel) { |
| 269 | case MT_EE_BAND_SEL_2G: |
| 270 | anb->cap = BAND_TYPE_2G; |
| 271 | break; |
| 272 | case MT_EE_BAND_SEL_5G: |
| 273 | anb->cap = BAND_TYPE_5G; |
| 274 | break; |
| 275 | case MT_EE_BAND_SEL_6G: |
| 276 | anb->cap = BAND_TYPE_6G; |
| 277 | break; |
| 278 | case MT_EE_BAND_SEL_5G_6G: |
| 279 | anb->cap = BAND_TYPE_5G_6G; |
| 280 | break; |
| 281 | default: |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | atenl_eeprom_init_antenna_cap(struct atenl *an) |
| 290 | { |
| 291 | if (is_mt7915(an)) { |
| 292 | if (an->anb[0].cap == BAND_TYPE_2G_5G) |
| 293 | an->anb[0].chainmask = 0xf; |
| 294 | else { |
| 295 | an->anb[0].chainmask = 0x3; |
| 296 | an->anb[1].chainmask = 0xc; |
| 297 | } |
| 298 | } else if (is_mt7916(an)) { |
| 299 | an->anb[0].chainmask = 0x3; |
| 300 | an->anb[1].chainmask = 0x3; |
| 301 | } else if (is_mt7986(an)) { |
| 302 | an->anb[0].chainmask = 0xf; |
| 303 | an->anb[1].chainmask = 0xf; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | int atenl_eeprom_init(struct atenl *an, u8 phy_idx) |
| 308 | { |
| 309 | bool flash_mode; |
| 310 | int eeprom_fd; |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 311 | char buf[30]; |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 312 | |
| 313 | set_band_val(an, 0, phy_idx, phy_idx); |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 314 | snprintf(buf, sizeof(buf), "/tmp/atenl-eeprom-phy%u", phy_idx); |
| 315 | eeprom_file = strdup(buf); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 316 | |
| 317 | atenl_nl_check_mtd(an); |
| 318 | flash_mode = an->mtd_part != NULL; |
| 319 | |
| 320 | eeprom_fd = atenl_eeprom_init_file(an, flash_mode); |
| 321 | if (eeprom_fd < 0) |
| 322 | return -1; |
| 323 | |
| 324 | an->eeprom_data = mmap(NULL, EEPROM_PART_SIZE, PROT_READ | PROT_WRITE, |
| 325 | MAP_SHARED, eeprom_fd, an->mtd_offset); |
| 326 | if (!an->eeprom_data) { |
| 327 | perror("mmap"); |
| 328 | close(eeprom_fd); |
| 329 | return -1; |
| 330 | } |
| 331 | |
| 332 | an->eeprom_fd = eeprom_fd; |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 333 | atenl_eeprom_init_chip_id(an); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 334 | atenl_eeprom_init_max_size(an); |
| 335 | atenl_eeprom_init_band_cap(an); |
| 336 | atenl_eeprom_init_antenna_cap(an); |
| 337 | |
| 338 | if (get_band_val(an, 1, valid)) |
| 339 | set_band_val(an, 1, phy_idx, phy_idx + 1); |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | void atenl_eeprom_close(struct atenl *an) |
| 345 | { |
| 346 | msync(an->eeprom_data, EEPROM_PART_SIZE, MS_SYNC); |
| 347 | munmap(an->eeprom_data, EEPROM_PART_SIZE); |
| 348 | close(an->eeprom_fd); |
| 349 | |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 350 | if (!an->cmd_mode) { |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 351 | if (remove(eeprom_file)) |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 352 | perror("remove"); |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | free(eeprom_file); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | int atenl_eeprom_write_mtd(struct atenl *an) |
| 359 | { |
| 360 | bool flash_mode = an->mtd_part != NULL; |
| 361 | pid_t pid; |
| 362 | |
| 363 | if (!flash_mode) |
| 364 | return 0; |
| 365 | |
| 366 | pid = fork(); |
| 367 | if (pid < 0) { |
| 368 | perror("Fork"); |
| 369 | return EXIT_FAILURE; |
| 370 | } else if (pid == 0) { |
| 371 | char *part = strdup(an->mtd_part); |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 372 | char *cmd[] = {"mtd", "write", eeprom_file, part, NULL}; |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 373 | int ret; |
| 374 | |
| 375 | ret = execvp("mtd", cmd); |
| 376 | if (ret < 0) { |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 377 | atenl_err("%s: exec error\n", __func__); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 378 | exit(0); |
| 379 | } |
| 380 | } else { |
| 381 | wait(&pid); |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 387 | /* Directly read values from driver's eeprom. |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 388 | * It's usally used to get calibrated data from driver. |
| 389 | */ |
| 390 | int atenl_eeprom_read_from_driver(struct atenl *an, u32 offset, int len) |
| 391 | { |
| 392 | u8 *eeprom_data = an->eeprom_data + offset; |
| 393 | char fname[64], buf[1024]; |
| 394 | int fd_ori, ret; |
| 395 | ssize_t rd; |
| 396 | |
| 397 | snprintf(fname, sizeof(fname), |
| 398 | "/sys/kernel/debug/ieee80211/phy%d/mt76/eeprom", |
| 399 | get_band_val(an, 0, phy_idx)); |
| 400 | fd_ori = open(fname, O_RDONLY); |
| 401 | if (fd_ori < 0) |
| 402 | return -1; |
| 403 | |
| 404 | ret = lseek(fd_ori, offset, SEEK_SET); |
| 405 | if (ret < 0) |
| 406 | goto out; |
| 407 | |
| 408 | while ((rd = read(fd_ori, buf, sizeof(buf))) > 0 && len) { |
| 409 | if (len < rd) { |
| 410 | memcpy(eeprom_data, buf, len); |
| 411 | break; |
| 412 | } else { |
| 413 | memcpy(eeprom_data, buf, rd); |
| 414 | eeprom_data += rd; |
| 415 | len -= rd; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | ret = 0; |
| 420 | out: |
| 421 | close(fd_ori); |
| 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | /* Update all eeprom values to driver before writing efuse */ |
| 426 | static void |
| 427 | atenl_eeprom_sync_to_driver(struct atenl *an) |
| 428 | { |
| 429 | int i; |
| 430 | |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 431 | for (i = 0; i < an->eeprom_size; i += 16) |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 432 | atenl_nl_write_eeprom(an, i, &an->eeprom_data[i], 16); |
| 433 | } |
| 434 | |
| 435 | void atenl_eeprom_cmd_handler(struct atenl *an, u8 phy_idx, char *cmd) |
| 436 | { |
| 437 | bool flash_mode; |
| 438 | |
| 439 | an->cmd_mode = true; |
| 440 | |
| 441 | atenl_eeprom_init(an, phy_idx); |
| 442 | flash_mode = an->mtd_part != NULL; |
| 443 | |
| 444 | if (!strncmp(cmd, "sync eeprom all", 15)) { |
| 445 | atenl_eeprom_write_mtd(an); |
| 446 | } else if (!strncmp(cmd, "eeprom", 6)) { |
| 447 | char *s = strchr(cmd, ' '); |
| 448 | |
| 449 | if (!s) { |
developer | f30d447 | 2022-05-30 16:40:23 +0800 | [diff] [blame^] | 450 | atenl_err("eeprom: please type a correct command\n"); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
| 454 | s++; |
| 455 | if (!strncmp(s, "reset", 5)) { |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 456 | unlink(eeprom_file); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 457 | } else if (!strncmp(s, "file", 4)) { |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 458 | atenl_info("%s\n", eeprom_file); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 459 | atenl_info("Flash mode: %d\n", flash_mode); |
| 460 | } else if (!strncmp(s, "set", 3)) { |
| 461 | u32 offset, val; |
| 462 | |
| 463 | s = strchr(s, ' '); |
| 464 | if (!s) |
| 465 | return; |
| 466 | s++; |
| 467 | |
| 468 | if (!sscanf(s, "%x=%x", &offset, &val) || |
| 469 | offset > EEPROM_PART_SIZE) |
| 470 | return; |
| 471 | |
| 472 | an->eeprom_data[offset] = val; |
| 473 | atenl_info("set offset 0x%x to 0x%x\n", offset, val); |
developer | 48fbcb6 | 2022-03-10 14:24:55 +0800 | [diff] [blame] | 474 | } else if (!strncmp(s, "update buffermode", 17)) { |
developer | 2bf395f | 2022-01-26 20:50:22 +0800 | [diff] [blame] | 475 | atenl_eeprom_sync_to_driver(an); |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 476 | atenl_nl_update_buffer_mode(an); |
| 477 | } else if (!strncmp(s, "write", 5)) { |
| 478 | s = strchr(s, ' '); |
| 479 | if (!s) |
| 480 | return; |
| 481 | s++; |
| 482 | |
developer | 48fbcb6 | 2022-03-10 14:24:55 +0800 | [diff] [blame] | 483 | if (!strncmp(s, "flash", 5)) { |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 484 | atenl_eeprom_write_mtd(an); |
developer | 48fbcb6 | 2022-03-10 14:24:55 +0800 | [diff] [blame] | 485 | } else if (!strncmp(s, "to efuse", 8)) { |
| 486 | atenl_eeprom_sync_to_driver(an); |
| 487 | atenl_nl_write_efuse_all(an); |
| 488 | } |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 489 | } else if (!strncmp(s, "read", 4)) { |
| 490 | u32 offset; |
| 491 | |
| 492 | s = strchr(s, ' '); |
| 493 | if (!s) |
| 494 | return; |
| 495 | s++; |
| 496 | |
| 497 | if (!sscanf(s, "%x", &offset) || |
| 498 | offset > EEPROM_PART_SIZE) |
| 499 | return; |
| 500 | |
| 501 | atenl_info("val = 0x%x (%u)\n", an->eeprom_data[offset], |
| 502 | an->eeprom_data[offset]); |
developer | 48fbcb6 | 2022-03-10 14:24:55 +0800 | [diff] [blame] | 503 | } else { |
| 504 | atenl_err("Unknown eeprom command: %s\n", cmd); |
| 505 | } |
developer | 22c7ab6 | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 506 | } else { |
| 507 | atenl_err("Unknown command: %s\n", cmd); |
| 508 | } |
| 509 | } |