From patchwork Fri Jan 18 01:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10769259 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 1220B6C2 for ; Fri, 18 Jan 2019 01:09:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2B302EBB0 for ; Fri, 18 Jan 2019 01:09:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3E232EBA9; Fri, 18 Jan 2019 01:09:57 +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,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 788482EBA9 for ; Fri, 18 Jan 2019 01:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbfARBJ5 (ORCPT ); Thu, 17 Jan 2019 20:09:57 -0500 Received: from hqemgate16.nvidia.com ([216.228.121.65]:14830 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfARBJ4 (ORCPT ); Thu, 17 Jan 2019 20:09:56 -0500 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 17 Jan 2019 17:09:25 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 17 Jan 2019 17:09:55 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 17 Jan 2019 17:09:55 -0800 Received: from ajayg.nvidia.com (172.17.174.172) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 18 Jan 2019 01:09:53 +0000 From: Ajay Gupta To: CC: , Ajay Gupta Subject: [PATCH 1/7] usb: typec: ucsi: add get_fw_info function Date: Thu, 17 Jan 2019 17:09:03 -0800 Message-ID: <20190118010909.16161-2-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190118010909.16161-1-ajayg@nvidia.com> References: <20190118010909.16161-1-ajayg@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-Originating-IP: [172.17.174.172] X-ClientProxiedBy: BGMAIL104.nvidia.com (10.25.59.13) To HQMAIL101.nvidia.com (172.20.187.10) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1547773765; bh=aH8vWGbgidtoqhH1fDGjsiTjqu+LeNxww61Vk58GhCo=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: X-Originating-IP:X-ClientProxiedBy:Content-Type; b=YtUR3fUuR5wP8utGHLthWeKYETrmRDnxVm1HpJOEYRsR+U4NtVsKQ32n+4bxA2dGb KTCdesqQ50S6lMbcJm8MVsTBrNl0pjPvJ0sR2Uza+ZCY5XdgofdLvetduyYn/IGCi8 2zIP3alvUsqnOLbBHTBH6p5uM13l5oVfOuuuaXHRyiUHGZxLIb8rmjrT6Neo5hr4U4 CmQ8OJfEbKU8KXHM/SdgW95g7hiMBDwsiCQDq9njh4JxytgfMFNp8JQWzCxtkKgtMo +Irp10hgYqYD0SEjd4rINrazE6O5XUxzLf9H48xVJ9w7AxHigV0ev5HSrEtslrX3xc KlIjx3RZxeV2g== 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. Signed-off-by: Ajay Gupta --- drivers/usb/typec/ucsi/ucsi_ccg.c | 76 ++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index de8a43bdff68..4d35279ab853 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 { + u8 fw_mode:2; + u8 two_pd_ports:2; + u8 row_size_256:2; + u8:1; /* reserved */ + u8 hpi_v2_mode:1; + u8 bl_mode:1; + u8 cfgtbl_invalid:1; + u8 fw1_invalid:1; + u8 fw2_invalid:1; + u8:4; /* reserved */ + u16 silicon_id; + u16 bl_last_row; +} __packed; + +struct version_format { + u16 build; + u8 patch; + u8 min:4; + u8 maj:4; +}; + +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; }; -#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,41 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) return IRQ_HANDLED; } +static int get_fw_info(struct ucsi_ccg *uc) +{ + struct device *dev = uc->dev; + struct version_info version[3]; + struct version_info *v; + int err, i; + + err = ccg_read(uc, CCGX_RAB_READ_ALL_VER, (u8 *)(&version), + sizeof(version)); + if (err < 0) + return err; + + for (i = 1; i < ARRAY_SIZE(version); i++) { + v = &version[i]; + dev_dbg(dev, + "FW%d Version: %c%c v%x.%x%x, [Base %d.%d.%d.%d]\n", + i, (v->app.build >> 8), (v->app.build & 0xFF), + v->app.patch, v->app.maj, v->app.min, + v->base.maj, v->base.min, v->base.patch, + v->base.build); + } + + err = ccg_read(uc, CCGX_RAB_DEVICE_MODE, (u8 *)(&uc->info), + sizeof(uc->info)); + if (err < 0) + return err; + + dev_dbg(dev, "fw_mode: %d\n", uc->info.fw_mode); + dev_dbg(dev, "fw1_invalid: %d\n", uc->info.fw1_invalid); + dev_dbg(dev, "fw2_invalid: %d\n", uc->info.fw2_invalid); + dev_dbg(dev, "silicon_id: 0x%04x\n", uc->info.silicon_id); + + return 0; +} + static int ucsi_ccg_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -248,6 +314,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,