From nobody Tue May 07 16:04:30 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VYjlL5C29z5J7NS; Tue, 07 May 2024 16:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VYjlL3rLGz4QMC; Tue, 7 May 2024 16:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715097870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EkOxXOB6T3V2tIWqRpEL/W0xbq1XYM8Pb1orEdwdj1Y=; b=fevPjw7Xe2kzX53MKiVagtt0Ck3lVzJa4e0gMXMFMhMq98RJJrM5wboCMe3rOvlgizMDGw itfXdDsoQ3aqBjdTI1V0WNDt07VbJQKZuEnk3drN0jrriULHAiJ2D03BkSMhkxo36PhEcL 7kpiVDniK0QlVp9YU3mdFMSMHDJitM2ccgcdH/n5lTcWPv8s9oAvNnkcldk4Di9tMTynFK xAbqwQkMU4FBhQAtqF86f0KLIVLhddfAXJLAHfaCjGvw4zZcyqmhOBgavlwqA8t1fAbrRV kwzTD53UXCdX7jpKhitiO+UlZ2YbHofLRULwyiUk9u/8NLE6DDHnZublP4zKww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715097870; a=rsa-sha256; cv=none; b=Wqz9jS1UPrpnfnhb/V3N8fKnuPjtGKAh7NfTS8vHW/rO1BAG3ym3zPl8G928g8QqMBKHJX CjbGCDdICRNe+sVqyY8dS7sdSCjy1+ilLilO9DKWqAPSHVlZ4FA/0fnoW5i3T+YKzkYoT7 nEik2Gc4jBORRCY7pJktjm1qTzRBcylxI1h80OfSJUVpbHJKDErKmWdsO1XrCrdg7+FIow 5qj/r7x00ntgpJQE5rkNc/pOPL0tXHQpkBpzb7JOVhwv2r0TXoJXakJE5fe70jAMwZfCvq Apt/RNUOD4OWHGT7qih5AlPm9T2K5BgUyQ5Q1JivXCHbsw7FBhpTvH+MrQzWyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715097870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EkOxXOB6T3V2tIWqRpEL/W0xbq1XYM8Pb1orEdwdj1Y=; b=m65q9Ed+x/RPuyq9T08BaNunME+XlvPUDgsNfHDinig+IB/7S27AAIdGjiQBmXA9rpqYOF dfBgYm+9hpG93XX5H6hZ/9vNhQpraAwxohFwC0xPBttKnlCE+mYnTRR5sipoataIU88gi4 20Lo4sj9Hti9giigU3u9PcYz0ZNFD2oW5Z8oUxhDw1Mf/yC3md3Y4gkhmXy1ePBIsgWEFV YxGJHdpkJSV0qYZ2rTzYfEWVM5BmaunPxChOPs9ERRmGLpwj3XedGWMKrvOto8cK8rEV6H ungx6HKOhh7oxpPbVOWm2obco8pi59R+2vyc2nORH6V7RfFqTJh9+7PvjD99Pg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VYjlL3S9kznZs; Tue, 7 May 2024 16:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 447G4UGE049729; Tue, 7 May 2024 16:04:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 447G4UOe049727; Tue, 7 May 2024 16:04:30 GMT (envelope-from git) Date: Tue, 7 May 2024 16:04:30 GMT Message-Id: <202405071604.447G4UOe049727@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: c8b472aa4b9d - main - jh7110: enable MMC driver List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c8b472aa4b9da064223cc134ad06a08defb23e6f Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=c8b472aa4b9da064223cc134ad06a08defb23e6f commit c8b472aa4b9da064223cc134ad06a08defb23e6f Author: Mitchell Horne AuthorDate: 2024-03-04 18:38:43 +0000 Commit: Mitchell Horne CommitDate: 2024-05-07 16:02:57 +0000 jh7110: enable MMC driver Add a variant of the existing dwmmc driver, and enable it in the GENERIC kernel. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D44026 --- sys/dev/mmc/host/dwmmc_starfive.c | 114 ++++++++++++++++++++++++++++++++++++++ sys/riscv/conf/std.starfive | 4 ++ sys/riscv/starfive/files.starfive | 1 + 3 files changed, 119 insertions(+) diff --git a/sys/dev/mmc/host/dwmmc_starfive.c b/sys/dev/mmc/host/dwmmc_starfive.c new file mode 100644 index 000000000000..ab90da3b2b57 --- /dev/null +++ b/sys/dev/mmc/host/dwmmc_starfive.c @@ -0,0 +1,114 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2017 Emmanuel Vadot + * Copyright (c) 2024 The FreeBSD Foundation + * + * Portions of this software were developed by Mitchell Horne + * under sponsorship from the FreeBSD Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +#include + +#include "opt_mmccam.h" + +enum dwmmc_type { + DWMMC_GENERIC = 1, + DWMMC_JH7110 +}; + +static struct ofw_compat_data compat_data[] = { + {"snps,dw-mshc", DWMMC_GENERIC}, + {"starfive,jh7110-mmc", DWMMC_JH7110}, + {NULL, 0} +}; + +static int dwmmc_starfive_update_ios(struct dwmmc_softc *sc, + struct mmc_ios *ios) +{ + int err; + + if (ios->clock != 0 && ios->clock != sc->bus_hz) { + err = clk_set_freq(sc->ciu, ios->clock, CLK_SET_ROUND_DOWN); + if (err != 0) { + printf("%s, Failed to set freq for ciu clock\n", + __func__); + return (err); + } + sc->bus_hz = ios->clock; + } + + return (0); +} + +static int +starfive_dwmmc_probe(device_t dev) +{ + phandle_t node; + int type; + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; + if (type == 0) + return (ENXIO); + + /* + * If we matched the generic compat string, check the top-level board + * compatible, to ensure we should actually use the starfive driver. + */ + if (type == DWMMC_GENERIC) { + node = OF_finddevice("/"); + if (!ofw_bus_node_is_compatible(node, "starfive,jh7110")) + return (ENXIO); + } + + device_set_desc(dev, "Synopsys DesignWare Mobile Storage " + "Host Controller (StarFive)"); + + return (BUS_PROBE_VENDOR); +} + +static int +starfive_dwmmc_attach(device_t dev) +{ + struct dwmmc_softc *sc; + + sc = device_get_softc(dev); + sc->update_ios = &dwmmc_starfive_update_ios; + + return (dwmmc_attach(dev)); +} + +static device_method_t starfive_dwmmc_methods[] = { + /* bus interface */ + DEVMETHOD(device_probe, starfive_dwmmc_probe), + DEVMETHOD(device_attach, starfive_dwmmc_attach), + DEVMETHOD(device_detach, dwmmc_detach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(starfive_dwmmc, starfive_dwmmc_driver, starfive_dwmmc_methods, + sizeof(struct dwmmc_softc), dwmmc_driver); + +DRIVER_MODULE(starfive_dwmmc, simplebus, starfive_dwmmc_driver, 0, 0); + +#ifndef MMCCAM +MMC_DECLARE_BRIDGE(starfive_dwmmc); +#endif diff --git a/sys/riscv/conf/std.starfive b/sys/riscv/conf/std.starfive index 578110dfd5a9..e4e3e7c46f3e 100644 --- a/sys/riscv/conf/std.starfive +++ b/sys/riscv/conf/std.starfive @@ -4,4 +4,8 @@ device uart_snps # DesignWare Synopsis UART driver +# MMC/SD/SDIO Card slot support +device dwmmc +device dwmmc_starfive + files "../starfive/files.starfive" diff --git a/sys/riscv/starfive/files.starfive b/sys/riscv/starfive/files.starfive index e11acba9dab1..d867dee1099b 100644 --- a/sys/riscv/starfive/files.starfive +++ b/sys/riscv/starfive/files.starfive @@ -2,5 +2,6 @@ dev/clk/starfive/jh7110_clk.c standard dev/clk/starfive/jh7110_clk_aon.c standard dev/clk/starfive/jh7110_clk_pll.c standard dev/clk/starfive/jh7110_clk_sys.c standard +dev/mmc/host/dwmmc_starfive.c optional dwmmc_starfive fdt riscv/starfive/starfive_syscon.c standard