xref: /linux-6.15/include/linux/mfd/wm8994/core.h (revision db4e8395)
1 /*
2  * include/linux/mfd/wm8994/core.h -- Core interface for WM8994
3  *
4  * Copyright 2009 Wolfson Microelectronics PLC.
5  *
6  * Author: Mark Brown <[email protected]>
7  *
8  *  This program is free software; you can redistribute  it and/or modify it
9  *  under  the terms of  the GNU General  Public License as published by the
10  *  Free Software Foundation;  either version 2 of the  License, or (at your
11  *  option) any later version.
12  *
13  */
14 
15 #ifndef __MFD_WM8994_CORE_H__
16 #define __MFD_WM8994_CORE_H__
17 
18 #include <linux/interrupt.h>
19 
20 enum wm8994_type {
21 	WM8994 = 0,
22 	WM8958 = 1,
23 	WM1811 = 2,
24 };
25 
26 struct regulator_dev;
27 struct regulator_bulk_data;
28 struct regmap;
29 
30 #define WM8994_NUM_GPIO_REGS 11
31 #define WM8994_NUM_LDO_REGS   2
32 #define WM8994_NUM_IRQ_REGS   2
33 
34 #define WM8994_IRQ_TEMP_SHUT		0
35 #define WM8994_IRQ_MIC1_DET		1
36 #define WM8994_IRQ_MIC1_SHRT		2
37 #define WM8994_IRQ_MIC2_DET		3
38 #define WM8994_IRQ_MIC2_SHRT		4
39 #define WM8994_IRQ_FLL1_LOCK		5
40 #define WM8994_IRQ_FLL2_LOCK		6
41 #define WM8994_IRQ_SRC1_LOCK		7
42 #define WM8994_IRQ_SRC2_LOCK		8
43 #define WM8994_IRQ_AIF1DRC1_SIG_DET	9
44 #define WM8994_IRQ_AIF1DRC2_SIG_DET	10
45 #define WM8994_IRQ_AIF2DRC_SIG_DET	11
46 #define WM8994_IRQ_FIFOS_ERR		12
47 #define WM8994_IRQ_WSEQ_DONE		13
48 #define WM8994_IRQ_DCS_DONE		14
49 #define WM8994_IRQ_TEMP_WARN		15
50 
51 /* GPIOs in the chip are numbered from 1-11 */
52 #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
53 
54 struct wm8994 {
55 	struct mutex irq_lock;
56 
57 	enum wm8994_type type;
58 
59 	struct device *dev;
60 	struct regmap *regmap;
61 
62 	int gpio_base;
63 	int irq_base;
64 
65 	int irq;
66 	u16 irq_masks_cur[WM8994_NUM_IRQ_REGS];
67 	u16 irq_masks_cache[WM8994_NUM_IRQ_REGS];
68 
69 	/* Used over suspend/resume */
70 	bool suspended;
71 	u16 ldo_regs[WM8994_NUM_LDO_REGS];
72 	u16 gpio_regs[WM8994_NUM_GPIO_REGS];
73 
74 	struct regulator_dev *dbvdd;
75 	int num_supplies;
76 	struct regulator_bulk_data *supplies;
77 };
78 
79 /* Device I/O API */
80 int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg);
81 int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
82 		 unsigned short val);
83 int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
84 		    unsigned short mask, unsigned short val);
85 int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
86 		     int count, u16 *buf);
87 int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
88 		     int count, const u16 *buf);
89 
90 
91 /* Helper to save on boilerplate */
92 static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
93 				     irq_handler_t handler, const char *name,
94 				     void *data)
95 {
96 	if (!wm8994->irq_base)
97 		return -EINVAL;
98 	return request_threaded_irq(wm8994->irq_base + irq, NULL, handler,
99 				    IRQF_TRIGGER_RISING, name,
100 				    data);
101 }
102 static inline void wm8994_free_irq(struct wm8994 *wm8994, int irq, void *data)
103 {
104 	if (!wm8994->irq_base)
105 		return;
106 	free_irq(wm8994->irq_base + irq, data);
107 }
108 
109 int wm8994_irq_init(struct wm8994 *wm8994);
110 void wm8994_irq_exit(struct wm8994 *wm8994);
111 
112 #endif
113