linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Scally <djrscally@gmail.com>
To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org
Cc: hdegoede@redhat.com, mgross@linux.intel.com,
	luzmaximilian@gmail.com, lgirdwood@gmail.com, broonie@kernel.org,
	andy.shevchenko@gmail.com, laurent.pinchart@ideasonboard.com,
	kieran.bingham@ideasonboard.com
Subject: [RFC PATCH 2/2] platform/surface: Add Surface Go 2 board file
Date: Thu,  8 Jul 2021 23:42:26 +0100	[thread overview]
Message-ID: <20210708224226.457224-3-djrscally@gmail.com> (raw)
In-Reply-To: <20210708224226.457224-1-djrscally@gmail.com>

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


  parent reply	other threads:[~2021-07-08 22:42 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 22:42 [RFC PATCH 0/2] Add software node support to regulator framework Daniel Scally
2021-07-08 22:42 ` [RFC PATCH 1/2] regulator: Add support for software node connections Daniel Scally
2021-07-09 17:26   ` Mark Brown
2021-07-08 22:42 ` Daniel Scally [this message]
2021-07-09 17:40   ` [RFC PATCH 2/2] platform/surface: Add Surface Go 2 board file Mark Brown
2021-07-09 17:04 ` [RFC PATCH 0/2] Add software node support to regulator framework Mark Brown
2021-07-10 22:48   ` Daniel Scally
2021-07-12 14:15     ` Mark Brown
2021-07-12 16:55       ` Laurent Pinchart
2021-07-12 17:32         ` Mark Brown
2021-07-11  9:37   ` Andy Shevchenko
2021-07-12 12:42     ` Mark Brown
2021-07-12 13:01       ` Andy Shevchenko
2021-07-12 13:34         ` Mark Brown
2021-07-12 16:08           ` Andy Shevchenko
2021-07-12 17:01             ` Mark Brown
2021-07-12 23:32               ` Daniel Scally
2021-07-13 15:24                 ` Mark Brown
2021-07-13 15:42                   ` Laurent Pinchart
2021-07-13 16:02                     ` Mark Brown
2021-07-13 16:06                       ` Laurent Pinchart
2021-07-13 18:24                         ` Mark Brown
2021-07-13 15:55                   ` Andy Shevchenko
2021-07-13 18:18                     ` Mark Brown
2021-07-13 19:46                       ` Andy Shevchenko
2021-07-14 16:05                         ` Mark Brown
2021-07-14  7:25                       ` Laurent Pinchart
2021-07-14 16:59                         ` Mark Brown
2021-07-14 17:18                           ` Laurent Pinchart
2021-07-14 17:28                             ` Mark Brown
2021-07-14 17:41                               ` Laurent Pinchart
2021-07-14 19:18                                 ` Mark Brown
2021-07-14 21:53                                   ` Laurent Pinchart
2021-07-13 22:06                   ` Daniel Scally
2021-07-10 22:28 ` Laurent Pinchart
2021-07-10 22:54   ` Daniel Scally
2021-07-11 16:55     ` Laurent Pinchart
2021-07-12  8:13       ` Daniel Scally
2021-07-12 11:50         ` Laurent Pinchart
2021-07-12 13:23         ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210708224226.457224-3-djrscally@gmail.com \
    --to=djrscally@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=broonie@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luzmaximilian@gmail.com \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).