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

MFD Driver for an SIPO/MUX GP matrix controller. More...

#include "mfd_sipomuxgp.h"
#include <zephyr/logging/log.h>

Macros

#define INST_DT_SIPOMUXGP(n, b)   DT_INST(n, sipo_mux_gp_##b)
 
#define MFD_SIPOMUXGP_CTX_SPEC_ELEM(_node_id, _prop, _idx)    GPIO_DT_SPEC_GET_BY_IDX(_node_id, _prop, _idx),
 
#define MFD_SIPOMUXGP_CTX_FOREACH_ELEM(n, b, p)
 
#define MFD_SIPOMUXGP_CTX_GPIOS_ADDR(n, b)
 
#define MFD_SIPOMUXGP_CTX_GPIO_ENABLE(n, b)    GPIO_DT_SPEC_GET_OR(INST_DT_SIPOMUXGP(n, b), oe_gpios, {0})
 
#define MFD_SIPOMUXGP_CTX_NUM_ADDR(n, b)    DT_PROP_LEN(INST_DT_SIPOMUXGP(n, b), addr_gpios)
 
#define MFD_SIPOMUXGP_CTX_ROWS(n, b)    BIT(MFD_SIPOMUXGP_CTX_NUM_ADDR(n, b))
 
#define MFD_SIPOMUXGP_CTX_COLUMNS(n, b)    DT_PROP(INST_DT_SIPOMUXGP(n, b), data_width)
 
#define MFD_SIPOMUXGP_CTX_NUM_BITS(n, b)    (MFD_SIPOMUXGP_CTX_ROWS(n, b) * MFD_SIPOMUXGP_CTX_COLUMNS(n, b))
 
#define MFD_SIPOMUXGP_CTX_BITBUF_SZ(n, b)    (__TOTAL_BYTES(MFD_SIPOMUXGP_CTX_NUM_BITS(n, b)))
 
#define MFD_SIPOMUXGP_CTX_BITBUF(n, b)    (uint8_t [(MFD_SIPOMUXGP_CTX_BITBUF_SZ(n, b))]) {}
 
#define MFD_SIPOMUXGP_CTX_SHIFTING(n, b)    DT_PROP(INST_DT_SIPOMUXGP(n, b), shift_width)
 
#define MFD_SIPOMUXGP_CTX_PADDING(n, b)    (MFD_SIPOMUXGP_CTX_SHIFTING(n, b) - MFD_SIPOMUXGP_CTX_COLUMNS(n, b))
 
#define MFD_SIPOMUXGP_CTX_PADDING_SZ(n, b)    (__TOTAL_BYTES(MFD_SIPOMUXGP_CTX_PADDING(n, b)))
 
#define MFD_SIPOMUXGP_CTX_RFSTIME(n, b)    DT_PROP(INST_DT_SIPOMUXGP(n, b), refresh_time_us)
 
#define MFD_SIPOMUXGP_CTX_BACKEND(n, b)
 
#define SIPOMUXGP_INIT(n, b)
 
#define DT_INST_FOREACH_SIPOMUXGP_STATUS_OKAY(b)
 

Functions

 LOG_MODULE_REGISTER (mfd_sipomuxgp, CONFIG_MFD_LOG_LEVEL)
 
int mfd_sipomuxgp_num_bits (const struct device *dev)
 Get number of available bits from SIPO/MUX GP.
 
static int mfd_sipomuxgp_get_bit (const struct device *dev, uint32_t bit, uint8_t *value)
 
int mfd_sipomuxgp_bits (const struct device *dev, size_t offs, uint32_t *val)
 Read 32 bits from SIPO/MUX GP.
 
static int mfd_sipomuxgp_set_bit (const struct device *dev, uint32_t bit, uint8_t value)
 
int mfd_sipomuxgp_bit_on (const struct device *dev, size_t bit)
 Write logical one to a single bit on SIPO/MUX GP.
 
int mfd_sipomuxgp_bit_off (const struct device *dev, size_t bit)
 Write logical zero to a single bit on SIPO/MUX GP.
 
int mfd_sipomuxgp_xy_on (const struct device *dev, size_t x, size_t y)
 Write logical one to a single XY position on SIPO/MUX GP.
 
int mfd_sipomuxgp_xy_off (const struct device *dev, size_t x, size_t y)
 Write logical zero to a single XY position on SIPO/MUX GP.
 
int mfd_sipomuxgp_output_ratio (const struct device *dev, uint8_t percent)
 Change ratio of SIPO/MUX GP output enable signal.
 
static void mfd_sipomuxgp_process (const struct device *dev)
 
static int mfd_sipomuxgp_set_oe (const struct device *dev, const uint8_t value)
 
static int mfd_sipomuxgp_set_addr (const struct device *dev, const uint8_t addr)
 
static int mfd_sipomuxgp_cfg_oe (const struct device *dev)
 
static int mfd_sipomuxgp_cfg_addr (const struct device *dev)
 
static void mfd_sipomuxgp_refresh_worker (struct k_work *work)
 
static void mfd_sipomuxgp_refresh_timer (struct k_timer *timer)
 
static int mfd_sipomuxgp_init (const struct device *dev)
 

Detailed Description

MFD Driver for an SIPO/MUX GP matrix controller.

Macro Definition Documentation

◆ DT_INST_FOREACH_SIPOMUXGP_STATUS_OKAY

#define DT_INST_FOREACH_SIPOMUXGP_STATUS_OKAY (   b)
Value:
LISTIFY( \
DT_NUM_INST_STATUS_OKAY(sipo_mux_gp_##b), SIPOMUXGP_INIT, (;), b)
#define SIPOMUXGP_INIT(n, b)
Definition mfd_sipomuxgp.c:446

◆ INST_DT_SIPOMUXGP

#define INST_DT_SIPOMUXGP (   n,
 
)    DT_INST(n, sipo_mux_gp_##b)

◆ MFD_SIPOMUXGP_CTX_BACKEND

#define MFD_SIPOMUXGP_CTX_BACKEND (   n,
 
)
Value:
{ \
.config = (const void *)&mfd_sipomuxgp_##b##_config_##n, \
.init = mfd_sipomuxgp_##b##_init, \
.cfg_oe = mfd_sipomuxgp_##b##_cfg_oe, \
.cfg_addr = mfd_sipomuxgp_##b##_cfg_addr, \
.set_oe = mfd_sipomuxgp_##b##_set_oe, \
.set_addr = mfd_sipomuxgp_##b##_set_addr, \
.xfr_data = mfd_sipomuxgp_##b##_transmit, \
}

◆ MFD_SIPOMUXGP_CTX_BITBUF

#define MFD_SIPOMUXGP_CTX_BITBUF (   n,
 
)     (uint8_t [(MFD_SIPOMUXGP_CTX_BITBUF_SZ(n, b))]) {}

◆ MFD_SIPOMUXGP_CTX_BITBUF_SZ

#define MFD_SIPOMUXGP_CTX_BITBUF_SZ (   n,
 
)     (__TOTAL_BYTES(MFD_SIPOMUXGP_CTX_NUM_BITS(n, b)))

◆ MFD_SIPOMUXGP_CTX_COLUMNS

#define MFD_SIPOMUXGP_CTX_COLUMNS (   n,
 
)     DT_PROP(INST_DT_SIPOMUXGP(n, b), data_width)

◆ MFD_SIPOMUXGP_CTX_FOREACH_ELEM

#define MFD_SIPOMUXGP_CTX_FOREACH_ELEM (   n,
  b,
 
)
Value:
DT_FOREACH_PROP_ELEM(INST_DT_SIPOMUXGP(n, b), p, \
#define MFD_SIPOMUXGP_CTX_SPEC_ELEM(_node_id, _prop, _idx)
Definition mfd_sipomuxgp.c:390
#define INST_DT_SIPOMUXGP(n, b)
Definition mfd_sipomuxgp.c:388

◆ MFD_SIPOMUXGP_CTX_GPIO_ENABLE

#define MFD_SIPOMUXGP_CTX_GPIO_ENABLE (   n,
 
)     GPIO_DT_SPEC_GET_OR(INST_DT_SIPOMUXGP(n, b), oe_gpios, {0})

◆ MFD_SIPOMUXGP_CTX_GPIOS_ADDR

#define MFD_SIPOMUXGP_CTX_GPIOS_ADDR (   n,
 
)
Value:
(const struct gpio_dt_spec[]){ \
MFD_SIPOMUXGP_CTX_FOREACH_ELEM(n, b, addr_gpios) \
}

◆ MFD_SIPOMUXGP_CTX_NUM_ADDR

#define MFD_SIPOMUXGP_CTX_NUM_ADDR (   n,
 
)     DT_PROP_LEN(INST_DT_SIPOMUXGP(n, b), addr_gpios)

◆ MFD_SIPOMUXGP_CTX_NUM_BITS

#define MFD_SIPOMUXGP_CTX_NUM_BITS (   n,
 
)     (MFD_SIPOMUXGP_CTX_ROWS(n, b) * MFD_SIPOMUXGP_CTX_COLUMNS(n, b))

◆ MFD_SIPOMUXGP_CTX_PADDING

#define MFD_SIPOMUXGP_CTX_PADDING (   n,
 
)     (MFD_SIPOMUXGP_CTX_SHIFTING(n, b) - MFD_SIPOMUXGP_CTX_COLUMNS(n, b))

◆ MFD_SIPOMUXGP_CTX_PADDING_SZ

#define MFD_SIPOMUXGP_CTX_PADDING_SZ (   n,
 
)     (__TOTAL_BYTES(MFD_SIPOMUXGP_CTX_PADDING(n, b)))

◆ MFD_SIPOMUXGP_CTX_RFSTIME

#define MFD_SIPOMUXGP_CTX_RFSTIME (   n,
 
)     DT_PROP(INST_DT_SIPOMUXGP(n, b), refresh_time_us)

◆ MFD_SIPOMUXGP_CTX_ROWS

#define MFD_SIPOMUXGP_CTX_ROWS (   n,
 
)     BIT(MFD_SIPOMUXGP_CTX_NUM_ADDR(n, b))

◆ MFD_SIPOMUXGP_CTX_SHIFTING

#define MFD_SIPOMUXGP_CTX_SHIFTING (   n,
 
)     DT_PROP(INST_DT_SIPOMUXGP(n, b), shift_width)

◆ MFD_SIPOMUXGP_CTX_SPEC_ELEM

#define MFD_SIPOMUXGP_CTX_SPEC_ELEM (   _node_id,
  _prop,
  _idx 
)     GPIO_DT_SPEC_GET_BY_IDX(_node_id, _prop, _idx),

◆ SIPOMUXGP_INIT

#define SIPOMUXGP_INIT (   n,
 
)
Value:
MFD_SIPOMUXGP_##b##_CFG_INIT(n, b); \
\
static const mfd_sipomuxgp_config_t mfd_sipomuxgp_config_##n = { \
.enable = MFD_SIPOMUXGP_CTX_GPIO_ENABLE(n, b), \
.num_addr = MFD_SIPOMUXGP_CTX_NUM_ADDR(n, b), \
.num_bits = MFD_SIPOMUXGP_CTX_NUM_BITS(n, b), \
.columns = MFD_SIPOMUXGP_CTX_COLUMNS(n, b), \
.rows = MFD_SIPOMUXGP_CTX_ROWS(n, b), \
.backend = MFD_SIPOMUXGP_CTX_BACKEND(n, b), \
}; \
\
BUILD_ASSERT(500 <= MFD_SIPOMUXGP_CTX_RFSTIME(n, b), \
"Bad refresh time, refresh-time-us must be >= 500 usec"); \
\
BUILD_ASSERT(0 < MFD_SIPOMUXGP_CTX_ROWS(n, b), \
"Bad rows, addr-gpios needs at least one entry"); \
\
BUILD_ASSERT(8 <= MFD_SIPOMUXGP_CTX_COLUMNS(n, b), \
"Bad columns, data-width must be equal or greater than 8"); \
\
BUILD_ASSERT(MFD_SIPOMUXGP_CTX_COLUMNS(n, b) \
"Too many bits, data-width does not fit into shift-width"); \
\
static mfd_sipomuxgp_data_t mfd_sipomuxgp_data_##n = { \
.padding_sz = MFD_SIPOMUXGP_CTX_PADDING_SZ(n, b), \
.bitbuf_sz = MFD_SIPOMUXGP_CTX_BITBUF_SZ(n, b), \
.bitbuf = MFD_SIPOMUXGP_CTX_BITBUF(n, b), \
.oe_noblank = true, \
.oe_noratio = true, \
.oe_count = 0, \
}; \
\
PM_DEVICE_DT_DEFINE(INST_DT_SIPOMUXGP(n, b), \
mfd_sipomuxgp_pm_device_pm_action); \
\
DEVICE_DT_DEFINE(INST_DT_SIPOMUXGP(n, b), mfd_sipomuxgp_init, \
PM_DEVICE_DT_GET(INST_DT_SIPOMUXGP(n, b)), \
&mfd_sipomuxgp_data_##n, \
&mfd_sipomuxgp_config_##n, POST_KERNEL, \
CONFIG_MFD_SIPOMUXGP_INIT_PRIORITY, NULL)
#define MFD_SIPOMUXGP_CTX_BITBUF_SZ(n, b)
Definition mfd_sipomuxgp.c:417
#define MFD_SIPOMUXGP_CTX_NUM_BITS(n, b)
Definition mfd_sipomuxgp.c:414
#define MFD_SIPOMUXGP_CTX_PADDING_SZ(n, b)
Definition mfd_sipomuxgp.c:429
#define MFD_SIPOMUXGP_CTX_BITBUF(n, b)
Definition mfd_sipomuxgp.c:420
#define MFD_SIPOMUXGP_CTX_GPIO_ENABLE(n, b)
Definition mfd_sipomuxgp.c:402
#define MFD_SIPOMUXGP_CTX_GPIOS_ADDR(n, b)
Definition mfd_sipomuxgp.c:397
#define MFD_SIPOMUXGP_CTX_BACKEND(n, b)
Definition mfd_sipomuxgp.c:435
#define MFD_SIPOMUXGP_CTX_ROWS(n, b)
Definition mfd_sipomuxgp.c:408
#define MFD_SIPOMUXGP_CTX_SHIFTING(n, b)
Definition mfd_sipomuxgp.c:423
#define MFD_SIPOMUXGP_CTX_RFSTIME(n, b)
Definition mfd_sipomuxgp.c:432
#define MFD_SIPOMUXGP_CTX_COLUMNS(n, b)
Definition mfd_sipomuxgp.c:411
static int mfd_sipomuxgp_init(const struct device *dev)
Definition mfd_sipomuxgp.c:338
#define MFD_SIPOMUXGP_CTX_NUM_ADDR(n, b)
Definition mfd_sipomuxgp.c:405
Definition mfd_sipomuxgp.h:37
const struct gpio_dt_spec * addr
Definition mfd_sipomuxgp.h:40
Definition mfd_sipomuxgp.h:47
uint32_t refresh_time_us
Definition mfd_sipomuxgp.h:52

Function Documentation

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( mfd_sipomuxgp  ,
CONFIG_MFD_LOG_LEVEL   
)

◆ mfd_sipomuxgp_cfg_addr()

static int mfd_sipomuxgp_cfg_addr ( const struct device *  dev)
static

◆ mfd_sipomuxgp_cfg_oe()

static int mfd_sipomuxgp_cfg_oe ( const struct device *  dev)
static

◆ mfd_sipomuxgp_get_bit()

static int mfd_sipomuxgp_get_bit ( const struct device *  dev,
uint32_t  bit,
uint8_t *  value 
)
static

◆ mfd_sipomuxgp_init()

static int mfd_sipomuxgp_init ( const struct device *  dev)
static

◆ mfd_sipomuxgp_process()

static void mfd_sipomuxgp_process ( const struct device *  dev)
static

◆ mfd_sipomuxgp_refresh_timer()

static void mfd_sipomuxgp_refresh_timer ( struct k_timer *  timer)
static

◆ mfd_sipomuxgp_refresh_worker()

static void mfd_sipomuxgp_refresh_worker ( struct k_work *  work)
static

◆ mfd_sipomuxgp_set_addr()

static int mfd_sipomuxgp_set_addr ( const struct device *  dev,
const uint8_t  addr 
)
static

◆ mfd_sipomuxgp_set_bit()

static int mfd_sipomuxgp_set_bit ( const struct device *  dev,
uint32_t  bit,
uint8_t  value 
)
static

◆ mfd_sipomuxgp_set_oe()

static int mfd_sipomuxgp_set_oe ( const struct device *  dev,
const uint8_t  value 
)
static