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>
34 static struct spi_slave *slave;
36 void pmic_spi_free(struct spi_slave *slave)
39 spi_free_slave(slave);
42 struct spi_slave *pmic_spi_probe(struct pmic *p)
44 return spi_setup_slave(p->bus,
50 static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
56 slave = pmic_spi_probe(p);
65 if (spi_claim_bus(slave))
68 pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
70 tmp = cpu_to_be32(pmic_tx);
72 if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
74 spi_release_bus(slave);
79 pmic_tx = p->hw.spi.prepare_tx(reg, val, 0);
80 tmp = cpu_to_be32(pmic_tx);
81 if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
83 spi_release_bus(slave);
88 spi_release_bus(slave);
89 *val = cpu_to_be32(pmic_rx);
94 int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
96 if (pmic_reg(p, reg, &val, 1))
102 int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
104 if (pmic_reg(p, reg, val, 0))