ucsi_ccg: Do not hardcode interrupt polarity and type
authorSanket Goswami <Sanket.Goswami@amd.com>
Thu, 26 May 2022 06:33:04 +0000 (12:03 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Jun 2022 09:54:08 +0000 (11:54 +0200)
The current implementation supports only Level trigger with ACTIVE HIGH,
which is overriding level and polarity set by the ACPI table, hence
implement the common utility function to manage irq requests.

Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Link: https://lore.kernel.org/r/20220526063305.3144352-2-Sanket.Goswami@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi_ccg.c

index 6db7c8d..0707a71 100644 (file)
@@ -627,6 +627,16 @@ err_clear_irq:
        return IRQ_HANDLED;
 }
 
+static int ccg_request_irq(struct ucsi_ccg *uc)
+{
+       unsigned long flags = IRQF_ONESHOT;
+
+       if (!has_acpi_companion(uc->dev))
+               flags |= IRQF_TRIGGER_HIGH;
+
+       return request_threaded_irq(uc->irq, NULL, ccg_irq_handler, flags, dev_name(uc->dev), uc);
+}
+
 static void ccg_pm_workaround_work(struct work_struct *pm_work)
 {
        ccg_irq_handler(0, container_of(pm_work, struct ucsi_ccg, pm_work));
@@ -1250,9 +1260,7 @@ static int ccg_restart(struct ucsi_ccg *uc)
                return status;
        }
 
-       status = request_threaded_irq(uc->irq, NULL, ccg_irq_handler,
-                                     IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
-                                     dev_name(dev), uc);
+       status = ccg_request_irq(uc);
        if (status < 0) {
                dev_err(dev, "request_threaded_irq failed - %d\n", status);
                return status;
@@ -1331,6 +1339,7 @@ static int ucsi_ccg_probe(struct i2c_client *client,
 
        uc->dev = dev;
        uc->client = client;
+       uc->irq = client->irq;
        mutex_init(&uc->lock);
        init_completion(&uc->complete);
        INIT_WORK(&uc->work, ccg_update_firmware);
@@ -1366,16 +1375,12 @@ static int ucsi_ccg_probe(struct i2c_client *client,
 
        ucsi_set_drvdata(uc->ucsi, uc);
 
-       status = request_threaded_irq(client->irq, NULL, ccg_irq_handler,
-                                     IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
-                                     dev_name(dev), uc);
+       status = ccg_request_irq(uc);
        if (status < 0) {
                dev_err(uc->dev, "request_threaded_irq failed - %d\n", status);
                goto out_ucsi_destroy;
        }
 
-       uc->irq = client->irq;
-
        status = ucsi_register(uc->ucsi);
        if (status)
                goto out_free_irq;