blob: 39259a3b09253cb643f26f4f2f98c79745fbff62 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Agner2f005692017-08-16 11:00:53 -07002/*
3 * cmd_sdp.c -- sdp command
4 *
5 * Copyright (C) 2016 Toradex
6 * Author: Stefan Agner <stefan.agner@toradex.com>
Stefan Agner2f005692017-08-16 11:00:53 -07007 */
8
Simon Glass09140112020-05-10 11:40:03 -06009#include <command.h>
Stefan Agner2f005692017-08-16 11:00:53 -070010#include <g_dnl.h>
11#include <sdp.h>
12#include <usb.h>
Simon Glass1e94b462023-09-14 18:21:46 -060013#include <linux/printk.h>
Stefan Agner2f005692017-08-16 11:00:53 -070014
Simon Glass09140112020-05-10 11:40:03 -060015static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Stefan Agner2f005692017-08-16 11:00:53 -070016{
Marek Vasut37fb7cb2023-09-01 11:49:52 +020017 int controller_index;
Marek Vasut6b84acc2023-09-01 11:49:58 +020018 struct udevice *udc;
Sjoerd Simons25ee9242019-06-04 21:01:55 +020019 int ret;
Stefan Agner2f005692017-08-16 11:00:53 -070020
21 if (argc < 2)
22 return CMD_RET_USAGE;
23
Marek Vasut37fb7cb2023-09-01 11:49:52 +020024 controller_index = simple_strtoul(argv[1], NULL, 0);
Marek Vasut6b84acc2023-09-01 11:49:58 +020025 ret = udc_device_get_by_index(controller_index, &udc);
26 if (ret)
27 return ret;
Stefan Agner2f005692017-08-16 11:00:53 -070028
29 g_dnl_clear_detach();
Sjoerd Simons25ee9242019-06-04 21:01:55 +020030 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 Agner2f005692017-08-16 11:00:53 -070035
Marek Vasut6b84acc2023-09-01 11:49:58 +020036 ret = sdp_init(udc);
Stefan Agner2f005692017-08-16 11:00:53 -070037 if (ret) {
Andre Heider24ccd0c2018-02-15 07:08:55 +010038 pr_err("SDP init failed: %d\n", ret);
Stefan Agner2f005692017-08-16 11:00:53 -070039 goto exit;
40 }
41
42 /* This command typically does not return but jumps to an image */
Marek Vasut6b84acc2023-09-01 11:49:58 +020043 sdp_handle(udc);
Andre Heider24ccd0c2018-02-15 07:08:55 +010044 pr_err("SDP ended\n");
Stefan Agner2f005692017-08-16 11:00:53 -070045
46exit:
47 g_dnl_unregister();
Sjoerd Simons25ee9242019-06-04 21:01:55 +020048exit_register:
Marek Vasut6b84acc2023-09-01 11:49:58 +020049 udc_device_put(udc);
Stefan Agner2f005692017-08-16 11:00:53 -070050
Sjoerd Simons25ee9242019-06-04 21:01:55 +020051 return CMD_RET_FAILURE;
Stefan Agner2f005692017-08-16 11:00:53 -070052}
53
54U_BOOT_CMD(sdp, 2, 1, do_sdp,
55 "Serial Downloader Protocol",
56 "<USB_controller>\n"
57 " - serial downloader protocol via <USB_controller>\n"
58);