summaryrefslogtreecommitdiff
path: root/drivers/platform/x86/x86-android-tablets/shared-psy-info.c
blob: fe34cedb6257b38f43a2a57ff481250ca75c1080 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Shared psy info for X86 tablets which ship with Android as the factory image
 * and which have broken DSDT tables. The factory kernels shipped on these
 * devices typically have a bunch of things hardcoded, rather than specified
 * in their DSDT.
 *
 * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
 */

#include <linux/gpio/machine.h>
#include <linux/platform_device.h>
#include <linux/power/bq24190_charger.h>
#include <linux/property.h>
#include <linux/regulator/machine.h>

#include "shared-psy-info.h"

/* Generic / shared charger / battery settings */
const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
const char * const bq24190_psy[] = { "bq24190-charger" };
const char * const bq25890_psy[] = { "bq25890-charger-0" };

static const struct property_entry fg_bq24190_supply_props[] = {
	PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
	{ }
};

const struct software_node fg_bq24190_supply_node = {
	.properties = fg_bq24190_supply_props,
};

static const struct property_entry fg_bq25890_supply_props[] = {
	PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq25890_psy),
	{ }
};

const struct software_node fg_bq25890_supply_node = {
	.properties = fg_bq25890_supply_props,
};

static const u32 generic_lipo_battery_ovc_cap_celcius[] = { 25 };

static const u32 generic_lipo_4v2_battery_ovc_cap_table0[] = {
	4200000, 100,
	4150000, 95,
	4110000, 90,
	4075000, 85,
	4020000, 80,
	3982500, 75,
	3945000, 70,
	3907500, 65,
	3870000, 60,
	3853333, 55,
	3836667, 50,
	3820000, 45,
	3803333, 40,
	3786667, 35,
	3770000, 30,
	3750000, 25,
	3730000, 20,
	3710000, 15,
	3690000, 10,
	3610000, 5,
	3350000, 0
};

static const u32 generic_lipo_hv_4v35_battery_ovc_cap_table0[] = {
	4300000, 100,
	4250000, 96,
	4200000, 91,
	4150000, 86,
	4110000, 82,
	4075000, 77,
	4020000, 73,
	3982500, 68,
	3945000, 64,
	3907500, 59,
	3870000, 55,
	3853333, 50,
	3836667, 45,
	3820000, 41,
	3803333, 36,
	3786667, 32,
	3770000, 27,
	3750000, 23,
	3730000, 18,
	3710000, 14,
	3690000, 9,
	3610000, 5,
	3350000, 0
};

/* Standard LiPo (max 4.2V) settings used by most devs with a LiPo battery */
static const struct property_entry generic_lipo_4v2_battery_props[] = {
	PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
	PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion-polymer"),
	PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
	PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
	PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 2048000),
	PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4208000),
	PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
	PROPERTY_ENTRY_U32_ARRAY("ocv-capacity-celsius",
				 generic_lipo_battery_ovc_cap_celcius),
	PROPERTY_ENTRY_U32_ARRAY("ocv-capacity-table-0",
				 generic_lipo_4v2_battery_ovc_cap_table0),
	{ }
};

const struct software_node generic_lipo_4v2_battery_node = {
	.properties = generic_lipo_4v2_battery_props,
};

/* LiPo HighVoltage (max 4.35V) settings used by most devs with a HV battery */
static const struct property_entry generic_lipo_hv_4v35_battery_props[] = {
	PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
	PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion"),
	PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
	PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
	PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 1856000),
	PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4352000),
	PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
	PROPERTY_ENTRY_U32_ARRAY("ocv-capacity-celsius",
				 generic_lipo_battery_ovc_cap_celcius),
	PROPERTY_ENTRY_U32_ARRAY("ocv-capacity-table-0",
				 generic_lipo_hv_4v35_battery_ovc_cap_table0),
	{ }
};

const struct software_node generic_lipo_hv_4v35_battery_node = {
	.properties = generic_lipo_hv_4v35_battery_props,
};

/* For enabling the bq24190 5V boost based on id-pin */
static struct regulator_consumer_supply intel_int3496_consumer = {
	.supply = "vbus",
	.dev_name = "intel-int3496",
};

static const struct regulator_init_data bq24190_vbus_init_data = {
	.constraints = {
		.name = "bq24190_vbus",
		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
	},
	.consumer_supplies = &intel_int3496_consumer,
	.num_consumer_supplies = 1,
};

struct bq24190_platform_data bq24190_pdata = {
	.regulator_init_data = &bq24190_vbus_init_data,
};

const char * const bq24190_modules[] __initconst = {
	"intel_crystal_cove_charger", /* For the bq24190 IRQ */
	"bq24190_charger",            /* For the Vbus regulator for intel-int3496 */
	NULL
};

/* Generic platform device array and GPIO lookup table for micro USB ID pin handling */
const struct platform_device_info int3496_pdevs[] __initconst = {
	{
		/* For micro USB ID pin handling */
		.name = "intel-int3496",
		.id = PLATFORM_DEVID_NONE,
	},
};

struct gpiod_lookup_table int3496_reference_gpios = {
	.dev_id = "intel-int3496",
	.table = {
		GPIO_LOOKUP("INT33FC:01", 15, "vbus", GPIO_ACTIVE_HIGH),
		GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_HIGH),
		GPIO_LOOKUP("INT33FC:02", 18, "id", GPIO_ACTIVE_HIGH),
		{ }
	},
};