* [RFC] MXS/i.MX23: detecting the boot source
@ 2013-05-17 8:18 Juergen Beisert
2013-05-21 6:57 ` Sascha Hauer
0 siblings, 1 reply; 5+ messages in thread
From: Juergen Beisert @ 2013-05-17 8:18 UTC (permalink / raw)
To: barebox
The boot source for the i.MX23 is configured via a few GPIOs, which are later
be used for different purposes (like LCD data for example). The SoC internal
ROM reads these GPIOs and uses the selected boot source.
For various reasons the boot source is also of interest when Barebox is running.
This detection approach reads again the GPIOs. It switches temporarily the pins
to act as GPIOs and input, reads their values, and switches back to their
previous functions.
Could this be a reliable way to detect the boot source?
BTW: is there a reason why the bootsource will create environment variables,
while other detected features find their way to the "global" device?
---
arch/arm/mach-mxs/imx.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
Index: barebox-2013.05.0/arch/arm/mach-mxs/imx.c
===================================================================
--- barebox-2013.05.0.orig/arch/arm/mach-mxs/imx.c
+++ barebox-2013.05.0/arch/arm/mach-mxs/imx.c
@@ -112,6 +114,48 @@ static void mxs_silicon_revision(void)
silicon_revision_set(product, revision);
}
+#define HW_PINCTRL_MUXSEL2 0x120
+#define HW_PINCTRL_MUXSEL3 0x130
+#define HW_PINCTRL_DOE1 0x710
+#define HW_PINCTRL_DIN1 0x610
+
+/*
+ * we are interested in the setting of:
+ * - GPIO BANK1/19: 1 = the ROM has used the following pins for boot source selection
+ * - GPIO BANK1/5: ETM enable
+ * - GPIO BANK1/3: BM3
+ * - GPIO BANK1/2: BM2
+ * - GPIO BANK1/1: BM1
+ * - GPIO BANK1/0: BM0
+ */
+static uint32_t mxs23_boot_save_loc(void)
+{
+ uint32_t mux2, mux3, dir, mode;
+
+ mux3 = readl(IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL3);
+ mux2 = readl(IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL2);
+ dir = readl(IMX_IOMUXC_BASE + HW_PINCTRL_DOE1);
+
+ /* force the GPIO lines of interest to input */
+ writel(0x0008002f, IMX_IOMUXC_BASE + HW_PINCTRL_DOE1 + 8);
+ /* force the GPIO lines of interest to act as GPIO */
+ writel(0x00000cff, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL2 + 4);
+ writel(0x000000c0, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL3 + 4);
+
+ /* read the bootstrapping */
+ mode = readl(IMX_IOMUXC_BASE + HW_PINCTRL_DIN1) & 0x8002f;
+
+ /* restore previous settings */
+ writel(mux3, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL3);
+ writel(mux2, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL2);
+ writel(dir, IMX_IOMUXC_BASE + HW_PINCTRL_DOE1);
+
+ if (!(mode & (1 << 19)))
+ return 0xff; /* invalid marker */
+
+ return (mode & 0xf) | ((mode & 0x20) >> 1);
+}
+
#define MX28_REV_1_0_MODE (0x0001a7f0)
#define MX28_REV_1_2_MODE (0x00019bf0)
@@ -122,7 +166,7 @@ static void mxs_boot_save_loc(void)
uint32_t mode = 0xff;
if (cpu_is_mx23()) {
- /* not implemented yet */
+ mode = mxs23_boot_save_loc();
} else if (cpu_is_mx28()) {
enum silicon_revision rev = silicon_revision_get();
Regards,
Juergen
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] MXS/i.MX23: detecting the boot source
2013-05-17 8:18 [RFC] MXS/i.MX23: detecting the boot source Juergen Beisert
@ 2013-05-21 6:57 ` Sascha Hauer
2013-05-21 8:01 ` Juergen Beisert
2013-05-21 8:44 ` [PATCH] MXS/i.MX23: add boot source detection Juergen Beisert
0 siblings, 2 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-05-21 6:57 UTC (permalink / raw)
To: Juergen Beisert; +Cc: barebox
On Fri, May 17, 2013 at 10:18:39AM +0200, Juergen Beisert wrote:
> The boot source for the i.MX23 is configured via a few GPIOs, which are later
> be used for different purposes (like LCD data for example). The SoC internal
> ROM reads these GPIOs and uses the selected boot source.
>
> For various reasons the boot source is also of interest when Barebox is running.
> This detection approach reads again the GPIOs. It switches temporarily the pins
> to act as GPIOs and input, reads their values, and switches back to their
> previous functions.
>
> Could this be a reliable way to detect the boot source?
I don't know. Are the bootstrap pins used as outputs only in the normal
usecase? Otherwise I could imagine that something is overriding the
bootstrap pins by the time you read them.
>
> BTW: is there a reason why the bootsource will create environment variables,
> while other detected features find their way to the "global" device?
No, at least not a good one ;)
> +static uint32_t mxs23_boot_save_loc(void)
Should you continue working on this please change the name to something
like mx23_get_bootsource(). This function does not save anything.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] MXS/i.MX23: detecting the boot source
2013-05-21 6:57 ` Sascha Hauer
@ 2013-05-21 8:01 ` Juergen Beisert
2013-05-21 8:44 ` [PATCH] MXS/i.MX23: add boot source detection Juergen Beisert
1 sibling, 0 replies; 5+ messages in thread
From: Juergen Beisert @ 2013-05-21 8:01 UTC (permalink / raw)
To: barebox
Sascha Hauer wrote:
> On Fri, May 17, 2013 at 10:18:39AM +0200, Juergen Beisert wrote:
> > The boot source for the i.MX23 is configured via a few GPIOs, which are
> > later be used for different purposes (like LCD data for example). The SoC
> > internal ROM reads these GPIOs and uses the selected boot source.
> >
> > For various reasons the boot source is also of interest when Barebox is
> > running. This detection approach reads again the GPIOs. It switches
> > temporarily the pins to act as GPIOs and input, reads their values, and
> > switches back to their previous functions.
> >
> > Could this be a reliable way to detect the boot source?
>
> I don't know. Are the bootstrap pins used as outputs only in the normal
> usecase? Otherwise I could imagine that something is overriding the
> bootstrap pins by the time you read them.
These where also my thoughts. The pins the ROM reads can also be used as
GPIO, LCD data out and for the Embedded Trace Macrocell (ETM). Maybe not
perfectly reliable, but the chance is high that it works as expected.
There is no real latch register to save the settings after reset (at least I
didn't found one). Maybe the ROM stores this value somewhere in the internal
SRAM (like the i.MX28 ROM does), but how to know where....?
> > BTW: is there a reason why the bootsource will create environment
> > variables, while other detected features find their way to the "global"
> > device?
>
> No, at least not a good one ;)
Ahh, okay :)
> > +static uint32_t mxs23_boot_save_loc(void)
>
> Should you continue working on this please change the name to something
> like mx23_get_bootsource(). This function does not save anything.
Yes, will do so.
jbe
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] MXS/i.MX23: add boot source detection
2013-05-21 6:57 ` Sascha Hauer
2013-05-21 8:01 ` Juergen Beisert
@ 2013-05-21 8:44 ` Juergen Beisert
2013-05-23 7:54 ` Sascha Hauer
1 sibling, 1 reply; 5+ messages in thread
From: Juergen Beisert @ 2013-05-21 8:44 UTC (permalink / raw)
To: barebox
The boot source for the i.MX23 is configured via a few GPIOs, which are later
be used for different purposes (like LCD data for example). The SoC internal
ROM reads these GPIOs and uses the selected boot source.
For various reasons the boot source is also of interest when Barebox is running.
This detection approach reads again the GPIOs. It switches temporarily the pins
to act as GPIOs and input, reads their settings, and switches back to their
previous functions.
Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
arch/arm/mach-mxs/imx.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
Index: barebox-2013.05.0/arch/arm/mach-mxs/imx.c
===================================================================
--- barebox-2013.05.0.orig/arch/arm/mach-mxs/imx.c
+++ barebox-2013.05.0/arch/arm/mach-mxs/imx.c
@@ -112,6 +112,48 @@ static void mxs_silicon_revision(void)
silicon_revision_set(product, revision);
}
+#define HW_PINCTRL_MUXSEL2 0x120
+#define HW_PINCTRL_MUXSEL3 0x130
+#define HW_PINCTRL_DOE1 0x710
+#define HW_PINCTRL_DIN1 0x610
+
+/*
+ * we are interested in the setting of:
+ * - GPIO BANK1/19: 1 = the ROM has used the following pins for boot source selection
+ * - GPIO BANK1/5: ETM enable
+ * - GPIO BANK1/3: BM3
+ * - GPIO BANK1/2: BM2
+ * - GPIO BANK1/1: BM1
+ * - GPIO BANK1/0: BM0
+ */
+static uint32_t mx23_detect_bootsource(void)
+{
+ uint32_t mux2, mux3, dir, mode;
+
+ mux3 = readl(IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL3);
+ mux2 = readl(IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL2);
+ dir = readl(IMX_IOMUXC_BASE + HW_PINCTRL_DOE1);
+
+ /* force the GPIO lines of interest to input */
+ writel(0x0008002f, IMX_IOMUXC_BASE + HW_PINCTRL_DOE1 + 8);
+ /* force the GPIO lines of interest to act as GPIO */
+ writel(0x00000cff, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL2 + 4);
+ writel(0x000000c0, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL3 + 4);
+
+ /* read the bootstrapping */
+ mode = readl(IMX_IOMUXC_BASE + HW_PINCTRL_DIN1) & 0x8002f;
+
+ /* restore previous settings */
+ writel(mux3, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL3);
+ writel(mux2, IMX_IOMUXC_BASE + HW_PINCTRL_MUXSEL2);
+ writel(dir, IMX_IOMUXC_BASE + HW_PINCTRL_DOE1);
+
+ if (!(mode & (1 << 19)))
+ return 0xff; /* invalid marker */
+
+ return (mode & 0xf) | ((mode & 0x20) >> 1);
+}
+
#define MX28_REV_1_0_MODE (0x0001a7f0)
#define MX28_REV_1_2_MODE (0x00019bf0)
@@ -122,7 +164,7 @@ static void mxs_boot_save_loc(void)
uint32_t mode = 0xff;
if (cpu_is_mx23()) {
- /* not implemented yet */
+ mode = mx23_detect_bootsource();
} else if (cpu_is_mx28()) {
enum silicon_revision rev = silicon_revision_get();
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] MXS/i.MX23: add boot source detection
2013-05-21 8:44 ` [PATCH] MXS/i.MX23: add boot source detection Juergen Beisert
@ 2013-05-23 7:54 ` Sascha Hauer
0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-05-23 7:54 UTC (permalink / raw)
To: Juergen Beisert; +Cc: barebox
On Tue, May 21, 2013 at 10:44:12AM +0200, Juergen Beisert wrote:
> The boot source for the i.MX23 is configured via a few GPIOs, which are later
> be used for different purposes (like LCD data for example). The SoC internal
> ROM reads these GPIOs and uses the selected boot source.
>
> For various reasons the boot source is also of interest when Barebox is running.
> This detection approach reads again the GPIOs. It switches temporarily the pins
> to act as GPIOs and input, reads their settings, and switches back to their
> previous functions.
>
> Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-05-23 7:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-17 8:18 [RFC] MXS/i.MX23: detecting the boot source Juergen Beisert
2013-05-21 6:57 ` Sascha Hauer
2013-05-21 8:01 ` Juergen Beisert
2013-05-21 8:44 ` [PATCH] MXS/i.MX23: add boot source detection Juergen Beisert
2013-05-23 7:54 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox