From patchwork Fri Feb 11 14:31:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 12743506 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FEC4C433EF for ; Fri, 11 Feb 2022 14:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349561AbiBKOcL (ORCPT ); Fri, 11 Feb 2022 09:32:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233400AbiBKOcK (ORCPT ); Fri, 11 Feb 2022 09:32:10 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD942C7; Fri, 11 Feb 2022 06:32:09 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id BBAAF1F46F58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1644589928; bh=gDeJVriYJKox6JwOjdk2huzH6vrKOPc2eK3IYUX/B7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dFWLEDa41iuQkc0lluM/loGIrcLnGjRnLVT8JqNeQ8tVh7g2YUje+nqbR2Jg1GEXM 70rtzgFzS2AJ92VSvITBmMjwDOebPU0+ZZuLUxQdje/BtCpY5qHBqHbOn3tdi1x/xJ cecl+VnoCPJkCVo6PkdHB+BVqgZSb3Hazd+kTebRiPBFkuulR1cq/Uh43vCh8nrZ/K /d2uSAVL5v6yb3sWAoD6fI+TDWYJ0naM4+X02N1gwYOo0FO2k8xIu4ncwrhu+X2nVg g5TnlEU2w0SsB98IKF0YA4SfkHzld+pRyyJugPXeZ9Nu9HxwYQwILMjOsYfTMWMGRj 51okHiLlfc/Wg== From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Sanjay R Mehta , Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Lucas Tanure , Nehal Bakulchandra Shah , Charles Keepax Cc: =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 1/3] spi: amd: Use iopoll for busy waiting Date: Fri, 11 Feb 2022 11:31:53 -0300 Message-Id: <20220211143155.75513-2-andrealmeid@collabora.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220211143155.75513-1-andrealmeid@collabora.com> References: <20220211143155.75513-1-andrealmeid@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Instead of implementing a custom IO busy wait function, just use readl_poll_timeout(). Signed-off-by: André Almeida --- drivers/spi/spi-amd.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index 4b3ac7aceaf6..899b8d90ff61 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -12,6 +12,7 @@ #include #include #include +#include #define AMD_SPI_CTRL0_REG 0x00 #define AMD_SPI_EXEC_CMD BIT(16) @@ -103,16 +104,10 @@ static inline void amd_spi_set_tx_count(struct amd_spi *amd_spi, u8 tx_count) static int amd_spi_busy_wait(struct amd_spi *amd_spi) { - int timeout = 100000; + u32 val; - /* poll for SPI bus to become idle */ - while (amd_spi_readreg32(amd_spi, AMD_SPI_CTRL0_REG) & AMD_SPI_BUSY) { - usleep_range(10, 20); - if (timeout-- < 0) - return -ETIMEDOUT; - } - - return 0; + return readl_poll_timeout(amd_spi->io_remap_addr + AMD_SPI_CTRL0_REG, + val, !(val & AMD_SPI_BUSY), 20, 2000000); } static int amd_spi_execute_opcode(struct amd_spi *amd_spi) From patchwork Fri Feb 11 14:31:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 12743507 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C246C433F5 for ; Fri, 11 Feb 2022 14:32:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350879AbiBKOcS (ORCPT ); Fri, 11 Feb 2022 09:32:18 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233400AbiBKOcN (ORCPT ); Fri, 11 Feb 2022 09:32:13 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4A94C7; Fri, 11 Feb 2022 06:32:12 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id DFCE31F46F54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1644589931; bh=3ww5JixqnqYDOM7TsH5CYSgQoLb3Ym1w7KoXmSWaMCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3TJlrQNL3YFQuDzQNgWycTEenJM9OFSrRsoVcAyDwpLlk5gDgJi0HE3X6Ck0spx0 ScCIqREYik1ZUdoqtDwHY2kLSbfpvJK9z2t03Te7oXJZ6B0wYb9R3HukPGkP7JAevV faFJWO/QwasFVsRSBJlzzGXyOLIH6ayOgL5Yym0TMretxQJrN7DDunLQEjVjS8xeSk JeOPETZg8U28tseCPBhHnFOeBUFfD3Kj4BgtE1U2vy6syce8DTU9wrQATVyIMxYzV1 /FSIqoxpAV11mH93mcRzmTAtaBRy/NUImKOFbdKHjf+K88LwMRqUpXxr1WiBMTupkd Pjh0arXMo4I0Q== From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Sanjay R Mehta , Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Lucas Tanure , Nehal Bakulchandra Shah , Charles Keepax Cc: =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 2/3] spi: amd: Remove needless rom_addr variable Date: Fri, 11 Feb 2022 11:31:54 -0300 Message-Id: <20220211143155.75513-3-andrealmeid@collabora.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220211143155.75513-1-andrealmeid@collabora.com> References: <20220211143155.75513-1-andrealmeid@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org rom_addr is not used in the code, so we can just drop it from struct amd_spi. Signed-off-by: André Almeida --- drivers/spi/spi-amd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index 899b8d90ff61..417ce14a21c6 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -38,7 +38,6 @@ struct amd_spi { void __iomem *io_remap_addr; unsigned long io_base_addr; - u32 rom_addr; }; static inline u8 amd_spi_readreg8(struct amd_spi *amd_spi, int idx) From patchwork Fri Feb 11 14:31:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 12743508 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B436C433EF for ; Fri, 11 Feb 2022 14:32:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350860AbiBKOcU (ORCPT ); Fri, 11 Feb 2022 09:32:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350877AbiBKOcS (ORCPT ); Fri, 11 Feb 2022 09:32:18 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C91DFBCC; Fri, 11 Feb 2022 06:32:15 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 19E671F46F5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1644589934; bh=S+FC0Hq3W/fuvMSspDsQ7mypGtl6UOx2hHL2pfs0UnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REfZK3qLHZsuXMkhk/ZQHOfFyjBOBYMki/t+yX0j7XdmxYXVllivMECibP+R4Un67 At0oe/YxTsqd4b9HFAS+WrWLM6QdxhxEojCEPKH4uOguwRS65lr8uecnsHiHYeuTYC XE6RY988ncTu7a3b9LwBQMmGky2+ryAVC+ANJfZLWUot8fmnbnOZoDB2f0Jb4xztLU CnrzeAAU+jR8DopW4xfqlQVE1oV3/MyQOTy3CdsyyjBjvFWV+0TyadjgGAJP8LxEeZ g0F78MifFgg/WbhrPdikd1Nhe4zpCQTvS40STorUxvWppiD9qkupicI1FlRHFqOtd9 p5UMvKVk8tLKA== From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Sanjay R Mehta , Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Lucas Tanure , Nehal Bakulchandra Shah , Charles Keepax Cc: =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 3/3] spi: amd: Add support for version AMDI0062 Date: Fri, 11 Feb 2022 11:31:55 -0300 Message-Id: <20220211143155.75513-4-andrealmeid@collabora.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220211143155.75513-1-andrealmeid@collabora.com> References: <20220211143155.75513-1-andrealmeid@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Add support for the AMD SPI controller version AMDI0062. Do this in a modular way where's easy to add new versions. Signed-off-by: André Almeida Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: kernel test robot --- Change from v1: - Replace `if (version == 2)` with a more extensible switch case. drivers/spi/spi-amd.c | 81 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index 417ce14a21c6..d909afac6e21 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -19,6 +19,10 @@ #define AMD_SPI_FIFO_CLEAR BIT(20) #define AMD_SPI_BUSY BIT(31) +#define AMD_SPI_OPCODE_REG 0x45 +#define AMD_SPI_CMD_TRIGGER_REG 0x47 +#define AMD_SPI_TRIGGER_CMD BIT(7) + #define AMD_SPI_OPCODE_MASK 0xFF #define AMD_SPI_ALT_CS_REG 0x1D @@ -35,9 +39,15 @@ #define AMD_SPI_XFER_TX 1 #define AMD_SPI_XFER_RX 2 +enum amd_spi_versions { + AMD_SPI_V1 = 1, /* AMDI0061 */ + AMD_SPI_V2, /* AMDI0062 */ +}; + struct amd_spi { void __iomem *io_remap_addr; unsigned long io_base_addr; + enum amd_spi_versions version; }; static inline u8 amd_spi_readreg8(struct amd_spi *amd_spi, int idx) @@ -81,14 +91,29 @@ static void amd_spi_select_chip(struct amd_spi *amd_spi, u8 cs) amd_spi_setclear_reg8(amd_spi, AMD_SPI_ALT_CS_REG, cs, AMD_SPI_ALT_CS_MASK); } +static inline void amd_spi_clear_chip(struct amd_spi *amd_spi, u8 chip_select) +{ + amd_spi_writereg8(amd_spi, AMD_SPI_ALT_CS_REG, chip_select & ~AMD_SPI_ALT_CS_MASK); +} + static void amd_spi_clear_fifo_ptr(struct amd_spi *amd_spi) { amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, AMD_SPI_FIFO_CLEAR, AMD_SPI_FIFO_CLEAR); } -static void amd_spi_set_opcode(struct amd_spi *amd_spi, u8 cmd_opcode) +static int amd_spi_set_opcode(struct amd_spi *amd_spi, u8 cmd_opcode) { - amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, cmd_opcode, AMD_SPI_OPCODE_MASK); + switch (amd_spi->version) { + case AMD_SPI_V1: + amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, cmd_opcode, + AMD_SPI_OPCODE_MASK); + return 0; + case AMD_SPI_V2: + amd_spi_writereg8(amd_spi, AMD_SPI_OPCODE_REG, cmd_opcode); + return 0; + default: + return -ENODEV; + } } static inline void amd_spi_set_rx_count(struct amd_spi *amd_spi, u8 rx_count) @@ -104,9 +129,21 @@ static inline void amd_spi_set_tx_count(struct amd_spi *amd_spi, u8 tx_count) static int amd_spi_busy_wait(struct amd_spi *amd_spi) { u32 val; + int reg; + + switch (amd_spi->version) { + case AMD_SPI_V1: + reg = AMD_SPI_CTRL0_REG; + break; + case AMD_SPI_V2: + reg = AMD_SPI_STATUS_REG; + break; + default: + return -ENODEV; + } - return readl_poll_timeout(amd_spi->io_remap_addr + AMD_SPI_CTRL0_REG, - val, !(val & AMD_SPI_BUSY), 20, 2000000); + return readl_poll_timeout(amd_spi->io_remap_addr + reg, val, + !(val & AMD_SPI_BUSY), 20, 2000000); } static int amd_spi_execute_opcode(struct amd_spi *amd_spi) @@ -117,10 +154,20 @@ static int amd_spi_execute_opcode(struct amd_spi *amd_spi) if (ret) return ret; - /* Set ExecuteOpCode bit in the CTRL0 register */ - amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, AMD_SPI_EXEC_CMD, AMD_SPI_EXEC_CMD); - - return 0; + switch (amd_spi->version) { + case AMD_SPI_V1: + /* Set ExecuteOpCode bit in the CTRL0 register */ + amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, AMD_SPI_EXEC_CMD, + AMD_SPI_EXEC_CMD); + return 0; + case AMD_SPI_V2: + /* Trigger the command execution */ + amd_spi_setclear_reg8(amd_spi, AMD_SPI_CMD_TRIGGER_REG, + AMD_SPI_TRIGGER_CMD, AMD_SPI_TRIGGER_CMD); + return 0; + default: + return -ENODEV; + } } static int amd_spi_master_setup(struct spi_device *spi) @@ -190,6 +237,17 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, message->actual_length = tx_len + rx_len + 1; /* complete the transaction */ message->status = 0; + + switch (amd_spi->version) { + case AMD_SPI_V1: + break; + case AMD_SPI_V2: + amd_spi_clear_chip(amd_spi, message->spi->chip_select); + break; + default: + return -ENODEV; + } + spi_finalize_current_message(master); return 0; @@ -235,6 +293,8 @@ static int amd_spi_probe(struct platform_device *pdev) } dev_dbg(dev, "io_remap_address: %p\n", amd_spi->io_remap_addr); + amd_spi->version = (enum amd_spi_versions) device_get_match_data(dev); + /* Initialize the spi_master fields */ master->bus_num = 0; master->num_chipselect = 4; @@ -260,7 +320,8 @@ static int amd_spi_probe(struct platform_device *pdev) #ifdef CONFIG_ACPI static const struct acpi_device_id spi_acpi_match[] = { - { "AMDI0061", 0 }, + { "AMDI0061", AMD_SPI_V1 }, + { "AMDI0062", AMD_SPI_V2 }, {}, }; MODULE_DEVICE_TABLE(acpi, spi_acpi_match); @@ -269,7 +330,7 @@ MODULE_DEVICE_TABLE(acpi, spi_acpi_match); static struct platform_driver amd_spi_driver = { .driver = { .name = "amd_spi", - .acpi_match_table = ACPI_PTR(spi_acpi_match), + .acpi_match_table = spi_acpi_match, }, .probe = amd_spi_probe, };