Blame view
drivers/power/power_spi.c
1.35 KB
e542b7f0a misc:pmic:core Ne... |
1 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. * |
1a4596601 Add GPL-2.0+ SPDX... |
10 |
* SPDX-License-Identifier: GPL-2.0+ |
e542b7f0a misc:pmic:core Ne... |
11 12 13 14 |
*/ #include <common.h> #include <linux/types.h> |
c73368150 pmic: Extend PMIC... |
15 |
#include <power/pmic.h> |
e542b7f0a misc:pmic:core Ne... |
16 17 18 |
#include <spi.h> static struct spi_slave *slave; |
e542b7f0a misc:pmic:core Ne... |
19 20 21 22 23 24 |
static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write) { u32 pmic_tx, pmic_rx; u32 tmp; if (!slave) { |
5b471dee9 power_spi.c: Rewr... |
25 26 |
slave = spi_setup_slave(p->bus, p->hw.spi.cs, p->hw.spi.clk, p->hw.spi.mode); |
e542b7f0a misc:pmic:core Ne... |
27 28 |
if (!slave) |
505cf4750 power: change fro... |
29 |
return -ENODEV; |
e542b7f0a misc:pmic:core Ne... |
30 |
} |
c73368150 pmic: Extend PMIC... |
31 |
if (check_reg(p, reg)) |
505cf4750 power: change fro... |
32 |
return -EINVAL; |
e542b7f0a misc:pmic:core Ne... |
33 34 |
if (spi_claim_bus(slave)) |
505cf4750 power: change fro... |
35 |
return -EBUSY; |
e542b7f0a misc:pmic:core Ne... |
36 37 38 39 40 41 |
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 power_spi.c: Rewr... |
42 43 |
pmic_spi_flags)) goto err; |
e542b7f0a misc:pmic:core Ne... |
44 45 |
if (write) { |
435a72858 misc: pmic: fix r... |
46 |
pmic_tx = p->hw.spi.prepare_tx(reg, val, 0); |
e542b7f0a misc:pmic:core Ne... |
47 48 |
tmp = cpu_to_be32(pmic_tx); if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx, |
5b471dee9 power_spi.c: Rewr... |
49 50 |
pmic_spi_flags)) goto err; |
e542b7f0a misc:pmic:core Ne... |
51 52 53 54 55 56 |
} spi_release_bus(slave); *val = cpu_to_be32(pmic_rx); return 0; |
5b471dee9 power_spi.c: Rewr... |
57 58 59 |
err: spi_release_bus(slave); |
505cf4750 power: change fro... |
60 |
return -ENOTSUPP; |
e542b7f0a misc:pmic:core Ne... |
61 62 63 64 |
} int pmic_reg_write(struct pmic *p, u32 reg, u32 val) { |
505cf4750 power: change fro... |
65 |
return pmic_reg(p, reg, &val, 1); |
e542b7f0a misc:pmic:core Ne... |
66 67 68 69 |
} int pmic_reg_read(struct pmic *p, u32 reg, u32 *val) { |
505cf4750 power: change fro... |
70 |
return pmic_reg(p, reg, val, 0); |
e542b7f0a misc:pmic:core Ne... |
71 |
} |