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

MFD Driver for an SC18IM604 bridge. More...

#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/device.h>
#include <zephyr/pm/device.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_utils.h>
#include <zephyr/drivers/mfd/sc18is604.h>
#include "mfd_sc18is604.h"
#include <zephyr/logging/log.h>

Macros

#define DT_DRV_COMPAT   nxp_sc18is604
 
#define MFD_SC18IS604_DEFINE(inst)
 

Functions

 LOG_MODULE_REGISTER (mfd_sc18is604, CONFIG_MFD_LOG_LEVEL)
 
int mfd_sc18is604_add_callback (const struct device *dev, struct gpio_callback *callback)
 Register an interrupt callback.
 
int mfd_sc18is604_remove_callback (const struct device *dev, struct gpio_callback *callback)
 Remove a previously registered interrupt callback.
 
int mfd_sc18is604_claim (const struct device *dev, k_timeout_t timeout)
 Claim a lock on an SC18IS604 device, preventing other users from accessing the device until the lock is released.
 
void mfd_sc18is604_release (const struct device *dev)
 Release a previously acquired lock on an SC18IS604 device.
 
static int mfd_sc18is604_request_version_string (const struct device *dev)
 Request device version string.
 
static int mfd_sc18is604_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_sc18is604_chip_reset (const struct device *dev)
 Reset device.
 
static int mfd_sc18is604_reset_state_apply (const struct device *dev)
 Apply register default values.
 
static int mfd_sc18is604_clear_interrupt_source (const struct device *dev)
 
static void mfd_sc18is604_interrupt_callback (const struct device *dev, struct gpio_callback *cb, gpio_port_pins_t pins)
 
static int mfd_sc18is604_check_chipid (const struct device *dev, k_timeout_t timeout)
 
static int mfd_sc18is604_bind_interrupt (const struct device *dev, const struct gpio_dt_spec *gpio, const gpio_flags_t flags)
 Set up interrupt handling.
 
static int mfd_sc18is604_init (const struct device *dev)
 
 DT_INST_FOREACH_STATUS_OKAY (MFD_SC18IS604_DEFINE)
 

Detailed Description

MFD Driver for an SC18IM604 bridge.

Macro Definition Documentation

◆ DT_DRV_COMPAT

#define DT_DRV_COMPAT   nxp_sc18is604

◆ MFD_SC18IS604_DEFINE

#define MFD_SC18IS604_DEFINE (   inst)
Value:
IF_ENABLED(CONFIG_MFD_SC18IS604_ASYNC, \
(K_THREAD_STACK_DEFINE(mfd_sc18is604_wq_stack_##inst, \
CONFIG_MFD_SC18IS604_WORKQUEUE_STACK_SIZE))); \
\
static const struct mfd_sc18is604_config mfd_sc18is604_config_##inst = { \
.spi = SPI_DT_SPEC_INST_GET(inst, \
SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | \
SPI_HOLD_ON_CS | SPI_LOCK_ON | SPI_MODE_CPOL | \
SPI_MODE_CPHA | SPI_WORD_SET(8), \
0), \
.interrupt = GPIO_DT_SPEC_INST_GET(inst, interrupt_gpios), \
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
}; \
BUILD_ASSERT(DT_INST_PROP(inst, spi_max_frequency) >= MFD_SC18IS604_SPI_HZ_MIN, \
"SPI bus clock too low"); \
BUILD_ASSERT(DT_INST_PROP(inst, spi_max_frequency) <= MFD_SC18IS604_SPI_HZ_MAX, \
"SPI bus clock too high"); \
\
static struct mfd_sc18is604_data mfd_sc18is604_data_##inst = { \
IF_ENABLED(CONFIG_MFD_SC18IS604_ASYNC, \
(.work_queue_stack = mfd_sc18is604_wq_stack_##inst,)) \
}; \
\
PM_DEVICE_DT_INST_DEFINE(inst, mfd_sc18is604_pm_device_pm_action); \
\
DEVICE_DT_INST_DEFINE(inst, mfd_sc18is604_init, PM_DEVICE_DT_INST_GET(inst), \
&mfd_sc18is604_data_##inst, &mfd_sc18is604_config_##inst, \
POST_KERNEL, CONFIG_MFD_SC18IS604_INIT_PRIORITY, NULL);
static int mfd_sc18is604_init(const struct device *dev)
Definition mfd_sc18is604.c:307
#define MFD_SC18IS604_SPI_HZ_MAX
Definition mfd_sc18is604.h:29
#define MFD_SC18IS604_SPI_HZ_MIN
Definition mfd_sc18is604.h:28

Function Documentation

◆ DT_INST_FOREACH_STATUS_OKAY()

DT_INST_FOREACH_STATUS_OKAY ( MFD_SC18IS604_DEFINE  )

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( mfd_sc18is604  ,
CONFIG_MFD_LOG_LEVEL   
)

◆ mfd_sc18is604_bind_interrupt()

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

Set up interrupt handling.

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

◆ mfd_sc18is604_check_chipid()

static int mfd_sc18is604_check_chipid ( const struct device *  dev,
k_timeout_t  timeout 
)
static

◆ mfd_sc18is604_chip_reset()

static int mfd_sc18is604_chip_reset ( const struct device *  dev)
static

Reset device.

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

◆ mfd_sc18is604_clear_interrupt_source()

static int mfd_sc18is604_clear_interrupt_source ( const struct device *  dev)
static

◆ mfd_sc18is604_configure_gpio_pin()

static int mfd_sc18is604_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 SC18IS604 MFD device.
gpioThe GPIO specification from devicetree.
flagsAdditional GPIO flags.
Return values
0On success.
Returns
Negative error code on failure.

◆ mfd_sc18is604_init()

static int mfd_sc18is604_init ( const struct device *  dev)
static

◆ mfd_sc18is604_interrupt_callback()

static void mfd_sc18is604_interrupt_callback ( const struct device *  dev,
struct gpio_callback *  cb,
gpio_port_pins_t  pins 
)
static

◆ mfd_sc18is604_request_version_string()

static int mfd_sc18is604_request_version_string ( const struct device *  dev)
static

Request device version string.

The string will be placed in the internal buffer. The device interrupt is set once the string is ready to be read from the buffer.

Parameters
devAn SC18IS604 MFD device.
Returns
A value from mfd_sc18is604_transfer().

◆ mfd_sc18is604_reset_state_apply()

static int mfd_sc18is604_reset_state_apply ( const struct device *  dev)
static

Apply register default values.

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