Page MenuHomeFreeBSD

Add support for cd-gpios for mmc
AbandonedPublic

Authored by manu on Dec 14 2016, 1:13 PM.
Tags
Referenced Files
Unknown Object (File)
Feb 9 2024, 5:55 AM
Unknown Object (File)
Dec 31 2023, 11:45 PM
Unknown Object (File)
Dec 13 2023, 12:03 AM
Unknown Object (File)
Nov 23 2023, 10:24 AM
Unknown Object (File)
Aug 30 2023, 7:44 AM
Unknown Object (File)
Aug 9 2023, 12:44 AM
Unknown Object (File)
Jul 9 2023, 12:23 AM
Unknown Object (File)
May 16 2023, 1:25 AM

Details

Reviewers
None
Summary

If the property cd-gpios is present in the dts, we will check the value of the gpio before scanning.
It avoid some boring timeouts when no extra sd card is inserted.
Note that it could/should be extend in the future to support gpio interrupts/polling to detect later card insertion.

Test Plan

Tested on Olimex A20 SOM EVB

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 6237
Build 6480: arc lint + arc unit

Event Timeline

manu retitled this revision from to Add support for cd-gpios for mmc.
manu updated this object.
manu edited the test plan for this revision. (Show Details)
manu set the repository for this revision to rS FreeBSD src repository - subversion.
manu added a project: ARM.
manu added a subscriber: ARM.

Timeout isn't as long as I remembered, so no need for this now (except to hide error message from the sd controller).
I'll implement interrupt/polling and update this review.

andrew added inline comments.
sys/dev/mmc/mmc.c
254

This will break on arm64 when booting with ACPI. There is no ofw node in this case, but FDT may be defined.

sys/dev/mmc/mmc.c
257

The use of ofw_gpiobus_parse_gpios() is incorrect.

The *-gpios property can specify any number of pins, ofw_gpiobus_parse_gpios() will return the number of read pins and will allocate the correct amount of memory for the pins structure (with all the pins).

You are supposed to free that memory after use.

Here is an usage example:

+ /* Get GPIO power pins, if any. */
+ npins = -1;
+ if (OF_hasprop(ofw_bus_get_node(dev), "gpios"))
+ npins = ofw_gpiobus_parse_gpios(dev, "gpios", &pins);
+ if (npins > 0) {
+ for (i = 0; i < npins; i++) {
+ device_printf(dev,
+ "USB power using %s pin %d.\n",
+ device_get_nameunit(pins[i].dev), pins[i].pin);
+ GPIO_PIN_SETFLAGS(pins[i].dev, pins[i].pin,
+ GPIO_PIN_OUTPUT);
+ GPIO_PIN_SET(pins[i].dev, pins[i].pin, GPIO_PIN_HIGH);
+ }
+ free(pins, M_DEVBUF);
+ }

mmel added inline comments.
sys/dev/mmc/mmc.c
257

or you can simply use gpio_pin_get_by_ofw_property(() ...

sys/dev/mmc/mmc.c
254

Mhm, ok, is there a way we can know we booted with ACPI ?

257

Corrected in my tree, thanks

sys/dev/mmc/mmc.c
254

You can subclass the mmc driver for FDT. It would check if ofw_bus_get_node returns a valid node in the probe function & run these in the attach function before calling into the existing mmc_attach.

You will need to change mmc_probe to return a BUS_PROBE_ so this new driver will attach.

I'll subclass mmc for ofw first.