blob: ed778f333e5387d3e85a4544557a8fabfb20962a [file] [log] [blame]
Stefano Babic222be652011-10-05 12:38:27 +02001/*
2 * Copyright (C) 2011 Samsung Electronics
3 * Lukasz Majewski <l.majewski@samsung.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefano Babic222be652011-10-05 12:38:27 +02006 */
7
8#include <common.h>
9#include <spi.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000010#include <power/pmic.h>
Stefano Babic222be652011-10-05 12:38:27 +020011#include <fsl_pmic.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000012#include <errno.h>
Stefano Babic222be652011-10-05 12:38:27 +020013
Fabio Estevam57c922b2012-10-23 06:34:50 +000014#if defined(CONFIG_PMIC_FSL_MC13892)
15#define FSL_PMIC_I2C_LENGTH 3
Fabio Estevam2e6453d2012-10-23 06:36:18 +000016#elif defined(CONFIG_PMIC_FSL_MC34704)
17#define FSL_PMIC_I2C_LENGTH 1
Fabio Estevam57c922b2012-10-23 06:34:50 +000018#endif
19
Łukasz Majewski1b6d9ed2012-11-13 03:22:14 +000020#if defined(CONFIG_POWER_SPI)
Stefano Babic222be652011-10-05 12:38:27 +020021static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
22{
Helmut Raigerb6e18412011-10-19 20:34:43 +000023 return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
Stefano Babic222be652011-10-05 12:38:27 +020024}
Stefano Babic54324c12011-10-06 21:06:39 +020025#endif
Stefano Babic222be652011-10-05 12:38:27 +020026
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000027int pmic_init(unsigned char bus)
Stefano Babic222be652011-10-05 12:38:27 +020028{
Stefano Babic222be652011-10-05 12:38:27 +020029 static const char name[] = "FSL_PMIC";
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000030 struct pmic *p = pmic_alloc();
31
32 if (!p) {
33 printf("%s: POWER allocation error!\n", __func__);
34 return -ENOMEM;
35 }
Stefano Babic222be652011-10-05 12:38:27 +020036
Stefano Babic222be652011-10-05 12:38:27 +020037 p->name = name;
Stefano Babic222be652011-10-05 12:38:27 +020038 p->number_of_regs = PMIC_NUM_OF_REGS;
Stefano Babic222be652011-10-05 12:38:27 +020039
Łukasz Majewski1b6d9ed2012-11-13 03:22:14 +000040#if defined(CONFIG_POWER_SPI)
Stefano Babic54324c12011-10-06 21:06:39 +020041 p->interface = PMIC_SPI;
42 p->bus = CONFIG_FSL_PMIC_BUS;
Stefano Babic222be652011-10-05 12:38:27 +020043 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 Majewski1b6d9ed2012-11-13 03:22:14 +000049#elif defined(CONFIG_POWER_I2C)
Stefano Babic54324c12011-10-06 21:06:39 +020050 p->interface = PMIC_I2C;
51 p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR;
Fabio Estevam57c922b2012-10-23 06:34:50 +000052 p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000053 p->bus = bus;
Stefano Babic54324c12011-10-06 21:06:39 +020054#else
Łukasz Majewski1b6d9ed2012-11-13 03:22:14 +000055#error "You must select CONFIG_POWER_SPI or CONFIG_PMIC_I2C"
Stefano Babic54324c12011-10-06 21:06:39 +020056#endif
Stefano Babic222be652011-10-05 12:38:27 +020057
58 return 0;
59}