]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/misc/fsl_pmic.c
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
)
51 slave
= pmic_spi_probe();
57 if (reg
> 63 || write
> 1) {
58 printf("<reg num> = %d is invalid. Should be less then 63\n",
63 if (spi_claim_bus(slave
))
66 pmic_tx
= (write
<< 31) | (reg
<< 25) | (val
& 0x00FFFFFF);
68 if (spi_xfer(slave
, 4 << 3, &pmic_tx
, &pmic_rx
,
69 SPI_XFER_BEGIN
| SPI_XFER_END
)) {
70 spi_release_bus(slave
);
75 pmic_tx
&= ~(1 << 31);
76 if (spi_xfer(slave
, 4 << 3, &pmic_tx
, &pmic_rx
,
77 SPI_XFER_BEGIN
| SPI_XFER_END
)) {
78 spi_release_bus(slave
);
83 spi_release_bus(slave
);
87 void pmic_reg_write(u32 reg
, u32 value
)
89 pmic_reg(reg
, value
, 1);
92 u32
pmic_reg_read(u32 reg
)
94 return pmic_reg(reg
, 0, 0);
97 void pmic_show_pmic_info(void)
101 rev_id
= pmic_reg_read(REG_IDENTIFICATION
);
102 printf("PMIC ID: 0x%08x [Rev: ", rev_id
);
103 switch (rev_id
& 0x1F) {
144 static void pmic_dump(int numregs
)
149 pmic_show_pmic_info();
150 for (i
= 0; i
< numregs
; i
++) {
151 val
= pmic_reg_read(i
);
153 printf ("\n0x%02x: ", i
);
154 printf("%08x ", val
);
159 int do_pmic(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
165 /* at least two arguments please */
167 return cmd_usage(cmdtp
);
170 if (strcmp(cmd
, "dump") == 0) {
172 return cmd_usage(cmdtp
);
174 nregs
= simple_strtoul(argv
[2], NULL
, 16);
178 if (strcmp(cmd
, "write") == 0) {
180 return cmd_usage(cmdtp
);
182 nregs
= simple_strtoul(argv
[2], NULL
, 16);
183 val
= simple_strtoul(argv
[3], NULL
, 16);
184 pmic_reg_write(nregs
, val
);
187 /* No subcommand found */
192 pmic
, CONFIG_SYS_MAXARGS
, 1, do_pmic
,
193 "Freescale PMIC (Atlas)",
194 "dump [numregs] dump registers\n"
195 "pmic write <reg> <value> - write register"