From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=139.219.17.92 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796364408; b=Q2yReB2mvI0aNoHfS0eu5ddGx/k8ZFqY1ncT0oBqRr76Am0PRiqLedy/8gXjB9zKw4q0 bMR9B4ozNBHxMjvMuCysKINlYC0n+OR1M6o09gMMWKJTCQmzFZ7g8LKNIS0pIDwRKu8In 67sGrO+SRI3HEO/VgE4wO5q5tBp6G0hMf9swCR9nKZOMJlOlg+HS5YJ5tJ5awdnTuZifp aTlXK7F+iQk3SzXZmnigdLDnXTOW8+IHJ03HEcgag8ZJi8VvrhXGG3TG1//BUeuf+z8ah zC74l6tRr4gupIlYKTKBjARpJM2L82pBCLupmAJx8qqeEFCuNRJag5Q+yMkk+U31psQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364408; h=DMARC-Filter:Received:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=pEXxovTufjdjRf5iah7xSPTqFr9aQUoJGfhcalEFaOo=; b=JnaXYYaXTXbe3M8akWSeB0ZA5PYATBkQQFZf0hLrfB2/g359Ex327uRxrMx1rZMbvlu7 CYXiJxJOUx/f5l5aeEyOCOrlEOzy0xGEhPMZfOhNDlXw/CAPxiXKgHzWL28hM9HyEhvat wONXOp9FFrua0LQ6iBKSF3pPVAZlBHE5MTm6q7WDOs2ha48LcuIrXbdgu4/olOyWSBHtd pIvAl7AHx+huB+rqwcBo9OOg/Hz7y0VBLtsUDbZQ+rl2wJ3WYvFSiZiwCic6U3iNUYiFf voRu77CO7Ri7RCLZkTwfBly/RpszU4uUzrXrZGE2Qpkj9AhsBLJio5M0l7DemBA9nmw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=starfivetech.com; spf=pass smtp.mailfrom=starfivetech.com; arc=pass header.oldest-pass=0 smtp.remote-ip=139.219.17.92 Received: from CHN02-BJS-obe.outbound.protection.partner.outlook.cn (mail-bjschn02on2092.outbound.protection.partner.outlook.cn [139.219.17.92]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 602DB606A33B; Fri, 4 Dec 2026 06:06:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 602DB606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=starfivetech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=starfivetech.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AiYjMLNMkBIOz1Fj8DZHy6mlYxR6Ya4kwKx3wVl41gMWLNwb/9zKnrIAJt022CsTfD+P8ACNlnPEiECL7nt/tB8wrcG7cvz+AS7Fg0T8nuN/4hbfAtAhhBxP2/EweLrqd+26KkuRDzqAAjW+LjqMMycUc6/a1m8IOFD+6zGmVPqjKEbtu7K7jk12uZa1eBfzOknpOfjVBz1nk50xDKEFrOzxNXh+MiWjIZ31pVkpWO6ypGe7Kz0+CmEJI4BqNTKO2sEFTtbmJGnR5SCjz/JP3qD3pblUNzmBEgTMSo3ZoN8rc39YXddlO63Xfs4a4nw3kKJYulBQDoaC9suylhxbaA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pEXxovTufjdjRf5iah7xSPTqFr9aQUoJGfhcalEFaOo=; b=cq/i6l1CTdw1j/+LrFabHN82SUir0EDcI7awUuoZexcIxVf5ykhQwg1pLfsXREbRnmF0218WabMJ10Ak/KpC6amwvw6YUqdeQV1NFk9vPXN52VSlcEk+6EgRgZvodgm0GKzOuRlhCyqw8GjVV3p/b5G5LHB96cCHcj76EZcXe07UL2jeaBkspYJEwkbshNlmg9qSSK4uiv1rBRXVh2R+t9O5pSyKpd4k8Yo2hr3KaYwbLcIHk0FZF+sdWzisNLdat1CGyRVi1uXEKxITauknp+8RWWFSQ1dh7rcV1SkhFEmqElPmMvHBa+AX3tW7xIuqDruCowlh+p7ZO4fs9Y+//g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=starfivetech.com; dmarc=pass action=none header.from=starfivetech.com; dkim=pass header.d=starfivetech.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=starfivetech.com; Received: from BJSPR01MB0577.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:d::12) by BJSPR01MB0881.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.18; Fri, 4 Dec 2026 06:06:36 +0000 Received: from BJSPR01MB0577.CHNPR01.prod.partner.outlook.cn ([fe80::c362:8d6f:de71:524d]) by BJSPR01MB0577.CHNPR01.prod.partner.outlook.cn ([fe80::c362:8d6f:de71:524d%7]) with mapi id 15.21.0639.015; Fri, 4 Dec 2026 06:06:36 +0000 From: Mason Huo To: Lee Jones , Corey Minyard , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: mfd@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, openipmi-developer@lists.sourceforge.net, Mason Huo Subject: [PATCH v2 2/3] mfd: Add StarFive JHB100 SuperIO driver Date: Fri, 4 Dec 2026 14:06:22 +0800 Message-ID: <20261204060623.2994008-3-mason.huo@starfivetech.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261204060623.2994008-1-mason.huo@starfivetech.com> References: <20261204060623.2994008-1-mason.huo@starfivetech.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: ZQ0PR01CA0006.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:5::16) To BJSPR01MB0577.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:d::12) X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BJSPR01MB0577:EE_|BJSPR01MB0881:EE_ X-MS-Office365-Filtering-Correlation-Id: 498cfa47-6c68-4ccd-038d-08df51ccc144 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|23010399003|1800799024|6133799003|261009223027099003|22082099003|18002099003|260925021311599003|260925022911599003|260925021911599003|56012099006|261026121527099003|261102123227099003|261022105027099003|261028144727099003|261026140227099003|261021121427099003|10067099003|261022075727099003|38350700014; X-Microsoft-Antispam-Message-Info: KnMRYDmIEhdaQ7b+I0R3zia1VEMi1HUpHiRMv8LCoEblT7G9OUKQ+IBHN9Y6v1BvrJd0hFTjJrnwyHTJdaGDX21PutNciPK5+789V+zcuF4Nl63NzSKbmydaYOtranQMlbm+sFIUcYqAnlc400owSpaVaoYYdVeL1A9NyfOjb1+AqStXzADUAjJbF258tHhXDWIGuZnBJY9IGol2ZlrWNE+VlOsHZqo10fES04NMylz2Gne8MuYX8yiysHFWR5m0cVPrbTh6nEWw117S1NLFneHiQu4jtim2IB4xbz8ld6ZZuiT+5nWPz4YRJUrRL/ctTNLIaVtiTrws6NzHehNkN0kuZKQCe3T5cA/Rb2WcFkxJ8iate8G/do3QrvyHilPk+ckc9Ae1rHCKpIhuD9b30k3jCFy9X2uVCjo9U9IpO48kID56XvL3zROwboz2y3rGH1yv/Ze8RX0A5rSNLHuxLoLHdiItClfk8XcVLJCtDx4FsgxhlrkNTbcEtkRL8gRxnf+SEFCktNvfFZMAtu11izTjW29Irt+4b7uBEAloAPixIG+fGEED55rYCP7C1jYA X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BJSPR01MB0577.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(366016)(23010399003)(1800799024)(6133799003)(261009223027099003)(22082099003)(18002099003)(260925021311599003)(260925022911599003)(260925021911599003)(56012099006)(261026121527099003)(261102123227099003)(261022105027099003)(261028144727099003)(261026140227099003)(261021121427099003)(10067099003)(261022075727099003)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?NafD0uUtjhd4QpM5GO0fx5RFOk8VLF4J/OZ7alR63UdCpDLcCV+FFF3hx4jI?= =?us-ascii?Q?HAlHf+vfEAw+Tx0ydi+huQs92I6dg+pj5+q2k5wW+xJyX381vvDfJzjXyfaC?= =?us-ascii?Q?gmIgZBvBlKwLGwMOHrcplatolwdiVU2JFekAq5ooYe9gjRjvzTtNXYt1NGEa?= =?us-ascii?Q?GzSQRxf/eH5F0ZVTdcYxwR3v+gaiDjI16SPc8N1nBzaR5M41KpzNazmz52ec?= =?us-ascii?Q?mC6iWNDNi7jmmJbMv+uMZxZomTh/KjruVDZCia7conv6bBxszncDqISix07E?= =?us-ascii?Q?zxKthIEYsY5JeGc8p592gnhehEL34xBepGpyaGGSjc/Baac3iARGbPGEablU?= =?us-ascii?Q?a238u216/VQ/Ja8j6Hpmb2ykW095q0Z13lG05fQTKOOFmemk4EkSK4AjIHZX?= =?us-ascii?Q?vO28eG1cIww0OkG7pt/OoTOCVK2PhBipnSfATNGk7unOgGZVbrhrwk1ybP/s?= =?us-ascii?Q?qhgKv7vkUkaYxEngTJFnnDCGSDYGl18F7vmkV+swmDcGXRVQcjRGv6p/FUl4?= =?us-ascii?Q?k8yUUhHpk80oGs6OTFlj6WlkWPWc1JaMENGTPReHvSHEMlICjy9/woJhccHM?= =?us-ascii?Q?75QpvUOXMxR8By9AbaV86btlq2iAG6ADAwK9eyOY7CmWQC+/0iMmYkvXRXSX?= =?us-ascii?Q?IfN4RpU8GsJAN/pHYT1oOd95nQ3LWPuTdb8st8qerPP7t6d4pWWCG3FI8MOC?= =?us-ascii?Q?h4QDkmOhDBTpDz2CVRX6VETAOyF1RN1+JeyYLXGH/sTXmB5sRSxVP/RkxrUe?= =?us-ascii?Q?3euYjbMJA5UKrsFcSW+JajJ/JQdGvDbilo2B83Ui5CuZ8ZKg4BaBAue0E/dj?= =?us-ascii?Q?XnQuBp/UF8s36QKNk1d5hl/P0LlvAvRcvX8YIjXq556MySc4OPvZHwxaDYcM?= =?us-ascii?Q?E0fNyrjcKdHZBRzQlQ1A4VWa0aPMXKXozoJZzHXFDPkIq155hzyK5kkp4EqG?= =?us-ascii?Q?Ahbj32s7vGhdMdD4OB9PWT5ybl/aFjl+oN+O9V0+h9RITBZL5rI8wPcBWPB3?= =?us-ascii?Q?bh1v0U6ncWLA19QqbTpi3+pWpz1kpPQa54SvZUtMXitztp9KJHHC5IQdVhmD?= =?us-ascii?Q?CNjyAMJ26RAv1zg7Xx9GliY7HWQi9mNpN9y2NJ4TzFt3Azl7dhoegerVJxHb?= =?us-ascii?Q?WZi1+h8e1VMnWkO22j+oTtSMVZ0Z2eavHniPGcWUmzl2CRvObNCUF4Z9bC93?= =?us-ascii?Q?zYlEXcWDpR6AN64HhOx/a1XMVD/sCjSDBlDJsp0kCJ8QiiWL83LYmXfZezZ2?= =?us-ascii?Q?hL7eef5ZwMQucwIV5DZ+84ltIEqkYggSEICBjt+ehDGEHZ+rzbgszoyP4ooe?= =?us-ascii?Q?ikOPx0vM96vIcqSK2o75CeTGxkb5ld0N050BMFz4qSRTMbAosY6mgf2iaCmq?= =?us-ascii?Q?Zdk2QKczN6vcFNYILq5u3ADyvHyfBXItTcIl+WIh0k4FoZDn2ktuy4rwwvv7?= =?us-ascii?Q?5QXtsPaYtgi4s14emOHskXVpJrb9U0FRrDLQkbqgMwDSnkZcPthVrNZJHpT+?= =?us-ascii?Q?+SGY7mUbCHvTGZM0sFedUhTlnOu3L05dmFN8NjbTVG0rUk+NMVOGv5CjabHl?= =?us-ascii?Q?a5daSkiOlwwHJCNdFvaHCOizK3N7lPMXMeIctyfB56quFe9afyULwWzYf2Qb?= =?us-ascii?Q?Tq7lzahSUbNIkz2XF9gL8tlC00Cs0eXoAFByE+DreJshuM/9zVm8oZXia343?= =?us-ascii?Q?8FYoN+HUT3GYB2KR+ULwFw9uZqVaAftjN8mIHTMXAk1qopmS/NlqqLOiIFOj?= =?us-ascii?Q?TmHnEkoXhhA3jm7WBP6vnE+0ZvF8swY=3D?= X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 498cfa47-6c68-4ccd-038d-08df51ccc144 X-MS-Exchange-CrossTenant-AuthSource: BJSPR01MB0577.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 06:06:36.8718 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 06fe3fa3-1221-43d3-861b-5a4ee687a85c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mxAECybXEM/3UF3fVBOF6aWiSrqA+Txjn0GpaiGADrHStrkV/s86AbBD8Z2/aK89yL/xK51mAUbWP/k+Htof6QM0OB26Q85hS1ahlmtKlCw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BJSPR01MB0881 Add a driver for the SuperIO (SIO) blocks of the StarFive JHB100 BMC SoC. It registers the functions of a block as MFD cells, for now the four IPMI KCS channels. Every instance of a function occupies a 0x100 byte register window of the block. Each cell gets its window as a memory resource, which its driver maps. The cells carry no interrupt resources, the driver of a function looks up its interrupts in the SIO node by name. The functions are described by a table, so adding the remaining ones only takes their cells and an entry each. The instances of a function in all SIO blocks are numbered consecutively, so the platform device id of a KCS cell is its channel number. The index of an SIO block follows from its address. Signed-off-by: Mason Huo --- MAINTAINERS | 6 ++ drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/starfive-jhb100-sio.c | 167 ++++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 drivers/mfd/starfive-jhb100-sio.c diff --git a/MAINTAINERS b/MAINTAINERS index 67ed5e45b61d..53ee9b601dcb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26834,6 +26834,12 @@ M: Changhuang Liang S: Maintained F: drivers/soc/starfive/socinfo/jhb100-socinfo.c +STARFIVE JHB100 SUPERIO DRIVER +M: Mason Huo +S: Supported +F: Documentation/devicetree/bindings/mfd/starfive,jhb100-sio.yaml +F: drivers/mfd/starfive-jhb100-sio.c + STATIC BRANCH/CALL M: Peter Zijlstra M: Josh Poimboeuf diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 0a2778052519..3ffa1c2ed81e 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1633,6 +1633,19 @@ config STMPE_SPI This is used to enable SPI interface of STMPE endmenu +config MFD_STARFIVE_JHB100_SIO + tristate "StarFive JHB100 SuperIO" + depends on ARCH_STARFIVE || COMPILE_TEST + select MFD_CORE + help + Support for the SuperIO (SIO) blocks of the StarFive JHB100 BMC SoC. + The host accesses them over the eSPI bus. This driver registers the + functions of each block, e.g. the IPMI KCS channels, which are + handled by their own drivers. + + This support is also available as a module. If so, the module + will be called starfive-jhb100-sio. + config MFD_SUN6I_PRCM bool "Allwinner A31/A23/A33 PRCM controller" depends on ARCH_SUNXI || COMPILE_TEST diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 72d3944b0ad8..d4a680fe0e51 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -267,6 +267,7 @@ obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o obj-$(CONFIG_MFD_ALTERA_SYSMGR) += altera-sysmgr.o obj-$(CONFIG_MFD_STPMIC1) += stpmic1.o obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o +obj-$(CONFIG_MFD_STARFIVE_JHB100_SIO) += starfive-jhb100-sio.o obj-$(CONFIG_MFD_STM32_LPTIMER) += stm32-lptimer.o obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o diff --git a/drivers/mfd/starfive-jhb100-sio.c b/drivers/mfd/starfive-jhb100-sio.c new file mode 100644 index 000000000000..7efc9135705a --- /dev/null +++ b/drivers/mfd/starfive-jhb100-sio.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * StarFive JHB100 SuperIO (SIO) driver + * + * Copyright (C) 2026 StarFive Technology Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define JHB100_SIO_SIZE 0x1000 + +/* Every instance of a function occupies a register window of this size */ +#define JHB100_SIO_FUNC_SIZE 0x100 + +/* + * The cells only carry the register window of their instance. The interrupts + * are those of the SIO node, the driver of a function looks them up there by + * name: its own one, followed by the id of the cell if the block has more than + * one instance of the function, and "espi", the eSPI bus reset interrupt, which + * all functions of the block share. + */ +static const struct resource jhb100_sio_kcs0_resources[] = { + DEFINE_RES_MEM(0x200, JHB100_SIO_FUNC_SIZE), +}; + +static const struct resource jhb100_sio_kcs1_resources[] = { + DEFINE_RES_MEM(0x300, JHB100_SIO_FUNC_SIZE), +}; + +static const struct resource jhb100_sio_kcs2_resources[] = { + DEFINE_RES_MEM(0x400, JHB100_SIO_FUNC_SIZE), +}; + +static const struct resource jhb100_sio_kcs3_resources[] = { + DEFINE_RES_MEM(0x500, JHB100_SIO_FUNC_SIZE), +}; + +static const struct mfd_cell jhb100_sio_kcs_cells[] = { + MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs0_resources, NULL, 0, 0), + MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs1_resources, NULL, 0, 1), + MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs2_resources, NULL, 0, 2), + MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs3_resources, NULL, 0, 3), +}; + +/** + * struct jhb100_sio_func - a function of the SIO block + * @cells: MFD cells of the instances of the function in an SIO block + * @num_cells: number of entries in @cells + * + * The instances of a function in all SIO blocks are numbered consecutively, + * so the platform device id of a cell is the system wide instance number, + * e.g. the KCS channel number. + */ +struct jhb100_sio_func { + const struct mfd_cell *cells; + unsigned int num_cells; +}; + +/* Only the KCS channels are supported so far */ +static const struct jhb100_sio_func jhb100_sio_funcs[] = { + { jhb100_sio_kcs_cells, ARRAY_SIZE(jhb100_sio_kcs_cells) }, +}; + +/** + * struct jhb100_sio_soc_data - SoC specific description of the SIO blocks + * @bases: base addresses of the SIO blocks of the SoC + * @num_bases: number of entries in @bases + */ +struct jhb100_sio_soc_data { + const resource_size_t *bases; + unsigned int num_bases; +}; + +/* + * The index of an SIO block is not described in the devicetree, it follows + * from the address of the block. + */ +static int jhb100_sio_get_index(struct device *dev, resource_size_t start, + unsigned int *index) +{ + const struct jhb100_sio_soc_data *data; + unsigned int i; + + data = device_get_match_data(dev); + if (!data) + return -ENODEV; + + for (i = 0; i < data->num_bases; i++) { + if (data->bases[i] == start) { + *index = i; + return 0; + } + } + + return -EINVAL; +} + +static int jhb100_sio_probe(struct platform_device *pdev) +{ + const struct jhb100_sio_func *func; + struct device *dev = &pdev->dev; + unsigned int index, i; + struct resource *mem; + int rc; + + /* + * The registers are not mapped here, the driver of each function maps + * the register window of its instance. + */ + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem || resource_size(mem) < JHB100_SIO_SIZE) + return dev_err_probe(dev, -EINVAL, "Invalid register window\n"); + + rc = jhb100_sio_get_index(dev, mem->start, &index); + if (rc) + return dev_err_probe(dev, rc, "Unknown SIO block %pR\n", mem); + + for (i = 0; i < ARRAY_SIZE(jhb100_sio_funcs); i++) { + func = &jhb100_sio_funcs[i]; + + rc = devm_mfd_add_devices(dev, index * func->num_cells, + func->cells, func->num_cells, mem, 0, + NULL); + if (rc) + return dev_err_probe(dev, rc, "Failed to add %s devices\n", + func->cells->name); + } + + return 0; +} + +static const resource_size_t jhb100_sio_bases[] = { + 0x10582000, + 0x10d82000, +}; + +static const struct jhb100_sio_soc_data jhb100_sio_soc_data = { + .bases = jhb100_sio_bases, + .num_bases = ARRAY_SIZE(jhb100_sio_bases), +}; + +static const struct of_device_id jhb100_sio_match[] = { + { .compatible = "starfive,jhb100-sio", .data = &jhb100_sio_soc_data }, + { } +}; +MODULE_DEVICE_TABLE(of, jhb100_sio_match); + +static struct platform_driver jhb100_sio_driver = { + .driver = { + .name = "starfive-jhb100-sio", + .of_match_table = jhb100_sio_match, + .suppress_bind_attrs = true, + }, + .probe = jhb100_sio_probe, +}; +module_platform_driver(jhb100_sio_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mason Huo "); +MODULE_DESCRIPTION("StarFive JHB100 SuperIO driver"); -- 2.50.1