From patchwork Sat Feb 2 01:05:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10793909 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 6950817E9 for ; Sat, 2 Feb 2019 01:05:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5ACF232F9F for ; Sat, 2 Feb 2019 01:05:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F53B32FA0; Sat, 2 Feb 2019 01:05:25 +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 BB4EE32F9D for ; Sat, 2 Feb 2019 01:05:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbfBBBFY (ORCPT ); Fri, 1 Feb 2019 20:05:24 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42426 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbfBBBFY (ORCPT ); Fri, 1 Feb 2019 20:05:24 -0500 Received: by mail-pg1-f194.google.com with SMTP id d72so3720925pga.9 for ; Fri, 01 Feb 2019 17:05:22 -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=jLStiT4BRse05XQf1t9oNBMChtzLA8+f5xlAxVPrtx8=; b=ikwoLDuWedprcpZBz74Bs8lr55iRTplej5S+wBzEu2pdn7z+W9Vg4pfDzDeVlL+AHO TpdOvHfQ3OKsyMEFvyM73DZWkaXHLLtXOCQEga5hnbZger1MDh1CVDUCzImXO6gYEOJx DSeMbimPp+GW6DeQR2daIW1FAl0S0WbLJE7p9lBCnlkCtfjx6nVPJ4yd7wMH9kj/Towz /Y1DWQ37l6KaCeDAAdHxl6DF6AF0UfZU9p/AN6rPkPHTUreSM5wdL3QPLFEzkvRWAavw GZVpF1tW+jjKokTqXRJRjoww5pDFTmihqvn2ZBr/ii8aPcMGgoh2afzbeVRIkc2jNK/r hjnA== 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=jLStiT4BRse05XQf1t9oNBMChtzLA8+f5xlAxVPrtx8=; b=cwW0vnXC7cA5dhrcrAiX9VKWcs7bazvWJfDApFkzyO57rShsb6uP4voLOjCJp7ApwZ IXZrwbiOq/fhuSfNXcfiU/ksIinMVbOWdphNAYFyovRL232KZa06uqJTJH01CM5B61N8 Y+cE3A/ddpu4vLcwFR7GehwXOuTf1J3iHwGmFdvbL00euL5mo0sqQfjthe18HoPNbGHb KhceBCLHrtGrMQFw9cbkg2LqlmCsgWWFH/tey+07W/HQTmwjCRpCA2zruIKTDgeC823t I0G6cXcW9MAf2V0Wgx0iGGiQe2ZToMircCPQVyVR2mGyv/5R1mWvy2a9wRfaL8+2ELdS L4+w== X-Gm-Message-State: AHQUAuYE07WnZ3+q2M3pPBgGUs1aJc/a6qvIvnqiyak5C+zZUtRSH9Za bFvaJzGuFn18WVD5FVfNOlwhThjA X-Google-Smtp-Source: AHgI3IbhN5VUVKBvPAVclN8zWX0Le0p/XD1cymzH5Os0QQCFvqx93T5c5rYZPJxaixyCgT60zVjhJQ== X-Received: by 2002:a63:f844:: with SMTP id v4mr4403349pgj.82.1549069521963; Fri, 01 Feb 2019 17:05:21 -0800 (PST) Received: from ajayg.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id f6sm13158685pfg.188.2019.02.01.17.05.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 17:05:21 -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 v3 1/6] usb: typec: ucsi: add get_fw_info function Date: Fri, 1 Feb 2019 17:05:05 -0800 Message-Id: <20190202010510.25016-2-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202010510.25016-1-ajayg@nvidia.com> References: <20190202010510.25016-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 From: Ajay Gupta 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 v2 to v3 - Fixed comments from Greg on using __le16 and __packed - Added enum_fw_mode and changed version[3] to version[FW2 + 1] drivers/usb/typec/ucsi/ucsi_ccg.c | 66 ++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index de8a43bdff68..3884fb41c72e 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -17,15 +17,54 @@ #include #include "ucsi.h" +enum enum_fw_mode { + BOOT, /* bootloader */ + FW1, /* FW partition-1 (contains secondary fw) */ + FW2, /* FW partition-2 (contains primary fw) */ + FW_INVALID, +}; + +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; + __le16 silicon_id; + __le16 bl_last_row; +} __packed; + +struct version_format { + __le16 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) +} __packed; + +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; + /* version info for boot, primary and secondary */ + struct version_info version[FW2 + 1]; }; -#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 +259,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 +304,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,