pmic: Extend PMIC framework to support multiple instances of PMIC devices
[oweals/u-boot.git] / board / samsung / universal_c210 / universal.c
index d0ff8341f648f3496cc14927338d0349ec134634..c4950ddc2698432c1f995c042302bc0e83b486fc 100644 (file)
 #include <asm/arch/adc.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
-#include <pmic.h>
+#include <power/pmic.h>
 #include <usb/s3c_udc.h>
 #include <asm/arch/cpu.h>
-#include <max8998_pmic.h>
+#include <power/max8998_pmic.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -58,13 +58,13 @@ int board_init(void)
        gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
 
-       check_hw_revision();
-       printf("HW Revision:\t0x%x\n", board_rev);
-
 #if defined(CONFIG_PMIC)
-       pmic_init();
+       pmic_init(I2C_5);
 #endif
 
+       check_hw_revision();
+       printf("HW Revision:\t0x%x\n", board_rev);
+
        return 0;
 }
 
@@ -109,10 +109,29 @@ static unsigned short get_adc_value(int channel)
        return ret;
 }
 
+static int adc_power_control(int on)
+{
+       int ret;
+       struct pmic *p = pmic_get("MAX8998_PMIC");
+       if (!p)
+               return -ENODEV;
+
+       if (pmic_probe(p))
+               return -1;
+
+       ret = pmic_set_output(p,
+                             MAX8998_REG_ONOFF1,
+                             MAX8998_LDO4, !!on);
+
+       return ret;
+}
+
 static unsigned int get_hw_revision(void)
 {
        int hwrev, mode0, mode1;
 
+       adc_power_control(1);
+
        mode0 = get_adc_value(1);               /* HWREV_MODE0 */
        mode1 = get_adc_value(2);               /* HWREV_MODE1 */
 
@@ -135,6 +154,8 @@ static unsigned int get_hw_revision(void)
 
        debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
 
+       adc_power_control(0);
+
        return hwrev;
 }
 
@@ -261,7 +282,9 @@ int board_mmc_init(bd_t *bis)
 static int s5pc210_phy_control(int on)
 {
        int ret = 0;
-       struct pmic *p = get_pmic();
+       struct pmic *p = pmic_get("MAX8998_PMIC");
+       if (!p)
+               return -ENODEV;
 
        if (pmic_probe(p))
                return -1;