於 三,2008-03-05 於 23:26 +0800,Andy Green 提到:
> -----BEGIN PGP SIGNED MESSAGE-----
> 
> Luckily I sent Wolfgang the list of jobs from my whiteboard last week
> before I cleared it down on leaving, covering most of this sudden onset
> of concern.  So make sure you have a nice holiday free of worry that
> nobody will be doing actual work.
        Hi Andy,

        Attached file is the patch for initial power setting. Basically, it's
necessary to check the following conditions are satisfied with boot up. 

        1. According to the charger source, PMU can provide correct the
limitation charger current. 
        2. Battery voltage is save to boot.  

        But I think you might have some thoughts on this. 
        Please let me know if you have any ideas about this patch. 

        Cheers,

        Matt
> 
> - -Andy
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (GNU/Linux)
> Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
> 
> iD8DBQFHzruSOjLpvpq7dMoRAquQAJ49nyNqhCWuOWuFia1h/PcOAlNfqACfTfSj
> NoXF7/m2tjAgHS+IuEiKoTw=
> =aNg9
> -----END PGP SIGNATURE-----
> 
> 
Index: u-boot/board/neo1973/gta02/gta02.c
===================================================================
--- u-boot.orig/board/neo1973/gta02/gta02.c	2008-03-06 14:53:54.000000000 +0800
+++ u-boot/board/neo1973/gta02/gta02.c	2008-03-06 17:57:40.000000000 +0800
@@ -44,6 +44,7 @@
 
 /* That many seconds the power key needs to be pressed to power up */
 #define POWER_KEY_SECONDS	2
+#define SAVE_POWER_VOLT    	3600
 
 #if defined(CONFIG_ARCH_GTA02_v1)
 //#define M_MDIV	0x7f		/* Fout = 405.00MHz */
@@ -236,17 +237,24 @@
 	char buf[32];
 	int menu_vote = 0; /* <= 0: no, > 0: yes */
 	int seconds = 0;
+	uint8_t power_cond = 0;
+
+	/* switch on one of the power led's */
+	neo1973_led(GTA02_LED_AUX_RED, 1);
 
 	/* Initialize the Power Management Unit with a safe register set */
-	pcf50633_init();
+	//pcf50633_init();
+	while (!power_cond){
+		if (pcf50633_init() > 100)
+			power_cond |=1;
+		/* make sure the voltage is safe to boot */
+		power_cond |= (pcf50633_read_battvolt() > SAVE_POWER_VOLT);
+	}
 
 	/* obtain wake-up reason */
 	int1 = pcf50633_reg_read(PCF50633_REG_INT1);
 	int2 = pcf50633_reg_read(PCF50633_REG_INT2);
 
-	/* switch on one of the power led's */
-	neo1973_led(GTA02_LED_PWR_ORANGE, 1);
-
 	/* issue a short pulse with the vibrator */
 	neo1973_vibrator(1);
 	udelay(20000);
@@ -511,4 +519,5 @@
 		gpio->GPBDAT |= (1 << led);
 	else
 		gpio->GPBDAT &= ~(1 << led);
+
 }
Index: u-boot/drivers/misc/pcf50633.c
===================================================================
--- u-boot.orig/drivers/misc/pcf50633.c	2008-03-06 14:53:54.000000000 +0800
+++ u-boot/drivers/misc/pcf50633.c	2008-03-06 17:43:10.000000000 +0800
@@ -13,6 +13,8 @@
 
 #define PCF50633_I2C_ADDR		0x73
 
+extern int usbtty_configured_flag;
+
 void __pcf50633_reg_write(u_int8_t reg, u_int8_t val)
 {
 	i2c_write(PCF50633_I2C_ADDR, reg, 1, &val, 1);
@@ -111,20 +113,14 @@
 	return 0;
 }
 
-/* figure out our charger situation */
-int pcf50633_read_charger_type(void)
+static u_int16_t pcf50633_adc_read(u_int8_t channel, u_int8_t avg)
 {
 	u_int16_t ret;
 
-	/* kill ratiometric, but enable ACCSW biasing */
-	pcf50633_reg_write(PCF50633_REG_ADCC2, 0x00);
-	pcf50633_reg_write(PCF50633_REG_ADCC3, 0x01);
-
 	/* start ADC conversion of selected channel */
-	pcf50633_reg_write(PCF50633_REG_ADCC1, PCF50633_ADCC1_MUX_ADCIN1 |
-					       PCF50633_ADCC1_AVERAGE_16 |
-					       PCF50633_ADCC1_ADCSTART |
-					       PCF50633_ADCC1_RES_10BIT);
+	pcf50633_reg_write(PCF50633_REG_ADCC1, channel | avg |
+					       	PCF50633_ADCC1_ADCSTART |
+					       	PCF50633_ADCC1_RES_10BIT);
 
 	/* spin until completed */
 	while (!(pcf50633_reg_read(PCF50633_REG_ADCS3) & 0x80))
@@ -135,24 +131,54 @@
 	      (pcf50633_reg_read(PCF50633_REG_ADCS3) &
 	      PCF50633_ADCS3_ADCDAT1L_MASK);
 
+	return ret;
+}
+
+/* figure out our charger situation */
+int pcf50633_read_charger_type(void)
+{
+	u_int16_t ret;
+
+	/* kill ratiometric, but enable ACCSW biasing */
+	pcf50633_reg_write(PCF50633_REG_ADCC2, 0x00);
+	pcf50633_reg_write(PCF50633_REG_ADCC3, 0x01);
+
+	/* do ADC processing */
+	ret = pcf50633_adc_read(PCF50633_ADCC1_MUX_ADCIN1 , PCF50633_ADCC1_AVERAGE_16);
+
 	/* well it is nearest to the 1A resistor */
 	if (ret < ((ADC_NOMINAL_RES_1A + ADC_NOMINAL_RES_NC_R_USB) / 2))
 		return 1000;
 
 	/* ok all we know is there is no resistor, it can be USB pwr or none */
-	if ((pcf50633_reg_read(PCF50633_REG_MBCS1) & 0x3) == 0x3)
-		return 500; /* USB power then */
+	if ((pcf50633_reg_read(PCF50633_REG_MBCS1) & 0x3) == 0x3){
+		if(usbtty_configured_flag == 1)
+			return 500;
+		else
+			return 100;
+	}
 
 	return 0; /* nope, no power, just battery */
 }
 
+u_int16_t pcf50633_read_battvolt(void)
+{
+	u_int16_t ret;
+
+	ret = pcf50633_adc_read(PCF50633_ADCC1_MUX_BATSNS_RES, 0);
+
+	ret = (ret * 6000) / 1024;
+
+	return ret;
+}
 
 
 /* initialize PCF50633 register set */
-void pcf50633_init(void)
+int pcf50633_init(void)
 {
 	unsigned long flags;
 	u_int8_t i, limit;
+	int chg_current;
 
 	local_irq_save(flags);
 	for (i = 0; i < PCF50633_LAST_REG; i++) {
@@ -162,8 +188,10 @@
 	}
 	local_irq_restore(flags);
 
+	chg_current = pcf50633_read_charger_type();
+
 	printf("Power: ");
-	switch (pcf50633_read_charger_type()) {
+	switch (chg_current) {
 	case 0: /* no charger, battery only */
 		printf("Battery\n");
 		limit = PCF50633_MBCC7_USB_SUSPEND;
@@ -172,14 +200,19 @@
 		printf("USB / 500mA\n");
 		limit = PCF50633_MBCC7_USB_500mA;
 		break;
-	default:
+	case 1000:
 		printf("1A\n");
 		limit = PCF50633_MBCC7_USB_1000mA;
 		break;
+	default:
+		printf("USB / 100mA\n");
+		limit = PCF50633_MBCC7_USB_100mA;
 	}
 	pcf50633_reg_write(PCF50633_REG_MBCC7,
 			   (pcf50633_reg_read(PCF50633_REG_MBCC7) &
 			   (~PCF56033_MBCC7_USB_MASK)) | limit);
+
+	return chg_current;
 }
 
 void pcf50633_usb_maxcurrent(unsigned int ma)
Index: u-boot/include/pcf50633.h
===================================================================
--- u-boot.orig/include/pcf50633.h	2008-03-06 14:53:54.000000000 +0800
+++ u-boot/include/pcf50633.h	2008-03-06 14:56:44.000000000 +0800
@@ -394,7 +394,7 @@
 void pcf50633_reg_set_bit_mask(u_int8_t reg, u_int8_t mask, u_int8_t val);
 void pcf50633_reg_clear_bits(u_int8_t reg, u_int8_t bits);
 
-void pcf50633_init(void);
+int pcf50633_init(void);
 void pcf50633_usb_maxcurrent(unsigned int ma);
 
 const char *pcf50633_charger_state(void);

Reply via email to