Merge branch 'agust@denx.de' of git://git.denx.de/u-boot-staging
[platform/kernel/u-boot.git] / board / samsung / trats / trats.c
index 2359a99..e540190 100644 (file)
@@ -39,6 +39,8 @@
 #include <power/max8997_pmic.h>
 #include <libtizen.h>
 #include <power/max8997_muic.h>
+#include <power/battery.h>
+#include <power/max17042_fg.h>
 
 #include "setup.h"
 
@@ -87,6 +89,64 @@ void i2c_init_board(void)
        s5p_gpio_direction_output(&gpio2->y4, 1, 1);
 }
 
+static void trats_low_power_mode(void)
+{
+       struct exynos4_clock *clk =
+           (struct exynos4_clock *)samsung_get_base_clock();
+       struct exynos4_power *pwr =
+           (struct exynos4_power *)samsung_get_base_power();
+
+       /* Power down CORE1 */
+       /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
+       writel(0x0, &pwr->arm_core1_configuration);
+
+       /* Change the APLL frequency */
+       /* ENABLE (1 enable) | LOCKED (1 locked)  */
+       /* [31]              | [29]               */
+       /* FSEL      | MDIV          | PDIV            | SDIV */
+       /* [27]      | [25:16]       | [13:8]          | [2:0]      */
+       writel(0xa0c80604, &clk->apll_con0);
+
+       /* Change CPU0 clock divider */
+       /* CORE2_RATIO  | APLL_RATIO   | PCLK_DBG_RATIO | ATB_RATIO  */
+       /* [30:28]      | [26:24]      | [22:20]        | [18:16]    */
+       /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO   | CORE_RATIO */
+       /* [14:12]      | [10:8]       | [6:4]          | [2:0]      */
+       writel(0x00000100, &clk->div_cpu0);
+
+       /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */
+       while (readl(&clk->div_stat_cpu0) & 0x1111111)
+               continue;
+
+       /* Change clock divider ratio for DMC */
+       /* DMCP_RATIO                  | DMCD_RATIO  */
+       /* [22:20]                     | [18:16]     */
+       /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO   | ACP_RATIO */
+       /* [14:12]   | [10:8]     | [6:4]            | [2:0]     */
+       writel(0x13113117, &clk->div_dmc0);
+
+       /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */
+       while (readl(&clk->div_stat_dmc0) & 0x11111111)
+               continue;
+
+       /* Turn off unnecessary power domains */
+       writel(0x0, &pwr->xxti_configuration);  /* XXTI */
+       writel(0x0, &pwr->cam_configuration);   /* CAM */
+       writel(0x0, &pwr->tv_configuration);    /* TV */
+       writel(0x0, &pwr->mfc_configuration);   /* MFC */
+       writel(0x0, &pwr->g3d_configuration);   /* G3D */
+       writel(0x0, &pwr->gps_configuration);   /* GPS */
+       writel(0x0, &pwr->gps_alive_configuration);     /* GPS_ALIVE */
+
+       /* Turn off unnecessary clocks */
+       writel(0x0, &clk->gate_ip_cam); /* CAM */
+       writel(0x0, &clk->gate_ip_tv);          /* TV */
+       writel(0x0, &clk->gate_ip_mfc); /* MFC */
+       writel(0x0, &clk->gate_ip_g3d); /* G3D */
+       writel(0x0, &clk->gate_ip_image);       /* IMAGE */
+       writel(0x0, &clk->gate_ip_gps); /* GPS */
+}
+
 static int pmic_init_max8997(void)
 {
        struct pmic *p = pmic_get("MAX8997_PMIC");
@@ -238,14 +298,63 @@ static int pmic_init_max8997(void)
 
 int power_init_board(void)
 {
-       int ret;
+       int chrg, ret;
+       struct power_battery *pb;
+       struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
 
        ret = pmic_init(I2C_5);
        ret |= pmic_init_max8997();
+       ret |= power_fg_init(I2C_9);
        ret |= power_muic_init(I2C_5);
+       ret |= power_bat_init(0);
        if (ret)
                return ret;
 
+       p_fg = pmic_get("MAX17042_FG");
+       if (!p_fg) {
+               puts("MAX17042_FG: Not found\n");
+               return -ENODEV;
+       }
+
+       p_chrg = pmic_get("MAX8997_PMIC");
+       if (!p_chrg) {
+               puts("MAX8997_PMIC: Not found\n");
+               return -ENODEV;
+       }
+
+       p_muic = pmic_get("MAX8997_MUIC");
+       if (!p_muic) {
+               puts("MAX8997_MUIC: Not found\n");
+               return -ENODEV;
+       }
+
+       p_bat = pmic_get("BAT_TRATS");
+       if (!p_bat) {
+               puts("BAT_TRATS: Not found\n");
+               return -ENODEV;
+       }
+
+       p_fg->parent =  p_bat;
+       p_chrg->parent = p_bat;
+       p_muic->parent = p_bat;
+
+       p_bat->low_power_mode = trats_low_power_mode;
+       p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
+
+       pb = p_bat->pbat;
+       chrg = p_muic->chrg->chrg_type(p_muic);
+       debug("CHARGER TYPE: %d\n", chrg);
+
+       if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
+               puts("No battery detected\n");
+               return -1;
+       }
+
+       p_fg->fg->fg_battery_check(p_fg, p_bat);
+
+       if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
+               puts("CHARGE Battery !\n");
+
        return 0;
 }