2 * Copyright (C) 2011 Samsung Electronics
3 * Lukasz Majewski <l.majewski@samsung.com>
6 * Stefano Babic, DENX Software Engineering, sbabic@denx.de
8 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <linux/types.h>
33 static struct pmic pmic;
35 int check_reg(u32 reg)
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);
45 int pmic_set_output(struct pmic *p, u32 reg, int out, int on)
49 if (pmic_reg_read(p, reg, &val))
57 if (pmic_reg_write(p, reg, val))
63 static void pmic_show_info(struct pmic *p)
65 printf("PMIC: %s\n", p->name);
68 static void pmic_dump(struct pmic *p)
74 for (i = 0; i < p->number_of_regs; i++) {
75 ret = pmic_reg_read(p, i, &val);
77 puts("PMIC: Registers dump failed\n");
80 printf("\n0x%02x: ", i);
87 struct pmic *get_pmic(void)
92 int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
97 struct pmic *p = &pmic;
99 /* at least two arguments please */
101 return cmd_usage(cmdtp);
104 if (strcmp(cmd, "dump") == 0) {
109 if (strcmp(cmd, "read") == 0) {
111 return cmd_usage(cmdtp);
113 reg = simple_strtoul(argv[2], NULL, 16);
115 ret = pmic_reg_read(p, reg, &val);
118 puts("PMIC: Register read failed\n");
120 printf("\n0x%02x: 0x%08x\n", reg, val);
125 if (strcmp(cmd, "write") == 0) {
127 return cmd_usage(cmdtp);
129 reg = simple_strtoul(argv[2], NULL, 16);
130 val = simple_strtoul(argv[3], NULL, 16);
132 pmic_reg_write(p, reg, val);
137 /* No subcommand found */
142 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
144 "dump - dump PMIC registers\n"
145 "pmic read <reg> - read register\n"
146 "pmic write <reg> <value> - write register"