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 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <command.h> |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 10 | #include <g_dnl.h> |
| 11 | #include <sdp.h> |
| 12 | #include <usb.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 13 | #include <linux/printk.h> |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 14 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | 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] | 16 | { |
Marek Vasut | 37fb7cb | 2023-09-01 11:49:52 +0200 | [diff] [blame] | 17 | int controller_index; |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 18 | struct udevice *udc; |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 19 | int ret; |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 20 | |
| 21 | if (argc < 2) |
| 22 | return CMD_RET_USAGE; |
| 23 | |
Marek Vasut | 37fb7cb | 2023-09-01 11:49:52 +0200 | [diff] [blame] | 24 | controller_index = simple_strtoul(argv[1], NULL, 0); |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 25 | ret = udc_device_get_by_index(controller_index, &udc); |
| 26 | if (ret) |
| 27 | return ret; |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 28 | |
| 29 | g_dnl_clear_detach(); |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 30 | ret = g_dnl_register("usb_dnl_sdp"); |
| 31 | if (ret) { |
| 32 | pr_err("SDP dnl register failed: %d\n", ret); |
| 33 | goto exit_register; |
| 34 | } |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 35 | |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 36 | ret = sdp_init(udc); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 37 | if (ret) { |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 38 | pr_err("SDP init failed: %d\n", ret); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 39 | goto exit; |
| 40 | } |
| 41 | |
| 42 | /* This command typically does not return but jumps to an image */ |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 43 | sdp_handle(udc); |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 44 | pr_err("SDP ended\n"); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 45 | |
| 46 | exit: |
| 47 | g_dnl_unregister(); |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 48 | exit_register: |
Marek Vasut | 6b84acc | 2023-09-01 11:49:58 +0200 | [diff] [blame] | 49 | udc_device_put(udc); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 50 | |
Sjoerd Simons | 25ee924 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 51 | return CMD_RET_FAILURE; |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | U_BOOT_CMD(sdp, 2, 1, do_sdp, |
| 55 | "Serial Downloader Protocol", |
| 56 | "<USB_controller>\n" |
| 57 | " - serial downloader protocol via <USB_controller>\n" |
| 58 | ); |