Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | 2f00569 | 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 | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <command.h> |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 11 | #include <g_dnl.h> |
| 12 | #include <sdp.h> |
| 13 | #include <usb.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 14 | #include <linux/printk.h> |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 15 | |
Simon Glass | 0914011 | 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 | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 17 | { |
Marek Vasut | 37fb7cb | 2023-09-01 11:49:52 +0200 | [diff] [blame] | 18 | int controller_index; |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 19 | struct udevice *udc; |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 20 | int ret; |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 21 | |
| 22 | if (argc < 2) |
| 23 | return CMD_RET_USAGE; |
| 24 | |
Marek Vasut | 37fb7cb | 2023-09-01 11:49:52 +0200 | [diff] [blame] | 25 | controller_index = simple_strtoul(argv[1], NULL, 0); |
Marek Vasut | 6b84acc | 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 | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 29 | |
| 30 | g_dnl_clear_detach(); |
Sjoerd Simons | 25ee924 | 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 | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 36 | |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 37 | ret = sdp_init(udc); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 38 | if (ret) { |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 39 | pr_err("SDP init failed: %d\n", ret); |
Stefan Agner | 2f00569 | 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 | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 44 | sdp_handle(udc); |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 45 | pr_err("SDP ended\n"); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 46 | |
| 47 | exit: |
| 48 | g_dnl_unregister(); |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 49 | exit_register: |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 50 | udc_device_put(udc); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 51 | |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 52 | return CMD_RET_FAILURE; |
Stefan Agner | 2f00569 | 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 | ); |