From patchwork Fri Oct 20 12:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?QsO2cmdlIFN0csO8bXBmZWw=?= X-Patchwork-Id: 1852513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=wBb0uNqV; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CebQaPWe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::239; helo=mail-lj1-x239.google.com; envelope-from=swupdate+bncbdxz3sol6amrbi7hzguqmgqemvxemri@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lj1-x239.google.com (mail-lj1-x239.google.com [IPv6:2a00:1450:4864:20::239]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SBkXT38ysz20cX for ; Fri, 20 Oct 2023 23:33:45 +1100 (AEDT) Received: by mail-lj1-x239.google.com with SMTP id 38308e7fff4ca-2c5032ab59esf6905671fa.3 for ; Fri, 20 Oct 2023 05:33:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697805221; cv=pass; d=google.com; s=arc-20160816; b=Qc/qgrcN3cVre5RS6hTsmUKtw1gF6OhI5F/L5SH7Hj0xNvFKwM7xwMzb9N1JTogPYW ROUOAzRyoA/dk1MKWoQuec84GcIOf1OzUkx28/6HxUrUlu6NLDR8pdHcOkICK0nWY4mq eGQHgWvipzI4IUlJQoyC65OdFZmh3Mf5VFaUanzwc2MQuxvYgKWOg9+NPzvR4fFsfuzu AliUl2eMgTmCdT+jvFwWoSwM8Tz2/ekO1HHUX/f5ef3nvkTCWspuinv/dKFR1PZXIaKM Mq/EqItqwMkB5LD8aq5XTgh+AnTEL1XVm2+piShSK9f/csg+dkEk0Uyh7qOUWFQcraum TkFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature :dkim-signature; bh=kieSJC38AbyiBqxnloKewGw6n8M7NnZI2wHSwK3N76Q=; fh=ZW2kvPqyWkPRSWvoMc2R6zaAWiAWPTkyocNi+jZr5nQ=; b=A0AWVZvKgln3TFD3fXqB+jp3ohfRL8QeAKdPvlyoGwWomR8XOtAXzUAdELmF/9D9Zq D6AL0nmvnWYz62aaWF66F/gFet2X+UE4af5cKzTkjEQvIk1CtWnQQVJ0HFoC4xXtVW3G V6LSAYzHdFXNwD7ppE38YQQ9qo+QGjP9NEuHFZ4jWQP+Mvcx44dD1XdT+4Kyw4AZ4OGX Or/ctqrRkFQGsJhOdcpnoJNPuq2EWlizAL9Uu6DMiNAGm1TyYyb01Ih982KKUtZY4WNx +lFd1dGJk96c/xx5hjHmalzc5mo4tGKqyUMprunfbIf4gIikdkHHWWtDz9wjVEa4umIv fASw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cyTNISsJ; spf=pass (google.com: domain of boerge.struempfel@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) smtp.mailfrom=boerge.struempfel@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1697805221; x=1698410021; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=kieSJC38AbyiBqxnloKewGw6n8M7NnZI2wHSwK3N76Q=; b=wBb0uNqVlbnwjztB4cCMizHMrER0qeZTaPfOdtuXzLdA9if8eiwnjmIJInUgPPX/5s VmQQElf13WCiX1ARH7oIHpI5LNr/ZqHJFUUlqNCGa5GllbGSZx/zCgORXHm13lODsKNA 6FzGjcNNQT0zPKQNcZv4mavD0k1WoxqDc2w8ZEsuGRo8HYNT+C6XnwqO57NkH1SM5iLa 9Gi6SFTMDKiCNsvtW8ZsGfd6861mL4BYyv7COc5BxbidYVXIKKiHx5hja6XGLB8Iv+R4 g0jsAm5iDhLNttwYtrMcrCikf1v8sZcbJyuHtnBTJgC4Lx4s/EeHMHDdYTacVFkzu/7F BYgw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697805221; x=1698410021; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=kieSJC38AbyiBqxnloKewGw6n8M7NnZI2wHSwK3N76Q=; b=CebQaPWeqs3LO7QpOC+fmwWptaSssUN+iE8fiaa4zjjjDfcJPCjSRk4VpKdUz5cqXt 1WxkvabNvDEzj9JKGccC4rzrllm1mVD1zXyWCnhrjMWSsLQhU5bHsd8+Ef61EI4QcMGT JTx8nx25Gq/GwX6WyvhF/NCm5W0BoM+zHHSUCY78HluIghaVUrwgeej3R6nQF8/Botsb n8QyYG+99zktoASXC13ZUry6NHS1jtA1r4WUn7BPVhoyBc2Gfbszgku1amgGxzkm5mOY 8miSVyr1h624xAAE1g1k+NcPJ++Ksm7kg3HHDZ+AAvdMFaIA0mylFDR7QEg8nEEvl/YF 1A6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697805221; x=1698410021; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=kieSJC38AbyiBqxnloKewGw6n8M7NnZI2wHSwK3N76Q=; b=i+DcW1tzX8eK5Dlx1RnMzQb9LCKnqFmWVqSKVdVFR3DJebXCTf2cZlTrlXb2rNt+Tq yi4nuYE7/bq5E7QYcLNf8rtneFuziZGJ8M3nHdCIjWp9bjjaVA7OyLePf7AFsXxESnGz hLfpqiFTST4btRTeIf8406ihwPF/v4muWtyIGTdBcUJidGvD8dcM2UyRSBwW8Vy4D2kd 7EMT7cmFnG4fkwr3J/WnKg6p+1yv0ZNyL7V9GNN+xBoytbgko1SI5AmJ7PL16ASHvMiG 8NrZxTiJQ8S9GSMCHSoL+qkEm9je48Yc8KGpA88YYpzRzq4w07IFDP2kJvGkxseSGy0w 6duQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0YzRlmfr+L/rodGS7xAdK92T56IfqFB/AmEu7RIb4bSV8/3OFrjd 9mEiiMHsAhGNH2B7NvCM/hY= X-Google-Smtp-Source: AGHT+IEXqIO52hXNju1DVgLfJ3Kb8RZ3RhOL22RXqRAauosayL8NyGhfTPlZ1wXFk6KhvCut31heSQ== X-Received: by 2002:a2e:b896:0:b0:2c5:488c:aedf with SMTP id r22-20020a2eb896000000b002c5488caedfmr1462678ljp.37.1697805220469; Fri, 20 Oct 2023 05:33:40 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:a4c9:0:b0:2bf:f477:1991 with SMTP id p9-20020a2ea4c9000000b002bff4771991ls517710ljm.2.-pod-prod-01-eu; Fri, 20 Oct 2023 05:33:38 -0700 (PDT) X-Received: by 2002:a2e:99c2:0:b0:2c5:1bbd:37c3 with SMTP id l2-20020a2e99c2000000b002c51bbd37c3mr1255392ljj.13.1697805218186; Fri, 20 Oct 2023 05:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697805218; cv=none; d=google.com; s=arc-20160816; b=loWAoz7C0n5LvqLLRnOmxFDN+r7Q+5Q0HZUNWslzGStIPRIvJb5SNPzQsX3rpXS00y qKMrrr067xRLVwXL2kmW2fZTLTGJQaX0HtEuay6s2cchrLjAZ9AxPcFYrszbTI0vA1Ju MDWOZ0wOK3roijzPRgikquWc/CLWy4ZqNJPsEqiOJfZ8upY5EIRMmps+u4b0IGFkotdq ovWvAn5xP94ArSHjP8ky5fGBhdrQxk+eDwEF+8pPshpNQMvE8JzBxI5jBWOu09McjVgJ uio+c240prmsfC06dnc1hsvjIAZpuyK3Wzd98+SXDSMIUYy3IyIYNjAY1sgKWFkpAZOm Tccg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Z6ty6Hat0TOiOD9MAagD0CWLWLMHInis067cAI1XoAw=; fh=ZW2kvPqyWkPRSWvoMc2R6zaAWiAWPTkyocNi+jZr5nQ=; b=jzE9bVrcE9eNEMcseflglBBUQmOo75D8LmpuNAt49zzlj0HkCbXL5cm1pN78b3AcjG LrlvbV+Kjc+p6PVzkMf+6dam76cpdIj+XsunlLs0H6zsJyoLqkmb9/ecBaAkML5xgtEo fYFn/8ZyCpqH8q+rSBP6cWW8/cvhEHj6OsdA3Wta7Ruh+IkhbcSdXXZajh4EgD9q/oft kXEWCGBPPNv3LksbT9NbGuaVSNfZeTtdWxIdA+2zk6jHmnj+ojXVM+1b53LpHoGt5QyJ gVtP5XTawHMhG3D15YsSgUdwh+NH5PE0sXDBe5UM4zMM38eAAJUTyByXqgGkoVMz9+uF paRQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cyTNISsJ; spf=pass (google.com: domain of boerge.struempfel@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) smtp.mailfrom=boerge.struempfel@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com. [2a00:1450:4864:20::630]) by gmr-mx.google.com with ESMTPS id hn6-20020a05600ca38600b00401df7502b6si163247wmb.1.2023.10.20.05.33.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Oct 2023 05:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of boerge.struempfel@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) client-ip=2a00:1450:4864:20::630; Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9a6190af24aso128319766b.0 for ; Fri, 20 Oct 2023 05:33:38 -0700 (PDT) X-Received: by 2002:a17:907:1c0b:b0:9be:45b3:1c3c with SMTP id nc11-20020a1709071c0b00b009be45b31c3cmr1359322ejc.64.1697805217453; Fri, 20 Oct 2023 05:33:37 -0700 (PDT) Received: from wslxew193.fritz.box (p200300c78721530013481e3cc3df2555.dip0.t-ipconnect.de. [2003:c7:8721:5300:1348:1e3c:c3df:2555]) by smtp.gmail.com with ESMTPSA id w21-20020a170907271500b009ad81554c1bsm1392916ejk.55.2023.10.20.05.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 05:33:36 -0700 (PDT) From: Boerge Struempfel To: Cc: boerge.struempfel@gmail.com, bstruempfel@ultratronik.de, anaumann@ultratronik.de, jkleintje@ultratronik.de, swupdate@googlegroups.com Subject: [swupdate] [PATCH 3/4] ucfw: Refactored gpio handling Date: Fri, 20 Oct 2023 14:33:14 +0200 Message-ID: <20231020123320.82500-4-boerge.struempfel@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020123320.82500-1-boerge.struempfel@gmail.com> References: <20231020123320.82500-1-boerge.struempfel@gmail.com> MIME-Version: 1.0 X-Original-Sender: boerge.struempfel@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cyTNISsJ; spf=pass (google.com: domain of boerge.struempfel@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) smtp.mailfrom=boerge.struempfel@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , This commit splits the switch_mode function into the gpio-initialization, the actual mode switch and the cleanup phases. This is mainly done in order to prepare for adding gpiolib v2 api capability but has the added advantage, that the gpios are no longer released during the update, which for one prevents the gpios from floating, and for another, stops other processes from taking over the pins during an update phase. Signed-off-by: Boerge Struempfel --- handlers/ucfw_handler.c | 60 ++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c index 6b986f5..0296f17 100644 --- a/handlers/ucfw_handler.c +++ b/handlers/ucfw_handler.c @@ -111,8 +111,18 @@ struct handler_priv { unsigned int nbytes; }; -static int switch_mode(struct handler_priv *priv, int mode) -{ +static void free_gpios(struct handler_priv *priv) { + if (priv->prog.chip && (priv->prog.chip != priv->reset.chip)){ + gpiod_chip_close(priv->prog.chip); + priv->reset.chip = NULL; + } + if (priv->reset.chip) { + gpiod_chip_close(priv->reset.chip); + priv->reset.chip = NULL; + } +} + +static int register_gpios(struct handler_priv *priv){ int ret = 0; int status; @@ -145,37 +155,51 @@ static int switch_mode(struct handler_priv *priv, int mode) ERROR("Cannot request reset line"); goto freegpios; } - status = gpiod_line_request_output(priv->prog.line, PROG_CONSUMER, mode); + status = gpiod_line_request_output(priv->prog.line, PROG_CONSUMER, 0); if (status) { ret =-ENODEV; ERROR("Cannot request prog line"); goto freegpios; } + return ret; +freegpios: + free_gpios(priv); + return ret; +} + +static int switch_mode(struct handler_priv *priv, int mode) +{ + int ret = 0; + if (!priv->reset.line || !priv->prog.line) return -ENODEV; + /* * A reset is always done */ - gpiod_line_set_value(priv->reset.line, 0); + ret = gpiod_line_set_value(priv->reset.line, 0); + if (ret){ + ERROR("unable to set reset to 0"); + return ret; + } /* Set programming mode */ - gpiod_line_set_value(priv->prog.line, mode); + ret = gpiod_line_set_value(priv->prog.line, mode); + if (ret){ + ERROR("unable to set prog to %i",mode); + return ret; + } usleep(20000); /* Remove reset */ - gpiod_line_set_value(priv->reset.line, 1); + ret = gpiod_line_set_value(priv->reset.line, 1); + if (ret){ + ERROR("unable to set reset to 1"); + return ret; + } usleep(20000); -freegpios: - if (priv->prog.chip && (priv->prog.chip != priv->reset.chip)){ - gpiod_chip_close(priv->prog.chip); - priv->reset.chip = NULL; - } - if (priv->reset.chip) { - gpiod_chip_close(priv->reset.chip); - priv->reset.chip = NULL; - } return ret; } @@ -383,6 +407,11 @@ static int prepare_update(struct handler_priv *priv, char msg[128]; int len; + ret = register_gpios(priv); + if (ret < 0) { + return -ENODEV; + } + ret = switch_mode(priv, MODE_PROG); if (ret < 0) { return -ENODEV; @@ -454,6 +483,7 @@ static int finish_update(struct handler_priv *priv) close(priv->fduart); ret = switch_mode(priv, MODE_NORMAL); + free_gpios(priv); if (ret < 0) { return -ENODEV; }