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