2 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/errno.h>
27 #include <linux/types.h>
30 static struct spi_slave *slave;
32 struct spi_slave *pmic_spi_probe(void)
34 return spi_setup_slave(CONFIG_FSL_PMIC_BUS,
37 CONFIG_FSL_PMIC_MODE);
40 void pmic_spi_free(struct spi_slave *slave)
43 spi_free_slave(slave);
46 u32 pmic_reg(u32 reg, u32 val, u32 write)
52 slave = pmic_spi_probe();
58 if (reg > 63 || write > 1) {
59 printf("<reg num> = %d is invalid. Should be less then 63\n",
64 if (spi_claim_bus(slave))
67 pmic_tx = (write << 31) | (reg << 25) | (val & 0x00FFFFFF);
69 tmp = cpu_to_be32(pmic_tx);
71 if (spi_xfer(slave, 4 << 3, &tmp, &pmic_rx,
72 SPI_XFER_BEGIN | SPI_XFER_END)) {
73 spi_release_bus(slave);
78 pmic_tx &= ~(1 << 31);
79 tmp = cpu_to_be32(pmic_tx);
80 if (spi_xfer(slave, 4 << 3, &tmp, &pmic_rx,
81 SPI_XFER_BEGIN | SPI_XFER_END)) {
82 spi_release_bus(slave);
87 spi_release_bus(slave);
88 return cpu_to_be32(pmic_rx);
91 void pmic_reg_write(u32 reg, u32 value)
93 pmic_reg(reg, value, 1);
96 u32 pmic_reg_read(u32 reg)
98 return pmic_reg(reg, 0, 0);
101 void pmic_show_pmic_info(void)
105 rev_id = pmic_reg_read(REG_IDENTIFICATION);
106 printf("PMIC ID: 0x%08x [Rev: ", rev_id);
107 switch (rev_id & 0x1F) {
148 static void pmic_dump(int numregs)
153 pmic_show_pmic_info();
154 for (i = 0; i < numregs; i++) {
155 val = pmic_reg_read(i);
157 printf ("\n0x%02x: ", i);
158 printf("%08x ", val);
163 int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
169 /* at least two arguments please */
171 return cmd_usage(cmdtp);
174 if (strcmp(cmd, "dump") == 0) {
176 return cmd_usage(cmdtp);
178 nregs = simple_strtoul(argv[2], NULL, 16);
182 if (strcmp(cmd, "write") == 0) {
184 return cmd_usage(cmdtp);
186 nregs = simple_strtoul(argv[2], NULL, 16);
187 val = simple_strtoul(argv[3], NULL, 16);
188 pmic_reg_write(nregs, val);
191 /* No subcommand found */
196 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
197 "Freescale PMIC (Atlas)",
198 "dump [numregs] dump registers\n"
199 "pmic write <reg> <value> - write register"