Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Toradex |
| 4 | * Author: Stefan Agner <stefan.agner@toradex.com> |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 9 | #include <spl.h> |
| 10 | #include <usb.h> |
| 11 | #include <g_dnl.h> |
| 12 | #include <sdp.h> |
| 13 | |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 14 | static int spl_sdp_load_image(struct spl_image_info *spl_image, |
| 15 | struct spl_boot_device *bootdev) |
| 16 | { |
| 17 | int ret; |
Ye Li | 407e384 | 2020-04-29 10:35:12 +0800 | [diff] [blame] | 18 | const int controller_index = CONFIG_SPL_SDP_USB_DEV; |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 19 | |
Sherry Sun | d8e7755 | 2020-04-29 10:35:14 +0800 | [diff] [blame] | 20 | usb_gadget_initialize(controller_index); |
Frank Li | 62597d2 | 2020-04-29 10:35:10 +0800 | [diff] [blame] | 21 | |
Fabio Estevam | 16aabfe | 2022-07-13 17:39:46 -0300 | [diff] [blame] | 22 | board_usb_init(controller_index, USB_INIT_DEVICE); |
Frank Li | 0ced2fa | 2020-08-18 18:16:43 +0800 | [diff] [blame] | 23 | |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 24 | g_dnl_clear_detach(); |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 25 | 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 Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 30 | |
| 31 | ret = sdp_init(controller_index); |
| 32 | if (ret) { |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 33 | pr_err("SDP init failed: %d\n", ret); |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 34 | return -ENODEV; |
| 35 | } |
| 36 | |
Frieder Schrempf | 2c72ead | 2019-06-04 21:56:29 +0200 | [diff] [blame] | 37 | /* |
| 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ár | 2e0429b | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 42 | ret = spl_sdp_handle(controller_index, spl_image, bootdev); |
Frieder Schrempf | 2c72ead | 2019-06-04 21:56:29 +0200 | [diff] [blame] | 43 | debug("SDP ended\n"); |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 44 | |
Sherry Sun | d8e7755 | 2020-04-29 10:35:14 +0800 | [diff] [blame] | 45 | usb_gadget_release(controller_index); |
Frieder Schrempf | 2c72ead | 2019-06-04 21:56:29 +0200 | [diff] [blame] | 46 | return ret; |
Stefan Agner | a3774c1 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 47 | } |
| 48 | SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image); |