2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-10-05 10:38:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Samsung Electronics
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2014-05-20 12:01:34 +00:00
|
|
|
#if defined(CONFIG_POWER_FSL_MC13892)
|
2012-10-23 06:34:50 +00:00
|
|
|
#define FSL_PMIC_I2C_LENGTH 3
|
2014-05-20 12:01:34 +00:00
|
|
|
#elif defined(CONFIG_POWER_FSL_MC34704)
|
2012-10-23 06:36:18 +00:00
|
|
|
#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;
|
2022-12-04 15:04:01 +00:00
|
|
|
p->hw.spi.cs = CFG_FSL_PMIC_CS;
|
2022-12-04 15:04:00 +00:00
|
|
|
p->hw.spi.clk = CFG_FSL_PMIC_CLK;
|
2022-12-04 15:04:02 +00:00
|
|
|
p->hw.spi.mode = CFG_FSL_PMIC_MODE;
|
2022-12-04 15:03:58 +00:00
|
|
|
p->hw.spi.bitlen = CFG_FSL_PMIC_BITLEN;
|
2011-10-05 10:38:27 +00:00
|
|
|
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;
|
2022-10-29 00:27:13 +00:00
|
|
|
p->hw.i2c.addr = CFG_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
|
|
|
#endif
|
2011-10-05 10:38:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|