From patchwork Sat Feb 10 07:09:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 199209 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1336949dyd; Fri, 9 Feb 2024 23:14:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUb2cJEc5zAOUqVcAaOkxLAKOCuREH0uj4xPxG6n/NsfxdQiP5f0zvo1na2VdmEkSgBFdAfC96synW3fcnPHA+KbXnf1g== X-Google-Smtp-Source: AGHT+IFjkvzVU0Vl1q4iAzP1pXwl8BIgnRKZu1EQg9x3kptzcgsgrparXVojaYbLl3R6h8a2mbps X-Received: by 2002:aa7:da1a:0:b0:560:b00:440d with SMTP id r26-20020aa7da1a000000b005600b00440dmr959886eds.13.1707549252597; Fri, 09 Feb 2024 23:14:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707549252; cv=pass; d=google.com; s=arc-20160816; b=O/Is5TU5RGsbJKNShX1ZF1CGYlp+oOz14dxELbyPWckAGQralZDdDb3BFZpZUDJKy3 9/M0kOn40wIThP6B6B6a9eRR/74cyvK77y0wvcaLHN/5Ou908Kn4laD3Wu5IrQQA3DWl Mgn4VD8qxraF8Tq1GGRy3HAXBmipRrBrIgqNPWJbtB5Y4SVRmQOvk6HeFiblZb4wYqeg tfCUGlEPoQjXN9NXz0yvZWqXJH46v/j1QskEtsV2FFOxMm4O09oDfZn+dvbbh1dAdFL/ 1XGG/IjP5Twaj2IVwVcL1hYoslSbE5h779RK6dxj+0/xe82KimFGrqnUxYrTZARCcFXE +KFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cLa98sn79mVMdRvO7elcd3rFtE2dKbRCTOlf+cCBAQk=; fh=gzpupdJqLhGneHqWb2Brp5we2h2NGlP5S/MFO2DeNoU=; b=KLgvWuxbkxqTdCDxxo4bEvFupq+dHE0RfPqA4xDXepY4yK+2wTOGtdXXMtTv7+vbmk WmpfdBWSL/Ip3JOpO7CM2Hp6rHSql7w0gbBiCvXmepp1BowIzY12IM0oZC5U7uGtV52X gwvTU1SNRH3qabi+skXRWlg+qdI851IU0K/kabvdgTrz4jEZO2Tz8WJD1/sl61cQNf7T FcjOCJXr/Pzcdp40pT2SNnOrK3hI+h3IQd0XucrD2lWYlJpjPq1QNepHhWbQHmdwXWIm o8WMP1z6I0YQ8+JcrwNnl16qvhPLG8Ztl1JpLty4XBm2Juy1Wh9EhVB6kA9kutN/fVvi eVug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lyw5x2J3; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60316-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60316-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCXicwpRCT4Sf3lZU5HdytuH1a961eBM0AIW+MeTl09BxeNRyuK/W1TpK6UK496v1Vp/CbHFmMKcnQxR2+Kvi7Xq+FeLSw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v5-20020aa7d645000000b00560ba41655asi566475edr.328.2024.02.09.23.14.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 23:14:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60316-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lyw5x2J3; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60316-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60316-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0C7BE1F223CD for ; Sat, 10 Feb 2024 07:14:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1858D39ACC; Sat, 10 Feb 2024 07:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="lyw5x2J3" Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A95939FD6 for ; Sat, 10 Feb 2024 07:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548999; cv=none; b=C+7qqjnzO9DG1asJQNUBoN6p1k0j5fci9nn5fv63xR82mAzxvJfFhMvp2QAsXUxiCQVWkC8Ie1DppdQUBiCmtpknu0CihPfOxP+PTeOg7LMbLCMi0MhkNWI6zdYZqtvXsg0TZWF8LEF80mU0BMcvppjBUMteqQpu+KiyGuKkUd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548999; c=relaxed/simple; bh=GwUq4JCcVzOBtEc3gN3wYan172xsmr2kIqhpahEGCT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hRfix0PMu43cj9HBHA7tQ4NJ29bgqH5oqplZ0dAnqJnWeZC1iXPJ9Sw9Jy+7ygoVd7Ele8782TcUMyNjVZ88fcg13irdXCCICrjqAcfq4lE/aWoosf2JI61bVIHsdZ5+XTyjcFG5V1jxgiRzhBUI/z3JumdrihOzOzsrOgSZkHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=lyw5x2J3; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d958e0d73dso12440735ad.1 for ; Fri, 09 Feb 2024 23:09:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707548997; x=1708153797; 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=cLa98sn79mVMdRvO7elcd3rFtE2dKbRCTOlf+cCBAQk=; b=lyw5x2J3+uK9Cx1DsuoFqkMjc2l1K8/1ncJqiF8tRyAcxvKsSnL7bYeP0y5cJbM6Fl bDuYZ168C7Y5Z6yl4kSXgCoJ9ZTQ8Gmh5iQnc75KRzSdROsBCEisbxVCuT0xg+88kzV+ GESSJaAvwyJWPZLbllmTxcRkUwr2OLndBccNg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707548997; x=1708153797; 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=cLa98sn79mVMdRvO7elcd3rFtE2dKbRCTOlf+cCBAQk=; b=t34qCaJ1TwZLFB0uUrpNKFRRVhZmE2FJFbJMycuPCoFADvsLfSlTQNzNJvvcrZJM6R u24RqX0Lz/YBLj2VIWbg2VHJaIFADZkUYknxn2Phpp6TyGesBIox5fIFLp1poAKhHET8 ivk7wyg2GzNIHtbooxPAwr98g8tJvUF9tH2+2qm+HIFANxbyo0mEcJROMkAqFZbPMhx+ d8d1grz8qwvgGRFn2rJ7HBnrWFjF34qnWhqd5adfj8cuTiEjFJFOTlZYfvXlnSmv/+Zh RB/GIiBk3iMSf6y9j6e06fQPnUv/BgtKELZRRjmFMkcKfvAfmhMMJe7HmGpTh8zkAoe+ q1lQ== X-Gm-Message-State: AOJu0Yyb7criSvlsr2XR0R0wJj5byOqKoKspaFO1P2PMZFrHYavDFKe6 0YvLSQQX31MBAocLJtY6bxx8SFQOC2eu8rc5Lui68qPfZZZIR5gqA9L5FfKZPQ== X-Received: by 2002:a17:903:1d2:b0:1d9:4143:5fe1 with SMTP id e18-20020a17090301d200b001d941435fe1mr2369262plh.0.1707548996758; Fri, 09 Feb 2024 23:09:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX+9S47JyY4gdCNtKq6p6Q6R+TDCHy2IVHoHTOc3nq7FC2K4H+Qinp22boBPl2v6yZ3Q4nfK7yLXXNWHe0/UTHmWNVaY/x9pnV6ASHZjzlnHxUq/8MIEm+7/wUgodRVAn/yDQml5JspzkxJ78jfbivxNH9PUZJYbHMO0JQsxmgvSDNgkoUCsh5a+HE/+D7s3CmQJalrJlAc8t8MMidr7MP8A4QvVyfbaYvDJvKdvLo32/1Gr8tkoxt77ColNbqnY/a/7yQvf+M78QElBKweLeuDALe465OoJDkDM8V/8O/PiPQQAlZWfuKn/H6RPamx7SvzoEjD3ONViFyUaucVVRZ5bniRH6uPktTYY0H9qt3tU/QN1jh9xQ== Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id ko13-20020a17090307cd00b001d88d791eccsm2507677plb.160.2024.02.09.23.09.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 23:09:56 -0800 (PST) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Prashant Malani , Benson Leung , Tzung-Bi Shih Subject: [PATCH 10/22] platform/chrome: cros_typec_switch: Move port creation code to sub-function Date: Fri, 9 Feb 2024 23:09:21 -0800 Message-ID: <20240210070934.2549994-11-swboyd@chromium.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240210070934.2549994-1-swboyd@chromium.org> References: <20240210070934.2549994-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790495164787691391 X-GMAIL-MSGID: 1790495164787691391 This driver will soon support devicetree firmwares. Extract the struct cros_typec_port creation part of cros_typec_register_switches() into a sub-function so that we can extend it for DT, where a graph is used instead of child nodes. Cc: Prashant Malani Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/platform/chrome/cros_typec_switch.c | 113 +++++++++++--------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index a23fe80d9d4b..1a718b661203 100644 --- a/drivers/platform/chrome/cros_typec_switch.c +++ b/drivers/platform/chrome/cros_typec_switch.c @@ -201,13 +201,69 @@ static int cros_typec_register_retimer(struct cros_typec_port *port, struct fwno return PTR_ERR_OR_ZERO(port->retimer); } -static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) +static int cros_typec_register_port(struct cros_typec_switch_data *sdata, + struct fwnode_handle *fwnode) { struct cros_typec_port *port; struct device *dev = sdata->dev; - struct fwnode_handle *fwnode; struct acpi_device *adev; unsigned long long index; + int ret; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + adev = to_acpi_device_node(fwnode); + if (adev) { + ret = acpi_evaluate_integer(adev->handle, "_ADR", NULL, &index); + if (ACPI_FAILURE(ret)) { + dev_err(fwnode->dev, "_ADR wasn't evaluated\n"); + return -ENODATA; + } + } + + if (!adev) { + dev_err(fwnode->dev, "Couldn't get ACPI handle\n"); + return -ENODEV; + } + + if (index >= EC_USB_PD_MAX_PORTS) { + dev_err(fwnode->dev, "Invalid port index number: %llu\n", index); + return -EINVAL; + } + port->sdata = sdata; + port->port_num = index; + sdata->ports[index] = port; + + if (fwnode_property_present(fwnode, "retimer-switch")) { + ret = cros_typec_register_retimer(port, fwnode); + if (ret) { + dev_err(dev, "Retimer switch register failed\n"); + return ret; + } + + dev_dbg(dev, "Retimer switch registered for index %llu\n", index); + } + + if (!fwnode_property_present(fwnode, "mode-switch")) + return 0; + + ret = cros_typec_register_mode_switch(port, fwnode); + if (ret) { + dev_err(dev, "Mode switch register failed\n"); + return ret; + } + + dev_dbg(dev, "Mode switch registered for index %llu\n", index); + + return ret; +} + +static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) +{ + struct device *dev = sdata->dev; + struct fwnode_handle *fwnode; int nports, ret; nports = device_get_child_node_count(dev); @@ -217,60 +273,15 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) } device_for_each_child_node(dev, fwnode) { - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); - if (!port) { - ret = -ENOMEM; - goto err_switch; - } - - adev = to_acpi_device_node(fwnode); - if (!adev) { - dev_err(fwnode->dev, "Couldn't get ACPI device handle\n"); - ret = -ENODEV; - goto err_switch; - } - - ret = acpi_evaluate_integer(adev->handle, "_ADR", NULL, &index); - if (ACPI_FAILURE(ret)) { - dev_err(fwnode->dev, "_ADR wasn't evaluated\n"); - ret = -ENODATA; - goto err_switch; - } - - if (index >= EC_USB_PD_MAX_PORTS) { - dev_err(fwnode->dev, "Invalid port index number: %llu\n", index); - ret = -EINVAL; - goto err_switch; - } - port->sdata = sdata; - port->port_num = index; - sdata->ports[index] = port; - - if (fwnode_property_present(fwnode, "retimer-switch")) { - ret = cros_typec_register_retimer(port, fwnode); - if (ret) { - dev_err(dev, "Retimer switch register failed\n"); - goto err_switch; - } - - dev_dbg(dev, "Retimer switch registered for index %llu\n", index); - } - - if (!fwnode_property_present(fwnode, "mode-switch")) - continue; - - ret = cros_typec_register_mode_switch(port, fwnode); + ret = cros_typec_register_port(sdata, fwnode); if (ret) { - dev_err(dev, "Mode switch register failed\n"); - goto err_switch; + fwnode_handle_put(fwnode); + goto err; } - - dev_dbg(dev, "Mode switch registered for index %llu\n", index); } return 0; -err_switch: - fwnode_handle_put(fwnode); +err: cros_typec_unregister_switches(sdata); return ret; }