xref: /linux/sound/soc/codecs/cs42l42.h (revision 2d066c6a78654c179f95c9beda1985d4c6befa4e)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
22c394ca7SJames Schulman /*
32c394ca7SJames Schulman  * cs42l42.h -- CS42L42 ALSA SoC audio driver header
42c394ca7SJames Schulman  *
57b43e6d7SStefan Binding  * Copyright 2016-2022 Cirrus Logic, Inc.
62c394ca7SJames Schulman  *
72c394ca7SJames Schulman  * Author: James Schulman <james.schulman@cirrus.com>
82c394ca7SJames Schulman  * Author: Brian Austin <brian.austin@cirrus.com>
92c394ca7SJames Schulman  * Author: Michael White <michael.white@cirrus.com>
102c394ca7SJames Schulman  */
112c394ca7SJames Schulman 
122c394ca7SJames Schulman #ifndef __CS42L42_H__
132c394ca7SJames Schulman #define __CS42L42_H__
142c394ca7SJames Schulman 
15b48d1da0SRichard Fitzgerald #include <dt-bindings/sound/cs42l42.h>
16b48d1da0SRichard Fitzgerald #include <linux/device.h>
17b48d1da0SRichard Fitzgerald #include <linux/gpio.h>
18fdd53528SRichard Fitzgerald #include <linux/mutex.h>
19b48d1da0SRichard Fitzgerald #include <linux/regmap.h>
20b48d1da0SRichard Fitzgerald #include <linux/regulator/consumer.h>
2190f6a2a2SRichard Fitzgerald #include <linux/soundwire/sdw.h>
22c5b8ee08SLucas Tanure #include <sound/jack.h>
237b43e6d7SStefan Binding #include <sound/cs42l42.h>
24ae9f5e60SRichard Fitzgerald #include <sound/soc-component.h>
25ae9f5e60SRichard Fitzgerald #include <sound/soc-dai.h>
262c394ca7SJames Schulman 
272c394ca7SJames Schulman struct  cs42l42_private {
282c394ca7SJames Schulman 	struct regmap *regmap;
292003c44eSRichard Fitzgerald 	struct device *dev;
302c394ca7SJames Schulman 	struct regulator_bulk_data supplies[CS42L42_NUM_SUPPLIES];
312c394ca7SJames Schulman 	struct gpio_desc *reset_gpio;
322c394ca7SJames Schulman 	struct completion pdn_done;
33c26a5289SLucas Tanure 	struct snd_soc_jack *jack;
3490f6a2a2SRichard Fitzgerald 	struct sdw_slave *sdw_peripheral;
355982b5a8SRichard Fitzgerald 	struct mutex irq_lock;
3694d5f62aSMartin Povišer 	int devid;
370285042fSRichard Fitzgerald 	int irq;
38f1040e86SRichard Fitzgerald 	int pll_config;
392c394ca7SJames Schulman 	u32 sclk;
4090f6a2a2SRichard Fitzgerald 	u32 sample_rate;
41ab2940a7SMartin Povišer 	u32 bclk_ratio;
422c394ca7SJames Schulman 	u8 plug_state;
432c394ca7SJames Schulman 	u8 hs_type;
442c394ca7SJames Schulman 	u8 ts_inv;
452c394ca7SJames Schulman 	u8 ts_dbnc_rise;
462c394ca7SJames Schulman 	u8 ts_dbnc_fall;
472c394ca7SJames Schulman 	u8 btn_det_init_dbnce;
482c394ca7SJames Schulman 	u8 btn_det_event_dbnce;
492c394ca7SJames Schulman 	u8 bias_thresholds[CS42L42_NUM_BIASES];
502c394ca7SJames Schulman 	u8 hs_bias_ramp_rate;
512c394ca7SJames Schulman 	u8 hs_bias_ramp_time;
52c9f2e3c3SVitaly Rodionov 	u8 hs_bias_sense_en;
5343fc3571SLucas Tanure 	u8 stream_use;
544ae1d8f9SRichard Fitzgerald 	bool hp_adc_up_pending;
55f8593e88SRichard Fitzgerald 	bool suspended;
56*2d066c6aSRichard Fitzgerald 	bool sdw_waiting_first_unattach;
570285042fSRichard Fitzgerald 	bool init_done;
582c394ca7SJames Schulman };
592c394ca7SJames Schulman 
6030b679e2SMartin Povišer extern const struct regmap_range_cfg cs42l42_page_range;
61ae9f5e60SRichard Fitzgerald extern const struct regmap_config cs42l42_regmap;
62ae9f5e60SRichard Fitzgerald extern const struct snd_soc_component_driver cs42l42_soc_component;
63ae9f5e60SRichard Fitzgerald extern struct snd_soc_dai_driver cs42l42_dai;
64ae9f5e60SRichard Fitzgerald 
6530b679e2SMartin Povišer bool cs42l42_readable_register(struct device *dev, unsigned int reg);
6630b679e2SMartin Povišer bool cs42l42_volatile_register(struct device *dev, unsigned int reg);
6730b679e2SMartin Povišer 
680998816aSRichard Fitzgerald int cs42l42_pll_config(struct snd_soc_component *component,
690998816aSRichard Fitzgerald 		       unsigned int clk, unsigned int sample_rate);
700998816aSRichard Fitzgerald void cs42l42_src_config(struct snd_soc_component *component, unsigned int sample_rate);
710998816aSRichard Fitzgerald int cs42l42_mute_stream(struct snd_soc_dai *dai, int mute, int stream);
720998816aSRichard Fitzgerald irqreturn_t cs42l42_irq_thread(int irq, void *data);
73ae9f5e60SRichard Fitzgerald int cs42l42_suspend(struct device *dev);
74ae9f5e60SRichard Fitzgerald int cs42l42_resume(struct device *dev);
75ae9f5e60SRichard Fitzgerald void cs42l42_resume_restore(struct device *dev);
76ae9f5e60SRichard Fitzgerald int cs42l42_common_probe(struct cs42l42_private *cs42l42,
77ae9f5e60SRichard Fitzgerald 			 const struct snd_soc_component_driver *component_drv,
78ae9f5e60SRichard Fitzgerald 			 struct snd_soc_dai_driver *dai);
79ae9f5e60SRichard Fitzgerald int cs42l42_init(struct cs42l42_private *cs42l42);
80ae9f5e60SRichard Fitzgerald void cs42l42_common_remove(struct cs42l42_private *cs42l42);
81ae9f5e60SRichard Fitzgerald 
822c394ca7SJames Schulman #endif /* __CS42L42_H__ */
83