Blame view

drivers/mfd/da9055-core.c 9.47 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
2896434cf   Ashish Jangam   mfd: DA9055 core ...
2
3
4
5
6
7
  /*
   * Device access for Dialog DA9055 PMICs.
   *
   * Copyright(c) 2012 Dialog Semiconductor Ltd.
   *
   * Author: David Dajun Chen <dchen@diasemi.com>
2896434cf   Ashish Jangam   mfd: DA9055 core ...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
   */
  
  #include <linux/module.h>
  #include <linux/device.h>
  #include <linux/input.h>
  #include <linux/irq.h>
  #include <linux/mutex.h>
  
  #include <linux/mfd/core.h>
  #include <linux/mfd/da9055/core.h>
  #include <linux/mfd/da9055/pdata.h>
  #include <linux/mfd/da9055/reg.h>
  
  #define DA9055_IRQ_NONKEY_MASK		0x01
  #define DA9055_IRQ_ALM_MASK		0x02
  #define DA9055_IRQ_TICK_MASK		0x04
  #define DA9055_IRQ_ADC_MASK		0x08
  #define DA9055_IRQ_BUCK_ILIM_MASK	0x08
  
  static bool da9055_register_readable(struct device *dev, unsigned int reg)
  {
  	switch (reg) {
  	case DA9055_REG_STATUS_A:
  	case DA9055_REG_STATUS_B:
  	case DA9055_REG_EVENT_A:
  	case DA9055_REG_EVENT_B:
  	case DA9055_REG_EVENT_C:
  	case DA9055_REG_IRQ_MASK_A:
  	case DA9055_REG_IRQ_MASK_B:
  	case DA9055_REG_IRQ_MASK_C:
  
  	case DA9055_REG_CONTROL_A:
  	case DA9055_REG_CONTROL_B:
  	case DA9055_REG_CONTROL_C:
  	case DA9055_REG_CONTROL_D:
  	case DA9055_REG_CONTROL_E:
  
  	case DA9055_REG_ADC_MAN:
  	case DA9055_REG_ADC_CONT:
  	case DA9055_REG_VSYS_MON:
  	case DA9055_REG_ADC_RES_L:
  	case DA9055_REG_ADC_RES_H:
  	case DA9055_REG_VSYS_RES:
  	case DA9055_REG_ADCIN1_RES:
  	case DA9055_REG_ADCIN2_RES:
  	case DA9055_REG_ADCIN3_RES:
  
  	case DA9055_REG_COUNT_S:
  	case DA9055_REG_COUNT_MI:
  	case DA9055_REG_COUNT_H:
  	case DA9055_REG_COUNT_D:
  	case DA9055_REG_COUNT_MO:
  	case DA9055_REG_COUNT_Y:
  	case DA9055_REG_ALARM_H:
  	case DA9055_REG_ALARM_D:
  	case DA9055_REG_ALARM_MI:
  	case DA9055_REG_ALARM_MO:
  	case DA9055_REG_ALARM_Y:
  
  	case DA9055_REG_GPIO0_1:
  	case DA9055_REG_GPIO2:
  	case DA9055_REG_GPIO_MODE0_2:
  
  	case DA9055_REG_BCORE_CONT:
  	case DA9055_REG_BMEM_CONT:
  	case DA9055_REG_LDO1_CONT:
  	case DA9055_REG_LDO2_CONT:
  	case DA9055_REG_LDO3_CONT:
  	case DA9055_REG_LDO4_CONT:
  	case DA9055_REG_LDO5_CONT:
  	case DA9055_REG_LDO6_CONT:
  	case DA9055_REG_BUCK_LIM:
  	case DA9055_REG_BCORE_MODE:
  	case DA9055_REG_VBCORE_A:
  	case DA9055_REG_VBMEM_A:
  	case DA9055_REG_VLDO1_A:
  	case DA9055_REG_VLDO2_A:
  	case DA9055_REG_VLDO3_A:
  	case DA9055_REG_VLDO4_A:
  	case DA9055_REG_VLDO5_A:
  	case DA9055_REG_VLDO6_A:
  	case DA9055_REG_VBCORE_B:
  	case DA9055_REG_VBMEM_B:
  	case DA9055_REG_VLDO1_B:
  	case DA9055_REG_VLDO2_B:
  	case DA9055_REG_VLDO3_B:
  	case DA9055_REG_VLDO4_B:
  	case DA9055_REG_VLDO5_B:
  	case DA9055_REG_VLDO6_B:
  		return true;
  	default:
  		return false;
  	}
  }
  
  static bool da9055_register_writeable(struct device *dev, unsigned int reg)
  {
  	switch (reg) {
  	case DA9055_REG_STATUS_A:
  	case DA9055_REG_STATUS_B:
  	case DA9055_REG_EVENT_A:
  	case DA9055_REG_EVENT_B:
  	case DA9055_REG_EVENT_C:
  	case DA9055_REG_IRQ_MASK_A:
  	case DA9055_REG_IRQ_MASK_B:
  	case DA9055_REG_IRQ_MASK_C:
  
  	case DA9055_REG_CONTROL_A:
  	case DA9055_REG_CONTROL_B:
  	case DA9055_REG_CONTROL_C:
  	case DA9055_REG_CONTROL_D:
  	case DA9055_REG_CONTROL_E:
  
  	case DA9055_REG_ADC_MAN:
  	case DA9055_REG_ADC_CONT:
  	case DA9055_REG_VSYS_MON:
  	case DA9055_REG_ADC_RES_L:
  	case DA9055_REG_ADC_RES_H:
  	case DA9055_REG_VSYS_RES:
  	case DA9055_REG_ADCIN1_RES:
  	case DA9055_REG_ADCIN2_RES:
  	case DA9055_REG_ADCIN3_RES:
  
  	case DA9055_REG_COUNT_S:
  	case DA9055_REG_COUNT_MI:
  	case DA9055_REG_COUNT_H:
  	case DA9055_REG_COUNT_D:
  	case DA9055_REG_COUNT_MO:
  	case DA9055_REG_COUNT_Y:
  	case DA9055_REG_ALARM_H:
  	case DA9055_REG_ALARM_D:
  	case DA9055_REG_ALARM_MI:
  	case DA9055_REG_ALARM_MO:
  	case DA9055_REG_ALARM_Y:
  
  	case DA9055_REG_GPIO0_1:
  	case DA9055_REG_GPIO2:
  	case DA9055_REG_GPIO_MODE0_2:
  
  	case DA9055_REG_BCORE_CONT:
  	case DA9055_REG_BMEM_CONT:
  	case DA9055_REG_LDO1_CONT:
  	case DA9055_REG_LDO2_CONT:
  	case DA9055_REG_LDO3_CONT:
  	case DA9055_REG_LDO4_CONT:
  	case DA9055_REG_LDO5_CONT:
  	case DA9055_REG_LDO6_CONT:
  	case DA9055_REG_BUCK_LIM:
  	case DA9055_REG_BCORE_MODE:
  	case DA9055_REG_VBCORE_A:
  	case DA9055_REG_VBMEM_A:
  	case DA9055_REG_VLDO1_A:
  	case DA9055_REG_VLDO2_A:
  	case DA9055_REG_VLDO3_A:
  	case DA9055_REG_VLDO4_A:
  	case DA9055_REG_VLDO5_A:
  	case DA9055_REG_VLDO6_A:
  	case DA9055_REG_VBCORE_B:
  	case DA9055_REG_VBMEM_B:
  	case DA9055_REG_VLDO1_B:
  	case DA9055_REG_VLDO2_B:
  	case DA9055_REG_VLDO3_B:
  	case DA9055_REG_VLDO4_B:
  	case DA9055_REG_VLDO5_B:
  	case DA9055_REG_VLDO6_B:
  		return true;
  	default:
  		return false;
  	}
  }
  
  static bool da9055_register_volatile(struct device *dev, unsigned int reg)
  {
  	switch (reg) {
  	case DA9055_REG_STATUS_A:
  	case DA9055_REG_STATUS_B:
  	case DA9055_REG_EVENT_A:
  	case DA9055_REG_EVENT_B:
  	case DA9055_REG_EVENT_C:
  
  	case DA9055_REG_CONTROL_A:
  	case DA9055_REG_CONTROL_E:
  
  	case DA9055_REG_ADC_MAN:
  	case DA9055_REG_ADC_RES_L:
  	case DA9055_REG_ADC_RES_H:
  	case DA9055_REG_VSYS_RES:
  	case DA9055_REG_ADCIN1_RES:
  	case DA9055_REG_ADCIN2_RES:
  	case DA9055_REG_ADCIN3_RES:
  
  	case DA9055_REG_COUNT_S:
  	case DA9055_REG_COUNT_MI:
  	case DA9055_REG_COUNT_H:
  	case DA9055_REG_COUNT_D:
  	case DA9055_REG_COUNT_MO:
  	case DA9055_REG_COUNT_Y:
  	case DA9055_REG_ALARM_MI:
  
  	case DA9055_REG_BCORE_CONT:
  	case DA9055_REG_BMEM_CONT:
  	case DA9055_REG_LDO1_CONT:
  	case DA9055_REG_LDO2_CONT:
  	case DA9055_REG_LDO3_CONT:
  	case DA9055_REG_LDO4_CONT:
  	case DA9055_REG_LDO5_CONT:
  	case DA9055_REG_LDO6_CONT:
  		return true;
  	default:
  		return false;
  	}
  }
7ce7b26f8   Krzysztof Kozlowski   mfd: Constify reg...
220
  static const struct regmap_irq da9055_irqs[] = {
2896434cf   Ashish Jangam   mfd: DA9055 core ...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
  	[DA9055_IRQ_NONKEY] = {
  		.reg_offset = 0,
  		.mask = DA9055_IRQ_NONKEY_MASK,
  	},
  	[DA9055_IRQ_ALARM] = {
  		.reg_offset = 0,
  		.mask = DA9055_IRQ_ALM_MASK,
  	},
  	[DA9055_IRQ_TICK] = {
  		.reg_offset = 0,
  		.mask = DA9055_IRQ_TICK_MASK,
  	},
  	[DA9055_IRQ_HWMON] = {
  		.reg_offset = 0,
  		.mask = DA9055_IRQ_ADC_MASK,
  	},
  	[DA9055_IRQ_REGULATOR] = {
  		.reg_offset = 1,
  		.mask = DA9055_IRQ_BUCK_ILIM_MASK,
  	},
  };
7ce7b26f8   Krzysztof Kozlowski   mfd: Constify reg...
242
  const struct regmap_config da9055_regmap_config = {
2896434cf   Ashish Jangam   mfd: DA9055 core ...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  	.reg_bits = 8,
  	.val_bits = 8,
  
  	.cache_type = REGCACHE_RBTREE,
  
  	.max_register = DA9055_MAX_REGISTER_CNT,
  	.readable_reg = da9055_register_readable,
  	.writeable_reg = da9055_register_writeable,
  	.volatile_reg = da9055_register_volatile,
  };
  EXPORT_SYMBOL_GPL(da9055_regmap_config);
  
  static struct resource da9055_onkey_resource = {
  	.name = "ONKEY",
  	.start = DA9055_IRQ_NONKEY,
  	.end   = DA9055_IRQ_NONKEY,
  	.flags = IORESOURCE_IRQ,
  };
  
  static struct resource da9055_rtc_resource[] = {
  	{
  		.name = "ALM",
  		.start = DA9055_IRQ_ALARM,
  		.end   = DA9055_IRQ_ALARM,
  		.flags = IORESOURCE_IRQ,
  	},
  	{
  		.name = "TICK",
  		.start = DA9055_IRQ_TICK,
  		.end   = DA9055_IRQ_TICK,
  		.flags = IORESOURCE_IRQ,
  	},
  };
  
  static struct resource da9055_hwmon_resource = {
  	.name = "HWMON",
  	.start = DA9055_IRQ_HWMON,
  	.end   = DA9055_IRQ_HWMON,
  	.flags = IORESOURCE_IRQ,
  };
  
  static struct resource da9055_ld05_6_resource = {
  	.name = "REGULATOR",
  	.start = DA9055_IRQ_REGULATOR,
  	.end   = DA9055_IRQ_REGULATOR,
  	.flags = IORESOURCE_IRQ,
  };
c8f675ff3   Geert Uytterhoeven   mfd: dialog: Cons...
290
  static const struct mfd_cell da9055_devs[] = {
2896434cf   Ashish Jangam   mfd: DA9055 core ...
291
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
292
  		.of_compatible = "dlg,da9055-gpio",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
293
294
295
  		.name = "da9055-gpio",
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
296
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
297
298
299
300
  		.name = "da9055-regulator",
  		.id = 1,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
301
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
302
303
304
305
  		.name = "da9055-regulator",
  		.id = 2,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
306
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
307
308
309
310
  		.name = "da9055-regulator",
  		.id = 3,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
311
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
312
313
314
315
  		.name = "da9055-regulator",
  		.id = 4,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
316
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
317
318
319
320
  		.name = "da9055-regulator",
  		.id = 5,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
321
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
322
323
324
325
  		.name = "da9055-regulator",
  		.id = 6,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
326
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
327
328
329
330
331
332
  		.name = "da9055-regulator",
  		.id = 7,
  		.resources = &da9055_ld05_6_resource,
  		.num_resources = 1,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
333
  		.of_compatible = "dlg,da9055-regulator",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
334
335
336
337
338
339
  		.name = "da9055-regulator",
  		.resources = &da9055_ld05_6_resource,
  		.num_resources = 1,
  		.id = 8,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
340
  		.of_compatible = "dlg,da9055-onkey",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
341
342
343
344
345
  		.name = "da9055-onkey",
  		.resources = &da9055_onkey_resource,
  		.num_resources = 1,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
346
  		.of_compatible = "dlg,da9055-rtc",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
347
348
349
350
351
  		.name = "da9055-rtc",
  		.resources = da9055_rtc_resource,
  		.num_resources = ARRAY_SIZE(da9055_rtc_resource),
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
352
  		.of_compatible = "dlg,da9055-hwmon",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
353
354
355
356
357
  		.name = "da9055-hwmon",
  		.resources = &da9055_hwmon_resource,
  		.num_resources = 1,
  	},
  	{
bd597f47c   Steve Twiss   devicetree: Dialo...
358
  		.of_compatible = "dlg,da9055-watchdog",
2896434cf   Ashish Jangam   mfd: DA9055 core ...
359
360
361
  		.name = "da9055-watchdog",
  	},
  };
7ce7b26f8   Krzysztof Kozlowski   mfd: Constify reg...
362
  static const struct regmap_irq_chip da9055_regmap_irq_chip = {
2896434cf   Ashish Jangam   mfd: DA9055 core ...
363
364
365
366
367
368
369
370
  	.name = "da9055_irq",
  	.status_base = DA9055_REG_EVENT_A,
  	.mask_base = DA9055_REG_IRQ_MASK_A,
  	.ack_base = DA9055_REG_EVENT_A,
  	.num_regs = 3,
  	.irqs = da9055_irqs,
  	.num_irqs = ARRAY_SIZE(da9055_irqs),
  };
f791be492   Bill Pemberton   mfd: remove use o...
371
  int da9055_device_init(struct da9055 *da9055)
2896434cf   Ashish Jangam   mfd: DA9055 core ...
372
  {
334a41ce9   Jingoo Han   mfd: Use dev_get_...
373
  	struct da9055_pdata *pdata = dev_get_platdata(da9055->dev);
2896434cf   Ashish Jangam   mfd: DA9055 core ...
374
  	int ret;
4b3b4a501   Ankur Raina   mfd: Fix for DA90...
375
  	uint8_t clear_events[3] = {0xFF, 0xFF, 0xFF};
2896434cf   Ashish Jangam   mfd: DA9055 core ...
376
377
378
379
380
381
382
383
  
  	if (pdata && pdata->init != NULL)
  		pdata->init(da9055);
  
  	if (!pdata || !pdata->irq_base)
  		da9055->irq_base = -1;
  	else
  		da9055->irq_base = pdata->irq_base;
4b3b4a501   Ankur Raina   mfd: Fix for DA90...
384
385
386
  	ret = da9055_group_write(da9055, DA9055_REG_EVENT_A, 3, clear_events);
  	if (ret < 0)
  		return ret;
2896434cf   Ashish Jangam   mfd: DA9055 core ...
387
  	ret = regmap_add_irq_chip(da9055->regmap, da9055->chip_irq,
3cec5f4e7   Ashish Jangam   mfd: da9055: Chan...
388
  				  IRQF_TRIGGER_LOW | IRQF_ONESHOT,
2896434cf   Ashish Jangam   mfd: DA9055 core ...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
  				  da9055->irq_base, &da9055_regmap_irq_chip,
  				  &da9055->irq_data);
  	if (ret < 0)
  		return ret;
  
  	da9055->irq_base = regmap_irq_chip_get_base(da9055->irq_data);
  
  	ret = mfd_add_devices(da9055->dev, -1,
  			      da9055_devs, ARRAY_SIZE(da9055_devs),
  			      NULL, da9055->irq_base, NULL);
  	if (ret)
  		goto err;
  
  	return 0;
  
  err:
  	mfd_remove_devices(da9055->dev);
  	return ret;
  }
4740f73fe   Bill Pemberton   mfd: remove use o...
408
  void da9055_device_exit(struct da9055 *da9055)
2896434cf   Ashish Jangam   mfd: DA9055 core ...
409
410
411
412
413
414
415
416
  {
  	regmap_del_irq_chip(da9055->chip_irq, da9055->irq_data);
  	mfd_remove_devices(da9055->dev);
  }
  
  MODULE_DESCRIPTION("Core support for the DA9055 PMIC");
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");