From patchwork Fri Apr 5 08:21:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 786194 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1101:b0:343:f27d:c44e with SMTP id z1csp52742wrw; Fri, 5 Apr 2024 01:22:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUOqN+K+C/9EoUSrikIAw1H1oAPhwMy5F/JxMpg0Ic6HEEZF2WflugoyDh4PHtWVobtPEy79IA8jZ1wX621zrDf X-Google-Smtp-Source: AGHT+IEqvW5b4401jfooygh7qXrdrJ6pd5vNTcLm0+z3r6gHslk1xem65SokdoKlesRGqu9uzJP5 X-Received: by 2002:a50:c2c2:0:b0:56d:b7d6:d64b with SMTP id u2-20020a50c2c2000000b0056db7d6d64bmr571488edf.29.1712305342544; Fri, 05 Apr 2024 01:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712305342; cv=none; d=google.com; s=arc-20160816; b=njVsSsOykFp1DwN5ZQw+KJzpCWPsPyxTrhjTCFyBLSC8rPpVOzeakDSo3gAjDvpu2e VvLKiaybKqtSm1wa13urP+u8A3Xxsh2HogxIGTvXaDKtjKd8Lafbl9q7uA5dP2eupjSq JDFDddJ3ELZsUsK+ecYjFaMW7r2gRnc0ghhVkJ+NG/cSRzAIKoHdaF3vYb6D3lfC7RX0 d9PdaQOONsk8z514InZOhgj5rRmgFE9UNBE19VIZKFzio3zBshYnmZUnQWz5Qp8nJ/Xi dIGEAeU87+3GY+R+f6+jtrakPuIrP2entmP3rQVbNbYyYuvxrxwUL951SQIe2hEIb3KE iJJA== 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:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=YVOcC+aJP/zP5nYNTwZP7yZVupvu+P2kFrJ8Oh6HoF4=; fh=CysUfdz8TMhrnL3XEYYwPXjcX61bp1VQIWrXNtJSfKA=; b=RqKaG86du7GJZZrS1caxexNNd+iEGRfDYSOh9jrDCCFoTHHfdXUorba5QdOy6Q+sCm zKljBFoVgvW5XgshHkl5lsp7qnh7xj08j/jYlKz7jWkb/3Y+5flJVnPqNBFco/C1+uIs Bu0a8J4cTQ190+YdoBgbXxaH5X5aWWgskPIZaJt47se0CkvOhNMyvOmEU7Bp7M6p9JIn oR+N8grhDQ7z2gzGijXR4mZOkCE3ZZ8D5rs+/DLVFLI5rpaIhMjL8rU18V3xLkgHCCqz 9KmXiUZy9S5nKDXpbteqvDAsPBwNL/FGPycKUL/UVMYpVFLW+dm2jJUxB5/t/+4ef/XF LfYg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rco2PrCG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id fd3-20020a056402388300b0056e2a14f4adsi484591edb.626.2024.04.05.01.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 01:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rco2PrCG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DEFCE8849D; Fri, 5 Apr 2024 10:22:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.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=linaro.org header.i=@linaro.org header.b="rco2PrCG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 15866884A5; Fri, 5 Apr 2024 10:22:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 634F18849F for ; Fri, 5 Apr 2024 10:22:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=neil.armstrong@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4162c2107d3so8016245e9.0 for ; Fri, 05 Apr 2024 01:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712305320; x=1712910120; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=YVOcC+aJP/zP5nYNTwZP7yZVupvu+P2kFrJ8Oh6HoF4=; b=rco2PrCGKB8inuuQBvnzxug5R6C+QxIYo4TCB9gf182m5f2ZXJefgN+9U+ceIexJIr CIAYkHY8qddFoQUOAaIN8ftD0Wnjd0C661/HjfloLgZ+X2Ao0cHP9yURcrKZH76i52RO Kw3rc++A5w2IVwfYKSHysnLCKVaMTz8yxz3A2TmAKIlyq8dONnMG3rnfa/U1JpgIh45W Yt2LWGJcpgOXGTZGCOK8iovbUQGzi092UQRPOR8+Zdx/LC2aUJHZRdE8X/9IKZ/8vVPe 1frpASu5EP3oY6UGjXKz39PaJUXf2/YOdM3ORk4svPUl5XxBR3H55scH1JBjo1IY0x3I bHYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712305320; x=1712910120; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YVOcC+aJP/zP5nYNTwZP7yZVupvu+P2kFrJ8Oh6HoF4=; b=isKqfZ4H9MbOSDInwNiP3zrBeRoAlr+MRxaxru2YraKDY/SNL5K2HINgbBD0ijgxK/ +IBwpFuHQLEtvV5gj3eFQK01mgAFEtPbdXcdbPs25jR4t9SBzAwv1x4Z3lC8CFB4LK7s j/8dB31Mh2/7e+qjXsOEucE1G4c809fQ5TghHoYWmFh3BnNjAaQfR4jRJYHBAVvnEcDC PNiobln6HI/qJTHwq5MERQVOeXiejmtgFx6VIoyOADMtsfhlbiKO2fG9aC/A3q5al8lI CBKJMWrOw6Z9/CSKxhbO75CkO9UJNB9j/g7qgaGqbxywSRnOKR9WAaLgQq0ceY81Bj4p Sc8g== X-Gm-Message-State: AOJu0YwnYkMiCE/6O6CZ95wHRn0xDY7tNyI0WdLGxTKviO5aR4BCyY3B 3DeWB9zbqEWpphcJTGPLa3AyvbQNjeua/gGOdEyeVKfbMi7nlx0BREtIwifyeoA= X-Received: by 2002:a5d:5146:0:b0:33e:6366:5f2a with SMTP id u6-20020a5d5146000000b0033e63665f2amr648184wrt.5.1712305319633; Fri, 05 Apr 2024 01:21:59 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id j27-20020adfb31b000000b00341d84f641asm1452326wrd.8.2024.04.05.01.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 01:21:59 -0700 (PDT) From: Neil Armstrong Date: Fri, 05 Apr 2024 10:21:54 +0200 Subject: [PATCH 2/4] spmi: msm: properly format command MIME-Version: 1.0 Message-Id: <20240405-topic-sm8x50-spmi-fixes-v1-2-031a9e5efab4@linaro.org> References: <20240405-topic-sm8x50-spmi-fixes-v1-0-031a9e5efab4@linaro.org> In-Reply-To: <20240405-topic-sm8x50-spmi-fixes-v1-0-031a9e5efab4@linaro.org> To: Caleb Connolly , Sumit Garg , Mateusz Kulikowski , Tom Rini , Dzmitry Sankouski Cc: u-boot@lists.denx.de, Neil Armstrong X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3605; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=L7dT0VNmPI3dYsmh0xmaANK0mnY7T76P4RWPgWp44w8=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBmD7SkhdfKS6R+LA5YCAeJ68mm04B/mMBSeVGzZ5Ho XhpKCLWJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZg+0pAAKCRB33NvayMhJ0f/oD/ 9w0YQxl7GiqzKQ9/qpwhsDqAhP29yxXq4bas6rAoPJf70u/WZB8UKLKxX/+kb2l8+ObXFv+iyjTfbV pjlrZrV/7wgEom2cgQG5amM6tt/EXsX/duZvs/j5L76Oa9RqTApsSIh7774Bo5CRPVyF2l2YIoV5Kl sUc8yV8IEe7ZXyC3FFWjJHN/32uaps/7/aeOIqgzcDfyOubW0lhSXzNGB26BAI46xxLpOQhVaYhXkj npLyyVpV6yXCjTqmroNPgy0tDbq22s73pM6G9jk2PtckrIIPR2h9eISNpU24sUHGcUWQXUtSxz7vsq I13JpX1HhLC7+dEnJHmvcax3FHhwGWwufI095oEa0TGGQbKn+H/it5MWpvxcnHsYApX9tuiT6m2LVX YLQRzWXljkQZ2yBmLGNIEgzMp9dbs+fyVHC/ZKByHIuU5wkTtflxmUamGURHgZODn8rTP3fD5Ydhhp 8a+kbKKGBO/vaP6IdkVaba+76eCnGtQnSgQpnYGObjp+k5Es2ON4X7F4vBR/xXSRiZKsQaJuSXcGRV 7D5KQf/5pbBUl2WXb+9ODdcWDiWKBYC2prhPPCdix90qnbAYlvvh7CU9A1NQ/1NWKKhqJa7M+AviLc +m2/qfMj+TB+HFKTMpdjPwQH4HLaHSuXodKg5ztTkFKOzcEmJyqgkwD2nHkw== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE 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.8 at phobos.denx.de X-Virus-Status: Clean Since version 2, the cmd format has changed, takes helpers from Linux driver and use a switch/case to handle all versions in msm_spmi_write/read() command. Signed-off-by: Neil Armstrong --- drivers/spmi/spmi-msm.c | 75 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/drivers/spmi/spmi-msm.c b/drivers/spmi/spmi-msm.c index 97383d8c7b8..68bb8a38c3c 100644 --- a/drivers/spmi/spmi-msm.c +++ b/drivers/spmi/spmi-msm.c @@ -78,6 +78,16 @@ struct msm_spmi_priv { u32 arb_ver; }; +static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u8 pid, u8 off) +{ + return (opc << 27) | (sid << 20) | (pid << 12) | (off << 4) | 1; +} + +static u32 pmic_arb_fmt_cmd_v2(u8 opc, u8 off) +{ + return (opc << 27) | (off << 4) | 1; +} + static int msm_spmi_write(struct udevice *dev, int usid, int pid, int off, uint8_t val) { @@ -93,24 +103,35 @@ static int msm_spmi_write(struct udevice *dev, int usid, int pid, int off, channel = priv->channel_map[usid][pid]; - if (priv->arb_ver == V5) - ch_offset = SPMI_V5_RW_CH_OFFSET(channel); - else + dev_dbg(dev, "[%d:%d] %s: channel %d\n", usid, pid, __func__, channel); + + switch (priv->arb_ver) { + case V1: + ch_offset = SPMI_CH_OFFSET(channel); + + reg = pmic_arb_fmt_cmd_v1(SPMI_CMD_EXT_REG_WRITE_LONG, + usid, pid, off); + break; + + case V2: ch_offset = SPMI_CH_OFFSET(channel); + reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_WRITE_LONG, off); + break; + + case V5: + ch_offset = SPMI_V5_RW_CH_OFFSET(channel); + + reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_WRITE_LONG, off); + break; + } + /* Disable IRQ mode for the current channel*/ writel(0x0, priv->spmi_chnls + ch_offset + SPMI_REG_CONFIG); /* Write single byte */ writel(val, priv->spmi_chnls + ch_offset + SPMI_REG_WDATA); - /* Prepare write command */ - reg |= SPMI_CMD_EXT_REG_WRITE_LONG << SPMI_CMD_OPCODE_SHIFT; - reg |= (usid << SPMI_CMD_SLAVE_ID_SHIFT); - reg |= (pid << SPMI_CMD_ADDR_SHIFT); - reg |= (off << SPMI_CMD_ADDR_OFFSET_SHIFT); - reg |= 1; /* byte count */ - /* Send write command */ writel(reg, priv->spmi_chnls + ch_offset + SPMI_REG_CMD0); @@ -143,21 +164,35 @@ static int msm_spmi_read(struct udevice *dev, int usid, int pid, int off) channel = priv->channel_map[usid][pid]; - if (priv->arb_ver == V5) - ch_offset = SPMI_V5_OBS_CH_OFFSET(channel); - else + dev_dbg(dev, "[%d:%d] %s: channel %d\n", usid, pid, __func__, channel); + + switch (priv->arb_ver) { + case V1: + ch_offset = SPMI_CH_OFFSET(channel); + + /* Prepare read command */ + reg = pmic_arb_fmt_cmd_v1(SPMI_CMD_EXT_REG_READ_LONG, + usid, pid, off); + break; + + case V2: ch_offset = SPMI_CH_OFFSET(channel); + /* Prepare read command */ + reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_READ_LONG, off); + break; + + case V5: + ch_offset = SPMI_V5_OBS_CH_OFFSET(channel); + + /* Prepare read command */ + reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_READ_LONG, off); + break; + } + /* Disable IRQ mode for the current channel*/ writel(0x0, priv->spmi_obs + ch_offset + SPMI_REG_CONFIG); - /* Prepare read command */ - reg |= SPMI_CMD_EXT_REG_READ_LONG << SPMI_CMD_OPCODE_SHIFT; - reg |= (usid << SPMI_CMD_SLAVE_ID_SHIFT); - reg |= (pid << SPMI_CMD_ADDR_SHIFT); - reg |= (off << SPMI_CMD_ADDR_OFFSET_SHIFT); - reg |= 1; /* byte count */ - /* Request read */ writel(reg, priv->spmi_obs + ch_offset + SPMI_REG_CMD0);