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 * SPDX-License-Identifier: GPL-2.0+
14 #include <linux/types.h>
15 #include <power/pmic.h>
18 static struct spi_slave *slave;
20 static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
26 slave = spi_setup_slave(p->bus, p->hw.spi.cs, p->hw.spi.clk,
33 if (check_reg(p, reg))
36 if (spi_claim_bus(slave))
39 pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
41 tmp = cpu_to_be32(pmic_tx);
43 if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
48 pmic_tx = p->hw.spi.prepare_tx(reg, val, 0);
49 tmp = cpu_to_be32(pmic_tx);
50 if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
55 spi_release_bus(slave);
56 *val = cpu_to_be32(pmic_rx);
61 spi_release_bus(slave);
65 int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
67 if (pmic_reg(p, reg, &val, 1))
73 int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
75 if (pmic_reg(p, reg, val, 0))