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