Skip to content

Commit

Permalink
subsys: greybus: remove deferred init
Browse files Browse the repository at this point in the history
Fixes #12
Changes as per discussion in  https://github.com/cfriedt/zephyr/pull/5

Currently priorities are assigned in the following manner:

CONFIG_GREYBUS_SERVICE_PRIORITY N-5
CONFIG_GREYBUS_STRING_PRIORITY N-4
CONFIG_GREYBUS_INTERFACE_PRIORITY N-3
CONFIG_GREYBUS_BUNDLE_PRIORITY N-2
CONFIG_GREYBUS_CPORT_PRIORITY N-1

where N = CONFIG_APPLICATION_INIT_PRIORITY

Tested GPIO, I2C and SPI on CC1352R SensorTag

Signed-off-by: Vaishnav M A <vaishnav@beagleboard.org>
  • Loading branch information
vaishnavachath authored and cfriedt committed Dec 29, 2020
1 parent 16853aa commit 1665cb4
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 167 deletions.
7 changes: 0 additions & 7 deletions samples/subsys/greybus/net/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
#include <stdio.h>
#include <zephyr.h>

struct device;
extern int greybus_service_init(struct device *bus);

void main(void)
{
int r = greybus_service_init(NULL);
if (r < 0) {
printf("gb_service_deferred_init() failed: %d\n", r);
}
}
7 changes: 0 additions & 7 deletions samples/subsys/greybus/uart/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
#include <stdio.h>
#include <zephyr.h>

struct device;
extern int greybus_service_init(struct device *bus);

void main(void)
{
int r = greybus_service_init(NULL);
if (r < 0) {
printf("gb_service_deferred_init() failed: %d\n", r);
}
}
1 change: 0 additions & 1 deletion subsys/greybus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ zephyr_library_sources(

platform/manifest.c
platform/platform.c
platform/deferred-init.c

platform/service.c

Expand Down
35 changes: 35 additions & 0 deletions subsys/greybus/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,41 @@ config GREYBUS_VIBRATOR
help
Select this for Greybus Vibrator support.

config GREYBUS_SERVICE_INIT_PRIORITY
int "default Greybus Service Init Priority"
default 85
range 0 99
help
Greybus service init priority to ensure device initialization order.

config GREYBUS_STRING_INIT_PRIORITY
int "default Greybus String Init Priority"
default 86
range 0 99
help
Greybus string init priority to ensure device initialization order.

config GREYBUS_INTERFACE_INIT_PRIORITY
int "default Greybus Interface Init Priority"
default 87
range 0 99
help
Greybus interface init priority to ensure device initialization order.

config GREYBUS_BUNDLE_INIT_PRIORITY
int "default Greybus Bundle Init Priority"
default 88
range 0 99
help
Greybus bundle init priority to ensure device initialization order.

config GREYBUS_CPORT_INIT_PRIORITY
int "default Greybus Cport Init Priority"
default 89
range 0 99
help
Greybus cport init priority to ensure device initialization order.

module = GREYBUS
module-str = gb
source "subsys/logging/Kconfig.template.log_config"
Expand Down
9 changes: 2 additions & 7 deletions subsys/greybus/platform/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ static int greybus_bundle_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_bundle_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_bundle_init);
}

#define DEFINE_GREYBUS_BUNDLE(_num) \
\
static const struct greybus_bundle_config \
Expand All @@ -54,10 +49,10 @@ static int defer_greybus_bundle_init(const struct device *dev) {
}; \
\
DEVICE_DT_INST_DEFINE(_num, \
defer_greybus_bundle_init, \
greybus_bundle_init, \
NULL, NULL, \
&greybus_bundle_config_##_num, \
POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL);
CONFIG_GREYBUS_BUNDLE_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_BUNDLE);
2 changes: 1 addition & 1 deletion subsys/greybus/platform/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int greybus_init(const struct device *bus) {
DEVICE_DT_INST_DEFINE(_num, \
greybus_init, NULL, NULL, \
&greybus_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
CONFIG_GREYBUS_SERVICE_INIT_PRIORITY, \
NULL);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS);
9 changes: 2 additions & 7 deletions subsys/greybus/platform/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ static int greybus_control_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_control_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_control_init);
}

#define DEFINE_GREYBUS_CONTROL(_num) \
\
BUILD_ASSERT(DT_PROP(DT_PARENT(DT_DRV_INST(_num)), bundle_class) \
Expand All @@ -60,9 +55,9 @@ static int defer_greybus_control_init(const struct device *dev) {
}; \
\
DEVICE_DT_INST_DEFINE(_num, \
defer_greybus_control_init, \
greybus_control_init, \
NULL, NULL, \
&greybus_control_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL);
CONFIG_GREYBUS_CPORT_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_CONTROL);
88 changes: 0 additions & 88 deletions subsys/greybus/platform/deferred-init.c

This file was deleted.

9 changes: 2 additions & 7 deletions subsys/greybus/platform/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ static int greybus_gpio_control_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_gpio_control_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_gpio_control_init);
}

#define DEFINE_GREYBUS_GPIO_CONTROL(_num) \
\
BUILD_ASSERT(DT_PROP(DT_PARENT(DT_DRV_INST(_num)), bundle_class) \
Expand All @@ -158,9 +153,9 @@ static int defer_greybus_gpio_control_init(const struct device *dev) {
greybus_gpio_control_data_##_num; \
\
DEVICE_DT_INST_DEFINE(_num, \
defer_greybus_gpio_control_init, NULL, \
greybus_gpio_control_init, NULL, \
&greybus_gpio_control_data_##_num, \
&greybus_gpio_control_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL);
CONFIG_GREYBUS_CPORT_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_GPIO_CONTROL);
9 changes: 2 additions & 7 deletions subsys/greybus/platform/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ static int greybus_i2c_control_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_i2c_control_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_i2c_control_init);
}

#define DEFINE_GREYBUS_I2C_CONTROL(_num) \
\
BUILD_ASSERT(DT_PROP(DT_PARENT(DT_DRV_INST(_num)), bundle_class) \
Expand All @@ -95,9 +90,9 @@ static int defer_greybus_i2c_control_init(const struct device *dev) {
greybus_i2c_control_data_##_num; \
\
DEVICE_INIT(i2c_i2c_control_##_num, "GBI2C_" #_num, \
defer_greybus_i2c_control_init, \
greybus_i2c_control_init, \
&greybus_i2c_control_data_##_num, \
&greybus_i2c_control_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
CONFIG_GREYBUS_CPORT_INIT_PRIORITY);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_I2C_CONTROL);
10 changes: 2 additions & 8 deletions subsys/greybus/platform/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ static int greybus_interface_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_interface_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_interface_init);
}


#define DEFINE_GREYBUS_INTERFACE(_num) \
\
static const struct greybus_interface_config \
Expand All @@ -61,9 +55,9 @@ static int defer_greybus_interface_init(const struct device *dev) {
}; \
\
DEVICE_DT_INST_DEFINE(_num, \
defer_greybus_interface_init, \
greybus_interface_init, \
NULL, NULL, \
&greybus_interface_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL);
CONFIG_GREYBUS_INTERFACE_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_INTERFACE);
20 changes: 10 additions & 10 deletions subsys/greybus/platform/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ gb_transport_get_backend(void)
return xport;
}

int greybus_service_init(const struct device *bus)
static int greybus_service_init(const struct device *bus)
{
int r;
int r;
uint8_t *mnfb;
size_t mnfb_size;
unsigned int *cports = NULL;
unsigned int *cports = NULL;

LOG_DBG("Greybus initializing..");

r = gb_service_deferred_init();
if (r < 0) {
LOG_ERR("gb_service_deferred_init() failed: %d", r);
goto out;
if (xport != NULL) {
LOG_ERR("service already initialized");
return -EALREADY;
}

LOG_DBG("Greybus initializing..");

bus = device_get_binding(GREYBUS_BUS_NAME);
if (NULL == bus) {
r = -ENODEV;
LOG_ERR("failed to get " GREYBUS_BUS_NAME " device");
goto out;
}
Expand Down Expand Up @@ -114,4 +114,4 @@ int greybus_service_init(const struct device *bus)
return r;
}

//SYS_INIT(greybus_service_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);
SYS_INIT(greybus_service_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
9 changes: 2 additions & 7 deletions subsys/greybus/platform/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ static int greybus_spi_control_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_spi_control_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_spi_control_init);
}

static int gb_plat_api_controller_config_response(const struct device *dev, struct gb_spi_master_config_response *rsp)
{
if (dev == NULL || NULL == rsp) {
Expand Down Expand Up @@ -329,10 +324,10 @@ static const struct gb_platform_spi_api gb_platform_spi_api = {
greybus_spi_control_data_##_num; \
\
DEVICE_DT_INST_DEFINE(_num, \
defer_greybus_spi_control_init, \
greybus_spi_control_init, \
NULL, &greybus_spi_control_data_##_num, \
&greybus_spi_control_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
CONFIG_GREYBUS_CPORT_INIT_PRIORITY, \
&gb_platform_spi_api);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_SPI_CONTROL);
9 changes: 2 additions & 7 deletions subsys/greybus/platform/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ static int greybus_string_init(const struct device *dev) {
return 0;
}

extern int gb_service_defer_init(const struct device *, int (*init)(const struct device *));
static int defer_greybus_string_init(const struct device *dev) {
return gb_service_defer_init(dev, &greybus_string_init);
}

#define DEFINE_GREYBUS_STRING(_num) \
\
static const struct greybus_string_config \
Expand All @@ -51,8 +46,8 @@ static int defer_greybus_string_init(const struct device *dev) {
}; \
\
DEVICE_DT_INST_DEFINE(_num, \
defer_greybus_string_init, NULL, NULL, \
greybus_string_init, NULL, NULL, \
&greybus_string_config_##_num, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL);
CONFIG_GREYBUS_STRING_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_GREYBUS_STRING);
3 changes: 0 additions & 3 deletions tests/subsys/greybus/gpio/src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ void test_greybus_setup(void) {

*port = htons(PORT);

extern int greybus_service_init(const struct device *);
greybus_service_init(NULL);

gpio_dev = (struct device *)device_get_binding(GPIO_DEV_NAME);
zassert_not_equal(gpio_dev, NULL, "failed to get device binding for " GPIO_DEV_NAME);

Expand Down

0 comments on commit 1665cb4

Please sign in to comment.