]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/tx6/rn5t567.c
karo: tx6: configure all relevant PMIC registers
[karo-tx-uboot.git] / board / karo / tx6 / rn5t567.c
1 /*
2  * Copyright (C) 2014 Lothar Waßmann <LW@KARO-electronics.de>
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 #include <common.h>
19 #include <i2c.h>
20
21 #include "../common/karo.h"
22 #include "pmic.h"
23
24 static int rn5t567_setup_regs(uchar slave_addr, struct pmic_regs *r,
25                         size_t count)
26 {
27         int ret;
28         int i;
29
30         for (i = 0; i < count; i++, r++) {
31                 unsigned char value;
32                 unsigned char newval;
33
34                 ret = i2c_read(slave_addr, r->addr, 1, &value, 1);
35                 if (ret) {
36                         printf("%s: failed to read PMIC register %02x: %d\n",
37                                 __func__, r->addr, ret);
38                         return ret;
39                 }
40                 newval = (value & ~r->mask) | r->val;
41 #ifdef DEBUG
42                 if (value != newval) {
43                         printf("Changing PMIC reg %02x from %02x to %02x\n",
44                                r->addr, value, newval);
45                 }
46 #endif
47                 ret = i2c_write(slave_addr, r->addr, 1, &newval, 1);
48                 if (ret) {
49                         printf("%s: failed to write PMIC register %02x: %d\n",
50                                 __func__, r->addr, ret);
51                         return ret;
52                 }
53 #ifdef DEBUG
54                 ret = i2c_read(slave_addr, r->addr, 1, &value, 1);
55                 if (ret) {
56                         printf("%s: failed to read PMIC register %02x: %d\n",
57                                 __func__, r->addr, ret);
58                         return ret;
59                 }
60                 if (value != newval) {
61                         printf("Failed to set PMIC reg %02x to %02x; actual value: %02x\n",
62                                 r->addr, newval, value);
63                 }
64 #endif
65         }
66         return 0;
67 }
68
69 int rn5t567_pmic_setup(uchar slave_addr, struct pmic_regs *regs,
70                 size_t count)
71 {
72         int ret;
73         unsigned char value;
74
75         ret = i2c_read(slave_addr, 0x11, 1, &value, 1);
76         if (ret) {
77                 printf("%s: i2c_read error: %d\n", __func__, ret);
78                 return ret;
79         }
80
81         ret = rn5t567_setup_regs(slave_addr, regs, count);
82         if (ret)
83                 return ret;
84
85         ret = i2c_read(slave_addr, RN5T567_DC1DAC, 1, &value, 1);
86         if (ret == 0) {
87                 printf("VDDCORE set to %umV\n", rn5t_regval_to_mV(value));
88         } else {
89                 printf("Failed to read VDDCORE register setting\n");
90         }
91 #ifndef CONFIG_SOC_MX6UL
92         ret = i2c_read(slave_addr, RN5T567_DC2DAC, 1, &value, 1);
93         if (ret == 0) {
94                 printf("VDDSOC  set to %umV\n", rn5t_regval_to_mV(value));
95         } else {
96                 printf("Failed to read VDDSOC register setting\n");
97         }
98 #endif
99         return ret;
100 }