1 /*
2  * bq2415x charger driver
3  *
4  * Copyright (C) 2011-2012  Pali Rohár <pali.rohar@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef BQ2415X_CHARGER_H
22 #define BQ2415X_CHARGER_H
23 
24 /*
25  * This is platform data for bq2415x chip. It contains default board
26  * voltages and currents which can be also later configured via sysfs. If
27  * value is -1 then default chip value (specified in datasheet) will be
28  * used.
29  *
30  * Value resistor_sense is needed for for configuring charge and
31  * termination current. It it is less or equal to zero, configuring charge
32  * and termination current will not be possible.
33  *
34  * Function set_mode_hook is needed for automode (setting correct current
35  * limit when charger is connected/disconnected or setting boost mode).
36  * When is NULL, automode function is disabled. When is not NULL, it must
37  * have this prototype:
38  *
39  *    int (*set_mode_hook)(
40  *      void (*hook)(enum bq2415x_mode mode, void *data),
41  *      void *data)
42  *
43  * hook is hook function (see below) and data is pointer to driver private
44  * data
45  *
46  * bq2415x driver will call it as:
47  *
48  *    platform_data->set_mode_hook(bq2415x_hook_function, bq2415x_device);
49  *
50  * Board/platform function set_mode_hook return non zero value when hook
51  * function was successful registered. Platform code should call that hook
52  * function (which get from pointer, with data) every time when charger
53  * was connected/disconnected or require to enable boost mode. bq2415x
54  * driver then will set correct current limit, enable/disable charger or
55  * boost mode.
56  *
57  * Hook function has this prototype:
58  *
59  *    void hook(enum bq2415x_mode mode, void *data);
60  *
61  * mode is bq2415x mode (charger or boost)
62  * data is pointer to driver private data (which get from
63  * set_charger_type_hook)
64  *
65  * When bq driver is being unloaded, it call function:
66  *
67  *    platform_data->set_mode_hook(NULL, NULL);
68  *
69  * (hook function and driver private data are NULL)
70  *
71  * After that board/platform code must not call driver hook function! It
72  * is possible that pointer to hook function will not be valid and calling
73  * will cause undefined result.
74  */
75 
76 /* Supported modes with maximal current limit */
77 enum bq2415x_mode {
78 	BQ2415X_MODE_OFF,		/* offline mode (charger disabled) */
79 	BQ2415X_MODE_NONE,		/* unknown charger (100mA) */
80 	BQ2415X_MODE_HOST_CHARGER,	/* usb host/hub charger (500mA) */
81 	BQ2415X_MODE_DEDICATED_CHARGER, /* dedicated charger (unlimited) */
82 	BQ2415X_MODE_BOOST,		/* boost mode (charging disabled) */
83 };
84 
85 struct bq2415x_platform_data {
86 	int current_limit;		/* mA */
87 	int weak_battery_voltage;	/* mV */
88 	int battery_regulation_voltage;	/* mV */
89 	int charge_current;		/* mA */
90 	int termination_current;	/* mA */
91 	int resistor_sense;		/* m ohm */
92 	int (*set_mode_hook)(void (*hook)(enum bq2415x_mode mode, void *data),
93 			     void *data);
94 };
95 
96 #endif
97