summaryrefslogtreecommitdiffstats
path: root/bsps/arm/beagle/start/bspstart.c
diff options
context:
space:
mode:
authorG S Niteesh Babu <niteesh.gs@gmail.com>2021-04-11 00:45:27 +0530
committerChristian Mauderer <oss@c-mauderer.de>2021-04-22 18:43:35 +0200
commitd75b29d95e71f04a71e375750c1a02b3bacd533f (patch)
tree8de04e2f1d63559badc3410acd84b4f814396585 /bsps/arm/beagle/start/bspstart.c
parentrtems: Mention timer server fire directives (diff)
downloadrtems-d75b29d95e71f04a71e375750c1a02b3bacd533f.tar.bz2
bsps/beagle: Refactored i2c driver
Refactored the i2c driver to parse register values from the device tree rather than hardcoding them. But still the clocks have to initialized manually.
Diffstat (limited to 'bsps/arm/beagle/start/bspstart.c')
-rw-r--r--bsps/arm/beagle/start/bspstart.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/bsps/arm/beagle/start/bspstart.c b/bsps/arm/beagle/start/bspstart.c
index a0736294c9..cb488626f1 100644
--- a/bsps/arm/beagle/start/bspstart.c
+++ b/bsps/arm/beagle/start/bspstart.c
@@ -22,6 +22,10 @@
#include "bsp-soc-detect.h"
#include <arm/ti/ti_pinmux.h>
#include <ofw/ofw.h>
+#include <bsp/i2c.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
#include "bspdebug.h"
@@ -70,6 +74,7 @@ static void traverse_fdt_nodes( phandle_t node )
* Put all driver initialization functions here
*/
beagle_pinmux_init(node);
+ beagle_i2c_init(node);
}
}
@@ -80,24 +85,40 @@ static void bbb_drivers_initialize(void)
traverse_fdt_nodes(node);
}
-static void bbb_i2c_0_initialize(void)
+int beagle_get_node_unit(phandle_t node)
{
- int err;
-
- err = am335x_i2c_bus_register(BBB_I2C_0_BUS_PATH,
- AM335X_I2C0_BASE,
- I2C_BUS_CLOCK_DEFAULT,
- BBB_I2C0_IRQ);
- if (err != 0) {
- printk("rtems i2c-0: Device could not be registered (%d)", err);
+ char name[30];
+ char prop[30];
+ char prop_val[30];
+ static int unit;
+ phandle_t aliases;
+ int rv;
+ int i;
+
+ rv = rtems_ofw_get_prop(node, "name", name, sizeof(name));
+ if (rv <= 0)
+ return unit++;
+
+ aliases = rtems_ofw_find_device("/aliases");
+
+ rv = rtems_ofw_next_prop(aliases, NULL, &prop[0], sizeof(prop));
+
+ while (rv > 0) {
+ rv = rtems_ofw_get_prop(aliases, prop, prop_val, sizeof(prop_val));
+
+ if (strstr(prop_val, name) != NULL) {
+ for (i = strlen(prop) - 1; i >= 0; i--) {
+ if (!isdigit(prop[i]))
+ break;
+ }
+
+ return strtol(&prop[i + 1], NULL, 10);
+ }
+ rv = rtems_ofw_next_prop(aliases, prop, prop, sizeof(prop));
}
-}
-RTEMS_SYSINIT_ITEM(
- bbb_i2c_0_initialize,
- RTEMS_SYSINIT_LAST,
- RTEMS_SYSINIT_ORDER_LAST_BUT_5
-);
+ return unit++;
+}
RTEMS_SYSINIT_ITEM(
bbb_drivers_initialize,