blob: cbdda733533ca53ccccffd457bbb8a6305d261fb [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
9#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -060010#include <command.h>
Stefan Agner2f005692017-08-16 11:00:53 -070011#include <g_dnl.h>
12#include <sdp.h>
13#include <usb.h>
Simon Glass1e94b462023-09-14 18:21:46 -060014#include <linux/printk.h>
Stefan Agner2f005692017-08-16 11:00:53 -070015
Simon Glass09140112020-05-10 11:40:03 -060016static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Stefan Agner2f005692017-08-16 11:00:53 -070017{
Marek Vasut37fb7cb2023-09-01 11:49:52 +020018 int controller_index;
Marek Vasut6b84acc2023-09-01 11:49:58 +020019 struct udevice *udc;
Sjoerd Simons25ee9242019-06-04 21:01:55 +020020 int ret;
Stefan Agner2f005692017-08-16 11:00:53 -070021
22 if (argc < 2)
23 return CMD_RET_USAGE;
24
Marek Vasut37fb7cb2023-09-01 11:49:52 +020025 controller_index = simple_strtoul(argv[1], NULL, 0);
Marek Vasut6b84acc2023-09-01 11:49:58 +020026 ret = udc_device_get_by_index(controller_index, &udc);
27 if (ret)
28 return ret;
Stefan Agner2f005692017-08-16 11:00:53 -070029
30 g_dnl_clear_detach();
Sjoerd Simons25ee9242019-06-04 21:01:55 +020031 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 Agner2f005692017-08-16 11:00:53 -070036
Marek Vasut6b84acc2023-09-01 11:49:58 +020037 ret = sdp_init(udc);
Stefan Agner2f005692017-08-16 11:00:53 -070038 if (ret) {
Andre Heider24ccd0c2018-02-15 07:08:55 +010039 pr_err("SDP init failed: %d\n", ret);
Stefan Agner2f005692017-08-16 11:00:53 -070040 goto exit;
41 }
42
43 /* This command typically does not return but jumps to an image */
Marek Vasut6b84acc2023-09-01 11:49:58 +020044 sdp_handle(udc);
Andre Heider24ccd0c2018-02-15 07:08:55 +010045 pr_err("SDP ended\n");
Stefan Agner2f005692017-08-16 11:00:53 -070046
47exit:
48 g_dnl_unregister();
Sjoerd Simons25ee9242019-06-04 21:01:55 +020049exit_register:
Marek Vasut6b84acc2023-09-01 11:49:58 +020050 udc_device_put(udc);
Stefan Agner2f005692017-08-16 11:00:53 -070051
Sjoerd Simons25ee9242019-06-04 21:01:55 +020052 return CMD_RET_FAILURE;
Stefan Agner2f005692017-08-16 11:00:53 -070053}
54
55U_BOOT_CMD(sdp, 2, 1, do_sdp,
56 "Serial Downloader Protocol",
57 "<USB_controller>\n"
58 " - serial downloader protocol via <USB_controller>\n"
59);