From 05f54abe0414a1cac1cee4de06c425aa7dd81c83 Mon Sep 17 00:00:00 2001 From: Minkyu Kang Date: Mon, 15 Nov 2010 17:35:53 +0900 Subject: [PATCH] s5p: support cancel the download mode s5pc110 didn't work. Signed-off-by: Minkyu Kang --- arch/arm/cpu/armv7/s5p-common/usb_downloader.c | 53 ++++- board/samsung/universal_c110/universal.c | 260 +++++++++++++------------ board/samsung/universal_c210/universal.c | 87 +++++---- common/cmd_usbd.c | 8 +- include/usbd.h | 4 +- 5 files changed, 245 insertions(+), 167 deletions(-) diff --git a/arch/arm/cpu/armv7/s5p-common/usb_downloader.c b/arch/arm/cpu/armv7/s5p-common/usb_downloader.c index 5b64691..87cc00c 100644 --- a/arch/arm/cpu/armv7/s5p-common/usb_downloader.c +++ b/arch/arm/cpu/armv7/s5p-common/usb_downloader.c @@ -31,6 +31,7 @@ static char tx_data[TX_DATA_LEN] = "MPL"; static char rx_data[RX_DATA_LEN]; +static int downloading; extern int s5p_receive_done; extern int s5p_usb_connected; @@ -47,6 +48,7 @@ extern int s5p_no_lcd_support(void); extern void s5pc_fimd_lcd_off(unsigned int win_id); extern void s5pc_fimd_window_off(unsigned int win_id); extern void get_rev_info(char *rev_info); +extern int check_exit_key(void); #ifdef CONFIG_GENERIC_MMC #include @@ -100,11 +102,11 @@ static void s5p_usb_clear_dnfile_info(void) } /* start the usb controller */ -static void usb_init(void) +static int usb_init(void) { if (usb_board_init()) { puts("Failed to usb_board_init\n"); - return; + return 0; } #ifdef CONFIG_S5PC1XXFB @@ -125,7 +127,8 @@ static void usb_init(void) fb_printf("\n"); #endif - fb_printf("Ready to USB Connection\n"); + fb_printf("USB Download Mode\n"); + fb_printf("Press the POWERKEY to CANCEL the downloading\n"); } #endif @@ -139,31 +142,54 @@ static void usb_init(void) s5p_udc_int_hndlr(); s5p_usb_clear_irq(); } + + if (check_exit_key()) + return 0; } s5p_usb_clear_dnfile_info(); puts("Connected!!\n"); + return 1; +} + +static void usb_stop(void) +{ +#ifdef CONFIG_S5PC1XXFB + if (!s5p_no_lcd_support()) { + exit_font(); + + /* it uses fb3 as default window. */ + s5pc_fimd_lcd_off(3); + s5pc_fimd_window_off(3); + } +#endif +} + +static void down_start(void) +{ + downloading = 1; + #ifdef CONFIG_S5PC1XXFB if (!s5p_no_lcd_support()) { fb_printf("Download Start\n"); - draw_progress(80, 0, FONT_WHITE); + draw_progress(95, 0, FONT_WHITE); } #endif } -static void usb_stop(void) +static void down_cancel(void) { #ifdef CONFIG_S5PC1XXFB if (!s5p_no_lcd_support()) { exit_font(); - /* it uses fb3 as default window. */ - s5pc_fimd_lcd_off(3); - s5pc_fimd_window_off(3); + /* clear fb */ + fb_clear(100); } #endif + run_command("run ubifsboot", 0); } /* @@ -182,6 +208,11 @@ static int usb_receive_packet(void) s5p_receive_done = 0; return otg.dn_filesize; } + + if (!downloading) { + if (check_exit_key()) + return 0; + } } } @@ -198,9 +229,10 @@ static void recv_setup(char *addr, int len) #ifdef CONFIG_S5PC1XXFB static void set_progress(int progress) { - draw_progress(80, progress, FONT_WHITE); + draw_progress(95, progress, FONT_WHITE); } #endif + /* * This function is interfaced between * USB Device Controller and USB Downloader @@ -217,6 +249,8 @@ struct usbd_ops *usbd_set_interface(struct usbd_ops *usbd) usbd->tx_len = TX_DATA_LEN; usbd->rx_len = RX_DATA_LEN; usbd->ram_addr = CONFIG_SYS_DOWN_ADDR; + usbd->down_cancel = down_cancel; + usbd->down_start = down_start; #ifdef CONFIG_S5PC1XXFB if (!s5p_no_lcd_support()) usbd->set_progress = set_progress; @@ -224,6 +258,7 @@ struct usbd_ops *usbd_set_interface(struct usbd_ops *usbd) #ifdef CONFIG_GENERIC_MMC usbd_set_mmc_dev(usbd); #endif + downloading = 0; return usbd; } diff --git a/board/samsung/universal_c110/universal.c b/board/samsung/universal_c110/universal.c index 6ed5cfa..5e0b4b4 100644 --- a/board/samsung/universal_c110/universal.c +++ b/board/samsung/universal_c110/universal.c @@ -870,127 +870,6 @@ static void setup_media_gpios(void) gpio_set_pull(&gpio->h3, 4, GPIO_PULL_UP); } -static int power_key_check(void) -{ - unsigned char addr, val[2]; - - addr = 0xCC >> 1; - i2c_set_bus_num(I2C_PMIC); - - if (i2c_probe(addr)) { - puts("Can't found max8998\n"); - return 1; - } - - /* power_key check */ - i2c_read(addr, 0x00, 1, val, 1); - return val[0] & (1 << 7); -} - -#define KBR3 (1 << 3) -#define KBR2 (1 << 2) -#define KBR1 (1 << 1) -#define KBR0 (1 << 0) - -static void check_keypad(void) -{ - unsigned int reg, value; - unsigned int col_num, row_num; - unsigned int col_mask; - unsigned int col_mask_shift; - unsigned int row_state[4]; - unsigned int i, power_key; - unsigned int auto_download = 0; - - if (mach_is_wmg160()) - return; - - if (board_is_limo_real() || board_is_limo_universal()) { - row_num = 2; - col_num = 3; - } else { - row_num = 4; - col_num = 4; - } - - for (i = 0; i < row_num; i++) { - if (board_is_sdk() && - (hwrevision(3) || hwrevision(4)) && i == 0) - continue; - - /* Set GPH3[3:0] to KP_ROW[3:0] */ - gpio_cfg_pin(&gpio->h3, i, 0x3); - gpio_set_pull(&gpio->h3, i, GPIO_PULL_UP); - } - - for (i = 0; i < col_num; i++) - /* Set GPH2[3:0] to KP_COL[3:0] */ - gpio_cfg_pin(&gpio->h2, i, 0x3); - - reg = S5PC110_KEYPAD_BASE; - col_mask = S5PC110_KEYIFCOLEN_MASK; - col_mask_shift = 8; - - /* KEYIFCOL reg clear */ - writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); - - /* power_key check */ - power_key = power_key_check(); - - /* key_scan */ - for (i = 0; i < col_num; i++) { - value = col_mask; - value &= ~(1 << i) << col_mask_shift; - - writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET); - udelay(1000); - - value = readl(reg + S5PC1XX_KEYIFROW_OFFSET); - row_state[i] = ~value & ((1 << row_num) - 1); - } - - /* KEYIFCOL reg clear */ - writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); - - if (mach_is_aquila() || mach_is_goni()) { - /* volume down */ - if (row_state[1] & 0x2) - display_info = 1; - if (board_is_sdk() && hwrevision(0)) { - /* home & volume down - * or hold key & volume down*/ - if ((power_key || (row_state[1] & 0x1)) - && (row_state[1] & 0x2)) - auto_download = 1; - } else if (board_is_sdk() && hwrevision(2)) { - /* cam full shot & volume down - * or hold key & volume down */ - if ((power_key || (row_state[1] & 0x6)) - && (row_state[2] & 0x4)) - auto_download = 1; - } else if (board_is_sdk() && (hwrevision(3) || hwrevision(4) || - hwrevision(6))) { - /* cam full shot & volume down - * or hold key & volume down */ - if ((power_key || (row_state[1] & 0x6)) - && (row_state[2] & 0x4)) - auto_download = 1; - } else { - /* cam full shot & volume down - * or hold key & volume down */ - if ((power_key || (row_state[0] & 0x1)) - && (row_state[1] & 0x2)) - auto_download = 1; - } - } else if (mach_is_geminus()) - /* volume down & home or hold key & volume down */ - if ((row_state[1] & 0x2) && ((power_key || row_state[2] & 0x1))) - auto_download = 1; - - if (auto_download) - setenv("bootcmd", "usbdown"); -} - static void check_battery(int mode) { unsigned char val[2]; @@ -1102,6 +981,23 @@ static void max8998_clear_interrupt(void) i2c_read(addr, 0x03, 1, val, 1); } +static int poweron_key_check(void) +{ + unsigned char addr, val[2]; + + addr = 0xCC >> 1; + if (max8998_probe()) + return 0; + + i2c_read(addr, 0x02, 1, val, 1); + return val[0] & 0x1; +} + +int check_exit_key(void) +{ + return poweron_key_check(); +} + static int max8998_power_key(void) { unsigned char addr, val[2]; @@ -1118,6 +1014,125 @@ static int max8998_power_key(void) return 0; } +static int power_key_check(void) +{ + unsigned char addr, val[2]; + + addr = 0xCC >> 1; + + if (max8998_probe()) + return 0; + + /* power_key check */ + i2c_read(addr, 0x00, 1, val, 1); + return val[0] & (1 << 7); +} + +#define KBR3 (1 << 3) +#define KBR2 (1 << 2) +#define KBR1 (1 << 1) +#define KBR0 (1 << 0) + +static void check_keypad(void) +{ + unsigned int reg, value; + unsigned int col_num, row_num; + unsigned int col_mask; + unsigned int col_mask_shift; + unsigned int row_state[4]; + unsigned int i, power_key; + unsigned int auto_download = 0; + + if (mach_is_wmg160()) + return; + + if (board_is_limo_real() || board_is_limo_universal()) { + row_num = 2; + col_num = 3; + } else { + row_num = 4; + col_num = 4; + } + + for (i = 0; i < row_num; i++) { + if (board_is_sdk() && + (hwrevision(3) || hwrevision(4)) && i == 0) + continue; + + /* Set GPH3[3:0] to KP_ROW[3:0] */ + gpio_cfg_pin(&gpio->h3, i, 0x3); + gpio_set_pull(&gpio->h3, i, GPIO_PULL_UP); + } + + for (i = 0; i < col_num; i++) + /* Set GPH2[3:0] to KP_COL[3:0] */ + gpio_cfg_pin(&gpio->h2, i, 0x3); + + reg = S5PC110_KEYPAD_BASE; + col_mask = S5PC110_KEYIFCOLEN_MASK; + col_mask_shift = 8; + + /* KEYIFCOL reg clear */ + writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); + + /* power_key check */ + power_key = power_key_check(); + + /* key_scan */ + for (i = 0; i < col_num; i++) { + value = col_mask; + value &= ~(1 << i) << col_mask_shift; + + writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET); + udelay(1000); + + value = readl(reg + S5PC1XX_KEYIFROW_OFFSET); + row_state[i] = ~value & ((1 << row_num) - 1); + } + + /* KEYIFCOL reg clear */ + writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); + + if (mach_is_aquila() || mach_is_goni()) { + /* volume down */ + if (row_state[1] & 0x2) + display_info = 1; + if (board_is_sdk() && hwrevision(0)) { + /* home & volume down + * or hold key & volume down*/ + if ((power_key || (row_state[1] & 0x1)) + && (row_state[1] & 0x2)) + auto_download = 1; + } else if (board_is_sdk() && hwrevision(2)) { + /* cam full shot & volume down + * or hold key & volume down */ + if ((power_key || (row_state[1] & 0x6)) + && (row_state[2] & 0x4)) + auto_download = 1; + } else if (board_is_sdk() && (hwrevision(3) || hwrevision(4) || + hwrevision(6))) { + /* cam full shot & volume down + * or hold key & volume down */ + if ((power_key || (row_state[1] & 0x6)) + && (row_state[2] & 0x4)) + auto_download = 1; + } else { + /* cam full shot & volume down + * or hold key & volume down */ + if ((power_key || (row_state[0] & 0x1)) + && (row_state[1] & 0x2)) + auto_download = 1; + } + } else if (mach_is_geminus()) + /* volume down & home or hold key & volume down */ + if ((row_state[1] & 0x2) && ((power_key || row_state[2] & 0x1))) + auto_download = 1; + + if (auto_download) + setenv("bootcmd", "usbdown"); +} + + static int max8998_has_ext_power_source(void) { unsigned char addr, val[2]; @@ -2854,6 +2869,9 @@ int board_eth_init(bd_t *bis) #ifdef CONFIG_CMD_USBDOWN int usb_board_init(void) { + /* interrupt clear */ + poweron_key_check(); + #ifdef CONFIG_CMD_PMIC run_command("pmic ldo 8 on", 0); run_command("pmic ldo 3 on", 0); diff --git a/board/samsung/universal_c210/universal.c b/board/samsung/universal_c210/universal.c index a2bb4dc..04d9ab8 100644 --- a/board/samsung/universal_c210/universal.c +++ b/board/samsung/universal_c210/universal.c @@ -252,39 +252,6 @@ static void check_auto_burn(void) memset((void *)magic_base, 0, 2); } -static int power_key_check(void) -{ - unsigned char addr, val[2]; - - addr = 0xCC >> 1; - i2c_set_bus_num(I2C_5); - - if (i2c_probe(addr)) { - puts("Can't found lp3974\n"); - return 1; - } - - /* power_key check */ - i2c_read(addr, 0x00, 1, val, 1); - return (~val[0] & (1 << 6)) >> 6; -} - -static void check_keypad(void) -{ - unsigned int val = 0; - unsigned int power_key, auto_download = 0; - - val = ~(gpio_get_value(&gpio2->x2, 1)); - - power_key = power_key_check(); - - if (power_key && (val & 0x1)) - auto_download = 1; - - if (auto_download) - setenv("bootcmd", "usbdown"); -} - static void check_battery(int mode) { unsigned char val[2]; @@ -415,11 +382,14 @@ static void micro_usb_switch(int path) i2c_write(addr, 0x2, 1, val, 1); } +#define LP3974_REG_IRQ1 0x00 +#define LP3974_REG_IRQ2 0x01 +#define LP3974_REG_IRQ3 0x02 #define LP3974_REG_ONOFF1 0x11 #define LP3974_REG_ONOFF2 0x12 #define LP3974_REG_ONOFF3 0x13 #define LP3974_REG_ONOFF4 0x14 -#define LP3974_REG_LDO7 0x21 +#define LP3974_REG_LDO7 0x21 #define LP3974_REG_LDO17 0x29 #define LP3974_REG_UVLO 0xB9 #define LP3974_REG_MODCHG 0xEF @@ -637,6 +607,52 @@ static void init_pmic_lp3974(void) i2c_write(addr, LP3974_REG_MODCHG, 1, val, 1); } +static int poweron_key_check(void) +{ + unsigned char addr, val[2]; + + addr = 0xCC >> 1; + if (lp3974_probe()) + return 0; + + i2c_read_r(addr, LP3974_REG_IRQ3, 1, val, 1); + return val[0] & 0x1; +} + +int check_exit_key(void) +{ + return poweron_key_check(); +} + +static int power_key_check(void) +{ + unsigned char addr, val[2]; + + addr = 0xCC >> 1; + if (lp3974_probe()) + return -1; + + /* power_key check */ + i2c_read_r(addr, LP3974_REG_IRQ1, 1, val, 1); + return (~val[0] & (1 << 6)) >> 6; +} + +static void check_keypad(void) +{ + unsigned int val = 0; + unsigned int power_key, auto_download = 0; + + val = ~(gpio_get_value(&gpio2->x2, 1)); + + power_key = power_key_check(); + + if (power_key && (val & 0x1)) + auto_download = 1; + + if (auto_download) + setenv("bootcmd", "usbdown"); +} + /* * charger_en(): set lp3974 pmic's charger mode * enable 0: disable charger @@ -1266,6 +1282,9 @@ int misc_init_r(void) #ifdef CONFIG_CMD_USBDOWN int usb_board_init(void) { + /* interrupt clear */ + poweron_key_check(); + #ifdef CONFIG_CMD_PMIC run_command("pmic ldo 8 on", 0); run_command("pmic ldo 3 on", 0); diff --git a/common/cmd_usbd.c b/common/cmd_usbd.c index aa7c516..2ea2bbd 100644 --- a/common/cmd_usbd.c +++ b/common/cmd_usbd.c @@ -1251,7 +1251,10 @@ int do_usbd_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) down_ram_addr = usbd->ram_addr; /* init the usb controller */ - usbd->usb_init(); + if (!usbd->usb_init()) { + usbd->down_cancel(); + return 0; + } /* receive setting */ usbd->recv_setup(usbd->rx_data, usbd->rx_len); @@ -1269,10 +1272,11 @@ int do_usbd_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 0; } } else { - printf("No download request from the Host PC!!\n"); + usbd->down_cancel(); return 0; } + usbd->down_start(); printf("Receive the packet\n"); /* receive the data from Host PC */ diff --git a/include/usbd.h b/include/usbd.h index 2728ee5..7e93de6 100644 --- a/include/usbd.h +++ b/include/usbd.h @@ -98,7 +98,7 @@ enum { * mmc_total : mmc total blocks */ struct usbd_ops { - void (*usb_init)(void); + int (*usb_init)(void); void (*usb_stop)(void); void (*send_data)(char *, int); int (*recv_data)(void); @@ -117,6 +117,8 @@ struct usbd_ops { void (*set_progress)(int); void (*cpu_reset)(void); + void (*down_start)(void); + void (*down_cancel)(void); }; /* This function is interfaced between USB Device Controller and USB Downloader -- 2.7.4