Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp58633ybb; Thu, 9 Apr 2020 17:11:11 -0700 (PDT) X-Google-Smtp-Source: APiQypL8xzVZz02kSMJ/mR92JpWFdpBC4cxt4ljTjyKlg3grWJ0s4EW+DvSP+6jOI40WYYpOVp0r X-Received: by 2002:a37:9a54:: with SMTP id c81mr1615468qke.185.1586477471484; Thu, 09 Apr 2020 17:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586477471; cv=none; d=google.com; s=arc-20160816; b=eRxfWOs/uyr4Vam1rQnW/HfsuymXhYAu2NY3cQBmiWzaJtbgFyq7hI1X9hvsNK+7Yb ncneNONLtFLjaqwEOVCEPt5CPm+71sN/6lp5nSGbALqE8wvEKlBsxvDbVj1oxfRFHhl/ XXmJu62CyI717zhA9a8pAPrxc0Qrr7tlbH3SSdzHjjPGkVROerNO6w/mLECLtA1KivcN FJO1owFZqc2VLm2MEl+XQwvdMJDmO1gcrtdpqgYXC1cSjqZozWvyNG0QihR4/abNdHe/ vZ2UFIcAQNdRKSf64Syexm1oPXjVUHn4rrg2RCWa2tawi9GcGiqwa+3XORD/dTXX2GkF OdFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=caullk2JpxyA8XTv34dW2t2SU+wbN7hf/K+rYHru9WI=; b=oJDFFMspD3+keO0FcwyACjaK4FIJGfSrnEBeKUSS0DpVRi2vDuU2E2VnV3BhANsAgq 1n9AswXYVZL3ThajhMuwkk2Bi1kk0Bb8Y60+4mA1jd7P3aVk3uhuUGt2NnWpfeQGa/O9 Jcl0y2ufiuD1xuoQhnBEQ6w4wokFYRaOHwdfpEhgjvWsD3rUlCRu/snxtzOG7mrIIzCD STM3Hs00KoAOe+AU6Xu3VlnWLKPRUmMuk211ixpjP9SJfYlVM5/cMojkhmYAVxvGoc6q uHYSoD7c7NffwxknqebgcnUgySYPwaMoRo1MMhsfmGMlu4mxXBPrGD25h+jD8lWyNXa5 VpiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iHl1nnP7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4si402025qka.207.2020.04.09.17.10.54; Thu, 09 Apr 2020 17:11:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iHl1nnP7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727126AbgDJAJQ (ORCPT + 99 others); Thu, 9 Apr 2020 20:09:16 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45678 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726916AbgDJAJP (ORCPT ); Thu, 9 Apr 2020 20:09:15 -0400 Received: by mail-pf1-f196.google.com with SMTP id r14so292873pfl.12 for ; Thu, 09 Apr 2020 17:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=caullk2JpxyA8XTv34dW2t2SU+wbN7hf/K+rYHru9WI=; b=iHl1nnP78KZLVM7XkDEQnzzyLTrdec91iiBkF/C3thfsUyoYBD6vueOH3Vs88g1prh uN1Gqf3EHx201mJc1a7LzIORanNmFadPXs0290zk8Ovsd1oB3OvwGyIfoz3F9PCH1bCZ QtHOrMhlqaG8h5iJEjQQcpcY5yjRYQewc8zrU= 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:mime-version:content-transfer-encoding; bh=caullk2JpxyA8XTv34dW2t2SU+wbN7hf/K+rYHru9WI=; b=a01DfneTGIXBd6fssJ9acAVHEzuGOxUJ2v5Ee+7GjYlJ8B3eWRqPhLjBK2HXqSCraS mWEKlstuD9aHlisc3XyzeF8VXBcmjaG7CIrI+f8H65RqcC662KyhAyaY9t++g3Oy5Qu8 UXVYDqI+12De+an7phaw/5QqLuyNNl1ZUbDHGMMg1BH/Vwim1hSfWmL9zSyvnZiZbG1V d497T+vmqVAk6rffE6k4lK00DcHDaWh8MzmCG+myuemAGE8UV76KJYDfV0CEtDNqfswt zJQ1V1gBKfnX275Do/iZY+1bozhkYoByHLPYldeAuFmHrH7vTNcb6rBft//zZKWMC2Sy ls6Q== X-Gm-Message-State: AGi0PuaHhqJbW8enqsJNgkPye8kWpXH50ENOOFEBOk3MoM4wJi4uOUCn Au5seXGiy4oMtpMMHW5+RZ33GPLhbcw= X-Received: by 2002:a63:af1d:: with SMTP id w29mr2039212pge.161.1586477354265; Thu, 09 Apr 2020 17:09:14 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:476b:691:abc3:38db]) by smtp.gmail.com with ESMTPSA id 6sm216421pgm.51.2020.04.09.17.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 17:09:13 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org Cc: heikki.krogerus@linux.intel.com, Prashant Malani , Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: [PATCH v2 2/3] platform/chrome: typec: Add struct for port data Date: Thu, 9 Apr 2020 17:08:21 -0700 Message-Id: <20200410000819.198668-3-pmalani@chromium.org> X-Mailer: git-send-email 2.26.0.110.g2183baf09c-goog In-Reply-To: <20200410000819.198668-1-pmalani@chromium.org> References: <20200410000819.198668-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a separate struct for storing port data, including Type C connector class struct pointers and caps. Signed-off-by: Prashant Malani --- Changes in v2: - Removed unrequired devm_kfree() call. drivers/platform/chrome/cros_ec_typec.c | 48 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index d444dd7422a2a..56ded09a60ffb 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -17,6 +17,13 @@ #define DRV_NAME "cros-ec-typec" +/* Per port data. */ +struct cros_typec_port { + struct typec_port *port; + /* Initial capabilities for the port. */ + struct typec_capability caps; +}; + /* Platform-specific data for the Chrome OS EC Type C controller. */ struct cros_typec_data { struct device *dev; @@ -24,9 +31,7 @@ struct cros_typec_data { int num_ports; unsigned int cmd_ver; /* Array of ports, indexed by port number. */ - struct typec_port *ports[EC_USB_PD_MAX_PORTS]; - /* Initial capabilities for each port. */ - struct typec_capability *caps[EC_USB_PD_MAX_PORTS]; + struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS]; struct notifier_block nb; }; @@ -76,14 +81,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap, return 0; } +static void cros_unregister_ports(struct cros_typec_data *typec) +{ + int i; + + for (i = 0; i < typec->num_ports; i++) { + if (!typec->ports[i]) + continue; + typec_unregister_port(typec->ports[i]->port); + } +} + static int cros_typec_init_ports(struct cros_typec_data *typec) { struct device *dev = typec->dev; struct typec_capability *cap; struct fwnode_handle *fwnode; + struct cros_typec_port *cros_port; const char *port_prop; int ret; - int i; int nports; u32 port_num = 0; @@ -115,22 +131,23 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) dev_dbg(dev, "Registering port %d\n", port_num); - cap = devm_kzalloc(dev, sizeof(*cap), GFP_KERNEL); - if (!cap) { + cros_port = devm_kzalloc(dev, sizeof(*cros_port), GFP_KERNEL); + if (!cros_port) { ret = -ENOMEM; goto unregister_ports; } - typec->caps[port_num] = cap; + typec->ports[port_num] = cros_port; + cap = &cros_port->caps; ret = cros_typec_parse_port_props(cap, fwnode, dev); if (ret < 0) goto unregister_ports; - typec->ports[port_num] = typec_register_port(dev, cap); - if (IS_ERR(typec->ports[port_num])) { + cros_port->port = typec_register_port(dev, cap); + if (IS_ERR(cros_port->port)) { dev_err(dev, "Failed to register port %d\n", port_num); - ret = PTR_ERR(typec->ports[port_num]); + ret = PTR_ERR(cros_port->port); goto unregister_ports; } } @@ -138,8 +155,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) return 0; unregister_ports: - for (i = 0; i < typec->num_ports; i++) - typec_unregister_port(typec->ports[i]); + cros_unregister_ports(typec); return ret; } @@ -177,7 +193,7 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, int port_num, struct ec_response_usb_pd_control *resp) { - struct typec_port *port = typec->ports[port_num]; + struct typec_port *port = typec->ports[port_num]->port; enum typec_orientation polarity; if (!resp->enabled) @@ -194,7 +210,7 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec, static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, int port_num, struct ec_response_usb_pd_control_v1 *resp) { - struct typec_port *port = typec->ports[port_num]; + struct typec_port *port = typec->ports[port_num]->port; enum typec_orientation polarity; if (!(resp->enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) @@ -358,9 +374,7 @@ static int cros_typec_probe(struct platform_device *pdev) return 0; unregister_ports: - for (i = 0; i < typec->num_ports; i++) - if (typec->ports[i]) - typec_unregister_port(typec->ports[i]); + cros_unregister_ports(typec); return ret; } -- 2.26.0.110.g2183baf09c-goog