Changeset 4229
- Timestamp:
- 03/20/08 02:04:37 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/u-boot/patches/wait-for-power-DONTUSE.patch
r4189 r4229 6 6 7 7 It makes the following changes: 8 - keeps the system from booting unless we have 500mA USB power (this is9 for testing)8 - keeps the system from booting unless we have either good battery power, 9 500mA from USB, or the wall charger supplying power 10 10 - flashes the red (AUX) LED during this 11 11 - defers initialization of the video subsystem until we're about to … … 14 14 15 15 Known issues: 16 - actually seems useless, because we don't seem to ever power up without17 a battery present anyway18 16 - still burns way too much power, see 19 17 http://people.openmoko.org/werner/wait-for-power-try1/usb-batt.html … … 23 21 --- u-boot.orig/board/neo1973/gta02/gta02.c 24 22 +++ u-boot/board/neo1973/gta02/gta02.c 25 @@ -63,6 +63,8 @@ 23 @@ -45,6 +45,9 @@ 24 /* That many seconds the power key needs to be pressed to power up */ 25 #define POWER_KEY_SECONDS 2 26 27 +/* If the battery voltage is below this, we can't provide stable power */ 28 +#define SAVE_POWER_MILLIVOLT 3600 29 + 30 #if defined(CONFIG_ARCH_GTA02_v1) 31 //#define M_MDIV 0x7f /* Fout = 405.00MHz */ 32 #define M_MDIV 0x7d /* Fout = 399.00MHz */ 33 @@ -63,6 +66,8 @@ 26 34 #define U_M_SDIV 2 27 35 #endif … … 32 40 extern unsigned char booted_from_nand; 33 41 extern unsigned char booted_from_nor; 34 @@ -229,6 +23 1,34@@42 @@ -229,6 +234,39 @@ 35 43 return 0; 36 44 } 37 45 46 +static void poll_charger(void) 47 +{ 48 + if (pcf50633_read_charger_type() == 1000) 49 + pcf50633_usb_maxcurrent(1000); 50 +} 51 + 38 52 +static void wait_for_power(void) 39 53 +{ … … 41 55 + 42 56 + while (1) { 43 +#if 044 57 + /* battery is present -> try to boot */ 45 + if (!(pcf50633_reg_read(PCF50633_REG_BVMCTL) & 1)) 58 + if (!(pcf50633_reg_read(PCF50633_REG_BVMCTL) & 1) && 59 + pcf50633_read_battvolt() >= SAVE_POWER_MILLIVOLT) 46 60 + break; 47 +#endif 48 + 49 + /* @@@FIXME: have to check ADC for external charger */ 61 + 62 + poll_charger(); 50 63 + 51 64 + /* we have plenty of external power -> try to boot */ … … 67 80 { 68 81 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); 69 @@ -236,6 +2 66,7 @@82 @@ -236,6 +274,7 @@ 70 83 char buf[32]; 71 84 int menu_vote = 0; /* <= 0: no, > 0: yes */ … … 75 88 /* Initialize the Power Management Unit with a safe register set */ 76 89 pcf50633_init(); 77 @@ -244,8 +2 75,7 @@90 @@ -244,8 +283,7 @@ 78 91 int1 = pcf50633_reg_read(PCF50633_REG_INT1); 79 92 int2 = pcf50633_reg_read(PCF50633_REG_INT2); … … 85 98 /* issue a short pulse with the vibrator */ 86 99 neo1973_vibrator(1); 87 @@ -311,9 +34 1,15 @@100 @@ -311,9 +349,15 @@ 88 101 neo1973_poweroff(); 89 102 … … 101 114 #if 0 102 115 { 103 @@ -324,7 +36 0,7 @@116 @@ -324,7 +368,7 @@ 104 117 } 105 118 #endif … … 127 140 --- u-boot.orig/drivers/misc/pcf50633.c 128 141 +++ u-boot/drivers/misc/pcf50633.c 129 @@ -175,10 +175,13 @@ 142 @@ -111,18 +111,13 @@ 143 return 0; 144 } 145 146 -/* figure out our charger situation */ 147 -int pcf50633_read_charger_type(void) 148 +static u_int16_t pcf50633_adc_read(u_int8_t channel, u_int8_t avg) 149 { 150 u_int16_t ret; 151 152 - /* kill ratiometric, but enable ACCSW biasing */ 153 - pcf50633_reg_write(PCF50633_REG_ADCC2, 0x00); 154 - pcf50633_reg_write(PCF50633_REG_ADCC3, 0x01); 155 - 156 /* start ADC conversion of selected channel */ 157 - pcf50633_reg_write(PCF50633_REG_ADCC1, PCF50633_ADCC1_MUX_ADCIN1 | 158 - PCF50633_ADCC1_AVERAGE_16 | 159 + pcf50633_reg_write(PCF50633_REG_ADCC1, channel | 160 + avg | 161 PCF50633_ADCC1_ADCSTART | 162 PCF50633_ADCC1_RES_10BIT); 163 164 @@ -135,18 +130,41 @@ 165 (pcf50633_reg_read(PCF50633_REG_ADCS3) & 166 PCF50633_ADCS3_ADCDAT1L_MASK); 167 168 + return ret; 169 +} 170 + 171 +/* figure out our charger situation */ 172 +int pcf50633_read_charger_type(void) 173 +{ 174 + u_int16_t ret; 175 + 176 + if ((pcf50633_reg_read(PCF50633_REG_MBCS1) & 0x3) != 0x3) 177 + return 0; /* no power, just battery */ 178 + 179 + /* kill ratiometric, but enable ACCSW biasing */ 180 + pcf50633_reg_write(PCF50633_REG_ADCC2, 0x00); 181 + pcf50633_reg_write(PCF50633_REG_ADCC3, 0x01); 182 + 183 + ret = pcf50633_adc_read(PCF50633_ADCC1_MUX_ADCIN1, 184 + PCF50633_ADCC1_AVERAGE_16); 185 + 186 /* well it is nearest to the 1A resistor */ 187 if (ret < ((ADC_NOMINAL_RES_1A + ADC_NOMINAL_RES_NC_R_USB) / 2)) 188 return 1000; 189 190 - /* ok all we know is there is no resistor, it can be USB pwr or none */ 191 - if ((pcf50633_reg_read(PCF50633_REG_MBCS1) & 0x3) == 0x3) 192 - return 100; /* USB power then */ 193 + /* there is no resistor, so it must be USB pwr */ 194 + return 100; /* USB power then */ 195 196 - return 0; /* nope, no power, just battery */ 197 } 198 199 +u_int16_t pcf50633_read_battvolt(void) 200 +{ 201 + u_int16_t ret; 202 + 203 + ret = pcf50633_adc_read(PCF50633_ADCC1_MUX_BATSNS_RES, 0); 204 205 + return (ret * 6000) / 1024; 206 +} 207 208 /* initialize PCF50633 register set */ 209 void pcf50633_init(void) 210 @@ -175,10 +193,13 @@ 130 211 } 131 212 } … … 167 248 168 249 u_int8_t pcf50633_reg_read(u_int8_t reg); 250 @@ -399,5 +401,8 @@ 251 252 const char *pcf50633_charger_state(void); 253 254 +int pcf50633_read_charger_type(void); 255 +u_int16_t pcf50633_read_battvolt(void); 256 + 257 #endif /* _PCF50633_H */ 258
Note: See TracChangeset
for help on using the changeset viewer.
