i2c: nvidia-gpu: Switch to use i2c_new_ccgx_ucsi()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 5 Jan 2022 14:19:32 +0000 (16:19 +0200)
committerWolfram Sang <wsa@kernel.org>
Tue, 15 Feb 2022 09:04:57 +0000 (10:04 +0100)
Instead of open coded variant switch to use i2c_new_ccgx_ucsi().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/busses/Kconfig
drivers/i2c/busses/i2c-nvidia-gpu.c

index 6df1bd1502330130e762ab0aa8dd8ff15795c8cd..df3ecbe8ff25b631c85a30f73a7dd67d8ccc4eef 100644 (file)
@@ -253,6 +253,7 @@ config I2C_NFORCE2_S4985
 config I2C_NVIDIA_GPU
        tristate "NVIDIA GPU I2C controller"
        depends on PCI
+       select I2C_CCGX_UCSI
        help
          If you say yes to this option, support will be included for the
          NVIDIA GPU I2C controller which is used to communicate with the GPU's
index b5055a3cbd935e7c5b0f483b4a9ba6e469eae1a4..8117c3674209c075208cb213430242b944dd2bcb 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <asm/unaligned.h>
 
+#include "i2c-ccgx-ucsi.h"
+
 /* I2C definitions */
 #define I2C_MST_CNTL                           0x00
 #define I2C_MST_CNTL_GEN_START                 BIT(0)
@@ -266,23 +268,6 @@ static const struct software_node ccgx_node = {
        .properties = ccgx_props,
 };
 
-static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq)
-{
-       i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev,
-                                          sizeof(*i2cd->gpu_ccgx_ucsi),
-                                          GFP_KERNEL);
-       if (!i2cd->gpu_ccgx_ucsi)
-               return -ENOMEM;
-
-       strlcpy(i2cd->gpu_ccgx_ucsi->type, "ccgx-ucsi",
-               sizeof(i2cd->gpu_ccgx_ucsi->type));
-       i2cd->gpu_ccgx_ucsi->addr = 0x8;
-       i2cd->gpu_ccgx_ucsi->irq = irq;
-       i2cd->gpu_ccgx_ucsi->swnode = &ccgx_node;
-       i2cd->ccgx_client = i2c_new_client_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi);
-       return PTR_ERR_OR_ZERO(i2cd->ccgx_client);
-}
-
 static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
        struct gpu_i2c_dev *i2cd;
@@ -328,9 +313,10 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        if (status < 0)
                goto free_irq_vectors;
 
-       status = gpu_populate_client(i2cd, pdev->irq);
-       if (status < 0) {
-               dev_err(&pdev->dev, "gpu_populate_client failed %d\n", status);
+       i2cd->ccgx_client = i2c_new_ccgx_ucsi(&i2cd->adapter, pdev->irq, &ccgx_node);
+       if (IS_ERR(i2cd->ccgx_client)) {
+               status = dev_err_probe(&pdev->dev, PTR_ERR(i2cd->ccgx_client),
+                                      "register UCSI failed\n");
                goto del_adapter;
        }