blob: 748aa0a74888a6b9b35e6c45d80a4d4e22ed507c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Agnerd9d661c2017-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 Agnerd9d661c2017-08-16 11:00:53 -07007 */
8
9#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -060010#include <command.h>
Stefan Agnerd9d661c2017-08-16 11:00:53 -070011#include <g_dnl.h>
12#include <sdp.h>
13#include <usb.h>
14
Simon Glassed38aef2020-05-10 11:40:03 -060015static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Stefan Agnerd9d661c2017-08-16 11:00:53 -070016{
Marek Vasut0b48adb2023-09-01 11:49:52 +020017 int controller_index;
Marek Vasut2bd299d2023-09-01 11:49:58 +020018 struct udevice *udc;
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020019 int ret;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070020
21 if (argc < 2)
22 return CMD_RET_USAGE;
23
Marek Vasut0b48adb2023-09-01 11:49:52 +020024 controller_index = simple_strtoul(argv[1], NULL, 0);
Marek Vasut2bd299d2023-09-01 11:49:58 +020025 ret = udc_device_get_by_index(controller_index, &udc);
26 if (ret)
27 return ret;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070028
29 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-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 Agnerd9d661c2017-08-16 11:00:53 -070035
Marek Vasut2bd299d2023-09-01 11:49:58 +020036 ret = sdp_init(udc);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070037 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010038 pr_err("SDP init failed: %d\n", ret);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070039 goto exit;
40 }
41
42 /* This command typically does not return but jumps to an image */
Marek Vasut2bd299d2023-09-01 11:49:58 +020043 sdp_handle(udc);
Andre Heiderb841e972018-02-15 07:08:55 +010044 pr_err("SDP ended\n");
Stefan Agnerd9d661c2017-08-16 11:00:53 -070045
46exit:
47 g_dnl_unregister();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020048exit_register:
Marek Vasut2bd299d2023-09-01 11:49:58 +020049 udc_device_put(udc);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070050
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020051 return CMD_RET_FAILURE;
Stefan Agnerd9d661c2017-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);