lkml.org 
[lkml]   [2021]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 2/2] platform/surface: Add Surface Go 2 board file
Date
The DSDT tables on the Surface Go 2 contain no power control methods for
the world facing camera, so the regulator, gpio and clk frameworks have no
way to discover the appropriate connections and settings.

To compensate for the shortcomings, define the connections and other
parameters in a board file for this device.

Signed-off-by: Daniel Scally <djrscally@gmail.com>
---
MAINTAINERS | 6 ++
drivers/platform/surface/Kconfig | 10 ++
drivers/platform/surface/Makefile | 1 +
drivers/platform/surface/surface_go_2.c | 135 ++++++++++++++++++++++++
4 files changed, 152 insertions(+)
create mode 100644 drivers/platform/surface/surface_go_2.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 52e61092c63b..f11e68daf939 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12143,6 +12143,12 @@ F: Documentation/driver-api/surface_aggregator/clients/dtx.rst
F: drivers/platform/surface/surface_dtx.c
F: include/uapi/linux/surface_aggregator/dtx.h

+MICROSOFT SURFACE GO 2 SUPPORT
+M: Daniel Scally <djrscally@gmail.com>
+L: platform-driver-x86@vger.kernel.org
+S: Maintained
+F: drivers/platform/surface/surface_go_2.c
+
MICROSOFT SURFACE GPE LID SUPPORT DRIVER
M: Maximilian Luz <luzmaximilian@gmail.com>
L: platform-driver-x86@vger.kernel.org
diff --git a/drivers/platform/surface/Kconfig b/drivers/platform/surface/Kconfig
index 3105f651614f..0c55bd531592 100644
--- a/drivers/platform/surface/Kconfig
+++ b/drivers/platform/surface/Kconfig
@@ -124,6 +124,16 @@ config SURFACE_DTX
Aggregator Bus (i.e. CONFIG_SURFACE_AGGREGATOR_BUS=n). In that case,
some devices, specifically the Surface Book 3, will not be supported.

+config SURFACE_GO_2
+ bool "Surface Go 2 Specific Driver"
+ help
+ This board file performs some platform specific configuration to help
+ the regulator, gpio and clk frameworks link those resources to the
+ consuming devices - specifically the world facing camera.
+
+ Select Y here if your device is a Microsoft Surface Go 2, otherwise
+ select N.
+
config SURFACE_GPE
tristate "Surface GPE/Lid Support Driver"
depends on DMI
diff --git a/drivers/platform/surface/Makefile b/drivers/platform/surface/Makefile
index 32889482de55..9f858d2a3d77 100644
--- a/drivers/platform/surface/Makefile
+++ b/drivers/platform/surface/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_SURFACE_AGGREGATOR) += aggregator/
obj-$(CONFIG_SURFACE_AGGREGATOR_CDEV) += surface_aggregator_cdev.o
obj-$(CONFIG_SURFACE_AGGREGATOR_REGISTRY) += surface_aggregator_registry.o
obj-$(CONFIG_SURFACE_DTX) += surface_dtx.o
+obj-$(CONFIG_SURFACE_GO_2) += surface_go_2.o
obj-$(CONFIG_SURFACE_GPE) += surface_gpe.o
obj-$(CONFIG_SURFACE_HOTPLUG) += surface_hotplug.o
obj-$(CONFIG_SURFACE_PLATFORM_PROFILE) += surface_platform_profile.o
diff --git a/drivers/platform/surface/surface_go_2.c b/drivers/platform/surface/surface_go_2.c
new file mode 100644
index 000000000000..4a335f0d5fd5
--- /dev/null
+++ b/drivers/platform/surface/surface_go_2.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Author: Dan Scally <djrscally@gmail.com> */
+
+#include <linux/acpi.h>
+#include <linux/gpio/machine.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/property.h>
+
+static const struct software_node tps68470_node = {
+ "INT3472",
+};
+
+static const struct property_entry ana_properties[] = {
+ PROPERTY_ENTRY_STRING("regulator-name", "ANA"),
+ PROPERTY_ENTRY_U32("regulator-min-microvolt", 2815200),
+ PROPERTY_ENTRY_U32("regulator-max-microvolt", 2815200),
+ { }
+};
+
+static const struct property_entry vsio_properties[] = {
+ PROPERTY_ENTRY_STRING("regulator-name", "VSIO"),
+ PROPERTY_ENTRY_U32("regulator-min-microvolt", 1800600),
+ PROPERTY_ENTRY_U32("regulator-max-microvolt", 1800600),
+ { }
+};
+
+static const struct property_entry core_properties[] = {
+ PROPERTY_ENTRY_STRING("regulator-name", "CORE"),
+ PROPERTY_ENTRY_U32("regulator-min-microvolt", 1200000),
+ PROPERTY_ENTRY_U32("regulator-max-microvolt", 1200000),
+ { }
+};
+
+static const struct software_node regulator_nodes[] = {
+ {"ANA", &tps68470_node, ana_properties},
+ {"VSIO", &tps68470_node, vsio_properties},
+ {"CORE", &tps68470_node, core_properties},
+};
+
+static const struct property_entry sensor_properties[] = {
+ PROPERTY_ENTRY_REF("avdd-supply", &regulator_nodes[0]),
+ PROPERTY_ENTRY_REF("dovdd-supply", &regulator_nodes[1]),
+ PROPERTY_ENTRY_REF("dvdd-supply", &regulator_nodes[2]),
+ { }
+};
+
+static struct software_node sensor_node = {
+ .name = "INT347A",
+ .properties = sensor_properties,
+};
+
+static struct gpiod_lookup_table surface_go_2_gpios = {
+ .dev_id = "i2c-INT347A:00",
+ .table = {
+ GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
+ GPIO_LOOKUP("tps68470-gpio", 7, "powerdown", GPIO_ACTIVE_LOW)
+ }
+};
+
+static int __init surface_go_2_init(void)
+{
+ struct fwnode_handle *fwnode, *sensor_fwnode;
+ struct acpi_device *adev, *sensor;
+ int ret;
+
+ adev = acpi_dev_get_first_match_dev("INT3472", "0", -1);
+ if (!adev) {
+ pr_err("%s(): Failed to find INT3472 ACPI device\n", __func__);
+ return -EINVAL;
+ }
+
+ ret = software_node_register(&tps68470_node);
+ if (ret) {
+ dev_err(&adev->dev, "Failed to add tps68470 software node\n");
+ goto err_put_adev;
+ }
+
+ fwnode = software_node_fwnode(&tps68470_node);
+ if (!fwnode) {
+ dev_err(&adev->dev, "Failed to find tps68470 fwnode\n");
+ ret = -ENODEV;
+ goto err_put_adev;
+ }
+
+ adev->fwnode.secondary = fwnode;
+
+ ret = software_node_register_nodes(regulator_nodes);
+ if (ret) {
+ dev_err(&adev->dev,
+ "failed to register software nodes for regulator\n");
+ goto err_unregister_node;
+ }
+
+ gpiod_add_lookup_table(&surface_go_2_gpios);
+
+ sensor = acpi_dev_get_first_match_dev("INT347A", "0", -1);
+ if (!sensor) {
+ pr_err("%s(): Failed to find sensor\n", __func__);
+ ret = -ENODEV;
+ goto err_remove_gpio_lookup;
+ }
+
+ ret = software_node_register(&sensor_node);
+ if (ret) {
+ dev_err(&sensor->dev, "Failed to add sensor node\n");
+ goto err_put_sensor;
+ }
+
+ sensor_fwnode = software_node_fwnode(&sensor_node);
+ if (!sensor_fwnode) {
+ dev_err(&sensor->dev, "Failed to find sensor fwnode\n");
+ ret = -ENODEV;
+ goto err_unregister_sensor_node;
+ }
+
+ sensor->fwnode.secondary = sensor_fwnode;
+
+ return ret;
+
+err_unregister_sensor_node:
+ software_node_unregister(&sensor_node);
+err_put_sensor:
+ acpi_dev_put(sensor);
+err_remove_gpio_lookup:
+ gpiod_remove_lookup_table(&surface_go_2_gpios);
+err_unregister_node:
+ adev->fwnode.secondary = -ENODEV;
+ software_node_unregister(&tps68470_node);
+err_put_adev:
+ acpi_dev_put(adev);
+
+ return ret;
+}
+device_initcall(surface_go_2_init);
--
2.25.1
\
 
 \ /
  Last update: 2021-07-09 00:43    [W:0.140 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site