<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hello,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I tested this patch by removing the pinmux initialization code from the Beagle I2C</div><div class="gmail_default" style="font-size:small">driver and letting this driver do the initialization. I then used the I2C driver to read</div><div class="gmail_default" style="font-size:small">the EEPROM in the pocket beagle using the I2C driver. The initialization of the</div><div class="gmail_default" style="font-size:small">pinmux settings was also confirmed using JTAG.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">To confirm that the driver also works in libBSD I used the media01 example to</div><div class="gmail_default" style="font-size:small">write a test file to the SD card. Though I couldn't write to it due to some pre-existing</div><div class="gmail_default" style="font-size:small">issue which I also faced during GSoC I was able to get the SD card details like the size</div><div class="gmail_default" style="font-size:small">and make which gives some hope that the driver works in libBSD too.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I kindly request people owning beagle hardware to test the driver.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I also apologies for the long inactivity, I was consumed with other activities which left</div><div class="gmail_default" style="font-size:small">me no free time to work on this post-GSoC.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Thanks,</div><div class="gmail_default" style="font-size:small">Niteesh.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 13, 2021 at 4:32 PM G S Niteesh Babu <<a href="mailto:niteesh.gs@gmail.com">niteesh.gs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The following files have been ported<br>
1) ti_pinmux.c<br>
2) ti_pinmux.h<br>
3) am335x_scm_padconf.c<br>
4) am335x_scm_padconf.h<br>
<br>
Update #3784<br>
---<br>
bsps/arm/beagle/start/bspstart.c | 31 +++++<br>
bsps/include/arm/ti/ti_pinmux.h | 9 +-<br>
.../sys/arm/ti/am335x/am335x_scm_padconf.c | 4 +<br>
bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c | 115 +++++++++++++++++-<br>
spec/build/bsps/obj.yml | 6 +<br>
5 files changed, 163 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/bsps/arm/beagle/start/bspstart.c b/bsps/arm/beagle/start/bspstart.c<br>
index 0a6f1b4a64..a0736294c9 100644<br>
--- a/bsps/arm/beagle/start/bspstart.c<br>
+++ b/bsps/arm/beagle/start/bspstart.c<br>
@@ -20,6 +20,8 @@<br>
#include <bsp/i2c.h><br>
#include <rtems/sysinit.h><br>
#include "bsp-soc-detect.h"<br>
+#include <arm/ti/ti_pinmux.h><br>
+#include <ofw/ofw.h><br>
<br>
#include "bspdebug.h"<br>
<br>
@@ -55,6 +57,29 @@ uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)<br>
return intr[0];<br>
}<br>
<br>
+static void traverse_fdt_nodes( phandle_t node )<br>
+{<br>
+<br>
+ for (node = rtems_ofw_child(node); node != 0; node = rtems_ofw_peer(node)) {<br>
+ traverse_fdt_nodes(node);<br>
+<br>
+ if (!rtems_ofw_node_status(node))<br>
+ continue;<br>
+<br>
+ /*<br>
+ * Put all driver initialization functions here<br>
+ */<br>
+ beagle_pinmux_init(node);<br>
+ }<br>
+}<br>
+<br>
+static void bbb_drivers_initialize(void)<br>
+{<br>
+ phandle_t node = rtems_ofw_peer(0);<br>
+<br>
+ traverse_fdt_nodes(node);<br>
+}<br>
+<br>
static void bbb_i2c_0_initialize(void)<br>
{<br>
int err;<br>
@@ -73,3 +98,9 @@ RTEMS_SYSINIT_ITEM(<br>
RTEMS_SYSINIT_LAST,<br>
RTEMS_SYSINIT_ORDER_LAST_BUT_5<br>
);<br>
+<br>
+RTEMS_SYSINIT_ITEM(<br>
+ bbb_drivers_initialize,<br>
+ RTEMS_SYSINIT_BSP_PRE_DRIVERS,<br>
+ RTEMS_SYSINIT_ORDER_LAST<br>
+);<br>
diff --git a/bsps/include/arm/ti/ti_pinmux.h b/bsps/include/arm/ti/ti_pinmux.h<br>
index 52409df61d..208e327c2b 100644<br>
--- a/bsps/include/arm/ti/ti_pinmux.h<br>
+++ b/bsps/include/arm/ti/ti_pinmux.h<br>
@@ -42,6 +42,9 @@<br>
*/<br>
#ifndef _TI_PINMUX_H_<br>
#define _TI_PINMUX_H_<br>
+#ifdef __rtems__<br>
+#include <ofw/ofw.h><br>
+#endif /* __rtems__ */<br>
<br>
struct ti_pinmux_padconf {<br>
uint16_t reg_off;<br>
@@ -63,12 +66,16 @@ struct ti_pinmux_device {<br>
const struct ti_pinmux_padconf *padconf;<br>
};<br>
<br>
+#ifndef __rtems__<br>
struct ti_pinmux_softc {<br>
device_t sc_dev;<br>
struct resource * sc_res[4];<br>
bus_space_tag_t sc_bst;<br>
bus_space_handle_t sc_bsh;<br>
};<br>
+#else /* __rtems__ */<br>
+void beagle_pinmux_init(phandle_t node);<br>
+#endif /* __rtems__ */<br>
<br>
int ti_pinmux_padconf_set(const char *padname, const char *muxmode, <br>
unsigned int state);<br>
@@ -77,4 +84,4 @@ int ti_pinmux_padconf_get(const char *padname, const char **muxmode,<br>
int ti_pinmux_padconf_set_gpiomode(uint32_t gpio, unsigned int state);<br>
int ti_pinmux_padconf_get_gpiomode(uint32_t gpio, unsigned int *state);<br>
<br>
-#endif /* _TI_SCM_H_ */<br>
\ No newline at end of file<br>
+#endif /* _TI_SCM_H_ */<br>
diff --git a/bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c b/bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c<br>
index 44a36a754b..e5cb1801e1 100644<br>
--- a/bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c<br>
+++ b/bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c<br>
@@ -27,9 +27,12 @@<br>
*/<br>
<br>
#include <sys/cdefs.h><br>
+#ifndef __rtems__<br>
__FBSDID("$FreeBSD$");<br>
+#endif /* __rtems__ */<br>
<br>
#include <sys/param.h><br>
+#ifndef __rtems__<br>
#include <sys/systm.h><br>
#include <sys/kernel.h><br>
#include <sys/module.h><br>
@@ -45,6 +48,7 @@ __FBSDID("$FreeBSD$");<br>
#include <sys/gpio.h><br>
<br>
#include <arm/ti/tivar.h><br>
+#endif /* __rtems__ */<br>
#include <arm/ti/ti_pinmux.h><br>
<br>
#include <arm/ti/am335x/am335x_scm_padconf.h><br>
diff --git a/bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c b/bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c<br>
index 7adbcbb365..cec30d2cc5 100644<br>
--- a/bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c<br>
+++ b/bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c<br>
@@ -34,9 +34,12 @@<br>
* Exposes pinmux module to pinctrl-compatible interface<br>
*/<br>
#include <sys/cdefs.h><br>
+#ifndef __rtems__<br>
__FBSDID("$FreeBSD$");<br>
+#endif /* __rtems__ */<br>
<br>
#include <sys/param.h><br>
+#ifndef __rtems__<br>
#include <sys/systm.h><br>
#include <sys/kernel.h><br>
#include <sys/module.h><br>
@@ -55,22 +58,52 @@ __FBSDID("$FreeBSD$");<br>
#include <dev/fdt/fdt_pinctrl.h><br>
<br>
#include <arm/ti/omap4/omap4_scm_padconf.h><br>
+#else /* __rtems__ */<br>
+#include <ofw/ofw_compat.h><br>
+#endif /* __rtems__ */<br>
#include <arm/ti/am335x/am335x_scm_padconf.h><br>
#include <arm/ti/ti_cpuid.h><br>
+#ifndef __rtems__<br>
#include "ti_pinmux.h"<br>
+#else /* __rtems__ */<br>
+#include <stdio.h><br>
+#include <string.h><br>
+#include <errno.h><br>
+#include <libfdt.h><br>
+#include <rtems/bspIo.h><br>
+#include <rtems/sysinit.h><br>
+#include <arm/ti/ti_pinmux.h><br>
+#endif /* __rtems__ */<br>
<br>
struct pincfg {<br>
uint32_t reg;<br>
uint32_t conf;<br>
};<br>
<br>
+#ifndef __rtems__<br>
static struct resource_spec ti_pinmux_res_spec[] = {<br>
{ SYS_RES_MEMORY, 0, RF_ACTIVE }, /* Control memory window */<br>
{ -1, 0 }<br>
};<br>
+#endif /* __rtems__ */<br>
+<br>
+#ifdef __rtems__<br>
+struct ti_pinmux_softc {<br>
+#ifndef __rtems__<br>
+ device_t sc_dev;<br>
+ struct resource * sc_res[4];<br>
+ bus_space_tag_t sc_bst;<br>
+ bus_space_handle_t sc_bsh;<br>
+#else /* __rtems__ */<br>
+ int sc_bst;<br>
+ uintptr_t sc_bsh;<br>
+#endif /* __rtems__ */<br>
+};<br>
+#endif /* __rtems__ */<br>
<br>
static struct ti_pinmux_softc *ti_pinmux_sc;<br>
<br>
+#ifndef __rtems__<br>
#define ti_pinmux_read_2(sc, reg) \<br>
bus_space_read_2((sc)->sc_bst, (sc)->sc_bsh, (reg))<br>
#define ti_pinmux_write_2(sc, reg, val) \<br>
@@ -79,6 +112,19 @@ static struct ti_pinmux_softc *ti_pinmux_sc;<br>
bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))<br>
#define ti_pinmux_write_4(sc, reg, val) \<br>
bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))<br>
+#else /* __rtems__ */<br>
+static uint16_t<br>
+ti_pinmux_read_2(struct ti_pinmux_softc *sc, uintptr_t ofs) {<br>
+ uintptr_t bsh = sc->sc_bsh;<br>
+ return *(uint16_t volatile *)(bsh + ofs);<br>
+}<br>
+static void<br>
+ti_pinmux_write_2(struct ti_pinmux_softc *sc, uintptr_t ofs, uint16_t val) {<br>
+ uintptr_t bsh = sc->sc_bsh;<br>
+ uint16_t volatile *bsp = (uint16_t volatile *)(bsh + ofs);<br>
+ *bsp = val;<br>
+}<br>
+#endif /* __rtems__ */<br>
<br>
<br>
/**<br>
@@ -149,16 +195,22 @@ ti_pinmux_padconf_set_internal(struct ti_pinmux_softc *sc,<br>
<br>
/* couldn't find the mux mode */<br>
if (mode >= 8) {<br>
+#ifndef __rtems__<br>
printf("Invalid mode \"%s\"\n", muxmode);<br>
+#else /* __rtems__ */<br>
+ printk("Invalid mode \"%s\"\n", muxmode);<br>
+#endif /* __rtems__ */<br>
return (EINVAL);<br>
}<br>
<br>
/* set the mux mode */<br>
reg_val |= (uint16_t)(mode & ti_pinmux_dev->padconf_muxmode_mask);<br>
<br>
+#ifndef __rtems__<br>
if (bootverbose)<br>
device_printf(sc->sc_dev, "setting internal %x for %s\n",<br>
reg_val, muxmode);<br>
+#endif /* __rtems__ */<br>
/* write the register value (16-bit writes) */<br>
ti_pinmux_write_2(sc, padconf->reg_off, reg_val);<br>
<br>
@@ -331,14 +383,20 @@ ti_pinmux_padconf_get_gpiomode(uint32_t gpio, unsigned int *state)<br>
}<br>
<br>
static int<br>
+#ifndef __rtems__<br>
ti_pinmux_configure_pins(device_t dev, phandle_t cfgxref)<br>
+#else /* __rtems__ */<br>
+ti_pinmux_configure_pins(struct ti_pinmux_softc *sc, phandle_t cfgxref)<br>
+#endif /* __rtems__ */<br>
{<br>
struct pincfg *cfgtuples, *cfg;<br>
phandle_t cfgnode;<br>
int i, ntuples;<br>
+#ifndef __rtems__<br>
static struct ti_pinmux_softc *sc;<br>
<br>
sc = device_get_softc(dev);<br>
+#endif /* __rtems__ */<br>
cfgnode = OF_node_from_xref(cfgxref);<br>
ntuples = OF_getencprop_alloc_multi(cfgnode, "pinctrl-single,pins",<br>
sizeof(*cfgtuples), (void **)&cfgtuples);<br>
@@ -350,12 +408,14 @@ ti_pinmux_configure_pins(device_t dev, phandle_t cfgxref)<br>
return (0); /* Empty property is not an error. */<br>
<br>
for (i = 0, cfg = cfgtuples; i < ntuples; i++, cfg++) {<br>
+#ifndef __rtems__<br>
if (bootverbose) {<br>
char name[32];<br>
OF_getprop(cfgnode, "name", &name, sizeof(name));<br>
printf("%16s: muxreg 0x%04x muxval 0x%02x\n",<br>
name, cfg->reg, cfg->conf);<br>
}<br>
+#endif /* __rtems__ */<br>
<br>
/* write the register value (16-bit writes) */<br>
ti_pinmux_write_2(sc, cfg->reg, cfg->conf);<br>
@@ -370,6 +430,7 @@ ti_pinmux_configure_pins(device_t dev, phandle_t cfgxref)<br>
* Device part of OMAP SCM driver<br>
*/<br>
<br>
+#ifndef __rtems__<br>
static int<br>
ti_pinmux_probe(device_t dev)<br>
{<br>
@@ -404,7 +465,27 @@ ti_pinmux_probe(device_t dev)<br>
device_set_desc(dev, "TI Pinmux Module");<br>
return (BUS_PROBE_DEFAULT);<br>
}<br>
+#endif /* __rtems__ */<br>
+<br>
+static void<br>
+beagle_pinctrl_configure_children(struct ti_pinmux_softc *sc, phandle_t parent)<br>
+{<br>
+ phandle_t node;<br>
+ int len;<br>
+ uint32_t phandle;<br>
+<br>
+ for (node = OF_child(parent); node != 0; node = OF_peer(node)) {<br>
+ if (rtems_ofw_node_status(node)) {<br>
+ beagle_pinctrl_configure_children(sc, node);<br>
+ len = OF_getencprop(node, "pinctrl-0", &phandle, sizeof(phandle));<br>
+ if (len == sizeof(phandle)) {<br>
+ ti_pinmux_configure_pins(sc, phandle);<br>
+ }<br>
+ }<br>
+ }<br>
+}<br>
<br>
+#ifndef __rtems__<br>
/**<br>
* ti_pinmux_attach - attaches the pinmux to the simplebus<br>
* @dev: new device<br>
@@ -440,7 +521,38 @@ ti_pinmux_attach(device_t dev)<br>
<br>
return (0);<br>
}<br>
+#endif<br>
+<br>
+void<br>
+beagle_pinmux_init(phandle_t node)<br>
+{<br>
+ static struct ti_pinmux_softc pinmux_softc;<br>
+ rtems_ofw_memory_area reg;<br>
+ int rv;<br>
+<br>
+ if (!rtems_ofw_is_node_compatible(node, "pinctrl-single"))<br>
+ return ;<br>
+<br>
+ switch (ti_chip()) {<br>
+ case CHIP_AM335X:<br>
+ ti_pinmux_dev = &ti_am335x_pinmux_dev;<br>
+ break;<br>
+ default:<br>
+ printk("Unknown CPU in pinmux\n");<br>
+ return ;<br>
+ }<br>
+<br>
+ rv = rtems_ofw_get_reg(node, ®, sizeof(reg));<br>
+ if (rv == -1) {<br>
+ printk("pinmux_init: rtems_ofw_get_reg failed %d\n", rv);<br>
+ return ;<br>
+ }<br>
+ pinmux_softc.sc_bsh = reg.start;<br>
+<br>
+ beagle_pinctrl_configure_children(&pinmux_softc, OF_peer(0));<br>
+}<br>
<br>
+#ifndef __rtems__<br>
static device_method_t ti_pinmux_methods[] = {<br>
DEVMETHOD(device_probe, ti_pinmux_probe),<br>
DEVMETHOD(device_attach, ti_pinmux_attach),<br>
@@ -458,4 +570,5 @@ static driver_t ti_pinmux_driver = {<br>
<br>
static devclass_t ti_pinmux_devclass;<br>
<br>
-DRIVER_MODULE(ti_pinmux, simplebus, ti_pinmux_driver, ti_pinmux_devclass, 0, 0);<br>
\ No newline at end of file<br>
+DRIVER_MODULE(ti_pinmux, simplebus, ti_pinmux_driver, ti_pinmux_devclass, 0, 0);<br>
+#endif /* __rtems__ */<br>
diff --git a/spec/build/bsps/obj.yml b/spec/build/bsps/obj.yml<br>
index 6d2bef84d8..906d9aadc0 100644<br>
--- a/spec/build/bsps/obj.yml<br>
+++ b/spec/build/bsps/obj.yml<br>
@@ -60,6 +60,10 @@ install:<br>
source:<br>
- bsps/include/rtems/zilog/z8036.h<br>
- bsps/include/rtems/zilog/z8530.h<br>
+- destination: ${BSP_INCLUDEDIR}/arm/ti<br>
+ source:<br>
+ - bsps/include/arm/ti/ti_pinmux.h<br>
+ - bsps/include/arm/ti/ti_cpuid.h<br>
links:<br>
- role: build-dependency<br>
uid: objmpci<br>
@@ -101,4 +105,6 @@ source:<br>
- bsps/shared/ofw/ofw.c<br>
- bsps/shared/rtems-version.c<br>
- bsps/shared/start/bootcard.c<br>
+- bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c<br>
+- bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c<br>
type: build<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div>