2011-10-05 18:38:27 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Samsung Electronics
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-10-05 18:38:27 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <spi.h>
|
2012-11-13 11:21:55 +08:00
|
|
|
#include <power/pmic.h>
|
2011-10-05 18:38:27 +08:00
|
|
|
#include <fsl_pmic.h>
|
2012-11-13 11:21:55 +08:00
|
|
|
#include <errno.h>
|
2011-10-05 18:38:27 +08:00
|
|
|
|
2014-05-20 20:01:34 +08:00
|
|
|
#if defined(CONFIG_POWER_FSL_MC13892)
|
2012-10-23 14:34:50 +08:00
|
|
|
#define FSL_PMIC_I2C_LENGTH 3
|
2014-05-20 20:01:34 +08:00
|
|
|
#elif defined(CONFIG_POWER_FSL_MC34704)
|
2012-10-23 14:36:18 +08:00
|
|
|
#define FSL_PMIC_I2C_LENGTH 1
|
2012-10-23 14:34:50 +08:00
|
|
|
#endif
|
|
|
|
|
2012-11-13 11:22:14 +08:00
|
|
|
#if defined(CONFIG_POWER_SPI)
|
2011-10-05 18:38:27 +08:00
|
|
|
static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
|
|
|
|
{
|
2011-10-20 04:34:43 +08:00
|
|
|
return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
|
2011-10-05 18:38:27 +08:00
|
|
|
}
|
2011-10-07 03:06:39 +08:00
|
|
|
#endif
|
2011-10-05 18:38:27 +08:00
|
|
|
|
2012-11-13 11:21:55 +08:00
|
|
|
int pmic_init(unsigned char bus)
|
2011-10-05 18:38:27 +08:00
|
|
|
{
|
|
|
|
static const char name[] = "FSL_PMIC";
|
2012-11-13 11:21:55 +08:00
|
|
|
struct pmic *p = pmic_alloc();
|
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
printf("%s: POWER allocation error!\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-10-05 18:38:27 +08:00
|
|
|
|
|
|
|
p->name = name;
|
|
|
|
p->number_of_regs = PMIC_NUM_OF_REGS;
|
2013-11-21 06:26:06 +08:00
|
|
|
p->bus = bus;
|
2011-10-05 18:38:27 +08:00
|
|
|
|
2012-11-13 11:22:14 +08:00
|
|
|
#if defined(CONFIG_POWER_SPI)
|
2011-10-07 03:06:39 +08:00
|
|
|
p->interface = PMIC_SPI;
|
2011-10-05 18:38:27 +08:00
|
|
|
p->hw.spi.cs = CONFIG_FSL_PMIC_CS;
|
|
|
|
p->hw.spi.clk = CONFIG_FSL_PMIC_CLK;
|
|
|
|
p->hw.spi.mode = CONFIG_FSL_PMIC_MODE;
|
|
|
|
p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN;
|
|
|
|
p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
|
|
|
|
p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
|
2012-11-13 11:22:14 +08:00
|
|
|
#elif defined(CONFIG_POWER_I2C)
|
2011-10-07 03:06:39 +08:00
|
|
|
p->interface = PMIC_I2C;
|
|
|
|
p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR;
|
2012-10-23 14:34:50 +08:00
|
|
|
p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH;
|
2011-10-07 03:06:39 +08:00
|
|
|
#else
|
2014-05-20 20:01:34 +08:00
|
|
|
#error "You must select CONFIG_POWER_SPI or CONFIG_POWER_I2C"
|
2011-10-07 03:06:39 +08:00
|
|
|
#endif
|
2011-10-05 18:38:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|