blob: 9143c27bbf1d9028fcee587de8272fe9cb4a06cb [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>
Simon Glassbdd5f812023-09-14 18:21:46 -060013#include <linux/printk.h>
Stefan Agnerd0d9d212017-08-16 11:00:54 -070014
Stefan Agnerd0d9d212017-08-16 11:00:54 -070015static int spl_sdp_load_image(struct spl_image_info *spl_image,
16 struct spl_boot_device *bootdev)
17{
Ye Lif7ac6fd2020-04-29 10:35:12 +080018 const int controller_index = CONFIG_SPL_SDP_USB_DEV;
Marek Vasut2bd299d2023-09-01 11:49:58 +020019 struct udevice *udc;
20 int ret;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070021
Marek Vasut2bd299d2023-09-01 11:49:58 +020022 ret = udc_device_get_by_index(controller_index, &udc);
23 if (ret)
24 return ret;
Frank Lia36d93e2020-04-29 10:35:10 +080025
Fabio Estevambcb8dc32022-07-13 17:39:46 -030026 board_usb_init(controller_index, USB_INIT_DEVICE);
Frank Li0b4b47b2020-08-18 18:16:43 +080027
Stefan Agnerd0d9d212017-08-16 11:00:54 -070028 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020029 ret = g_dnl_register("usb_dnl_sdp");
30 if (ret) {
31 pr_err("SDP dnl register failed: %d\n", ret);
Marek Vasutd67f2102023-09-01 11:49:57 +020032 goto err_detach;
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020033 }
Stefan Agnerd0d9d212017-08-16 11:00:54 -070034
Marek Vasut2bd299d2023-09-01 11:49:58 +020035 ret = sdp_init(udc);
Stefan Agnerd0d9d212017-08-16 11:00:54 -070036 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010037 pr_err("SDP init failed: %d\n", ret);
Marek Vasutd67f2102023-09-01 11:49:57 +020038 goto err_unregister;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070039 }
40
Frieder Schrempf09580e22019-06-04 21:56:29 +020041 /*
42 * This command either loads a legacy image, jumps and never returns,
43 * or it loads a FIT image and returns it to be handled by the SPL
44 * code.
45 */
Marek Vasut2bd299d2023-09-01 11:49:58 +020046 ret = spl_sdp_handle(udc, spl_image, bootdev);
Frieder Schrempf09580e22019-06-04 21:56:29 +020047 debug("SDP ended\n");
Stefan Agnerd0d9d212017-08-16 11:00:54 -070048
Marek Vasutd67f2102023-09-01 11:49:57 +020049err_unregister:
50 g_dnl_unregister();
51err_detach:
Marek Vasut2bd299d2023-09-01 11:49:58 +020052 udc_device_put(udc);
Frieder Schrempf09580e22019-06-04 21:56:29 +020053 return ret;
Stefan Agnerd0d9d212017-08-16 11:00:54 -070054}
55SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);