blob: cbdda733533ca53ccccffd457bbb8a6305d261fb [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>
Simon Glassbdd5f812023-09-14 18:21:46 -060014#include <linux/printk.h>
Stefan Agnerd9d661c2017-08-16 11:00:53 -070015
Simon Glassed38aef2020-05-10 11:40:03 -060016static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Stefan Agnerd9d661c2017-08-16 11:00:53 -070017{
Marek Vasut0b48adb2023-09-01 11:49:52 +020018 int controller_index;
Marek Vasut2bd299d2023-09-01 11:49:58 +020019 struct udevice *udc;
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020020 int ret;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070021
22 if (argc < 2)
23 return CMD_RET_USAGE;
24
Marek Vasut0b48adb2023-09-01 11:49:52 +020025 controller_index = simple_strtoul(argv[1], NULL, 0);
Marek Vasut2bd299d2023-09-01 11:49:58 +020026 ret = udc_device_get_by_index(controller_index, &udc);
27 if (ret)
28 return ret;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070029
30 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-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 Agnerd9d661c2017-08-16 11:00:53 -070036
Marek Vasut2bd299d2023-09-01 11:49:58 +020037 ret = sdp_init(udc);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070038 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010039 pr_err("SDP init failed: %d\n", ret);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070040 goto exit;
41 }
42
43 /* This command typically does not return but jumps to an image */
Marek Vasut2bd299d2023-09-01 11:49:58 +020044 sdp_handle(udc);
Andre Heiderb841e972018-02-15 07:08:55 +010045 pr_err("SDP ended\n");
Stefan Agnerd9d661c2017-08-16 11:00:53 -070046
47exit:
48 g_dnl_unregister();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020049exit_register:
Marek Vasut2bd299d2023-09-01 11:49:58 +020050 udc_device_put(udc);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070051
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020052 return CMD_RET_FAILURE;
Stefan Agnerd9d661c2017-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);