Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * include/linux/mfd/wm8994/core.h -- Core interface for WM8994
0004  *
0005  * Copyright 2009 Wolfson Microelectronics PLC.
0006  *
0007  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
0008  */
0009 
0010 #ifndef __MFD_WM8994_CORE_H__
0011 #define __MFD_WM8994_CORE_H__
0012 
0013 #include <linux/mutex.h>
0014 #include <linux/interrupt.h>
0015 #include <linux/regmap.h>
0016 
0017 #include <linux/mfd/wm8994/pdata.h>
0018 
0019 enum wm8994_type {
0020     WM8994 = 0,
0021     WM8958 = 1,
0022     WM1811 = 2,
0023 };
0024 
0025 struct regulator_dev;
0026 struct regulator_bulk_data;
0027 struct irq_domain;
0028 
0029 #define WM8994_NUM_GPIO_REGS 11
0030 #define WM8994_NUM_LDO_REGS   2
0031 #define WM8994_NUM_IRQ_REGS   2
0032 
0033 #define WM8994_IRQ_TEMP_SHUT        0
0034 #define WM8994_IRQ_MIC1_DET     1
0035 #define WM8994_IRQ_MIC1_SHRT        2
0036 #define WM8994_IRQ_MIC2_DET     3
0037 #define WM8994_IRQ_MIC2_SHRT        4
0038 #define WM8994_IRQ_FLL1_LOCK        5
0039 #define WM8994_IRQ_FLL2_LOCK        6
0040 #define WM8994_IRQ_SRC1_LOCK        7
0041 #define WM8994_IRQ_SRC2_LOCK        8
0042 #define WM8994_IRQ_AIF1DRC1_SIG_DET 9
0043 #define WM8994_IRQ_AIF1DRC2_SIG_DET 10
0044 #define WM8994_IRQ_AIF2DRC_SIG_DET  11
0045 #define WM8994_IRQ_FIFOS_ERR        12
0046 #define WM8994_IRQ_WSEQ_DONE        13
0047 #define WM8994_IRQ_DCS_DONE     14
0048 #define WM8994_IRQ_TEMP_WARN        15
0049 
0050 /* GPIOs in the chip are numbered from 1-11 */
0051 #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
0052 
0053 struct wm8994 {
0054     struct wm8994_pdata pdata;
0055 
0056     enum wm8994_type type;
0057     int revision;
0058     int cust_id;
0059 
0060     struct device *dev;
0061     struct regmap *regmap;
0062 
0063     bool ldo_ena_always_driven;
0064 
0065     int gpio_base;
0066     int irq_base;
0067 
0068     int irq;
0069     struct regmap_irq_chip_data *irq_data;
0070     struct irq_domain *edge_irq;
0071 
0072     /* Used over suspend/resume */
0073     bool suspended;
0074 
0075     struct regulator_dev *dbvdd;
0076     int num_supplies;
0077     struct regulator_bulk_data *supplies;
0078 };
0079 
0080 /* Device I/O API */
0081 
0082 static inline int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
0083 {
0084     unsigned int val;
0085     int ret;
0086 
0087     ret = regmap_read(wm8994->regmap, reg, &val);
0088 
0089     if (ret < 0)
0090         return ret;
0091     else
0092         return val;
0093 }
0094 
0095 static inline int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
0096                    unsigned short val)
0097 {
0098     return regmap_write(wm8994->regmap, reg, val);
0099 }
0100 
0101 static inline int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
0102                    int count, u16 *buf)
0103 {
0104     return regmap_bulk_read(wm8994->regmap, reg, buf, count);
0105 }
0106 
0107 static inline int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
0108                     int count, const u16 *buf)
0109 {
0110     return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
0111 }
0112 
0113 static inline int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
0114             unsigned short mask, unsigned short val)
0115 {
0116     return regmap_update_bits(wm8994->regmap, reg, mask, val);
0117 }
0118 
0119 /* Helper to save on boilerplate */
0120 static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
0121                      irq_handler_t handler, const char *name,
0122                      void *data)
0123 {
0124     if (!wm8994->irq_data)
0125         return -EINVAL;
0126     return request_threaded_irq(regmap_irq_get_virq(wm8994->irq_data, irq),
0127                     NULL, handler, IRQF_TRIGGER_RISING, name,
0128                     data);
0129 }
0130 static inline void wm8994_free_irq(struct wm8994 *wm8994, int irq, void *data)
0131 {
0132     if (!wm8994->irq_data)
0133         return;
0134     free_irq(regmap_irq_get_virq(wm8994->irq_data, irq), data);
0135 }
0136 
0137 int wm8994_irq_init(struct wm8994 *wm8994);
0138 void wm8994_irq_exit(struct wm8994 *wm8994);
0139 
0140 #endif