1/* SPDX-License-Identifier: GPL-2.0
2 *
3 * CS35L41 ALSA HDA audio driver
4 *
5 * Copyright 2021 Cirrus Logic, Inc.
6 *
7 * Author: Lucas Tanure <tanureal@opensource.cirrus.com>
8 */
9
10#ifndef __CS35L41_HDA_H__
11#define __CS35L41_HDA_H__
12
13#include <linux/acpi.h>
14#include <linux/efi.h>
15#include <linux/regulator/consumer.h>
16#include <linux/gpio/consumer.h>
17#include <linux/device.h>
18#include <sound/cs35l41.h>
19
20#include <linux/firmware/cirrus/cs_dsp.h>
21#include <linux/firmware/cirrus/wmfw.h>
22
23#define CS35L41_MAX_ACCEPTABLE_SPI_SPEED_HZ	1000000
24
25struct cs35l41_amp_cal_data {
26	u32 calTarget[2];
27	u32 calTime[2];
28	s8 calAmbient;
29	u8 calStatus;
30	u16 calR;
31} __packed;
32
33struct cs35l41_amp_efi_data {
34	u32 size;
35	u32 count;
36	struct cs35l41_amp_cal_data data[];
37} __packed;
38
39enum cs35l41_hda_spk_pos {
40	CS35L41_LEFT,
41	CS35L41_RIGHT,
42};
43
44enum cs35l41_hda_gpio_function {
45	CS35L41_NOT_USED,
46	CS35l41_VSPK_SWITCH,
47	CS35L41_INTERRUPT,
48	CS35l41_SYNC,
49};
50
51enum control_bus {
52	I2C,
53	SPI
54};
55
56struct cs35l41_hda {
57	struct device *dev;
58	struct regmap *regmap;
59	struct gpio_desc *reset_gpio;
60	struct gpio_desc *cs_gpio;
61	struct cs35l41_hw_cfg hw_cfg;
62	struct hda_codec *codec;
63
64	int irq;
65	int index;
66	int channel_index;
67	unsigned volatile long irq_errors;
68	const char *amp_name;
69	const char *acpi_subsystem_id;
70	int firmware_type;
71	int speaker_id;
72	struct mutex fw_mutex;
73	struct work_struct fw_load_work;
74
75	struct regmap_irq_chip_data *irq_data;
76	bool firmware_running;
77	bool request_fw_load;
78	bool fw_request_ongoing;
79	bool halo_initialized;
80	bool playback_started;
81	struct cs_dsp cs_dsp;
82	struct acpi_device *dacpi;
83	bool mute_override;
84	enum control_bus control_bus;
85	bool bypass_fw;
86
87};
88
89enum halo_state {
90	HALO_STATE_CODE_INIT_DOWNLOAD = 0,
91	HALO_STATE_CODE_START,
92	HALO_STATE_CODE_RUN
93};
94
95extern const struct dev_pm_ops cs35l41_hda_pm_ops;
96
97int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int irq,
98		      struct regmap *regmap, enum control_bus control_bus);
99void cs35l41_hda_remove(struct device *dev);
100int cs35l41_get_speaker_id(struct device *dev, int amp_index, int num_amps, int fixed_gpio_id);
101
102#endif /*__CS35L41_HDA_H__*/
103