board: samsung: trats: convert to driver model for controlling phy
authorJaehoon Chung <jh80.chung@samsung.com>
Thu, 30 Mar 2017 12:29:59 +0000 (21:29 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Mon, 3 Apr 2017 02:35:38 +0000 (11:35 +0900)
Convert to driver model for controlling phy.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
board/samsung/trats/trats.c

index fa297c3d41fa7799c41b84731dd1f22834080a9c..be5e2e271062323be1d86ec5e933f088c98b01e3 100644 (file)
@@ -23,6 +23,7 @@
 #include <power/max8997_muic.h>
 #include <power/battery.h>
 #include <power/max17042_fg.h>
+#include <power/pmic.h>
 #include <libtizen.h>
 #include <usb.h>
 #include <usb_mass_storage.h>
@@ -232,39 +233,59 @@ static void check_hw_revision(void)
 #ifdef CONFIG_USB_GADGET
 static int s5pc210_phy_control(int on)
 {
-#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
-       int ret = 0;
-       u32 val = 0;
-       struct pmic *p = pmic_get("MAX8997_PMIC");
-       if (!p)
-               return -ENODEV;
+       struct udevice *dev;
+       int reg, ret;
 
-       if (pmic_probe(p))
-               return -1;
+       ret = pmic_get("max8997-pmic", &dev);
+       if (ret)
+               return ret;
 
        if (on) {
-               ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
-                                     ENSAFEOUT1, LDO_ON);
-               ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
-               ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, EN_LDO | val);
-
-               ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
-               ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, EN_LDO | val);
+               reg = pmic_reg_read(dev, MAX8997_REG_SAFEOUTCTRL);
+               reg |= ENSAFEOUT1;
+               ret = pmic_reg_write(dev, MAX8997_REG_SAFEOUTCTRL, reg);
+               if (ret) {
+                       puts("MAX8997 setting error!\n");
+                       return ret;
+               }
+               reg = pmic_reg_read(dev, MAX8997_REG_LDO3CTRL);
+               reg |= EN_LDO;
+               ret = pmic_reg_write(dev, MAX8997_REG_LDO3CTRL, reg);
+               if (ret) {
+                       puts("MAX8997 setting error!\n");
+                       return ret;
+               }
+               reg = pmic_reg_read(dev, MAX8997_REG_LDO8CTRL);
+               reg |= EN_LDO;
+               ret = pmic_reg_write(dev, MAX8997_REG_LDO8CTRL, reg);
+               if (ret) {
+                       puts("MAX8997 setting error!\n");
+                       return ret;
+               }
        } else {
-               ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
-               ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, DIS_LDO | val);
-
-               ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
-               ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, DIS_LDO | val);
-               ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
-                                     ENSAFEOUT1, LDO_OFF);
-       }
+               reg = pmic_reg_read(dev, MAX8997_REG_LDO8CTRL);
+               reg &= DIS_LDO;
+               ret = pmic_reg_write(dev, MAX8997_REG_LDO8CTRL, reg);
+               if (ret) {
+                       puts("MAX8997 setting error!\n");
+                       return ret;
+               }
+               reg = pmic_reg_read(dev, MAX8997_REG_LDO3CTRL);
+               reg &= DIS_LDO;
+               ret = pmic_reg_write(dev, MAX8997_REG_LDO3CTRL, reg);
+               if (ret) {
+                       puts("MAX8997 setting error!\n");
+                       return ret;
+               }
+               reg = pmic_reg_read(dev, MAX8997_REG_SAFEOUTCTRL);
+               reg &= ~ENSAFEOUT1;
+               ret = pmic_reg_write(dev, MAX8997_REG_SAFEOUTCTRL, reg);
+               if (ret) {
+                       puts("MAX8997 setting error!\n");
+                       return ret;
+               }
 
-       if (ret) {
-               puts("MAX8997 LDO setting error!\n");
-               return -1;
        }
-#endif
 
        return 0;
 }