From patchwork Mon Sep 20 16:11:20 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: 12505911 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, 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 50CC3C433FE for ; Mon, 20 Sep 2021 16:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D00D60F58 for ; Mon, 20 Sep 2021 16:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243617AbhITQQN (ORCPT ); Mon, 20 Sep 2021 12:16:13 -0400 Received: from mail-dm6nam12on2045.outbound.protection.outlook.com ([40.107.243.45]:61920 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S242407AbhITQNw (ORCPT ); Mon, 20 Sep 2021 12:13:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ADs00xBAQRAj+tiFlrfsP0ZmzOsxn/ox+TDwq9p3tSsWGqwGobkzdhOc/fNrIrmH7jrcdzmCCSv02ghSo2iB33wG1V0zfIC+Z9M13zB2Dz3yK/p5sBIJ2llk8M2U61hm8VuoBy107JARz+4VOK0w4EkoR5FXPOyjtkZ7c4h336QOxxu4Xf18h8R/swPOAJdFF5cMOcWU14QTMb28HgqykqM/t5OYVdYJS7W+tbL3qTj7/jkuB9fEY8jQKBtlP6420TGCzI7V9GHRU7kRpUjUuWZTGI1xjdHZ/n2Zl8lpQz1XNX6dG6XcZL6ahh7ZgR18usoOQE0YOvgxRdv/g86f3w== 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=GaCzUjUdFMbt+/H6mF8HBY8e01XnqaMuOQdEJjxOr1PHEyXfl/0hxvhy/lfyNF3wN09hzUyP6V+/tjgXf+sfgVofXbrluM9+XbsvNxpL5yhwCUaA6nqbD7d25qCIodNf5fMOfwFwCjZmuECF8q5IwyB1pJglEKugwCwhcEmvFMsJ5IDNBaQ35GksnroRUzocvakdJ/JOb9NcfnCDSBVrU+phEhD3C5Ur57kgPhFJ71egVMVEcRMvic42IJb5kiqBJ2SX7AdxE63cAB9v28YWivpU/TGcooWWQovSJk0eywq4UT6Z7oeTOH2LHMNucgR47vQQCVsPRpL7uePjQt2SyA== 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=F9OZpj3oWdHKkaCLkUl2512Q/DK5cLDufABNvCuytPSCzRd+DBkGc67f2pisaE6fjTBlNEIkSJ/uG4c+RJfSXwXcVd8zVjeE+jh/HfmibKgByM0FXUp0xYgiLzMIqs1rgmu5zyQPy69r4VyiQfSJBAAGoyd5lieZPZa1VelJXBI= 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 SA2PR11MB5002.namprd11.prod.outlook.com (2603:10b6:806:fb::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Mon, 20 Sep 2021 16:12:13 +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.4523.018; Mon, 20 Sep 2021 16:12:13 +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 v7 08/24] wfx: add bus_sdio.c Date: Mon, 20 Sep 2021 18:11:20 +0200 Message-Id: <20210920161136.2398632-9-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920161136.2398632-1-Jerome.Pouiller@silabs.com> References: <20210920161136.2398632-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SA0PR11CA0064.namprd11.prod.outlook.com (2603:10b6:806:d2::9) 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 SA0PR11CA0064.namprd11.prod.outlook.com (2603:10b6:806:d2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 16:12:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d202181-b998-4321-eb8f-08d97c5167f3 X-MS-TrafficTypeDiagnostic: SA2PR11MB5002: 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: 5T/g3h2CV41NvybzkZPgiEexmnN+vyEp6EQXVOPWFiAWZv5hFKsbFkQqLzF5ZYG4OKmXLus9ekh9ox7qLe6Bdwuca+LsttCzxhVVl1WmQ4QMnUSHsp46PcmaNECUD5zJ6K9E1IgClvw/WJOx00NeGiQkVCQLpumuabD57JQhjId3vpEqaoqCsmxuaFrr+Jtxm2L2FLixz8CxvMYO8v2DEYBCWUi1gBYaomfYDELoQ0uHaEaxmjpyqyrwBVRW9jks3zC2Ntd3xxcnuSW2kKaVWQqm4hFwvuxcNhDvllLrbn1q6vCqdMdZvUiuAMXmpXc6QrssfZ3ucSnJtSiG+tj0uVt4ufOwU5NylqssQQevjrYQSB5EF/57sI8gHbneTH6fp1aQrtCHTZ7hgpg7fSrFaabveVvAM5J7geqPRuMEc1XZvR8oq64YoFlA92iFUzpZS3iRYcDpN1lUdijQ9F3guOTwQkKDSbYBPmjYlsb3oHwOuFLn65a6Ar4uHiNHViIOHPkDETGnOEog7MSMmK04jDBMcRXhRtMugwobwjRXCcUgRltY9qY07cieokiopDoJ/ixbe+9aaPegiDq3eka8uE5m/0a4wtUdhMohIHsOCcRWN8/Gw6iHAgE47fB1gs1+3au++H2nvNsk3DPVywnsWw== 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)(66476007)(36756003)(2616005)(66556008)(107886003)(186003)(54906003)(5660300002)(6486002)(66574015)(66946007)(52116002)(38100700002)(83380400001)(7696005)(6916009)(2906002)(1076003)(4326008)(8936002)(316002)(8676002)(508600001)(86362001)(6666004)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vq8nJjddZvPufEMX6w5He5Fei9WUb4uENKsatcF+cBjrI3LesH4Ry8VKyKgl5YGmkyaCAc8k7q+9L2in/1iHT7xlA+x15JhBcY5BWOCx7ibhsA7ihIU+E/KmB7xdD9YeqrqlQLz27KfKiSH5wU7Zliicwbb1f0utqgUXhFpBN7Wvcgow42I2eHQHLkeqO/grTNd9Aey4MGm2w20jMQ+fkzb+VcDO3oxleItXKZx93CjCQxEpGSsaWQ5LstWlAJtcrutWd8Cs/SKfTqZead4NObQhBkzI72zy0VCLQyVBDg01FQUX0ONBKm/pg0psXm1MRalzTqh4uTrAEVX5s8Gp9RIvtgQUy+AR8oN++SyhuF2BegjGM6mTKiXex70QMvLKQSi5QD+xt0d+DNhJJ2+WPUw6v6XaD+PefFWQxEhDIUT0qcAsoINdCcDQMr3TMVkdRL6azfmxMyZ4naCYa86x+ciIGP4jNphIMrJOBOocbrddokxht2y4Ubl20X7AduRVe+6DenQm+kRo61CDJgMurDVtYLTvs3RZenUhm2sIN+4vUmjVQYcW45qEdc2+nrXpJUkCUhdN5eGlAk939zDl/lnXZSlAqOodifkkT4cAWbSxCXw0+3EZa4ka+Ish6MX9k26TjtdGzCsp/PtKt+OZm/GT5yUCoRkntrDqxRsPpTaSO8uvS016FSa2oQaS/U93H2CwztsMXgYveNhf8ai2oXp0RUS507YlD709D/9qjiU1q6Ijh/eV5WFVTvx7CxE4j4Y+rqWQxHdaSWbude17F4AN7SMht1oFR/DzabHa4lgmkef2o9LmlSlDhezeCy5e X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d202181-b998-4321-eb8f-08d97c5167f3 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 16:12:13.0238 (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: +LiPnag1ZNr3wmmlltyyJ4jhYsb8OY9ZS3H5d8DcBWWpz47edHRzCKmWvCFLGNzkw8d8BUDeM/pc7T18Y3ci8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5002 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, + } +};