]>
Commit | Line | Data |
---|---|---|
b2e5add3 SB |
1 | /* |
2 | * Copyright (C) 2011 Samsung Electronics | |
3 | * Lukasz Majewski <l.majewski@samsung.com> | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
b2e5add3 SB |
6 | */ |
7 | ||
8 | #include <common.h> | |
9 | #include <spi.h> | |
c7336815 | 10 | #include <power/pmic.h> |
b2e5add3 | 11 | #include <fsl_pmic.h> |
c7336815 | 12 | #include <errno.h> |
b2e5add3 | 13 | |
4cfc6c4f FE |
14 | #if defined(CONFIG_PMIC_FSL_MC13892) |
15 | #define FSL_PMIC_I2C_LENGTH 3 | |
787f4f30 FE |
16 | #elif defined(CONFIG_PMIC_FSL_MC34704) |
17 | #define FSL_PMIC_I2C_LENGTH 1 | |
4cfc6c4f FE |
18 | #endif |
19 | ||
be3b51aa | 20 | #if defined(CONFIG_POWER_SPI) |
b2e5add3 SB |
21 | static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write) |
22 | { | |
435a7285 | 23 | return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF); |
b2e5add3 | 24 | } |
b7b7d3cc | 25 | #endif |
b2e5add3 | 26 | |
c7336815 | 27 | int pmic_init(unsigned char bus) |
b2e5add3 | 28 | { |
b2e5add3 | 29 | static const char name[] = "FSL_PMIC"; |
c7336815 ŁM |
30 | struct pmic *p = pmic_alloc(); |
31 | ||
32 | if (!p) { | |
33 | printf("%s: POWER allocation error!\n", __func__); | |
34 | return -ENOMEM; | |
35 | } | |
b2e5add3 | 36 | |
b2e5add3 | 37 | p->name = name; |
b2e5add3 | 38 | p->number_of_regs = PMIC_NUM_OF_REGS; |
b2e5add3 | 39 | |
be3b51aa | 40 | #if defined(CONFIG_POWER_SPI) |
b7b7d3cc SB |
41 | p->interface = PMIC_SPI; |
42 | p->bus = CONFIG_FSL_PMIC_BUS; | |
b2e5add3 SB |
43 | p->hw.spi.cs = CONFIG_FSL_PMIC_CS; |
44 | p->hw.spi.clk = CONFIG_FSL_PMIC_CLK; | |
45 | p->hw.spi.mode = CONFIG_FSL_PMIC_MODE; | |
46 | p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN; | |
47 | p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END; | |
48 | p->hw.spi.prepare_tx = pmic_spi_prepare_tx; | |
be3b51aa | 49 | #elif defined(CONFIG_POWER_I2C) |
b7b7d3cc SB |
50 | p->interface = PMIC_I2C; |
51 | p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR; | |
4cfc6c4f | 52 | p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH; |
c7336815 | 53 | p->bus = bus; |
b7b7d3cc | 54 | #else |
be3b51aa | 55 | #error "You must select CONFIG_POWER_SPI or CONFIG_PMIC_I2C" |
b7b7d3cc | 56 | #endif |
b2e5add3 SB |
57 | |
58 | return 0; | |
59 | } |