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