]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/tx6/rn5t567.c
karo: tx6: don't write u-boot image with WITH_DROP_FFS
[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 #ifdef DEBUG
32                 unsigned char value;
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                 if ((value & ~r->mask) != r->val) {
41                         printf("Changing PMIC reg %02x from %02x to %02x\n",
42                                 r->addr, value, r->val);
43                 }
44 #endif
45                 ret = i2c_write(slave_addr, r->addr, 1, &r->val, 1);
46                 if (ret) {
47                         printf("%s: failed to write PMIC register %02x: %d\n",
48                                 __func__, r->addr, ret);
49                         return ret;
50                 }
51 #ifdef DEBUG
52                 ret = i2c_read(slave_addr, r->addr, 1, &value, 1);
53                 if (ret) {
54                         printf("%s: failed to read PMIC register %02x: %d\n",
55                                 __func__, r->addr, ret);
56                         return ret;
57                 }
58                 if (value != r->val) {
59                         printf("Failed to set PMIC reg %02x to %02x; actual value: %02x\n",
60                                 r->addr, r->val, value);
61                 }
62 #endif
63         }
64         return 0;
65 }
66
67 int rn5t567_pmic_setup(uchar slave_addr, struct pmic_regs *regs,
68                 size_t count)
69 {
70         int ret;
71         unsigned char value;
72
73         ret = i2c_read(slave_addr, 0x11, 1, &value, 1);
74         if (ret) {
75                 printf("%s: i2c_read error: %d\n", __func__, ret);
76                 return ret;
77         }
78
79         ret = rn5t567_setup_regs(slave_addr, regs, count);
80         if (ret)
81                 return ret;
82
83         ret = i2c_read(slave_addr, RN5T567_DC1DAC, 1, &value, 1);
84         if (ret == 0) {
85                 printf("VDDCORE set to %umV\n", rn5t_regval_to_mV(value));
86         } else {
87                 printf("Failed to read VDDCORE register setting\n");
88         }
89 #ifndef CONFIG_SOC_MX6UL
90         ret = i2c_read(slave_addr, RN5T567_DC2DAC, 1, &value, 1);
91         if (ret == 0) {
92                 printf("VDDSOC  set to %umV\n", rn5t_regval_to_mV(value));
93         } else {
94                 printf("Failed to read VDDSOC register setting\n");
95         }
96 #endif
97         return ret;
98 }