Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: sdhc: Add MAX32 SDHC driver #83464

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mertekren
Copy link
Contributor

@mertekren mertekren commented Dec 31, 2024

This PR adds SDHC support for max32666fthr.

Implement SDHC driver for MAX32666fthr
Add sdhc0 instances for MAX32666 .dtsi file
Add SDHC to MAX32666fthr board driver list

tests:
.\tests\drivers\sdhc
image

.\samples\subsys\fs\fs_sample\

image

.\tests\drivers\disk\disk_performance
image

Dependencies:

@mertekren mertekren changed the title sdhc: max32: Add sdhc for max32666fthr drivers: sdhc: Add MAX32 SDHC driver Jan 3, 2025
@zephyrbot
Copy link
Collaborator

zephyrbot commented Jan 3, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_adi zephyrproject-rtos/hal_adi@a9ca7d1 (main) zephyrproject-rtos/hal_adi#12 zephyrproject-rtos/hal_adi#12/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

reg:
required: true

sd-bus-voltage:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be set at boot time? Typically it is configured by the SDMMC framework when the card is probed. Or is this indicating the voltage the controller actually supports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good note, thanks.
hal_adi side does this only in sdhc init and we thought we need to pass this voltage information in devicetree. there could be cases that sdmmc is not used, and user might want to set it via overlay etc i think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases when sdmmc isn't used? Do you mean the MMC framework? SD cards are going to boot at 3.3V, so the controller should be operating at that voltage at boot time. If this indicates what the controller supports, that is fine- but currently it looks like this is setting the signalling voltage during SD init.

boards/adi/max32666fthr/doc/index.rst Outdated Show resolved Hide resolved
drivers/sdhc/sdhc_max32.c Outdated Show resolved Hide resolved
drivers/sdhc/sdhc_max32.c Show resolved Hide resolved
return ENOTSUP;
}

static int sdhc_max32_set_io(const struct device *dev, struct sdhc_io *ios)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments about this function:

  • can we support setting voltage in this function? Or does the hardware not support adjusting that dynamically? It likely does if the controller supports UHS cards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good note. i think we can support it. however, our hal doesn't have this functionality yet. i'll add this as a seperate task in future, unless it's a requirement?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not la requirement if you only want to support slower card speeds at 3.3V. However if you want to support UHS cards with this driver, voltage setting needs to be done dynamically.

* remove this with a better solution in future.
*/
k_sleep(K_MSEC(1));
ret = MXC_SDHC_SendCommand(&sd_cmd_cfg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question here- is this function blocking? Or does it use interrupts within the HAL layer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's blocking. it loops in while() until register is complete/timeout. we'll try to add interrupt functionality in future.

@MaureenHelm MaureenHelm added this to the v4.1.0 milestone Jan 20, 2025
mertekren and others added 3 commits January 24, 2025 18:18
Pull in support that adds sdhc header from hal_adi

Signed-off-by: Mert Ekren <mert.ekren@analog.com>
This commit adds MAX32666 SDHC driver.

Co-Authored-By: Anil Kara <Anil.Kara@analog.com>
Co-Authored-By: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
Signed-off-by: Mert Ekren <mert.ekren@analog.com>
Include sdhc0 in MAX32666 devicetree and add devicetree bindings for
MAX32 SDHC driver

Signed-off-by: Mert Ekren <mert.ekren@analog.com>
Add SDHC to supported list for MAX32666FTHR

Signed-off-by: Mert Ekren <mert.ekren@analog.com>
Add MAX32666fthr for fs_sample testing

Signed-off-by: Mert Ekren <mert.ekren@analog.com>
@mertekren
Copy link
Contributor Author

@mertekren I think you messed up your update to west.yml as it's doing a lot more than updating hal_adi :)

yes i rebased wrong, should be good now. thanks! :)

Add MAX32666fthr sdhc to tests/drivers/disk/disk_performance

Signed-off-by: Mert Ekren <mert.ekren@analog.com>
sdhc_data->props.host_caps.sdma_support = true;
sdhc_data->props.host_caps.suspend_res_support = true;
sdhc_data->props.host_caps.vol_330_support = true;
sdhc_data->props.host_caps.vol_300_support = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated- if the driver does not support reconfiguring the voltage, that should be reported to the host stack here by setting the vol_300_support and vol_180_support fields to false

return ret;
}

cfg.bus_voltage = sdhc_config->bus_volt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be configured statically. If memory serves, the SDHC spec specifies cards should start at 3.3V, and then switch to 1.8V during initialization. So there are two options here:

  • support dynamic voltage configuration
  • only support cards at 3.3V

Have you been able to initialize a card at 1.8V using this mechanism? Maybe my memory is wrong, but I thought that only eMMC could boot at 1.8V. SD cards need to switch to 1.8V at runtime

}

/* init delay, without it applications fail. 5ms found empirically */
k_sleep(K_MSEC(5));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some busy bit in the hardware we could poll here? Honestly, it sounds to me like what this delay is doing is giving the SD host controller time to send the 74 initialization clocks required at power on. That should not occur here though, it should occur each time the SD controller toggles power on to the card (in the sdhc_max32_set_io function)

return ENOTSUP;
}

static int sdhc_max32_set_io(const struct device *dev, struct sdhc_io *ios)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not la requirement if you only want to support slower card speeds at 3.3V. However if you want to support UHS cards with this driver, voltage setting needs to be done dynamically.

enum sdhc_clock_speed speed = ios->clock;
unsigned int clk_div = 0;

MXC_SDHC_PowerDown();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function remove power from the card? If so, you should not unconditionally toggle power to the card here- this function is called multiple times during card initialization to change clocks/IO properties, and removing power to the card will effectively reset the negotiation process.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit with DT nodes and bindings should be before the commit with the driver code

reg:
required: true

sd-bus-voltage:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases when sdmmc isn't used? Do you mean the MMC framework? SD cards are going to boot at 3.3V, so the controller should be operating at that voltage at boot time. If this indicates what the controller supports, that is fine- but currently it looks like this is setting the signalling voltage during SD init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants