<div dir="ltr"><div><div><div>Hi Pavel,<br><br></div>I cherry-picked your patch and for some reason I still get this error. <br><br>-------------------------------------------------------------------------------------------------------<br>*** SDHCI 01 TEST ***<br>nexus0: <RTEMS Nexus device><br>bcm_dma0: <BCM2835 DMA Controller> on nexus0<br>sdhci_bcm0: <Broadcom 2708 SDHCI controller> on nexus0<br>Enable the power returns -2<br>sdhci_bcm0: Unable to enable the power<br>device_attach: sdhci_bcm0 attach returned -2<br><br>RTEMS Shell on /dev/console. Use 'help' to list commands.<br>[/] # <br>---------------------------------------------------------------------------------------------------------<br><br></div>I have used the same code as mentioned by you.<br><br></div>Mudit<br><div><div><div><br><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 19, 2016 at 7:14 PM, Pavel Pisa <span dir="ltr"><<a href="mailto:ppisa4lists@pikron.com" target="_blank">ppisa4lists@pikron.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Mudit Jain ,<br>
<span class=""><br>
On Sunday 19 of June 2016 10:51:37 Mudit Jain wrote:<br>
> Hi all,<br>
><br>
> I am getting an error in setting the power using the mailbox.<br>
><br>
> This is how I am calling the function in the bcm_sdhci_attach as follows.<br>
><br>
> ---------------------------------------------------------------------------<br>
>-------------------------------------<br>
> bcm2835_set_power_state_entries* power_state_sd;<br>
> power_state_sd->dev_id=bcm2835_mailbox_power_udid_sd_card;<br>
> power_state_sd->state=BCM2835_MAILBOX_SET_POWER_STATE_REQ_ON ;<br>
> err = bcm2835_mailbox_set_power_state(power_state_sd);<br>
> if (err != 0) {<br>
>     device_printf(dev, "Unable to enable the power\n");<br>
>     return (err);<br>
> }<br>
> ---------------------------------------------------------------------------<br>
>---------------------------------------<br>
><br>
> RTEMS on RPi gives a err = -2, indicating the<br>
</span>> *bcm2835_mailbox_buffer_suceeded *fails<br>
<span class="">><br>
> I have been stuck here from quite some time.Can someone help me with this ?<br>
<br>
</span>I see serious problem in your code.<br>
<br>
You declare power_state_sd as pointer but do not fill it by location<br>
(malloc or reference) so the following lines use random location in memory.<br>
<br>
But it is possible that there could be some other problem so I analyzed<br>
U-boot and Linux kernel how they communicate with VideoCore firmware<br>
when they need to control power.<br>
<br>
Linux kernel implements this part in.<br>
<br>
<a href="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/soc/bcm2835/raspberrypi-firmware.h" rel="noreferrer" target="_blank">https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/soc/bcm2835/raspberrypi-firmware.h</a><br>
<br>
<a href="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/soc/bcm/raspberrypi-power.c" rel="noreferrer" target="_blank">https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/soc/bcm/raspberrypi-power.c</a><br>
<br>
Generally RTEMS code looks similar, the same channel<br>
is used for property set. There is difference that<br>
newer RPi firmware versions add support for domains functions.<br>
<br>
#define BCM2835_MAILBOX_TAG_GET_DOMAIN_STATE    0x00030030<br>
#define BCM2835_MAILBOX_TAG_SET_DOMAIN_STATE    0x00038030<br>
<br>
But even in the case of newer firmware old<br>
<br>
#define BCM2835_MAILBOX_TAG_SET_POWER_STATE  0x00028001<br>
<br>
is used at least for USB, so I expect that old power<br>
state control should work with new firmware.<br>
<br>
On the other hand, Linux seems to not count SD card power<br>
domain ID 0 into account. Linux IDs are defined as HW IDs - 1.<br>
I would expect that it is already set by firware because<br>
it uses SD card to boot the system.<br>
<br>
But anyway, I have updated VideoCore access code to be sure that<br>
data are correctly propagated to main memory after ARM caches are<br>
enabled. Original Yang Qiao code does not care about that<br>
(it is not required during startup before MMU is enabled)<br>
and there could be difference that RPi2 Cortex-A7 data cache line<br>
length is 64 bytes instead of 32 for RPi1 so without explicit<br>
cache management there could be more problems on RPi2.<br>
<br>
I am sending my patch as followup. If there is no objection,<br>
I push it to RTEMS mainline. Patch is applied to my<br>
personal RTEMS repo as well<br>
<br>
<a href="https://github.com/ppisa/rtems/tree/rtems-rpi-devel" rel="noreferrer" target="_blank">https://github.com/ppisa/rtems/tree/rtems-rpi-devel</a><br>
<br>
I have tested next code after VC cache flush update<br>
with current RTEMS mainline and I get correct result<br>
<br>
  int err;<br>
<br>
  bcm2835_set_power_state_entries power_state_sd;<br>
  power_state_sd.dev_id=bcm2835_mailbox_power_udid_sd_card;<br>
  power_state_sd.state=BCM2835_MAILBOX_SET_POWER_STATE_REQ_ON ;<br>
  err = bcm2835_mailbox_set_power_state(&power_state_sd);<br>
  printk("Enable the power returns %d\n", err);<br>
<br>
I have not tested before cache clarification because I have<br>
noticed problem with pointer later.<br>
<br>
All tested on RPi1 with U-boot based load.<br>
I have tested with both serial and graphics console.<br>
Testing on RPi2 would be appreciated.<br>
<br>
Best wishes,<br>
<br>
             Pavel<br>
</blockquote></div><br></div>