1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2011 Samsung Electronics
4 * Lukasz Majewski <l.majewski@samsung.com>
7 * Stefano Babic, DENX Software Engineering, sbabic@denx.de
9 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
13 #include <linux/types.h>
14 #include <power/pmic.h>
17 static struct spi_slave *slave;
19 static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
25 slave = spi_setup_slave(p->bus, p->hw.spi.cs, p->hw.spi.clk,
32 if (check_reg(p, reg))
35 if (spi_claim_bus(slave))
38 pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
40 tmp = cpu_to_be32(pmic_tx);
42 if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
47 pmic_tx = p->hw.spi.prepare_tx(reg, val, 0);
48 tmp = cpu_to_be32(pmic_tx);
49 if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
54 spi_release_bus(slave);
55 *val = cpu_to_be32(pmic_rx);
60 spi_release_bus(slave);
64 int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
66 return pmic_reg(p, reg, &val, 1);
69 int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
71 return pmic_reg(p, reg, val, 0);