]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/mfd/wm8994/core.h
UBUNTU: Ubuntu-4.15.0-96.97
[mirror_ubuntu-bionic-kernel.git] / include / linux / mfd / wm8994 / core.h
CommitLineData
9e501086
MB
1/*
2 * include/linux/mfd/wm8994/core.h -- Core interface for WM8994
3 *
4 * Copyright 2009 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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
19f95571 18#include <linux/mutex.h>
c9fbf7e0 19#include <linux/interrupt.h>
6550334f 20#include <linux/regmap.h>
c9fbf7e0 21
a8a8fc28
MB
22#include <linux/mfd/wm8994/pdata.h>
23
559e0df6
MB
24enum wm8994_type {
25 WM8994 = 0,
26 WM8958 = 1,
b1f43bf3 27 WM1811 = 2,
559e0df6
MB
28};
29
9e501086
MB
30struct regulator_dev;
31struct regulator_bulk_data;
7c884448 32struct irq_domain;
9e501086
MB
33
34#define WM8994_NUM_GPIO_REGS 11
c9fbf7e0
MB
35#define WM8994_NUM_LDO_REGS 2
36#define WM8994_NUM_IRQ_REGS 2
37
38#define WM8994_IRQ_TEMP_SHUT 0
39#define WM8994_IRQ_MIC1_DET 1
40#define WM8994_IRQ_MIC1_SHRT 2
41#define WM8994_IRQ_MIC2_DET 3
42#define WM8994_IRQ_MIC2_SHRT 4
43#define WM8994_IRQ_FLL1_LOCK 5
44#define WM8994_IRQ_FLL2_LOCK 6
45#define WM8994_IRQ_SRC1_LOCK 7
46#define WM8994_IRQ_SRC2_LOCK 8
47#define WM8994_IRQ_AIF1DRC1_SIG_DET 9
48#define WM8994_IRQ_AIF1DRC2_SIG_DET 10
49#define WM8994_IRQ_AIF2DRC_SIG_DET 11
50#define WM8994_IRQ_FIFOS_ERR 12
51#define WM8994_IRQ_WSEQ_DONE 13
52#define WM8994_IRQ_DCS_DONE 14
53#define WM8994_IRQ_TEMP_WARN 15
54
55/* GPIOs in the chip are numbered from 1-11 */
56#define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
9e501086
MB
57
58struct wm8994 {
a8a8fc28
MB
59 struct wm8994_pdata pdata;
60
559e0df6 61 enum wm8994_type type;
7ed5849c 62 int revision;
cc7a7279 63 int cust_id;
559e0df6 64
9e501086 65 struct device *dev;
d6c645fc 66 struct regmap *regmap;
9e501086 67
881de670
MB
68 bool ldo_ena_always_driven;
69
9e501086 70 int gpio_base;
c9fbf7e0
MB
71 int irq_base;
72
73 int irq;
8ab30691 74 struct regmap_irq_chip_data *irq_data;
7c884448 75 struct irq_domain *edge_irq;
9e501086
MB
76
77 /* Used over suspend/resume */
77bd70e9 78 bool suspended;
9e501086
MB
79
80 struct regulator_dev *dbvdd;
559e0df6 81 int num_supplies;
9e501086
MB
82 struct regulator_bulk_data *supplies;
83};
84
85/* Device I/O API */
9e501086 86
b5f90240
MB
87static inline int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
88{
89 unsigned int val;
90 int ret;
91
92 ret = regmap_read(wm8994->regmap, reg, &val);
93
94 if (ret < 0)
95 return ret;
96 else
97 return val;
98}
99
100static inline int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
101 unsigned short val)
102{
103 return regmap_write(wm8994->regmap, reg, val);
104}
105
106static inline int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
107 int count, u16 *buf)
108{
109 return regmap_bulk_read(wm8994->regmap, reg, buf, count);
110}
111
112static inline int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
113 int count, const u16 *buf)
114{
115 return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
116}
117
118static inline int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
119 unsigned short mask, unsigned short val)
120{
121 return regmap_update_bits(wm8994->regmap, reg, mask, val);
122}
c9fbf7e0
MB
123
124/* Helper to save on boilerplate */
125static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
126 irq_handler_t handler, const char *name,
127 void *data)
128{
6550334f 129 if (!wm8994->irq_data)
c9fbf7e0 130 return -EINVAL;
6550334f
MB
131 return request_threaded_irq(regmap_irq_get_virq(wm8994->irq_data, irq),
132 NULL, handler, IRQF_TRIGGER_RISING, name,
c9fbf7e0
MB
133 data);
134}
135static inline void wm8994_free_irq(struct wm8994 *wm8994, int irq, void *data)
136{
6550334f 137 if (!wm8994->irq_data)
c9fbf7e0 138 return;
6550334f 139 free_irq(regmap_irq_get_virq(wm8994->irq_data, irq), data);
c9fbf7e0
MB
140}
141
142int wm8994_irq_init(struct wm8994 *wm8994);
143void wm8994_irq_exit(struct wm8994 *wm8994);
144
9e501086 145#endif