blob: 0e7aa3149272da6e9752d5966322581a5e7e4c8e [file] [log] [blame]
Łukasz Majewskie542b7f2011-10-06 02:37:34 +00001/*
Łukasz Majewskic7336812012-11-13 03:21:55 +00002 * Copyright (C) 2011-2012 Samsung Electronics
Łukasz Majewskie542b7f2011-10-06 02:37:34 +00003 * Lukasz Majewski <l.majewski@samsung.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Łukasz Majewskie542b7f2011-10-06 02:37:34 +00006 */
7
8#ifndef __CORE_PMIC_H_
9#define __CORE_PMIC_H_
10
Łukasz Majewskic7336812012-11-13 03:21:55 +000011#include <common.h>
12#include <linux/list.h>
13#include <i2c.h>
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000014#include <power/power_chrg.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000015
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000016enum { PMIC_I2C, PMIC_SPI, PMIC_NONE};
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000017enum { I2C_PMIC, I2C_NUM, };
18enum { PMIC_READ, PMIC_WRITE, };
Łukasz Majewski86879d72012-11-13 03:21:53 +000019enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, };
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000020
21struct p_i2c {
22 unsigned char addr;
23 unsigned char *buf;
24 unsigned char tx_num;
25};
26
27struct p_spi {
28 unsigned int cs;
29 unsigned int mode;
30 unsigned int bitlen;
31 unsigned int clk;
32 unsigned int flags;
33 u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
34};
35
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000036struct pmic;
37struct power_fg {
38 int (*fg_battery_check) (struct pmic *p, struct pmic *bat);
39 int (*fg_battery_update) (struct pmic *p, struct pmic *bat);
40};
41
42struct power_chrg {
43 int (*chrg_type) (struct pmic *p);
44 int (*chrg_bat_present) (struct pmic *p);
45 int (*chrg_state) (struct pmic *p, int state, int current);
46};
47
48struct power_battery {
49 struct battery *bat;
50 int (*battery_init) (struct pmic *bat, struct pmic *p1,
51 struct pmic *p2, struct pmic *p3);
52 int (*battery_charge) (struct pmic *bat);
53 /* Keep info about power devices involved with battery operation */
54 struct pmic *chrg, *fg, *muic;
55};
56
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000057struct pmic {
58 const char *name;
59 unsigned char bus;
60 unsigned char interface;
Łukasz Majewski86879d72012-11-13 03:21:53 +000061 unsigned char sensor_byte_order;
Łukasz Majewskic7336812012-11-13 03:21:55 +000062 unsigned int number_of_regs;
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000063 union hw {
64 struct p_i2c i2c;
65 struct p_spi spi;
66 } hw;
Łukasz Majewskic7336812012-11-13 03:21:55 +000067
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000068 void (*low_power_mode) (void);
69 struct power_battery *pbat;
70 struct power_chrg *chrg;
71 struct power_fg *fg;
72
73 struct pmic *parent;
Łukasz Majewskic7336812012-11-13 03:21:55 +000074 struct list_head list;
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000075};
76
Łukasz Majewskic7336812012-11-13 03:21:55 +000077int pmic_init(unsigned char bus);
78int pmic_dialog_init(unsigned char bus);
79int check_reg(struct pmic *p, u32 reg);
80struct pmic *pmic_alloc(void);
81struct pmic *pmic_get(const char *s);
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000082int pmic_probe(struct pmic *p);
83int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
84int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
85int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
86
87#define pmic_i2c_addr (p->hw.i2c.addr)
88#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
89
90#define pmic_spi_bitlen (p->hw.spi.bitlen)
91#define pmic_spi_flags (p->hw.spi.flags)
92
93#endif /* __CORE_PMIC_H_ */