samv7/pwm: add support for PWMIOC_FAULTS_FETCH_AND_CLEAR ioctl
Some checks are pending
Build Documentation / build-html (push) Waiting to run

This ioctl fetches and clears PWM faults.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc
2025-02-20 10:56:54 +01:00
committed by Alan C. Assis
parent 86917b4777
commit 4e70cc1e69

View File

@@ -1118,7 +1118,43 @@ static int pwm_stop(struct pwm_lowerhalf_s *dev)
static int pwm_ioctl(struct pwm_lowerhalf_s *dev, int cmd,
unsigned long arg)
{
return -ENOTTY;
struct sam_pwm_s *priv = (struct sam_pwm_s *)dev;
uint32_t regval;
int ret = OK;
switch (cmd)
{
case PWMIOC_FAULTS_FETCH_AND_CLEAR:
{
unsigned long clear = arg != 0 ?
*(unsigned long *)(uintptr_t)arg : FCR_FCLR_MASK;
/* Get current faults. */
regval = pwm_getreg(priv, SAMV7_PWM_FSR);
/* Clear the faults. */
clear &= ((regval & FSR_FS_MASK) >> FSR_FS_SHIFT);
pwm_putreg(priv, SAMV7_PWM_FCR, FCR_FCLR_SEL(clear));
/* And return the previously read faults. */
if (arg != 0)
{
*(unsigned long *)(uintptr_t)arg =
(regval & FSR_FS_MASK) >> FSR_FS_SHIFT;
}
}
break;
default:
{
pwmerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
}
}
return ret;
}
/****************************************************************************