Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 1 | /* |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011-2012 Samsung Electronics |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 3 | * Lukasz Majewski <l.majewski@samsung.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __CORE_PMIC_H_ |
| 9 | #define __CORE_PMIC_H_ |
| 10 | |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <i2c.h> |
Łukasz Majewski | bd8479e | 2012-11-13 03:22:00 +0000 | [diff] [blame] | 13 | #include <power/power_chrg.h> |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 14 | |
Łukasz Majewski | bd8479e | 2012-11-13 03:22:00 +0000 | [diff] [blame] | 15 | enum { PMIC_I2C, PMIC_SPI, PMIC_NONE}; |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 16 | enum { I2C_PMIC, I2C_NUM, }; |
| 17 | enum { PMIC_READ, PMIC_WRITE, }; |
Łukasz Majewski | 86879d7 | 2012-11-13 03:21:53 +0000 | [diff] [blame] | 18 | enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, }; |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 19 | |
Simon Glass | 78a36c3 | 2014-05-20 06:01:35 -0600 | [diff] [blame^] | 20 | enum { |
| 21 | PMIC_CHARGER_DISABLE, |
| 22 | PMIC_CHARGER_ENABLE, |
| 23 | }; |
| 24 | |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 25 | struct p_i2c { |
| 26 | unsigned char addr; |
| 27 | unsigned char *buf; |
| 28 | unsigned char tx_num; |
| 29 | }; |
| 30 | |
| 31 | struct p_spi { |
| 32 | unsigned int cs; |
| 33 | unsigned int mode; |
| 34 | unsigned int bitlen; |
| 35 | unsigned int clk; |
| 36 | unsigned int flags; |
| 37 | u32 (*prepare_tx)(u32 reg, u32 *val, u32 write); |
| 38 | }; |
| 39 | |
Łukasz Majewski | bd8479e | 2012-11-13 03:22:00 +0000 | [diff] [blame] | 40 | struct pmic; |
| 41 | struct power_fg { |
| 42 | int (*fg_battery_check) (struct pmic *p, struct pmic *bat); |
| 43 | int (*fg_battery_update) (struct pmic *p, struct pmic *bat); |
| 44 | }; |
| 45 | |
| 46 | struct power_chrg { |
| 47 | int (*chrg_type) (struct pmic *p); |
| 48 | int (*chrg_bat_present) (struct pmic *p); |
| 49 | int (*chrg_state) (struct pmic *p, int state, int current); |
| 50 | }; |
| 51 | |
| 52 | struct power_battery { |
| 53 | struct battery *bat; |
| 54 | int (*battery_init) (struct pmic *bat, struct pmic *p1, |
| 55 | struct pmic *p2, struct pmic *p3); |
| 56 | int (*battery_charge) (struct pmic *bat); |
| 57 | /* Keep info about power devices involved with battery operation */ |
| 58 | struct pmic *chrg, *fg, *muic; |
| 59 | }; |
| 60 | |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 61 | struct pmic { |
| 62 | const char *name; |
| 63 | unsigned char bus; |
| 64 | unsigned char interface; |
Łukasz Majewski | 86879d7 | 2012-11-13 03:21:53 +0000 | [diff] [blame] | 65 | unsigned char sensor_byte_order; |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 66 | unsigned int number_of_regs; |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 67 | union hw { |
| 68 | struct p_i2c i2c; |
| 69 | struct p_spi spi; |
| 70 | } hw; |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 71 | |
Łukasz Majewski | bd8479e | 2012-11-13 03:22:00 +0000 | [diff] [blame] | 72 | void (*low_power_mode) (void); |
| 73 | struct power_battery *pbat; |
| 74 | struct power_chrg *chrg; |
| 75 | struct power_fg *fg; |
| 76 | |
| 77 | struct pmic *parent; |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 78 | struct list_head list; |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Łukasz Majewski | c733681 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 81 | int pmic_init(unsigned char bus); |
| 82 | int pmic_dialog_init(unsigned char bus); |
| 83 | int check_reg(struct pmic *p, u32 reg); |
| 84 | struct pmic *pmic_alloc(void); |
| 85 | struct pmic *pmic_get(const char *s); |
Łukasz Majewski | e542b7f | 2011-10-06 02:37:34 +0000 | [diff] [blame] | 86 | int pmic_probe(struct pmic *p); |
| 87 | int pmic_reg_read(struct pmic *p, u32 reg, u32 *val); |
| 88 | int pmic_reg_write(struct pmic *p, u32 reg, u32 val); |
| 89 | int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on); |
| 90 | |
| 91 | #define pmic_i2c_addr (p->hw.i2c.addr) |
| 92 | #define pmic_i2c_tx_num (p->hw.i2c.tx_num) |
| 93 | |
| 94 | #define pmic_spi_bitlen (p->hw.spi.bitlen) |
| 95 | #define pmic_spi_flags (p->hw.spi.flags) |
| 96 | |
| 97 | #endif /* __CORE_PMIC_H_ */ |