board: stm32mp1: Update power supply check via USB TYPE-C
[oweals/u-boot.git] / board / st / stm32mp1 / stm32mp1.c
1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2 /*
3  * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4  */
5 #include <common.h>
6 #include <adc.h>
7 #include <config.h>
8 #include <clk.h>
9 #include <dm.h>
10 #include <environment.h>
11 #include <g_dnl.h>
12 #include <generic-phy.h>
13 #include <i2c.h>
14 #include <led.h>
15 #include <misc.h>
16 #include <phy.h>
17 #include <reset.h>
18 #include <syscon.h>
19 #include <usb.h>
20 #include <asm/io.h>
21 #include <asm/gpio.h>
22 #include <asm/arch/stm32.h>
23 #include <asm/arch/sys_proto.h>
24 #include <power/regulator.h>
25 #include <usb/dwc2_udc.h>
26
27 /* SYSCFG registers */
28 #define SYSCFG_BOOTR            0x00
29 #define SYSCFG_PMCSETR          0x04
30 #define SYSCFG_IOCTRLSETR       0x18
31 #define SYSCFG_ICNR             0x1C
32 #define SYSCFG_CMPCR            0x20
33 #define SYSCFG_CMPENSETR        0x24
34 #define SYSCFG_PMCCLRR          0x44
35
36 #define SYSCFG_BOOTR_BOOT_MASK          GENMASK(2, 0)
37 #define SYSCFG_BOOTR_BOOTPD_SHIFT       4
38
39 #define SYSCFG_IOCTRLSETR_HSLVEN_TRACE          BIT(0)
40 #define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI        BIT(1)
41 #define SYSCFG_IOCTRLSETR_HSLVEN_ETH            BIT(2)
42 #define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC          BIT(3)
43 #define SYSCFG_IOCTRLSETR_HSLVEN_SPI            BIT(4)
44
45 #define SYSCFG_CMPCR_SW_CTRL            BIT(1)
46 #define SYSCFG_CMPCR_READY              BIT(8)
47
48 #define SYSCFG_CMPENSETR_MPU_EN         BIT(0)
49
50 #define SYSCFG_PMCSETR_ETH_CLK_SEL      BIT(16)
51 #define SYSCFG_PMCSETR_ETH_REF_CLK_SEL  BIT(17)
52
53 #define SYSCFG_PMCSETR_ETH_SELMII       BIT(20)
54
55 #define SYSCFG_PMCSETR_ETH_SEL_MASK     GENMASK(23, 21)
56 #define SYSCFG_PMCSETR_ETH_SEL_GMII_MII (0 << 21)
57 #define SYSCFG_PMCSETR_ETH_SEL_RGMII    (1 << 21)
58 #define SYSCFG_PMCSETR_ETH_SEL_RMII     (4 << 21)
59
60 /*
61  * Get a global data pointer
62  */
63 DECLARE_GLOBAL_DATA_PTR;
64
65 #define USB_LOW_THRESHOLD_UV            200000
66 #define USB_WARNING_LOW_THRESHOLD_UV    660000
67 #define USB_START_LOW_THRESHOLD_UV      1230000
68 #define USB_START_HIGH_THRESHOLD_UV     2150000
69
70 int checkboard(void)
71 {
72         int ret;
73         char *mode;
74         u32 otp;
75         struct udevice *dev;
76         const char *fdt_compat;
77         int fdt_compat_len;
78
79         if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
80                 mode = "trusted";
81         else
82                 mode = "basic";
83
84         printf("Board: stm32mp1 in %s mode", mode);
85         fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
86                                  &fdt_compat_len);
87         if (fdt_compat && fdt_compat_len)
88                 printf(" (%s)", fdt_compat);
89         puts("\n");
90
91         ret = uclass_get_device_by_driver(UCLASS_MISC,
92                                           DM_GET_DRIVER(stm32mp_bsec),
93                                           &dev);
94
95         if (!ret)
96                 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
97                                 &otp, sizeof(otp));
98         if (!ret && otp) {
99                 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
100                        otp >> 16,
101                        (otp >> 12) & 0xF,
102                        ((otp >> 8) & 0xF) - 1 + 'A',
103                        otp & 0xF);
104         }
105
106         return 0;
107 }
108
109 static void board_key_check(void)
110 {
111 #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
112         ofnode node;
113         struct gpio_desc gpio;
114         enum forced_boot_mode boot_mode = BOOT_NORMAL;
115
116         node = ofnode_path("/config");
117         if (!ofnode_valid(node)) {
118                 debug("%s: no /config node?\n", __func__);
119                 return;
120         }
121 #ifdef CONFIG_FASTBOOT
122         if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
123                                        &gpio, GPIOD_IS_IN)) {
124                 debug("%s: could not find a /config/st,fastboot-gpios\n",
125                       __func__);
126         } else {
127                 if (dm_gpio_get_value(&gpio)) {
128                         puts("Fastboot key pressed, ");
129                         boot_mode = BOOT_FASTBOOT;
130                 }
131
132                 dm_gpio_free(NULL, &gpio);
133         }
134 #endif
135 #ifdef CONFIG_CMD_STM32PROG
136         if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
137                                        &gpio, GPIOD_IS_IN)) {
138                 debug("%s: could not find a /config/st,stm32prog-gpios\n",
139                       __func__);
140         } else {
141                 if (dm_gpio_get_value(&gpio)) {
142                         puts("STM32Programmer key pressed, ");
143                         boot_mode = BOOT_STM32PROG;
144                 }
145                 dm_gpio_free(NULL, &gpio);
146         }
147 #endif
148
149         if (boot_mode != BOOT_NORMAL) {
150                 puts("entering download mode...\n");
151                 clrsetbits_le32(TAMP_BOOT_CONTEXT,
152                                 TAMP_BOOT_FORCED_MASK,
153                                 boot_mode);
154         }
155 #endif
156 }
157
158 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
159
160 /* STMicroelectronics STUSB1600 Type-C controller */
161 #define STUSB1600_CC_CONNECTION_STATUS          0x0E
162
163 /* STUSB1600_CC_CONNECTION_STATUS bitfields */
164 #define STUSB1600_CC_ATTACH                     BIT(0)
165
166 static int stusb1600_init(struct udevice **dev_stusb1600)
167 {
168         ofnode node;
169         struct udevice *dev, *bus;
170         int ret;
171         u32 chip_addr;
172
173         *dev_stusb1600 = NULL;
174
175         /* if node stusb1600 is present, means DK1 or DK2 board */
176         node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
177         if (!ofnode_valid(node))
178                 return -ENODEV;
179
180         ret = ofnode_read_u32(node, "reg", &chip_addr);
181         if (ret)
182                 return -EINVAL;
183
184         ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
185                                           &bus);
186         if (ret) {
187                 printf("bus for stusb1600 not found\n");
188                 return -ENODEV;
189         }
190
191         ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
192         if (!ret)
193                 *dev_stusb1600 = dev;
194
195         return ret;
196 }
197
198 static int stusb1600_cable_connected(struct udevice *dev)
199 {
200         u8 status;
201
202         if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
203                 return 0;
204
205         return status & STUSB1600_CC_ATTACH;
206 }
207
208 #include <usb/dwc2_udc.h>
209 int g_dnl_board_usb_cable_connected(void)
210 {
211         struct udevice *stusb1600;
212         struct udevice *dwc2_udc_otg;
213         int ret;
214
215         if (!stusb1600_init(&stusb1600))
216                 return stusb1600_cable_connected(stusb1600);
217
218         ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
219                                           DM_GET_DRIVER(dwc2_udc_otg),
220                                           &dwc2_udc_otg);
221         if (!ret)
222                 debug("dwc2_udc_otg init failed\n");
223
224         return dwc2_udc_B_session_valid(dwc2_udc_otg);
225 }
226 #endif /* CONFIG_USB_GADGET */
227
228 static int get_led(struct udevice **dev, char *led_string)
229 {
230         char *led_name;
231         int ret;
232
233         led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
234         if (!led_name) {
235                 pr_debug("%s: could not find %s config string\n",
236                          __func__, led_string);
237                 return -ENOENT;
238         }
239         ret = led_get_by_label(led_name, dev);
240         if (ret) {
241                 debug("%s: get=%d\n", __func__, ret);
242                 return ret;
243         }
244
245         return 0;
246 }
247
248 static int setup_led(enum led_state_t cmd)
249 {
250         struct udevice *dev;
251         int ret;
252
253         ret = get_led(&dev, "u-boot,boot-led");
254         if (ret)
255                 return ret;
256
257         ret = led_set_state(dev, cmd);
258         return ret;
259 }
260
261 static int board_check_usb_power(void)
262 {
263         struct ofnode_phandle_args adc_args;
264         struct udevice *adc;
265         struct udevice *led;
266         ofnode node;
267         unsigned int raw;
268         int max_uV = 0;
269         int min_uV = USB_START_HIGH_THRESHOLD_UV;
270         int ret, uV, adc_count;
271         u32 nb_blink;
272         u8 i;
273         node = ofnode_path("/config");
274         if (!ofnode_valid(node)) {
275                 debug("%s: no /config node?\n", __func__);
276                 return -ENOENT;
277         }
278
279         /*
280          * Retrieve the ADC channels devices and get measurement
281          * for each of them
282          */
283         adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
284                                                    "#io-channel-cells");
285         if (adc_count < 0) {
286                 if (adc_count == -ENOENT)
287                         return 0;
288
289                 pr_err("%s: can't find adc channel (%d)\n", __func__,
290                        adc_count);
291
292                 return adc_count;
293         }
294
295         for (i = 0; i < adc_count; i++) {
296                 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
297                                                    "#io-channel-cells", 0, i,
298                                                    &adc_args)) {
299                         pr_debug("%s: can't find /config/st,adc_usb_pd\n",
300                                  __func__);
301                         return 0;
302                 }
303
304                 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
305                                                   &adc);
306
307                 if (ret) {
308                         pr_err("%s: Can't get adc device(%d)\n", __func__,
309                                ret);
310                         return ret;
311                 }
312
313                 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
314                                               &raw);
315                 if (ret) {
316                         pr_err("%s: single shot failed for %s[%d]!\n",
317                                __func__, adc->name, adc_args.args[0]);
318                         return ret;
319                 }
320                 /* Convert to uV */
321                 if (!adc_raw_to_uV(adc, raw, &uV)) {
322                         if (uV > max_uV)
323                                 max_uV = uV;
324                         if (uV < min_uV)
325                                 min_uV = uV;
326                         pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
327                                  adc->name, adc_args.args[0], raw, uV);
328                 } else {
329                         pr_err("%s: Can't get uV value for %s[%d]\n",
330                                __func__, adc->name, adc_args.args[0]);
331                 }
332         }
333
334         /*
335          * If highest value is inside 1.23 Volts and 2.10 Volts, that means
336          * board is plugged on an USB-C 3A power supply and boot process can
337          * continue.
338          */
339         if (max_uV > USB_START_LOW_THRESHOLD_UV &&
340             max_uV <= USB_START_HIGH_THRESHOLD_UV &&
341             min_uV <= USB_LOW_THRESHOLD_UV)
342                 return 0;
343
344         pr_err("****************************************************\n");
345
346         /*
347          * If highest and lowest value are either both below
348          * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
349          * means USB TYPE-C is in unattached mode, this is an issue, make
350          * u-boot,error-led blinking and stop boot process.
351          */
352         if ((max_uV > USB_LOW_THRESHOLD_UV &&
353              min_uV > USB_LOW_THRESHOLD_UV) ||
354              (max_uV <= USB_LOW_THRESHOLD_UV &&
355              min_uV <= USB_LOW_THRESHOLD_UV)) {
356                 pr_err("* ERROR USB TYPE-C connection in unattached mode   *\n");
357                 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
358                 /* with 125ms interval, led will blink for 17.02 years ....*/
359                 nb_blink = U32_MAX;
360         }
361
362         if (max_uV > USB_LOW_THRESHOLD_UV &&
363             max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
364             min_uV <= USB_LOW_THRESHOLD_UV) {
365                 pr_err("*        WARNING 500mA power supply detected       *\n");
366                 nb_blink = 2;
367         }
368
369         if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
370             max_uV <= USB_START_LOW_THRESHOLD_UV &&
371             min_uV <= USB_LOW_THRESHOLD_UV) {
372                 pr_err("*       WARNING 1.5mA power supply detected        *\n");
373                 nb_blink = 3;
374         }
375
376         /*
377          * If highest value is above 2.15 Volts that means that the USB TypeC
378          * supplies more than 3 Amp, this is not compliant with TypeC specification
379          */
380         if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
381                 pr_err("*      USB TYPE-C charger not compliant with       *\n");
382                 pr_err("*                   specification                  *\n");
383                 pr_err("****************************************************\n\n");
384                 /* with 125ms interval, led will blink for 17.02 years ....*/
385                 nb_blink = U32_MAX;
386         } else {
387                 pr_err("*     Current too low, use a 3A power supply!      *\n");
388                 pr_err("****************************************************\n\n");
389         }
390
391         ret = get_led(&led, "u-boot,error-led");
392         if (ret) {
393                 /* in unattached case, the boot process must be stopped */
394                 if (nb_blink == U32_MAX)
395                         hang();
396                 return ret;
397         }
398
399         /* make u-boot,error-led blinking */
400         for (i = 0; i < nb_blink * 2; i++) {
401                 led_set_state(led, LEDST_TOGGLE);
402                 mdelay(125);
403         }
404         led_set_state(led, LEDST_ON);
405
406         return 0;
407 }
408
409 static void sysconf_init(void)
410 {
411 #ifndef CONFIG_STM32MP1_TRUSTED
412         u8 *syscfg;
413 #ifdef CONFIG_DM_REGULATOR
414         struct udevice *pwr_dev;
415         struct udevice *pwr_reg;
416         struct udevice *dev;
417         int ret;
418         u32 otp = 0;
419 #endif
420         u32 bootr;
421
422         syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
423
424         /* interconnect update : select master using the port 1 */
425         /* LTDC = AXI_M9 */
426         /* GPU  = AXI_M8 */
427         /* today information is hardcoded in U-Boot */
428         writel(BIT(9), syscfg + SYSCFG_ICNR);
429
430         /* disable Pull-Down for boot pin connected to VDD */
431         bootr = readl(syscfg + SYSCFG_BOOTR);
432         bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
433         bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
434         writel(bootr, syscfg + SYSCFG_BOOTR);
435
436 #ifdef CONFIG_DM_REGULATOR
437         /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
438          * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
439          * The customer will have to disable this for low frequencies
440          * or if AFMUX is selected but the function not used, typically for
441          * TRACE. Otherwise, impact on power consumption.
442          *
443          * WARNING:
444          *   enabling High Speed mode while VDD>2.7V
445          *   with the OTP product_below_2v5 (OTP 18, BIT 13)
446          *   erroneously set to 1 can damage the IC!
447          *   => U-Boot set the register only if VDD < 2.7V (in DT)
448          *      but this value need to be consistent with board design
449          */
450         ret = syscon_get_by_driver_data(STM32MP_SYSCON_PWR, &pwr_dev);
451         if (!ret) {
452                 ret = uclass_get_device_by_driver(UCLASS_MISC,
453                                                   DM_GET_DRIVER(stm32mp_bsec),
454                                                   &dev);
455                 if (ret) {
456                         pr_err("Can't find stm32mp_bsec driver\n");
457                         return;
458                 }
459
460                 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
461                 if (!ret)
462                         otp = otp & BIT(13);
463
464                 /* get VDD = pwr-supply */
465                 ret = device_get_supply_regulator(pwr_dev, "pwr-supply",
466                                                   &pwr_reg);
467
468                 /* check if VDD is Low Voltage */
469                 if (!ret) {
470                         if (regulator_get_value(pwr_reg) < 2700000) {
471                                 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
472                                        SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
473                                        SYSCFG_IOCTRLSETR_HSLVEN_ETH |
474                                        SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
475                                        SYSCFG_IOCTRLSETR_HSLVEN_SPI,
476                                        syscfg + SYSCFG_IOCTRLSETR);
477
478                                 if (!otp)
479                                         pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
480                         } else {
481                                 if (otp)
482                                         pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
483                         }
484                 } else {
485                         debug("VDD unknown");
486                 }
487         }
488 #endif
489
490         /* activate automatic I/O compensation
491          * warning: need to ensure CSI enabled and ready in clock driver
492          */
493         writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
494
495         while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
496                 ;
497         clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
498 #endif
499 }
500
501 /* board dependent setup after realloc */
502 int board_init(void)
503 {
504         struct udevice *dev;
505
506         /* address of boot parameters */
507         gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
508
509         /* probe all PINCTRL for hog */
510         for (uclass_first_device(UCLASS_PINCTRL, &dev);
511              dev;
512              uclass_next_device(&dev)) {
513                 pr_debug("probe pincontrol = %s\n", dev->name);
514         }
515
516         board_key_check();
517
518         sysconf_init();
519
520         if (IS_ENABLED(CONFIG_LED))
521                 led_default_state();
522
523         return 0;
524 }
525
526 int board_late_init(void)
527 {
528 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
529         const void *fdt_compat;
530         int fdt_compat_len;
531
532         fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
533                                  &fdt_compat_len);
534         if (fdt_compat && fdt_compat_len) {
535                 if (strncmp(fdt_compat, "st,", 3) != 0)
536                         env_set("board_name", fdt_compat);
537                 else
538                         env_set("board_name", fdt_compat + 3);
539         }
540 #endif
541
542         /* for DK1/DK2 boards */
543         board_check_usb_power();
544
545         return 0;
546 }
547
548 void board_quiesce_devices(void)
549 {
550         setup_led(LEDST_OFF);
551 }
552
553 enum env_location env_get_location(enum env_operation op, int prio)
554 {
555         u32 bootmode = get_bootmode();
556
557         if (prio)
558                 return ENVL_UNKNOWN;
559
560         switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
561 #ifdef CONFIG_ENV_IS_IN_EXT4
562         case BOOT_FLASH_SD:
563         case BOOT_FLASH_EMMC:
564                 return ENVL_EXT4;
565 #endif
566 #ifdef CONFIG_ENV_IS_IN_UBI
567         case BOOT_FLASH_NAND:
568                 return ENVL_UBI;
569 #endif
570 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
571         case BOOT_FLASH_NOR:
572                 return ENVL_SPI_FLASH;
573 #endif
574         default:
575                 return ENVL_NOWHERE;
576         }
577 }
578
579 #if defined(CONFIG_ENV_IS_IN_EXT4)
580 const char *env_ext4_get_intf(void)
581 {
582         u32 bootmode = get_bootmode();
583
584         switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
585         case BOOT_FLASH_SD:
586         case BOOT_FLASH_EMMC:
587                 return "mmc";
588         default:
589                 return "";
590         }
591 }
592
593 const char *env_ext4_get_dev_part(void)
594 {
595         static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
596         u32 bootmode = get_bootmode();
597
598         return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
599 }
600 #endif
601
602 #ifdef CONFIG_SYS_MTDPARTS_RUNTIME
603
604 #define MTDPARTS_LEN            256
605 #define MTDIDS_LEN              128
606
607 /**
608  * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
609  * If we need to access it before the env is relocated, then we need
610  * to use our own stack buffer. gd->env_buf will be too small.
611  *
612  * @param buf temporary buffer pointer MTDPARTS_LEN long
613  * @return mtdparts variable string, NULL if not found
614  */
615 static const char *env_get_mtdparts(const char *str, char *buf)
616 {
617         if (gd->flags & GD_FLG_ENV_READY)
618                 return env_get(str);
619         if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
620                 return buf;
621
622         return NULL;
623 }
624
625 /**
626  * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
627  */
628 static void board_get_mtdparts(const char *dev,
629                                char *mtdids,
630                                char *mtdparts)
631 {
632         char env_name[32] = "mtdparts_";
633         char tmp_mtdparts[MTDPARTS_LEN];
634         const char *tmp;
635
636         /* name of env variable to read = mtdparts_<dev> */
637         strcat(env_name, dev);
638         tmp = env_get_mtdparts(env_name, tmp_mtdparts);
639         if (tmp) {
640                 /* mtdids: "<dev>=<dev>, ...." */
641                 if (mtdids[0] != '\0')
642                         strcat(mtdids, ",");
643                 strcat(mtdids, dev);
644                 strcat(mtdids, "=");
645                 strcat(mtdids, dev);
646
647                 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
648                 if (mtdparts[0] != '\0')
649                         strncat(mtdparts, ";", MTDPARTS_LEN);
650                 else
651                         strcat(mtdparts, "mtdparts=");
652                 strncat(mtdparts, dev, MTDPARTS_LEN);
653                 strncat(mtdparts, ":", MTDPARTS_LEN);
654                 strncat(mtdparts, tmp, MTDPARTS_LEN);
655         }
656 }
657
658 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
659 {
660         struct udevice *dev;
661         static char parts[2 * MTDPARTS_LEN + 1];
662         static char ids[MTDIDS_LEN + 1];
663         static bool mtd_initialized;
664
665         if (mtd_initialized) {
666                 *mtdids = ids;
667                 *mtdparts = parts;
668                 return;
669         }
670
671         memset(parts, 0, sizeof(parts));
672         memset(ids, 0, sizeof(ids));
673
674         if (!uclass_get_device(UCLASS_MTD, 0, &dev))
675                 board_get_mtdparts("nand0", ids, parts);
676
677         if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
678                 board_get_mtdparts("nor0", ids, parts);
679
680         mtd_initialized = true;
681         *mtdids = ids;
682         *mtdparts = parts;
683         debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
684 }
685 #endif