1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <common.h>
30#include <linux/types.h>
31#include <pmic.h>
32
33static struct pmic pmic;
34
35int check_reg(u32 reg)
36{
37 if (reg >= pmic.number_of_regs) {
38 printf("<reg num> = %d is invalid. Should be less than %d\n",
39 reg, pmic.number_of_regs);
40 return -1;
41 }
42 return 0;
43}
44
45int pmic_set_output(struct pmic *p, u32 reg, int out, int on)
46{
47 u32 val;
48
49 if (pmic_reg_read(p, reg, &val))
50 return -1;
51
52 if (on)
53 val |= out;
54 else
55 val &= ~out;
56
57 if (pmic_reg_write(p, reg, val))
58 return -1;
59
60 return 0;
61}
62
63static void pmic_show_info(struct pmic *p)
64{
65 printf("PMIC: %s\n", p->name);
66}
67
68static void pmic_dump(struct pmic *p)
69{
70 int i, ret;
71 u32 val;
72
73 pmic_show_info(p);
74 for (i = 0; i < p->number_of_regs; i++) {
75 ret = pmic_reg_read(p, i, &val);
76 if (ret)
77 puts("PMIC: Registers dump failed\n");
78
79 if (!(i % 8))
80 printf("\n0x%02x: ", i);
81
82 printf("%08x ", val);
83 }
84 puts("\n");
85}
86
87struct pmic *get_pmic(void)
88{
89 return &pmic;
90}
91
92int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
93{
94 u32 ret, reg, val;
95 char *cmd;
96
97 struct pmic *p = &pmic;
98
99
100 if (argc < 2)
101 return cmd_usage(cmdtp);
102
103 cmd = argv[1];
104 if (strcmp(cmd, "dump") == 0) {
105 pmic_dump(p);
106 return 0;
107 }
108
109 if (strcmp(cmd, "read") == 0) {
110 if (argc < 3)
111 return cmd_usage(cmdtp);
112
113 reg = simple_strtoul(argv[2], NULL, 16);
114
115 ret = pmic_reg_read(p, reg, &val);
116
117 if (ret)
118 puts("PMIC: Register read failed\n");
119
120 printf("\n0x%02x: 0x%08x\n", reg, val);
121
122 return 0;
123 }
124
125 if (strcmp(cmd, "write") == 0) {
126 if (argc < 4)
127 return cmd_usage(cmdtp);
128
129 reg = simple_strtoul(argv[2], NULL, 16);
130 val = simple_strtoul(argv[3], NULL, 16);
131
132 pmic_reg_write(p, reg, val);
133
134 return 0;
135 }
136
137
138 return 1;
139}
140
141U_BOOT_CMD(
142 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
143 "PMIC",
144 "dump - dump PMIC registers\n"
145 "pmic read <reg> - read register\n"
146 "pmic write <reg> <value> - write register"
147);
148