]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/power/tps6586x.c
dm: power: Add a function to set up all regulators
[karo-tx-uboot.git] / drivers / power / tps6586x.c
index f3f2ec6e58e1ca410b2865be2959c96162917c5e..865098386d932ae22ce5f3d781e268bede874a95 100644 (file)
@@ -2,23 +2,7 @@
  * 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
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -26,9 +10,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 +30,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 +47,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 +54,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 +70,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]);
@@ -179,7 +151,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,7 +172,7 @@ 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)) {
@@ -271,10 +243,9 @@ int tps6586x_adjust_sm0_sm1(int sm0_target, int sm1_target, int step, int rate,
        return bad ? -1 : 0;
 }
 
-int tps6586x_init(int bus)
+int tps6586x_init(struct udevice *dev)
 {
-       bus_num = bus;
-       inited = 1;
+       tps6586x_dev = dev;
 
        return 0;
 }