/* SPDX-License-Identifier: GPL-2.0 */


#ifndef __SDCA_INTERRUPTS_H__
#define __SDCA_INTERRUPTS_H__

#include <linux/interrupt.h>
#include <linux/mutex.h>
#include <linux/regmap.h>

struct device;
struct snd_soc_component;
struct sdca_function_data;

#define SDCA_MAX_INTERRUPTS 31 


struct sdca_interrupt {
	const char *name;

	struct device *dev;
	struct regmap *device_regmap;
	struct regmap *function_regmap;
	struct snd_soc_component *component;
	struct sdca_function_data *function;
	struct sdca_entity *entity;
	struct sdca_control *control;

	void *priv;

	int irq;
};


struct sdca_interrupt_info {
	struct regmap_irq_chip irq_chip;
	struct regmap_irq_chip_data *irq_data;

	struct sdca_interrupt irqs[SDCA_MAX_INTERRUPTS];

	struct mutex irq_lock; 
};

int sdca_irq_request(struct device *dev, struct sdca_interrupt_info *interrupt_info,
		     int sdca_irq, const char *name, irq_handler_t handler,
		     void *data);
void sdca_irq_free(struct device *dev, struct sdca_interrupt_info *interrupt_info,
		   int sdca_irq, const char *name, void *data);
int sdca_irq_data_populate(struct device *dev, struct regmap *function_regmap,
			   struct snd_soc_component *component,
			   struct sdca_function_data *function,
			   struct sdca_entity *entity,
			   struct sdca_control *control,
			   struct sdca_interrupt *interrupt);
int sdca_irq_populate_early(struct device *dev, struct regmap *function_regmap,
			    struct sdca_function_data *function,
			    struct sdca_interrupt_info *info);
int sdca_irq_populate(struct sdca_function_data *function,
		      struct snd_soc_component *component,
		      struct sdca_interrupt_info *info);
void sdca_irq_cleanup(struct device *dev,
		      struct sdca_function_data *function,
		      struct sdca_interrupt_info *info);
struct sdca_interrupt_info *sdca_irq_allocate(struct device *dev,
					      struct regmap *regmap, int irq);

void sdca_irq_enable_early(struct sdca_function_data *function,
			   struct sdca_interrupt_info *info);
void sdca_irq_enable(struct sdca_function_data *function,
		     struct sdca_interrupt_info *info);
void sdca_irq_disable(struct sdca_function_data *function,
		      struct sdca_interrupt_info *info);

#endif
