blob: e7f7b6841163463b50f37bcfdb7faffc15f339a2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Agnerd0d9d212017-08-16 11:00:54 -07002/*
3 * (C) Copyright 2016 Toradex
4 * Author: Stefan Agner <stefan.agner@toradex.com>
Stefan Agnerd0d9d212017-08-16 11:00:54 -07005 */
6
7#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Stefan Agnerd0d9d212017-08-16 11:00:54 -07009#include <spl.h>
10#include <usb.h>
11#include <g_dnl.h>
12#include <sdp.h>
13
Stefan Agnerd0d9d212017-08-16 11:00:54 -070014static int spl_sdp_load_image(struct spl_image_info *spl_image,
15 struct spl_boot_device *bootdev)
16{
17 int ret;
Ye Lif7ac6fd2020-04-29 10:35:12 +080018 const int controller_index = CONFIG_SPL_SDP_USB_DEV;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070019
Sherry Sun97286822020-04-29 10:35:14 +080020 usb_gadget_initialize(controller_index);
Frank Lia36d93e2020-04-29 10:35:10 +080021
Stefan Agnerd0d9d212017-08-16 11:00:54 -070022 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020023 ret = g_dnl_register("usb_dnl_sdp");
24 if (ret) {
25 pr_err("SDP dnl register failed: %d\n", ret);
26 return ret;
27 }
Stefan Agnerd0d9d212017-08-16 11:00:54 -070028
29 ret = sdp_init(controller_index);
30 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010031 pr_err("SDP init failed: %d\n", ret);
Stefan Agnerd0d9d212017-08-16 11:00:54 -070032 return -ENODEV;
33 }
34
Frieder Schrempf09580e22019-06-04 21:56:29 +020035 /*
36 * This command either loads a legacy image, jumps and never returns,
37 * or it loads a FIT image and returns it to be handled by the SPL
38 * code.
39 */
40 ret = spl_sdp_handle(controller_index, spl_image);
41 debug("SDP ended\n");
Stefan Agnerd0d9d212017-08-16 11:00:54 -070042
Sherry Sun97286822020-04-29 10:35:14 +080043 usb_gadget_release(controller_index);
Frieder Schrempf09580e22019-06-04 21:56:29 +020044 return ret;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070045}
46SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);