blob: a10a14a79616ca1c65a7aa168434a96e6a1d1d42 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babicb2e5add2011-10-05 12:38:27 +02002/*
3 * Copyright (C) 2011 Samsung Electronics
4 * Lukasz Majewski <l.majewski@samsung.com>
Stefano Babicb2e5add2011-10-05 12:38:27 +02005 */
6
Tom Rini03de3052024-05-20 13:35:03 -06007#include <config.h>
Stefano Babicb2e5add2011-10-05 12:38:27 +02008#include <spi.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +00009#include <power/pmic.h>
Stefano Babicb2e5add2011-10-05 12:38:27 +020010#include <fsl_pmic.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000011#include <errno.h>
Stefano Babicb2e5add2011-10-05 12:38:27 +020012
Simon Glass913702c2014-05-20 06:01:34 -060013#if defined(CONFIG_POWER_FSL_MC13892)
Fabio Estevam4cfc6c42012-10-23 06:34:50 +000014#define FSL_PMIC_I2C_LENGTH 3
Simon Glass913702c2014-05-20 06:01:34 -060015#elif defined(CONFIG_POWER_FSL_MC34704)
Fabio Estevam787f4f32012-10-23 06:36:18 +000016#define FSL_PMIC_I2C_LENGTH 1
Fabio Estevam4cfc6c42012-10-23 06:34:50 +000017#endif
18
Łukasz Majewskibe3b51a2012-11-13 03:22:14 +000019#if defined(CONFIG_POWER_SPI)
Stefano Babicb2e5add2011-10-05 12:38:27 +020020static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
21{
Helmut Raiger435a7282011-10-19 20:34:43 +000022 return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
Stefano Babicb2e5add2011-10-05 12:38:27 +020023}
Stefano Babicb7b7d3c2011-10-06 21:06:39 +020024#endif
Stefano Babicb2e5add2011-10-05 12:38:27 +020025
Łukasz Majewskic7336812012-11-13 03:21:55 +000026int pmic_init(unsigned char bus)
Stefano Babicb2e5add2011-10-05 12:38:27 +020027{
Stefano Babicb2e5add2011-10-05 12:38:27 +020028 static const char name[] = "FSL_PMIC";
Łukasz Majewskic7336812012-11-13 03:21:55 +000029 struct pmic *p = pmic_alloc();
30
31 if (!p) {
32 printf("%s: POWER allocation error!\n", __func__);
33 return -ENOMEM;
34 }
Stefano Babicb2e5add2011-10-05 12:38:27 +020035
Stefano Babicb2e5add2011-10-05 12:38:27 +020036 p->name = name;
Stefano Babicb2e5add2011-10-05 12:38:27 +020037 p->number_of_regs = PMIC_NUM_OF_REGS;
Fabio Estevam839f4d42013-11-20 20:26:06 -020038 p->bus = bus;
Stefano Babicb2e5add2011-10-05 12:38:27 +020039
Łukasz Majewskibe3b51a2012-11-13 03:22:14 +000040#if defined(CONFIG_POWER_SPI)
Stefano Babicb7b7d3c2011-10-06 21:06:39 +020041 p->interface = PMIC_SPI;
Tom Rinif200d712022-12-04 10:04:01 -050042 p->hw.spi.cs = CFG_FSL_PMIC_CS;
Tom Rini3a8be4d2022-12-04 10:04:00 -050043 p->hw.spi.clk = CFG_FSL_PMIC_CLK;
Tom Rini193d7ab2022-12-04 10:04:02 -050044 p->hw.spi.mode = CFG_FSL_PMIC_MODE;
Tom Rinie3e4efc2022-12-04 10:03:58 -050045 p->hw.spi.bitlen = CFG_FSL_PMIC_BITLEN;
Stefano Babicb2e5add2011-10-05 12:38:27 +020046 p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
47 p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
Łukasz Majewskibe3b51a2012-11-13 03:22:14 +000048#elif defined(CONFIG_POWER_I2C)
Stefano Babicb7b7d3c2011-10-06 21:06:39 +020049 p->interface = PMIC_I2C;
Tom Rini6cc04542022-10-28 20:27:13 -040050 p->hw.i2c.addr = CFG_SYS_FSL_PMIC_I2C_ADDR;
Fabio Estevam4cfc6c42012-10-23 06:34:50 +000051 p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH;
Stefano Babicb7b7d3c2011-10-06 21:06:39 +020052#endif
Stefano Babicb2e5add2011-10-05 12:38:27 +020053
54 return 0;
55}