162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * cs42l42.h -- CS42L42 ALSA SoC audio driver header
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2016-2022 Cirrus Logic, Inc.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: James Schulman <james.schulman@cirrus.com>
862306a36Sopenharmony_ci * Author: Brian Austin <brian.austin@cirrus.com>
962306a36Sopenharmony_ci * Author: Michael White <michael.white@cirrus.com>
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifndef __CS42L42_H__
1362306a36Sopenharmony_ci#define __CS42L42_H__
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <dt-bindings/sound/cs42l42.h>
1662306a36Sopenharmony_ci#include <linux/device.h>
1762306a36Sopenharmony_ci#include <linux/gpio.h>
1862306a36Sopenharmony_ci#include <linux/mutex.h>
1962306a36Sopenharmony_ci#include <linux/regmap.h>
2062306a36Sopenharmony_ci#include <linux/regulator/consumer.h>
2162306a36Sopenharmony_ci#include <linux/soundwire/sdw.h>
2262306a36Sopenharmony_ci#include <sound/jack.h>
2362306a36Sopenharmony_ci#include <sound/cs42l42.h>
2462306a36Sopenharmony_ci#include <sound/soc-component.h>
2562306a36Sopenharmony_ci#include <sound/soc-dai.h>
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistruct  cs42l42_private {
2862306a36Sopenharmony_ci	struct regmap *regmap;
2962306a36Sopenharmony_ci	struct device *dev;
3062306a36Sopenharmony_ci	struct regulator_bulk_data supplies[CS42L42_NUM_SUPPLIES];
3162306a36Sopenharmony_ci	struct gpio_desc *reset_gpio;
3262306a36Sopenharmony_ci	struct completion pdn_done;
3362306a36Sopenharmony_ci	struct snd_soc_jack *jack;
3462306a36Sopenharmony_ci	struct sdw_slave *sdw_peripheral;
3562306a36Sopenharmony_ci	struct mutex irq_lock;
3662306a36Sopenharmony_ci	int devid;
3762306a36Sopenharmony_ci	int irq;
3862306a36Sopenharmony_ci	int pll_config;
3962306a36Sopenharmony_ci	u32 sclk;
4062306a36Sopenharmony_ci	u32 sample_rate;
4162306a36Sopenharmony_ci	u32 bclk_ratio;
4262306a36Sopenharmony_ci	u8 plug_state;
4362306a36Sopenharmony_ci	u8 hs_type;
4462306a36Sopenharmony_ci	u8 ts_inv;
4562306a36Sopenharmony_ci	u8 ts_dbnc_rise;
4662306a36Sopenharmony_ci	u8 ts_dbnc_fall;
4762306a36Sopenharmony_ci	u8 btn_det_init_dbnce;
4862306a36Sopenharmony_ci	u8 btn_det_event_dbnce;
4962306a36Sopenharmony_ci	u8 bias_thresholds[CS42L42_NUM_BIASES];
5062306a36Sopenharmony_ci	u8 hs_bias_ramp_rate;
5162306a36Sopenharmony_ci	u8 hs_bias_ramp_time;
5262306a36Sopenharmony_ci	u8 hs_bias_sense_en;
5362306a36Sopenharmony_ci	u8 stream_use;
5462306a36Sopenharmony_ci	bool hp_adc_up_pending;
5562306a36Sopenharmony_ci	bool suspended;
5662306a36Sopenharmony_ci	bool sdw_waiting_first_unattach;
5762306a36Sopenharmony_ci	bool init_done;
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciextern const struct regmap_range_cfg cs42l42_page_range;
6162306a36Sopenharmony_ciextern const struct regmap_config cs42l42_regmap;
6262306a36Sopenharmony_ciextern const struct snd_soc_component_driver cs42l42_soc_component;
6362306a36Sopenharmony_ciextern struct snd_soc_dai_driver cs42l42_dai;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cibool cs42l42_readable_register(struct device *dev, unsigned int reg);
6662306a36Sopenharmony_cibool cs42l42_volatile_register(struct device *dev, unsigned int reg);
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ciint cs42l42_pll_config(struct snd_soc_component *component,
6962306a36Sopenharmony_ci		       unsigned int clk, unsigned int sample_rate);
7062306a36Sopenharmony_civoid cs42l42_src_config(struct snd_soc_component *component, unsigned int sample_rate);
7162306a36Sopenharmony_ciint cs42l42_mute_stream(struct snd_soc_dai *dai, int mute, int stream);
7262306a36Sopenharmony_ciirqreturn_t cs42l42_irq_thread(int irq, void *data);
7362306a36Sopenharmony_ciint cs42l42_suspend(struct device *dev);
7462306a36Sopenharmony_ciint cs42l42_resume(struct device *dev);
7562306a36Sopenharmony_civoid cs42l42_resume_restore(struct device *dev);
7662306a36Sopenharmony_ciint cs42l42_common_probe(struct cs42l42_private *cs42l42,
7762306a36Sopenharmony_ci			 const struct snd_soc_component_driver *component_drv,
7862306a36Sopenharmony_ci			 struct snd_soc_dai_driver *dai);
7962306a36Sopenharmony_ciint cs42l42_init(struct cs42l42_private *cs42l42);
8062306a36Sopenharmony_civoid cs42l42_common_remove(struct cs42l42_private *cs42l42);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#endif /* __CS42L42_H__ */
83