Blame view
drivers/power/power_spi.c
1.35 KB
83d290c56
|
1 |
// SPDX-License-Identifier: GPL-2.0+ |
e542b7f0a
|
2 3 4 5 6 7 8 9 |
/* * Copyright (C) 2011 Samsung Electronics * Lukasz Majewski <l.majewski@samsung.com> * * (C) Copyright 2010 * Stefano Babic, DENX Software Engineering, sbabic@denx.de * * (C) Copyright 2008-2009 Freescale Semiconductor, Inc. |
e542b7f0a
|
10 11 12 13 |
*/ #include <common.h> #include <linux/types.h> |
c73368150
|
14 |
#include <power/pmic.h> |
e542b7f0a
|
15 16 17 |
#include <spi.h> static struct spi_slave *slave; |
e542b7f0a
|
18 19 20 21 22 23 |
static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write) { u32 pmic_tx, pmic_rx; u32 tmp; if (!slave) { |
5b471dee9
|
24 25 |
slave = spi_setup_slave(p->bus, p->hw.spi.cs, p->hw.spi.clk, p->hw.spi.mode); |
e542b7f0a
|
26 27 |
if (!slave) |
505cf4750
|
28 |
return -ENODEV; |
e542b7f0a
|
29 |
} |
c73368150
|
30 |
if (check_reg(p, reg)) |
505cf4750
|
31 |
return -EINVAL; |
e542b7f0a
|
32 33 |
if (spi_claim_bus(slave)) |
505cf4750
|
34 |
return -EBUSY; |
e542b7f0a
|
35 36 37 38 39 40 |
pmic_tx = p->hw.spi.prepare_tx(reg, val, write); tmp = cpu_to_be32(pmic_tx); if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx, |
5b471dee9
|
41 42 |
pmic_spi_flags)) goto err; |
e542b7f0a
|
43 44 |
if (write) { |
435a72858
|
45 |
pmic_tx = p->hw.spi.prepare_tx(reg, val, 0); |
e542b7f0a
|
46 47 |
tmp = cpu_to_be32(pmic_tx); if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx, |
5b471dee9
|
48 49 |
pmic_spi_flags)) goto err; |
e542b7f0a
|
50 51 52 53 54 55 |
} spi_release_bus(slave); *val = cpu_to_be32(pmic_rx); return 0; |
5b471dee9
|
56 57 58 |
err: spi_release_bus(slave); |
505cf4750
|
59 |
return -ENOTSUPP; |
e542b7f0a
|
60 61 62 63 |
} int pmic_reg_write(struct pmic *p, u32 reg, u32 val) { |
505cf4750
|
64 |
return pmic_reg(p, reg, &val, 1); |
e542b7f0a
|
65 66 67 68 |
} int pmic_reg_read(struct pmic *p, u32 reg, u32 *val) { |
505cf4750
|
69 |
return pmic_reg(p, reg, val, 0); |
e542b7f0a
|
70 |
} |