From patchwork Tue Jan 10 08:29:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 640838 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp2600812pvb; Tue, 10 Jan 2023 01:39:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXtXsGUhSzoz/JZ+tEEPdcIGdfGoBLUmW41U1Db/Pz8qXTRq6Zn1kO4JqhtqnX3/vOlH/NQc X-Received: by 2002:ac8:1e19:0:b0:3a7:242:501 with SMTP id n25-20020ac81e19000000b003a702420501mr102264571qtl.46.1673343564452; Tue, 10 Jan 2023 01:39:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673343564; cv=none; d=google.com; s=arc-20160816; b=pHOrIEWI1WZh98bI3zTKH58fdGgenj+vQds1CN3hEcSuqUtXj/+Gq0f4pVLhBa3hFe 7w1XgVrFsi2lF72M2QvW1No4IkJNXMd4FGT8JSmQx8P2HxvFY+68JPTG98O+RU2DqbHX DQi+w4xRkmLL1fh4Exr1RanZkvDOLyLvimp8T2cGELHfANvNfUR6CyjsYjuX78MQu2al 6m7Zr5OwLxXFsOa+1pjF23AgrMztB9R5NWyqtQD9xDq6hT+OoIugk8nWJGawgVg47YnZ xkxEjnjHyn6KADACMpZIxQmtqFQy8TGauo8nXuTTNb9tC0L4n6jhUhbid+LgFE1QtVlH ehPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iDnNDu+oMICH4wdH8XoWszonkd1H38BArRChhxQlZUY=; b=jhZ7THQ4caN9EvwShv45S8vs+c6OkD3KQH7K+/gPY44A6kg6I0MZhhENsb4l0E7SUf veTvRam8yxqHaRHroHG/QYASDGZr8pFP/4IOuAv5Q034wO56pEnLexE8qdoL+5hf0TRj lGwbaL2o+oxXEXEwP6dnrLgn3ukQntrmQJ9INYNLlFjDOkUVa+7llsODmRw1Fx+kMbkw OKZLav705tOadQTsglzUAi/pmAeSvqrsCGZ8nt5NRPYzsgvGcGDi1Hm2Y7aov9iIIX4u 6Yhg4c6zq85/frk4KaPnthXM+itOzRV2TTCteVgSbr37RR4VA6nWEY6izUa/GjMtlv6d EFkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IhhgT/jd"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d19-20020ac851d3000000b003afe9ee26b7si15013qtn.641.2023.01.10.01.39.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jan 2023 01:39:24 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IhhgT/jd"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFA17-0006fh-5M; Tue, 10 Jan 2023 03:29:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pFA11-0006eR-Sm for qemu-devel@nongnu.org; Tue, 10 Jan 2023 03:29:51 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pFA10-0006JN-CH for qemu-devel@nongnu.org; Tue, 10 Jan 2023 03:29:51 -0500 Received: by mail-wm1-x32d.google.com with SMTP id m3so8200357wmq.0 for ; Tue, 10 Jan 2023 00:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=iDnNDu+oMICH4wdH8XoWszonkd1H38BArRChhxQlZUY=; b=IhhgT/jdED5YXPhBH+OO3KYG25RU8oHkoKptSPMMkUnvrq14RWge8xot7+BYF/fYoa IaTA3ZiPJpi6oEoZd6PTQVbWG19MVIgK8ftcN9yXUO8/yWGOsYHDaSs1CIdGaaFKJnFw wYcriEdUxNH7+5Q1kj+bk5xgiBb3YhCFXoiGe1mOwD66anFS+8mTrkHbgJqPX6DkFa9i D15FCq9Yn9OgmbTvVrp2GLhTsFD/wzhs2fxME7j1YGeTo+3AGRUrJCeO72J/hQJNeJgd kF1i1Elf94RvJ51+/XFTS7sHeGD1urKDepnvnANCumMrir4PbVmOwjboXRQHfGItpObo YJ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iDnNDu+oMICH4wdH8XoWszonkd1H38BArRChhxQlZUY=; b=abF+unEnq9nqf3wEKICqsGXcIMEvV8NQdDoklQYSfbDLg+4RAF3Ml84gPDdwT2KOld 4iwNBUI2CRjvDHXMyw9tKWY8cgZVAVM5HDfgoGd5aghvGxG6bjZXjbhLBumJyDYEWPoJ WYP/VML9RZhWqa2onPD7MgXHe3eAA1cbOFhlGBR5tBfiOTV02b6cLZglzVNwqCM3u+Yb k+xVk9HmSbjKnILpHQBRXWZezQ6c/o/JkFLYOfUb9okjFxir36a+ZMVHKN/O2cejkd3P oNzeqc5CoyWU5lcAndmF5aT4bsNdQJeEA0nj2BXrSaHI1gULuzNAqBK2yCy/1VQ7yD2g Tr4Q== X-Gm-Message-State: AFqh2kphh0J50THQq4ET8UjFTcmhMLKCzlIafWHnC3KGAgRvY8ACZUbN gxTylKQ7SuWTrXoJJcnhVT5F8xCRvokFVGQS X-Received: by 2002:a05:600c:ac8:b0:3d7:7cea:b410 with SMTP id c8-20020a05600c0ac800b003d77ceab410mr48541017wmr.33.1673339388858; Tue, 10 Jan 2023 00:29:48 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id c18-20020a05600c0ad200b003d9c97d82f2sm13869803wmr.8.2023.01.10.00.29.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 10 Jan 2023 00:29:48 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Jan Kiszka , qemu-trivial@nongnu.org, qemu-arm@nongnu.org, Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Richard Henderson Subject: [PATCH v2 3/5] hw/i2c/bitbang_i2c: Change state calling bitbang_i2c_set_state() helper Date: Tue, 10 Jan 2023 09:29:30 +0100 Message-Id: <20230110082932.24386-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230110082932.24386-1-philmd@linaro.org> References: <20230110082932.24386-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/i2c/bitbang_i2c.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/hw/i2c/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c index e41cb63daa..bf4b781393 100644 --- a/hw/i2c/bitbang_i2c.c +++ b/hw/i2c/bitbang_i2c.c @@ -26,13 +26,19 @@ do { printf("bitbang_i2c: " fmt , ## __VA_ARGS__); } while (0) #define DPRINTF(fmt, ...) do {} while(0) #endif +static void bitbang_i2c_set_state(bitbang_i2c_interface *i2c, + bitbang_i2c_state state) +{ + i2c->state = state; +} + static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c) { DPRINTF("STOP\n"); if (i2c->current_addr >= 0) i2c_end_transfer(i2c->bus); i2c->current_addr = -1; - i2c->state = STOPPED; + bitbang_i2c_set_state(i2c, STOPPED); } /* Set device data pin. */ @@ -69,7 +75,7 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level) if (level == 0) { DPRINTF("START\n"); /* START condition. */ - i2c->state = SENDING_BIT7; + bitbang_i2c_set_state(i2c, SENDING_BIT7); i2c->current_addr = -1; } else { /* STOP condition. */ @@ -96,7 +102,7 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level) case SENDING_BIT7 ... SENDING_BIT0: i2c->buffer = (i2c->buffer << 1) | data; /* will end up in WAITING_FOR_ACK */ - i2c->state++; + bitbang_i2c_set_state(i2c, i2c->state + 1); return bitbang_i2c_ret(i2c, 1); case WAITING_FOR_ACK: @@ -117,13 +123,14 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level) * device we were sending to decided to NACK us). */ DPRINTF("Got NACK\n"); + bitbang_i2c_set_state(i2c, SENT_NACK); bitbang_i2c_enter_stop(i2c); return bitbang_i2c_ret(i2c, 1); } if (i2c->current_addr & 1) { - i2c->state = RECEIVING_BIT7; + bitbang_i2c_set_state(i2c, RECEIVING_BIT7); } else { - i2c->state = SENDING_BIT7; + bitbang_i2c_set_state(i2c, SENDING_BIT7); } return bitbang_i2c_ret(i2c, 0); } @@ -134,18 +141,18 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level) case RECEIVING_BIT6 ... RECEIVING_BIT0: data = i2c->buffer >> 7; /* will end up in SENDING_ACK */ - i2c->state++; + bitbang_i2c_set_state(i2c, i2c->state + 1); i2c->buffer <<= 1; return bitbang_i2c_ret(i2c, data); case SENDING_ACK: - i2c->state = RECEIVING_BIT7; if (data != 0) { DPRINTF("NACKED\n"); - i2c->state = SENT_NACK; + bitbang_i2c_set_state(i2c, SENT_NACK); i2c_nack(i2c->bus); } else { DPRINTF("ACKED\n"); + bitbang_i2c_set_state(i2c, RECEIVING_BIT7); } return bitbang_i2c_ret(i2c, 1); }