Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 2 | /* |
3 | * Copyright (C) 2011 Samsung Electronics | ||||
4 | * Lukasz Majewski <l.majewski@samsung.com> | ||||
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 5 | */ |
6 | |||||
Tom Rini | 78f809d | 2024-05-01 19:31:09 -0600 | [diff] [blame] | 7 | #include <config.h> |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 8 | #include <spi.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 9 | #include <power/pmic.h> |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 10 | #include <fsl_pmic.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 11 | #include <errno.h> |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 12 | |
Simon Glass | 0222981 | 2014-05-20 06:01:34 -0600 | [diff] [blame] | 13 | #if defined(CONFIG_POWER_FSL_MC13892) |
Fabio Estevam | 57c922b | 2012-10-23 06:34:50 +0000 | [diff] [blame] | 14 | #define FSL_PMIC_I2C_LENGTH 3 |
Simon Glass | 0222981 | 2014-05-20 06:01:34 -0600 | [diff] [blame] | 15 | #elif defined(CONFIG_POWER_FSL_MC34704) |
Fabio Estevam | 2e6453d | 2012-10-23 06:36:18 +0000 | [diff] [blame] | 16 | #define FSL_PMIC_I2C_LENGTH 1 |
Fabio Estevam | 57c922b | 2012-10-23 06:34:50 +0000 | [diff] [blame] | 17 | #endif |
18 | |||||
Łukasz Majewski | 1b6d9ed | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 19 | #if defined(CONFIG_POWER_SPI) |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 20 | static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write) |
21 | { | ||||
Helmut Raiger | b6e1841 | 2011-10-19 20:34:43 +0000 | [diff] [blame] | 22 | return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF); |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 23 | } |
Stefano Babic | 54324c1 | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 24 | #endif |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 25 | |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 26 | int pmic_init(unsigned char bus) |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 27 | { |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 28 | static const char name[] = "FSL_PMIC"; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 29 | struct pmic *p = pmic_alloc(); |
30 | |||||
31 | if (!p) { | ||||
32 | printf("%s: POWER allocation error!\n", __func__); | ||||
33 | return -ENOMEM; | ||||
34 | } | ||||
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 35 | |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 36 | p->name = name; |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 37 | p->number_of_regs = PMIC_NUM_OF_REGS; |
Fabio Estevam | 883bdb1 | 2013-11-20 20:26:06 -0200 | [diff] [blame] | 38 | p->bus = bus; |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 39 | |
Łukasz Majewski | 1b6d9ed | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 40 | #if defined(CONFIG_POWER_SPI) |
Stefano Babic | 54324c1 | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 41 | p->interface = PMIC_SPI; |
Tom Rini | 610d41f | 2022-12-04 10:04:01 -0500 | [diff] [blame] | 42 | p->hw.spi.cs = CFG_FSL_PMIC_CS; |
Tom Rini | a35b7ba | 2022-12-04 10:04:00 -0500 | [diff] [blame] | 43 | p->hw.spi.clk = CFG_FSL_PMIC_CLK; |
Tom Rini | fc9d6a1 | 2022-12-04 10:04:02 -0500 | [diff] [blame] | 44 | p->hw.spi.mode = CFG_FSL_PMIC_MODE; |
Tom Rini | 0da17ea | 2022-12-04 10:03:58 -0500 | [diff] [blame] | 45 | p->hw.spi.bitlen = CFG_FSL_PMIC_BITLEN; |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 46 | p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END; |
47 | p->hw.spi.prepare_tx = pmic_spi_prepare_tx; | ||||
Łukasz Majewski | 1b6d9ed | 2012-11-13 03:22:14 +0000 | [diff] [blame] | 48 | #elif defined(CONFIG_POWER_I2C) |
Stefano Babic | 54324c1 | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 49 | p->interface = PMIC_I2C; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 50 | p->hw.i2c.addr = CFG_SYS_FSL_PMIC_I2C_ADDR; |
Fabio Estevam | 57c922b | 2012-10-23 06:34:50 +0000 | [diff] [blame] | 51 | p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH; |
Stefano Babic | 54324c1 | 2011-10-06 21:06:39 +0200 | [diff] [blame] | 52 | #endif |
Stefano Babic | 222be65 | 2011-10-05 12:38:27 +0200 | [diff] [blame] | 53 | |
54 | return 0; | ||||
55 | } |