blob: 1ecfc0543cc51de03d44b30be855856fd12c12bc [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 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#ifndef __CORE_PMIC_H_
25#define __CORE_PMIC_H_
26
Łukasz Majewskic7336812012-11-13 03:21:55 +000027#include <common.h>
28#include <linux/list.h>
29#include <i2c.h>
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000030#include <power/power_chrg.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000031
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000032enum { PMIC_I2C, PMIC_SPI, PMIC_NONE};
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000033enum { I2C_PMIC, I2C_NUM, };
34enum { PMIC_READ, PMIC_WRITE, };
Łukasz Majewski86879d72012-11-13 03:21:53 +000035enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, };
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000036
37struct p_i2c {
38 unsigned char addr;
39 unsigned char *buf;
40 unsigned char tx_num;
41};
42
43struct p_spi {
44 unsigned int cs;
45 unsigned int mode;
46 unsigned int bitlen;
47 unsigned int clk;
48 unsigned int flags;
49 u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
50};
51
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000052struct pmic;
53struct power_fg {
54 int (*fg_battery_check) (struct pmic *p, struct pmic *bat);
55 int (*fg_battery_update) (struct pmic *p, struct pmic *bat);
56};
57
58struct power_chrg {
59 int (*chrg_type) (struct pmic *p);
60 int (*chrg_bat_present) (struct pmic *p);
61 int (*chrg_state) (struct pmic *p, int state, int current);
62};
63
64struct power_battery {
65 struct battery *bat;
66 int (*battery_init) (struct pmic *bat, struct pmic *p1,
67 struct pmic *p2, struct pmic *p3);
68 int (*battery_charge) (struct pmic *bat);
69 /* Keep info about power devices involved with battery operation */
70 struct pmic *chrg, *fg, *muic;
71};
72
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000073struct pmic {
74 const char *name;
75 unsigned char bus;
76 unsigned char interface;
Łukasz Majewski86879d72012-11-13 03:21:53 +000077 unsigned char sensor_byte_order;
Łukasz Majewskic7336812012-11-13 03:21:55 +000078 unsigned int number_of_regs;
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000079 union hw {
80 struct p_i2c i2c;
81 struct p_spi spi;
82 } hw;
Łukasz Majewskic7336812012-11-13 03:21:55 +000083
Łukasz Majewskibd8479e2012-11-13 03:22:00 +000084 void (*low_power_mode) (void);
85 struct power_battery *pbat;
86 struct power_chrg *chrg;
87 struct power_fg *fg;
88
89 struct pmic *parent;
Łukasz Majewskic7336812012-11-13 03:21:55 +000090 struct list_head list;
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000091};
92
Łukasz Majewskic7336812012-11-13 03:21:55 +000093int pmic_init(unsigned char bus);
94int pmic_dialog_init(unsigned char bus);
95int check_reg(struct pmic *p, u32 reg);
96struct pmic *pmic_alloc(void);
97struct pmic *pmic_get(const char *s);
Łukasz Majewskie542b7f2011-10-06 02:37:34 +000098int pmic_probe(struct pmic *p);
99int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
100int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
101int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
102
103#define pmic_i2c_addr (p->hw.i2c.addr)
104#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
105
106#define pmic_spi_bitlen (p->hw.spi.bitlen)
107#define pmic_spi_flags (p->hw.spi.flags)
108
109#endif /* __CORE_PMIC_H_ */