]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
Revert "UBUNTU: SAUCE: change power control driver to acpi driver"
authorStefan Bader <stefan.bader@canonical.com>
Mon, 2 May 2022 09:55:41 +0000 (11:55 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 2 May 2022 10:06:51 +0000 (12:06 +0200)
BugLink: https://bugs.launchpad.net/bugs/1955383
This reverts commit c513be4d8a0ec1bbe327a57bf229417b6ac2cb06.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/media/i2c/ov01a1s.c
drivers/media/i2c/power_ctrl_logic.c
drivers/media/i2c/power_ctrl_logic.h

index 8cd9e2dd4e7e85c0fed00b0b47df55bcf727054c..8c34c0da4bd4a01638ea39f4c9c06bc6140d5290 100644 (file)
@@ -836,21 +836,17 @@ static int ov01a1s_probe(struct i2c_client *client)
        struct ov01a1s *ov01a1s;
        int ret = 0;
 
-       if (power_ctrl_logic_set_power(1)) {
-               dev_dbg(&client->dev, "power control driver not ready.\n");
-               return -EPROBE_DEFER;
-       }
        ov01a1s = devm_kzalloc(&client->dev, sizeof(*ov01a1s), GFP_KERNEL);
-       if (!ov01a1s) {
-               ret = -ENOMEM;
-               goto probe_error_ret;
-       }
+       if (!ov01a1s)
+               return -ENOMEM;
 
        v4l2_i2c_subdev_init(&ov01a1s->sd, client, &ov01a1s_subdev_ops);
+       power_ctrl_logic_set_power(0);
+       power_ctrl_logic_set_power(1);
        ret = ov01a1s_identify_module(ov01a1s);
        if (ret) {
                dev_err(&client->dev, "failed to find sensor: %d", ret);
-               goto probe_error_ret;
+               return ret;
        }
 
        mutex_init(&ov01a1s->mutex);
@@ -897,8 +893,6 @@ probe_error_v4l2_ctrl_handler_free:
        v4l2_ctrl_handler_free(ov01a1s->sd.ctrl_handler);
        mutex_destroy(&ov01a1s->mutex);
 
-probe_error_ret:
-       power_ctrl_logic_set_power(0);
        return ret;
 }
 
index 1ccd94f9e97e3594ea61312a5cbc3619e5ac36d8..17665056eac4942aabf84c29c1e8855ae19eebe1 100644 (file)
@@ -1,30 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2020-2021 Intel Corporation.
 
-#include <linux/acpi.h>
+#include <linux/delay.h>
 #include <linux/module.h>
-#include <linux/device.h>
-#include <linux/mutex.h>
-#include <linux/gpio/consumer.h>
-
-#define PCL_DRV_NAME "power_ctrl_logic"
-
-struct power_ctrl_logic {
-       /* gpio resource*/
-       struct gpio_desc *reset_gpio;
-       struct gpio_desc *powerdn_gpio;
-       struct gpio_desc *clocken_gpio;
-       struct gpio_desc *indled_gpio;
-       /* status */
-       struct mutex status_lock;
-       bool power_on;
-       bool gpio_ready;
-};
-
-struct power_ctrl_gpio {
-       const char *name;
-       struct gpio_desc **pin;
-};
+#include "power_ctrl_logic.h"
 
 /* mcu gpio resources*/
 static const struct acpi_gpio_params camreset_gpio  = { 0, 0, false };
@@ -39,6 +18,10 @@ static const struct acpi_gpio_mapping dsc1_acpi_gpios[] = {
        { }
 };
 
+static const char * const pin_names[] = {
+       "camreset", "campwdn", "midmclken", "indled"
+};
+
 static struct power_ctrl_logic pcl = {
        .reset_gpio = NULL,
        .powerdn_gpio = NULL,
@@ -48,45 +31,65 @@ static struct power_ctrl_logic pcl = {
        .gpio_ready = false,
 };
 
-static struct power_ctrl_gpio pcl_gpios[] = {
-       { "camreset", &pcl.reset_gpio },
-       { "campwdn", &pcl.powerdn_gpio },
-       { "midmclken", &pcl.clocken_gpio},
-       { "indled", &pcl.indled_gpio},
-};
+static int get_gpio_pin(struct gpio_desc **pin_d, struct pci_dev *pdev, int idx)
+{
+       int count = PCL_PROBE_MAX_TRY;
+
+       do {
+               dev_dbg(&pdev->dev, "get %s:tried once\n", pin_names[idx]);
+               *pin_d = devm_gpiod_get(&pdev->dev, pin_names[idx],
+                                       GPIOD_OUT_LOW);
+               if (!IS_ERR(*pin_d))
+                       return 0;
+               *pin_d = NULL;
+               msleep_interruptible(PCL_PROBE_TRY_GAP);
+       } while (--count > 0);
+
+       return -EBUSY;
+}
 
-static int power_ctrl_logic_add(struct acpi_device *adev)
+static int power_ctrl_logic_probe(struct pci_dev *pdev,
+                                 const struct pci_device_id *id)
 {
-       int i, ret;
+       int ret;
 
-       dev_dbg(&adev->dev, "@%s, enter\n", __func__);
-       set_primary_fwnode(&adev->dev, &adev->fwnode);
+       if (!pdev) {
+               dev_err(&pdev->dev, "@%s: probed null pdev %x:%x\n",
+                       __func__, PCL_PCI_BRG_VEN_ID, PCL_PCI_BRG_PDT_ID);
+               return -ENODEV;
+       }
+       dev_dbg(&pdev->dev, "@%s, enter\n", __func__);
 
-       ret = acpi_dev_add_driver_gpios(adev, dsc1_acpi_gpios);
+       ret = devm_acpi_dev_add_driver_gpios(&pdev->dev, dsc1_acpi_gpios);
        if (ret) {
-               dev_err(&adev->dev, "@%s: --111---fail to add gpio. ret %d\n", __func__, ret);
+               dev_err(&pdev->dev, "@%s: fail to add gpio\n", __func__);
                return -EBUSY;
        }
-
-       for (i = 0; i < ARRAY_SIZE(pcl_gpios); i++) {
-               *pcl_gpios[i].pin = gpiod_get(&adev->dev, pcl_gpios[i].name, GPIOD_OUT_LOW);
-               if (IS_ERR(*pcl_gpios[i].pin)) {
-                       dev_dbg(&adev->dev, "failed to get gpio %s\n", pcl_gpios[i].name);
-                       return -EPROBE_DEFER;
-               }
-       }
+       ret = get_gpio_pin(&pcl.reset_gpio, pdev, 0);
+       if (ret)
+               goto power_ctrl_logic_probe_end;
+       ret = get_gpio_pin(&pcl.powerdn_gpio, pdev, 1);
+       if (ret)
+               goto power_ctrl_logic_probe_end;
+       ret = get_gpio_pin(&pcl.clocken_gpio, pdev, 2);
+       if (ret)
+               goto power_ctrl_logic_probe_end;
+       ret = get_gpio_pin(&pcl.indled_gpio, pdev, 3);
+       if (ret)
+               goto power_ctrl_logic_probe_end;
 
        mutex_lock(&pcl.status_lock);
        pcl.gpio_ready = true;
        mutex_unlock(&pcl.status_lock);
 
-       dev_dbg(&adev->dev, "@%s, exit\n", __func__);
+power_ctrl_logic_probe_end:
+       dev_dbg(&pdev->dev, "@%s, exit\n", __func__);
        return ret;
 }
 
-static int power_ctrl_logic_remove(struct acpi_device *adev)
+static void power_ctrl_logic_remove(struct pci_dev *pdev)
 {
-       dev_dbg(&adev->dev, "@%s, enter\n", __func__);
+       dev_dbg(&pdev->dev, "@%s, enter\n", __func__);
        mutex_lock(&pcl.status_lock);
        pcl.gpio_ready = false;
        gpiod_set_value_cansleep(pcl.reset_gpio, 0);
@@ -98,35 +101,43 @@ static int power_ctrl_logic_remove(struct acpi_device *adev)
        gpiod_set_value_cansleep(pcl.indled_gpio, 0);
        gpiod_put(pcl.indled_gpio);
        mutex_unlock(&pcl.status_lock);
-       dev_dbg(&adev->dev, "@%s, exit\n", __func__);
-       return 0;
+       dev_dbg(&pdev->dev, "@%s, exit\n", __func__);
 }
 
-static struct acpi_device_id acpi_ids[] = {
-       { "INT3472", 0 },
-       { },
+static struct pci_device_id power_ctrl_logic_ids[] = {
+       { PCI_DEVICE(PCL_PCI_BRG_VEN_ID, PCL_PCI_BRG_PDT_ID) },
+       { 0, },
 };
-MODULE_DEVICE_TABLE(acpi, acpi_ids);
-
-static struct acpi_driver _driver = {
-       .name = PCL_DRV_NAME,
-       .class = PCL_DRV_NAME,
-       .ids = acpi_ids,
-       .ops = {
-               .add = power_ctrl_logic_add,
-               .remove = power_ctrl_logic_remove,
-       },
+MODULE_DEVICE_TABLE(pci, power_ctrl_logic_ids);
+
+static struct pci_driver power_ctrl_logic_driver = {
+       .name     = PCL_DRV_NAME,
+       .id_table = power_ctrl_logic_ids,
+       .probe    = power_ctrl_logic_probe,
+       .remove   = power_ctrl_logic_remove,
 };
-module_acpi_driver(_driver);
+
+static int __init power_ctrl_logic_init(void)
+{
+       mutex_init(&pcl.status_lock);
+       return pci_register_driver(&power_ctrl_logic_driver);
+}
+
+static void __exit power_ctrl_logic_exit(void)
+{
+       pci_unregister_driver(&power_ctrl_logic_driver);
+}
+module_init(power_ctrl_logic_init);
+module_exit(power_ctrl_logic_exit);
 
 int power_ctrl_logic_set_power(int on)
 {
        mutex_lock(&pcl.status_lock);
-       if (!pcl.gpio_ready) {
+       if (!pcl.gpio_ready || on < 0 || on > 1) {
                pr_debug("@%s,failed to set power, gpio_ready=%d, on=%d\n",
                         __func__, pcl.gpio_ready, on);
                mutex_unlock(&pcl.status_lock);
-               return -EPROBE_DEFER;
+               return -EBUSY;
        }
        if (pcl.power_on != on) {
                gpiod_set_value_cansleep(pcl.reset_gpio, on);
index a7967858fbe95f74f06d8498f4cfa6bd622c51d1..1c6d71dcc62f1555e2aba2ec708e2ab9dfeb6d7b 100644 (file)
@@ -4,6 +4,30 @@
 #ifndef _POWER_CTRL_LOGIC_H_
 #define _POWER_CTRL_LOGIC_H_
 
+#include <linux/gpio/consumer.h>
+#include <linux/mutex.h>
+#include <linux/pci.h>
+
+/* pci id for probe power control logic*/
+#define PCL_PCI_BRG_VEN_ID 0x8086
+#define PCL_PCI_BRG_PDT_ID 0x9a14
+
+#define PCL_DRV_NAME "power_ctrl_logic"
+#define PCL_PROBE_MAX_TRY 5
+#define PCL_PROBE_TRY_GAP 500 /* in millseconds */
+
+struct power_ctrl_logic {
+       /* gpio resource*/
+       struct gpio_desc *reset_gpio;
+       struct gpio_desc *powerdn_gpio;
+       struct gpio_desc *clocken_gpio;
+       struct gpio_desc *indled_gpio;
+       /* status */
+       struct mutex status_lock;
+       bool power_on;
+       bool gpio_ready;
+};
+
 /* exported function for extern module */
 int power_ctrl_logic_set_power(int on);
 #endif