2 * Copyright (C) 2009 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include "usb-hs-otg.h"
25 #ifdef CONFIG_S5PC1XXFB
29 static char tx_data[8] = "MPL";
30 static long tx_len = 4;
32 static char rx_data[2048];
33 static long rx_len = 64;
35 extern int s5p_receive_done;
36 extern int s5p_usb_connected;
39 static int __usb_board_init(void)
44 int usb_board_init(void) __attribute__((weak, alias("__usb_board_init")));
46 extern int s5p_no_lcd_support(void);
48 /* clear download informations */
49 static void s5p_usb_clear_dnfile_info(void)
56 /* clear upload informations */
57 static void s5p_usb_clear_upfile_info(void)
64 /* start the usb controller */
65 static void usb_init(void)
67 if (usb_board_init()) {
68 printf("Failed to usb_board_init\n");
72 #ifdef CONFIG_S5PC1XXFB
73 if (!s5p_no_lcd_support()) {
75 set_font_color(FONT_WHITE);
76 fb_printf("Ready to USB Connection\n");
83 printf("USB Start!! - %s Speed\n",
84 otg.speed ? "Full" : "High");
86 while (!s5p_usb_connected) {
87 if (s5p_usb_detect_irq()) {
93 s5p_usb_clear_dnfile_info();
95 printf("Connected!!\n");
97 #ifdef CONFIG_S5PC1XXFB
98 if (!s5p_no_lcd_support()) {
99 fb_printf("Download Start\n");
100 draw_progress(40, 0, FONT_WHITE);
105 static void usb_stop(void)
108 #ifdef CONFIG_S5PC1XXFB
109 if (!s5p_no_lcd_support()) {
112 /* it uses fb3 as default window. */
113 s5pc_fimd_lcd_off(3);
114 s5pc_fimd_window_off(3);
120 * receive the packet from host PC
121 * return received size
123 static int usb_receive_packet(void)
126 if (s5p_usb_detect_irq()) {
131 if (s5p_receive_done) {
132 s5p_receive_done = 0;
133 return otg.dn_filesize;
138 /* setup the download informations */
139 static void recv_setup(char *addr, int len)
141 s5p_usb_clear_dnfile_info();
143 otg.dn_addr = (u32)addr;
144 otg.dn_ptr = (u8 *) addr;
145 otg.dn_filesize = len;
148 #ifdef CONFIG_GENERIC_MMC
150 extern int s5p_no_mmc_support(void);
152 static void usbd_set_mmc_dev(struct usbd_ops *usbd)
156 if (s5p_no_mmc_support())
161 usbd->mmc_max = 0x8000;
163 mmc = find_mmc_device(usbd->mmc_dev);
166 usbd->mmc_blk = mmc->read_bl_len;
168 if (mmc->high_capacity)
169 usbd->mmc_total = mmc->capacity;
171 usbd->mmc_total = mmc->capacity / mmc->read_bl_len;
175 #ifdef CONFIG_S5PC1XXFB
176 static void set_progress(int progress)
178 draw_progress(40, progress, FONT_WHITE);
182 * This function is interfaced between
183 * USB Device Controller and USB Downloader
185 struct usbd_ops *usbd_set_interface(struct usbd_ops *usbd)
187 usbd->usb_init = usb_init;
188 usbd->usb_stop = usb_stop;
189 usbd->send_data = s5p_usb_tx;
190 usbd->recv_data = usb_receive_packet;
191 usbd->recv_setup = recv_setup;
192 usbd->tx_data = tx_data;
193 usbd->rx_data = rx_data;
194 usbd->tx_len = tx_len;
195 usbd->rx_len = rx_len;
196 usbd->ram_addr = CONFIG_SYS_DOWN_ADDR;
197 #ifdef CONFIG_S5PC1XXFB
198 if (!s5p_no_lcd_support())
199 usbd->set_progress = set_progress;
201 #ifdef CONFIG_GENERIC_MMC
202 usbd_set_mmc_dev(usbd);