Skip to content

drivers: sdhc: fix sdhc caps field offset #91691

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

Closed
wants to merge 1 commit into from

Conversation

natto1784
Copy link
Contributor

@natto1784 natto1784 commented Jun 16, 2025

The first field in the capabilities register, "Timeout Clock Frequency" takes up the first 6 bits (5:0), not 5.

Reference: 2.2.26, SD Specifications, Part A2, SD Host Controller
Simplified Specification, Version 4.20
URL: https://www.sdcard.org/downloads/pls/pdf/?p=PartA2_SD%20Host_Controller_Simplified_Specification_Ver4.20.jpg

Side note: I am writing an SDHCI driver and found that most drivers write their own struct/macros for the SDHC registers, is it possible to have a common definition for these registers to avoid duplicated code?

The first field in the capabilities register, "Timeout Clock Frequency"
takes up the first 6 bits (5:0), not 5.

Reference: 2.2.26, SD Specifications, Part A2, SD Host Controller
           Simplified Specification, Version 4.20
           URL: https://www.sdcard.org/downloads/pls/pdf/?p=PartA2_SD%20Host_Controller_Simplified_Specification_Ver4.20.jpg

Signed-off-by: Amneesh Singh <a-singh7@ti.com>
@github-actions github-actions bot added area: Disk Access size: XS A PR changing only a single line of code labels Jun 16, 2025
@github-actions github-actions bot requested a review from danieldegrasse June 16, 2025 12:22
Copy link

@natto1784
Copy link
Contributor Author

natto1784 commented Jun 16, 2025

Actually on further inspection, seems like the struct was written as a bitfield to fit the capabilities register like a fiddle (hence the names of the reserved fields). However, some fields were added (and some were also omitted) that makes it very weird to look at. I will see if this needs more changes.

We can do two things

  1. Get rid of reserved field
  2. Make two sub-structs inside this, one that fits the standard spec and another for extra configurations (like hs200/hs400 support)

@natto1784
Copy link
Contributor Author

natto1784 commented Jun 16, 2025

Created a more comprehensive patch here: #91701 that splits standard capabilities from non standard capabilities. Please do let me know if this is desirable before I undraft it and ping every affected maintainer.

@danieldegrasse
Copy link
Contributor

Created a more comprehensive patch here: #91691 that splits standard capabilities from non standard capabilities. Please do let me know if this is desirable before I undraft it and ping every affected maintainer.

This looks like the same PR- did you intend to link to a different draft?

@danieldegrasse
Copy link
Contributor

Actually on further inspection, seems like the struct was written as a bitfield to fit the capabilities register like a fiddle (hence the names of the reserved fields). However, some fields were added (and some were also omitted) that makes it very weird to look at. I will see if this needs more changes.

We can do two things

Get rid of reserved field
Make two sub-structs inside this, one that fits the standard spec and another for extra configurations (like hs200/hs400 support)

Yup, the struct was originally written to follow the capabilities register in the SD host specification (although the offset error this PR fixes always existed), but when MMC support was added the struct deviated from that format. Can you update the link to your more comprehensive patch? I think making this struct match the SDHCI specification would be best

Side note: I am writing an SDHCI driver and found that most drivers write their own struct/macros for the SDHC registers, is it possible to have a common definition for these registers to avoid duplicated code?

Sure- the only reason common definitions don't exist right now is because not every SDHC IP I've encountered works well with the SDHCI specification, some need vendor specific registers

@natto1784
Copy link
Contributor Author

Created a more comprehensive patch here: #91691 that splits standard capabilities from non standard capabilities. Please do let me know if this is desirable before I undraft it and ping every affected maintainer.

This looks like the same PR- did you intend to link to a different draft?

Oops my bad, edited: #91701

@natto1784
Copy link
Contributor Author

Closing in favor of #91701

@natto1784 natto1784 closed this Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Disk Access size: XS A PR changing only a single line of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants