From patchwork Mon Mar 15 13:24:45 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: 12139529 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.8 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, 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 02E4FC433E6 for ; Mon, 15 Mar 2021 13:46:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B055764EE3 for ; Mon, 15 Mar 2021 13:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbhCON0T (ORCPT ); Mon, 15 Mar 2021 09:26:19 -0400 Received: from mail-mw2nam10on2048.outbound.protection.outlook.com ([40.107.94.48]:59751 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230386AbhCONZq (ORCPT ); Mon, 15 Mar 2021 09:25:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iS/iDaDnkJjvxoq7UhCKFiE2lScvLkPO4lnf29xp1orNNVgN7Jn8RwdB0kuQmwdk5O3GJVtj55qRLQjupNuKVDnUHUFzvHqAFtqCfL09FXx6yQrj2zBGfIJE7eYyqYmzs02XWdYV8t6FxAQSHKg85HFDorVBSB+JUckXhglbu41X1SlVihl7l4+AYpsDNnui01XjRFpa58RtL0l+l7NUKa+rv6TZxRh2HUSD9ZF1cr++nwXUFzC3twB0IPMyv5YJraR02qhukFVr15q92gCGkfQkxxOGNWPPKvv3TodDs/5iL770rzhklggFCBPs1OJ07IcoequJxR00BYyEZfZjXw== 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:X-MS-Exchange-SenderADCheck; bh=HE9qpTIHbkJvCj7PV9cILnllRgQW9KyY3MO8fZz9G+c=; b=hAtfk0JJKBnY+0TvRIVmy5uY9RrvwCdG4Y3HDTJhD8ZQwPBpwa0AyrzEBRd0p8IEfGJW++n0JZdZ8TWjbCnOT8wxe7VtaIl1khRBY6pCGir4ErzLxq2EqlZc1JhDgmZu6rc7AGGGMnap4hW8ZqTgRIbe7cveKhHoVmR4kzuaC7ZlBATBmAvP45/mHoWdqqZuUg1yJZl3rRXSCau07TGqpCL2yJRnQmf4WL08tHXDh6ZveFBDWyFyl/XG2XJrIKZxgJudOMoRpQkmLblo6sO3C8UbfcKvVRVgT5LcMXPDfAlyFso+Ao5ep2zPz1wodtPEPtCZz6MgFWhXFuACrEXcIg== 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=HE9qpTIHbkJvCj7PV9cILnllRgQW9KyY3MO8fZz9G+c=; b=VFFh3BHYvfDn6mfhSjb0p3N1z8Or8RQLivXPcVQkewHo/yjlVNR6O8SkZ4g73mzPOn+PTV1SNaBCxaP8QuwW5toLUb6d3JoJjslbY7b9eF4E36ZSo0Re6bGKVQIwzRC41VPGoKJ9F3Ato+xTOHzV+j/Pmr0T2bDW5YXGi/OjgeY= 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 SA0PR11MB4544.namprd11.prod.outlook.com (2603:10b6:806:92::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 13:25:44 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701%7]) with mapi id 15.20.3933.032; Mon, 15 Mar 2021 13:25:44 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v5 08/24] wfx: add bus_sdio.c Date: Mon, 15 Mar 2021 14:24:45 +0100 Message-Id: <20210315132501.441681-9-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> References: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> X-Originating-IP: [2a01:e35:2435:66a0:544b:f17b:7ae8:fb7] X-ClientProxiedBy: SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pc-42.silabs.com (2a01:e35:2435:66a0:544b:f17b:7ae8:fb7) by SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 13:25:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd02f314-73c6-4f71-704d-08d8e7b5d643 X-MS-TrafficTypeDiagnostic: SA0PR11MB4544: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iWi3JNv/aMBR83LiwymqnXdluLsYT7oqLiYWDJUmI+1hkKimG+o9uNd0N8FfqY29T4E+nRwz1UZvguyPMfMtgJQ72hyPVi7r2HTDXisyIx+J6zNKLRBgwOxXIW8A7PY3tzZ21h1V8uc0UVugsx2X26ScDVbiyW0pUhrRyPCo85f/7ztRgqUsJQhXKDuZ8vpS7N1OqxG5b5kgXILh+BeiDyeSFt91Ny/q0fWYqTPPBQoIiCsgXMUG5XZTxR0j3miN8yN/g6ls5DVLi9gOwroYmWJEiRgVz1Go0yv077BmKxTGuKSWs134hROQPq4RWF9qeTfzOQCVUJvdDI+txf/EL3niQEi1cVK7zNmh5VYIV1uyjZ0+LGAyzlK2CroC/L1HBWKj8CjoKF2gpCaxLxEp0vDskNENrpSl5s27TSoY9/pN025/OCgtrkVuxFL/od8JWFOihluKXPEuFxIQW4a4wZFZIzGXsP2NVjcX/OD4TIqOLSejBn0OjgmcVJCXC0vmF6uusV4jFsrdnOIWi277rumXeWoUjr7S7AAj2se1PVSetksHipZkCuG9h32oyMpE 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:(346002)(396003)(366004)(376002)(39850400004)(136003)(66574015)(8676002)(186003)(52116002)(86362001)(5660300002)(6486002)(7696005)(2906002)(83380400001)(4326008)(66476007)(16526019)(2616005)(107886003)(66946007)(8936002)(66556008)(1076003)(478600001)(36756003)(7416002)(316002)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?VaW/EZqbZTlKFU/wxy4O+ju3k0PX9d?= =?utf-8?q?8U0aDKCi2YgaijKsJoyAu8ux7zFfoGt2vjh0hcuDewzdBZwM4Em3FbnZSgy0cigCC?= =?utf-8?q?QTmyRXTAy/kIWsgQxhwFFkMNz7+DWRQvbksxnTnGmdunXuAH9yiFpbq8SWsEIjjAz?= =?utf-8?q?1Sn9mERn0lDmuN/BEV5TNKPZaEjZyA3ik90zZKL4P5cA4kD61BJMIJwamRPavoT0S?= =?utf-8?q?vHcwCeLJTZRUoDm99RKyyGZWI8d94xEFE/OtLCJeWmWQ8G4gD7EMQeO9v62dT9LIk?= =?utf-8?q?slpVraD1p3mRdWgf0Ruvd81+CQwlYDAr1LjKQqV8Owjpp/RxmHNgMBI4sBv9dVivg?= =?utf-8?q?0Lm85Svn3dWKEjYtR5qoVMIUi07WrpMzRVHhzyodKyXgHlhHvJgKY9RhQ3xvMjSDe?= =?utf-8?q?+GtHuR7uDL/KVUmE7vczL9hfBWeTtCauMPxyter6VZFrgc9oWjkhpYCuelqYK8Lo7?= =?utf-8?q?kT2SbWA2kRGVP3SwlC91S00/nv9kRTC6X8Trmp/QGby437PGzpFIjPtQeCQCSVqCn?= =?utf-8?q?P+OdNGQcjgukwXg+vYLUB5q1gxoNdBG1TwCCBP42zMcSXdEG5s05jaHFkfueK4+x8?= =?utf-8?q?SMaCY/rzOFp/JAMU4C27IM7dmtXsRdaEey47PFIwek8SbelW5Y4Y7yoHYYckhDKsx?= =?utf-8?q?rwVdhMQq5gGPMxw1pOFvLjv3cdO3ZvLzyQUvb1pyN0uMi9urtopd3BegqcCeUSEQB?= =?utf-8?q?5gvjC9y4sEqfuWiuOAsRRoguew+3HKlScOh2prr8+EFJbNCz39bhWIth3RnVUDHDM?= =?utf-8?q?XqdnMATkfrmkFhDpBbWnDJ43L6goM4YBTZEVzZNoK9731/dmJhEhRjNw7wLkoWs14?= =?utf-8?q?yGnsi95/LacMk0v5vOvSTg1dcRT/9XrR5FXCbMVYKMcMt7p0rTCT+DJiSnrLi5GS2?= =?utf-8?q?e/FsZrTn90ivS8b4rfTfW5w3WA4YO1C066HQhqyAEfforchuOdt4mIJ5RLoAVLk8j?= =?utf-8?q?ACstCVxF7K5YzbVeqecPmDMB4dVOterkKrw5n9zqxdk2Lcz98eQfJq1Io1orqYG/L?= =?utf-8?q?dYIqL/7D41MtiZ2qAki8o++We+XXuclUgBvsLM7Q3UJG1s1+HDqIYnJJ33T++m567?= =?utf-8?q?1yZGhTyABhEGNU5S/IoM2xGwacI4r4h4sJSThqSKJ7j1eDlr0USNgS1PL8m1uJv5q?= =?utf-8?q?B+L0SbKQuiJlljxprpHyaOpbMN3q/g898fAjpcHjIn6aGvvpl+mnS5bOpE3TkoiOD?= =?utf-8?q?/G47wpja3CPwg6IDAEU6vzqDCR0ZZO4SJev/7TyVmVGovWUdPQ5Q/BecSpr2zlCTa?= =?utf-8?q?EcLqHrgHXsLpqYhsCase4XddenUDzz9tjc9sDnaEhXw8kiAmP6ParNpQBtukFwso5?= =?utf-8?q?7aWKQ5OlyoAg9?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd02f314-73c6-4f71-704d-08d8e7b5d643 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 13:25:44.5204 (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: ip7t16nqNn7jxkJIbULJcZi/jp6d9oFmto+dr7HwGKmODbAxNT8o/bInCY293JVGesRwC/J2BtzHu16cKPGOWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR11MB4544 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 | 259 +++++++++++++++++++++ 1 file changed, 259 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..55b6728416ba --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/bus_sdio.c @@ -0,0 +1,259 @@ +// 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; + } + + 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); + flags = irq_get_trigger_type(bus->of_irq); + if (!flags) + flags = IRQF_TRIGGER_HIGH; + flags |= IRQF_ONESHOT; + return devm_request_threaded_irq(&bus->func->dev, bus->of_irq, NULL, + wfx_sdio_irq_handler_ext, flags, + "wfx", bus); +} + +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) + goto err0; + + bus->core = wfx_init_common(&func->dev, &wfx_sdio_pdata, + &wfx_sdio_hwbus_ops, bus); + if (!bus->core) { + ret = -EIO; + goto err1; + } + + ret = wfx_probe(bus->core); + if (ret) + goto err1; + + return 0; + +err1: + sdio_claim_host(func); + sdio_disable_func(func); + sdio_release_host(func); +err0: + 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, + } +};