Skip to content

Conversation

@xakep-amatop
Copy link
Contributor

Add basic functionality of Renesas SD/MMC driver. It can be used for both gen3 and gen4 R-car boards, but tested only with H3ULCB, Salvator XS M3 and Spider boards. This driver working with SDHC subsystem.

The driver supports regularal reading/writing throught SD/MMC controller buffer, DMA mode w/o interrupts.
Notes:

  • the driver doesn't support SPI mode;
  • SCC tuning and DMA mode based on IRQs are enabled by default;
  • an address of a data buffer has to be aligned to 128 bytes if it is not, driver will use non-DMA mode automatically;
  • Renesas MMC DMAC doesn't support 64-bit DMA addresses, so for case when we have 64-bit xref data address we use non-DMA mode;
  • SD/MMC controller supports block size between 512 and 1 with a lot of restrictions, more details you can find in code;
  • support of HS400 mode isn't implemented inside driver.

@xakep-amatop xakep-amatop force-pushed the add-support-of-rcar-mmc-driver branch 2 times, most recently from 18d519a to f549562 Compare July 12, 2023 11:20
@xakep-amatop xakep-amatop marked this pull request as ready for review July 12, 2023 11:51
@zephyrbot zephyrbot added area: File System platform: Renesas R-Car ARM64 Renesas Electronics Corporation, R-Car ARM64 platform: Renesas R-Car Renesas R-Car area: ARM64 ARM (64-bit) Architecture area: Regulators area: Devicetree Binding PR modifies or adds a Device Tree binding area: Disk Access labels Jul 12, 2023
Copy link
Contributor

@danieldegrasse danieldegrasse left a comment

Choose a reason for hiding this comment

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

Driver itself generally looks good. Just a few comments/questions

Note- I'm not familiar with the hardware itself- I'd appreciate a review from anyone who is (@lorc)?

Copy link
Contributor

Choose a reason for hiding this comment

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

A few comments here:

  • personally, I'd prefer this be in a second PR. That way the SD changes can be looked at independently of the regulator ones (and the regulator changes will pull in the appropriate reviewers)
  • If we need these functions to be available to provide a common interface to regulators, could we implement them within regulator_common.c?
  • ping @gmarull

Copy link
Contributor Author

Choose a reason for hiding this comment

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

personally, I'd prefer this be in a second PR. That way the SD changes can be looked at independently of the regulator ones (and the regulator changes will pull in the appropriate reviewers)

actually, GitHub CI will be red here due to lack of regulator changes, some of reviewers really worried about it

If we need these functions to be available to provide a common interface to regulators, could we implement them within regulator_common.c?

I'm not sure about that. I think it's better to change this file. At least from now, it works in a similar way to the fixed regulator inside the Linux kernel. But we should consult with the maintainer of this driver, @gmarull, for the final decision.

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on your other comments in this PR, would the preferred regulator for this SD device be the driver being added in #58411?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this pull request doesn't contain all the necessary changes for supporting SD cards. The driver is full, but we still need the following:

The eMMC device on R-Car has only fixed regulators, and we can't disable power using these regulators, they are always on and fixed. If we talk about SD cards, they have both fixed and gpio regulators. One of them can disable the SD card power supply, and the other is used for controlling IO lines power.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please copy this patch to own PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll do it

subsys/sd/sd.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the comment here, and correctly record the signal voltage below:

card->card_voltage = SD_VOL_3_3_V;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be default y, with depends on DT_HAS_RENESAS_RCAR_MMC_ENABLED, see here:

depends on DT_HAS_NXP_LPC_SDIF_ENABLED

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

The SD subsystem should insure all data buffers passed to the driver are aligned to CONFIG_SDHC_BUFFER_ALIGNMENT, see here: https://github.com/zephyrproject-rtos/zephyr/blob/18636af6d6658cf66e5f055901ffe2515116d329/subsys/sd/sd_ops.c

So it should be possible to always use the DMA function when dev_data->dma_support is true unless I'm missing something specific to this controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I need some time to investigate it thoroughly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused what the regulator driver is used for here. It seems these fixed regulators cannot be enabled or disabled, and are just being used to determine the voltage ranges supported by the SDHC? Or is there a method to enable and disable these regulators I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a common API used to determine the supported voltage of the regulator. However, this driver is not aware of the specific regulator used underneath. For example, it could be a GPIO regulator for SD cards.
Unfortunately, the GPIO regulator driver is still under review. Once it is merged, I will add overlays to samples and make additional changes to the boards dts/dtsi files.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly confused about these regulator nodes:

  • Should always-on be present, or boot-on? These regulators are not always enabled, and they are managed via the SDHC driver.
  • Based on the changes to the fixed regulator driver and the lack of an enable pin, are these regulator nodes just being used to determine the voltage the SD host controller supports? If so, we should just make this a property of the host controller binding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should always-on be present, or boot-on?

Yes, it means that you cannot disable this regulator and it's enabled after boot of board.

These regulators are not always enabled, and they are managed via the SDHC driver.

The common regulator API examines the always-on flag, and in cases where we request turning off or on, it simply ignores the request. You can refer to the source code at https://elixir.bootlin.com/zephyr/latest/source/drivers/regulator/regulator_common.c#L89 for more details.

Based on the changes to the fixed regulator driver and the lack of an enable pin, are these regulator nodes just being used to determine the voltage the SD host controller supports?

In the SD/MMC driver, we utilize a common regulator API for voltage control (get/set) and enabling/disabling regulators. While we cannot control power for this particular device, there might be other devices, such as SD cards, for which power control is possible. GPIO regulators will be used for SD cards for R-Car Gen3/Gen4 boards. The pull request can be found here: #58411.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok- I'm not familiar with the Rcar boards, but given that #58411 is merged, can this PR be updated to use that driver for either of these boards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it would be better to address these changes in a separate pull request. Adding new modifications to this one will only extend the review time.

The driver introduced in #58411 can be used for SD cards, I'll add support of them in a separate pull after merging this one.

Copy link

Choose a reason for hiding this comment

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

+1 to rebasing on the current code state. We don't want to introduce code that is known to ignore existing features.

Copy link

Choose a reason for hiding this comment

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

Ah, I got this. This is for eMMC, when regulators are indeed fixed. It it strange that you didn't mentioned in the commit message, that you are adding DTS definitions for eMMC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing seems strange to me. Feel free to walk through Zephyr commits in the 'dts' directory and look at the commit descriptions to see how other people have done it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why declare the disk here, if we are only going to enable it in overlays? Couldn't the disk be defined and enabled within the overlay itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see no reason to declare the compatible property in every instance. It should always be the same for all the MMC/SD nodes.

Certainly, I can move the complete definition of the disk nodes to overlays. If you want, I'll do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would personally prefer we declare the disk in overlays, but I don't feel too strongly about it. Feel free to leave this as is

Copy link
Contributor

Choose a reason for hiding this comment

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

Commit message needs to be updated here, this is an update to the LFS subsystem. It should also be in a separate PR (although I assume the change here is to deal with 64 bit pointers)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, #60452

@xakep-amatop xakep-amatop force-pushed the add-support-of-rcar-mmc-driver branch from f549562 to 919b264 Compare July 17, 2023 22:38
@xakep-amatop
Copy link
Contributor Author

Hi, @danieldegrasse @lorc @aaillet

I want to become a maintainer of this driver. Is it possible or not? Do I need to get additional approvals from someone else?

@aaillet
Copy link
Member

aaillet commented Aug 2, 2023

Hi, @danieldegrasse @lorc @aaillet

I want to become a maintainer of this driver. Is it possible or not? Do I need to get additional approvals from someone else?

From my POV it's okay, add yourself as such in CODEOWNER file.
This file is supposed not to be used anymore but you will also become a collaborator after merge of #61066 so it's okay.
You can get more information about official "promotion" mechanism here : https://docs.zephyrproject.org/latest/project/project_roles.html

@MaureenHelm MaureenHelm removed the dev-review To be discussed in dev-review meeting label Feb 14, 2024
@xakep-amatop xakep-amatop dismissed stale reviews from lorc and danieldegrasse via 9faa8d5 March 5, 2024 08:32
@xakep-amatop xakep-amatop force-pushed the add-support-of-rcar-mmc-driver branch from b8f99e4 to 9faa8d5 Compare March 5, 2024 08:32
@xakep-amatop
Copy link
Contributor Author

fixed conflicts

@danieldegrasse
Copy link
Contributor

fixed conflicts

Can you take a look at the failing testcases?

@xakep-amatop xakep-amatop force-pushed the add-support-of-rcar-mmc-driver branch from 9faa8d5 to e1d7fae Compare March 6, 2024 07:58
@xakep-amatop
Copy link
Contributor Author

fixed conflicts

Can you take a look at the failing testcases?

done

@xakep-amatop
Copy link
Contributor Author

@danieldegrasse @lorc please take another look at this pull request.

Add basic functionality of Renesas SD/MMC driver. It can be used
for both gen3 and gen4 R-car boards, but tested only with H3ULCB,
Salvator XS M3 and Spider boards. This driver working with SDHC
subsystem.

The driver supports regularal reading/writing throught SD/MMC
controller buffer, DMA mode w/o interrupts and timing tuning.

Add gpio5 and sd0 nodes to h3ulcb and salvator xs which are needed
for working with SD cards. The GPIO node is needed for switching
voltage on SD card through gpio regulator driver.

Notes:
    * the driver doesn't support SPI mode;
    * SCC tuning and DMA mode based on IRQs are enabled by default;
    * an address of a data buffer has to be aligned to 128 bytes if it
      is not, driver will use non-DMA mode automatically;
    * Renesas MMC DMAC doesn't support 64-bit DMA addresses, so for
      case when we have 64-bit xref data address we use non-DMA mode;
    * SD/MMC controller supports block size between 512 and 1 with
      a lot of restrictions, more details you can find in code;
    * support of HS400 mode isn't implemented inside driver.

Signed-off-by: Mykola Kvach <[email protected]>
Add pin control group for UHS modes for H3ULCB, Salvator XS M3
boards to appropriate dts files. Both 'uhs' and 'default' pins
states have the same properties for eMMC, e.g. 1.8V.

Signed-off-by: Mykola Kvach <[email protected]>
Add MMC related cfgs/overlays of arm64 gen3 rcar boards to perf and
susys/sd/mmc tests.

Signed-off-by: Mykola Kvach <[email protected]>
Add support of R-Car H3ULCB and Salvator XS M3 boards to
littlefs sample.

Signed-off-by: Mykola Kvach <[email protected]>
lorc
lorc previously approved these changes Mar 14, 2024
@xakep-amatop
Copy link
Contributor Author

fixed conflicts

@xakep-amatop xakep-amatop requested a review from lorc March 14, 2024 11:50
@danieldegrasse
Copy link
Contributor

@jfischer-no can you please revisit this pull request?

@xakep-amatop
Copy link
Contributor Author

@danieldegrasse would you please review it again?

@danieldegrasse
Copy link
Contributor

danieldegrasse commented Apr 1, 2024

Problematic or unnecessary comment style not addressed. A large number of doxygen-style comments for no reason. Not only is this unnecessary and unused, but it bloats the code, requires maintenance, and causes unnecessary diff lines.
Also increases the driver's carbon footprint.

@jfischer-no is there a specific reason you don't want to use doxygen-style comments in the code for this PR? From what I can tell, this does not result in the functions being added to the Zephyr project API documentation, and other drivers in tree do use this style. If there is a code or style guideline I'm missing that would mandate this, please let me know. Otherwise, I do not want to continue to block the movement of this PR based on this issue.

@xakep-amatop
Copy link
Contributor Author

@danieldegrasse ping

@danieldegrasse
Copy link
Contributor

@jfischer-no is there a specific reason you don't want to use doxygen-style comments in the code for this PR? From what I can tell, this does not result in the functions being added to the Zephyr project API documentation, and other drivers in tree do use this style. If there is a code or style guideline I'm missing that would mandate this, please let me know. Otherwise, I do not want to continue to block the movement of this PR based on this issue.

@jfischer-no Please revisit your block (or add a comment clarifying your reasoning above) before Thursday (April 22nd, 2024). Otherwise, following the criteria given by the project I will have to dismiss your review to in order to move this PR forwards.

(To be clear, the reason for dismissal would be The reviewer did not revisit the pull request after 2 week and multiple pings by the author. While @xakep-amatop has not pinged you recently, I have done so multiple times on their behalf.)

@danieldegrasse danieldegrasse dismissed jfischer-no’s stale review May 1, 2024 13:50

Dismissing review due to no response from reviewer

@nashif nashif merged commit 27fa6d9 into zephyrproject-rtos:main May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ARM64 ARM (64-bit) Architecture area: Devicetree Binding PR modifies or adds a Device Tree binding area: Disk Access area: File System area: Samples Samples platform: Renesas R-Car ARM64 Renesas Electronics Corporation, R-Car ARM64 platform: Renesas R-Car Renesas R-Car

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants