Skip to content

Commit

Permalink
platform/x86: intel_cht_int33fe: Switch to DMI modalias based loading
Browse files Browse the repository at this point in the history
The intel_cht_int33fe driver is intended to deal with ACPI INT33FE
firmware-nodes on Cherry Trail devices with a Whiskey Cove PMIC.

The original version of the driver only dealt with the GPD win and
GPD pocket boards where the WC PMIC is connected to a TI BQ24292i charger,
paired with a Maxim MAX17047 fuelgauge + a FUSB302 USB Type-C Controller +
a PI3USB30532 USB switch, for a fully functional Type-C port.

Later it was split into a Type-C and a Micro-B variant to deal with
the Lenovo Yoga Book YB1-X90 / Lenovo Yoga Book YB1-X91 boards where
the ACPI INT33FE firmware-node only describes the TI BQ27542 fuelgauge.

Currently the driver differentiates between these 2 models by counting
the number of I2cSerialBus resources in the firmware-node.

There are a number of problems with this approach:

1. The driver autoloads based on the acpi:INT33FE modalias causing it
to get loaded on almost all Bay Trail and Cherry Trail devices. It
checks for the presence of a WC PMIC, so it won't bind but the loading
still wastes time and memory.

2. Both code paths in the driver are really only designed for a single
board and have harcoded various assumptions about these boards, if
another design matching the current checks ever shows up the driver
may end up doing something completely wrong.

Avoid both issues by switching to using DMI based autoloading of
the module, which has neither of these problems.

Note this splits the previous intel_cht_int33fe kernel module into two
modules: intel_cht_int33fe_typec and intel_cht_int33fe_microb, one for
each model.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220206220220.88491-2-hdegoede@redhat.com
  • Loading branch information
Hans de Goede committed Feb 11, 2022
1 parent 5030e8d commit 915623a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 171 deletions.
5 changes: 1 addition & 4 deletions drivers/platform/x86/intel/int33fe/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_INTEL_CHT_INT33FE) += intel_cht_int33fe.o
intel_cht_int33fe-y := intel_cht_int33fe_common.o \
intel_cht_int33fe_typec.o \
intel_cht_int33fe_microb.o
obj-$(CONFIG_INTEL_CHT_INT33FE) += intel_cht_int33fe_typec.o intel_cht_int33fe_microb.o
118 changes: 0 additions & 118 deletions drivers/platform/x86/intel/int33fe/intel_cht_int33fe_common.c

This file was deleted.

41 changes: 0 additions & 41 deletions drivers/platform/x86/intel/int33fe/intel_cht_int33fe_common.h

This file was deleted.

53 changes: 49 additions & 4 deletions drivers/platform/x86/intel/int33fe/intel_cht_int33fe_microb.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/pci.h>
Expand All @@ -26,7 +27,9 @@
#include <linux/slab.h>
#include <linux/usb/pd.h>

#include "intel_cht_int33fe_common.h"
struct cht_int33fe_data {
struct i2c_client *battery_fg;
};

static const char * const bq27xxx_suppliers[] = { "bq25890-charger" };

Expand All @@ -39,10 +42,30 @@ static const struct software_node bq27xxx_node = {
.properties = bq27xxx_props,
};

int cht_int33fe_microb_probe(struct cht_int33fe_data *data)
static const struct dmi_system_id cht_int33fe_microb_ids[] = {
{
/* Lenovo Yoga Book X90F / X91F / X91L */
.matches = {
/* Non exact match to match all versions */
DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"),
},
},
{ }
};
MODULE_DEVICE_TABLE(dmi, cht_int33fe_microb_ids);

static int cht_int33fe_microb_probe(struct platform_device *pdev)
{
struct device *dev = data->dev;
struct i2c_board_info board_info;
struct device *dev = &pdev->dev;
struct cht_int33fe_data *data;

if (!dmi_check_system(cht_int33fe_microb_ids))
return -ENODEV;

data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

memset(&board_info, 0, sizeof(board_info));
strscpy(board_info.type, "bq27542", ARRAY_SIZE(board_info.type));
Expand All @@ -53,9 +76,31 @@ int cht_int33fe_microb_probe(struct cht_int33fe_data *data)
return PTR_ERR_OR_ZERO(data->battery_fg);
}

int cht_int33fe_microb_remove(struct cht_int33fe_data *data)
static int cht_int33fe_microb_remove(struct platform_device *pdev)
{
struct cht_int33fe_data *data = platform_get_drvdata(pdev);

i2c_unregister_device(data->battery_fg);

return 0;
}

static const struct acpi_device_id cht_int33fe_acpi_ids[] = {
{ "INT33FE", },
{ }
};

static struct platform_driver cht_int33fe_microb_driver = {
.driver = {
.name = "Intel Cherry Trail ACPI INT33FE micro-B driver",
.acpi_match_table = ACPI_PTR(cht_int33fe_acpi_ids),
},
.probe = cht_int33fe_microb_probe,
.remove = cht_int33fe_microb_remove,
};

module_platform_driver(cht_int33fe_microb_driver);

MODULE_DESCRIPTION("Intel Cherry Trail ACPI INT33FE micro-B pseudo device driver");
MODULE_AUTHOR("Yauhen Kharuzhy <jekhor@gmail.com>");
MODULE_LICENSE("GPL v2");
65 changes: 61 additions & 4 deletions drivers/platform/x86/intel/int33fe/intel_cht_int33fe_typec.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* for these chips can bind to the them.
*/

#include <linux/dmi.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
Expand All @@ -26,7 +27,12 @@
#include <linux/slab.h>
#include <linux/usb/pd.h>

#include "intel_cht_int33fe_common.h"
struct cht_int33fe_data {
struct i2c_client *battery_fg;
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
struct fwnode_handle *dp;
};

/*
* Grrr, I severely dislike buggy BIOS-es. At least one BIOS enumerates
Expand Down Expand Up @@ -272,15 +278,44 @@ cht_int33fe_register_max17047(struct device *dev, struct cht_int33fe_data *data)
return PTR_ERR_OR_ZERO(data->battery_fg);
}

int cht_int33fe_typec_probe(struct cht_int33fe_data *data)
static const struct dmi_system_id cht_int33fe_typec_ids[] = {
{
/*
* GPD win / GPD pocket mini laptops
*
* This DMI match may not seem unique, but it is. In the 67000+
* DMI decode dumps from linux-hardware.org only 116 have
* board_vendor set to "AMI Corporation" and of those 116 only
* the GPD win's and pocket's board_name is "Default string".
*/
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
},
},
{ }
};
MODULE_DEVICE_TABLE(dmi, cht_int33fe_typec_ids);

static int cht_int33fe_typec_probe(struct platform_device *pdev)
{
struct device *dev = data->dev;
struct i2c_board_info board_info;
struct device *dev = &pdev->dev;
struct cht_int33fe_data *data;
struct fwnode_handle *fwnode;
struct regulator *regulator;
int fusb302_irq;
int ret;

if (!dmi_check_system(cht_int33fe_typec_ids))
return -ENODEV;

data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

/*
* We expect the WC PMIC to be paired with a TI bq24292i charger-IC.
* We check for the bq24292i vbus regulator here, this has 2 purposes:
Expand Down Expand Up @@ -368,8 +403,10 @@ int cht_int33fe_typec_probe(struct cht_int33fe_data *data)
return ret;
}

int cht_int33fe_typec_remove(struct cht_int33fe_data *data)
static int cht_int33fe_typec_remove(struct platform_device *pdev)
{
struct cht_int33fe_data *data = platform_get_drvdata(pdev);

i2c_unregister_device(data->pi3usb30532);
i2c_unregister_device(data->fusb302);
i2c_unregister_device(data->battery_fg);
Expand All @@ -378,3 +415,23 @@ int cht_int33fe_typec_remove(struct cht_int33fe_data *data)

return 0;
}

static const struct acpi_device_id cht_int33fe_acpi_ids[] = {
{ "INT33FE", },
{ }
};

static struct platform_driver cht_int33fe_typec_driver = {
.driver = {
.name = "Intel Cherry Trail ACPI INT33FE Type-C driver",
.acpi_match_table = ACPI_PTR(cht_int33fe_acpi_ids),
},
.probe = cht_int33fe_typec_probe,
.remove = cht_int33fe_typec_remove,
};

module_platform_driver(cht_int33fe_typec_driver);

MODULE_DESCRIPTION("Intel Cherry Trail ACPI INT33FE Type-C pseudo device driver");
MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
MODULE_LICENSE("GPL v2");

0 comments on commit 915623a

Please sign in to comment.