From patchwork Mon Jan 28 20:37:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10784703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BB7C139A for ; Mon, 28 Jan 2019 20:37:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3732F2C048 for ; Mon, 28 Jan 2019 20:37:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B8BD2C2E0; Mon, 28 Jan 2019 20:37:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0F502C345 for ; Mon, 28 Jan 2019 20:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbfA1Uhn (ORCPT ); Mon, 28 Jan 2019 15:37:43 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34518 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727115AbfA1Uhn (ORCPT ); Mon, 28 Jan 2019 15:37:43 -0500 Received: by mail-pf1-f193.google.com with SMTP id h3so8558087pfg.1 for ; Mon, 28 Jan 2019 12:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mYzchNjikRNCbk6Vy9NeeLttSoN5tumBPhkzJQ0G9NQ=; b=BIiMkXx50rAe5HpKb9NQkrPwy2d1NUDjH/Yl1Tw2CGms3eR69mPJw8nKsxF3Tgko1J TqQ1uIIQgIFmP10ldN/h7H/Hyg2DbMj3l9z11abXn71RBKVb7nSJt8hFmNi7/lmV+KFy Z5RT3rnFi+VN2fPaAv3tjesXuP3aOkGvn4OyZ8hovQDMspHXjT+xfi54aWGB8DlNL42V cHM/qRdy5XV6ojYixRGgijA6tvV3np5M+Jd6kz6/K0OVf5n276hydLigGiFRfZ+bFdN1 WcfdLyRQrZrZw754C+u9hGhwX3+tpqBBlpTfbWhO6d3TKb9sncVUCD/hetmpNHILMfTY ZPSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mYzchNjikRNCbk6Vy9NeeLttSoN5tumBPhkzJQ0G9NQ=; b=CJv0RlZUuEHTYwm+dZOASlIjUZgcfx33y7U5+aLBIzwazLqHERkSnUqL+c4lAA4w93 l/4r84XtiAlp7km/7lRZjVa0XLJfnsQ7+Ev0nrfPuAksKKHx/Ot43D41Pk2BZvW66Omb pFcIk6Fh6fpJ2KHaeBwPuIc7OcMrSdmvxeAmlr6ATkmhh3P/A4ryWTAoohWwjaLW+C/A wVuBRGwE0npY1ID2PyZ36qESltbo4T0zfkSCcaatGYpDbufBq+Kg1NLpb+pUccklqwCs gA3IPcB+aq3+zjgAdkmlVtbcRss2S9zjtEIU21bwqhNCbWcByFjZCsDOd8ZkVKVoj9KT rtvQ== X-Gm-Message-State: AJcUukclYc2TF4YO8lvihF00g3SU5m109Whr8TeB2SWIQtW2gSVDQiMx AwEbo9kZXhFPgK1vb5S5pcM= X-Google-Smtp-Source: ALg8bN67SqGlYXIQW7kTrE1PTFoOdqCeuv8tzesD6IMMnR9DurSHXDuQcOpE3wS7keI0KVNcOoDaHQ== X-Received: by 2002:a63:fd53:: with SMTP id m19mr21385853pgj.340.1548707862049; Mon, 28 Jan 2019 12:37:42 -0800 (PST) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id t3sm34628047pgv.31.2019.01.28.12.37.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 12:37:41 -0800 (PST) From: Ajay Gupta X-Google-Original-From: Ajay Gupta To: heikki.krogerus@linux.intel.com Cc: linux-usb@vger.kernel.org, Ajay Gupta Subject: [PATCH v2 1/6] usb: typec: ucsi: add get_fw_info function Date: Mon, 28 Jan 2019 12:37:26 -0800 Message-Id: <20190128203731.12681-2-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128203731.12681-1-ajayg@nvidia.com> References: <20190128203731.12681-1-ajayg@nvidia.com> X-NVConfidentiality: public Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Function is to get the details of ccg firmware and device version. It will be useful in debugging and also during firmware update. Signed-off-by: Ajay Gupta --- Changes from v1: - Updated commit message - Dropped uses of bitfield - Removed dev_dbg prints drivers/usb/typec/ucsi/ucsi_ccg.c | 58 +++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index de8a43bdff68..76cf772872db 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -17,15 +17,46 @@ #include #include "ucsi.h" +struct ccg_dev_info { +#define CCG_DEVINFO_FWMODE_SHIFT (0) +#define CCG_DEVINFO_FWMODE_MASK (0x3 << CCG_DEVINFO_FWMODE_SHIFT) +#define CCG_DEVINFO_PDPORTS_SHIFT (2) +#define CCG_DEVINFO_PDPORTS_MASK (0x3 << CCG_DEVINFO_PDPORTS_SHIFT) + u8 mode; + u8 bl_mode; + u16 silicon_id; + u16 bl_last_row; +}; + +struct version_format { + u16 build; + u8 patch; + u8 ver; +#define CCG_VERSION_MIN_SHIFT (0) +#define CCG_VERSION_MIN_MASK (0xf << CCG_VERSION_MIN_SHIFT) +#define CCG_VERSION_MAJ_SHIFT (4) +#define CCG_VERSION_MAJ_MASK (0xf << CCG_VERSION_MAJ_SHIFT) +}; + +struct version_info { + struct version_format base; + struct version_format app; +}; + struct ucsi_ccg { struct device *dev; struct ucsi *ucsi; struct ucsi_ppm ppm; struct i2c_client *client; + struct ccg_dev_info info; + struct version_info version[3]; }; -#define CCGX_RAB_INTR_REG 0x06 -#define CCGX_RAB_UCSI_CONTROL 0x39 +#define CCGX_RAB_DEVICE_MODE 0x0000 +#define CCGX_RAB_INTR_REG 0x0006 +#define CCGX_RAB_READ_ALL_VER 0x0010 +#define CCGX_RAB_READ_FW2_VER 0x0020 +#define CCGX_RAB_UCSI_CONTROL 0x0039 #define CCGX_RAB_UCSI_CONTROL_START BIT(0) #define CCGX_RAB_UCSI_CONTROL_STOP BIT(1) #define CCGX_RAB_UCSI_DATA_BLOCK(offset) (0xf000 | ((offset) & 0xff)) @@ -220,6 +251,23 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) return IRQ_HANDLED; } +static int get_fw_info(struct ucsi_ccg *uc) +{ + int err; + + err = ccg_read(uc, CCGX_RAB_READ_ALL_VER, (u8 *)(&uc->version), + sizeof(uc->version)); + if (err < 0) + return err; + + err = ccg_read(uc, CCGX_RAB_DEVICE_MODE, (u8 *)(&uc->info), + sizeof(uc->info)); + if (err < 0) + return err; + + return 0; +} + static int ucsi_ccg_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -248,6 +296,12 @@ static int ucsi_ccg_probe(struct i2c_client *client, return status; } + status = get_fw_info(uc); + if (status < 0) { + dev_err(uc->dev, "get_fw_info failed - %d\n", status); + return status; + } + status = devm_request_threaded_irq(dev, client->irq, NULL, ccg_irq_handler, IRQF_ONESHOT | IRQF_TRIGGER_HIGH,