Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 2 | /* |
| 3 | * cmd_sdp.c -- sdp command |
| 4 | * |
| 5 | * Copyright (C) 2016 Toradex |
| 6 | * Author: Stefan Agner <stefan.agner@toradex.com> |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <command.h> |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 11 | #include <g_dnl.h> |
| 12 | #include <sdp.h> |
| 13 | #include <usb.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 14 | #include <linux/printk.h> |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 15 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 16 | static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 17 | { |
Marek Vasut | 0b48adb | 2023-09-01 11:49:52 +0200 | [diff] [blame] | 18 | int controller_index; |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 19 | struct udevice *udc; |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 20 | int ret; |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 21 | |
| 22 | if (argc < 2) |
| 23 | return CMD_RET_USAGE; |
| 24 | |
Marek Vasut | 0b48adb | 2023-09-01 11:49:52 +0200 | [diff] [blame] | 25 | controller_index = simple_strtoul(argv[1], NULL, 0); |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 26 | ret = udc_device_get_by_index(controller_index, &udc); |
| 27 | if (ret) |
| 28 | return ret; |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 29 | |
| 30 | g_dnl_clear_detach(); |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 31 | ret = g_dnl_register("usb_dnl_sdp"); |
| 32 | if (ret) { |
| 33 | pr_err("SDP dnl register failed: %d\n", ret); |
| 34 | goto exit_register; |
| 35 | } |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 36 | |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 37 | ret = sdp_init(udc); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 38 | if (ret) { |
Andre Heider | b841e97 | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 39 | pr_err("SDP init failed: %d\n", ret); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 40 | goto exit; |
| 41 | } |
| 42 | |
| 43 | /* This command typically does not return but jumps to an image */ |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 44 | sdp_handle(udc); |
Andre Heider | b841e97 | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 45 | pr_err("SDP ended\n"); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 46 | |
| 47 | exit: |
| 48 | g_dnl_unregister(); |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 49 | exit_register: |
Marek Vasut | 2bd299d | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 50 | udc_device_put(udc); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 51 | |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 52 | return CMD_RET_FAILURE; |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | U_BOOT_CMD(sdp, 2, 1, do_sdp, |
| 56 | "Serial Downloader Protocol", |
| 57 | "<USB_controller>\n" |
| 58 | " - serial downloader protocol via <USB_controller>\n" |
| 59 | ); |