Bridle API 4.1.99
A Zephyr based application framework
Loading...
Searching...
No Matches
mfd_sc16is75x.c File Reference

MFD Driver for an SC16IS75X bridge. More...

#include <zephyr/kernel.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio/gpio_utils.h>
#include <zephyr/drivers/mfd/sc16is75x.h>
#include "mfd_sc16is75x.h"
#include "zephyr/sys/util_macro.h"
#include <zephyr/logging/log.h>

Macros

#define SC16IS75X_SA_RD   true
 
#define SC16IS75X_SA_WR   false
 
#define READ_SC16IS75X_CHANNEL(dev, ch, reg, buf, len)    mfd_sc16is75x_read((dev), (ch), SC16IS75X_REG_##reg, (buf), (len));
 
#define WRITE_SC16IS75X_CHANNEL(dev, ch, reg, buf, len)    mfd_sc16is75x_write((dev), (ch), SC16IS75X_REG_##reg, (buf), (len));
 
#define MFD_SC16IS75X_CHILD_CHANNEL(child)
 For a given child node, if it's a UART controller: return the channel id (reg property), with a comma.
 
#define MFD_SC16IS75X_UART_CHANNELS(inst)    {DT_INST_FOREACH_CHILD_STATUS_OKAY(inst, MFD_SC16IS75X_CHILD_CHANNEL)}
 Construct a bracketed list of all child UART controllers' channel id (== reg property)
 
#define MFD_SC16IS75X_DEFINE_SPI_BUS(inst)
 Construct struct initializer entries for an SPI bus configuration.
 
#define MFD_SC16IS75X_DEFINE_I2C_BUS(inst)    .i2c = I2C_DT_SPEC_INST_GET(inst), .bus_init = mfd_sc16is75x_i2c_init
 Construct struct initializer entries for an I2C bus configuration.
 
#define MFD_SC16IS75X_DEFINE_BUS(inst)
 Return one of the two bus initializer lists above, selecting the correct bus based on the devicetree.
 
#define MFD_SC16IS75X_DEFINE(inst)
 Initializer macro for a device driver instance.
 

Functions

 LOG_MODULE_REGISTER (mfd_sc16is75x, CONFIG_MFD_LOG_LEVEL)
 
static int mfd_sc16is75x_sub_address (const bool read, const uint8_t reg, const uint8_t channel, uint8_t *sub_address)
 
static int mfd_sc16is75x_read (const struct device *dev, const uint8_t channel, const uint8_t reg, uint8_t *buf, const size_t len)
 
static int mfd_sc16is75x_write (const struct device *dev, const uint8_t channel, const uint8_t reg, const uint8_t *buf, const size_t len)
 
int mfd_sc16is75x_read_register (const struct device *dev, const uint8_t channel, const uint8_t reg, uint8_t *value)
 Read from an internal register.
 
int mfd_sc16is75x_write_register (const struct device *dev, const uint8_t channel, const uint8_t reg, const uint8_t value)
 Write to an internal register.
 
int mfd_sc16is75x_set_register_bit (const struct device *dev, const uint8_t channel, const uint8_t reg, const uint8_t bit, const bool value)
 Enable or disable a bit in an internal register.
 
int mfd_sc16is75x_read_fifo (const struct device *dev, const uint8_t channel, uint8_t *buf, const size_t len)
 Read data from FIFO.
 
int mfd_sc16is75x_write_fifo (const struct device *dev, const uint8_t channel, const uint8_t *buf, const size_t len)
 Write data to FIFO.
 
static int mfd_sc16is75x_chip_reset (const struct device *dev)
 Reset device.
 
static int mfd_sc16is75x_configure_gpio_pin (const struct device *dev, const struct gpio_dt_spec *gpio, const gpio_flags_t flags)
 Set up GPIO pin.
 
static int mfd_sc16is75x_sw_reset (const struct device *dev)
 
static int mfd_sc16is75x_pm_device_pm_action (const struct device *dev, enum pm_device_action action)
 
static int mfd_sc16is75x_init (const struct device *dev)
 
 DT_INST_FOREACH_STATUS_OKAY (MFD_SC16IS75X_DEFINE)
 

Detailed Description

MFD Driver for an SC16IS75X bridge.

Macro Definition Documentation

◆ MFD_SC16IS75X_CHILD_CHANNEL

#define MFD_SC16IS75X_CHILD_CHANNEL (   child)
Value:
COND_CODE_1(DT_NODE_HAS_COMPAT(child, nxp_sc16is75x_uart), \
(DT_PROP_BY_IDX(child, reg, 0),), \
() \
)

For a given child node, if it's a UART controller: return the channel id (reg property), with a comma.

If the child is not a UART controller, return nothing.

Note that since the property is technically an array, we take the 0th entry to avoid extra braces.

◆ MFD_SC16IS75X_DEFINE

#define MFD_SC16IS75X_DEFINE (   inst)
Value:
\
static uint8_t mfd_sc16is75x_uart_channels_##inst[] = MFD_SC16IS75X_UART_CHANNELS(inst); \
\
IF_ENABLED(CONFIG_MFD_SC16IS75X_ASWQ, \
(K_THREAD_STACK_DEFINE(mfd_sc16is75x_wq_thread_stack_##inst,\
CONFIG_MFD_SC16IS75X_WORKQUEUE_STACK_SIZE))); \
\
static struct mfd_sc16is75x_config mfd_sc16is75x_config_##inst = { \
MFD_SC16IS75X_DEFINE_BUS(inst), \
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
.n_channels = ARRAY_SIZE(mfd_sc16is75x_uart_channels_##inst), \
.channels = MFD_SC16IS75X_UART_CHANNELS(inst), \
IF_ENABLED(CONFIG_MFD_SC16IS75X_INTERRUPTS, \
(.interrupt = GPIO_DT_SPEC_INST_GET(inst, \
interrupt_gpios),)) }; \
\
static struct mfd_sc16is75x_data mfd_sc16is75x_data_##inst = { \
IF_ENABLED(CONFIG_MFD_SC16IS75X_ASWQ, \
(.work_queue_stack \
= mfd_sc16is75x_wq_thread_stack_##inst,)) }; \
\
PM_DEVICE_DT_INST_DEFINE(inst, mfd_sc16is75x_pm_device_pm_action); \
\
DEVICE_DT_INST_DEFINE(inst, mfd_sc16is75x_init, PM_DEVICE_DT_INST_GET(inst), \
&mfd_sc16is75x_data_##inst, &mfd_sc16is75x_config_##inst, \
POST_KERNEL, CONFIG_MFD_SC16IS75X_INIT_PRIORITY, NULL);
static int mfd_sc16is75x_init(const struct device *dev)
Definition mfd_sc16is75x.c:450
#define MFD_SC16IS75X_UART_CHANNELS(inst)
Construct a bracketed list of all child UART controllers' channel id (== reg property)
Definition mfd_sc16is75x.c:538
static int mfd_sc16is75x_pm_device_pm_action(const struct device *dev, enum pm_device_action action)
Definition mfd_sc16is75x.c:442
SC16IS75X MFD configuration data.
Definition mfd_sc16is75x.h:43
struct gpio_dt_spec reset
GPIO pin for chip reset.
Definition mfd_sc16is75x.h:53
uint8_t n_channels
Number of UART channels provided by this device.
Definition mfd_sc16is75x.h:55
SC16IS75X MFD data.
Definition mfd_sc16is75x.h:102

Initializer macro for a device driver instance.

In order to count the number of channels, we create an instance of the channels list. Unfortunately, GCC doesn't like us using this same instance for initialization, so we have to invoke the list construction macro again to get a naked initializer list later.

◆ MFD_SC16IS75X_DEFINE_BUS

#define MFD_SC16IS75X_DEFINE_BUS (   inst)
Value:
COND_CODE_1(DT_INST_ON_BUS(inst, spi), \
#define MFD_SC16IS75X_DEFINE_SPI_BUS(inst)
Construct struct initializer entries for an SPI bus configuration.
Definition mfd_sc16is75x.c:544
#define MFD_SC16IS75X_DEFINE_I2C_BUS(inst)
Construct struct initializer entries for an I2C bus configuration.
Definition mfd_sc16is75x.c:551

Return one of the two bus initializer lists above, selecting the correct bus based on the devicetree.

◆ MFD_SC16IS75X_DEFINE_I2C_BUS

#define MFD_SC16IS75X_DEFINE_I2C_BUS (   inst)     .i2c = I2C_DT_SPEC_INST_GET(inst), .bus_init = mfd_sc16is75x_i2c_init

Construct struct initializer entries for an I2C bus configuration.

◆ MFD_SC16IS75X_DEFINE_SPI_BUS

#define MFD_SC16IS75X_DEFINE_SPI_BUS (   inst)
Value:
.spi = SPI_DT_SPEC_INST_GET(inst, SPI_OP_MODE_MASTER | SPI_WORD_SET(8), 0), \
int mfd_sc16is75x_spi_init(const struct device *dev)
Definition mfd_sc16is75x_spi.c:177

Construct struct initializer entries for an SPI bus configuration.

◆ MFD_SC16IS75X_UART_CHANNELS

#define MFD_SC16IS75X_UART_CHANNELS (   inst)     {DT_INST_FOREACH_CHILD_STATUS_OKAY(inst, MFD_SC16IS75X_CHILD_CHANNEL)}

Construct a bracketed list of all child UART controllers' channel id (== reg property)

◆ READ_SC16IS75X_CHANNEL

#define READ_SC16IS75X_CHANNEL (   dev,
  ch,
  reg,
  buf,
  len 
)     mfd_sc16is75x_read((dev), (ch), SC16IS75X_REG_##reg, (buf), (len));

◆ SC16IS75X_SA_RD

#define SC16IS75X_SA_RD   true

◆ SC16IS75X_SA_WR

#define SC16IS75X_SA_WR   false

◆ WRITE_SC16IS75X_CHANNEL

#define WRITE_SC16IS75X_CHANNEL (   dev,
  ch,
  reg,
  buf,
  len 
)     mfd_sc16is75x_write((dev), (ch), SC16IS75X_REG_##reg, (buf), (len));

Function Documentation

◆ DT_INST_FOREACH_STATUS_OKAY()

DT_INST_FOREACH_STATUS_OKAY ( MFD_SC16IS75X_DEFINE  )

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( mfd_sc16is75x  ,
CONFIG_MFD_LOG_LEVEL   
)

◆ mfd_sc16is75x_chip_reset()

static int mfd_sc16is75x_chip_reset ( const struct device *  dev)
static

Reset device.

Parameters
devAn SC16IS75X MFD device.
Return values
0On success.
Returns
Negative error code on failure.

◆ mfd_sc16is75x_configure_gpio_pin()

static int mfd_sc16is75x_configure_gpio_pin ( const struct device *  dev,
const struct gpio_dt_spec *  gpio,
const gpio_flags_t  flags 
)
static

Set up GPIO pin.

Parameters
devAn SC16IS75X MFD device.
gpioThe GPIO specification from devicetree.
flagsAdditional GPIO flags.
Return values
0On success.
Returns
Negative error code on failure.

◆ mfd_sc16is75x_init()

static int mfd_sc16is75x_init ( const struct device *  dev)
static

◆ mfd_sc16is75x_pm_device_pm_action()

static int mfd_sc16is75x_pm_device_pm_action ( const struct device *  dev,
enum pm_device_action  action 
)
static

◆ mfd_sc16is75x_read()

static int mfd_sc16is75x_read ( const struct device *  dev,
const uint8_t  channel,
const uint8_t  reg,
uint8_t *  buf,
const size_t  len 
)
static

◆ mfd_sc16is75x_sub_address()

static int mfd_sc16is75x_sub_address ( const bool  read,
const uint8_t  reg,
const uint8_t  channel,
uint8_t *  sub_address 
)
inlinestatic

◆ mfd_sc16is75x_sw_reset()

static int mfd_sc16is75x_sw_reset ( const struct device *  dev)
static

◆ mfd_sc16is75x_write()

static int mfd_sc16is75x_write ( const struct device *  dev,
const uint8_t  channel,
const uint8_t  reg,
const uint8_t *  buf,
const size_t  len 
)
static