Commit graph

238 commits

Author SHA1 Message Date
Mitchell Horne c8b472aa4b 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
2024-05-07 13:02:57 -03:00
Andriy Gapon 43ca38eb59 mmc_fdt_parse: remove redundant bootverbose check 2024-01-28 13:39:03 +02:00
Andriy Gapon ea7f45d3d8 dwmmc: fix a typo 2024-01-28 13:37:57 +02:00
Emmanuel Vadot b2f0caf160 regulator: Move regulator code in dev/regulator
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
2024-01-10 19:20:32 +01:00
Emmanuel Vadot 1f469a9fc4 hwreset: Move reset code in dev/hwreset
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
2024-01-10 19:20:28 +01:00
Emmanuel Vadot be82b3a0bf clk: Move clock code in dev/clk
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
2024-01-10 19:20:26 +01:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
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
2023-11-26 22:24:00 -07:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
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
2023-05-12 10:44:03 -06:00
Marius Strobl bd15d31cef mmc(4): Don't call bridge driver for timings not requiring tuning
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.
2023-04-18 19:17:24 +02:00
Elliott Mitchell 862dd0d214 mmc: purge EOL release compatibility
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
2023-02-04 09:11:13 -07:00
Emmanuel Vadot 348164aa9e sdio: Add CCCR speed defines
Those are the defines needed to change speed on a SDIO card.
2022-08-10 22:07:24 +02:00
Mitchell Horne 489ba22236 kerneldump: remove physical argument from d_dumper
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
2022-05-13 10:42:48 -03:00
John Baldwin b58c5abf07 mmc: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-06 15:39:32 -07:00
Kornel Duleba b344de4d0d Extend device_get_property API
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
2022-03-10 12:11:32 +01:00
Emmanuel Vadot b4cc0f7d28 dwmmc: Make ext_resources non-optional
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
2022-02-21 17:28:42 +01:00
Emmanuel Vadot 78f8b4aafa mmc: Make ext_resources non-optional
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
2022-02-21 17:28:40 +01:00
Andriy Gapon 44682688f0 mmc_da: implement d_dump method, sddadump
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
2022-01-12 09:02:47 +02:00
Kornel Duleba 8661e085fb mmc: Fix HS200/HS400 capability check
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
2021-11-29 17:02:01 +01:00
Mateusz Guzik 2ef1cfd2ef mmc: plug set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-11-25 12:10:27 +00:00
Michal Meloun dfb7360222 dwmmc: Calculate the maximum transaction length correctly.
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
2021-10-08 09:21:03 +02:00
Jessica Clarke 4a331971d2 mmc: Fix regression in 8a8166e5bc breaking Stratix 10 boot
The refactoring in 8a8166e5bc 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:	8a8166e5bc ("mmc: switch mmc_helper to device_ api")
Reviewed by:	manu, mw
Differential Revision:	https://reviews.freebsd.org/D32209
2021-09-29 13:59:13 +01:00
Mateusz Guzik 13c63ae08d mmc: fix 1-byte reallocs (when it should have been sizeof device_t)
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")
2021-09-25 14:58:31 +00:00
Emmanuel Vadot 559f60214b dwmmc: Remove dwmmc_setup_bus call from start_cmd
There is no need to re-setup the bus before each commands.
Tested-on:  Rock64, RockPro64
Reported by:	    avg
2021-09-21 18:17:20 +02:00
Emmanuel Vadot af32e2cc32 dwmmc: Properly implement power_off/power_up
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
2021-09-21 18:17:20 +02:00
Bartlomiej Grzesik 8a8166e5bc mmc: switch mmc_helper to device_ api
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
2021-09-20 17:18:02 +02:00
Scott Long bd9e461cf7 Address the reported mmc serialization issue.
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")
2021-08-10 22:41:23 +00:00
Bartłomiej Grzesik d8789cd0ae mmc_fdt_helper: correct typo in DT property name
'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: e63fbd7bb7

MFC after: 1 week
Sponsored by: Semihalf
2021-08-09 02:27:41 +02:00
Yang Zhong d5341d72a1 mmc: Drain the intrhook in mmc_detach()
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
2021-07-22 13:50:10 -04:00
Emmanuel Vadot 990a1dbf6f dwmmc: Fix MMCCAM block size support
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
2021-07-22 17:03:14 +02:00
Warner Losh ddfc9c4c59 newbus: Move from bus_child_{pnpinfo,location}_src to 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
2021-06-22 20:52:06 -06:00
Warner Losh ef65f7bdf2 mmc:: Undo my conversion of (bool) to !!.
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
2021-06-03 11:29:04 -06:00
Priit Trees cfae21201a mmc-fdt: fix mmc_fdt_gpio_get_{present,readonly}
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
2021-06-02 21:58:30 -06:00
Austin Shafer e7dc08415a mmc: ignore CRC errors from CMD13 (status) when changing rates
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
2021-06-02 19:46:23 -06:00
Emmanuel Vadot c99d887ca8 dwmmc: Add bus_generic_add_child in the methods
Otherwise sdiob cannot add it's children.

Sponsored by:	Diablotin Systems
Differential Revision:	https://reviews.freebsd.org/D30295
2021-05-21 17:40:14 +02:00
Emmanuel Vadot ce41765c21 mmc: dwmmc: Call mmc_fdt_set_power
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
2021-05-21 17:38:35 +02:00
Emmanuel Vadot 03d4e8bb65 mmc_fdt_helper: Add mmc_fdt_set_power
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
2021-05-21 17:38:05 +02:00
Emmanuel Vadot b0387990a7 mmc_fdt_helpers: Parse the optional pwrseq element.
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
2021-05-21 17:36:58 +02:00
Emmanuel Vadot 5b2a81f58d mmc: Add mmc-pwrseq driver
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
2021-05-21 17:36:20 +02:00
Emmanuel Vadot 7cbdf8a05d dwmmc: Add \n to a debug printf 2021-04-27 19:01:09 +02:00
Emmanuel Vadot f1cc48e5da mmc: dwmmc: Convert driver to use the mmc_sim interface
A lot more generic cam related things are done in mmc_sim so this simplify
the driver a lot.

Differential Revision:	https://reviews.freebsd.org/D27487
Reviewed by:	kibab
2021-04-27 19:00:47 +02:00
Ruslan Bukin 4c1ecf5502 Consider the broken card detect flag that comes from 'broken-cd;'
dts property.

This fixes operation on Intel Stratix 10 devices.

Tested on Terasic DE10-Pro.

Reviewed by: manu
Sponsored by: UKRI
Differential revision: https://reviews.freebsd.org/D29999
2021-04-27 12:19:05 +01:00
Michal Meloun 8727c174b0 dwmmc: Multiple busdma fixes.
- limit maximum segment size to 2048 bytes.  Although dwmmc supports a buffer
  fragment with a maximum length of 4095 bytes, use the nearest lower power
  of two as the maximum fragment size. Otherwise, busdma create excessive
  buffer fragments.
- fix off by one error in computation of the maximum data transfer length.
- in addition, reserve two DMA descriptors that can be used by busdma
  bouncing. The beginning or end of the buffer can be misaligned.
- Don’t ignore errors passed to bus_dmamap_load() callback function.
- In theory, a DMA engine may be running at time when next dma descriptor is
  constructed. Create a full DMA descriptor before OWN bit is set.

MFC after:	2 weeks
2021-02-03 21:15:11 +01:00
Marius Strobl 3b433ed765 mmcsd(4): properly set BIO error when partition switching fails
While at it, remove redundant braces and goto in mmcsd_task().

Reported by:	Coverity
CID:		1419639
2021-01-22 00:18:40 +01:00
Emmanuel Vadot f4e5e045e2 dwmmc: dwmmc_switch_vccq is only used in MMCCAM kernel
Silence the build for non MMCCAM kernel
2020-11-16 11:53:36 +00:00
Mateusz Guzik 56feefccc7 mmc: clean up empty lines in .c and .h files 2020-09-01 22:07:26 +00:00
Bjoern A. Zeeb d3fd812ca9 dwmmc: remove printf even under bootverbose
Remove two debugging printfs, even if hidden under boot -v.
They seemed to be of debug nature and always spit onto the
console when running camcontrol devlist -v.

Reviewed by:	manu
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D25962
2020-08-17 20:07:14 +00:00
Emmanuel Vadot 41c653be98 dwmmc: Add MMCCAM part
Add support for MMCCAM for dwmmc

Submitted by:	kibab
Tested On:	Rock64, RockPro64
2020-07-24 19:52:52 +00:00