Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Samsung Electronics |
| 3 | * Lukasz Majewski <l.majewski@samsung.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <spi.h> |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 10 | #include <power/pmic.h> |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 11 | #include <fsl_pmic.h> |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 12 | #include <errno.h> |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 13 | |
Fabio Estevam | 4cfc6c4 | 2012-10-23 06:34:50 +0000 | [diff] [blame] | 14 | #if defined(CONFIG_PMIC_FSL_MC13892) |
| 15 | #define FSL_PMIC_I2C_LENGTH 3 |
Fabio Estevam | 787f4f3 | 2012-10-23 06:36:18 +0000 | [diff] [blame] | 16 | #elif defined(CONFIG_PMIC_FSL_MC34704) |
| 17 | #define FSL_PMIC_I2C_LENGTH 1 |
Fabio Estevam | 4cfc6c4 | 2012-10-23 06:34:50 +0000 | [diff] [blame] | 18 | #endif |
| 19 | |
Łukasz Majewski | be3b51a | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 20 | #if defined(CONFIG_POWER_SPI) |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 21 | static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write) |
| 22 | { |
Helmut Raiger | 435a728 | 2011-10-19 20:34:43 +0000 | [diff] [blame] | 23 | return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF); |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 24 | } |
Stefano Babic | b7b7d3c | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 25 | #endif |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 26 | |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 27 | int pmic_init(unsigned char bus) |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 28 | { |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 29 | static const char name[] = "FSL_PMIC"; |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 30 | struct pmic *p = pmic_alloc(); |
| 31 | |
| 32 | if (!p) { |
| 33 | printf("%s: POWER allocation error!\n", __func__); |
| 34 | return -ENOMEM; |
| 35 | } |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 36 | |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 37 | p->name = name; |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 38 | p->number_of_regs = PMIC_NUM_OF_REGS; |
Fabio Estevam | 839f4d4 | 2013-11-20 20:26:06 -0200 | [diff] [blame] | 39 | p->bus = bus; |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 40 | |
Łukasz Majewski | be3b51a | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 41 | #if defined(CONFIG_POWER_SPI) |
Stefano Babic | b7b7d3c | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 42 | p->interface = PMIC_SPI; |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 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; |
Łukasz Majewski | be3b51a | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 49 | #elif defined(CONFIG_POWER_I2C) |
Stefano Babic | b7b7d3c | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 50 | p->interface = PMIC_I2C; |
| 51 | p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR; |
Fabio Estevam | 4cfc6c4 | 2012-10-23 06:34:50 +0000 | [diff] [blame] | 52 | p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH; |
Stefano Babic | b7b7d3c | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 53 | #else |
Łukasz Majewski | be3b51a | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 54 | #error "You must select CONFIG_POWER_SPI or CONFIG_PMIC_I2C" |
Stefano Babic | b7b7d3c | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 55 | #endif |
Stefano Babic | b2e5add | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | } |