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>
31 static u32 pmic_tx, pmic_rx;
34 * To read/write to a PMIC register. For write, it does another read for the
35 * actual register value.
37 * @param reg register number inside the PMIC
38 * @param val data to be written to the register; don't care for read
39 * @param write 0 for read; 1 for write
41 * @return the actual data in the PMIC register
43 u32 pmic_reg(struct spi_slave *slave, u32 reg, u32 val, u32 write)
48 if (reg > 63 || write > 1) {
49 printf("<reg num> = %d is invalide. Should be less then 63\n",
53 pmic_tx = (write << 31) | (reg << 25) | (val & 0x00FFFFFF);
54 debug("reg=0x%x, val=0x%08x\n", reg, pmic_tx);
56 if (spi_xfer(slave, 4 << 3, (u8 *)&pmic_tx, (u8 *)&pmic_rx,
57 SPI_XFER_BEGIN | SPI_XFER_END)) {
62 pmic_tx &= ~(1 << 31);
63 if (spi_xfer(slave, 4 << 3, (u8 *)&pmic_tx, (u8 *)&pmic_rx,
64 SPI_XFER_BEGIN | SPI_XFER_END)) {
72 void show_pmic_info(struct spi_slave *slave)
79 rev_id = pmic_reg(slave, 7, 0, 0);
80 debug("PMIC ID: 0x%08x [Rev: ", rev_id);
81 switch (rev_id & 0x1F) {
122 struct spi_slave *spi_pmic_probe(void)
124 return spi_setup_slave(0, CONFIG_IMX_SPI_PMIC_CS, 2500000, 0);
127 void spi_pmic_free(struct spi_slave *slave)
130 spi_free_slave(slave);