<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads in MCUXpresso SDK</title>
    <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178769#M2862</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please let me know if my understanding is correct:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;You have partitioned the QSPI flash into 2 partitions.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1st partition has the M4 image, A7 access(Read+write) this partition to validate the M4 image. 2nd partition is where the M4 writes the logs.&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;M4 only access(Read) the first partition during boot time to load the firmware image to RAM. After the firmware is loaded in the RAM, it uses the 2nd partition to write the logs.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Following are a few more queries:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;During A7 reboot, A7 will validate the M4 image from the 1st partition of the QSPI. So at that time will the M4 firmware image, which is in the RAM is still executing? If it is the case, there will be conflict as the M4 image is already running, and writing the logs in the 2nd partition of the QSPI and M4 once again reinit the QSPI as you mentioned.&lt;/LI&gt;
&lt;LI&gt;Which uboot version you are using? Because as I check the fsl_qspi.c that you provided is quite different than the uboot revision 1_2020.04-r0, which is using in Linux 5.4.24. Please find the attachment for reference.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The LUT of the M4 that you are using and the one provided in the SDK is the same.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Karan Gajjar&lt;/P&gt;</description>
    <pubDate>Thu, 05 Nov 2020 12:12:22 GMT</pubDate>
    <dc:creator>nxf65420</dc:creator>
    <dc:date>2020-11-05T12:12:22Z</dc:date>
    <item>
      <title>fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1077439#M2595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if u-boot configures QSPI for AHB reads, the M4 must clear the&lt;BR /&gt;QUADSPI_BFGENCR register during its init to bring it back to a well&lt;BR /&gt;known state.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="color: #c5c8c6; background-color: #1e1e1e; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #9872a2;"&gt;void&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QSPI_SoftwareReset&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #9b0000;"&gt;QuadSPI_Type&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;*&lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;base&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9b0000;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;i&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9a9b99;"&gt;/* Reset AHB domain and buffer domian */&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;base&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #9872a2;"&gt;MCR&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;|=&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QuadSPI_MCR_SWRSTHD_MASK&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;|&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QuadSPI_MCR_SWRSTSD_MASK&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;SPAN style="color: #6089b4;"&gt;!!!!!!!!!!!!!!!!!!!!!!base&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #9872a2;"&gt;BFGENCR&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9a9b99;"&gt;/* Wait several time for the reset to finish, this method came from IC team */&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9872a2;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;i&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;i&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;100&lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;U&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;i&lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;++&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;__NOP&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9a9b99;"&gt;/* Disable QSPI module */&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QSPI_Enable&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;base&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;false&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9a9b99;"&gt;/* Clear the reset flags */&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;base&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #9872a2;"&gt;MCR&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;&amp;amp;=&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;~&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QuadSPI_MCR_SWRSTHD_MASK&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #676867;"&gt;|&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QuadSPI_MCR_SWRSTSD_MASK&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #9a9b99;"&gt;/* Enable QSPI module */&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;QSPI_Enable&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #6089b4;"&gt;base&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #ce6700;"&gt;true&lt;/SPAN&gt;&lt;SPAN style="color: #c5c8c6;"&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #c5c8c6;"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Is this line in attached code snippet missing in official driver, or is there better solution of situation?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2020 11:33:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1077439#M2595</guid>
      <dc:creator>cervenka</dc:creator>
      <dc:date>2020-08-10T11:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1077440#M2596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Which source code are you talking about? Could you tell me the location of the source code.&lt;/P&gt;&lt;P&gt;What is the version of it?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Aug 2020 09:37:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1077440#M2596</guid>
      <dc:creator>jimmychan</dc:creator>
      <dc:date>2020-08-19T09:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1153365#M2767</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/1422"&gt;@jimmychan&lt;/a&gt;&amp;nbsp;, as mentioned in&amp;nbsp; header the issue is in fsl_qspi.c. We observed this issue in sdk2.6, sdk2.7 and sdk2.8(newest one). Currently we need add this one line manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solution is showed inside code snippet inside !!!!!!!!!!!!!!!!! ... !!!!!!!!!!!!!!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is qspi driver used in our case in imx7ulp&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 09:02:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1153365#M2767</guid>
      <dc:creator>cervenka</dc:creator>
      <dc:date>2020-09-15T09:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1154562#M2771</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;Our expert have a few queries regarding the patch you have mentioned.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;===========================&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;The customer has explicitly written 0 to BFGENCR (Buffer generic configuration register) in the QSPI reset function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Has the customer faced any issue while resetting his application or the EVK? If yes, can he provide the steps for the same?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Has the customer tried with the sample QSPI driver provided by the NXP?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Can the customer confirm whether the below note is applicable to his scenario?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;This note in imx7ULPRM connects to the patch in which the customer has reset the value of SEQID by writing 0.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="qspi_bfgencr.png" style="width: 751px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/125379i2B4D95593FC27963/image-size/large?v=v2&amp;amp;px=999" role="button" title="qspi_bfgencr.png" alt="qspi_bfgencr.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;============================&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 06:42:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1154562#M2771</guid>
      <dc:creator>jimmychan</dc:creator>
      <dc:date>2020-09-17T06:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1157141#M2781</link>
      <description>&lt;P&gt;My colleague is saying that the case was when uboot run before m4. M4 inits QSPI (m4 assume it comes from reset),&amp;nbsp;&lt;SPAN&gt;that value wasnt set to its default;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 19:04:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1157141#M2781</guid>
      <dc:creator>cervenka</dc:creator>
      <dc:date>2020-09-22T19:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1157332#M2782</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Below are our additional observations:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;We checked in u-boot for Linux version 5.4.24-2.1.0,&amp;nbsp;RX Buffer content is read using the AHB Bus registers by default. From the file:&amp;nbsp;&lt;STRONG&gt;drivers/spi/fsl_qspi.c&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;/*
* There are two different ways to read out the data from the flash:
* the "IP Command Read" and the "AHB Command Read". 
*
* The IC guy suggests we use the "AHB Command Read" which is faster
* then the "IP Command Read". (What's more is that there is a bug in
* the "IP Command Read" in the Vybrid.)
*
* After we set up the registers for the "AHB Command Read", we can use
* the memcpy to read the data directly. A "missed" access to the buffer
* causes the controller to clear the buffer, and use the sequence pointed
* by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Also, we checked on u-boot, the register value of&amp;nbsp;RX Buffer Control Register (QuadSPIx_RBCT):&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;=&amp;gt; md.w 0x410a5110 2
410a5110: 0007 0000&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN&gt;&lt;BR /&gt;This indicates&amp;nbsp;RXBRD bit is set to 0:&amp;nbsp;RX Buffer content is read using the AHB Bus registers QSPI_ARDB0 to QSPI_ARDB15&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;We also checked the&amp;nbsp;qspi_polling_transfer.c example from the&amp;nbsp;SDK_2.8.0_EVK-MCIMX7ULP. We modified the example to continuously test and read the RBCT register.&lt;BR /&gt;Added below line in the &lt;STRONG&gt;qspi_polling_transfer.c:&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;while (1) 
{ 
PRINTF("RBCT Reg: 0x%x\n",QSPI_ReadRBCT_Reg(EXAMPLE_QSPI));
qspi_polling();
int tmp = 200000000;
while(tmp--);
} &lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;fsl_qspi.h:&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;inline int32_t QSPI_ReadRBCT_Reg(QuadSPI_Type *base){                                                                                                 
        return base-&amp;gt;RBCT;
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN&gt;&lt;BR /&gt;Below is the output on M4 console:&lt;BR /&gt;&lt;/SPAN&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;QSPI example started!
Erase finished!
Program data finished!
Program through QSPI polling succeed!
RBCT Reg: 0x7
             Erase finished!
Program data finished!
Program through QSPI polling succeed!
RBCT Reg: 0x7
             Erase finished!
Program data finished!
Program through QSPI polling succeed!
RBCT Reg: 0x7
             Erase finished!
Program data finished!
Program through QSPI polling succeed!
RBCT Reg: 0x7
             Erase finished!
Program data finished!
Program through QSPI polling succeed!
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you have any specific scenario or application, do let us know the steps or provide us with the application to test on.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 02:30:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1157332#M2782</guid>
      <dc:creator>jimmychan</dc:creator>
      <dc:date>2020-09-23T02:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1157657#M2783</link>
      <description>&lt;P&gt;Hi !&lt;/P&gt;&lt;P&gt;Just to weight in the discussion. The use case is the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;M4 code is accessing part of the QSPI as a log space.&lt;/LI&gt;&lt;LI&gt;A7 core might be rebooting while M4 is still operational.&lt;/LI&gt;&lt;LI&gt;As u-boot comes up and does some verification on the QSPI, M4 waits before reaccessing the qspi log zone&lt;/LI&gt;&lt;LI&gt;u-boot accesses the QSPI with its own set of QSPI config parameters (reinit qspi)&lt;/LI&gt;&lt;LI&gt;When u-boot is down and A7 stops accessing QSPI, M4 must reset and reinit the QSPI config to its desired config before proceeding.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The current sdk2.8 implementation of the Reset routine in fsl_qspi does not provide insurance of a proper reset state with BFGENCR potentially in a non-default state after u-boot accessed the QSPI. This patch is to ensure this does not happen. It is an issue we have faced when rebooting the A7 side while keeping M4 in operation (only A7 reboot). With the M4 not being able to properly reinitialize and read/write to the qspi afterward.&lt;/P&gt;&lt;P&gt;Note that:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;we run a modified 4.19 kernel&amp;nbsp;&lt;A href="https://github.com/embeddedartists/linux-imx" target="_blank"&gt;https://github.com/embeddedartists/linux-imx&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;uboot accesses qspi to check M4 firmware signing and also update the M4 firmware&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 23 Sep 2020 09:48:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1157657#M2783</guid>
      <dc:creator>quentincabrol</dc:creator>
      <dc:date>2020-09-23T09:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1168255#M2831</link>
      <description />
      <pubDate>Thu, 15 Oct 2020 13:14:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1168255#M2831</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-10-15T13:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1168256#M2832</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;We would like to know a bit more about the set-up.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is it a single memory boot or dual memory boot?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How A7 is rebooted? From M4 or A7?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Karan Gajjar&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 13:15:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1168256#M2832</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-10-15T13:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1170976#M2845</link>
      <description>&lt;P&gt;Hi Karan,&lt;/P&gt;&lt;P&gt;Sorry I missed your message. This is a dual memory boot. With uboot loading A7 Linux from eMMC and M4 loading its program from a dedicated QSPI.&lt;/P&gt;&lt;P&gt;In term of operation, several situations can occur:&lt;/P&gt;&lt;P&gt;- A7 rebooting alone&lt;/P&gt;&lt;P&gt;- A7 rebooting the whole system from u-boot after a M4 update was downloaded (power reset occurs)&lt;/P&gt;&lt;P&gt;- M4 resetting the system with a POR on wdog0 timeout as a safety measure against freezing code&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 11:41:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1170976#M2845</guid>
      <dc:creator>quentincabrol</dc:creator>
      <dc:date>2020-10-21T11:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1171790#M2846</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No issues.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here is how we tried to replicate the issue, we copied the QSPI polling example from the "SDK_2.8.0_EVK-MCIMX7ULP/boards/evkmcimx7ulp/driver_examples/qspi/polling_transfer" and integrated it with the power mode example in the demo apps "SDK_2.8.0_EVK-MCIMX7ULP/boards/evkmcimx7ulp/demo_apps/power_mode_switch".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;We have created a separate task for the polling QSPI along with the power mode switch, you can find the source code as well as the binary in the attachment.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;So the M4 will do the QSPI polling test regularly.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;We flashed this M4 image in QSPI and Linux(A7) in the SD card and booted the board.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Next, we rebooted A7 using reboot command in A7 itself. However, our observation was that the polling QSPI application was running smoothly in the M4. We rebooted around 3-4 times from A7 and the M4 application was running fine.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Kindly, let us know if we are missing something in the setup here, or if you have a demo application for M4, we will check that on our end with the default Linux image in A7 and will let you know the result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Karan Gajjar&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 11:08:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1171790#M2846</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-10-22T11:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1172343#M2848</link>
      <description>&lt;P&gt;Hi Karan,&lt;/P&gt;&lt;P&gt;I think that the issue is specific to the fact that uboot on A7 reboots does two things in our case to the M4 QSPI:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;uboot sets QSPI for access from uboot &amp;amp; checks QSPI firmware SHA &amp;amp; signature (secure boot)&lt;/LI&gt;&lt;LI&gt;If SHA doesn't match what the uboot expects, QSPI flash is reflashed with a known firmware stored n eMMC and a system POR ensues.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;During the A7 reboot sequence, M4 will not access the qspi and once the reboot is completed the qspi config will be reinitialized by the M4 firmware back to a known state (in theory) for M4 access.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;base-&amp;gt;BFGENCR = 0;&lt;/LI-CODE&gt;&lt;P&gt;But the missing BFGENCR register clear means the software reset could be improper. Not sure how best to reproduce that, maybe you would need our uboot&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;lut&lt;/STRONG&gt;&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;config&amp;nbsp;for the qspi ? uboot must access the QSPI and read it during reboot for sure.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 08:57:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1172343#M2848</guid>
      <dc:creator>quentincabrol</dc:creator>
      <dc:date>2020-10-23T08:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1174443#M2851</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In your use case, let's say, M4 is running and it will be using QSPI. Now, when you reboot the A7, M4 will not be affected, as POR in A7 will only affect A7. So when U-boot comes-up after reboot, it will read the QSPI firmware to match the SHA. During this time, both M4 and A7 will be accessing the QSPI simultaneously. Now, if the SHA does not match, uboot will reflash the QSPI, while M4 still using the QSPI. This might lead to data corruption. So, have you checked here, if only one core is accessing the QSPI at one time? You might need to use XRDC for the same.&lt;/P&gt;
&lt;P&gt;In case of dual boot mode in i.MX7ULP, M4 will start from the QSPI and A7 will start from eMMC/uSDHC, independently. So the firmware will start executing on QSPI, and the u-boot checks for the SHA match. Now, if u-boot or M4 has inited the QSPI, the other should not go to re-init the same, else the data corruption might also occur in this case. So you might need to have a software-imposed handshaking inserted explicitly to synchronize the process between the A7 and M4 during boot or POR.&lt;/P&gt;
&lt;P&gt;From the below link suggestions were given so as to how to use M4 for logging and A7 to read the logs, so which mechanism have you implemented?&lt;BR /&gt;&lt;A href="https://community.nxp.com/t5/i-MX-Processors/Shared-QSPI-on-i-Mx7-ULP/td-p/935874" target="_blank"&gt;https://community.nxp.com/t5/i-MX-Processors/Shared-QSPI-on-i-Mx7-ULP/td-p/935874&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Can you let us know the partition details of QSPI and which core is accessing them in what scenario? Also, if possible please share the LUT details. We are trying to reproduce the scenario on our side, also if possible for you to reproduce with demo examples files we provided in the last comment would be helpful.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Karan Gajjar&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 10:04:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1174443#M2851</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-10-28T10:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1177672#M2858</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did you get a chance to look at the last comment?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Karan Gajjar&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 05:07:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1177672#M2858</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-11-04T05:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1177928#M2859</link>
      <description>&lt;P&gt;Hi Karan,&lt;/P&gt;&lt;P&gt;Apologies for the delay.&lt;/P&gt;&lt;P&gt;We enforce exclusive access not via the XRDC but with a SEMA42 handshake so to prevent any concurrent access. This occurs every time the power status change of the A7 is detected by the M4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We don't really have a simpler demo at the moment but here are the LUT on each side&lt;/P&gt;&lt;P&gt;M4:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;uint32_t lut[FSL_FEATURE_QSPI_LUT_DEPTH] = { /* Seq0 :Quad Read */
                                             /* CMD:        0xEB - Quad Read, Single pad */
                                             /* ADDR:       0x18 - 24bit address, Quad pads */
                                             /* DUMMY:      0x06 - 6 clock cyles, Quad pads */
                                             /* READ:       0x80 - Read 128 bytes, Quad pads */
                                             /* JUMP_ON_CS: 0 */
                                             [0] = 0x0A1804EB,
                                             [1] = 0x1E800E06,
                                             [2] = 0x2400,

                                             /* Seq1: Write Enable */
                                             /* CMD:      0x06 - Write Enable, Single pad */
                                             [4] = 0x406,

                                             /* Seq2: Erase All */
                                             /* CMD:    0x60 - Erase All chip, Single pad */
                                             [8] = 0x460,

                                             /* Seq3: Read Status */
                                             /* CMD:    0x05 - Read Status, single pad */
                                             /* READ:   0x01 - Read 1 byte */
                                             [12] = 0x1c010405,

                                             /* Seq4: Page Program */
                                             /* CMD:    0x02 - Page Program, Single pad */
                                             /* ADDR:   0x18 - 24bit address, Single pad */
                                             /* WRITE:  0x80 - Write 128 bytes at one pass, Single pad */
                                             [16] = 0x08180402,
                                             [17] = 0x2080,

                                             /* Seq5: Write Register */
                                             /* CMD:    0x01 - Write Status Register, single pad */
                                             /* WRITE:  0x01 - Write 1 byte of data, single pad */
                                             [20] = 0x20010401,

                                             /* Seq6: Read Config Register */
                                             /* CMD:  0x05 - Read Config register, single pad */
                                             /* READ: 0x01 - Read 1 byte */
                                             [24] = 0x1c010405,

                                             /* Seq7: Erase Sector */
                                             /* CMD:  0x20 - Sector Erase, single pad */
                                             /* ADDR: 0x18 - 24 bit address, single pad */
                                             [28] = 0x08180420,

                                             /* Seq8: Dummy */
                                             /* CMD:    0xFF - Dummy command, used to force SPI flash to exit continuous
                                                read mode */
                                             [32] = 0x4FF,

                                             /* Seq9: Fast Single read */
                                             /* CMD:        0x0B - Fast Read, Single Pad */
                                             /* ADDR:       0x18 - 24bit address, Single Pad */
                                             /* DUMMY:      0x08 - 8 clock cyles, Single Pad */
                                             /* READ:       0x80 - Read 128 bytes, Single Pad */
                                             /* JUMP_ON_CS: 0 */
                                             [36] = 0x0818040B,
                                             [37] = 0x1C800C08,
                                             [38] = 0x2400,

                                             /* Seq10: Fast Dual read */
                                             /* CMD:        0x3B - Dual Read, Single Pad */
                                             /* ADDR:       0x18 - 24bit address, Single Pad */
                                             /* DUMMY:      0x08 - 8 clock cyles, Single Pad */
                                             /* READ:       0x80 - Read 128 bytes, Dual pads */
                                             /* JUMP_ON_CS: 0 */
                                             [40] = 0x0818043B,
                                             [41] = 0x1D800C08,
                                             [42] = 0x2400,

                                             /* Match MISRA rule */
                                             [63] = 0
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On A7 uboot checks that any program flashed to the qspi fits into the space before the START_CANARY address and only this section of the QSPI is formatted if an update for the M4 is provided.&lt;/P&gt;&lt;P&gt;Note: the M4 is not using the QSPI XiP option but loads its firmware from QSPI and execute from its own RAM &amp;amp; TCM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A7 (with config for 7ULP):&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2013-2015 Freescale Semiconductor, Inc.
 *
 * Freescale Quad Serial Peripheral Interface (QSPI) driver
 */

#include &amp;lt;common.h&amp;gt;
#include &amp;lt;malloc.h&amp;gt;
#include &amp;lt;spi.h&amp;gt;
#include &amp;lt;asm/io.h&amp;gt;
#include &amp;lt;linux/sizes.h&amp;gt;
#include &amp;lt;dm.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;watchdog.h&amp;gt;
#include &amp;lt;wait_bit.h&amp;gt;
#include "fsl_qspi.h"
#include &amp;lt;asm/arch/sys_proto.h&amp;gt;

DECLARE_GLOBAL_DATA_PTR;

#define RX_BUFFER_SIZE		0x80
#if defined(CONFIG_MX6SX) || defined(CONFIG_MX6UL) || \
	defined(CONFIG_MX6ULL) || defined(CONFIG_MX7D) || defined(CONFIG_IMX8M)
#define TX_BUFFER_SIZE		0x200
#else
#define TX_BUFFER_SIZE		0x40
#endif

#define OFFSET_BITS_MASK	GENMASK(23, 0)

#define FLASH_STATUS_WEL	0x02
#define FLASH_STATUS_WIP	0x01

/* SEQID */
#define SEQID_WREN		1
#define SEQID_FAST_READ		2
#define SEQID_RDSR		3
#define SEQID_SE		4
#define SEQID_CHIP_ERASE	5
#define SEQID_PP		6
#define SEQID_RDID		7
#define SEQID_BE_4K		8
#ifdef CONFIG_SPI_FLASH_BAR
#define SEQID_BRRD		9
#define SEQID_BRWR		10
#define SEQID_RDEAR		11
#define SEQID_WREAR		12
#endif
#define SEQID_WRAR		13
#define SEQID_RDAR		14
#define SEQID_RDFSR		15

/* QSPI CMD */
#define QSPI_CMD_PP		0x02	/* Page program (up to 256 bytes) */
#define QSPI_CMD_RDSR		0x05	/* Read status register */
#define QSPI_CMD_WREN		0x06	/* Write enable */
#define QSPI_CMD_FAST_READ	0x0b	/* Read data bytes (high frequency) */
#define QSPI_CMD_BE_4K		0x20    /* 4K erase */
#define QSPI_CMD_CHIP_ERASE	0xc7	/* Erase whole flash chip */
#define QSPI_CMD_SE		0xd8	/* Sector erase (usually 64KiB) */
#define QSPI_CMD_RDID		0x9f	/* Read JEDEC ID */
#define QSPI_CMD_FLAG_SR	0x70	/* Read FLAG STATUS*/

/* Used for Micron, winbond and Macronix flashes */
#define	QSPI_CMD_WREAR		0xc5	/* EAR register write */
#define	QSPI_CMD_RDEAR		0xc8	/* EAR reigster read */

/* Used for Spansion flashes only. */
#define	QSPI_CMD_BRRD		0x16	/* Bank register read */
#define	QSPI_CMD_BRWR		0x17	/* Bank register write */

/* Used for Spansion S25FS-S family flash only. */
#define QSPI_CMD_RDAR		0x65	/* Read any device register */
#define QSPI_CMD_WRAR		0x71	/* Write any device register */

/* 4-byte address QSPI CMD - used on Spansion and some Macronix flashes */
#define QSPI_CMD_FAST_READ_4B	0x0c    /* Read data bytes (high frequency) */
#define QSPI_CMD_PP_4B		0x12    /* Page program (up to 256 bytes) */
#define QSPI_CMD_SE_4B		0xdc    /* Sector erase (usually 64KiB) */

/* fsl_qspi_platdata flags */
#define QSPI_FLAG_REGMAP_ENDIAN_BIG	BIT(0)

/* default SCK frequency, unit: HZ */
#define FSL_QSPI_DEFAULT_SCK_FREQ	50000000

/* QSPI max chipselect signals number */
#define FSL_QSPI_MAX_CHIPSELECT_NUM     4

#ifdef CONFIG_DM_SPI
/**
 * struct fsl_qspi_platdata - platform data for Freescale QSPI
 *
 * @flags: Flags for QSPI QSPI_FLAG_...
 * @speed_hz: Default SCK frequency
 * @reg_base: Base address of QSPI registers
 * @amba_base: Base address of QSPI memory mapping
 * @amba_total_size: size of QSPI memory mapping
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/4909"&gt;@flash&lt;/a&gt;_num: Number of active slave devices
 * @num_chipselect: Number of QSPI chipselect signals
 */
struct fsl_qspi_platdata {
	u32 flags;
	u32 speed_hz;
	fdt_addr_t reg_base;
	fdt_addr_t amba_base;
	fdt_size_t amba_total_size;
	u32 flash_num;
	u32 num_chipselect;
};
#endif

/**
 * struct fsl_qspi_priv - private data for Freescale QSPI
 *
 * @flags: Flags for QSPI QSPI_FLAG_...
 * @bus_clk: QSPI input clk frequency
 * @speed_hz: Default SCK frequency
 * @cur_seqid: current LUT table sequence id
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/26308"&gt;@sf&lt;/a&gt;_addr: flash access offset
 * @amba_base: Base address of QSPI memory mapping of every CS
 * @amba_total_size: size of QSPI memory mapping
 * @cur_amba_base: Base address of QSPI memory mapping of current CS
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/4909"&gt;@flash&lt;/a&gt;_num: Number of active slave devices
 * @num_chipselect: Number of QSPI chipselect signals
 * &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/69554"&gt;@regs&lt;/a&gt;: Point to QSPI register structure for I/O access
 */
struct fsl_qspi_priv {
	u32 flags;
	u32 bus_clk;
	u32 speed_hz;
	u32 cur_seqid;
	u32 sf_addr;
	u32 amba_base[FSL_QSPI_MAX_CHIPSELECT_NUM];
	u32 amba_total_size;
	u32 cur_amba_base;
	u32 flash_num;
	u32 num_chipselect;
	struct fsl_qspi_regs *regs;
};

#ifndef CONFIG_DM_SPI
struct fsl_qspi {
	struct spi_slave slave;
	struct fsl_qspi_priv priv;
};
#endif

static u32 qspi_read32(u32 flags, u32 *addr)
{
	return flags &amp;amp; QSPI_FLAG_REGMAP_ENDIAN_BIG ?
		in_be32(addr) : in_le32(addr);
}

static void qspi_write32(u32 flags, u32 *addr, u32 val)
{
	flags &amp;amp; QSPI_FLAG_REGMAP_ENDIAN_BIG ?
		out_be32(addr, val) : out_le32(addr, val);
}

static inline int is_controller_busy(const struct fsl_qspi_priv *priv)
{
	u32 val;
	const u32 mask = QSPI_SR_BUSY_MASK | QSPI_SR_AHB_ACC_MASK |
			 QSPI_SR_IP_ACC_MASK;
	unsigned long timeout = 100; /* 100ms timeout */

	unsigned long start = get_timer(0);
	while (1) {
		val = qspi_read32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sr);

		if ((~val &amp;amp; mask) == mask)
			return 0;

		if (get_timer(start) &amp;gt; timeout)
			break;

		udelay(1);
	}

	return -ETIMEDOUT;
}

/* QSPI support swapping the flash read/write data
 * in hardware for LS102xA, but not for VF610 */
static inline u32 qspi_endian_xchg(u32 data)
{
#ifdef CONFIG_VF610
	return swab32(data);
#else
	return data;
#endif
}

static void qspi_set_lut(struct fsl_qspi_priv *priv)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 lut_base;

	/* Unlock the LUT */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lutkey, LUT_KEY_VALUE);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lckcr, QSPI_LCKCR_UNLOCK);

	/* Write Enable */
	lut_base = SEQID_WREN * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_WREN) |
		PAD0(LUT_PAD1) | INSTR0(LUT_CMD));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* Fast Read */
	lut_base = SEQID_FAST_READ * 4;
#ifdef CONFIG_SPI_FLASH_BAR
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
		     OPRND0(QSPI_CMD_FAST_READ) | PAD0(LUT_PAD1) |
		     INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
#else
	if (FSL_QSPI_FLASH_SIZE  &amp;lt;= SZ_16M)
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
			     OPRND0(QSPI_CMD_FAST_READ) | PAD0(LUT_PAD1) |
			     INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
			     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
	else
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
			     OPRND0(QSPI_CMD_FAST_READ_4B) |
			     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) |
			     OPRND1(ADDR32BIT) | PAD1(LUT_PAD1) |
			     INSTR1(LUT_ADDR));
#endif
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1],
		     OPRND0(8) | PAD0(LUT_PAD1) | INSTR0(LUT_DUMMY) |
		     OPRND1(RX_BUFFER_SIZE) | PAD1(LUT_PAD1) |
		     INSTR1(LUT_READ));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* Read Status */
	lut_base = SEQID_RDSR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_RDSR) |
		PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(1) |
		PAD1(LUT_PAD1) | INSTR1(LUT_READ));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* Read Flag Status */
	lut_base = SEQID_RDFSR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_FLAG_SR) |
		PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(1) |
		PAD1(LUT_PAD1) | INSTR1(LUT_READ));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* Erase a sector */
	lut_base = SEQID_SE * 4;
#ifdef CONFIG_SPI_FLASH_BAR
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_SE) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
#else
	if (FSL_QSPI_FLASH_SIZE  &amp;lt;= SZ_16M)
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
			     OPRND0(QSPI_CMD_SE) | PAD0(LUT_PAD1) |
			     INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
			     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
	else
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
			     OPRND0(QSPI_CMD_SE_4B) | PAD0(LUT_PAD1) |
			     INSTR0(LUT_CMD) | OPRND1(ADDR32BIT) |
			     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
#endif
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* Erase the whole chip */
	lut_base = SEQID_CHIP_ERASE * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
		     OPRND0(QSPI_CMD_CHIP_ERASE) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* Page Program */
	lut_base = SEQID_PP * 4;
#ifdef CONFIG_SPI_FLASH_BAR
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_PP) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
#else
	if (FSL_QSPI_FLASH_SIZE  &amp;lt;= SZ_16M)
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
			     OPRND0(QSPI_CMD_PP) | PAD0(LUT_PAD1) |
			     INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
			     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
	else
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
			     OPRND0(QSPI_CMD_PP_4B) | PAD0(LUT_PAD1) |
			     INSTR0(LUT_CMD) | OPRND1(ADDR32BIT) |
			     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
#endif
#if defined(CONFIG_MX6SX) || defined(CONFIG_MX6UL) || \
	defined(CONFIG_MX6ULL) || defined(CONFIG_MX7D) || defined(CONFIG_IMX8M)
	/*
	 * To MX6SX, OPRND0(TX_BUFFER_SIZE) can not work correctly.
	 * So, Use IDATSZ in IPCR to determine the size and here set 0.
	 */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], OPRND0(0) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_WRITE));
#else
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1],
		     OPRND0(TX_BUFFER_SIZE) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_WRITE));
#endif
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* READ ID */
	lut_base = SEQID_RDID * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_RDID) |
		PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(8) |
		PAD1(LUT_PAD1) | INSTR1(LUT_READ));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 2], 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 3], 0);

	/* SUB SECTOR 4K ERASE */
	lut_base = SEQID_BE_4K * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_BE_4K) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));

#ifdef CONFIG_SPI_FLASH_BAR
	/*
	 * BRRD BRWR RDEAR WREAR are all supported, because it is hard to
	 * dynamically check whether to set BRRD BRWR or RDEAR WREAR during
	 * initialization.
	 */
	lut_base = SEQID_BRRD * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_BRRD) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(1) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_READ));

	lut_base = SEQID_BRWR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_BRWR) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(1) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_WRITE));

	lut_base = SEQID_RDEAR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_RDEAR) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(1) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_READ));

	lut_base = SEQID_WREAR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base], OPRND0(QSPI_CMD_WREAR) |
		     PAD0(LUT_PAD1) | INSTR0(LUT_CMD) | OPRND1(1) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_WRITE));
#endif

	/*
	 * Read any device register.
	 * Used for Spansion S25FS-S family flash only.
	 */
	lut_base = SEQID_RDAR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
		     OPRND0(QSPI_CMD_RDAR) | PAD0(LUT_PAD1) |
		     INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1],
		     OPRND0(8) | PAD0(LUT_PAD1) | INSTR0(LUT_DUMMY) |
		     OPRND1(1) | PAD1(LUT_PAD1) |
		     INSTR1(LUT_READ));

	/*
	 * Write any device register.
	 * Used for Spansion S25FS-S family flash only.
	 */
	lut_base = SEQID_WRAR * 4;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base],
		     OPRND0(QSPI_CMD_WRAR) | PAD0(LUT_PAD1) |
		     INSTR0(LUT_CMD) | OPRND1(ADDR24BIT) |
		     PAD1(LUT_PAD1) | INSTR1(LUT_ADDR));
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lut[lut_base + 1],
		     OPRND0(1) | PAD0(LUT_PAD1) | INSTR0(LUT_WRITE));

	/* Lock the LUT */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lutkey, LUT_KEY_VALUE);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;lckcr, QSPI_LCKCR_LOCK);
}

#if defined(CONFIG_SYS_FSL_QSPI_AHB)
/*
 * If we have changed the content of the flash by writing or erasing,
 * we need to invalidate the AHB buffer. If we do not do so, we may read out
 * the wrong data. The spec tells us reset the AHB domain and Serial Flash
 * domain at the same time.
 */
static inline void qspi_ahb_invalid(struct fsl_qspi_priv *priv)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 reg;

	reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	reg |= QSPI_MCR_SWRSTHD_MASK | QSPI_MCR_SWRSTSD_MASK;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, reg);

	/*
	 * The minimum delay : 1 AHB + 2 SFCK clocks.
	 * Delay 1 us is enough.
	 */
	udelay(1);

	reg &amp;amp;= ~(QSPI_MCR_SWRSTHD_MASK | QSPI_MCR_SWRSTSD_MASK);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, reg);
}

/* Read out the data from the AHB buffer. */
static inline void qspi_ahb_read(struct fsl_qspi_priv *priv, u8 *rxbuf, int len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg;
	void *rx_addr = NULL;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);

	rx_addr = (void *)(uintptr_t)(priv-&amp;gt;cur_amba_base + priv-&amp;gt;sf_addr);
	/* Read out the data directly from the AHB buffer. */
	memcpy(rxbuf, rx_addr, len);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

#ifndef CONFIG_MX7ULP
static void qspi_enable_ddr_mode(struct fsl_qspi_priv *priv)
{
	u32 reg, reg2;
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;

	reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	/* Disable the module */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, reg | QSPI_MCR_MDIS_MASK);

	/* Set the Sampling Register for DDR */
	reg2 = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;smpr);
	reg2 &amp;amp;= ~QSPI_SMPR_DDRSMP_MASK;
	reg2 |= (2 &amp;lt;&amp;lt; QSPI_SMPR_DDRSMP_SHIFT);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;smpr, reg2);

	/* Enable the module again (enable the DDR too) */
	reg |= QSPI_MCR_DDR_EN_MASK;
	/* Enable bit 29 for imx6sx */
	reg |= BIT(29);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, reg);

	/* Enable the TDH to 1 for i.mx6ul and mx7d, it is reserved on other platforms */
	reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;flshcr);
	reg &amp;amp;= ~(BIT(17));
	reg |= BIT(16);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;flshcr, reg);
}
#endif

/*
 * There are two different ways to read out the data from the flash:
 *  the "IP Command Read" and the "AHB Command Read".
 *
 * The IC guy suggests we use the "AHB Command Read" which is faster
 * then the "IP Command Read". (What's more is that there is a bug in
 * the "IP Command Read" in the Vybrid.)
 *
 * After we set up the registers for the "AHB Command Read", we can use
 * the memcpy to read the data directly. A "missed" access to the buffer
 * causes the controller to clear the buffer, and use the sequence pointed
 * by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
 */
static void qspi_init_ahb_read(struct fsl_qspi_priv *priv)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;

	/* AHB configuration for access buffer 0/1/2 .*/
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf0cr, QSPI_BUFXCR_INVALID_MSTRID);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf1cr, QSPI_BUFXCR_INVALID_MSTRID);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf2cr, QSPI_BUFXCR_INVALID_MSTRID);
#ifdef CONFIG_MX7ULP
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf3cr, QSPI_BUF3CR_ALLMST_MASK |
		     (0x10 &amp;lt;&amp;lt; QSPI_BUF3CR_ADATSZ_SHIFT));
#else
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf3cr, QSPI_BUF3CR_ALLMST_MASK |
		     (0x80 &amp;lt;&amp;lt; QSPI_BUF3CR_ADATSZ_SHIFT));
#endif

	/* We only use the buffer3 */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf0ind, 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf1ind, 0);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;buf2ind, 0);

	/*
	 * Set the default lut sequence for AHB Read.
	 * Parallel mode is disabled.
	 */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;bfgencr,
		     SEQID_FAST_READ &amp;lt;&amp;lt; QSPI_BFGENCR_SEQID_SHIFT);

#ifndef CONFIG_MX7ULP
	/*Enable DDR Mode*/
	qspi_enable_ddr_mode(priv);
#endif
}
#endif

#ifdef CONFIG_SPI_FLASH_BAR
/* Bank register read/write, EAR register read/write */
static void qspi_op_rdbank(struct fsl_qspi_priv *priv, u8 *rxbuf, u32 len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 reg, mcr_reg, data, seqid;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, priv-&amp;gt;cur_amba_base);

	if (priv-&amp;gt;cur_seqid == QSPI_CMD_BRRD)
		seqid = SEQID_BRRD;
	else
		seqid = SEQID_RDEAR;

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
		     (seqid &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | len);

	/* Wait previous command complete */
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	while (1) {
		WATCHDOG_RESET();

		reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbsr);
		if (reg &amp;amp; QSPI_RBSR_RDBFL_MASK) {
			data = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[0]);
			data = qspi_endian_xchg(data);
			memcpy(rxbuf, &amp;amp;data, len);
			qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
				     qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr) |
				     QSPI_MCR_CLR_RXF_MASK);
			break;
		}
	}

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}
#endif

static void qspi_op_rdid(struct fsl_qspi_priv *priv, u32 *rxbuf, u32 len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg, rbsr_reg, data, size;
	int i;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, priv-&amp;gt;cur_amba_base);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
		     (SEQID_RDID &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	i = 0;
	while ((RX_BUFFER_SIZE &amp;gt;= len) &amp;amp;&amp;amp; (len &amp;gt; 0)) {
		WATCHDOG_RESET();

		rbsr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbsr);
		if (rbsr_reg &amp;amp; QSPI_RBSR_RDBFL_MASK) {
			data = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[i]);
			data = qspi_endian_xchg(data);
			size = (len &amp;lt; 4) ? len : 4;
			memcpy(rxbuf, &amp;amp;data, size);
			len -= size;
			rxbuf++;
			i++;
		}
	}

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

/* If not use AHB read, read data from ip interface */
static void qspi_op_read(struct fsl_qspi_priv *priv, u32 *rxbuf, u32 len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg, data;
	int i, size;
	u32 to_or_from;
	u32 seqid;

	if (priv-&amp;gt;cur_seqid == QSPI_CMD_RDAR)
		seqid = SEQID_RDAR;
	else
		seqid = SEQID_FAST_READ;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	to_or_from = priv-&amp;gt;sf_addr + priv-&amp;gt;cur_amba_base;

	while (len &amp;gt; 0) {
		WATCHDOG_RESET();

		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, to_or_from);

		size = (len &amp;gt; RX_BUFFER_SIZE) ?
			RX_BUFFER_SIZE : len;

		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
			     (seqid &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) |
			     size);
		while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
			;

		to_or_from += size;
		len -= size;

		i = 0;
		while ((RX_BUFFER_SIZE &amp;gt;= size) &amp;amp;&amp;amp; (size &amp;gt; 0)) {
			data = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[i]);
			data = qspi_endian_xchg(data);
			if (size &amp;lt; 4)
				memcpy(rxbuf, &amp;amp;data, size);
			else
				memcpy(rxbuf, &amp;amp;data, 4);
			rxbuf++;
			size -= 4;
			i++;
		}
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
			     qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr) |
			     QSPI_MCR_CLR_RXF_MASK);
	}

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

static void qspi_op_write(struct fsl_qspi_priv *priv, u8 *txbuf, u32 len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg, data, reg, status_reg, seqid;
	int i, size, tx_size;
	u32 to_or_from = 0;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	if (TX_BUFFER_SIZE &amp;lt;= 256) {
		status_reg = 0;
		do {
			WATCHDOG_RESET();

			qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
				     (SEQID_RDSR &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 1);
			while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
				;

			reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbsr);
			if (reg &amp;amp; QSPI_RBSR_RDBFL_MASK) {
				status_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[0]);
				status_reg = qspi_endian_xchg(status_reg);
			}
			qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
				     qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr) |
				     QSPI_MCR_CLR_RXF_MASK);
		} while ((status_reg &amp;amp; FLASH_STATUS_WIP) == FLASH_STATUS_WIP);
	}

	status_reg = 0;
	while ((status_reg &amp;amp; FLASH_STATUS_WEL) != FLASH_STATUS_WEL) {
		WATCHDOG_RESET();

		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
			     (SEQID_WREN &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
		while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
			;

		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
			     (SEQID_RDSR &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 1);
		while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
			;

		reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbsr);
		if (reg &amp;amp; QSPI_RBSR_RDBFL_MASK) {
			status_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[0]);
			status_reg = qspi_endian_xchg(status_reg);
		}
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
			     qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr) |
			     QSPI_MCR_CLR_RXF_MASK);
	}

	/* Default is page programming */
	seqid = SEQID_PP;
	if (priv-&amp;gt;cur_seqid == QSPI_CMD_WRAR)
		seqid = SEQID_WRAR;
#ifdef CONFIG_SPI_FLASH_BAR
	if (priv-&amp;gt;cur_seqid == QSPI_CMD_BRWR)
		seqid = SEQID_BRWR;
	else if (priv-&amp;gt;cur_seqid == QSPI_CMD_WREAR)
		seqid = SEQID_WREAR;
#endif

	to_or_from = priv-&amp;gt;sf_addr + priv-&amp;gt;cur_amba_base;

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, to_or_from);

	tx_size = (len &amp;gt; TX_BUFFER_SIZE) ?
		TX_BUFFER_SIZE : len;

	size = tx_size / 16;
	/*
	 * There must be atleast 128bit data
	 * available in TX FIFO for any pop operation
	 */
	if (tx_size % 16)
		size++;
	for (i = 0; i &amp;lt; size * 4; i++) {
		memcpy(&amp;amp;data, txbuf, 4);
		data = qspi_endian_xchg(data);
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;tbdr, data);
		txbuf += 4;
	}

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
		     (seqid &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | tx_size);
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

static void qspi_op_rdsr(struct fsl_qspi_priv *priv, void *rxbuf, u32 len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg, reg, data;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, priv-&amp;gt;cur_amba_base);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
		     (SEQID_RDSR &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	while (1) {
		WATCHDOG_RESET();

		reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbsr);
		if (reg &amp;amp; QSPI_RBSR_RDBFL_MASK) {
			data = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[0]);
			data = qspi_endian_xchg(data);
			memcpy(rxbuf, &amp;amp;data, len);
			qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
				     qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr) |
				     QSPI_MCR_CLR_RXF_MASK);
			break;
		}
	}

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

static void qspi_op_rdfsr(struct fsl_qspi_priv *priv, void *rxbuf, u32 len)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg, reg, data;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, priv-&amp;gt;cur_amba_base);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
		     (SEQID_RDFSR &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	while (1) {
		WATCHDOG_RESET();

		reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbsr);
		if (reg &amp;amp; QSPI_RBSR_RDBFL_MASK) {
			data = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbdr[0]);
			data = qspi_endian_xchg(data);
			memcpy(rxbuf, &amp;amp;data, len);
			qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
				     qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr) |
				     QSPI_MCR_CLR_RXF_MASK);
			break;
		}
	}

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

static void qspi_op_erase(struct fsl_qspi_priv *priv)
{
	struct fsl_qspi_regs *regs = priv-&amp;gt;regs;
	u32 mcr_reg;
	u32 to_or_from = 0;

	mcr_reg = qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_CLR_RXF_MASK | QSPI_MCR_CLR_TXF_MASK |
		     mcr_reg);
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;rbct, QSPI_RBCT_RXBRD_USEIPS);

	to_or_from = priv-&amp;gt;sf_addr + priv-&amp;gt;cur_amba_base;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sfar, to_or_from);

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
		     (SEQID_WREN &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	if (priv-&amp;gt;cur_seqid == QSPI_CMD_SE) {
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
			     (SEQID_SE &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
	} else if (priv-&amp;gt;cur_seqid == QSPI_CMD_BE_4K) {
		qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;ipcr,
			     (SEQID_BE_4K &amp;lt;&amp;lt; QSPI_IPCR_SEQID_SHIFT) | 0);
	}
	while (qspi_read32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;sr) &amp;amp; QSPI_SR_BUSY_MASK)
		;

	qspi_write32(priv-&amp;gt;flags, &amp;amp;regs-&amp;gt;mcr, mcr_reg);
}

int qspi_xfer(struct fsl_qspi_priv *priv, unsigned int bitlen,
		const void *dout, void *din, unsigned long flags)
{
	u32 bytes = DIV_ROUND_UP(bitlen, 8);
	static u32 wr_sfaddr;
	u32 txbuf;

	WATCHDOG_RESET();

	if (dout) {
		if (flags &amp;amp; SPI_XFER_BEGIN) {
			priv-&amp;gt;cur_seqid = *(u8 *)dout;
			memcpy(&amp;amp;txbuf, dout, 4);
		}

		if (flags == SPI_XFER_END) {
			if ((priv-&amp;gt;cur_seqid == QSPI_CMD_SE) ||
				(priv-&amp;gt;cur_seqid == QSPI_CMD_BE_4K)) {
				int i;
				txbuf = *(u8 *)dout;
				for (i = 1; i &amp;lt; bytes; i++) {
					txbuf &amp;lt;&amp;lt;= 8;
					txbuf |= *(((u8 *)dout) + i);
				}

				priv-&amp;gt;sf_addr = txbuf;
				qspi_op_erase(priv);
				return 0;
			}
			priv-&amp;gt;sf_addr = wr_sfaddr;
			qspi_op_write(priv, (u8 *)dout, bytes);
			return 0;
		}

		if (priv-&amp;gt;cur_seqid == QSPI_CMD_FAST_READ ||
		    priv-&amp;gt;cur_seqid == QSPI_CMD_RDAR) {
			priv-&amp;gt;sf_addr = swab32(txbuf) &amp;amp; OFFSET_BITS_MASK;
		} else if (priv-&amp;gt;cur_seqid == QSPI_CMD_PP ||
			   priv-&amp;gt;cur_seqid == QSPI_CMD_WRAR) {
			wr_sfaddr = swab32(txbuf) &amp;amp; OFFSET_BITS_MASK;
		} else if ((priv-&amp;gt;cur_seqid == QSPI_CMD_BRWR) ||
			 (priv-&amp;gt;cur_seqid == QSPI_CMD_WREAR)) {
#ifdef CONFIG_SPI_FLASH_BAR
			wr_sfaddr = 0;
#endif
		}
	}

	if (din) {
		if (priv-&amp;gt;cur_seqid == QSPI_CMD_FAST_READ) {
#ifdef CONFIG_SYS_FSL_QSPI_AHB
			qspi_ahb_read(priv, din, bytes);
#else
			qspi_op_read(priv, din, bytes);
#endif
		} else if (priv-&amp;gt;cur_seqid == QSPI_CMD_RDAR) {
			qspi_op_read(priv, din, bytes);
		} else if (priv-&amp;gt;cur_seqid == QSPI_CMD_RDID)
			qspi_op_rdid(priv, din, bytes);
		else if (priv-&amp;gt;cur_seqid == QSPI_CMD_RDSR)
			qspi_op_rdsr(priv, din, bytes);
		else if (priv-&amp;gt;cur_seqid == QSPI_CMD_FLAG_SR)
			qspi_op_rdfsr(priv, din, bytes);
#ifdef CONFIG_SPI_FLASH_BAR
		else if ((priv-&amp;gt;cur_seqid == QSPI_CMD_BRRD) ||
			 (priv-&amp;gt;cur_seqid == QSPI_CMD_RDEAR)) {
			priv-&amp;gt;sf_addr = 0;
			qspi_op_rdbank(priv, din, bytes);
		}
#endif
	}

#ifdef CONFIG_SYS_FSL_QSPI_AHB
	if ((priv-&amp;gt;cur_seqid == QSPI_CMD_SE) ||
	    (priv-&amp;gt;cur_seqid == QSPI_CMD_PP) ||
	    (priv-&amp;gt;cur_seqid == QSPI_CMD_BE_4K) ||
	    (priv-&amp;gt;cur_seqid == QSPI_CMD_WREAR) ||
	    (priv-&amp;gt;cur_seqid == QSPI_CMD_BRWR))
		qspi_ahb_invalid(priv);
#endif

	return 0;
}

void qspi_module_disable(struct fsl_qspi_priv *priv, u8 disable)
{
	u32 mcr_val;

	mcr_val = qspi_read32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;mcr);
	if (disable)
		mcr_val |= QSPI_MCR_MDIS_MASK;
	else
		mcr_val &amp;amp;= ~QSPI_MCR_MDIS_MASK;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;mcr, mcr_val);
}

void qspi_cfg_smpr(struct fsl_qspi_priv *priv, u32 clear_bits, u32 set_bits)
{
	u32 smpr_val;

	smpr_val = qspi_read32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;smpr);
	smpr_val &amp;amp;= ~clear_bits;
	smpr_val |= set_bits;
	qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;smpr, smpr_val);
}
#ifndef CONFIG_DM_SPI
static unsigned long spi_bases[] = {
	QSPI0_BASE_ADDR,
#ifdef CONFIG_MX6SX
	QSPI1_BASE_ADDR,
#endif
};

static unsigned long amba_bases[] = {
	QSPI0_AMBA_BASE,
#ifdef CONFIG_MX6SX
	QSPI1_AMBA_BASE,
#endif
};

static inline struct fsl_qspi *to_qspi_spi(struct spi_slave *slave)
{
	return container_of(slave, struct fsl_qspi, slave);
}

struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
		unsigned int max_hz, unsigned int mode)
{
	u32 mcr_val;
	struct fsl_qspi *qspi;
	struct fsl_qspi_regs *regs;
	u32 total_size;

	if (bus &amp;gt;= ARRAY_SIZE(spi_bases))
		return NULL;

#ifdef CONFIG_MX6
	if (mx6_qspi_fused(spi_bases[bus])) {
		printf("QSPI@0x%lx is fused, disable it\n", spi_bases[bus]);
		return NULL;
	}
#endif

	if (cs &amp;gt;= FSL_QSPI_FLASH_NUM)
		return NULL;

	qspi = spi_alloc_slave(struct fsl_qspi, bus, cs);
	if (!qspi)
		return NULL;

#ifdef CONFIG_SYS_FSL_QSPI_BE
	qspi-&amp;gt;priv.flags |= QSPI_FLAG_REGMAP_ENDIAN_BIG;
#endif

	regs = (struct fsl_qspi_regs *)spi_bases[bus];
	qspi-&amp;gt;priv.regs = regs;
	/*
	 * According cs, use different amba_base to choose the
	 * corresponding flash devices.
	 *
	 * If not, only one flash device is used even if passing
	 * different cs using `sf probe`
	 */
	qspi-&amp;gt;priv.cur_amba_base = amba_bases[bus] + cs * FSL_QSPI_FLASH_SIZE;

	qspi-&amp;gt;slave.max_write_size = TX_BUFFER_SIZE;

	mcr_val = qspi_read32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;mcr);

	/* Set endianness to LE for i.mx */
	if (IS_ENABLED(CONFIG_MX6) || IS_ENABLED(CONFIG_MX7) || IS_ENABLED(CONFIG_MX7ULP))
		mcr_val = QSPI_MCR_END_CFD_LE;

	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;mcr,
		     QSPI_MCR_RESERVED_MASK | QSPI_MCR_MDIS_MASK |
		     (mcr_val &amp;amp; QSPI_MCR_END_CFD_MASK));

	qspi_cfg_smpr(&amp;amp;qspi-&amp;gt;priv,
		      ~(QSPI_SMPR_FSDLY_MASK | QSPI_SMPR_DDRSMP_MASK |
		      QSPI_SMPR_FSPHS_MASK | QSPI_SMPR_HSENA_MASK), 0);

	total_size = FSL_QSPI_FLASH_SIZE * FSL_QSPI_FLASH_NUM;

#if defined(CONFIG_MX7ULP)
	/*
	 * mx7ulp QSPI controller does not support parallel mode, it only has port A.
	 * To support dual die flash and single die flash, we set flash 1 size to CS0 area,
	 * set flash2 size to CS1 area.
	*/
	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;sfa1ad,
		     FSL_QSPI_FLASH_SIZE | amba_bases[bus]);
	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;sfa2ad,
		     total_size | amba_bases[bus]);
#else
	/*
	 * Any read access to non-implemented addresses will provide
	 * undefined results.
	 *
	 * In case single die flash devices, TOP_ADDR_MEMA2 and
	 * TOP_ADDR_MEMB2 should be initialized/programmed to
	 * TOP_ADDR_MEMA1 and TOP_ADDR_MEMB1 respectively - in effect,
	 * setting the size of these devices to 0.  This would ensure
	 * that the complete memory map is assigned to only one flash device.
	 */
	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;sfa1ad,
		     FSL_QSPI_FLASH_SIZE | amba_bases[bus]);
	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;sfa2ad,
		     FSL_QSPI_FLASH_SIZE | amba_bases[bus]);
	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;sfb1ad,
		     total_size | amba_bases[bus]);
	qspi_write32(qspi-&amp;gt;priv.flags, &amp;amp;regs-&amp;gt;sfb2ad,
		     total_size | amba_bases[bus]);
#endif

	qspi_set_lut(&amp;amp;qspi-&amp;gt;priv);

#ifdef CONFIG_SYS_FSL_QSPI_AHB
	qspi_init_ahb_read(&amp;amp;qspi-&amp;gt;priv);
#endif

	qspi_module_disable(&amp;amp;qspi-&amp;gt;priv, 0);

	return &amp;amp;qspi-&amp;gt;slave;
}

void spi_free_slave(struct spi_slave *slave)
{
	struct fsl_qspi *qspi = to_qspi_spi(slave);

	free(qspi);
}

int spi_claim_bus(struct spi_slave *slave)
{
	return 0;
}

void spi_release_bus(struct spi_slave *slave)
{
	/* Nothing to do */
}

int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
		const void *dout, void *din, unsigned long flags)
{
	struct fsl_qspi *qspi = to_qspi_spi(slave);

	return qspi_xfer(&amp;amp;qspi-&amp;gt;priv, bitlen, dout, din, flags);
}

void spi_init(void)
{
	/* Nothing to do */
}
#else
static int fsl_qspi_child_pre_probe(struct udevice *dev)
{
	struct spi_slave *slave = dev_get_parent_priv(dev);

	slave-&amp;gt;max_write_size = TX_BUFFER_SIZE;

	return 0;
}

static int fsl_qspi_probe(struct udevice *bus)
{
	u32 mcr_val;
	u32 amba_size_per_chip;
	struct fsl_qspi_platdata *plat = dev_get_platdata(bus);
	struct fsl_qspi_priv *priv = dev_get_priv(bus);
	struct dm_spi_bus *dm_spi_bus;
	int i, ret;

#ifdef CONFIG_MX6
	if (mx6_qspi_fused(plat-&amp;gt;reg_base)) {
		printf("QSPI@0x%lx is fused, disable it\n", plat-&amp;gt;reg_base);
		return -ENODEV;
	}
#endif

	dm_spi_bus = bus-&amp;gt;uclass_priv;

	dm_spi_bus-&amp;gt;max_hz = plat-&amp;gt;speed_hz;

	priv-&amp;gt;regs = (struct fsl_qspi_regs *)(uintptr_t)plat-&amp;gt;reg_base;
	priv-&amp;gt;flags = plat-&amp;gt;flags;

	priv-&amp;gt;speed_hz = plat-&amp;gt;speed_hz;
	/*
	 * QSPI SFADR width is 32bits, the max dest addr is 4GB-1.
	 * AMBA memory zone should be located on the 0~4GB space
	 * even on a 64bits cpu.
	 */
	priv-&amp;gt;amba_base[0] = (u32)plat-&amp;gt;amba_base;
	priv-&amp;gt;amba_total_size = (u32)plat-&amp;gt;amba_total_size;
	priv-&amp;gt;flash_num = plat-&amp;gt;flash_num;
	priv-&amp;gt;num_chipselect = plat-&amp;gt;num_chipselect;

	/* make sure controller is not busy anywhere */
	ret = is_controller_busy(priv);

	if (ret) {
		debug("ERROR : The controller is busy\n");
		return ret;
	}

	mcr_val = qspi_read32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;mcr);

	/* Set endianness to LE for i.mx */
	if (IS_ENABLED(CONFIG_MX6) || IS_ENABLED(CONFIG_MX7) || IS_ENABLED(CONFIG_MX7ULP))
		mcr_val = QSPI_MCR_END_CFD_LE;

	qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;mcr,
		     QSPI_MCR_RESERVED_MASK | QSPI_MCR_MDIS_MASK |
		     (mcr_val &amp;amp; QSPI_MCR_END_CFD_MASK));

	qspi_cfg_smpr(priv, ~(QSPI_SMPR_FSDLY_MASK | QSPI_SMPR_DDRSMP_MASK |
		QSPI_SMPR_FSPHS_MASK | QSPI_SMPR_HSENA_MASK), 0);

	/*
	 * Assign AMBA memory zone for every chipselect
	 * QuadSPI has two channels, every channel has two chipselects.
	 * If the property 'num-cs' in dts is 2, the AMBA memory will be divided
	 * into two parts and assign to every channel. This indicate that every
	 * channel only has one valid chipselect.
	 * If the property 'num-cs' in dts is 4, the AMBA memory will be divided
	 * into four parts and assign to every chipselect.
	 * Every channel will has two valid chipselects.
	 */
	amba_size_per_chip = priv-&amp;gt;amba_total_size &amp;gt;&amp;gt;
			     (priv-&amp;gt;num_chipselect &amp;gt;&amp;gt; 1);
	for (i = 1 ; i &amp;lt; priv-&amp;gt;num_chipselect ; i++)
		priv-&amp;gt;amba_base[i] =
			amba_size_per_chip + priv-&amp;gt;amba_base[i - 1];

	/*
	 * Any read access to non-implemented addresses will provide
	 * undefined results.
	 *
	 * In case single die flash devices, TOP_ADDR_MEMA2 and
	 * TOP_ADDR_MEMB2 should be initialized/programmed to
	 * TOP_ADDR_MEMA1 and TOP_ADDR_MEMB1 respectively - in effect,
	 * setting the size of these devices to 0.  This would ensure
	 * that the complete memory map is assigned to only one flash device.
	 */
	qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfa1ad,
		     priv-&amp;gt;amba_base[0] + amba_size_per_chip);
	switch (priv-&amp;gt;num_chipselect) {
	case 1:
		break;
	case 2:
		qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfa2ad,
			     priv-&amp;gt;amba_base[1]);
		qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfb1ad,
			     priv-&amp;gt;amba_base[1] + amba_size_per_chip);
		qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfb2ad,
			     priv-&amp;gt;amba_base[1] + amba_size_per_chip);
		break;
	case 4:
		qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfa2ad,
			     priv-&amp;gt;amba_base[2]);
		qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfb1ad,
			     priv-&amp;gt;amba_base[3]);
		qspi_write32(priv-&amp;gt;flags, &amp;amp;priv-&amp;gt;regs-&amp;gt;sfb2ad,
			     priv-&amp;gt;amba_base[3] + amba_size_per_chip);
		break;
	default:
		debug("Error: Unsupported chipselect number %u!\n",
		      priv-&amp;gt;num_chipselect);
		qspi_module_disable(priv, 1);
		return -EINVAL;
	}

	qspi_set_lut(priv);

#ifdef CONFIG_SYS_FSL_QSPI_AHB
	qspi_init_ahb_read(priv);
#endif

	qspi_module_disable(priv, 0);

	return 0;
}

static int fsl_qspi_ofdata_to_platdata(struct udevice *bus)
{
	struct fdt_resource res_regs, res_mem;
	struct fsl_qspi_platdata *plat = bus-&amp;gt;platdata;
	const void *blob = gd-&amp;gt;fdt_blob;
	int node = dev_of_offset(bus);
	int ret, flash_num = 0, subnode;

	if (fdtdec_get_bool(blob, node, "big-endian"))
		plat-&amp;gt;flags |= QSPI_FLAG_REGMAP_ENDIAN_BIG;

	ret = fdt_get_named_resource(blob, node, "reg", "reg-names",
				     "QuadSPI", &amp;amp;res_regs);
	if (ret) {
		debug("Error: can't get regs base addresses(ret = %d)!\n", ret);
		return -ENOMEM;
	}
	ret = fdt_get_named_resource(blob, node, "reg", "reg-names",
				     "QuadSPI-memory", &amp;amp;res_mem);
	if (ret) {
		debug("Error: can't get AMBA base addresses(ret = %d)!\n", ret);
		return -ENOMEM;
	}

	/* Count flash numbers */
	fdt_for_each_subnode(subnode, blob, node)
		++flash_num;

	if (flash_num == 0) {
		debug("Error: Missing flashes!\n");
		return -ENODEV;
	}

	plat-&amp;gt;speed_hz = fdtdec_get_int(blob, node, "spi-max-frequency",
					FSL_QSPI_DEFAULT_SCK_FREQ);
	plat-&amp;gt;num_chipselect = fdtdec_get_int(blob, node, "num-cs",
					      FSL_QSPI_MAX_CHIPSELECT_NUM);

	plat-&amp;gt;reg_base = res_regs.start;
	plat-&amp;gt;amba_base = res_mem.start;
	plat-&amp;gt;amba_total_size = res_mem.end - res_mem.start + 1;
	plat-&amp;gt;flash_num = flash_num;

	debug("%s: regs=&amp;lt;0x%llx&amp;gt; &amp;lt;0x%llx, 0x%llx&amp;gt;, max-frequency=%d, endianess=%s\n",
	      __func__,
	      (u64)plat-&amp;gt;reg_base,
	      (u64)plat-&amp;gt;amba_base,
	      (u64)plat-&amp;gt;amba_total_size,
	      plat-&amp;gt;speed_hz,
	      plat-&amp;gt;flags &amp;amp; QSPI_FLAG_REGMAP_ENDIAN_BIG ? "be" : "le"
	      );

	return 0;
}

static int fsl_qspi_xfer(struct udevice *dev, unsigned int bitlen,
		const void *dout, void *din, unsigned long flags)
{
	struct fsl_qspi_priv *priv;
	struct udevice *bus;

	bus = dev-&amp;gt;parent;
	priv = dev_get_priv(bus);

	return qspi_xfer(priv, bitlen, dout, din, flags);
}

static int fsl_qspi_claim_bus(struct udevice *dev)
{
	struct fsl_qspi_priv *priv;
	struct udevice *bus;
	struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
	int ret;

	bus = dev-&amp;gt;parent;
	priv = dev_get_priv(bus);

	/* make sure controller is not busy anywhere */
	ret = is_controller_busy(priv);

	if (ret) {
		debug("ERROR : The controller is busy\n");
		return ret;
	}

	priv-&amp;gt;cur_amba_base = priv-&amp;gt;amba_base[slave_plat-&amp;gt;cs];

	qspi_module_disable(priv, 0);

	return 0;
}

static int fsl_qspi_release_bus(struct udevice *dev)
{
	struct fsl_qspi_priv *priv;
	struct udevice *bus;

	bus = dev-&amp;gt;parent;
	priv = dev_get_priv(bus);

	qspi_module_disable(priv, 1);

	return 0;
}

static int fsl_qspi_set_speed(struct udevice *bus, uint speed)
{
	/* Nothing to do */
	return 0;
}

static int fsl_qspi_set_mode(struct udevice *bus, uint mode)
{
	/* Nothing to do */
	return 0;
}

static const struct dm_spi_ops fsl_qspi_ops = {
	.claim_bus	= fsl_qspi_claim_bus,
	.release_bus	= fsl_qspi_release_bus,
	.xfer		= fsl_qspi_xfer,
	.set_speed	= fsl_qspi_set_speed,
	.set_mode	= fsl_qspi_set_mode,
};

static const struct udevice_id fsl_qspi_ids[] = {
	{ .compatible = "fsl,vf610-qspi" },
	{ .compatible = "fsl,imx6sx-qspi" },
	{ .compatible = "fsl,imx6ul-qspi" },
	{ .compatible = "fsl,imx7d-qspi" },
	{ .compatible = "fsl,imx7ulp-qspi" },
	{ }
};

U_BOOT_DRIVER(fsl_qspi) = {
	.name	= "fsl_qspi",
	.id	= UCLASS_SPI,
	.of_match = fsl_qspi_ids,
	.ops	= &amp;amp;fsl_qspi_ops,
	.ofdata_to_platdata = fsl_qspi_ofdata_to_platdata,
	.platdata_auto_alloc_size = sizeof(struct fsl_qspi_platdata),
	.priv_auto_alloc_size = sizeof(struct fsl_qspi_priv),
	.probe	= fsl_qspi_probe,
	.child_pre_probe = fsl_qspi_child_pre_probe,
};
#endif&lt;/LI-CODE&gt;&lt;P&gt;After the SEMA42 handshake, M4 reinitializes the QSPI &amp;amp; lut thereof before accessing again the log space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M4 side partitioning of the QSPI log:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#define EXAMPLE_QSPI QuadSPI0
#define QSPI_CLK_FREQ CLOCK_GetIpFreq(kCLOCK_Qspi)
#define EXAMPLE_DMAMUX DMA_CH_MUX0
#define EXAMPLE_CHANNEL 16U
#define EXAMPLE_DMA DMA0
#define EXAMPLE_DMA_SOURCE kDmaRequestMux0QSPITx
#define FLASH_PAGE_SIZE_U8    256U
#define FLASH_PAGE_SIZE_U32   (FLASH_PAGE_SIZE_U8)/4
#define FLASH_SECTOR_SIZE_U8  4096U
#define FLASH_SECTOR_SIZE_U32 (FLASH_SECTOR_SIZE_U8)/4
#define FLASH_SIZE 0x00400000U
#define FLASH_ENABLE_QUAD_CMD 0x40U
#define QSPI_ERASE_ADDR_OFFSET 0x200000U
#define DUMMY_MASTER (0xE)

#define QSPI_MSG_FLAG_SIZE (1)
#define QSPI_MSG_FLAG_NEW  (0xEE)
#define QSPI_MSG_FLAG_SENT (0xCC)

#define QSPI_BLOB_FLAG_SIZE (1)
#define QSPI_BLOB_XOR_SIZE  (1)
#define QSPI_BLOB_FLAG      (0x55)

#define QSPI_BUFFER_SIZE_PAGES 4096U /*number of entries (1 page long or less), size in memory pages*/
#define QSPI_CANARY_START_ADDR (uint32_t*)(FSL_FEATURE_QSPI_AMBA_BASE + QSPI_ERASE_ADDR_OFFSET)
#define QSPI_CANARY_END_ADDR (uint32_t*)(FSL_FEATURE_QSPI_AMBA_BASE + QSPI_ERASE_ADDR_OFFSET + (FLASH_PAGE_SIZE_U8 * QSPI_BUFFER_SIZE_PAGES))
#define QSPI_START_BUFFER (uint32_t*)(QSPI_CANARY_START_ADDR + (FLASH_SECTOR_SIZE_U8))
#define QSPI_END_BUFFER (uint32_t*)(QSPI_CANARY_END_ADDR - (FLASH_SECTOR_SIZE_U8))

/* calibration data space for BME680 sensors */
#define QSPI_BLOB_SPACE_SIZE_SECTORS 8U
#define QSPI_CANARY_BLOB_SPACE_START_ADDR   (uint32_t*)(FSL_FEATURE_QSPI_AMBA_BASE + QSPI_ERASE_ADDR_OFFSET + (FLASH_PAGE_SIZE_U8 * QSPI_BUFFER_SIZE_PAGES))
#define QSPI_CANARY_BLOB_SPACE_END_ADDR     (uint32_t*)(FSL_FEATURE_QSPI_AMBA_BASE + QSPI_ERASE_ADDR_OFFSET + (FLASH_PAGE_SIZE_U8 * QSPI_BUFFER_SIZE_PAGES) + (QSPI_BLOB_SPACE_SIZE_SECTORS*FLASH_SECTOR_SIZE_U8))

#define QSPI_START_BLOB_SPACE               (uint32_t*)(QSPI_CANARY_BLOB_SPACE_START_ADDR + FLASH_SECTOR_SIZE_U8)
#define QSPI_END_BLOB_SPACE                 (uint32_t*)(QSPI_CANARY_BLOB_SPACE_END_ADDR - FLASH_SECTOR_SIZE_U8)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In consequence, A7 only accesses the first part for the QSPI (before the defined LOG space) and M4 only accesses the log space (except when loading its program at boat time from QSPI).&lt;/P&gt;&lt;P&gt;Logs are then transmitted from M4 to A7 via RPMsg (no direct log access of A7 at runtime).&lt;/P&gt;&lt;P&gt;Hope this clarifies the use case. As said we unfortunately don't have a simple demo of that at the moment.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 11:55:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1177928#M2859</guid>
      <dc:creator>quentincabrol</dc:creator>
      <dc:date>2020-11-04T11:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178769#M2862</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please let me know if my understanding is correct:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;You have partitioned the QSPI flash into 2 partitions.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1st partition has the M4 image, A7 access(Read+write) this partition to validate the M4 image. 2nd partition is where the M4 writes the logs.&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;M4 only access(Read) the first partition during boot time to load the firmware image to RAM. After the firmware is loaded in the RAM, it uses the 2nd partition to write the logs.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Following are a few more queries:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;During A7 reboot, A7 will validate the M4 image from the 1st partition of the QSPI. So at that time will the M4 firmware image, which is in the RAM is still executing? If it is the case, there will be conflict as the M4 image is already running, and writing the logs in the 2nd partition of the QSPI and M4 once again reinit the QSPI as you mentioned.&lt;/LI&gt;
&lt;LI&gt;Which uboot version you are using? Because as I check the fsl_qspi.c that you provided is quite different than the uboot revision 1_2020.04-r0, which is using in Linux 5.4.24. Please find the attachment for reference.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The LUT of the M4 that you are using and the one provided in the SDK is the same.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Karan Gajjar&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 12:12:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178769#M2862</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-11-05T12:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178781#M2863</link>
      <description>&lt;P&gt;Hello Karan,&lt;/P&gt;&lt;P&gt;Thanks for the follow-up.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;1) correct&lt;/LI&gt;&lt;LI&gt;2) also correct&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Regarding the additional queries questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;correct M4 is still running when A7 reboots. But M4 detects on interrupt the A7 state change and prevent access to the QSPI by the M4 until the full SEMA42 handshake sequence with uboot is completed and the SEMA42 made available. (there is no concurrent access because we prevent M4 access during A7 reboot sequence).&lt;/LI&gt;&lt;LI&gt;we are still running with a slightly modified version of the 4.14.98 with uboot version&lt;DIV class="c-message_kit__gutter"&gt;&lt;DIV class="c-message_kit__gutter__right"&gt;&lt;DIV class="c-message_kit__blocks c-message_kit__blocks--rich_text"&gt;&lt;DIV class="c-message__message_blocks c-message__message_blocks--rich_text"&gt;&lt;DIV class="p-block_kit_renderer"&gt;&lt;DIV class="p-block_kit_renderer__block_wrapper p-block_kit_renderer__block_wrapper--first"&gt;&lt;DIV class="p-rich_text_block"&gt;&lt;DIV class="p-rich_text_section"&gt;&lt;A href="https://github.com/foundriesio/u-boot/tree/2019.10+fio" target="_self"&gt;u-boot-fio-v2019.10+git &lt;/A&gt;&amp;nbsp;BSP on 5.4 is not ready yet for our product.&lt;/DIV&gt;&lt;DIV class="p-rich_text_section"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="p-rich_text_section"&gt;I reattached the file fsl_qspi as well as I am not sure i forwarded the proper version first time around.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks again for the support&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 12:57:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178781#M2863</guid>
      <dc:creator>quentincabrol</dc:creator>
      <dc:date>2020-11-05T12:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178796#M2864</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for the quick response, we will try to replicate the setup at our end and will get back to you with our findings.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Our current demo application loads the firmware image from QSPI and runs on M4. We need to customize this to stop accessing the QSPI when A7 is accessing. So we need to update the uboot code as well to read the QSPI firmware image on reboot. And partition the QSPI and use SEMA42.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Karan Gajjar&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 13:37:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178796#M2864</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-11-05T13:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178834#M2865</link>
      <description>&lt;P&gt;thanks very much for the support !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need any additional information, let us know.&lt;/P&gt;&lt;P&gt;Looking forward to your feedback on that matter.&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 15:08:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1178834#M2865</guid>
      <dc:creator>quentincabrol</dc:creator>
      <dc:date>2020-11-05T15:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: fsl_qspi.c init sequence not working when u-boot configures QSPI for AHB reads</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1183144#M2878</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;quentincabrol,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just a quick question, how are you partitioning the QSPI? Are you doing that by changing the start address of QSPI in M4? Like changing the value of&amp;nbsp;FSL_FEATURE_QSPI_AMBA_BASE? And changing the size of the QSPI in uboot for A7?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Karan Gajjar&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 12:33:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/fsl-qspi-c-init-sequence-not-working-when-u-boot-configures-QSPI/m-p/1183144#M2878</guid>
      <dc:creator>nxf65420</dc:creator>
      <dc:date>2020-11-13T12:33:56Z</dc:date>
    </item>
  </channel>
</rss>

