smbus: Move smbus_utils.h from includes to driver area
Move smbus_utils.h header from generic includes to the driver's area in order to have in include/zephyr/drivers only smbus.h header. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
3cccf45507
commit
1679faaa0e
4 changed files with 4 additions and 2 deletions
|
@ -21,7 +21,7 @@
|
|||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(intel_pch, CONFIG_SMBUS_LOG_LEVEL);
|
||||
|
||||
#include <zephyr/drivers/smbus_utils.h>
|
||||
#include "smbus_utils.h"
|
||||
#include "intel_pch_smbus.h"
|
||||
|
||||
/**
|
||||
|
|
95
drivers/smbus/smbus_utils.h
Normal file
95
drivers/smbus/smbus_utils.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_
|
||||
#define ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_
|
||||
|
||||
/**
|
||||
* @brief Generic function to insert a callback to a callback list
|
||||
*
|
||||
* @param callbacks A pointer to the original list of callbacks (can be NULL)
|
||||
* @param callback A pointer of the callback to insert to the list
|
||||
*
|
||||
* @return 0 on success, negative errno otherwise.
|
||||
*/
|
||||
static inline int smbus_callback_set(sys_slist_t *callbacks,
|
||||
struct smbus_callback *callback)
|
||||
{
|
||||
__ASSERT(callback, "No callback!");
|
||||
__ASSERT(callback->handler, "No callback handler!");
|
||||
|
||||
if (!sys_slist_is_empty(callbacks)) {
|
||||
sys_slist_find_and_remove(callbacks, &callback->node);
|
||||
}
|
||||
|
||||
sys_slist_prepend(callbacks, &callback->node);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generic function to remove a callback from a callback list
|
||||
*
|
||||
* @param callbacks A pointer to the original list of callbacks (can be NULL)
|
||||
* @param callback A pointer of the callback to remove from the list
|
||||
*
|
||||
* @return 0 on success, negative errno otherwise.
|
||||
*/
|
||||
static inline int smbus_callback_remove(sys_slist_t *callbacks,
|
||||
struct smbus_callback *callback)
|
||||
{
|
||||
__ASSERT(callback, "No callback!");
|
||||
__ASSERT(callback->handler, "No callback handler!");
|
||||
|
||||
if (sys_slist_is_empty(callbacks) ||
|
||||
!sys_slist_find_and_remove(callbacks, &callback->node)) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generic function to go through and fire callback from a callback list
|
||||
*
|
||||
* @param list A pointer on the SMBus callback list
|
||||
* @param dev A pointer on the SMBus device instance
|
||||
* @param addr A SMBus peripheral device address.
|
||||
*/
|
||||
static inline void smbus_fire_callbacks(sys_slist_t *list,
|
||||
const struct device *dev,
|
||||
uint8_t addr)
|
||||
{
|
||||
struct smbus_callback *cb, *tmp;
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cb, tmp, node) {
|
||||
if (cb->addr == addr) {
|
||||
__ASSERT(cb->handler, "No callback handler!");
|
||||
cb->handler(dev, cb, addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper to initialize a struct smbus_callback properly
|
||||
*
|
||||
* @param callback A valid Application's callback structure pointer.
|
||||
* @param handler A valid handler function pointer.
|
||||
* @param addr A SMBus peripheral device address.
|
||||
*/
|
||||
static inline void smbus_init_callback(struct smbus_callback *callback,
|
||||
smbus_callback_handler_t handler,
|
||||
uint8_t addr)
|
||||
{
|
||||
__ASSERT(callback, "Callback pointer should not be NULL");
|
||||
__ASSERT(handler, "Callback handler pointer should not be NULL");
|
||||
|
||||
callback->handler = handler;
|
||||
callback->addr = addr;
|
||||
}
|
||||
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue