From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C134BC00144 for ; Mon, 1 Aug 2022 10:11:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7EB1C84468; Mon, 1 Aug 2022 12:11:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="uhU6Rz7t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 33E6D8414A; Mon, 1 Aug 2022 12:11:25 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BC95784468 for ; Mon, 1 Aug 2022 12:11:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8EA6A61162; Mon, 1 Aug 2022 10:11:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0547C433D6; Mon, 1 Aug 2022 10:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659348680; bh=vC1G0xNSE+w+VeUtfB5xEh98KAOLPB/zjP9HC+2P+l8=; h=From:To:Cc:Subject:Date:From; b=uhU6Rz7tNlcn8hmdmDq7/rnnJBE8iFHaAa3QdvawUI7dhLtGvC0dVTQDiZ1ZpSytx K90WgrAfLjDC2NBUsp91Be5MlCTBPtTfl1tjHZKM9iUqhaKoYSplRAMnvIt7PkAc1F D5sjRmnjhAfjw7C+DT+N0aubvNeMiuA/MN5o5rsTUf+GcjGwC2cfqFhUJxI/Ft3Jbj bckuoQ1nElHL8oM9D2viKH9uE8wG+NLoOjctQ9FpDmWfpejWcQWdVauiuZzuoK7aNr X8FI4nnCo/Bf+y6Jvso01l47W9bC58OWYTXPXqYbOlp2MxmddSX3e1toaN4LMTxC+A bDD8G5uw8l7mQ== Received: by pali.im (Postfix) id 1602675F; Mon, 1 Aug 2022 12:11:17 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= Cc: u-boot@lists.denx.de Subject: [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL Date: Mon, 1 Aug 2022 12:11:13 +0200 Message-Id: <20220801101113.25186-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean CMD_GENERAL_CONTROL takes two 8-bit arguments but CMD_EXT_CONTROL takes two 16-bit arguments. Fix this issue and change CMD_EXT_CONTROL arguments to 16-bit. Fixes: 5e4d24ccc115 ("gpio: Add Turris Omnia MCU driver") Signed-off-by: Pali Rohár --- drivers/gpio/turris_omnia_mcu.c | 56 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/drivers/gpio/turris_omnia_mcu.c b/drivers/gpio/turris_omnia_mcu.c index 3e5d74e62cdb..986ccde6bc70 100644 --- a/drivers/gpio/turris_omnia_mcu.c +++ b/drivers/gpio/turris_omnia_mcu.c @@ -137,48 +137,44 @@ static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset) static int turris_omnia_mcu_set_value(struct udevice *dev, uint offset, int value) { struct turris_omnia_mcu_info *info = dev_get_plat(dev); - u8 val[2]; - int ret; - u8 reg; + u8 val16[2]; + u8 val32[4]; switch (offset) { /* bank 0 */ - case ilog2(STS_USB30_PWRON): - reg = CMD_GENERAL_CONTROL; - val[1] = CTL_USB30_PWRON; - break; - case ilog2(STS_USB31_PWRON): - reg = CMD_GENERAL_CONTROL; - val[1] = CTL_USB31_PWRON; - break; - case ilog2(STS_ENABLE_4V5): - reg = CMD_GENERAL_CONTROL; - val[1] = CTL_ENABLE_4V5; - break; - case ilog2(STS_BUTTON_MODE): - reg = CMD_GENERAL_CONTROL; - val[1] = CTL_BUTTON_MODE; - break; + case 0 ... 15: + switch (offset) { + case ilog2(STS_USB30_PWRON): + val16[1] = CTL_USB30_PWRON; + break; + case ilog2(STS_USB31_PWRON): + val16[1] = CTL_USB31_PWRON; + break; + case ilog2(STS_ENABLE_4V5): + val16[1] = CTL_ENABLE_4V5; + break; + case ilog2(STS_BUTTON_MODE): + val16[1] = CTL_BUTTON_MODE; + break; + default: + return -EINVAL; + } + val16[0] = value ? val16[1] : 0; + return dm_i2c_write(dev, CMD_GENERAL_CONTROL, val16, sizeof(val16)); /* bank 2 - supported only when FEAT_EXT_CMDS is set */ case (16 + 32 + 0) ... (16 + 32 + 15): if (!(info->features & FEAT_EXT_CMDS)) return -EINVAL; - reg = CMD_EXT_CONTROL; - val[1] = BIT(offset - 16 - 32); - break; + val32[3] = BIT(offset - 16 - 32) >> 8; + val32[2] = BIT(offset - 16 - 32) & 0xff; + val32[1] = value ? val32[3] : 0; + val32[0] = value ? val32[2] : 0; + return dm_i2c_write(dev, CMD_EXT_CONTROL, val32, sizeof(val32)); default: return -EINVAL; } - - val[0] = value ? val[1] : 0; - - ret = dm_i2c_write(dev, reg, val, 2); - if (ret) - return ret; - - return 0; } static int turris_omnia_mcu_direction_input(struct udevice *dev, uint offset) -- 2.20.1