Skip to content

Use Device Tree to add the bcm2835-mmc device #909

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

Merged
merged 9 commits into from
Mar 27, 2015
Merged

Use Device Tree to add the bcm2835-mmc device #909

merged 9 commits into from
Mar 27, 2015

Conversation

notro
Copy link
Contributor

@notro notro commented Mar 24, 2015

Move the dma and mmc devices to Device Tree.
This enables drivers to get DMA channels using Device Tree.

Tested on Pi1 B+ and Pi2 in both DT and non-DT mode.

notro added 6 commits March 24, 2015 14:21
Mirror bcm2835-dma.c commit 9eba553:
chancnt is already filled by dma_async_device_register, which uses the channel
list to know how much channels there is.

Since it's already filled, we can safely remove it from the drivers' probe
function.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Don't register the device in the driver. Do it in the board file.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Both ARCH_BCM2835 and ARCH_BCM270x are built with OF now.
Add Device Tree support to the non ARCH_BCM2835 case.
Use the same driver name regardless of architecture.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Add Device Tree entry for bcm2835-dma.
The entry doesn't contain any resources since they are handled
by the arch/arm/mach-bcm270x/dma.c driver.
In non-DT mode, don't add the device in the board file.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Add clock for the mmc-bcm2835.0 device.
Will be used in non-DT mode.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Both ARCH_BCM2835 and ARCH_BCM270x are built with OF now.
Enable Device Tree support for all architectures.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
@notro
Copy link
Contributor Author

notro commented Mar 24, 2015

Error handling in the bcm2835-mmc probe function is broken.
It didn't seem to be an easy fix, so I haven't addressed it.
I'm just flagging the issue here in case someone wants to look at it.

@popcornmix
Copy link
Collaborator

Cool. I'll give it a test.
ping @pelwell

@@ -734,8 +734,6 @@ static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
vchan_init(&c->vc, &d->ddev);
INIT_LIST_HEAD(&c->node);

d->ddev.chancnt++;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why this change is necessary (or why the old code is no longer necessary)?

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's explained in the commit message.
I'm following up on this commit that came with 3.19: 9eba553
I guess this is the line that the message refers to: http://lxr.free-electrons.com/source/drivers/dma/dmaengine.c#L875

@popcornmix
Copy link
Collaborator

There is a slight gotcha with this. If you update the kernel without updating the dtb, you get a rather worrying file system check failed error on drop to a an emergency root console.

Not saying there is anything we can necessarily do about this, but I imagine I won't be the only user who does this so we might see users hitting this in the future.

@pelwell
Copy link
Contributor

pelwell commented Mar 24, 2015

I have no objections. It is good to be moving closer to BCM2835, but it feels wrong having to ADD a platform device to bcm270x.c.

@notro
Copy link
Contributor Author

notro commented Mar 24, 2015

There is a slight gotcha with this. If you update the kernel without updating the dtb, you get a rather worrying file system check failed error on drop to a an emergency root console.

I what situation would this happen? Not by using rpi-update?

@popcornmix
Copy link
Collaborator

rpi-update users should be safe.
People who build their own kernels or manually switch kernel versions by copying could run into this.
Not a critical issue, but something to be aware of.

@notro
Copy link
Contributor Author

notro commented Mar 24, 2015

it feels wrong having to ADD a platform device to bcm270x.c

Hopefully it won't stay there very long 😄

@notro
Copy link
Contributor Author

notro commented Mar 25, 2015

I have added .device_prep_slave_sg to bcm2835-dma.c which is working fine except that bcm2708_fb doesn't get it's dma channel and errors out (needs dma.c).

While doing this I discovered that the dmaengine driver always overwrites the dreq from DT with slave_id from config.
This did hide the fact that the dreq=5 I used in the DT node is wrong, it should be 11.
I will try to update this PR tomorrow.

-                       dmas = <&dma 5>,
-                              <&dma 5>;
+                       dmas = <&dma 11>,
+                              <&dma 11>;

                        /* Setup DREQ channel */
-                       c->dreq = c->cfg.slave_id;
+                       if (c->cfg.slave_id)
+                               c->dreq = c->cfg.slave_id;

A related question:
What's the purpose of arch/arm/mach-bcm2709/dmaer.c?
This one also uses dma.c

@pelwell
Copy link
Contributor

pelwell commented Mar 25, 2015

It looks like user-mode access to DMA. It's a shame the squashing hides the history.

@popcornmix
Copy link
Collaborator

I believe this is complete history:
https://github.com/raspberrypi/linux/commits/rpi-3.10.y/arch/arm/mach-bcm2708/dmaer.c

It was used by Simon Hall in some experimental X acceleration code, and probably in his open source 3d driver competition entry. I don't believe it is currently in use.

In fact it was deleted from mach-bcm2708, so its presence in mach-bcm2709 is only accidental.

@notro
Copy link
Contributor Author

notro commented Mar 25, 2015

That's good to hear.

@monroerl
Copy link

No this isn't just a problem for user built kernels. I'm using Kali 1.1 as a Pen Test and Forensic tool on the Pi 2 and can't get the Tiny3.5 TFT screen to work at all. I've asked Kali folks about it and they are puzzled as to what happened between the Pi B+ and the Pi 2. The Pi's were built fairly close together so why is aren't TFT's supported for most Nix brews? I'm dieing here. Please help.

@pelwell
Copy link
Contributor

pelwell commented Mar 26, 2015

@monroerl What does your problem have to do with this Pull Request? Please find a more appropriate location.

@notro
Copy link
Contributor Author

notro commented Mar 26, 2015

The problem with slave_id always being used also applies to the cyclic case:

bcm2835_dma_prep_dma_cyclic():

        /* Setup DREQ channel */
        if (c->cfg.slave_id != 0)
            control_block->info |=
                BCM2835_DMA_PER_MAP(c->cfg.slave_id);


bcm2835_dma_prep_slave_sg():

            c->dreq = c->cfg.slave_id; /* DREQ loaded from config */

So I propose to only use dreq in the prep_dma functions and add this to dma_slave_config:

bcm2835_dma_slave_config():

    if (c->cfg.slave_id)
        c->dreq = c->cfg.slave_id;

@popcornmix Do you have hardware to test i2s (uses cyclic dma) if I make this change?

@popcornmix
Copy link
Collaborator

Not sure what I2S devices use cyclic dma. I've only got audio cards that use I2S. Not sure if @pelwell has anything else?

@pelwell
Copy link
Contributor

pelwell commented Mar 26, 2015

I'm pretty sure the audio devices use cyclic dma.

@notro
Copy link
Contributor Author

notro commented Mar 26, 2015

@koalo submitted both the dmaengine driver and the i2s driver, and it sets slave_id in the probe function and calls snd_dmaengine_pcm_register(). So I guess any i2s audio device will do.
I tried enabling i2s, but it didn't call slave_config during probing at least. But the calls are hidden in the audio subsystem, so it might get called later during an enabling phase or something.
I really don't know neither the DMA subsystem nor the audio subsystem, so I'm on thin ice here.

Maybe I should just fix the slave_sg case which I can test?

notro added 3 commits March 26, 2015 16:16
Add Device Tree entry for bcm2835-mmc.
In non-DT mode, don't add the device in the board file.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Probe error handling is broken in several places.
Simplify error handling by using device managed functions.
Replace pr_{err,info} with dev_{err,info}.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
dreq is set when the DMA channel is fetched from Device Tree.
slave_id is set using dmaengine_slave_config().
Only overwrite dreq with slave_id if it is not set.

dreq/slave_id in the cyclic DMA case is not touched, because I don't
have hardware to test with.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
@notro
Copy link
Contributor Author

notro commented Mar 27, 2015

I have updated the PR:

  • dreq in dts file set to 11
  • fixed error handling
  • honour dreq from DT

@notro
Copy link
Contributor Author

notro commented Mar 27, 2015

I skipped dreq/slave_id and the cyclic dma case.
We'll just pick it up later if necessary. It probably won't be a problem before we have switched to bcm2835-dma.c anyway, and slave_id isn't used there.

popcornmix added a commit that referenced this pull request Mar 27, 2015
Use Device Tree to add the bcm2835-mmc device
@popcornmix popcornmix merged commit eeaa92a into raspberrypi:rpi-3.19.y Mar 27, 2015
@popcornmix
Copy link
Collaborator

Thanks. Changes look good, we'll accept for wider testing (e.g. this kernel is used in OpenELEC Milhouse nightly builds) and keep an eye out for any regression reports.

@notro notro deleted the mmc branch March 27, 2015 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants