blob: cc4fb4f7cca2183d1a4ff35afd46a07156ee2f2c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Agnera3774c12017-08-16 11:00:54 -07002/*
3 * (C) Copyright 2016 Toradex
4 * Author: Stefan Agner <stefan.agner@toradex.com>
Stefan Agnera3774c12017-08-16 11:00:54 -07005 */
6
7#include <common.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Stefan Agnera3774c12017-08-16 11:00:54 -07009#include <spl.h>
10#include <usb.h>
11#include <g_dnl.h>
12#include <sdp.h>
13
Stefan Agnera3774c12017-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 Li407e3842020-04-29 10:35:12 +080018 const int controller_index = CONFIG_SPL_SDP_USB_DEV;
Stefan Agnera3774c12017-08-16 11:00:54 -070019
Sherry Sund8e77552020-04-29 10:35:14 +080020 usb_gadget_initialize(controller_index);
Frank Li62597d22020-04-29 10:35:10 +080021
Fabio Estevam16aabfe2022-07-13 17:39:46 -030022 board_usb_init(controller_index, USB_INIT_DEVICE);
Frank Li0ced2fa2020-08-18 18:16:43 +080023
Stefan Agnera3774c12017-08-16 11:00:54 -070024 g_dnl_clear_detach();
Sjoerd Simons25ee9242019-06-04 21:01:55 +020025 ret = g_dnl_register("usb_dnl_sdp");
26 if (ret) {
27 pr_err("SDP dnl register failed: %d\n", ret);
28 return ret;
29 }
Stefan Agnera3774c12017-08-16 11:00:54 -070030
31 ret = sdp_init(controller_index);
32 if (ret) {
Andre Heider24ccd0c2018-02-15 07:08:55 +010033 pr_err("SDP init failed: %d\n", ret);
Stefan Agnera3774c12017-08-16 11:00:54 -070034 return -ENODEV;
35 }
36
Frieder Schrempf2c72ead2019-06-04 21:56:29 +020037 /*
38 * This command either loads a legacy image, jumps and never returns,
39 * or it loads a FIT image and returns it to be handled by the SPL
40 * code.
41 */
Pali Rohár2e0429b2022-01-14 14:31:38 +010042 ret = spl_sdp_handle(controller_index, spl_image, bootdev);
Frieder Schrempf2c72ead2019-06-04 21:56:29 +020043 debug("SDP ended\n");
Stefan Agnera3774c12017-08-16 11:00:54 -070044
Sherry Sund8e77552020-04-29 10:35:14 +080045 usb_gadget_release(controller_index);
Frieder Schrempf2c72ead2019-06-04 21:56:29 +020046 return ret;
Stefan Agnera3774c12017-08-16 11:00:54 -070047}
48SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);