drivers: haptics: Update CS40L5x driver to use new haptics API

Modifies the CS40L5x driver to use the error callback mechanism
added to the haptics API instead of a device-specific API
extension.

Signed-off-by: Liam Ogletree <liam.ogletree@cirrus.com>
This commit is contained in:
Liam Ogletree
2026-01-06 10:40:07 -06:00
committed by Maureen Helm
parent abaf251800
commit 339d2df232
2 changed files with 18 additions and 38 deletions

View File

@@ -770,7 +770,7 @@ static void cs40l5x_error_callback(const struct device *const dev, const uint32_
struct cs40l5x_data *const data = dev->data;
if (data->error_callback != NULL) {
(void)data->error_callback(dev, error_bitmask);
(void)data->error_callback(dev, error_bitmask, data->user_data);
}
}
@@ -854,7 +854,7 @@ static int cs40l5x_process_mailbox(const struct device *const dev)
case CS40L5X_MBOX_PERMANENT_SHORT_DETECTED:
__fallthrough;
case CS40L5X_MBOX_RUNTIME_SHORT_DETECTED:
(void)cs40l5x_error_callback(dev, CS40L5X_ERROR_AMPLIFIER_SHORT);
(void)cs40l5x_error_callback(dev, HAPTICS_ERROR_OVERCURRENT);
return 0;
default:
@@ -881,37 +881,37 @@ static int cs40l5x_process_interrupts(const struct device *const dev,
if (FIELD_GET(CS40L5X_MASK_IRQ1_AMP, irq_ints[CS40L5X_INT1]) != 0) {
LOG_INST_WRN(config->log, "amplifier short detected");
error_bitmask |= CS40L5X_ERROR_AMPLIFIER_SHORT;
error_bitmask |= HAPTICS_ERROR_OVERCURRENT;
}
if (FIELD_GET(CS40L5X_MASK_IRQ8_TEMP, irq_ints[CS40L5X_INT8]) != 0) {
LOG_INST_WRN(config->log, "overtemperature detected");
error_bitmask |= CS40L5X_ERROR_OVERTEMPERATURE;
error_bitmask |= HAPTICS_ERROR_OVERTEMPERATURE;
}
if (FIELD_GET(CS40L5X_MASK_IRQ9_UVP, irq_ints[CS40L5X_INT9]) != 0) {
LOG_INST_WRN(config->log, "undervoltage detected");
error_bitmask |= CS40L5X_ERROR_UNDERVOLTAGE;
error_bitmask |= HAPTICS_ERROR_UNDERVOLTAGE;
}
if (FIELD_GET(CS40L5X_MASK_IRQ9_IND_SHORT, irq_ints[CS40L5X_INT9]) != 0) {
LOG_INST_WRN(config->log, "inductor short detected");
error_bitmask |= CS40L5X_ERROR_INDUCTOR_SHORT;
error_bitmask |= HAPTICS_ERROR_OVERCURRENT;
}
if (FIELD_GET(CS40L5X_MASK_IRQ9_CUR_LIMIT, irq_ints[CS40L5X_INT9]) != 0) {
LOG_INST_WRN(config->log, "overcurrent condition detected");
error_bitmask |= CS40L5X_ERROR_OVERCURRENT;
error_bitmask |= HAPTICS_ERROR_OVERCURRENT;
}
if (FIELD_GET(CS40L5X_MASK_IRQ1_VDDB, irq_ints[CS40L5X_INT10]) != 0) {
LOG_INST_WRN(config->log, "battery undervoltage detected");
error_bitmask |= CS40L5X_ERROR_BATTERY_UNDERVOLTAGE;
error_bitmask |= HAPTICS_ERROR_UNDERVOLTAGE;
}
if (error_bitmask != 0) {
@@ -1870,13 +1870,15 @@ int cs40l5x_logger_get(const struct device *const dev, enum cs40l5x_logger_sourc
return ret;
}
void cs40l5x_register_error_callback(const struct device *dev,
void (*error_callback)(const struct device *const haptic_dev,
const uint32_t errors))
static int cs40l5x_register_error_callback(const struct device *dev, haptics_error_callback_t cb,
void *const user_data)
{
struct cs40l5x_data *const data = dev->data;
data->error_callback = error_callback;
data->error_callback = cb;
data->user_data = user_data;
return 0;
}
int cs40l5x_select_output(const struct device *const dev, const enum cs40l5x_bank bank,
@@ -2293,6 +2295,7 @@ error_pm:
static DEVICE_API(haptics, cs40l5x_driver_api) = {
.start_output = &cs40l5x_start_output,
.stop_output = &cs40l5x_stop_output,
.register_error_callback = &cs40l5x_register_error_callback,
};
static int cs40l5x_pm_resume(const struct device *const dev)

View File

@@ -77,20 +77,6 @@ enum cs40l5x_custom_index {
CS40L5X_NUM_CUSTOM_EFFECTS, /**< Maximum number of custom haptics effects */
};
/**
* @brief Types of fatal CS40L5x hardware errors
*
* @details Provided to application callback function. See @ref cs40l5x_register_error_callback().
*/
enum cs40l5x_error_type {
CS40L5X_ERROR_AMPLIFIER_SHORT = BIT(0), /**< Amplifier short detected */
CS40L5X_ERROR_OVERTEMPERATURE = BIT(1), /**< Overtemperature detected */
CS40L5X_ERROR_UNDERVOLTAGE = BIT(2), /**< Undervoltage detected */
CS40L5X_ERROR_INDUCTOR_SHORT = BIT(3), /**< Inductor short detected */
CS40L5X_ERROR_OVERCURRENT = BIT(4), /**< Overcurrent condition detected */
CS40L5X_ERROR_BATTERY_UNDERVOLTAGE = BIT(4), /**< Vdd_batt undervoltage detected */
};
/**
* @brief Options for runtime haptics logging
*
@@ -318,7 +304,9 @@ struct cs40l5x_data {
/**< Callback handler for trigger logging */
struct gpio_callback trigger_callback;
/**< Application-provided callback to recover from fatal hardware errors */
void (*error_callback)(const struct device *const haptic_dev, const uint32_t errors);
haptics_error_callback_t error_callback;
/**< Application-provided user data for callback context */
void *user_data;
/**< Semaphore used to sequence the calibration routine */
struct k_sem calibration_semaphore;
/**< F0 and ReDC data derived from calibration */
@@ -418,17 +406,6 @@ int cs40l5x_logger(const struct device *const dev, enum cs40l5x_logger logger_st
int cs40l5x_logger_get(const struct device *const dev, enum cs40l5x_logger_source source,
enum cs40l5x_logger_source_type type, uint32_t *const value);
/**
* @brief Register an application callback to handle fatal hardware errors
*
* @param dev Pointer to the device structure for haptic device instance
* @param error_callback Application function that takes a pointer to the device structure for a
* haptic device instance and a bitmask of @ref cs40l5x_error_type
*/
void cs40l5x_register_error_callback(const struct device *dev,
void (*error_callback)(const struct device *const haptic_dev,
const uint32_t errors));
/**
* @brief Select haptic effect triggered via @ref haptics_start_output()
*