]> git.sur5r.net Git - u-boot/blobdiff - drivers/power/tps6586x.c
net: sun8i-emac: fix printing NULL character
[u-boot] / drivers / power / tps6586x.c
index f3f2ec6e58e1ca410b2865be2959c96162917c5e..19680e2e76deb72335f5e6ec6d909702dc2ce3d7 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
  * (C) Copyright 2010,2011 NVIDIA Corporation <www.nvidia.com>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 #include <common.h>
@@ -26,9 +9,7 @@
 #include <asm/io.h>
 #include <i2c.h>
 
-static int bus_num;            /* I2C bus we are on */
-#define I2C_ADDRESS            0x34    /* chip requires this address */
-static char inited;            /* 1 if we have been inited */
+static struct udevice *tps6586x_dev;
 
 enum {
        /* Registers that we access */
@@ -48,18 +29,14 @@ enum {
 };
 
 #define MAX_I2C_RETRY  3
-int tps6586x_read(int reg)
+static int tps6586x_read(int reg)
 {
        int     i;
        uchar   data;
        int     retval = -1;
-       int     old_bus_num;
-
-       old_bus_num = i2c_get_bus_num();
-       i2c_set_bus_num(bus_num);
 
        for (i = 0; i < MAX_I2C_RETRY; ++i) {
-               if (!i2c_read(I2C_ADDRESS, reg, 1, &data, 1)) {
+               if (!dm_i2c_read(tps6586x_dev, reg,  &data, 1)) {
                        retval = (int)data;
                        goto exit;
                }
@@ -69,7 +46,6 @@ int tps6586x_read(int reg)
        }
 
 exit:
-       i2c_set_bus_num(old_bus_num);
        debug("pmu_read %x=%x\n", reg, retval);
        if (retval < 0)
                debug("%s: failed to read register %#x: %d\n", __func__, reg,
@@ -77,17 +53,13 @@ exit:
        return retval;
 }
 
-int tps6586x_write(int reg, uchar *data, uint len)
+static int tps6586x_write(int reg, uchar *data, uint len)
 {
        int     i;
        int     retval = -1;
-       int     old_bus_num;
-
-       old_bus_num = i2c_get_bus_num();
-       i2c_set_bus_num(bus_num);
 
        for (i = 0; i < MAX_I2C_RETRY; ++i) {
-               if (!i2c_write(I2C_ADDRESS, reg, 1, data, len)) {
+               if (!dm_i2c_write(tps6586x_dev, reg, data, len)) {
                        retval = 0;
                        goto exit;
                }
@@ -97,7 +69,6 @@ int tps6586x_write(int reg, uchar *data, uint len)
        }
 
 exit:
-       i2c_set_bus_num(old_bus_num);
        debug("pmu_write %x=%x: ", reg, retval);
        for (i = 0; i < len; i++)
                debug("%x ", data[i]);
@@ -125,14 +96,14 @@ static int read_voltages(int *sm0, int *sm1)
        ctrl1 = tps6586x_read(SUPPLY_CONTROL1);
        ctrl2 = tps6586x_read(SUPPLY_CONTROL2);
        if (ctrl1 == -1 || ctrl2 == -1)
-               return -1;
+               return -ENOTSUPP;
 
        /* Figure out whether V1 or V2 is selected */
        is_v2 = (ctrl1 | ctrl2) & CTRL_SM0_SUPPLY2;
        *sm0 = tps6586x_read(is_v2 ? SM0_VOLTAGE_V2 : SM0_VOLTAGE_V1);
        *sm1 = tps6586x_read(is_v2 ? SM1_VOLTAGE_V2 : SM1_VOLTAGE_V1);
        if (*sm0 == -1 || *sm1 == -1)
-               return -1;
+               return -ENOTSUPP;
 
        return 0;
 }
@@ -157,7 +128,7 @@ static int set_voltage(int reg, int data, int rate)
        /* write v1, v2 and rate, then trigger */
        if (tps6586x_write(reg, buff, 3) ||
            tps6586x_write(SUPPLY_CONTROL1, &control_bit, 1))
-               return -1;
+               return -ENOTSUPP;
 
        return 0;
 }
@@ -179,7 +150,7 @@ int tps6586x_set_pwm_mode(int mask)
        uchar val;
        int ret;
 
-       assert(inited);
+       assert(tps6586x_dev);
        ret = tps6586x_read(PFM_MODE);
        if (ret != -1) {
                val = (uchar)ret;
@@ -200,12 +171,12 @@ int tps6586x_adjust_sm0_sm1(int sm0_target, int sm1_target, int step, int rate,
        int sm0, sm1;
        int bad;
 
-       assert(inited);
+       assert(tps6586x_dev);
 
        /* get current voltage settings */
        if (read_voltages(&sm0, &sm1)) {
                debug("%s: Cannot read voltage settings\n", __func__);
-               return -1;
+               return -EINVAL;
        }
 
        /*
@@ -217,7 +188,7 @@ int tps6586x_adjust_sm0_sm1(int sm0_target, int sm1_target, int step, int rate,
        if (min_sm0_over_sm1 != -1 && sm0 < sm1 + min_sm0_over_sm1) {
                debug("%s: SM0 is %d, SM1 is %d, but min_sm0_over_sm1 is %d\n",
                      __func__, sm0, sm1, min_sm0_over_sm1);
-               return -1;
+               return -EINVAL;
        }
 
        /*
@@ -268,13 +239,12 @@ int tps6586x_adjust_sm0_sm1(int sm0_target, int sm1_target, int step, int rate,
        }
        debug("%d-%d   %d-%d   done\n", sm0, sm0_target, sm1, sm1_target);
 
-       return bad ? -1 : 0;
+       return bad ? -EINVAL : 0;
 }
 
-int tps6586x_init(int bus)
+int tps6586x_init(struct udevice *dev)
 {
-       bus_num = bus;
-       inited = 1;
+       tps6586x_dev = dev;
 
        return 0;
 }