summaryrefslogtreecommitdiff
path: root/chip/lm4/charger.c
blob: e603e634537ed4dfe3a117d7ba2f5bad4c935226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Charger/battery debug command module for Chrome EC */

/* TODO: remove this or merge into charger/battery modules
 * once charger and battery modules are ready.
 */

#include "charger.h"
#include "board.h"
#include "i2c.h"
#include "console.h"
#include "uart.h"
#include "util.h"

/* Address of battery charger */
#define CHARGER_ADDR 0x12

/* Address of battery */
#define BATTERY_ADDR 0x16

/*****************************************************************************/
/* Console commands */

static int command_charger(int argc, char **argv)
{
	int rv;
	int d;

	uart_puts("Reading battery charger...\n");

	rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0xfe, &d);
	if (rv)
		return rv;
	uart_printf("  Manufacturer ID: 0x%04x\n", d);

	rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0xff, &d);
	uart_printf("  Device ID:       0x%04x\n", d);

	rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x12, &d);
	uart_printf("  Option:          0x%04x\n", d);

	rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x14, &d);
	uart_printf("  Charge current:  0x%04x\n", d);

	rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x15, &d);
	uart_printf("  Charge voltage:  0x%04x\n", d);

	rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x3f, &d);
	uart_printf("  Input current:   0x%04x\n", d);

	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(charger, command_charger);

static int command_battery(int argc, char **argv)
{
	int rv;
	int d;

	uart_puts("Reading battery...\n");

	rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x08, &d);
	if (rv)
		return rv;
	uart_printf("  Temperature:            0x%04x = %d C\n",
		    d, (d-2731)/10);

	rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x09, &d);
	uart_printf("  Voltage:                0x%04x = %d mV\n", d, d);

	rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x0f, &d);
	uart_printf("  Remaining capacity:     0x%04x = %d mAh\n", d, d);
	rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x10, &d);
	uart_printf("  Full charge capacity:   0x%04x = %d mAh\n", d, d);

	rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x14, &d);
	uart_printf("  Desired charge current: 0x%04x = %d mA\n", d, d);
	rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x15, &d);
	uart_printf("  Desired charge voltage: 0x%04x = %d mV\n", d, d);


	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(battery, command_battery);

/*****************************************************************************/
/* Initialization */

int charger_init(void)
{
	return EC_SUCCESS;
}