blob: 75366b55f16c6ade375e83c2dbddcc12d82132ac [file] [log] [blame]
Mattias Wallin5814fc32010-09-13 16:05:04 +02001/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
6 */
carriere etienne0fbce762011-04-08 16:26:36 +02007/*
8 * AB8500 register access
9 * ======================
10 *
11 * read:
12 * # echo BANK > <debugfs>/ab8500/register-bank
13 * # echo ADDR > <debugfs>/ab8500/register-address
14 * # cat <debugfs>/ab8500/register-value
15 *
16 * write:
17 * # echo BANK > <debugfs>/ab8500/register-bank
18 * # echo ADDR > <debugfs>/ab8500/register-address
19 * # echo VALUE > <debugfs>/ab8500/register-value
20 *
21 * read all registers from a bank:
22 * # echo BANK > <debugfs>/ab8500/register-bank
23 * # cat <debugfs>/ab8500/all-bank-register
24 *
25 * BANK target AB8500 register bank
26 * ADDR target AB8500 register address
27 * VALUE decimal or 0x-prefixed hexadecimal
28 *
29 *
30 * User Space notification on AB8500 IRQ
31 * =====================================
32 *
33 * Allows user space entity to be notified when target AB8500 IRQ occurs.
34 * When subscribed, a sysfs entry is created in ab8500.i2c platform device.
35 * One can pool this file to get target IRQ occurence information.
36 *
37 * subscribe to an AB8500 IRQ:
38 * # echo IRQ > <debugfs>/ab8500/irq-subscribe
39 *
40 * unsubscribe from an AB8500 IRQ:
41 * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe
42 *
43 *
44 * AB8500 register formated read/write access
45 * ==========================================
46 *
47 * Read: read data, data>>SHIFT, data&=MASK, output data
48 * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE
49 * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data
50 * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98]
51 *
52 * Usage:
53 * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
54 *
55 * CMD read read access
56 * write write access
57 *
58 * BANK target reg bank
59 * ADDRESS target reg address
60 * VALUE (write) value to be updated
61 *
62 * OPTIONS
63 * -d|-dec (read) output in decimal
64 * -h|-hexa (read) output in 0x-hexa (default)
65 * -l|-w|-b 32bit (default), 16bit or 8bit reg access
66 * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF)
67 * -s|-shift SHIFT bit shift value (read:left, write:right)
68 * -o|-offset OFFSET address offset to add to ADDRESS value
69 *
70 * Warning: bit shift operation is applied to bit-mask.
71 * Warning: bit shift direction depends on read or right command.
72 */
Mattias Wallin5814fc32010-09-13 16:05:04 +020073
74#include <linux/seq_file.h>
75#include <linux/uaccess.h>
76#include <linux/fs.h>
Paul Gortmaker4e36dd32011-07-03 15:13:27 -040077#include <linux/module.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020078#include <linux/debugfs.h>
79#include <linux/platform_device.h>
Lee Jones4b8ac082013-01-14 16:10:36 +000080#include <linux/interrupt.h>
81#include <linux/kobject.h>
82#include <linux/slab.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020083
84#include <linux/mfd/abx500.h>
Linus Walleij0cd5b6d02013-02-06 23:23:01 +010085#include <linux/mfd/abx500/ab8500.h>
John Beckett1478a312011-05-31 13:54:27 +010086#include <linux/mfd/abx500/ab8500-gpadc.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020087
carriere etienne0fbce762011-04-08 16:26:36 +020088#ifdef CONFIG_DEBUG_FS
89#include <linux/string.h>
90#include <linux/ctype.h>
91#endif
92
Mattias Wallin5814fc32010-09-13 16:05:04 +020093static u32 debug_bank;
94static u32 debug_address;
95
Lee Jones4b8ac082013-01-14 16:10:36 +000096static int irq_first;
97static int irq_last;
Linus Walleijddba25f2012-02-03 11:19:05 +010098static u32 *irq_count;
99static int num_irqs;
Mattias Wallin0b337e72010-11-19 17:55:11 +0100100
Linus Walleijddba25f2012-02-03 11:19:05 +0100101static struct device_attribute **dev_attr;
102static char **event_name;
Lee Jones4b8ac082013-01-14 16:10:36 +0000103
Lee Jones73482342013-02-26 10:06:55 +0000104static u8 avg_sample = SAMPLE_16;
105static u8 trig_edge = RISING_EDGE;
106static u8 conv_type = ADC_SW;
107static u8 trig_timer;
108
Mattias Wallin5814fc32010-09-13 16:05:04 +0200109/**
110 * struct ab8500_reg_range
111 * @first: the first address of the range
112 * @last: the last address of the range
113 * @perm: access permissions for the range
114 */
115struct ab8500_reg_range {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100116 u8 first;
117 u8 last;
118 u8 perm;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200119};
120
121/**
Lee Jones822672a2012-06-20 13:56:38 +0100122 * struct ab8500_prcmu_ranges
Mattias Wallin5814fc32010-09-13 16:05:04 +0200123 * @num_ranges: the number of ranges in the list
124 * @bankid: bank identifier
125 * @range: the list of register ranges
126 */
Lee Jones822672a2012-06-20 13:56:38 +0100127struct ab8500_prcmu_ranges {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100128 u8 num_ranges;
129 u8 bankid;
130 const struct ab8500_reg_range *range;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200131};
132
carriere etienne0fbce762011-04-08 16:26:36 +0200133/* hwreg- "mask" and "shift" entries ressources */
134struct hwreg_cfg {
135 u32 bank; /* target bank */
136 u32 addr; /* target address */
137 uint fmt; /* format */
138 uint mask; /* read/write mask, applied before any bit shift */
139 int shift; /* bit shift (read:right shift, write:left shift */
140};
141/* fmt bit #0: 0=hexa, 1=dec */
142#define REG_FMT_DEC(c) ((c)->fmt & 0x1)
143#define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
144
145static struct hwreg_cfg hwreg_cfg = {
146 .addr = 0, /* default: invalid phys addr */
147 .fmt = 0, /* default: 32bit access, hex output */
148 .mask = 0xFFFFFFFF, /* default: no mask */
149 .shift = 0, /* default: no bit shift */
150};
151
Mattias Wallin5814fc32010-09-13 16:05:04 +0200152#define AB8500_NAME_STRING "ab8500"
John Beckett1478a312011-05-31 13:54:27 +0100153#define AB8500_ADC_NAME_STRING "gpadc"
Philippe Langlais40c064e2011-10-17 09:48:55 +0200154#define AB8500_NUM_BANKS 24
Mattias Wallin5814fc32010-09-13 16:05:04 +0200155
156#define AB8500_REV_REG 0x80
157
Lee Jones822672a2012-06-20 13:56:38 +0100158static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100159 [0x0] = {
160 .num_ranges = 0,
Lee Jonesfad55a82013-01-14 17:17:34 +0000161 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100162 },
163 [AB8500_SYS_CTRL1_BLOCK] = {
164 .num_ranges = 3,
165 .range = (struct ab8500_reg_range[]) {
166 {
167 .first = 0x00,
168 .last = 0x02,
169 },
170 {
171 .first = 0x42,
172 .last = 0x42,
173 },
174 {
175 .first = 0x80,
176 .last = 0x81,
177 },
178 },
179 },
180 [AB8500_SYS_CTRL2_BLOCK] = {
181 .num_ranges = 4,
182 .range = (struct ab8500_reg_range[]) {
183 {
184 .first = 0x00,
185 .last = 0x0D,
186 },
187 {
188 .first = 0x0F,
189 .last = 0x17,
190 },
191 {
192 .first = 0x30,
193 .last = 0x30,
194 },
195 {
196 .first = 0x32,
197 .last = 0x33,
198 },
199 },
200 },
201 [AB8500_REGU_CTRL1] = {
202 .num_ranges = 3,
203 .range = (struct ab8500_reg_range[]) {
204 {
205 .first = 0x00,
206 .last = 0x00,
207 },
208 {
209 .first = 0x03,
210 .last = 0x10,
211 },
212 {
213 .first = 0x80,
214 .last = 0x84,
215 },
216 },
217 },
218 [AB8500_REGU_CTRL2] = {
219 .num_ranges = 5,
220 .range = (struct ab8500_reg_range[]) {
221 {
222 .first = 0x00,
223 .last = 0x15,
224 },
225 {
226 .first = 0x17,
227 .last = 0x19,
228 },
229 {
230 .first = 0x1B,
231 .last = 0x1D,
232 },
233 {
234 .first = 0x1F,
235 .last = 0x22,
236 },
237 {
238 .first = 0x40,
239 .last = 0x44,
240 },
241 /* 0x80-0x8B is SIM registers and should
242 * not be accessed from here */
243 },
244 },
245 [AB8500_USB] = {
246 .num_ranges = 2,
247 .range = (struct ab8500_reg_range[]) {
248 {
249 .first = 0x80,
250 .last = 0x83,
251 },
252 {
253 .first = 0x87,
254 .last = 0x8A,
255 },
256 },
257 },
258 [AB8500_TVOUT] = {
259 .num_ranges = 9,
260 .range = (struct ab8500_reg_range[]) {
261 {
262 .first = 0x00,
263 .last = 0x12,
264 },
265 {
266 .first = 0x15,
267 .last = 0x17,
268 },
269 {
270 .first = 0x19,
271 .last = 0x21,
272 },
273 {
274 .first = 0x27,
275 .last = 0x2C,
276 },
277 {
278 .first = 0x41,
279 .last = 0x41,
280 },
281 {
282 .first = 0x45,
283 .last = 0x5B,
284 },
285 {
286 .first = 0x5D,
287 .last = 0x5D,
288 },
289 {
290 .first = 0x69,
291 .last = 0x69,
292 },
293 {
294 .first = 0x80,
295 .last = 0x81,
296 },
297 },
298 },
299 [AB8500_DBI] = {
300 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000301 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100302 },
303 [AB8500_ECI_AV_ACC] = {
304 .num_ranges = 1,
305 .range = (struct ab8500_reg_range[]) {
306 {
307 .first = 0x80,
308 .last = 0x82,
309 },
310 },
311 },
312 [0x9] = {
313 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000314 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100315 },
316 [AB8500_GPADC] = {
317 .num_ranges = 1,
318 .range = (struct ab8500_reg_range[]) {
319 {
320 .first = 0x00,
321 .last = 0x08,
322 },
323 },
324 },
325 [AB8500_CHARGER] = {
Philippe Langlais40c064e2011-10-17 09:48:55 +0200326 .num_ranges = 9,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100327 .range = (struct ab8500_reg_range[]) {
328 {
329 .first = 0x00,
330 .last = 0x03,
331 },
332 {
333 .first = 0x05,
334 .last = 0x05,
335 },
336 {
337 .first = 0x40,
338 .last = 0x40,
339 },
340 {
341 .first = 0x42,
342 .last = 0x42,
343 },
344 {
345 .first = 0x44,
346 .last = 0x44,
347 },
348 {
349 .first = 0x50,
350 .last = 0x55,
351 },
352 {
353 .first = 0x80,
354 .last = 0x82,
355 },
356 {
357 .first = 0xC0,
358 .last = 0xC2,
359 },
Philippe Langlais40c064e2011-10-17 09:48:55 +0200360 {
361 .first = 0xf5,
362 .last = 0xf6,
363 },
Mattias Wallind7b9f322010-11-26 13:06:39 +0100364 },
365 },
366 [AB8500_GAS_GAUGE] = {
367 .num_ranges = 3,
368 .range = (struct ab8500_reg_range[]) {
369 {
370 .first = 0x00,
371 .last = 0x00,
372 },
373 {
374 .first = 0x07,
375 .last = 0x0A,
376 },
377 {
378 .first = 0x10,
379 .last = 0x14,
380 },
381 },
382 },
Philippe Langlais40c064e2011-10-17 09:48:55 +0200383 [AB8500_DEVELOPMENT] = {
384 .num_ranges = 1,
385 .range = (struct ab8500_reg_range[]) {
386 {
387 .first = 0x00,
388 .last = 0x00,
389 },
390 },
391 },
392 [AB8500_DEBUG] = {
393 .num_ranges = 1,
394 .range = (struct ab8500_reg_range[]) {
395 {
396 .first = 0x05,
397 .last = 0x07,
398 },
399 },
400 },
Mattias Wallind7b9f322010-11-26 13:06:39 +0100401 [AB8500_AUDIO] = {
402 .num_ranges = 1,
403 .range = (struct ab8500_reg_range[]) {
404 {
405 .first = 0x00,
406 .last = 0x6F,
407 },
408 },
409 },
410 [AB8500_INTERRUPT] = {
411 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000412 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100413 },
414 [AB8500_RTC] = {
415 .num_ranges = 1,
416 .range = (struct ab8500_reg_range[]) {
417 {
418 .first = 0x00,
419 .last = 0x0F,
420 },
421 },
422 },
423 [AB8500_MISC] = {
424 .num_ranges = 8,
425 .range = (struct ab8500_reg_range[]) {
426 {
427 .first = 0x00,
428 .last = 0x05,
429 },
430 {
431 .first = 0x10,
432 .last = 0x15,
433 },
434 {
435 .first = 0x20,
436 .last = 0x25,
437 },
438 {
439 .first = 0x30,
440 .last = 0x35,
441 },
442 {
443 .first = 0x40,
444 .last = 0x45,
445 },
446 {
447 .first = 0x50,
448 .last = 0x50,
449 },
450 {
451 .first = 0x60,
452 .last = 0x67,
453 },
454 {
455 .first = 0x80,
456 .last = 0x80,
457 },
458 },
459 },
460 [0x11] = {
461 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000462 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100463 },
464 [0x12] = {
465 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000466 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100467 },
468 [0x13] = {
469 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000470 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100471 },
472 [0x14] = {
473 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000474 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100475 },
476 [AB8500_OTP_EMUL] = {
477 .num_ranges = 1,
478 .range = (struct ab8500_reg_range[]) {
479 {
480 .first = 0x01,
481 .last = 0x0F,
482 },
483 },
484 },
Mattias Wallin5814fc32010-09-13 16:05:04 +0200485};
486
Lee Jones4b8ac082013-01-14 16:10:36 +0000487static irqreturn_t ab8500_debug_handler(int irq, void *data)
488{
489 char buf[16];
490 struct kobject *kobj = (struct kobject *)data;
Mattias Wallin0b337e72010-11-19 17:55:11 +0100491 unsigned int irq_abb = irq - irq_first;
Lee Jones4b8ac082013-01-14 16:10:36 +0000492
Linus Walleijddba25f2012-02-03 11:19:05 +0100493 if (irq_abb < num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +0100494 irq_count[irq_abb]++;
Lee Jones4b8ac082013-01-14 16:10:36 +0000495 /*
496 * This makes it possible to use poll for events (POLLPRI | POLLERR)
Mattias Wallin0b337e72010-11-19 17:55:11 +0100497 * from userspace on sysfs file named <irq-nr>
Lee Jones4b8ac082013-01-14 16:10:36 +0000498 */
Mattias Wallin0b337e72010-11-19 17:55:11 +0100499 sprintf(buf, "%d", irq);
Lee Jones4b8ac082013-01-14 16:10:36 +0000500 sysfs_notify(kobj, NULL, buf);
501
502 return IRQ_HANDLED;
503}
504
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100505/* Prints to seq_file or log_buf */
506static int ab8500_registers_print(struct device *dev, u32 bank,
507 struct seq_file *s)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200508{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100509 unsigned int i;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200510
Mattias Wallind7b9f322010-11-26 13:06:39 +0100511 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
512 u32 reg;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200513
Mattias Wallind7b9f322010-11-26 13:06:39 +0100514 for (reg = debug_ranges[bank].range[i].first;
515 reg <= debug_ranges[bank].range[i].last;
516 reg++) {
517 u8 value;
518 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200519
Mattias Wallind7b9f322010-11-26 13:06:39 +0100520 err = abx500_get_register_interruptible(dev,
521 (u8)bank, (u8)reg, &value);
522 if (err < 0) {
523 dev_err(dev, "ab->read fail %d\n", err);
524 return err;
525 }
Mattias Wallin5814fc32010-09-13 16:05:04 +0200526
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100527 if (s) {
Mattias Wallincfc08492012-05-28 15:53:58 +0200528 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100529 bank, reg, value);
530 if (err < 0) {
531 dev_err(dev,
Mattias Wallincfc08492012-05-28 15:53:58 +0200532 "seq_printf overflow bank=0x%02X reg=0x%02X\n",
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100533 bank, reg);
534 /* Error is not returned here since
535 * the output is wanted in any case */
536 return 0;
537 }
538 } else {
Mattias Wallincfc08492012-05-28 15:53:58 +0200539 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
540 bank, reg, value);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100541 }
542 }
543 }
544 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200545}
546
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100547static int ab8500_print_bank_registers(struct seq_file *s, void *p)
548{
549 struct device *dev = s->private;
550 u32 bank = debug_bank;
551
552 seq_printf(s, AB8500_NAME_STRING " register values:\n");
553
Mattias Wallincfc08492012-05-28 15:53:58 +0200554 seq_printf(s, " bank 0x%02X:\n", bank);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100555
556 ab8500_registers_print(dev, bank, s);
557 return 0;
558}
559
Mattias Wallin5814fc32010-09-13 16:05:04 +0200560static int ab8500_registers_open(struct inode *inode, struct file *file)
561{
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100562 return single_open(file, ab8500_print_bank_registers, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200563}
564
565static const struct file_operations ab8500_registers_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100566 .open = ab8500_registers_open,
567 .read = seq_read,
568 .llseek = seq_lseek,
569 .release = single_release,
570 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200571};
572
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100573static int ab8500_print_all_banks(struct seq_file *s, void *p)
574{
575 struct device *dev = s->private;
576 unsigned int i;
577 int err;
578
579 seq_printf(s, AB8500_NAME_STRING " register values:\n");
580
581 for (i = 1; i < AB8500_NUM_BANKS; i++) {
Mattias Wallincfc08492012-05-28 15:53:58 +0200582 err = seq_printf(s, " bank 0x%02X:\n", i);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100583 if (err < 0)
Mattias Wallincfc08492012-05-28 15:53:58 +0200584 dev_err(dev, "seq_printf overflow, bank=0x%02X\n", i);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100585
586 ab8500_registers_print(dev, i, s);
587 }
588 return 0;
589}
590
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +0100591/* Dump registers to kernel log */
592void ab8500_dump_all_banks(struct device *dev)
593{
594 unsigned int i;
595
596 printk(KERN_INFO"ab8500 register values:\n");
597
598 for (i = 1; i < AB8500_NUM_BANKS; i++) {
Mattias Wallincfc08492012-05-28 15:53:58 +0200599 printk(KERN_INFO" bank 0x%02X:\n", i);
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +0100600 ab8500_registers_print(dev, i, NULL);
601 }
602}
603
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +0100604static int ab8500_all_banks_open(struct inode *inode, struct file *file)
605{
606 struct seq_file *s;
607 int err;
608
609 err = single_open(file, ab8500_print_all_banks, inode->i_private);
610 if (!err) {
611 /* Default buf size in seq_read is not enough */
612 s = (struct seq_file *)file->private_data;
613 s->size = (PAGE_SIZE * 2);
614 s->buf = kmalloc(s->size, GFP_KERNEL);
615 if (!s->buf) {
616 single_release(inode, file);
617 err = -ENOMEM;
618 }
619 }
620 return err;
621}
622
623static const struct file_operations ab8500_all_banks_fops = {
624 .open = ab8500_all_banks_open,
625 .read = seq_read,
626 .llseek = seq_lseek,
627 .release = single_release,
628 .owner = THIS_MODULE,
629};
630
Mattias Wallin5814fc32010-09-13 16:05:04 +0200631static int ab8500_bank_print(struct seq_file *s, void *p)
632{
Mattias Wallincfc08492012-05-28 15:53:58 +0200633 return seq_printf(s, "0x%02X\n", debug_bank);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200634}
635
636static int ab8500_bank_open(struct inode *inode, struct file *file)
637{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100638 return single_open(file, ab8500_bank_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200639}
640
641static ssize_t ab8500_bank_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100642 const char __user *user_buf,
643 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200644{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100645 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +0100646 unsigned long user_bank;
647 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200648
Mattias Wallind7b9f322010-11-26 13:06:39 +0100649 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +0200650 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100651 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +0200652 return err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200653
Mattias Wallind7b9f322010-11-26 13:06:39 +0100654 if (user_bank >= AB8500_NUM_BANKS) {
655 dev_err(dev, "debugfs error input > number of banks\n");
656 return -EINVAL;
657 }
Mattias Wallin5814fc32010-09-13 16:05:04 +0200658
Mattias Wallind7b9f322010-11-26 13:06:39 +0100659 debug_bank = user_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200660
Peter Huewe8504d632011-06-06 22:43:32 +0200661 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200662}
663
664static int ab8500_address_print(struct seq_file *s, void *p)
665{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100666 return seq_printf(s, "0x%02X\n", debug_address);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200667}
668
669static int ab8500_address_open(struct inode *inode, struct file *file)
670{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100671 return single_open(file, ab8500_address_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200672}
673
674static ssize_t ab8500_address_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100675 const char __user *user_buf,
676 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200677{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100678 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +0100679 unsigned long user_address;
680 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200681
Mattias Wallind7b9f322010-11-26 13:06:39 +0100682 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +0200683 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100684 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +0200685 return err;
686
Mattias Wallind7b9f322010-11-26 13:06:39 +0100687 if (user_address > 0xff) {
688 dev_err(dev, "debugfs error input > 0xff\n");
689 return -EINVAL;
690 }
691 debug_address = user_address;
Peter Huewe8504d632011-06-06 22:43:32 +0200692 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200693}
694
695static int ab8500_val_print(struct seq_file *s, void *p)
696{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100697 struct device *dev = s->private;
698 int ret;
699 u8 regvalue;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200700
Mattias Wallind7b9f322010-11-26 13:06:39 +0100701 ret = abx500_get_register_interruptible(dev,
702 (u8)debug_bank, (u8)debug_address, &regvalue);
703 if (ret < 0) {
704 dev_err(dev, "abx500_get_reg fail %d, %d\n",
705 ret, __LINE__);
706 return -EINVAL;
707 }
708 seq_printf(s, "0x%02X\n", regvalue);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200709
Mattias Wallind7b9f322010-11-26 13:06:39 +0100710 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200711}
712
713static int ab8500_val_open(struct inode *inode, struct file *file)
714{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100715 return single_open(file, ab8500_val_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200716}
717
718static ssize_t ab8500_val_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100719 const char __user *user_buf,
720 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200721{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100722 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +0100723 unsigned long user_val;
724 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200725
Mattias Wallind7b9f322010-11-26 13:06:39 +0100726 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +0200727 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100728 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +0200729 return err;
730
Mattias Wallind7b9f322010-11-26 13:06:39 +0100731 if (user_val > 0xff) {
732 dev_err(dev, "debugfs error input > 0xff\n");
733 return -EINVAL;
734 }
735 err = abx500_set_register_interruptible(dev,
736 (u8)debug_bank, debug_address, (u8)user_val);
737 if (err < 0) {
738 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
739 return -EINVAL;
740 }
Mattias Wallin5814fc32010-09-13 16:05:04 +0200741
Peter Huewe8504d632011-06-06 22:43:32 +0200742 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200743}
744
carriere etienne0fbce762011-04-08 16:26:36 +0200745/*
Bengt Jonsson8f0eb432012-02-14 13:01:00 +0100746 * Interrupt status
747 */
748static u32 num_interrupts[AB8500_MAX_NR_IRQS];
749static int num_interrupt_lines;
750
751void ab8500_debug_register_interrupt(int line)
752{
753 if (line < num_interrupt_lines)
754 num_interrupts[line]++;
755}
756
757static int ab8500_interrupts_print(struct seq_file *s, void *p)
758{
759 int line;
760
761 seq_printf(s, "irq: number of\n");
762
763 for (line = 0; line < num_interrupt_lines; line++)
764 seq_printf(s, "%3i: %6i\n", line, num_interrupts[line]);
765
766 return 0;
767}
768
769static int ab8500_interrupts_open(struct inode *inode, struct file *file)
770{
771 return single_open(file, ab8500_interrupts_print, inode->i_private);
772}
773
774/*
carriere etienne0fbce762011-04-08 16:26:36 +0200775 * - HWREG DB8500 formated routines
776 */
777static int ab8500_hwreg_print(struct seq_file *s, void *d)
778{
779 struct device *dev = s->private;
780 int ret;
781 u8 regvalue;
782
783 ret = abx500_get_register_interruptible(dev,
784 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
785 if (ret < 0) {
786 dev_err(dev, "abx500_get_reg fail %d, %d\n",
787 ret, __LINE__);
788 return -EINVAL;
789 }
790
791 if (hwreg_cfg.shift >= 0)
792 regvalue >>= hwreg_cfg.shift;
793 else
794 regvalue <<= -hwreg_cfg.shift;
795 regvalue &= hwreg_cfg.mask;
796
797 if (REG_FMT_DEC(&hwreg_cfg))
798 seq_printf(s, "%d\n", regvalue);
799 else
800 seq_printf(s, "0x%02X\n", regvalue);
801 return 0;
802}
803
804static int ab8500_hwreg_open(struct inode *inode, struct file *file)
805{
806 return single_open(file, ab8500_hwreg_print, inode->i_private);
807}
808
John Beckett1478a312011-05-31 13:54:27 +0100809static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
810{
811 int bat_ctrl_raw;
812 int bat_ctrl_convert;
813 struct ab8500_gpadc *gpadc;
814
Philippe Langlais8908c042012-04-18 15:52:59 +0200815 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000816 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
817 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100818 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +0000819 BAT_CTRL, bat_ctrl_raw);
John Beckett1478a312011-05-31 13:54:27 +0100820
821 return seq_printf(s, "%d,0x%X\n",
822 bat_ctrl_convert, bat_ctrl_raw);
823}
824
825static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
826{
827 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
828}
829
830static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
831 .open = ab8500_gpadc_bat_ctrl_open,
832 .read = seq_read,
833 .llseek = seq_lseek,
834 .release = single_release,
835 .owner = THIS_MODULE,
836};
837
838static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
839{
840 int btemp_ball_raw;
841 int btemp_ball_convert;
842 struct ab8500_gpadc *gpadc;
843
Philippe Langlais8908c042012-04-18 15:52:59 +0200844 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000845 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
846 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100847 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
Lee Jones73482342013-02-26 10:06:55 +0000848 btemp_ball_raw);
John Beckett1478a312011-05-31 13:54:27 +0100849
850 return seq_printf(s,
851 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
852}
853
854static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
855 struct file *file)
856{
857 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
858}
859
860static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
861 .open = ab8500_gpadc_btemp_ball_open,
862 .read = seq_read,
863 .llseek = seq_lseek,
864 .release = single_release,
865 .owner = THIS_MODULE,
866};
867
868static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
869{
870 int main_charger_v_raw;
871 int main_charger_v_convert;
872 struct ab8500_gpadc *gpadc;
873
Philippe Langlais8908c042012-04-18 15:52:59 +0200874 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000875 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
876 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100877 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +0000878 MAIN_CHARGER_V, main_charger_v_raw);
John Beckett1478a312011-05-31 13:54:27 +0100879
880 return seq_printf(s, "%d,0x%X\n",
881 main_charger_v_convert, main_charger_v_raw);
882}
883
884static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
885 struct file *file)
886{
887 return single_open(file, ab8500_gpadc_main_charger_v_print,
888 inode->i_private);
889}
890
891static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
892 .open = ab8500_gpadc_main_charger_v_open,
893 .read = seq_read,
894 .llseek = seq_lseek,
895 .release = single_release,
896 .owner = THIS_MODULE,
897};
898
899static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
900{
901 int acc_detect1_raw;
902 int acc_detect1_convert;
903 struct ab8500_gpadc *gpadc;
904
Philippe Langlais8908c042012-04-18 15:52:59 +0200905 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000906 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
907 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100908 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
Lee Jones73482342013-02-26 10:06:55 +0000909 acc_detect1_raw);
John Beckett1478a312011-05-31 13:54:27 +0100910
911 return seq_printf(s, "%d,0x%X\n",
912 acc_detect1_convert, acc_detect1_raw);
913}
914
915static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
916 struct file *file)
917{
918 return single_open(file, ab8500_gpadc_acc_detect1_print,
919 inode->i_private);
920}
921
922static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
923 .open = ab8500_gpadc_acc_detect1_open,
924 .read = seq_read,
925 .llseek = seq_lseek,
926 .release = single_release,
927 .owner = THIS_MODULE,
928};
929
930static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
931{
932 int acc_detect2_raw;
933 int acc_detect2_convert;
934 struct ab8500_gpadc *gpadc;
935
Philippe Langlais8908c042012-04-18 15:52:59 +0200936 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000937 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
938 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100939 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +0000940 ACC_DETECT2, acc_detect2_raw);
John Beckett1478a312011-05-31 13:54:27 +0100941
942 return seq_printf(s, "%d,0x%X\n",
943 acc_detect2_convert, acc_detect2_raw);
944}
945
946static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
947 struct file *file)
948{
949 return single_open(file, ab8500_gpadc_acc_detect2_print,
950 inode->i_private);
951}
952
953static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
954 .open = ab8500_gpadc_acc_detect2_open,
955 .read = seq_read,
956 .llseek = seq_lseek,
957 .release = single_release,
958 .owner = THIS_MODULE,
959};
960
961static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
962{
963 int aux1_raw;
964 int aux1_convert;
965 struct ab8500_gpadc *gpadc;
966
Philippe Langlais8908c042012-04-18 15:52:59 +0200967 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000968 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
969 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100970 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
Lee Jones73482342013-02-26 10:06:55 +0000971 aux1_raw);
John Beckett1478a312011-05-31 13:54:27 +0100972
973 return seq_printf(s, "%d,0x%X\n",
974 aux1_convert, aux1_raw);
975}
976
977static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
978{
979 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
980}
981
982static const struct file_operations ab8500_gpadc_aux1_fops = {
983 .open = ab8500_gpadc_aux1_open,
984 .read = seq_read,
985 .llseek = seq_lseek,
986 .release = single_release,
987 .owner = THIS_MODULE,
988};
989
990static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
991{
992 int aux2_raw;
993 int aux2_convert;
994 struct ab8500_gpadc *gpadc;
995
Philippe Langlais8908c042012-04-18 15:52:59 +0200996 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +0000997 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
998 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +0100999 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
Lee Jones73482342013-02-26 10:06:55 +00001000 aux2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001001
1002 return seq_printf(s, "%d,0x%X\n",
1003 aux2_convert, aux2_raw);
1004}
1005
1006static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1007{
1008 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1009}
1010
1011static const struct file_operations ab8500_gpadc_aux2_fops = {
1012 .open = ab8500_gpadc_aux2_open,
1013 .read = seq_read,
1014 .llseek = seq_lseek,
1015 .release = single_release,
1016 .owner = THIS_MODULE,
1017};
1018
1019static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1020{
1021 int main_bat_v_raw;
1022 int main_bat_v_convert;
1023 struct ab8500_gpadc *gpadc;
1024
Philippe Langlais8908c042012-04-18 15:52:59 +02001025 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001026 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1027 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001028 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
Lee Jones73482342013-02-26 10:06:55 +00001029 main_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001030
1031 return seq_printf(s, "%d,0x%X\n",
1032 main_bat_v_convert, main_bat_v_raw);
1033}
1034
1035static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1036 struct file *file)
1037{
1038 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1039}
1040
1041static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1042 .open = ab8500_gpadc_main_bat_v_open,
1043 .read = seq_read,
1044 .llseek = seq_lseek,
1045 .release = single_release,
1046 .owner = THIS_MODULE,
1047};
1048
1049static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1050{
1051 int vbus_v_raw;
1052 int vbus_v_convert;
1053 struct ab8500_gpadc *gpadc;
1054
Philippe Langlais8908c042012-04-18 15:52:59 +02001055 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001056 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1057 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001058 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
Lee Jones73482342013-02-26 10:06:55 +00001059 vbus_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001060
1061 return seq_printf(s, "%d,0x%X\n",
1062 vbus_v_convert, vbus_v_raw);
1063}
1064
1065static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1066{
1067 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1068}
1069
1070static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1071 .open = ab8500_gpadc_vbus_v_open,
1072 .read = seq_read,
1073 .llseek = seq_lseek,
1074 .release = single_release,
1075 .owner = THIS_MODULE,
1076};
1077
1078static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1079{
1080 int main_charger_c_raw;
1081 int main_charger_c_convert;
1082 struct ab8500_gpadc *gpadc;
1083
Philippe Langlais8908c042012-04-18 15:52:59 +02001084 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001085 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
1086 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001087 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001088 MAIN_CHARGER_C, main_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01001089
1090 return seq_printf(s, "%d,0x%X\n",
1091 main_charger_c_convert, main_charger_c_raw);
1092}
1093
1094static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1095 struct file *file)
1096{
1097 return single_open(file, ab8500_gpadc_main_charger_c_print,
1098 inode->i_private);
1099}
1100
1101static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
1102 .open = ab8500_gpadc_main_charger_c_open,
1103 .read = seq_read,
1104 .llseek = seq_lseek,
1105 .release = single_release,
1106 .owner = THIS_MODULE,
1107};
1108
1109static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1110{
1111 int usb_charger_c_raw;
1112 int usb_charger_c_convert;
1113 struct ab8500_gpadc *gpadc;
1114
Philippe Langlais8908c042012-04-18 15:52:59 +02001115 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001116 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
1117 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001118 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001119 USB_CHARGER_C, usb_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01001120
1121 return seq_printf(s, "%d,0x%X\n",
1122 usb_charger_c_convert, usb_charger_c_raw);
1123}
1124
1125static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
1126 struct file *file)
1127{
1128 return single_open(file, ab8500_gpadc_usb_charger_c_print,
1129 inode->i_private);
1130}
1131
1132static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
1133 .open = ab8500_gpadc_usb_charger_c_open,
1134 .read = seq_read,
1135 .llseek = seq_lseek,
1136 .release = single_release,
1137 .owner = THIS_MODULE,
1138};
1139
1140static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
1141{
1142 int bk_bat_v_raw;
1143 int bk_bat_v_convert;
1144 struct ab8500_gpadc *gpadc;
1145
Philippe Langlais8908c042012-04-18 15:52:59 +02001146 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001147 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
1148 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001149 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001150 BK_BAT_V, bk_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001151
1152 return seq_printf(s, "%d,0x%X\n",
1153 bk_bat_v_convert, bk_bat_v_raw);
1154}
1155
1156static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
1157{
1158 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
1159}
1160
1161static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
1162 .open = ab8500_gpadc_bk_bat_v_open,
1163 .read = seq_read,
1164 .llseek = seq_lseek,
1165 .release = single_release,
1166 .owner = THIS_MODULE,
1167};
1168
1169static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
1170{
1171 int die_temp_raw;
1172 int die_temp_convert;
1173 struct ab8500_gpadc *gpadc;
1174
Philippe Langlais8908c042012-04-18 15:52:59 +02001175 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001176 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
1177 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001178 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
Lee Jones73482342013-02-26 10:06:55 +00001179 die_temp_raw);
John Beckett1478a312011-05-31 13:54:27 +01001180
1181 return seq_printf(s, "%d,0x%X\n",
1182 die_temp_convert, die_temp_raw);
1183}
1184
1185static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
1186{
1187 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
1188}
1189
1190static const struct file_operations ab8500_gpadc_die_temp_fops = {
1191 .open = ab8500_gpadc_die_temp_open,
1192 .read = seq_read,
1193 .llseek = seq_lseek,
1194 .release = single_release,
1195 .owner = THIS_MODULE,
1196};
1197
Lee Jones73482342013-02-26 10:06:55 +00001198static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
1199{
1200 return seq_printf(s, "%d\n", avg_sample);
1201}
1202
1203static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
1204{
1205 return single_open(file, ab8500_gpadc_avg_sample_print,
1206 inode->i_private);
1207}
1208
1209static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
1210 const char __user *user_buf,
1211 size_t count, loff_t *ppos)
1212{
1213 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1214 char buf[32];
1215 int buf_size;
1216 unsigned long user_avg_sample;
1217 int err;
1218
1219 /* Get userspace string and assure termination */
1220 buf_size = min(count, (sizeof(buf) - 1));
1221 if (copy_from_user(buf, user_buf, buf_size))
1222 return -EFAULT;
1223 buf[buf_size] = 0;
1224
1225 err = strict_strtoul(buf, 0, &user_avg_sample);
1226 if (err)
1227 return -EINVAL;
1228 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
1229 || (user_avg_sample == SAMPLE_8)
1230 || (user_avg_sample == SAMPLE_16)) {
1231 avg_sample = (u8) user_avg_sample;
1232 } else {
1233 dev_err(dev, "debugfs error input: "
1234 "should be egal to 1, 4, 8 or 16\n");
1235 return -EINVAL;
1236 }
1237 return buf_size;
1238}
1239
1240static const struct file_operations ab8500_gpadc_avg_sample_fops = {
1241 .open = ab8500_gpadc_avg_sample_open,
1242 .read = seq_read,
1243 .write = ab8500_gpadc_avg_sample_write,
1244 .llseek = seq_lseek,
1245 .release = single_release,
1246 .owner = THIS_MODULE,
1247};
1248
1249static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
1250{
1251 return seq_printf(s, "%d\n", trig_edge);
1252}
1253
1254static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
1255{
1256 return single_open(file, ab8500_gpadc_trig_edge_print,
1257 inode->i_private);
1258}
1259
1260static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
1261 const char __user *user_buf,
1262 size_t count, loff_t *ppos)
1263{
1264 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1265 char buf[32];
1266 int buf_size;
1267 unsigned long user_trig_edge;
1268 int err;
1269
1270 /* Get userspace string and assure termination */
1271 buf_size = min(count, (sizeof(buf) - 1));
1272 if (copy_from_user(buf, user_buf, buf_size))
1273 return -EFAULT;
1274 buf[buf_size] = 0;
1275
1276 err = strict_strtoul(buf, 0, &user_trig_edge);
1277 if (err)
1278 return -EINVAL;
1279 if ((user_trig_edge == RISING_EDGE)
1280 || (user_trig_edge == FALLING_EDGE)) {
1281 trig_edge = (u8) user_trig_edge;
1282 } else {
1283 dev_err(dev, "Wrong input:\n"
1284 "Enter 0. Rising edge\n"
1285 "Enter 1. Falling edge\n");
1286 return -EINVAL;
1287 }
1288 return buf_size;
1289}
1290
1291static const struct file_operations ab8500_gpadc_trig_edge_fops = {
1292 .open = ab8500_gpadc_trig_edge_open,
1293 .read = seq_read,
1294 .write = ab8500_gpadc_trig_edge_write,
1295 .llseek = seq_lseek,
1296 .release = single_release,
1297 .owner = THIS_MODULE,
1298};
1299
1300static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
1301{
1302 return seq_printf(s, "%d\n", trig_timer);
1303}
1304
1305static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
1306{
1307 return single_open(file, ab8500_gpadc_trig_timer_print,
1308 inode->i_private);
1309}
1310
1311static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
1312 const char __user *user_buf,
1313 size_t count, loff_t *ppos)
1314{
1315 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1316 char buf[32];
1317 int buf_size;
1318 unsigned long user_trig_timer;
1319 int err;
1320
1321 /* Get userspace string and assure termination */
1322 buf_size = min(count, (sizeof(buf) - 1));
1323 if (copy_from_user(buf, user_buf, buf_size))
1324 return -EFAULT;
1325 buf[buf_size] = 0;
1326
1327 err = strict_strtoul(buf, 0, &user_trig_timer);
1328 if (err)
1329 return -EINVAL;
1330 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
1331 trig_timer = (u8) user_trig_timer;
1332 } else {
1333 dev_err(dev, "debugfs error input: "
1334 "should be beetween 0 to 255\n");
1335 return -EINVAL;
1336 }
1337 return buf_size;
1338}
1339
1340static const struct file_operations ab8500_gpadc_trig_timer_fops = {
1341 .open = ab8500_gpadc_trig_timer_open,
1342 .read = seq_read,
1343 .write = ab8500_gpadc_trig_timer_write,
1344 .llseek = seq_lseek,
1345 .release = single_release,
1346 .owner = THIS_MODULE,
1347};
1348
1349static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
1350{
1351 return seq_printf(s, "%d\n", conv_type);
1352}
1353
1354static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
1355{
1356 return single_open(file, ab8500_gpadc_conv_type_print,
1357 inode->i_private);
1358}
1359
1360static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
1361 const char __user *user_buf,
1362 size_t count, loff_t *ppos)
1363{
1364 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1365 char buf[32];
1366 int buf_size;
1367 unsigned long user_conv_type;
1368 int err;
1369
1370 /* Get userspace string and assure termination */
1371 buf_size = min(count, (sizeof(buf) - 1));
1372 if (copy_from_user(buf, user_buf, buf_size))
1373 return -EFAULT;
1374 buf[buf_size] = 0;
1375
1376 err = strict_strtoul(buf, 0, &user_conv_type);
1377 if (err)
1378 return -EINVAL;
1379 if ((user_conv_type == ADC_SW)
1380 || (user_conv_type == ADC_HW)) {
1381 conv_type = (u8) user_conv_type;
1382 } else {
1383 dev_err(dev, "Wrong input:\n"
1384 "Enter 0. ADC SW conversion\n"
1385 "Enter 1. ADC HW conversion\n");
1386 return -EINVAL;
1387 }
1388 return buf_size;
1389}
1390
1391static const struct file_operations ab8500_gpadc_conv_type_fops = {
1392 .open = ab8500_gpadc_conv_type_open,
1393 .read = seq_read,
1394 .write = ab8500_gpadc_conv_type_write,
1395 .llseek = seq_lseek,
1396 .release = single_release,
1397 .owner = THIS_MODULE,
1398};
1399
carriere etienne0fbce762011-04-08 16:26:36 +02001400/*
1401 * return length of an ASCII numerical value, 0 is string is not a
1402 * numerical value.
1403 * string shall start at value 1st char.
1404 * string can be tailed with \0 or space or newline chars only.
1405 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1406 */
1407static int strval_len(char *b)
1408{
1409 char *s = b;
1410 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
1411 s += 2;
1412 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1413 if (!isxdigit(*s))
1414 return 0;
1415 }
1416 } else {
1417 if (*s == '-')
1418 s++;
1419 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1420 if (!isdigit(*s))
1421 return 0;
1422 }
1423 }
1424 return (int) (s-b);
1425}
1426
1427/*
1428 * parse hwreg input data.
1429 * update global hwreg_cfg only if input data syntax is ok.
1430 */
1431static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
1432 struct device *dev)
1433{
1434 uint write, val = 0;
1435 u8 regvalue;
1436 int ret;
1437 struct hwreg_cfg loc = {
1438 .bank = 0, /* default: invalid phys addr */
1439 .addr = 0, /* default: invalid phys addr */
1440 .fmt = 0, /* default: 32bit access, hex output */
1441 .mask = 0xFFFFFFFF, /* default: no mask */
1442 .shift = 0, /* default: no bit shift */
1443 };
1444
1445 /* read or write ? */
1446 if (!strncmp(b, "read ", 5)) {
1447 write = 0;
1448 b += 5;
1449 } else if (!strncmp(b, "write ", 6)) {
1450 write = 1;
1451 b += 6;
1452 } else
1453 return -EINVAL;
1454
1455 /* OPTIONS -l|-w|-b -s -m -o */
1456 while ((*b == ' ') || (*b == '-')) {
1457 if (*(b-1) != ' ') {
1458 b++;
1459 continue;
1460 }
1461 if ((!strncmp(b, "-d ", 3)) ||
1462 (!strncmp(b, "-dec ", 5))) {
1463 b += (*(b+2) == ' ') ? 3 : 5;
1464 loc.fmt |= (1<<0);
1465 } else if ((!strncmp(b, "-h ", 3)) ||
1466 (!strncmp(b, "-hex ", 5))) {
1467 b += (*(b+2) == ' ') ? 3 : 5;
1468 loc.fmt &= ~(1<<0);
1469 } else if ((!strncmp(b, "-m ", 3)) ||
1470 (!strncmp(b, "-mask ", 6))) {
1471 b += (*(b+2) == ' ') ? 3 : 6;
1472 if (strval_len(b) == 0)
1473 return -EINVAL;
1474 loc.mask = simple_strtoul(b, &b, 0);
1475 } else if ((!strncmp(b, "-s ", 3)) ||
1476 (!strncmp(b, "-shift ", 7))) {
1477 b += (*(b+2) == ' ') ? 3 : 7;
1478 if (strval_len(b) == 0)
1479 return -EINVAL;
1480 loc.shift = simple_strtol(b, &b, 0);
1481 } else {
1482 return -EINVAL;
1483 }
1484 }
1485 /* get arg BANK and ADDRESS */
1486 if (strval_len(b) == 0)
1487 return -EINVAL;
1488 loc.bank = simple_strtoul(b, &b, 0);
1489 while (*b == ' ')
1490 b++;
1491 if (strval_len(b) == 0)
1492 return -EINVAL;
1493 loc.addr = simple_strtoul(b, &b, 0);
1494
1495 if (write) {
1496 while (*b == ' ')
1497 b++;
1498 if (strval_len(b) == 0)
1499 return -EINVAL;
1500 val = simple_strtoul(b, &b, 0);
1501 }
1502
1503 /* args are ok, update target cfg (mainly for read) */
1504 *cfg = loc;
1505
1506#ifdef ABB_HWREG_DEBUG
1507 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
1508 "value=0x%X\n", (write) ? "write" : "read",
1509 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
1510 cfg->addr, cfg->mask, cfg->shift, val);
1511#endif
1512
1513 if (!write)
1514 return 0;
1515
1516 ret = abx500_get_register_interruptible(dev,
1517 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
1518 if (ret < 0) {
1519 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1520 ret, __LINE__);
1521 return -EINVAL;
1522 }
1523
1524 if (cfg->shift >= 0) {
1525 regvalue &= ~(cfg->mask << (cfg->shift));
1526 val = (val & cfg->mask) << (cfg->shift);
1527 } else {
1528 regvalue &= ~(cfg->mask >> (-cfg->shift));
1529 val = (val & cfg->mask) >> (-cfg->shift);
1530 }
1531 val = val | regvalue;
1532
1533 ret = abx500_set_register_interruptible(dev,
1534 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
1535 if (ret < 0) {
1536 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
1537 return -EINVAL;
1538 }
1539
1540 return 0;
1541}
1542
1543static ssize_t ab8500_hwreg_write(struct file *file,
1544 const char __user *user_buf, size_t count, loff_t *ppos)
1545{
1546 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1547 char buf[128];
1548 int buf_size, ret;
1549
1550 /* Get userspace string and assure termination */
1551 buf_size = min(count, (sizeof(buf)-1));
1552 if (copy_from_user(buf, user_buf, buf_size))
1553 return -EFAULT;
1554 buf[buf_size] = 0;
1555
1556 /* get args and process */
1557 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
1558 return (ret) ? ret : buf_size;
1559}
1560
1561/*
1562 * - irq subscribe/unsubscribe stuff
1563 */
Lee Jones4b8ac082013-01-14 16:10:36 +00001564static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
1565{
1566 seq_printf(s, "%d\n", irq_first);
1567
1568 return 0;
1569}
1570
1571static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1572 struct file *file)
1573{
1574 return single_open(file, ab8500_subscribe_unsubscribe_print,
1575 inode->i_private);
1576}
1577
1578/*
Mattias Wallin0b337e72010-11-19 17:55:11 +01001579 * Userspace should use poll() on this file. When an event occur
Lee Jones4b8ac082013-01-14 16:10:36 +00001580 * the blocking poll will be released.
1581 */
1582static ssize_t show_irq(struct device *dev,
1583 struct device_attribute *attr, char *buf)
1584{
Mattias Wallin0b337e72010-11-19 17:55:11 +01001585 unsigned long name;
1586 unsigned int irq_index;
1587 int err;
Lee Jones4b8ac082013-01-14 16:10:36 +00001588
Mattias Wallin0b337e72010-11-19 17:55:11 +01001589 err = strict_strtoul(attr->attr.name, 0, &name);
1590 if (err)
1591 return err;
1592
1593 irq_index = name - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01001594 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001595 return -EINVAL;
1596 else
1597 return sprintf(buf, "%u\n", irq_count[irq_index]);
1598}
Lee Jones4b8ac082013-01-14 16:10:36 +00001599
1600static ssize_t ab8500_subscribe_write(struct file *file,
1601 const char __user *user_buf,
1602 size_t count, loff_t *ppos)
1603{
1604 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1605 char buf[32];
1606 int buf_size;
1607 unsigned long user_val;
1608 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01001609 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00001610
1611 /* Get userspace string and assure termination */
1612 buf_size = min(count, (sizeof(buf)-1));
1613 if (copy_from_user(buf, user_buf, buf_size))
1614 return -EFAULT;
1615 buf[buf_size] = 0;
1616
1617 err = strict_strtoul(buf, 0, &user_val);
1618 if (err)
1619 return -EINVAL;
1620 if (user_val < irq_first) {
1621 dev_err(dev, "debugfs error input < %d\n", irq_first);
1622 return -EINVAL;
1623 }
1624 if (user_val > irq_last) {
1625 dev_err(dev, "debugfs error input > %d\n", irq_last);
1626 return -EINVAL;
1627 }
1628
Mattias Wallin0b337e72010-11-19 17:55:11 +01001629 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01001630 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001631 return -EINVAL;
1632
Lee Jones4b8ac082013-01-14 16:10:36 +00001633 /*
Mattias Wallin0b337e72010-11-19 17:55:11 +01001634 * This will create a sysfs file named <irq-nr> which userspace can
Lee Jones4b8ac082013-01-14 16:10:36 +00001635 * use to select or poll and get the AB8500 events
1636 */
Mattias Wallin0b337e72010-11-19 17:55:11 +01001637 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1638 GFP_KERNEL);
1639 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
1640 sprintf(event_name[irq_index], "%lu", user_val);
1641 dev_attr[irq_index]->show = show_irq;
1642 dev_attr[irq_index]->store = NULL;
1643 dev_attr[irq_index]->attr.name = event_name[irq_index];
1644 dev_attr[irq_index]->attr.mode = S_IRUGO;
1645 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00001646 if (err < 0) {
1647 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
1648 return err;
1649 }
1650
1651 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
1652 IRQF_SHARED | IRQF_NO_SUSPEND,
1653 "ab8500-debug", &dev->kobj);
1654 if (err < 0) {
1655 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
1656 err, user_val);
Mattias Wallin0b337e72010-11-19 17:55:11 +01001657 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00001658 return err;
1659 }
1660
1661 return buf_size;
1662}
1663
1664static ssize_t ab8500_unsubscribe_write(struct file *file,
1665 const char __user *user_buf,
1666 size_t count, loff_t *ppos)
1667{
1668 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1669 char buf[32];
1670 int buf_size;
1671 unsigned long user_val;
1672 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01001673 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00001674
1675 /* Get userspace string and assure termination */
1676 buf_size = min(count, (sizeof(buf)-1));
1677 if (copy_from_user(buf, user_buf, buf_size))
1678 return -EFAULT;
1679 buf[buf_size] = 0;
1680
1681 err = strict_strtoul(buf, 0, &user_val);
1682 if (err)
1683 return -EINVAL;
1684 if (user_val < irq_first) {
1685 dev_err(dev, "debugfs error input < %d\n", irq_first);
1686 return -EINVAL;
1687 }
1688 if (user_val > irq_last) {
1689 dev_err(dev, "debugfs error input > %d\n", irq_last);
1690 return -EINVAL;
1691 }
1692
Mattias Wallin0b337e72010-11-19 17:55:11 +01001693 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01001694 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001695 return -EINVAL;
Lee Jones4b8ac082013-01-14 16:10:36 +00001696
Mattias Wallin0b337e72010-11-19 17:55:11 +01001697 /* Set irq count to 0 when unsubscribe */
1698 irq_count[irq_index] = 0;
1699
1700 if (dev_attr[irq_index])
1701 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1702
1703
1704 free_irq(user_val, &dev->kobj);
1705 kfree(event_name[irq_index]);
1706 kfree(dev_attr[irq_index]);
Lee Jones4b8ac082013-01-14 16:10:36 +00001707
1708 return buf_size;
1709}
1710
carriere etienne0fbce762011-04-08 16:26:36 +02001711/*
1712 * - several deubgfs nodes fops
1713 */
1714
Mattias Wallin5814fc32010-09-13 16:05:04 +02001715static const struct file_operations ab8500_bank_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01001716 .open = ab8500_bank_open,
1717 .write = ab8500_bank_write,
1718 .read = seq_read,
1719 .llseek = seq_lseek,
1720 .release = single_release,
1721 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02001722};
1723
1724static const struct file_operations ab8500_address_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01001725 .open = ab8500_address_open,
1726 .write = ab8500_address_write,
1727 .read = seq_read,
1728 .llseek = seq_lseek,
1729 .release = single_release,
1730 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02001731};
1732
1733static const struct file_operations ab8500_val_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01001734 .open = ab8500_val_open,
1735 .write = ab8500_val_write,
1736 .read = seq_read,
1737 .llseek = seq_lseek,
1738 .release = single_release,
1739 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02001740};
1741
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001742static const struct file_operations ab8500_interrupts_fops = {
1743 .open = ab8500_interrupts_open,
1744 .read = seq_read,
1745 .llseek = seq_lseek,
1746 .release = single_release,
1747 .owner = THIS_MODULE,
1748};
1749
Lee Jones4b8ac082013-01-14 16:10:36 +00001750static const struct file_operations ab8500_subscribe_fops = {
1751 .open = ab8500_subscribe_unsubscribe_open,
1752 .write = ab8500_subscribe_write,
1753 .read = seq_read,
1754 .llseek = seq_lseek,
1755 .release = single_release,
1756 .owner = THIS_MODULE,
1757};
1758
1759static const struct file_operations ab8500_unsubscribe_fops = {
1760 .open = ab8500_subscribe_unsubscribe_open,
1761 .write = ab8500_unsubscribe_write,
1762 .read = seq_read,
1763 .llseek = seq_lseek,
1764 .release = single_release,
1765 .owner = THIS_MODULE,
1766};
1767
carriere etienne0fbce762011-04-08 16:26:36 +02001768static const struct file_operations ab8500_hwreg_fops = {
1769 .open = ab8500_hwreg_open,
1770 .write = ab8500_hwreg_write,
1771 .read = seq_read,
1772 .llseek = seq_lseek,
1773 .release = single_release,
1774 .owner = THIS_MODULE,
1775};
1776
Mattias Wallin5814fc32010-09-13 16:05:04 +02001777static struct dentry *ab8500_dir;
John Beckett1478a312011-05-31 13:54:27 +01001778static struct dentry *ab8500_gpadc_dir;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001779
Bill Pembertonf791be42012-11-19 13:23:04 -05001780static int ab8500_debug_probe(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001781{
carriere etienne0fbce762011-04-08 16:26:36 +02001782 struct dentry *file;
Linus Walleijddba25f2012-02-03 11:19:05 +01001783 int ret = -ENOMEM;
1784 struct ab8500 *ab8500;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001785 debug_bank = AB8500_MISC;
1786 debug_address = AB8500_REV_REG & 0x00FF;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001787
Linus Walleijddba25f2012-02-03 11:19:05 +01001788 ab8500 = dev_get_drvdata(plf->dev.parent);
1789 num_irqs = ab8500->mask_size;
1790
Ashok G70bad042012-02-28 10:21:00 +05301791 irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
Linus Walleijddba25f2012-02-03 11:19:05 +01001792 if (!irq_count)
1793 return -ENOMEM;
1794
1795 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
1796 if (!dev_attr)
1797 goto out_freeirq_count;
1798
1799 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
1800 if (!event_name)
1801 goto out_freedev_attr;
1802
Lee Jones4b8ac082013-01-14 16:10:36 +00001803 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
1804 if (irq_first < 0) {
1805 dev_err(&plf->dev, "First irq not found, err %d\n",
John Beckett1478a312011-05-31 13:54:27 +01001806 irq_first);
Linus Walleijddba25f2012-02-03 11:19:05 +01001807 ret = irq_first;
1808 goto out_freeevent_name;
Lee Jones4b8ac082013-01-14 16:10:36 +00001809 }
1810
1811 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
1812 if (irq_last < 0) {
1813 dev_err(&plf->dev, "Last irq not found, err %d\n",
John Beckett1478a312011-05-31 13:54:27 +01001814 irq_last);
Linus Walleijddba25f2012-02-03 11:19:05 +01001815 ret = irq_last;
1816 goto out_freeevent_name;
Lee Jones4b8ac082013-01-14 16:10:36 +00001817 }
1818
Mattias Wallind7b9f322010-11-26 13:06:39 +01001819 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
1820 if (!ab8500_dir)
carriere etienne0fbce762011-04-08 16:26:36 +02001821 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001822
John Beckett1478a312011-05-31 13:54:27 +01001823 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
1824 ab8500_dir);
1825 if (!ab8500_gpadc_dir)
1826 goto err;
1827
1828 file = debugfs_create_file("all-bank-registers", S_IRUGO,
1829 ab8500_dir, &plf->dev, &ab8500_registers_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001830 if (!file)
1831 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001832
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001833 file = debugfs_create_file("all-banks", S_IRUGO,
1834 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
1835 if (!file)
1836 goto err;
1837
John Beckett1478a312011-05-31 13:54:27 +01001838 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
1839 ab8500_dir, &plf->dev, &ab8500_bank_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001840 if (!file)
1841 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001842
John Beckett1478a312011-05-31 13:54:27 +01001843 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
1844 ab8500_dir, &plf->dev, &ab8500_address_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001845 if (!file)
1846 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001847
John Beckett1478a312011-05-31 13:54:27 +01001848 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
1849 ab8500_dir, &plf->dev, &ab8500_val_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001850 if (!file)
1851 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001852
John Beckett1478a312011-05-31 13:54:27 +01001853 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
1854 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001855 if (!file)
1856 goto err;
Lee Jones4b8ac082013-01-14 16:10:36 +00001857
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001858 if (is_ab8500(ab8500))
1859 num_interrupt_lines = AB8500_NR_IRQS;
1860 else if (is_ab8505(ab8500))
1861 num_interrupt_lines = AB8505_NR_IRQS;
1862 else if (is_ab9540(ab8500))
1863 num_interrupt_lines = AB9540_NR_IRQS;
1864
1865 file = debugfs_create_file("interrupts", (S_IRUGO),
1866 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
1867 if (!file)
1868 goto err;
1869
John Beckett1478a312011-05-31 13:54:27 +01001870 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
1871 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001872 if (!file)
1873 goto err;
1874
John Beckett1478a312011-05-31 13:54:27 +01001875 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
1876 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
1877 if (!file)
1878 goto err;
1879
1880 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
1881 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
1882 if (!file)
1883 goto err;
1884
1885 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
1886 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
1887 if (!file)
1888 goto err;
1889
1890 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
1891 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
1892 if (!file)
1893 goto err;
1894
1895 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
1896 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
1897 if (!file)
1898 goto err;
1899
1900 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
1901 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
1902 if (!file)
1903 goto err;
1904
1905 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
1906 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
1907 if (!file)
1908 goto err;
1909
1910 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
1911 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
1912 if (!file)
1913 goto err;
1914
1915 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
1916 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
1917 if (!file)
1918 goto err;
1919
1920 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
1921 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
1922 if (!file)
1923 goto err;
1924
1925 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
1926 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
1927 if (!file)
1928 goto err;
1929
1930 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
1931 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
1932 if (!file)
1933 goto err;
1934
1935 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
1936 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
1937 if (!file)
1938 goto err;
1939
1940 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
1941 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02001942 if (!file)
1943 goto err;
Lee Jones4b8ac082013-01-14 16:10:36 +00001944
Lee Jones73482342013-02-26 10:06:55 +00001945 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUGO),
1946 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
1947 if (!file)
1948 goto err;
1949
1950 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUGO),
1951 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
1952 if (!file)
1953 goto err;
1954
1955 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUGO),
1956 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
1957 if (!file)
1958 goto err;
1959
1960 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUGO),
1961 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
1962 if (!file)
1963 goto err;
1964
Mattias Wallind7b9f322010-11-26 13:06:39 +01001965 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001966
carriere etienne0fbce762011-04-08 16:26:36 +02001967err:
1968 if (ab8500_dir)
1969 debugfs_remove_recursive(ab8500_dir);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001970 dev_err(&plf->dev, "failed to create debugfs entries.\n");
Linus Walleijddba25f2012-02-03 11:19:05 +01001971out_freeevent_name:
1972 kfree(event_name);
1973out_freedev_attr:
1974 kfree(dev_attr);
1975out_freeirq_count:
1976 kfree(irq_count);
1977
1978 return ret;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001979}
1980
Bill Pemberton4740f732012-11-19 13:26:01 -05001981static int ab8500_debug_remove(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001982{
carriere etienne0fbce762011-04-08 16:26:36 +02001983 debugfs_remove_recursive(ab8500_dir);
Linus Walleijddba25f2012-02-03 11:19:05 +01001984 kfree(event_name);
1985 kfree(dev_attr);
1986 kfree(irq_count);
1987
Mattias Wallind7b9f322010-11-26 13:06:39 +01001988 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001989}
1990
1991static struct platform_driver ab8500_debug_driver = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01001992 .driver = {
1993 .name = "ab8500-debug",
1994 .owner = THIS_MODULE,
1995 },
1996 .probe = ab8500_debug_probe,
Bill Pemberton84449212012-11-19 13:20:24 -05001997 .remove = ab8500_debug_remove
Mattias Wallin5814fc32010-09-13 16:05:04 +02001998};
1999
2000static int __init ab8500_debug_init(void)
2001{
Mattias Wallind7b9f322010-11-26 13:06:39 +01002002 return platform_driver_register(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02002003}
2004
2005static void __exit ab8500_debug_exit(void)
2006{
Mattias Wallind7b9f322010-11-26 13:06:39 +01002007 platform_driver_unregister(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02002008}
2009subsys_initcall(ab8500_debug_init);
2010module_exit(ab8500_debug_exit);
2011
2012MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
2013MODULE_DESCRIPTION("AB8500 DEBUG");
2014MODULE_LICENSE("GPL v2");