/*
 * diag_usb.c
 * Copyright (C) 2011 Allied Telesis Labs NZ
 *
 * Author: Luuk Paulussen
 *
 * This file is licensed under the terms of the GNU General Public License
 * version 2. This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */


#include <common.h>
#include <diag.h>
#include <usb.h>

DECLARE_GLOBAL_DATA_PTR;

int diag_usb_test(void)
{
	int ret = 0;
	u32 silent = gd->flags & GD_FLG_SILENT;

	/* Make the console non-silent so usb code messages come out. */
	gd->flags &= ~GD_FLG_SILENT;

	usb_stop();

	ret = usb_init();
	if (ret < 0) {
		printf("FAIL: usb init failed.\n");
		return -1;
	}

	ret = usb_stor_scan(1);
	if (ret < 0) {
		printf("FAIL: failed to scan mass storage device in USB port.\n");
		return -1;
	}

	ret = usb_stor_info();
	if (ret < 0) {
		printf("FAIL: Couldn't print USB storage device info.\n");
		return -1;
	}

	printf("PASS: USB slot was able to init and read card information.\n");

	gd->flags |= silent;

	return 0;
}
