2011-10-05 10:38:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Samsung Electronics
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
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;
|
|
|
|
p->bus = CONFIG_FSL_PMIC_BUS;
|
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;
|
2012-11-13 03:21:55 +00:00
|
|
|
p->bus = bus;
|
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;
|
|
|
|
}
|