aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/mmc
Commit message (Collapse)AuthorAgeFilesLines
* dwmmc: cleanup cmd and locking, consistency between mmc and mmccamBjoern A. Zeeb4 days1-39/+44
| | | | | | | | | | | | | | | | | | | | | | | | In general sprinkle locking assertions and harmonized KASSERTs throughout the upper part of the driver to document expectations. In dwmmc_cmd_done() "cmd" should be set correctly and be used for both MMCCAM and classic mmc rather than special-casing mmccam. In dwmmc_next_operation() place variable declarations on the top for both cases before the first debug and lock assertion calls; then factor out common parts at the end and put both cases in the same order. By calling dwmmc_next_operation() directly from both dwmmc_request() in the mmc case, and dwmmc_cam_request() in the mmccase (rather than) chaining calls in the latter, we avoid unlocking the sc in the mmccam case and have a consistent call path from both; also removing the mmccam #ifdef from dwmmc_request() brings more clarity. In dwmmc_next_operation() enhance the panic/error messages with some extra information and assert that we come in with a cam pinfo on CAM_ACTIVE_INDEX. MFC after: 3 days Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D51628
* mmc: SPI-mode support for SD cards.Ruslan Bukin2025-04-091-0/+2378
| | | | | | | | | | | | | | | | | | | | | | | Introduce SPI-mode support which allows an SD card to communicate with a host system using SPI protocol, as described in the SD Card Specification. This feature is useful for low-end, FPGA or RISC-V research systems when a SoC is limited in terms of peripherals available (e.g. lack of a dedicated MMC controller in hardware). Examples of such systems include Codasip, lowRISC and CVA6. Project timeline: 2007: Warner first discussed SPI operational mode in his MMC presentation: https://people.freebsd.org/~imp/bsdcan2007.pdf 2012: Patrick Kelsey engineered the support. 2025: Ruslan cleaned up, tested on Codasip X730 platform (RISC-V FPGA) and put the patch to review. 2025: Patrick Kelsey reviewed the patch and aligned with the current MMC code. Reviewed by: pkelsey Sponsored by: UKRI Differential Revision: https://reviews.freebsd.org/D49248
* mmc: support for SPI bus typeRuslan Bukin2025-04-095-0/+28
| | | | | | | | | | | - Introduce the bus_type accessor, which allows to skip card selection and timing settings in SPI mode; - Add MMC_CMD_IS_APP flag for commands followed by the APP command, which is required by the upcoming MMCSPI driver. Reviewed by: pkelsey Sponsored by: UKRI Differential Revision: https://reviews.freebsd.org/D49249
* Disable HS200 on rockchip_dwmmc in attachStephen Hurd2025-03-181-1/+11
| | | | | | | | HS200 mode requires tuning, and there is no code to perform this tuning at present. Until there is, leave HS200 mode disabled. Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D49400
* mmc: Use bus_topo_lock and taskqueue_bus while adding/removing child devicesJohn Baldwin2025-03-102-18/+14
| | | | | | | | | | | Some drivers held regular mutexes across some new-bus calls; instead depend on bus_topo_lock to protect the relevant softc members. This also fixes the bus_topo_lock to be explicit in these drivers rather than relying on the implicit Giant from taskqueue_swi_giant. It avoids calling sleepable routines like device_probe_and_attach from an swi context. Differential Revision: https://reviews.freebsd.org/D49270
* Use bus_generic_detach instead of device_delete_children in detachJohn Baldwin2025-01-021-1/+1
| | | | | | | While here, check for errors from bus_generic_detach and move it to the start of detach if necessary. Differential Revision: https://reviews.freebsd.org/D47969
* Replace calls to bus_generic_attach with bus_attach_childrenJohn Baldwin2024-12-061-1/+1
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47675
* geom_flashmap: Rename the kernel moduleMark Johnston2024-10-291-1/+1
| | | | | | | | | | | | | | | | | Absent a linker.hints, if a module dependency exists on disk, the loader will automatically load it. That is, if something depends on module foo, and foo.ko exists, we'll load foo.ko even though the linker hints file is missing. It's a bit of a hack but it's handy. This breaks with geom_flashmap though, since it's geom_flashmap.ko on disk but the module is called g_flashmap. However, pretty much every other GEOM module is given a "geom_" prefix, so for consistency's sake alone, it seems nice to rename the module. PR: 274388 Reviewed by: jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D47311
* newbus: globally replace device_add_child(..., -1) with DEVICE_UNIT_ANYWarner Losh2024-07-252-2/+2
| | | | Sponsored by: Netflix
* jh7110: enable MMC driverMitchell Horne2024-05-071-0/+114
| | | | | | | | 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
* mmc_fdt_parse: remove redundant bootverbose checkAndriy Gapon2024-01-281-1/+1
|
* dwmmc: fix a typoAndriy Gapon2024-01-281-1/+1
|
* regulator: Move regulator code in dev/regulatorEmmanuel Vadot2024-01-104-4/+4
| | | | | | | | | | | We've removed kernel option EXT_RESOURCES almost two years ago. While it was ok to have some code under a common 'extres' subdirectory at first, we now have a lot of consumer of it and we made it mandatory so no need to have it under a cryptic name. Reviewed by: emaste, imp Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43194
* hwreset: Move reset code in dev/hwresetEmmanuel Vadot2024-01-101-1/+1
| | | | | | | | | | | We've removed kernel option EXT_RESOURCES almost two years ago. While it was ok to have some code under a common 'extres' subdirectory at first, we now have a lot of consumer of it and we made it mandatory so no need to have it under a cryptic name. Reviewed by: imp Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43192
* clk: Move clock code in dev/clkEmmanuel Vadot2024-01-104-4/+4
| | | | | | | | | | | We've removed kernel option EXT_RESOURCES almost two years ago. While it was ok to have some code under a common 'extres' subdirectory at first, we now have a lot of consumer of it and we made it mandatory so no need to have it under a cryptic name. Reviewed by: mhorne Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43191
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-2711-11/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* sys: Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1611-22/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1610-20/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-128-8/+8
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* mmc(4): Don't call bridge driver for timings not requiring tuningMarius Strobl2023-04-181-0/+9
| | | | | | | | | | | | The original idea behind calling into the bridge driver was to have the logic deciding whether tuning is actually required for a particular bus timing in a given slot as well as doing the sanity checking only on the controller layer which also generally is better suited for these due to say SDHCI_SDR50_NEEDS_TUNING. On another thought, not every such driver should need to check whether tuning is required at all, though, and not everything is SDHCI in the first place. Adjust sdhci{,_fsl_fdt}(4) accordingly, but keep sdhci_generic_tune() a bit cautious still.
* mmc: purge EOL release compatibilityElliott Mitchell2023-02-041-5/+0
| | | | | | | | | Remove support for FreeBSD 7 needed for a product that's not shipped FreeBSD 7 in ~15 years.... Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/603 Differential Revision: https://reviews.freebsd.org/D35560
* sdio: Add CCCR speed definesEmmanuel Vadot2022-08-101-1/+13
| | | | Those are the defines needed to change speed on a SDIO card.
* kerneldump: remove physical argument from d_dumperMitchell Horne2022-05-131-4/+2
| | | | | | | | | | | The physical address argument is essentially ignored by every dumper method. In addition, the dump routines don't actually pass a real address; every call to dump_append() passes a value of zero for physical. Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35173
* mmc: Remove unused devclass arguments to DRIVER_MODULE.John Baldwin2022-05-068-32/+11
|
* Extend device_get_property APIKornel Duleba2022-03-101-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | In order to support various types of data stored in device tree properties or ACPI _DSD packages, create a new enum so the caller can specify the expected type of a property they want to read, according to the binding. The bus logic will use that information to process the underlying data. For example in DT all integer properties are stored in BE format. In order to get constant results across different platforms we need to convert its endianness to match the host. Another example are ACPI_TYPE_INTEGER properties stored as uint64_t. Before this patch the ACPI logic would refuse to read them if the provided buffer was smaller than 8 bytes. Now this can be handled by using DEVICE_PROP_UINT32 type. Modify the existing consumers of this API to reflect the changes and update the man pages accordingly. Reviewed by: mw Obtained from: Semihalf MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D33457
* dwmmc: Make ext_resources non-optionalEmmanuel Vadot2022-02-213-19/+0
| | | | | | | | EXT_RESOURCES have been introduced in 12-CURRENT and all supported releases have it enabled in their kernel config. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D33822
* mmc: Make ext_resources non-optionalEmmanuel Vadot2022-02-213-10/+0
| | | | | | | | EXT_RESOURCES have been introduced in 12-CURRENT and all supported releases have it enabled in their kernel config. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D33821
* mmc_da: implement d_dump method, sddadumpAndriy Gapon2022-01-121-0/+15
| | | | | | | | | | | | | | | | | | | | sddadump has been derived from sddastart. mmc_sim interface has grown a new method, cam_poll, to support polled operation. mmc_sim code has been changed to provide a sim_poll hook only if the controller implements the new method. The hooks is implemented in terms of the new mmc_sim_cam_poll method. Additionally, in-progress CCB-s now have CAM_REQ_INPROG status to satisfy xpt_pollwait(). mmc_sim_cam_poll method has been implemented in dwmmc host controller. Reviewed by: manu, mav, imp MFC after: 2 weeks Relnotes: perhaps Differential Revision: https://reviews.freebsd.org/D33843
* mmc: Fix HS200/HS400 capability checkKornel Duleba2021-11-291-2/+4
| | | | | | | | | | | | | | | HS200 and HS400 speeds can be enabled either with 1.2, or 1.8V signaling voltage. Because of that we have four cabability flags: MMC_CAP_MMC_HS200_120, MMC_CAP_MMC_HS200_180, MMC_CAP_MMC_HS400_120, MMC_CAP_MMC_HS400_180. MMC logic only enables HS200/HS400 mode if both flags are set for the corresponding speed. Fix that by being more permissive in host timing cap check. Reviewed by: manu, mw MFC after: 2 weeks Obtained from: Semihalf Sponsored by: Alstom Group Differential revision: https://reviews.freebsd.org/D33130
* mmc: plug set-but-not-used varsMateusz Guzik2021-11-251-4/+0
| | | | Sponsored by: Rubicon Communications, LLC ("Netgate")
* dwmmc: Calculate the maximum transaction length correctly.Michal Meloun2021-10-081-8/+7
| | | | | | | | | | We should reserve two descriptors (not MMC_SECTORS) for potentially unaligned (so bounced) buffer fragments, one for the starting fragment and one for the ending fragment. Submitted by: kjopek@gmail.com MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D30387
* mmc: Fix regression in 8a8166e5bcfb breaking Stratix 10 bootJessica Clarke2021-09-291-3/+3
| | | | | | | | | | | | | | | | The refactoring in 8a8166e5bcfb introduced a functional change that breaks booting on the Stratix 10, hanging when it should be attaching da0. Previously OF_getencprop was called with a pointer to host->f_max, so if it wasn't present then the existing value was left untouched, but after that commit it will instead clobber the value with 0. The dwmmc driver, as used on the Stratix 10, sets a default value before calling mmc_fdt_parse and so was broken by this functional change. It appears that aw_mmc also does the same thing, so was presumably also broken on some boards. Fixes: 8a8166e5bcfb ("mmc: switch mmc_helper to device_ api") Reviewed by: manu, mw Differential Revision: https://reviews.freebsd.org/D32209
* mmc: fix 1-byte reallocs (when it should have been sizeof device_t)Mateusz Guzik2021-09-251-1/+1
| | | | | | | | | | | | Reported by KASAN: panic: ASan: Invalid access, 8-byte write at 0xfffffe00f0992610, RedZonePartial(1) panic() at panic+0xb5/frame 0xffffffff86a595b0 __asan_store8_noabort() at __asan_store8_noabort+0x376/frame 0xffffffff86a59670 mmc_go_discovery() at mmc_go_discovery+0x6c61/frame 0xffffffff86a5a790 mmc_delayed_attach() at mmc_delayed_attach+0x35/frame 0xffffffff86a5a7b0 [snip] Sponsored by: Rubicon Communications, LLC ("Netgate")
* dwmmc: Remove dwmmc_setup_bus call from start_cmdEmmanuel Vadot2021-09-211-3/+0
| | | | | | There is no need to re-setup the bus before each commands. Tested-on: Rock64, RockPro64 Reported by: avg
* dwmmc: Properly implement power_off/power_upEmmanuel Vadot2021-09-213-12/+11
| | | | | | | | | | | Write to the PWREN register should be done in update_ios based on the power_mode value in the ios struct. Also none of the manual (RockChip and Altera) and Linux talks about the needed for an inverted PWREN value so just remove this. This fixes eMMC (and possibly SD) when u-boot didn't setup the controller. Reported by: avg Tested-on: Rock64, RockPro64
* mmc: switch mmc_helper to device_ apiBartlomiej Grzesik2021-09-205-135/+229
| | | | | | | | | | | | Add generic mmc_helper which uses newly introduced device_*_property api. Thanks to this change the sd/mmc drivers will be capable of parsing both DT and ACPI description. Ensure backward compatibility for all mmc_fdt_helper users. Reviewed by: manu, mw Sponsored by: Semihalf Differential revision: https://reviews.freebsd.org/D31598
* Address the reported mmc serialization issue.Scott Long2021-08-101-7/+1
| | | | | | | | | | Reset the mmc owner before calling the bridge release host callback. Some people are hitting the "mmc: host bridge didn't serialize us." panic as the bridge is released before the mmc owner is reset. Submitted by: luiz Sponsored by: Rubicon Communications, LLC ("Netgate")
* mmc_fdt_helper: correct typo in DT property nameBartłomiej Grzesik2021-08-091-1/+1
| | | | | | | | | | | 'no-1-8-v' is a proper name according to the DT binding documentation (https://www.kernel.org/doc/Documentation/devicetree/bindings/mmc/mmc-controller.yaml). Fixes: e63fbd7bb7a25 MFC after: 1 week Sponsored by: Semihalf
* mmc: Drain the intrhook in mmc_detach()Yang Zhong2021-07-221-0/+1
| | | | | | | | | | | | | | | | Buggy SD card drivers may attach and detach a mmc(4) driver instance in quick succession. In this case mmc(4) must disestablish its intrhook callback during detach. Thus, this change adds a call to config_intrhook_drain(), which blocks or does nothing if the intrhook is running or has already ran (the SD card was plugged in), and disestablishes the hook if it hasn't ran yet (the SD card was not plugged in). PR: 254373 Reviewed by: imp, manu, markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31262
* dwmmc: Fix MMCCAM block size supportEmmanuel Vadot2021-07-221-4/+12
| | | | | | | | | When using SDIO the block size if per function and most of the time not equal to MMC_SECTOR_SIZE, fix sdio on dwmmc by setting the correct block size in the mmc registers. MFC after: 1 month Sponsored by: Diablotin Systems
* newbus: Move from bus_child_{pnpinfo,location}_src to ↵Warner Losh2021-06-231-6/+5
| | | | | | | | | | | | | | | | | | | | | | bus_child_{pnpinfo,location} with sbuf Now that the upper layers all go through a layer to tie into these information functions that translates an sbuf into char * and len. The current interface suffers issues of what to do in cases of truncation, etc. Instead, migrate all these functions to using struct sbuf and these issues go away. The caller is also in charge of any memory allocation and/or expansion that's needed during this process. Create a bus_generic_child_{pnpinfo,location} and make it default. It just returns success. This is for those busses that have no information for these items. Migrate the now-empty routines to using this as appropriate. Document these new interfaces with man pages, and oversight from before. Reviewed by: jhb, bcr Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D29937
* mmc:: Undo my conversion of (bool) to !!.Warner Losh2021-06-031-2/+2
| | | | | | | | The need for !! over (bool) pre-dates gcc 4.2, so go with the patch as-submitted because the kernel tends to prefer that. Suggested by: emaste@ Sponsored by: Netflix
* mmc-fdt: fix mmc_fdt_gpio_get_{present,readonly}Priit Trees2021-06-031-2/+2
| | | | | | | | | | | Currently, mmc_fdt_gpio_get_{present,readonly} return all time true. true ^ 100b = true false ^ 100b = true since that's done after promotion to integers. Use !! to convert the bit to a bool before xor. Reviewed by: imp@ (converted to (bool) to !! for portability) Pull Request: https://github.com/freebsd/freebsd-src/pull/461
* mmc: ignore CRC errors from CMD13 (status) when changing ratesAustin Shafer2021-06-031-2/+14
| | | | | | | | | | | | | Update mmc_switch_status to ignore a few CRC errrors when asking for the card status after setting the new rate with CMD6. Since the card may take a little while to make the switch, it's possible we'll get a communications error if we sent the command at the wrong time. Several low end laptops needs this workaround as they have a window that seems longer than other systems. This is known to fix at least the Acer Aspire A114-32-P7E5. Reviewed by: imp@, manu@ Differential Revision: https://reviews.freebsd.org/D24740
* dwmmc: Add bus_generic_add_child in the methodsEmmanuel Vadot2021-05-211-0/+2
| | | | | | | Otherwise sdiob cannot add it's children. Sponsored by: Diablotin Systems Differential Revision: https://reviews.freebsd.org/D30295
* mmc: dwmmc: Call mmc_fdt_set_powerEmmanuel Vadot2021-05-211-0/+2
| | | | | | | | This allow us to powerup/down the card and enabling/disabling the regulators if any. Sponsored by: Diablotin Systems Differential Revision: https://reviews.freebsd.org/D30292
* mmc_fdt_helper: Add mmc_fdt_set_powerEmmanuel Vadot2021-05-212-0/+43
| | | | | | | | This helper can be used to enable/disable the regulator and starting the power sequence of sd/sdio/eMMC cards. Sponsored by: Diablotin Systems Differential Revision: https://reviews.freebsd.org/D30291
* mmc_fdt_helpers: Parse the optional pwrseq element.Emmanuel Vadot2021-05-212-0/+10
| | | | | | | | | If a sd/emmc node have a pwrseq property parse it and get the corresponding driver. This can later be used to powerup/powerdown the SDIO card or eMMC. Sponsored by: Diablotin Systems Differential Revision: https://reviews.freebsd.org/D30289
* mmc: Add mmc-pwrseq driverEmmanuel Vadot2021-05-212-0/+232
| | | | | | | | This driver is used to power up sdio card or eMMC. It handle the reset-gpio, clocks and needed delays for powerup/powerdown. Sponsored by: Diablotin Systems Differential Revision: https://reviews.freebsd.org/D30288