Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor device structures #23407

Merged
merged 8 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion boards/arm/thingy52_nrf52832/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct pwr_ctrl_cfg {

static int pwr_ctrl_init(struct device *dev)
{
const struct pwr_ctrl_cfg *cfg = dev->config->config_info;
const struct pwr_ctrl_cfg *cfg = dev->config_info;
struct device *gpio;

gpio = device_get_binding(cfg->port);
Expand Down
2 changes: 1 addition & 1 deletion doc/guides/dts/howtos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ As shown above, the driver uses additional information from
:file:`devicetree.h` to create :ref:`struct device <device_struct>` instances
than just the node label. Devicetree property values used to configure the
device at boot time are stored in ROM in the value pointed to by a
``device->config->config_info`` field. This allows users to configure your
``device->config_info`` field. This allows users to configure your
driver using overlays.

The Zephyr convention is to name each ``struct device`` using its devicetree
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/drivers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ In the implementation of the common init function:

int my_driver_init(struct device *device)
{
const struct my_driver_config *config = device->config->config_info;
const struct my_driver_config *config = device->config_info;

/* Do other initialization stuff */
...
Expand Down
4 changes: 2 additions & 2 deletions doc/reference/usermode/syscalls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ Several macros exist to validate arguments:
* :c:macro:`Z_SYSCALL_SPECIFIC_DRIVER()` is a runtime check to verify that
pabigot marked this conversation as resolved.
Show resolved Hide resolved
a provided pointer is a valid instance of a specific device driver, that
the calling thread has permissions on it, and that the driver has been
initialized. It does this by checking the init function pointer that
initialized. It does this by checking the API structure pointer that
is stored within the driver instance and ensuring that it matches the
provided value, which should be the address of the specific driver's
init function.
API structure.

If any check fails, the macros will return a nonzero value. The macro
:c:macro:`Z_OOPS()` can be used to induce a kernel oops which will kill the
Expand Down
14 changes: 7 additions & 7 deletions drivers/adc/adc_lmp90xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static inline u8_t lmp90xxx_inst2_sz(size_t len)
static int lmp90xxx_read_reg(struct device *dev, u8_t addr, u8_t *dptr,
size_t len)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;
struct lmp90xxx_data *data = dev->driver_data;
u8_t ura = LMP90XXX_URA(addr);
u8_t inst1_uab[2] = { LMP90XXX_INST1_WAB, ura };
Expand Down Expand Up @@ -249,7 +249,7 @@ static int lmp90xxx_read_reg8(struct device *dev, u8_t addr, u8_t *val)
static int lmp90xxx_write_reg(struct device *dev, u8_t addr, u8_t *dptr,
size_t len)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;
struct lmp90xxx_data *data = dev->driver_data;
u8_t ura = LMP90XXX_URA(addr);
u8_t inst1_uab[2] = { LMP90XXX_INST1_WAB, ura };
Expand Down Expand Up @@ -327,7 +327,7 @@ static int lmp90xxx_soft_reset(struct device *dev)

static inline bool lmp90xxx_has_channel(struct device *dev, u8_t channel)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;

if (channel >= config->channels) {
return false;
Expand All @@ -338,7 +338,7 @@ static inline bool lmp90xxx_has_channel(struct device *dev, u8_t channel)

static inline bool lmp90xxx_has_input(struct device *dev, u8_t input)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;

if (input >= LMP90XXX_MAX_INPUTS) {
return false;
Expand Down Expand Up @@ -496,7 +496,7 @@ static int lmp90xxx_validate_buffer_size(const struct adc_sequence *sequence)
static int lmp90xxx_adc_start_read(struct device *dev,
const struct adc_sequence *sequence)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;
struct lmp90xxx_data *data = dev->driver_data;
int err;

Expand Down Expand Up @@ -569,7 +569,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx,
static int lmp90xxx_adc_read_channel(struct device *dev, u8_t channel,
s32_t *result)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;
struct lmp90xxx_data *data = dev->driver_data;
u8_t adc_done;
u8_t ch_scan;
Expand Down Expand Up @@ -913,7 +913,7 @@ int lmp90xxx_gpio_port_toggle_bits(struct device *dev, gpio_port_pins_t pins)

static int lmp90xxx_init(struct device *dev)
{
const struct lmp90xxx_config *config = dev->config->config_info;
const struct lmp90xxx_config *config = dev->config_info;
struct lmp90xxx_data *data = dev->driver_data;
struct device *drdyb_dev;
int err;
Expand Down
10 changes: 5 additions & 5 deletions drivers/adc/adc_mcp320x.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct mcp320x_data {
static int mcp320x_channel_setup(struct device *dev,
const struct adc_channel_cfg *channel_cfg)
{
const struct mcp320x_config *config = dev->config->config_info;
const struct mcp320x_config *config = dev->config_info;
struct mcp320x_data *data = dev->driver_data;

if (channel_cfg->gain != ADC_GAIN_1) {
Expand Down Expand Up @@ -85,7 +85,7 @@ static int mcp320x_channel_setup(struct device *dev,
static int mcp320x_validate_buffer_size(struct device *dev,
const struct adc_sequence *sequence)
{
const struct mcp320x_config *config = dev->config->config_info;
const struct mcp320x_config *config = dev->config_info;
u8_t channels = 0;
size_t needed;
u32_t mask;
Expand All @@ -111,7 +111,7 @@ static int mcp320x_validate_buffer_size(struct device *dev,
static int mcp320x_start_read(struct device *dev,
const struct adc_sequence *sequence)
{
const struct mcp320x_config *config = dev->config->config_info;
const struct mcp320x_config *config = dev->config_info;
struct mcp320x_data *data = dev->driver_data;
int err;

Expand Down Expand Up @@ -180,7 +180,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx,

static int mcp320x_read_channel(struct device *dev, u8_t channel, u16_t *result)
{
const struct mcp320x_config *config = dev->config->config_info;
const struct mcp320x_config *config = dev->config_info;
struct mcp320x_data *data = dev->driver_data;
u8_t tx_bytes[2];
u8_t rx_bytes[2];
Expand Down Expand Up @@ -272,7 +272,7 @@ static void mcp320x_acquisition_thread(struct device *dev)

static int mcp320x_init(struct device *dev)
{
const struct mcp320x_config *config = dev->config->config_info;
const struct mcp320x_config *config = dev->config_info;
struct mcp320x_data *data = dev->driver_data;

k_sem_init(&data->sem, 0, 1);
Expand Down
8 changes: 4 additions & 4 deletions drivers/adc/adc_mcux_adc12.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int mcux_adc12_channel_setup(struct device *dev,
static int mcux_adc12_start_read(struct device *dev,
const struct adc_sequence *sequence)
{
const struct mcux_adc12_config *config = dev->config->config_info;
const struct mcux_adc12_config *config = dev->config_info;
struct mcux_adc12_data *data = dev->driver_data;
adc12_hardware_average_mode_t mode;
adc12_resolution_t resolution;
Expand Down Expand Up @@ -152,7 +152,7 @@ static int mcux_adc12_read(struct device *dev,

static void mcux_adc12_start_channel(struct device *dev)
{
const struct mcux_adc12_config *config = dev->config->config_info;
const struct mcux_adc12_config *config = dev->config_info;
struct mcux_adc12_data *data = dev->driver_data;

adc12_channel_config_t channel_config;
Expand Down Expand Up @@ -191,7 +191,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx,
static void mcux_adc12_isr(void *arg)
{
struct device *dev = (struct device *)arg;
const struct mcux_adc12_config *config = dev->config->config_info;
const struct mcux_adc12_config *config = dev->config_info;
struct mcux_adc12_data *data = dev->driver_data;
ADC_Type *base = config->base;
u32_t channel_group = 0U;
Expand All @@ -213,7 +213,7 @@ static void mcux_adc12_isr(void *arg)

static int mcux_adc12_init(struct device *dev)
{
const struct mcux_adc12_config *config = dev->config->config_info;
const struct mcux_adc12_config *config = dev->config_info;
struct mcux_adc12_data *data = dev->driver_data;
ADC_Type *base = config->base;
adc12_config_t adc_config;
Expand Down
8 changes: 4 additions & 4 deletions drivers/adc/adc_mcux_adc16.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int mcux_adc16_channel_setup(struct device *dev,

static int start_read(struct device *dev, const struct adc_sequence *sequence)
{
const struct mcux_adc16_config *config = dev->config->config_info;
const struct mcux_adc16_config *config = dev->config_info;
struct mcux_adc16_data *data = dev->driver_data;
adc16_hardware_average_mode_t mode;
adc16_resolution_t resolution;
Expand Down Expand Up @@ -162,7 +162,7 @@ static int mcux_adc16_read_async(struct device *dev,

static void mcux_adc16_start_channel(struct device *dev)
{
const struct mcux_adc16_config *config = dev->config->config_info;
const struct mcux_adc16_config *config = dev->config_info;
struct mcux_adc16_data *data = dev->driver_data;

adc16_channel_config_t channel_config;
Expand Down Expand Up @@ -205,7 +205,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx,
static void mcux_adc16_isr(void *arg)
{
struct device *dev = (struct device *)arg;
const struct mcux_adc16_config *config = dev->config->config_info;
const struct mcux_adc16_config *config = dev->config_info;
struct mcux_adc16_data *data = dev->driver_data;
ADC_Type *base = config->base;
u32_t channel_group = 0U;
Expand All @@ -227,7 +227,7 @@ static void mcux_adc16_isr(void *arg)

static int mcux_adc16_init(struct device *dev)
{
const struct mcux_adc16_config *config = dev->config->config_info;
const struct mcux_adc16_config *config = dev->config_info;
struct mcux_adc16_data *data = dev->driver_data;
ADC_Type *base = config->base;
adc16_config_t adc_config;
Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_nrfx_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static int init_adc(struct device *dev)

if (result != NRFX_SUCCESS) {
LOG_ERR("Failed to initialize device: %s",
dev->config->name);
dev->name);
return -EBUSY;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_sam0.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct adc_sam0_cfg {
};

#define DEV_CFG(dev) \
((const struct adc_sam0_cfg *const)(dev)->config->config_info)
((const struct adc_sam0_cfg *const)(dev)->config_info)
#define DEV_DATA(dev) \
((struct adc_sam0_data *)(dev)->driver_data)

Expand Down
2 changes: 1 addition & 1 deletion drivers/adc/adc_sam_afec.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct adc_sam_cfg {
};

#define DEV_CFG(dev) \
((const struct adc_sam_cfg *const)(dev)->config->config_info)
((const struct adc_sam_cfg *const)(dev)->config_info)

#define DEV_DATA(dev) \
((struct adc_sam_data *)(dev)->driver_data)
Expand Down
12 changes: 6 additions & 6 deletions drivers/adc/adc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static int check_buffer_size(const struct adc_sequence *sequence,

static void adc_stm32_start_conversion(struct device *dev)
{
const struct adc_stm32_cfg *config = dev->config->config_info;
const struct adc_stm32_cfg *config = dev->config_info;
ADC_TypeDef *adc = (ADC_TypeDef *)config->base;

LOG_DBG("Starting conversion");
Expand All @@ -265,7 +265,7 @@ static void adc_stm32_start_conversion(struct device *dev)

static int start_read(struct device *dev, const struct adc_sequence *sequence)
{
const struct adc_stm32_cfg *config = dev->config->config_info;
const struct adc_stm32_cfg *config = dev->config_info;
struct adc_stm32_data *data = dev->driver_data;
ADC_TypeDef *adc = (ADC_TypeDef *)config->base;
u8_t resolution;
Expand Down Expand Up @@ -390,7 +390,7 @@ static void adc_stm32_isr(void *arg)
struct device *dev = (struct device *)arg;
struct adc_stm32_data *data = (struct adc_stm32_data *)dev->driver_data;
struct adc_stm32_cfg *config =
(struct adc_stm32_cfg *)dev->config->config_info;
(struct adc_stm32_cfg *)dev->config_info;
ADC_TypeDef *adc = config->base;

*data->buffer++ = LL_ADC_REG_ReadConversionData32(adc);
Expand Down Expand Up @@ -450,7 +450,7 @@ static void adc_stm32_setup_speed(struct device *dev, u8_t id,
u8_t acq_time_index)
{
struct adc_stm32_cfg *config =
(struct adc_stm32_cfg *)dev->config->config_info;
(struct adc_stm32_cfg *)dev->config_info;
ADC_TypeDef *adc = config->base;

#if defined(CONFIG_SOC_SERIES_STM32F0X) || defined(CONFIG_SOC_SERIES_STM32L0X)
Expand Down Expand Up @@ -523,7 +523,7 @@ static int adc_stm32_channel_setup(struct device *dev,
static void adc_stm32_calib(struct device *dev)
{
struct adc_stm32_cfg *config =
(struct adc_stm32_cfg *)dev->config->config_info;
(struct adc_stm32_cfg *)dev->config_info;
ADC_TypeDef *adc = config->base;

#if defined(CONFIG_SOC_SERIES_STM32F3X) || \
Expand All @@ -545,7 +545,7 @@ static void adc_stm32_calib(struct device *dev)
static int adc_stm32_init(struct device *dev)
{
struct adc_stm32_data *data = dev->driver_data;
const struct adc_stm32_cfg *config = dev->config->config_info;
const struct adc_stm32_cfg *config = dev->config_info;
struct device *clk =
device_get_binding(STM32_CLOCK_CONTROL_NAME);
ADC_TypeDef *adc = (ADC_TypeDef *)config->base;
Expand Down
2 changes: 1 addition & 1 deletion drivers/audio/intel_dmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ static int dmic_initialize_device(struct device *dev)
/* Set state, note there is no playback direction support */
dmic_private.state = DMIC_STATE_INITIALIZED;

LOG_DBG("Device %s Initialized", dev->config->name);
LOG_DBG("Device %s Initialized", dev->name);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/audio/mpxxdtyy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
#define MPXXDTYY_MAX_PDM_FREQ 3250000 /* 3.25MHz */

#define DEV_CFG(dev) \
((struct mpxxdtyy_config *const)(dev)->config->config_info)
((struct mpxxdtyy_config *const)(dev)->config_info)
#define DEV_DATA(dev) \
((struct mpxxdtyy_data *const)(dev)->driver_data)

Expand Down
2 changes: 1 addition & 1 deletion drivers/audio/tlv320dac310x.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static struct codec_driver_config codec_device_config = {
static struct codec_driver_data codec_device_data;

#define DEV_CFG(dev) \
((struct codec_driver_config *const)(dev)->config->config_info)
((struct codec_driver_config *const)(dev)->config_info)
#define DEV_DATA(dev) \
((struct codec_driver_data *const)(dev)->driver_data)

Expand Down
7 changes: 4 additions & 3 deletions drivers/can/can_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int can_loopback_send(struct device *dev, const struct zcan_frame *frame,
struct k_sem tx_sem;

LOG_DBG("Sending %d bytes on %s. Id: 0x%x, ID type: %s %s",
frame->dlc, dev->config->name,
frame->dlc, dev->name,
frame->id_type == CAN_STANDARD_IDENTIFIER ?
frame->std_id : frame->ext_id,
frame->id_type == CAN_STANDARD_IDENTIFIER ?
Expand Down Expand Up @@ -267,7 +267,8 @@ static int can_loopback_init(struct device *dev)
return -1;
}

LOG_INF("Init of %s done", dev->config->name);
LOG_INF("Init of %s done", dev->name);

return 0;
}

Expand All @@ -290,7 +291,7 @@ static int socket_can_init_1(struct device *dev)
struct socket_can_context *socket_context = dev->driver_data;

LOG_DBG("Init socket CAN device %p (%s) for dev %p (%s)",
dev, dev->config->name, can_dev, can_dev->config->name);
dev, dev->name, can_dev, can_dev->name);

socket_context->can_dev = can_dev;
socket_context->msgq = &socket_can_msgq;
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_loopback.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define DEV_DATA(dev) ((struct can_loopback_data *const)(dev)->driver_data)
#define DEV_CFG(dev) \
((const struct can_loopback_config *const)(dev)->config->config_info)
((const struct can_loopback_config *const)(dev)->config_info)

struct can_loopback_filter {
can_rx_callback_t rx_cb;
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcp2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define MCP2515_FRAME_LEN 13

#define DEV_CFG(dev) \
((const struct mcp2515_config *const)(dev)->config->config_info)
((const struct mcp2515_config *const)(dev)->config_info)
#define DEV_DATA(dev) ((struct mcp2515_data *const)(dev)->driver_data)

struct mcp2515_tx_cb {
Expand Down
Loading