Re: [PATCH 5/6] gpio: max77759: add Maxim MAX77759 gpio driver

André Draszik
2025-02-24T10:46:49Z

On Mon, 2025-02-24 at 10:28 +0000, André Draszik wrote:
> [...]
>
> +#define MAX77759_GPIOx_TRIGGER(offs, val) (((val) & 1) << (offs))
> +#define MAX77759_GPIOx_TRIGGER_MASK(offs) MAX77759_GPIOx_TRIGGER(offs, ~0)
> +enum max77759_trigger_gpio_type {
> + MAX77759_GPIO_TRIGGER_RISING = 0,
> + MAX77759_GPIO_TRIGGER_FALLING = 1
> +};
> +
> +#define MAX77759_GPIOx_DIR(offs, dir) (((dir) & 1) << (2 + (3 * (offs))))
> +#define MAX77759_GPIOx_DIR_MASK(offs) MAX77759_GPIOx_DIR(offs, ~0)
> +enum max77759_control_gpio_dir {
> + MAX77759_GPIO_DIR_IN = 0,
> + MAX77759_GPIO_DIR_OUT = 1
> +};
> +
> +#define MAX77759_GPIOx_OUTVAL(offs, val) (((val) & 1) << (3 + (3 * (offs))))
> +#define MAX77759_GPIOx_OUTVAL_MASK(offs) MAX77759_GPIOx_OUTVAL(offs, ~0)
> +
> +#define MAX77759_GPIOx_INVAL_MASK(offs) (BIT(4) << (3 * (offs)))
> +
> +[...]
>
> +static int
> +max77759_gpio_direction_from_control(int ctrl, unsigned int offset)
> +{
> + return (((ctrl & MAX77759_GPIOx_DIR_MASK(offset))
> + == MAX77759_GPIO_DIR_OUT)
> + ? GPIO_LINE_DIRECTION_OUT
> + : GPIO_LINE_DIRECTION_IN);

Eek, I made a last minute change that I shouldn't have :-(
This should be something more like:

static int
max77759_gpio_direction_from_control(int ctrl, unsigned int offset)
{
enum max77759_control_gpio_dir dir;

dir = !!(ctrl & MAX77759_GPIOx_DIR_MASK(offset));
return ((dir == MAX77759_GPIO_DIR_OUT)
? GPIO_LINE_DIRECTION_OUT
: GPIO_LINE_DIRECTION_IN);
}

I'll fix that for v2.

A.