| 1 | /* |
| 2 | * Copyright(C) 2009 Qi Hardware Inc., |
| 3 | * Authors: Xiangfu Liu <xiangfu@qi-hardware.com> |
| 4 | * Marek Lindner <lindner_marek@yahoo.de> |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef __INGENIC_USB_H__ |
| 21 | #define __INGENIC_USB_H__ |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | #include "usb_boot_defines.h" |
| 25 | |
| 26 | #define INGENIC_OUT_ENDPOINT 0x01 |
| 27 | #define INGENIC_IN_ENDPOINT 0x81 |
| 28 | |
| 29 | #define VR_GET_CPU_INFO 0x00 |
| 30 | #define VR_SET_DATA_ADDRESS 0x01 |
| 31 | #define VR_SET_DATA_LENGTH 0x02 |
| 32 | #define VR_FLUSH_CACHES 0x03 |
| 33 | #define VR_PROGRAM_START1 0x04 |
| 34 | #define VR_PROGRAM_START2 0x05 |
| 35 | #define VR_NOR_OPS 0x06 |
| 36 | #define VR_NAND_OPS 0x07 |
| 37 | #define VR_SDRAM_OPS 0x08 |
| 38 | #define VR_CONFIGURATION 0x09 |
| 39 | #define VR_MEM_OPS 0x0a |
| 40 | #define VR_GET_NUM 0x0b |
| 41 | |
| 42 | #define STAGE_ADDR_MSB(addr) ((addr) >> 16) |
| 43 | #define STAGE_ADDR_LSB(addr) ((addr) & 0xffff) |
| 44 | |
| 45 | #define USB_PACKET_SIZE 512 |
| 46 | #define USB_TIMEOUT 5000 |
| 47 | |
| 48 | #define VENDOR_ID 0x601a |
| 49 | #define PRODUCT_ID 0x4740 |
| 50 | |
| 51 | #define STAGE1_FILE_PATH "/usr/share/xburst-tools/xburst_stage1.bin" |
| 52 | #define STAGE2_FILE_PATH "/usr/share/xburst-tools/xburst_stage2.bin" |
| 53 | |
| 54 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 55 | |
| 56 | struct ingenic_dev { |
| 57 | struct usb_device *usb_dev; |
| 58 | struct usb_dev_handle *usb_handle; |
| 59 | uint8_t interface; |
| 60 | |
| 61 | struct hand config; |
| 62 | }; |
| 63 | |
| 64 | enum ingenic_cpu_type { |
| 65 | INGENIC_CPU_UNKOWN, |
| 66 | INGENIC_CPU_JZ4740V1, |
| 67 | INGENIC_CPU_JZ4750V1, |
| 68 | INGENIC_CPU_JZ4740, |
| 69 | INGENIC_CPU_JZ4750, |
| 70 | }; |
| 71 | |
| 72 | int usb_ingenic_init(struct ingenic_dev *ingenic_dev); |
| 73 | int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev); |
| 74 | int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage, const char *buf, int size); |
| 75 | void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev); |
| 76 | int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops); |
| 77 | int usb_ingenic_mem_ops(struct ingenic_dev *ingenic_dev, int ops); |
| 78 | int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, |
| 79 | unsigned int stage_addr); |
| 80 | int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, |
| 81 | uint32_t len); |
| 82 | int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev, const char *data, |
| 83 | int size); |
| 84 | int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev, char *buffer, |
| 85 | int size); |
| 86 | int usb_ingenic_start(struct ingenic_dev *ingenic_dev, int rqst, int stage_addr); |
| 87 | int usb_ingenic_sdram_ops(struct ingenic_dev *ingenic_dev, int ops); |
| 88 | int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops); |
| 89 | int usb_ingenic_flush_cache(struct ingenic_dev *ingenic_dev); |
| 90 | |
| 91 | #endif /* __INGENIC_USB_H__ */ |
| 92 | |
| 93 | |