pmic.c (83d290c56fab2d38cd1ab4c4cc7099559c1d5046) pmic.c (d4505c8e0dec72effc1b6017eafe1f6aa025cc5d)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2014-2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
5 */
6#include <common.h>
7#include <errno.h>
8#include <dm.h>

--- 61 unchanged lines hidden (view full) ---

70 if (ret)
71 return CMD_RET_FAILURE;
72
73 return CMD_RET_SUCCESS;
74}
75
76static int do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
77{
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2014-2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
5 */
6#include <common.h>
7#include <errno.h>
8#include <dm.h>

--- 61 unchanged lines hidden (view full) ---

70 if (ret)
71 return CMD_RET_FAILURE;
72
73 return CMD_RET_SUCCESS;
74}
75
76static int do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
77{
78 struct uc_pmic_priv *priv;
78 struct udevice *dev;
79 struct udevice *dev;
79 uint8_t value;
80 char fmt[16];
80 uint reg;
81 int ret;
82
83 if (!currdev) {
84 printf("First, set the PMIC device!\n");
85 return CMD_RET_USAGE;
86 }
87
88 dev = currdev;
81 uint reg;
82 int ret;
83
84 if (!currdev) {
85 printf("First, set the PMIC device!\n");
86 return CMD_RET_USAGE;
87 }
88
89 dev = currdev;
89
90 priv = dev_get_uclass_priv(dev);
90 printf("Dump pmic: %s registers\n", dev->name);
91
91 printf("Dump pmic: %s registers\n", dev->name);
92
93 sprintf(fmt, "%%%d.%dx ", priv->trans_len * 2,
94 priv->trans_len * 2);
95
92 for (reg = 0; reg < pmic_reg_count(dev); reg++) {
96 for (reg = 0; reg < pmic_reg_count(dev); reg++) {
93 ret = pmic_read(dev, reg, &value, 1);
94 if (ret) {
97 ret = pmic_reg_read(dev, reg);
98 if (ret < 0) {
95 printf("Can't read register: %d\n", reg);
96 return failure(ret);
97 }
98
99 if (!(reg % 16))
100 printf("\n0x%02x: ", reg);
101
99 printf("Can't read register: %d\n", reg);
100 return failure(ret);
101 }
102
103 if (!(reg % 16))
104 printf("\n0x%02x: ", reg);
105
102 printf("%2.2x ", value);
106 printf(fmt, ret);
103 }
104 printf("\n");
105
106 return CMD_RET_SUCCESS;
107}
108
109static int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
110{
107 }
108 printf("\n");
109
110 return CMD_RET_SUCCESS;
111}
112
113static int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
114{
115 struct uc_pmic_priv *priv;
111 struct udevice *dev;
112 int regs, ret;
116 struct udevice *dev;
117 int regs, ret;
113 uint8_t value;
118 char fmt[24];
114 uint reg;
115
116 if (!currdev) {
117 printf("First, set the PMIC device!\n");
118 return CMD_RET_USAGE;
119 }
120
121 dev = currdev;
119 uint reg;
120
121 if (!currdev) {
122 printf("First, set the PMIC device!\n");
123 return CMD_RET_USAGE;
124 }
125
126 dev = currdev;
127 priv = dev_get_uclass_priv(dev);
122
123 if (argc != 2)
124 return CMD_RET_USAGE;
125
126 reg = simple_strtoul(argv[1], NULL, 0);
127 regs = pmic_reg_count(dev);
128 if (reg > regs) {
129 printf("PMIC max reg: %d\n", regs);
130 return failure(-EFAULT);
131 }
132
128
129 if (argc != 2)
130 return CMD_RET_USAGE;
131
132 reg = simple_strtoul(argv[1], NULL, 0);
133 regs = pmic_reg_count(dev);
134 if (reg > regs) {
135 printf("PMIC max reg: %d\n", regs);
136 return failure(-EFAULT);
137 }
138
133 ret = pmic_read(dev, reg, &value, 1);
134 if (ret) {
139 ret = pmic_reg_read(dev, reg);
140 if (ret < 0) {
135 printf("Can't read PMIC register: %d!\n", reg);
136 return failure(ret);
137 }
138
141 printf("Can't read PMIC register: %d!\n", reg);
142 return failure(ret);
143 }
144
139 printf("0x%02x: 0x%2.2x\n", reg, value);
145 sprintf(fmt, "0x%%02x: 0x%%%d.%dx\n", priv->trans_len * 2,
146 priv->trans_len * 2);
147 printf(fmt, reg, ret);
140
141 return CMD_RET_SUCCESS;
142}
143
144static int do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
145{
146 struct udevice *dev;
148
149 return CMD_RET_SUCCESS;
150}
151
152static int do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
153{
154 struct udevice *dev;
155 uint reg, value;
147 int regs, ret;
156 int regs, ret;
148 uint8_t value;
149 uint reg;
150
151 if (!currdev) {
152 printf("First, set the PMIC device!\n");
153 return CMD_RET_USAGE;
154 }
155
156 dev = currdev;
157

--- 4 unchanged lines hidden (view full) ---

162 regs = pmic_reg_count(dev);
163 if (reg > regs) {
164 printf("PMIC max reg: %d\n", regs);
165 return failure(-EFAULT);
166 }
167
168 value = simple_strtoul(argv[2], NULL, 0);
169
157
158 if (!currdev) {
159 printf("First, set the PMIC device!\n");
160 return CMD_RET_USAGE;
161 }
162
163 dev = currdev;
164

--- 4 unchanged lines hidden (view full) ---

169 regs = pmic_reg_count(dev);
170 if (reg > regs) {
171 printf("PMIC max reg: %d\n", regs);
172 return failure(-EFAULT);
173 }
174
175 value = simple_strtoul(argv[2], NULL, 0);
176
170 ret = pmic_write(dev, reg, &value, 1);
177 ret = pmic_reg_write(dev, reg, value);
171 if (ret) {
172 printf("Can't write PMIC register: %d!\n", reg);
173 return failure(ret);
174 }
175
176 return CMD_RET_SUCCESS;
177}
178

--- 31 unchanged lines hidden ---
178 if (ret) {
179 printf("Can't write PMIC register: %d!\n", reg);
180 return failure(ret);
181 }
182
183 return CMD_RET_SUCCESS;
184}
185

--- 31 unchanged lines hidden ---