1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Shared psy info for X86 tablets which ship with Android as the factory image
4 * and which have broken DSDT tables. The factory kernels shipped on these
5 * devices typically have a bunch of things hardcoded, rather than specified
6 * in their DSDT.
7 *
8 * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
9 */
10
11#include <linux/gpio/machine.h>
12#include <linux/platform_device.h>
13#include <linux/power/bq24190_charger.h>
14#include <linux/property.h>
15#include <linux/regulator/machine.h>
16
17#include "shared-psy-info.h"
18
19/* Generic / shared charger / battery settings */
20const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
21const char * const bq24190_psy[] = { "bq24190-charger" };
22const char * const bq25890_psy[] = { "bq25890-charger-0" };
23
24static const struct property_entry fg_bq24190_supply_props[] = {
25	PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
26	{ }
27};
28
29const struct software_node fg_bq24190_supply_node = {
30	.properties = fg_bq24190_supply_props,
31};
32
33static const struct property_entry fg_bq25890_supply_props[] = {
34	PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq25890_psy),
35	{ }
36};
37
38const struct software_node fg_bq25890_supply_node = {
39	.properties = fg_bq25890_supply_props,
40};
41
42/* LiPo HighVoltage (max 4.35V) settings used by most devs with a HV bat. */
43static const struct property_entry generic_lipo_hv_4v35_battery_props[] = {
44	PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
45	PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion"),
46	PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
47	PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
48	PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 1856000),
49	PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4352000),
50	PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
51	{ }
52};
53
54const struct software_node generic_lipo_hv_4v35_battery_node = {
55	.properties = generic_lipo_hv_4v35_battery_props,
56};
57
58/* For enabling the bq24190 5V boost based on id-pin */
59static struct regulator_consumer_supply intel_int3496_consumer = {
60	.supply = "vbus",
61	.dev_name = "intel-int3496",
62};
63
64static const struct regulator_init_data bq24190_vbus_init_data = {
65	.constraints = {
66		.name = "bq24190_vbus",
67		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
68	},
69	.consumer_supplies = &intel_int3496_consumer,
70	.num_consumer_supplies = 1,
71};
72
73struct bq24190_platform_data bq24190_pdata = {
74	.regulator_init_data = &bq24190_vbus_init_data,
75};
76
77const char * const bq24190_modules[] __initconst = {
78	"intel_crystal_cove_charger", /* For the bq24190 IRQ */
79	"bq24190_charger",            /* For the Vbus regulator for intel-int3496 */
80	NULL
81};
82
83/* Generic pdevs array and gpio-lookups for micro USB ID pin handling */
84const struct platform_device_info int3496_pdevs[] __initconst = {
85	{
86		/* For micro USB ID pin handling */
87		.name = "intel-int3496",
88		.id = PLATFORM_DEVID_NONE,
89	},
90};
91
92struct gpiod_lookup_table int3496_reference_gpios = {
93	.dev_id = "intel-int3496",
94	.table = {
95		GPIO_LOOKUP("INT33FC:01", 15, "vbus", GPIO_ACTIVE_HIGH),
96		GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_HIGH),
97		GPIO_LOOKUP("INT33FC:02", 18, "id", GPIO_ACTIVE_HIGH),
98		{ }
99	},
100};
101