From patchwork Sun Sep 17 15:26:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 141162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2212820vqi; Sun, 17 Sep 2023 09:35:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfakA4AoTXzfgHUQzIBUUCjM3tOvZWCwML8UCw0SMOVulq6ifa8y/5aRO1wP5j8wwSarKU X-Received: by 2002:a05:6a20:4306:b0:14c:7b5d:1fe0 with SMTP id h6-20020a056a20430600b0014c7b5d1fe0mr9337709pzk.3.1694968550901; Sun, 17 Sep 2023 09:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694968550; cv=none; d=google.com; s=arc-20160816; b=rHQYXVLjMPrZsigdtSmwnlx126LZ1P84+8yRH5ZQH6nFI9SSsZBl+m6S9sgvha4qxR Jd+aFLJd7qb1c+mDpiz+W2aGshN40AF/qOyuSrSh7BJPVhwhsW6VMg5VhCLcsWZ+VyO7 nj5voKykGN9xPQ4zha618f5GYWY3W2FCwdQuvzwCoY1NN2eiRAJVRxOusqV7tpgeutUP SksfezWlKAYPLGKxw3lUdeTtTgERVmhtfbgS74bJp98WOqjUkHxef05+crGlUASBJ2NI WhU5O4QjwBdNe3azr4ryh5HoUc409KUVj3Un5qdCJCRV9BKh5zQSVEvT1qbC/8yTeOz0 v9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6tQbjNBA0eBP8DdL0NmRWM+a5YA5TtpgDMffVlXzxR0=; fh=1TLHXZLxbVW/pzxFCwcQN1QIszWWCFgsgFdloZrlyPk=; b=KwHArW1PUIdHOH819Lq0OUN2HA+PMmHKFPcUNZ65dcGMZjlvlziipcWDtYzHfdcJAW cVHjmTy4CwxJv1Jj9fB+eFdsYqmpa4Hilb+oldZW2PJ6/fqph9XHWSEG3l6y+57k7tgy 4D346C2Y59RfJr4/MUVrMDQWCSJMUNVs+go/g7dE4Q21pyfKKvZjlEP8Wlcv/E2PHrvu wbi/IF1Zuc0Dp9G9U4t1nGr8EL+eHvHx/XvqKiLzXG5RaIz1Q0B/mTLwRvIKq3OeDZFD kEJ0F2ihUJcYcIC6LTWCg50nb4ptScNJ31puv7fe7ZIfSlIvqNVPVXGw8q6oQVjHXX2I Bsww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LVAOd8qj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id f21-20020a056a00229500b0068e3e4f5b90si6941189pfe.10.2023.09.17.09.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 09:35:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LVAOd8qj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7FDD68087FE6; Sun, 17 Sep 2023 08:31:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237002AbjIQP2L (ORCPT + 29 others); Sun, 17 Sep 2023 11:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234679AbjIQP1o (ORCPT ); Sun, 17 Sep 2023 11:27:44 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2AEE187; Sun, 17 Sep 2023 08:27:38 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40472c3faadso35587655e9.2; Sun, 17 Sep 2023 08:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694964457; x=1695569257; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6tQbjNBA0eBP8DdL0NmRWM+a5YA5TtpgDMffVlXzxR0=; b=LVAOd8qjwniXU/6gVi88gXGJZWSjTWRpGnnDO21kBvYTpG20pMQFQtIG9j4LET9i8C Bu2vJqCa3Kyl6dWH7ds/ZyITW9zSVsnuDJSbjxYgafKPqyQ4uQNcfGtApAiCTzhgInAo ErlRHP0imguDxh0SDaCLJ6ShaYmsCXEaBJ+prPuvivp2AqKbIYo3hPhIlJNm7sSzj5NN lCIfh0NDiUMBGB8ZRqxI1M+ARUdEBj73mSRaknMLpw77fWTLoFjij1fHj3L1z2zfCIPs Zth+RMDurKJya37AUeHRxYXnJT7Qs08n3R15NHRHFOArHcQZjkNB/S/DWbWe1NhQPQhW k46A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694964457; x=1695569257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6tQbjNBA0eBP8DdL0NmRWM+a5YA5TtpgDMffVlXzxR0=; b=MHmtSipM8is/pDhjVslD95Li27Rd6DP3f89HpGFM6GSklnd++G5/OYSHgNz5w6/2Bo v5FPPCA5pY/ce+ASg7LpMqqVf+YUq+fQu0j04fxl8DJy0mVxDAUAWgRu4vbo/wKVru6r fcAQHNoNgR+MDIC1XSYHUh2QVCyTH6ljfo7CPiWk7xMbThlcHCKBIfVVUC5qGKa/vo6/ wkEE2p+cCANbcQmnqTNOgDMpUXiV5OGnpoJiEbmzq4E1x4zfNQ1FmisxcplJhZFF1qzE PnZGDWn0MYJvXHR/lxais6czmLnwG0SG4hBPo+fakdsBCyZ9dn3jLSOEkPBBnRmUjMKO X5hg== X-Gm-Message-State: AOJu0YzP1/edZyfheOrxCGobklPPpA7C1Icma/qODkat/Uh/cnz0EF11 g7okfM00bVF+DcNgBdYBvDQ= X-Received: by 2002:a1c:4c0f:0:b0:402:fec4:fddc with SMTP id z15-20020a1c4c0f000000b00402fec4fddcmr5523275wmf.17.1694964457063; Sun, 17 Sep 2023 08:27:37 -0700 (PDT) Received: from localhost.localdomain ([5.45.134.53]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c489700b003fe15ac0934sm7388865wmp.1.2023.09.17.08.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 08:27:36 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org, linux-kernel@vger.kernel.org, abdelalkuor@geotab.com Subject: [PATCH v5 08/15] USB: typec: Add interrupt support for TPS25750 Date: Sun, 17 Sep 2023 11:26:32 -0400 Message-Id: <20230917152639.21443-9-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230917152639.21443-1-alkuor@gmail.com> References: <20230917152639.21443-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sun, 17 Sep 2023 08:31:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777303342998746914 X-GMAIL-MSGID: 1777303342998746914 From: Abdel Alkuor Update tps6598x interrupt handler to accommodate tps25750 interrupt Signed-off-by: Abdel Alkuor --- drivers/usb/typec/tipd/core.c | 49 +++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index bd5436fd88fd..17b3bc480f97 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -120,6 +120,7 @@ struct tps6598x { enum power_supply_usb_type usb_type; int wakeup; + u32 status; /* status reg */ u16 pwr_status; struct delayed_work wq_poll; irq_handler_t irq_handler; @@ -539,50 +540,71 @@ static irqreturn_t cd321x_interrupt(int irq, void *data) return IRQ_NONE; } +static bool tps6598x_has_role_changed(struct tps6598x *tps, u32 status) +{ + status ^= tps->status; + + return status & (TPS_STATUS_PORTROLE | TPS_STATUS_DATAROLE); +} + static irqreturn_t tps6598x_interrupt(int irq, void *data) { struct tps6598x *tps = data; - u64 event1 = 0; - u64 event2 = 0; + u64 event[2] = { }; u32 status; int ret; mutex_lock(&tps->lock); - ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event1); - ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event2); + if (tps->is_tps25750) { + ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event, 11); + } else { + ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event[0]); + ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event[1]); + } + if (ret) { dev_err(tps->dev, "%s: failed to read events\n", __func__); goto err_unlock; } - trace_tps6598x_irq(event1, event2); + trace_tps6598x_irq(event[0], event[1]); - if (!(event1 | event2)) + if (!(event[0] | event[1])) goto err_unlock; if (!tps6598x_read_status(tps, &status)) goto err_clear_ints; - if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) + if ((event[0] | event[1]) & TPS_REG_INT_POWER_STATUS_UPDATE) if (!tps6598x_read_power_status(tps)) goto err_clear_ints; - if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) + if ((event[0] | event[1]) & TPS_REG_INT_DATA_STATUS_UPDATE) if (!tps6598x_read_data_status(tps)) goto err_clear_ints; - /* Handle plug insert or removal */ - if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) + /* + * data/port roles could be updated independently after + * a plug event. Therefore, we need to check + * for pr/dr status change to set TypeC dr/pr accordingly. + */ + if ((event[0] | event[1]) & TPS_REG_INT_PLUG_EVENT || + tps6598x_has_role_changed(tps, status)) tps6598x_handle_plug_event(tps, status); + tps->status = status; err_clear_ints: - tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1); - tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2); + if (tps->is_tps25750) { + tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event, 11); + } else { + tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event[0]); + tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event[1]); + } err_unlock: mutex_unlock(&tps->lock); - if (event1 | event2) + if (event[0] | event[1]) return IRQ_HANDLED; return IRQ_NONE; } @@ -1003,7 +1025,6 @@ static int tps6598x_probe(struct i2c_client *client) irq_handler = cd321x_interrupt; } else { - tps->is_tps25750 = of_device_is_compatible(np, "ti,tps25750"); /* Enable power status, data status and plug event interrupts */ mask1 = TPS_REG_INT_POWER_STATUS_UPDATE |