From: Minkyu Kang Date: Thu, 20 Jan 2011 05:26:19 +0000 (+0900) Subject: max8998: move power key check routines X-Git-Tag: v0.2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a77bba3a5ca264c0bbcc6e432b952d63259d88c9;p=kernel%2Fu-boot.git max8998: move power key check routines Signed-off-by: Minkyu Kang --- diff --git a/board/samsung/universal_c110/universal.c b/board/samsung/universal_c110/universal.c index 27929b2..1731d8f 100644 --- a/board/samsung/universal_c110/universal.c +++ b/board/samsung/universal_c110/universal.c @@ -1005,51 +1005,9 @@ 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]; - addr = 0xCC >> 1; - - if (max8998_probe()) - return 0; - - /* Accessing IRQ1 register */ - i2c_read(addr, 0x00, 1, val, 1); - if (val[0] & (1 << 6)) - return 1; - - 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); + return pmic_get_irq(PWRON1S); } #define KBR3 (1 << 3) @@ -1100,7 +1058,7 @@ static void check_keypad(void) writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET); /* power_key check */ - power_key = power_key_check(); + power_key = pmic_get_irq(PWRONR); /* key_scan */ for (i = 0; i < col_num; i++) { @@ -1388,7 +1346,7 @@ static void into_charge_mode(void) free(bmp); for (k = 0; k < 10; k++) { - if (max8998_power_key()) { + if (pmic_get_irq(PWRONF)) { lcd_display_clear(); goto restore_screen; } else if (!max8998_has_ext_power_source()) { @@ -1411,7 +1369,7 @@ static void into_charge_mode(void) unsigned int org, org_ip3; empty_device_info_buffer(); - if (max8998_power_key()) + if (pmic_get_irq(PWRONF)) break; else if (!max8998_has_ext_power_source()) break; @@ -2523,13 +2481,13 @@ int misc_init_r(void) /* Setup Media board GPIOs */ setup_media_gpios(); - /* To usbdown automatically */ - check_keypad(); - /* check max8998 */ pmic_bus_init(I2C_PMIC); init_pmic(); + /* To usbdown automatically */ + check_keypad(); + #ifdef CONFIG_S5PC1XXFB display_device_info(); #endif @@ -2884,7 +2842,7 @@ struct ums_board_info *board_ums_init(void) int usb_board_init(void) { /* interrupt clear */ - poweron_key_check(); + pmic_get_irq(PWRON1S); #ifdef CONFIG_CMD_PMIC run_command("pmic ldo 8 on", 0); diff --git a/board/samsung/universal_c210/universal.c b/board/samsung/universal_c210/universal.c index 0dacb53..bde23b5 100644 --- a/board/samsung/universal_c210/universal.c +++ b/board/samsung/universal_c210/universal.c @@ -604,38 +604,9 @@ 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[4]; - int tmp; - - addr = 0xCC >> 1; - if (lp3974_probe()) - return -1; - - /* power_key check */ - i2c_read_r(addr, LP3974_REG_IRQ1, 1, val, 4); - - tmp = ((val[0] & (1 << 7)) >> 7); - - return tmp; + return pmic_get_irq(PWRON1S); } static void check_keypad(void) @@ -645,7 +616,7 @@ static void check_keypad(void) val = ~(gpio_get_value(&gpio2->x2, 1)); - power_key = power_key_check(); + power_key = pmic_get_irq(PWRONR); if (power_key && (val & 0x1)) auto_download = 1; @@ -1189,6 +1160,9 @@ int misc_init_r(void) #endif show_hw_revision(); + + pmic_bus_init(I2C_5); + check_keypad(); check_auto_burn(); @@ -1204,7 +1178,6 @@ int misc_init_r(void) #endif #ifdef CONFIG_CMD_PMIC - pmic_bus_init(I2C_5); run_command("pmic ldo 4 off", 0); /* adc off */ #endif @@ -1216,7 +1189,7 @@ int misc_init_r(void) int usb_board_init(void) { /* interrupt clear */ - poweron_key_check(); + pmic_get_irq(PWRON1S); #ifdef CONFIG_CMD_PMIC run_command("pmic ldo 8 on", 0); diff --git a/drivers/misc/max8998.c b/drivers/misc/max8998.c index 2dd4ad6..dfd9f2b 100644 --- a/drivers/misc/max8998.c +++ b/drivers/misc/max8998.c @@ -8,6 +8,7 @@ #include #include +#include unsigned int pmic_bus; @@ -38,6 +39,41 @@ static int pmic_probe(void) i2c_read(addr, reg, alen, val, len) #endif +unsigned int pmic_get_irq(int irq) +{ + unsigned char addr, val[4]; + unsigned int ret; + unsigned int reg; + unsigned int shift; + + addr = 0xCC >> 1; + if (pmic_probe()) + return 0; + + switch (irq) { + case PWRONR: + reg = 0; + shift = 7; + break; + case PWRONF: + reg = 0; + shift = 6; + break; + case PWRON1S: + reg = 2; + shift = 0; + break; + default: + return 0; + } + + i2c_read_func(addr, 0x0, 1, val, 4); + + ret = val[reg] & (1 << shift); + + return !!ret; +} + static int pmic_status(void) { unsigned char addr, val[2]; diff --git a/include/pmic.h b/include/pmic.h index dcaaf36..09f3319 100644 --- a/include/pmic.h +++ b/include/pmic.h @@ -4,4 +4,11 @@ * Kyungmin Park */ +enum { + PWRONR, + PWRONF, + PWRON1S, +}; + +unsigned int pmic_get_irq(int irq); void pmic_bus_init(int bus_num);