blob: c0da652e6dadbe96e132456c20aa2af1ae1d6a11 [file] [log] [blame]
/*
* Copyright (C) 2018 Synaptics Incorporated. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND
* SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY
* INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR
* CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE
* OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND
* BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF
* COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT
* DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY
* TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS.
*/
#ifndef _USB_STORAGE_H_
#define _USB_STORAGE_H_
#include <part.h>
/** USB DRIVER API.
*
* Follow the steps to use it.
* step 1, call usb_start() to initialize USB.
* step 2, call usb_stor_scan() to scan usb storage devices.
* step 3, loop calling usb_stor_read() to get image from scaned devices
* and check validity of image.
*
* Take booting up daig.bin as an example.
*
* static int do_binary_check(unsigned char *usb_buf)
* {
* return 0;
* }
* static int usb_stor_read_example()
* {
* int usb_stor_cnt=0;
* int ret, i;
* unsigned int start_blk, size_blk;
* unsigned char *usb_buf = (unsigned char*)0x05008000;
*
* start_blk = 1; //start from the second block
* size_blk = (4<<20)/512; //size of zImage
*
* ret = usb_init();
* // try to recognize storage devices immediately
* if (ret >= 0)
* usb_stor_cnt = usb_stor_scan();
*
* for(i = 0;i < usb_stor_cnt; i++) //try to read binary from all scaned device.
* {
* memset(usb_buf,0,size_blk*512);
*
* if(usb_stor_read(i, start_blk, size_blk, usb_buf) == size_blk)
* {
* lgpl_printf("usb_read: end startblk %d, blccnt %d buffer 0x%x\n",
* start_blk, size_blk, usb_buf);
* if (do_binary_check(usb_buf) == 0)//passed check
* break;
* }
* }
* if (i == usb_stor_cnt)
* {
* lgpl_printf("Can not get daig image.\n");
* if (usb_stor_cnt == 0)
* lgpl_printf("No usb stor dev available.\n");
* while(1);
* }
* __reset_cpu((unsigned int)usb_buf, 1330, 0);
* }
*/
/* Stop usb devices.
*
* Stops the LowLevel Part and deregisters USB devices.
*/
int usb_stop(void);
/* Init usb devices.
*
* usb init and scan usb device.
*
* @retval =0 has found usb devices.
* @retval = -1 has not found usb devices.
*/
int usb_init();
/* Scan usb storage devices.
*
* scan the usb and reports device info.
*
* @retval the number of usb storage devices.
*/
int usb_stor_scan();
/** Usb storage read
*
* @param device usb storage device index.
* @param blknr start address in block.
* @param blkcnt size in block.
* @param buffer objective data buffer.
*
* @retval: >0 count of read blocks.
* @retval: =0 read errror.
*/
unsigned long usb_stor_read(int device, unsigned long blknr,
unsigned long blkcnt, void *buffer);
/** Get storage descriptor
*
* @param device usb storage device index.
* @param desc Pointer to return descriptor in.
*
* @retval: =0 Success
* @retval: <0 Failure.
*/
int get_usb_storage_desc(int device, block_dev_desc_t* desc);
#endif