blob: 9ca80bd534f8ba5bad46d6df5e5c1664af6b6a33 [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
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Stefan Agnerd0d9d212017-08-16 11:00:54 -07008#include <spl.h>
9#include <usb.h>
10#include <g_dnl.h>
11#include <sdp.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060012#include <linux/printk.h>
Stefan Agnerd0d9d212017-08-16 11:00:54 -070013
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{
Ye Lif7ac6fd2020-04-29 10:35:12 +080017 const int controller_index = CONFIG_SPL_SDP_USB_DEV;
Marek Vasut2bd299d2023-09-01 11:49:58 +020018 struct udevice *udc;
19 int ret;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070020
Marek Vasut2bd299d2023-09-01 11:49:58 +020021 ret = udc_device_get_by_index(controller_index, &udc);
22 if (ret)
23 return ret;
Frank Lia36d93e2020-04-29 10:35:10 +080024
Fabio Estevambcb8dc32022-07-13 17:39:46 -030025 board_usb_init(controller_index, USB_INIT_DEVICE);
Frank Li0b4b47b2020-08-18 18:16:43 +080026
Stefan Agnerd0d9d212017-08-16 11:00:54 -070027 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020028 ret = g_dnl_register("usb_dnl_sdp");
29 if (ret) {
30 pr_err("SDP dnl register failed: %d\n", ret);
Marek Vasutd67f2102023-09-01 11:49:57 +020031 goto err_detach;
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020032 }
Stefan Agnerd0d9d212017-08-16 11:00:54 -070033
Marek Vasut2bd299d2023-09-01 11:49:58 +020034 ret = sdp_init(udc);
Stefan Agnerd0d9d212017-08-16 11:00:54 -070035 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010036 pr_err("SDP init failed: %d\n", ret);
Marek Vasutd67f2102023-09-01 11:49:57 +020037 goto err_unregister;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070038 }
39
Frieder Schrempf09580e22019-06-04 21:56:29 +020040 /*
41 * This command either loads a legacy image, jumps and never returns,
42 * or it loads a FIT image and returns it to be handled by the SPL
43 * code.
44 */
Marek Vasut2bd299d2023-09-01 11:49:58 +020045 ret = spl_sdp_handle(udc, spl_image, bootdev);
Frieder Schrempf09580e22019-06-04 21:56:29 +020046 debug("SDP ended\n");
Stefan Agnerd0d9d212017-08-16 11:00:54 -070047
Marek Vasutd67f2102023-09-01 11:49:57 +020048err_unregister:
49 g_dnl_unregister();
50err_detach:
Marek Vasut2bd299d2023-09-01 11:49:58 +020051 udc_device_put(udc);
Frieder Schrempf09580e22019-06-04 21:56:29 +020052 return ret;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070053}
54SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);