Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | d0d9d21 | 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 | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 8 | #include <spl.h> |
| 9 | #include <usb.h> |
| 10 | #include <g_dnl.h> |
| 11 | #include <sdp.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 12 | #include <linux/printk.h> |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 13 | |
Stefan Agner | d0d9d21 | 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 | { |
Ye Li | f7ac6fd | 2020-04-29 10:35:12 +0800 | [diff] [blame] | 17 | const int controller_index = CONFIG_SPL_SDP_USB_DEV; |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 18 | struct udevice *udc; |
| 19 | int ret; |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 20 | |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 21 | ret = udc_device_get_by_index(controller_index, &udc); |
| 22 | if (ret) |
| 23 | return ret; |
Frank Li | a36d93e | 2020-04-29 10:35:10 +0800 | [diff] [blame] | 24 | |
Fabio Estevam | bcb8dc3 | 2022-07-13 17:39:46 -0300 | [diff] [blame] | 25 | board_usb_init(controller_index, USB_INIT_DEVICE); |
Frank Li | 0b4b47b | 2020-08-18 18:16:43 +0800 | [diff] [blame] | 26 | |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 27 | g_dnl_clear_detach(); |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 28 | ret = g_dnl_register("usb_dnl_sdp"); |
| 29 | if (ret) { |
| 30 | pr_err("SDP dnl register failed: %d\n", ret); |
Marek Vasut | d67f210 | 2023-09-01 11:49:57 +0200 | [diff] [blame] | 31 | goto err_detach; |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 32 | } |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 33 | |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 34 | ret = sdp_init(udc); |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 35 | if (ret) { |
Andre Heider | b841e97 | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 36 | pr_err("SDP init failed: %d\n", ret); |
Marek Vasut | d67f210 | 2023-09-01 11:49:57 +0200 | [diff] [blame] | 37 | goto err_unregister; |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Frieder Schrempf | 09580e2 | 2019-06-04 21:56:29 +0200 | [diff] [blame] | 40 | /* |
| 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 Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 45 | ret = spl_sdp_handle(udc, spl_image, bootdev); |
Frieder Schrempf | 09580e2 | 2019-06-04 21:56:29 +0200 | [diff] [blame] | 46 | debug("SDP ended\n"); |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 47 | |
Marek Vasut | d67f210 | 2023-09-01 11:49:57 +0200 | [diff] [blame] | 48 | err_unregister: |
| 49 | g_dnl_unregister(); |
| 50 | err_detach: |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 51 | udc_device_put(udc); |
Frieder Schrempf | 09580e2 | 2019-06-04 21:56:29 +0200 | [diff] [blame] | 52 | return ret; |
Stefan Agner | d0d9d21 | 2017-08-16 11:00:54 -0700 | [diff] [blame] | 53 | } |
| 54 | SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image); |