From patchwork Fri Sep 17 15:13:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 12502491 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05129C4332F for ; Fri, 17 Sep 2021 15:15:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E29BC61246 for ; Fri, 17 Sep 2021 15:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343872AbhIQPQ4 (ORCPT ); Fri, 17 Sep 2021 11:16:56 -0400 Received: from mail-mw2nam12on2059.outbound.protection.outlook.com ([40.107.244.59]:52499 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S243807AbhIQPQD (ORCPT ); Fri, 17 Sep 2021 11:16:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S4rZYaMpTyciOtjo78CYybFCF2FgMzJT9Ah2koDURzlXMNfXUL91EU38ETWpgmEDLnmRdiRDQ0reNnTQUqQWALOntJQVWwEl/HFZAGfqe352ZCN98Mdfsqnqj6x9PXFq1m0NFfYl4iGUuu/BTiV2L3zTtk28cKJYAUve8BXKQ6nF5T+6mxmn1/BnI7urxkgxOiGsocvT3K50XWylMycVtJI6O6xFzqi4leAYBS2GOPDutatLraGLdnOhPSnoUyunRuWTlawnSfSI08vFiereB4ZIEbIRIQRU61ZYKbb2L9KePA+IODCC/MakxCM7EE6EiFUiTJM2+YIV7uzNhgB8VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xmd7SUjoSEyeOiv4CDsasXGm1X8plGvXuvoFzyTPzWI=; b=HjtKpd3gchW2jptLLmmALy59Adh397tq23JNZE1iAXXm2bsMwvinA1/AgdUrIuOrRapxwQvqVNvNDSqbpQAdCs9KmCDURr17sIYilCbpRTCcUSZYxLBUy+zXOLkc8f81Z3Dljt/pxTzpRbG/AQx+dXinKNHMyx3KflpX8JnjyT2CVuNY0872tXRfJtY56BtagaFASkqEfp3GTupk8nRJjvItSs2v5O0+7ACz4cD0bE4nSaU6mIIDHxhYtgY3d95x06Z2rGx+mjPwWH70UP/YgVae0Ur/fz53xfSHDtVFenpY49JA72wW9dA6lBFn1BdDIZZ651Lc5MEjAeOEpYPmFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xmd7SUjoSEyeOiv4CDsasXGm1X8plGvXuvoFzyTPzWI=; b=HU2mnuvE4ooph6y+PeiHPkRLhZ4W/4sw+n+2FQnMyMCwsT3eSj3b5F9qnQSldVO09u74ekJdYnykIZu944/e78aJTFYhRg58ph6LzeJyzqUTVi2XM8cIQC0VTCpJmU8HwNOGW3YZM3+xkT3fDeGAV7tFu5dZjBcNruY26kgRNsA= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=silabs.com; Received: from SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SA2PR11MB4876.namprd11.prod.outlook.com (2603:10b6:806:119::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 15:14:39 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd%7]) with mapi id 15.20.4500.017; Fri, 17 Sep 2021 15:14:39 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Kalle Valo Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali?= =?utf-8?q?_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v6 08/24] wfx: add bus_sdio.c Date: Fri, 17 Sep 2021 17:13:44 +0200 Message-Id: <20210917151401.2274772-9-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> References: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 Received: from pc-42.silabs.com (2a01:e34:ecb5:66a0:9876:e1d7:65be:d294) by SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 15:14:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89ec278f-e62b-4ad4-e30d-08d979edde18 X-MS-TrafficTypeDiagnostic: SA2PR11MB4876: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jpdAbdPmDFV3l5ER53uncOzstz+3Ev/G+pTq+oGUkt6AHDyV4xrzG2PG9o97EHrhpre3EiO1HT9UZ/n14TlM++qJ/itZLpIS+ksxIdugx7dTBP97rRhFa39DhhTpRi1tN8bE9UueCO51Rsu9yoeXLIFtJeTHVLs6nQ5skBlv96MNQ8jsCV7WNuy8fbqDuMwYfbEduDrb4h51lHp4zvzwU9j1wtZi6yyI1EZkZnvGoJ/dFKFAOf4tvo2xkSDeRpkO7HUrm8tAgs+Nzb1Wlbt6w1qClZC/k/zSmZQEc47cZthGb+SHh4OGLlOww63JS7c8LP5QINQVZk9zbe5g3J4nFQqhBybngu7tm7W7uutlC0VZoz83dzWDDVSPmUVC6pYBcibpXugfQwxTdgnFvEo8yehoIo1q/XfY1/dmURMPgidA9RdyidGMGiSaM+bX72EIZzKDThj5lvqJrtaE0rpJeb6MO1X1IpNDr4+NndP37G5H/k30tdsxg03G/01DKZryp4yC1u4btrEBXJRa6+b1cFlE9P4rwxmY8rIaePZrN/jNXId9yE2SOpC1CrN9MqpmF5BzbHYKs9GyLJVVaU5Lro64ZaHt496RoYCOG3lDjt12oUmo6o9z54tOgUP/04Jo3PJFDIJ1gbYEaZ9u06nBAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR11MB2718.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(66556008)(66946007)(508600001)(52116002)(7696005)(6916009)(66476007)(4326008)(316002)(6666004)(86362001)(2616005)(6486002)(1076003)(107886003)(38100700002)(83380400001)(7416002)(2906002)(54906003)(5660300002)(186003)(8676002)(8936002)(66574015)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?A5IK9BWp7aBjF6L9iIOoIhxsRas3?= =?utf-8?q?auznqtggWYWr7DTqUvh/6ww3Na+EoQScys/1mloHyP/4paxzLrEwa05CSy1LiMDMG?= =?utf-8?q?h8zNkTGMoeYXrKPlI54j4Hj67uIaO1xCKftQhnRW7N29ob7WogqZc4ZCR+TkYoNAz?= =?utf-8?q?FKY1YXpWmDH8z6I5GoKpZdURPCohxMOVc7gU4Ra+NOTVLHqN2DYjDiHmj+x0hHx+x?= =?utf-8?q?4t1zKjLgormftU00qJ+JLN3/IDyHpmjji9HOBQ2lB0PEroaKysgP6Bi5howh/KOCZ?= =?utf-8?q?tncPQpt9Qu9LnUZ9VU8Ee2LqKOPaKBttZVyi8U13pp0lNBm8TiNYvwdT5dVtCzwaU?= =?utf-8?q?QmpHcbSksI82eoJ2w7pdXfNjweSYUhtUxyFwD64DNlOexiYc7ZLAYkMM6cbciHOMu?= =?utf-8?q?hUBNQL2NJJUIdTmPaYx9Ppbj40cANSObKFRXNXYeXUdGU3Z2CTIMNKAXNRxjmzk+U?= =?utf-8?q?NX+qCTI24/oo5SStKfQFmnIh0KJoJw6QJU4eXpHu4wXBRujrKp+JEzacpogSdDHPm?= =?utf-8?q?DSBvJjS7U2B50qCOOu4ICHVm8INefLYk9GapFmBHih8sEQOL0xouQ297laWTeZR0T?= =?utf-8?q?SJOtkO6qViCz11K/kqFZWQKPsmeMxLJaQJPhMvTMVUJrTxxS48NcFIiwJTa52d248?= =?utf-8?q?v+nInglGzci/XDXCf0VYiuwf1wvoHk0hgBkJbR8X8B+5GF6Y8Jmst9Ic0vKaCagSM?= =?utf-8?q?nZ1N/b7SE0eyH0F84Nry0VxC17RZWEoItFOq9gl2CL0WrqGk8Vy7BSo9icNkipqwa?= =?utf-8?q?YtWLZN/EvOhbNs2Zxo2Qu2LpXmb7aYN+7mET1qprL1Y32Dt38q7SAFRfyhGY3740i?= =?utf-8?q?4m6tQ9HOzlwvwnEiJE1DZPclmD/05xA8NsgPH7uqyspEfPu/f0ZZmC7ARjEinYInX?= =?utf-8?q?69R7q5tERTA0ydgOTbVzTJ0PCSMTRh1B4gLz3ZZIpx5eKyvJfM9SVIhpaouyAaUAH?= =?utf-8?q?Tk/Wj3LjHC2xHoivuYQDSNygwYvj2UvkgiODwkk1eP+txwc6QZDpkX6FPXYkoDLpv?= =?utf-8?q?+LSGzwWFAeXt9Lbqj0i1Ab6wUSAvyx0kRVDPWw63oozFVNl/Jw4nfwOsNhU1UklXe?= =?utf-8?q?4cue96tLwQ3fnAk3A8UiZ+cEsW2U0ePX01e1/MoHej4qx7xUrGqUSHZCghB0VmRTK?= =?utf-8?q?+dlmgfBY1sJ5p7o6XOIXkstmrgiiRmumPncGi8Hk9WbY6WX6KHPPfGFnbxbykrT8+?= =?utf-8?q?dMIuv/p48XNn1NHUAB0PbYi1CQVYqr5kjj39cbX5FPlCgiECJuA2AvjQbE2SUzfH9?= =?utf-8?q?0JqMhyL1X9VVCaybr+rBZeXeaugHUWdLDF4bkB3+IjzF9y9UMSVvLc0Oc1RJbsfkk?= =?utf-8?q?CTokLTBgpTMYU9z?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89ec278f-e62b-4ad4-e30d-08d979edde18 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 15:14:39.2277 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rrI6lL7Xk/PdTcHvUlMin1kY5oQR5+azBXpAWV+TE+EOBJPSY34TGYdQAK0m5eGlGtlFwL8m9SdHz3CrGOBJHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB4876 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller Signed-off-by: Jérôme Pouiller --- drivers/net/wireless/silabs/wfx/bus_sdio.c | 261 +++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 drivers/net/wireless/silabs/wfx/bus_sdio.c diff --git a/drivers/net/wireless/silabs/wfx/bus_sdio.c b/drivers/net/wireless/silabs/wfx/bus_sdio.c new file mode 100644 index 000000000000..869ecb7d99db --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/bus_sdio.c @@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * SDIO interface. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bus.h" +#include "wfx.h" +#include "hwio.h" +#include "main.h" +#include "bh.h" + +static const struct wfx_platform_data wfx_sdio_pdata = { + .file_fw = "wfm_wf200", + .file_pds = "wf200.pds", +}; + +struct wfx_sdio_priv { + struct sdio_func *func; + struct wfx_dev *core; + u8 buf_id_tx; + u8 buf_id_rx; + int of_irq; +}; + +static int wfx_sdio_copy_from_io(void *priv, unsigned int reg_id, + void *dst, size_t count) +{ + struct wfx_sdio_priv *bus = priv; + unsigned int sdio_addr = reg_id << 2; + int ret; + + WARN(reg_id > 7, "chip only has 7 registers"); + WARN(((uintptr_t)dst) & 3, "unaligned buffer size"); + WARN(count & 3, "unaligned buffer address"); + + /* Use queue mode buffers */ + if (reg_id == WFX_REG_IN_OUT_QUEUE) + sdio_addr |= (bus->buf_id_rx + 1) << 7; + ret = sdio_memcpy_fromio(bus->func, dst, sdio_addr, count); + if (!ret && reg_id == WFX_REG_IN_OUT_QUEUE) + bus->buf_id_rx = (bus->buf_id_rx + 1) % 4; + + return ret; +} + +static int wfx_sdio_copy_to_io(void *priv, unsigned int reg_id, + const void *src, size_t count) +{ + struct wfx_sdio_priv *bus = priv; + unsigned int sdio_addr = reg_id << 2; + int ret; + + WARN(reg_id > 7, "chip only has 7 registers"); + WARN(((uintptr_t)src) & 3, "unaligned buffer size"); + WARN(count & 3, "unaligned buffer address"); + + /* Use queue mode buffers */ + if (reg_id == WFX_REG_IN_OUT_QUEUE) + sdio_addr |= bus->buf_id_tx << 7; + /* FIXME: discards 'const' qualifier for src */ + ret = sdio_memcpy_toio(bus->func, sdio_addr, (void *)src, count); + if (!ret && reg_id == WFX_REG_IN_OUT_QUEUE) + bus->buf_id_tx = (bus->buf_id_tx + 1) % 32; + + return ret; +} + +static void wfx_sdio_lock(void *priv) +{ + struct wfx_sdio_priv *bus = priv; + + sdio_claim_host(bus->func); +} + +static void wfx_sdio_unlock(void *priv) +{ + struct wfx_sdio_priv *bus = priv; + + sdio_release_host(bus->func); +} + +static void wfx_sdio_irq_handler(struct sdio_func *func) +{ + struct wfx_sdio_priv *bus = sdio_get_drvdata(func); + + wfx_bh_request_rx(bus->core); +} + +static irqreturn_t wfx_sdio_irq_handler_ext(int irq, void *priv) +{ + struct wfx_sdio_priv *bus = priv; + + sdio_claim_host(bus->func); + wfx_bh_request_rx(bus->core); + sdio_release_host(bus->func); + return IRQ_HANDLED; +} + +static int wfx_sdio_irq_subscribe(void *priv) +{ + struct wfx_sdio_priv *bus = priv; + u32 flags; + int ret; + u8 cccr; + + if (!bus->of_irq) { + sdio_claim_host(bus->func); + ret = sdio_claim_irq(bus->func, wfx_sdio_irq_handler); + sdio_release_host(bus->func); + return ret; + } + + flags = irq_get_trigger_type(bus->of_irq); + if (!flags) + flags = IRQF_TRIGGER_HIGH; + flags |= IRQF_ONESHOT; + ret = devm_request_threaded_irq(&bus->func->dev, bus->of_irq, NULL, + wfx_sdio_irq_handler_ext, flags, + "wfx", bus); + if (ret) + return ret; + sdio_claim_host(bus->func); + cccr = sdio_f0_readb(bus->func, SDIO_CCCR_IENx, NULL); + cccr |= BIT(0); + cccr |= BIT(bus->func->num); + sdio_f0_writeb(bus->func, cccr, SDIO_CCCR_IENx, NULL); + sdio_release_host(bus->func); + return 0; +} + +static int wfx_sdio_irq_unsubscribe(void *priv) +{ + struct wfx_sdio_priv *bus = priv; + int ret; + + if (bus->of_irq) + devm_free_irq(&bus->func->dev, bus->of_irq, bus); + sdio_claim_host(bus->func); + ret = sdio_release_irq(bus->func); + sdio_release_host(bus->func); + return ret; +} + +static size_t wfx_sdio_align_size(void *priv, size_t size) +{ + struct wfx_sdio_priv *bus = priv; + + return sdio_align_size(bus->func, size); +} + +static const struct hwbus_ops wfx_sdio_hwbus_ops = { + .copy_from_io = wfx_sdio_copy_from_io, + .copy_to_io = wfx_sdio_copy_to_io, + .irq_subscribe = wfx_sdio_irq_subscribe, + .irq_unsubscribe = wfx_sdio_irq_unsubscribe, + .lock = wfx_sdio_lock, + .unlock = wfx_sdio_unlock, + .align_size = wfx_sdio_align_size, +}; + +static const struct of_device_id wfx_sdio_of_match[] = { + { .compatible = "silabs,wfx-sdio" }, + { .compatible = "silabs,wf200" }, + { }, +}; +MODULE_DEVICE_TABLE(of, wfx_sdio_of_match); + +static int wfx_sdio_probe(struct sdio_func *func, + const struct sdio_device_id *id) +{ + struct device_node *np = func->dev.of_node; + struct wfx_sdio_priv *bus; + int ret; + + if (func->num != 1) { + dev_err(&func->dev, "SDIO function number is %d while it should always be 1 (unsupported chip?)\n", + func->num); + return -ENODEV; + } + + bus = devm_kzalloc(&func->dev, sizeof(*bus), GFP_KERNEL); + if (!bus) + return -ENOMEM; + + if (!np || !of_match_node(wfx_sdio_of_match, np)) { + dev_warn(&func->dev, "no compatible device found in DT\n"); + return -ENODEV; + } + + bus->func = func; + bus->of_irq = irq_of_parse_and_map(np, 0); + sdio_set_drvdata(func, bus); + func->card->quirks |= MMC_QUIRK_LENIENT_FN0 | + MMC_QUIRK_BLKSZ_FOR_BYTE_MODE | + MMC_QUIRK_BROKEN_BYTE_MODE_512; + + sdio_claim_host(func); + ret = sdio_enable_func(func); + /* Block of 64 bytes is more efficient than 512B for frame sizes < 4k */ + sdio_set_block_size(func, 64); + sdio_release_host(func); + if (ret) + return ret; + + bus->core = wfx_init_common(&func->dev, &wfx_sdio_pdata, + &wfx_sdio_hwbus_ops, bus); + if (!bus->core) { + ret = -EIO; + goto sdio_release; + } + + ret = wfx_probe(bus->core); + if (ret) + goto sdio_release; + + return 0; + +sdio_release: + sdio_claim_host(func); + sdio_disable_func(func); + sdio_release_host(func); + return ret; +} + +static void wfx_sdio_remove(struct sdio_func *func) +{ + struct wfx_sdio_priv *bus = sdio_get_drvdata(func); + + wfx_release(bus->core); + sdio_claim_host(func); + sdio_disable_func(func); + sdio_release_host(func); +} + +static const struct sdio_device_id wfx_sdio_ids[] = { + { SDIO_DEVICE(SDIO_VENDOR_ID_SILABS, SDIO_DEVICE_ID_SILABS_WF200) }, + { }, +}; +MODULE_DEVICE_TABLE(sdio, wfx_sdio_ids); + +struct sdio_driver wfx_sdio_driver = { + .name = "wfx-sdio", + .id_table = wfx_sdio_ids, + .probe = wfx_sdio_probe, + .remove = wfx_sdio_remove, + .drv = { + .owner = THIS_MODULE, + .of_match_table = wfx_sdio_of_match, + } +};