aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-02-13 18:23:17 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2013-02-13 18:23:17 -0500
commitdce7886e8064d92430bd34e444678f3cd7e3082c (patch)
tree4f21d0cd5a86b74371cf500a0fa23b3d58950f40 /drivers/mfd
parentba3980df4fc145f36a577307d6387c42841438fd (diff)
parent8908c04985ed67b9138c6e06be2c81867f24e2d4 (diff)
Merge branch 'for-mfd' of git://git.linaro.org/people/ljones/linux-3.0-ux500 into for-next
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/ab8500-core.c2
-rw-r--r--drivers/mfd/ab8500-debugfs.c1249
-rw-r--r--drivers/mfd/ab8500-gpadc.c90
-rw-r--r--drivers/mfd/ab8500-sysctrl.c92
-rw-r--r--drivers/mfd/abx500-core.c16
5 files changed, 1375 insertions, 74 deletions
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index cdcaa5b78c4d..104514228b74 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -320,6 +320,7 @@ static struct abx500_ops ab8500_ops = {
320 .mask_and_set_register = ab8500_mask_and_set_register, 320 .mask_and_set_register = ab8500_mask_and_set_register,
321 .event_registers_startup_state_get = NULL, 321 .event_registers_startup_state_get = NULL,
322 .startup_irq_enabled = NULL, 322 .startup_irq_enabled = NULL,
323 .dump_all_banks = ab8500_dump_all_banks,
323}; 324};
324 325
325static void ab8500_irq_lock(struct irq_data *data) 326static void ab8500_irq_lock(struct irq_data *data)
@@ -521,6 +522,7 @@ static irqreturn_t ab8500_irq(int irq, void *dev)
521 int virq = ab8500_irq_get_virq(ab8500, line); 522 int virq = ab8500_irq_get_virq(ab8500, line);
522 523
523 handle_nested_irq(virq); 524 handle_nested_irq(virq);
525 ab8500_debug_register_interrupt(line);
524 value &= ~(1 << bit); 526 value &= ~(1 << bit);
525 527
526 } while (value); 528 } while (value);
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 5a8e707bc038..ba25f95e1677 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -4,6 +4,72 @@
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson. 4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2 5 * License Terms: GNU General Public License v2
6 */ 6 */
7/*
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 */
7 73
8#include <linux/seq_file.h> 74#include <linux/seq_file.h>
9#include <linux/uaccess.h> 75#include <linux/uaccess.h>
@@ -11,13 +77,29 @@
11#include <linux/module.h> 77#include <linux/module.h>
12#include <linux/debugfs.h> 78#include <linux/debugfs.h>
13#include <linux/platform_device.h> 79#include <linux/platform_device.h>
80#include <linux/interrupt.h>
81#include <linux/kobject.h>
82#include <linux/slab.h>
14 83
15#include <linux/mfd/abx500.h> 84#include <linux/mfd/abx500.h>
16#include <linux/mfd/abx500/ab8500.h> 85#include <linux/mfd/abx500/ab8500-gpadc.h>
86
87#ifdef CONFIG_DEBUG_FS
88#include <linux/string.h>
89#include <linux/ctype.h>
90#endif
17 91
18static u32 debug_bank; 92static u32 debug_bank;
19static u32 debug_address; 93static u32 debug_address;
20 94
95static int irq_first;
96static int irq_last;
97static u32 *irq_count;
98static int num_irqs;
99
100static struct device_attribute **dev_attr;
101static char **event_name;
102
21/** 103/**
22 * struct ab8500_reg_range 104 * struct ab8500_reg_range
23 * @first: the first address of the range 105 * @first: the first address of the range
@@ -42,15 +124,35 @@ struct ab8500_prcmu_ranges {
42 const struct ab8500_reg_range *range; 124 const struct ab8500_reg_range *range;
43}; 125};
44 126
127/* hwreg- "mask" and "shift" entries ressources */
128struct hwreg_cfg {
129 u32 bank; /* target bank */
130 u32 addr; /* target address */
131 uint fmt; /* format */
132 uint mask; /* read/write mask, applied before any bit shift */
133 int shift; /* bit shift (read:right shift, write:left shift */
134};
135/* fmt bit #0: 0=hexa, 1=dec */
136#define REG_FMT_DEC(c) ((c)->fmt & 0x1)
137#define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
138
139static struct hwreg_cfg hwreg_cfg = {
140 .addr = 0, /* default: invalid phys addr */
141 .fmt = 0, /* default: 32bit access, hex output */
142 .mask = 0xFFFFFFFF, /* default: no mask */
143 .shift = 0, /* default: no bit shift */
144};
145
45#define AB8500_NAME_STRING "ab8500" 146#define AB8500_NAME_STRING "ab8500"
46#define AB8500_NUM_BANKS 22 147#define AB8500_ADC_NAME_STRING "gpadc"
148#define AB8500_NUM_BANKS 24
47 149
48#define AB8500_REV_REG 0x80 150#define AB8500_REV_REG 0x80
49 151
50static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { 152static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
51 [0x0] = { 153 [0x0] = {
52 .num_ranges = 0, 154 .num_ranges = 0,
53 .range = 0, 155 .range = NULL,
54 }, 156 },
55 [AB8500_SYS_CTRL1_BLOCK] = { 157 [AB8500_SYS_CTRL1_BLOCK] = {
56 .num_ranges = 3, 158 .num_ranges = 3,
@@ -215,7 +317,7 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
215 }, 317 },
216 }, 318 },
217 [AB8500_CHARGER] = { 319 [AB8500_CHARGER] = {
218 .num_ranges = 8, 320 .num_ranges = 9,
219 .range = (struct ab8500_reg_range[]) { 321 .range = (struct ab8500_reg_range[]) {
220 { 322 {
221 .first = 0x00, 323 .first = 0x00,
@@ -249,6 +351,10 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
249 .first = 0xC0, 351 .first = 0xC0,
250 .last = 0xC2, 352 .last = 0xC2,
251 }, 353 },
354 {
355 .first = 0xf5,
356 .last = 0xf6,
357 },
252 }, 358 },
253 }, 359 },
254 [AB8500_GAS_GAUGE] = { 360 [AB8500_GAS_GAUGE] = {
@@ -268,6 +374,24 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
268 }, 374 },
269 }, 375 },
270 }, 376 },
377 [AB8500_DEVELOPMENT] = {
378 .num_ranges = 1,
379 .range = (struct ab8500_reg_range[]) {
380 {
381 .first = 0x00,
382 .last = 0x00,
383 },
384 },
385 },
386 [AB8500_DEBUG] = {
387 .num_ranges = 1,
388 .range = (struct ab8500_reg_range[]) {
389 {
390 .first = 0x05,
391 .last = 0x07,
392 },
393 },
394 },
271 [AB8500_AUDIO] = { 395 [AB8500_AUDIO] = {
272 .num_ranges = 1, 396 .num_ranges = 1,
273 .range = (struct ab8500_reg_range[]) { 397 .range = (struct ab8500_reg_range[]) {
@@ -354,15 +478,30 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
354 }, 478 },
355}; 479};
356 480
357static int ab8500_registers_print(struct seq_file *s, void *p) 481static irqreturn_t ab8500_debug_handler(int irq, void *data)
358{ 482{
359 struct device *dev = s->private; 483 char buf[16];
360 unsigned int i; 484 struct kobject *kobj = (struct kobject *)data;
361 u32 bank = debug_bank; 485 unsigned int irq_abb = irq - irq_first;
362 486
363 seq_printf(s, AB8500_NAME_STRING " register values:\n"); 487 if (irq_abb < num_irqs)
488 irq_count[irq_abb]++;
489 /*
490 * This makes it possible to use poll for events (POLLPRI | POLLERR)
491 * from userspace on sysfs file named <irq-nr>
492 */
493 sprintf(buf, "%d", irq);
494 sysfs_notify(kobj, NULL, buf);
495
496 return IRQ_HANDLED;
497}
498
499/* Prints to seq_file or log_buf */
500static int ab8500_registers_print(struct device *dev, u32 bank,
501 struct seq_file *s)
502{
503 unsigned int i;
364 504
365 seq_printf(s, " bank %u:\n", bank);
366 for (i = 0; i < debug_ranges[bank].num_ranges; i++) { 505 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
367 u32 reg; 506 u32 reg;
368 507
@@ -379,22 +518,42 @@ static int ab8500_registers_print(struct seq_file *s, void *p)
379 return err; 518 return err;
380 } 519 }
381 520
382 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, 521 if (s) {
383 reg, value); 522 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n",
384 if (err < 0) { 523 bank, reg, value);
385 dev_err(dev, "seq_printf overflow\n"); 524 if (err < 0) {
386 /* Error is not returned here since 525 dev_err(dev,
387 * the output is wanted in any case */ 526 "seq_printf overflow bank=%d reg=%d\n",
388 return 0; 527 bank, reg);
528 /* Error is not returned here since
529 * the output is wanted in any case */
530 return 0;
531 }
532 } else {
533 printk(KERN_INFO" [%u/0x%02X]: 0x%02X\n", bank,
534 reg, value);
389 } 535 }
390 } 536 }
391 } 537 }
392 return 0; 538 return 0;
393} 539}
394 540
541static int ab8500_print_bank_registers(struct seq_file *s, void *p)
542{
543 struct device *dev = s->private;
544 u32 bank = debug_bank;
545
546 seq_printf(s, AB8500_NAME_STRING " register values:\n");
547
548 seq_printf(s, " bank %u:\n", bank);
549
550 ab8500_registers_print(dev, bank, s);
551 return 0;
552}
553
395static int ab8500_registers_open(struct inode *inode, struct file *file) 554static int ab8500_registers_open(struct inode *inode, struct file *file)
396{ 555{
397 return single_open(file, ab8500_registers_print, inode->i_private); 556 return single_open(file, ab8500_print_bank_registers, inode->i_private);
398} 557}
399 558
400static const struct file_operations ab8500_registers_fops = { 559static const struct file_operations ab8500_registers_fops = {
@@ -405,6 +564,64 @@ static const struct file_operations ab8500_registers_fops = {
405 .owner = THIS_MODULE, 564 .owner = THIS_MODULE,
406}; 565};
407 566
567static int ab8500_print_all_banks(struct seq_file *s, void *p)
568{
569 struct device *dev = s->private;
570 unsigned int i;
571 int err;
572
573 seq_printf(s, AB8500_NAME_STRING " register values:\n");
574
575 for (i = 1; i < AB8500_NUM_BANKS; i++) {
576 err = seq_printf(s, " bank %u:\n", i);
577 if (err < 0)
578 dev_err(dev, "seq_printf overflow, bank=%d\n", i);
579
580 ab8500_registers_print(dev, i, s);
581 }
582 return 0;
583}
584
585/* Dump registers to kernel log */
586void ab8500_dump_all_banks(struct device *dev)
587{
588 unsigned int i;
589
590 printk(KERN_INFO"ab8500 register values:\n");
591
592 for (i = 1; i < AB8500_NUM_BANKS; i++) {
593 printk(KERN_INFO" bank %u:\n", i);
594 ab8500_registers_print(dev, i, NULL);
595 }
596}
597
598static int ab8500_all_banks_open(struct inode *inode, struct file *file)
599{
600 struct seq_file *s;
601 int err;
602
603 err = single_open(file, ab8500_print_all_banks, inode->i_private);
604 if (!err) {
605 /* Default buf size in seq_read is not enough */
606 s = (struct seq_file *)file->private_data;
607 s->size = (PAGE_SIZE * 2);
608 s->buf = kmalloc(s->size, GFP_KERNEL);
609 if (!s->buf) {
610 single_release(inode, file);
611 err = -ENOMEM;
612 }
613 }
614 return err;
615}
616
617static const struct file_operations ab8500_all_banks_fops = {
618 .open = ab8500_all_banks_open,
619 .read = seq_read,
620 .llseek = seq_lseek,
621 .release = single_release,
622 .owner = THIS_MODULE,
623};
624
408static int ab8500_bank_print(struct seq_file *s, void *p) 625static int ab8500_bank_print(struct seq_file *s, void *p)
409{ 626{
410 return seq_printf(s, "%d\n", debug_bank); 627 return seq_printf(s, "%d\n", debug_bank);
@@ -519,6 +736,761 @@ static ssize_t ab8500_val_write(struct file *file,
519 return count; 736 return count;
520} 737}
521 738
739/*
740 * Interrupt status
741 */
742static u32 num_interrupts[AB8500_MAX_NR_IRQS];
743static int num_interrupt_lines;
744
745void ab8500_debug_register_interrupt(int line)
746{
747 if (line < num_interrupt_lines)
748 num_interrupts[line]++;
749}
750
751static int ab8500_interrupts_print(struct seq_file *s, void *p)
752{
753 int line;
754
755 seq_printf(s, "irq: number of\n");
756
757 for (line = 0; line < num_interrupt_lines; line++)
758 seq_printf(s, "%3i: %6i\n", line, num_interrupts[line]);
759
760 return 0;
761}
762
763static int ab8500_interrupts_open(struct inode *inode, struct file *file)
764{
765 return single_open(file, ab8500_interrupts_print, inode->i_private);
766}
767
768/*
769 * - HWREG DB8500 formated routines
770 */
771static int ab8500_hwreg_print(struct seq_file *s, void *d)
772{
773 struct device *dev = s->private;
774 int ret;
775 u8 regvalue;
776
777 ret = abx500_get_register_interruptible(dev,
778 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
779 if (ret < 0) {
780 dev_err(dev, "abx500_get_reg fail %d, %d\n",
781 ret, __LINE__);
782 return -EINVAL;
783 }
784
785 if (hwreg_cfg.shift >= 0)
786 regvalue >>= hwreg_cfg.shift;
787 else
788 regvalue <<= -hwreg_cfg.shift;
789 regvalue &= hwreg_cfg.mask;
790
791 if (REG_FMT_DEC(&hwreg_cfg))
792 seq_printf(s, "%d\n", regvalue);
793 else
794 seq_printf(s, "0x%02X\n", regvalue);
795 return 0;
796}
797
798static int ab8500_hwreg_open(struct inode *inode, struct file *file)
799{
800 return single_open(file, ab8500_hwreg_print, inode->i_private);
801}
802
803static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
804{
805 int bat_ctrl_raw;
806 int bat_ctrl_convert;
807 struct ab8500_gpadc *gpadc;
808
809 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
810 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL);
811 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
812 BAT_CTRL, bat_ctrl_raw);
813
814 return seq_printf(s, "%d,0x%X\n",
815 bat_ctrl_convert, bat_ctrl_raw);
816}
817
818static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
819{
820 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
821}
822
823static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
824 .open = ab8500_gpadc_bat_ctrl_open,
825 .read = seq_read,
826 .llseek = seq_lseek,
827 .release = single_release,
828 .owner = THIS_MODULE,
829};
830
831static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
832{
833 int btemp_ball_raw;
834 int btemp_ball_convert;
835 struct ab8500_gpadc *gpadc;
836
837 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
838 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL);
839 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
840 btemp_ball_raw);
841
842 return seq_printf(s,
843 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
844}
845
846static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
847 struct file *file)
848{
849 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
850}
851
852static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
853 .open = ab8500_gpadc_btemp_ball_open,
854 .read = seq_read,
855 .llseek = seq_lseek,
856 .release = single_release,
857 .owner = THIS_MODULE,
858};
859
860static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
861{
862 int main_charger_v_raw;
863 int main_charger_v_convert;
864 struct ab8500_gpadc *gpadc;
865
866 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
867 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V);
868 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
869 MAIN_CHARGER_V, main_charger_v_raw);
870
871 return seq_printf(s, "%d,0x%X\n",
872 main_charger_v_convert, main_charger_v_raw);
873}
874
875static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
876 struct file *file)
877{
878 return single_open(file, ab8500_gpadc_main_charger_v_print,
879 inode->i_private);
880}
881
882static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
883 .open = ab8500_gpadc_main_charger_v_open,
884 .read = seq_read,
885 .llseek = seq_lseek,
886 .release = single_release,
887 .owner = THIS_MODULE,
888};
889
890static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
891{
892 int acc_detect1_raw;
893 int acc_detect1_convert;
894 struct ab8500_gpadc *gpadc;
895
896 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
897 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1);
898 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
899 acc_detect1_raw);
900
901 return seq_printf(s, "%d,0x%X\n",
902 acc_detect1_convert, acc_detect1_raw);
903}
904
905static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
906 struct file *file)
907{
908 return single_open(file, ab8500_gpadc_acc_detect1_print,
909 inode->i_private);
910}
911
912static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
913 .open = ab8500_gpadc_acc_detect1_open,
914 .read = seq_read,
915 .llseek = seq_lseek,
916 .release = single_release,
917 .owner = THIS_MODULE,
918};
919
920static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
921{
922 int acc_detect2_raw;
923 int acc_detect2_convert;
924 struct ab8500_gpadc *gpadc;
925
926 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
927 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2);
928 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
929 ACC_DETECT2, acc_detect2_raw);
930
931 return seq_printf(s, "%d,0x%X\n",
932 acc_detect2_convert, acc_detect2_raw);
933}
934
935static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
936 struct file *file)
937{
938 return single_open(file, ab8500_gpadc_acc_detect2_print,
939 inode->i_private);
940}
941
942static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
943 .open = ab8500_gpadc_acc_detect2_open,
944 .read = seq_read,
945 .llseek = seq_lseek,
946 .release = single_release,
947 .owner = THIS_MODULE,
948};
949
950static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
951{
952 int aux1_raw;
953 int aux1_convert;
954 struct ab8500_gpadc *gpadc;
955
956 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
957 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1);
958 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
959 aux1_raw);
960
961 return seq_printf(s, "%d,0x%X\n",
962 aux1_convert, aux1_raw);
963}
964
965static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
966{
967 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
968}
969
970static const struct file_operations ab8500_gpadc_aux1_fops = {
971 .open = ab8500_gpadc_aux1_open,
972 .read = seq_read,
973 .llseek = seq_lseek,
974 .release = single_release,
975 .owner = THIS_MODULE,
976};
977
978static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
979{
980 int aux2_raw;
981 int aux2_convert;
982 struct ab8500_gpadc *gpadc;
983
984 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
985 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2);
986 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
987 aux2_raw);
988
989 return seq_printf(s, "%d,0x%X\n",
990 aux2_convert, aux2_raw);
991}
992
993static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
994{
995 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
996}
997
998static const struct file_operations ab8500_gpadc_aux2_fops = {
999 .open = ab8500_gpadc_aux2_open,
1000 .read = seq_read,
1001 .llseek = seq_lseek,
1002 .release = single_release,
1003 .owner = THIS_MODULE,
1004};
1005
1006static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1007{
1008 int main_bat_v_raw;
1009 int main_bat_v_convert;
1010 struct ab8500_gpadc *gpadc;
1011
1012 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1013 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V);
1014 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1015 main_bat_v_raw);
1016
1017 return seq_printf(s, "%d,0x%X\n",
1018 main_bat_v_convert, main_bat_v_raw);
1019}
1020
1021static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1022 struct file *file)
1023{
1024 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1025}
1026
1027static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1028 .open = ab8500_gpadc_main_bat_v_open,
1029 .read = seq_read,
1030 .llseek = seq_lseek,
1031 .release = single_release,
1032 .owner = THIS_MODULE,
1033};
1034
1035static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1036{
1037 int vbus_v_raw;
1038 int vbus_v_convert;
1039 struct ab8500_gpadc *gpadc;
1040
1041 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1042 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V);
1043 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1044 vbus_v_raw);
1045
1046 return seq_printf(s, "%d,0x%X\n",
1047 vbus_v_convert, vbus_v_raw);
1048}
1049
1050static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1051{
1052 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1053}
1054
1055static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1056 .open = ab8500_gpadc_vbus_v_open,
1057 .read = seq_read,
1058 .llseek = seq_lseek,
1059 .release = single_release,
1060 .owner = THIS_MODULE,
1061};
1062
1063static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1064{
1065 int main_charger_c_raw;
1066 int main_charger_c_convert;
1067 struct ab8500_gpadc *gpadc;
1068
1069 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1070 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C);
1071 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1072 MAIN_CHARGER_C, main_charger_c_raw);
1073
1074 return seq_printf(s, "%d,0x%X\n",
1075 main_charger_c_convert, main_charger_c_raw);
1076}
1077
1078static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1079 struct file *file)
1080{
1081 return single_open(file, ab8500_gpadc_main_charger_c_print,
1082 inode->i_private);
1083}
1084
1085static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
1086 .open = ab8500_gpadc_main_charger_c_open,
1087 .read = seq_read,
1088 .llseek = seq_lseek,
1089 .release = single_release,
1090 .owner = THIS_MODULE,
1091};
1092
1093static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1094{
1095 int usb_charger_c_raw;
1096 int usb_charger_c_convert;
1097 struct ab8500_gpadc *gpadc;
1098
1099 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1100 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C);
1101 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1102 USB_CHARGER_C, usb_charger_c_raw);
1103
1104 return seq_printf(s, "%d,0x%X\n",
1105 usb_charger_c_convert, usb_charger_c_raw);
1106}
1107
1108static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
1109 struct file *file)
1110{
1111 return single_open(file, ab8500_gpadc_usb_charger_c_print,
1112 inode->i_private);
1113}
1114
1115static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
1116 .open = ab8500_gpadc_usb_charger_c_open,
1117 .read = seq_read,
1118 .llseek = seq_lseek,
1119 .release = single_release,
1120 .owner = THIS_MODULE,
1121};
1122
1123static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
1124{
1125 int bk_bat_v_raw;
1126 int bk_bat_v_convert;
1127 struct ab8500_gpadc *gpadc;
1128
1129 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1130 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V);
1131 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1132 BK_BAT_V, bk_bat_v_raw);
1133
1134 return seq_printf(s, "%d,0x%X\n",
1135 bk_bat_v_convert, bk_bat_v_raw);
1136}
1137
1138static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
1139{
1140 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
1141}
1142
1143static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
1144 .open = ab8500_gpadc_bk_bat_v_open,
1145 .read = seq_read,
1146 .llseek = seq_lseek,
1147 .release = single_release,
1148 .owner = THIS_MODULE,
1149};
1150
1151static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
1152{
1153 int die_temp_raw;
1154 int die_temp_convert;
1155 struct ab8500_gpadc *gpadc;
1156
1157 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1158 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP);
1159 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
1160 die_temp_raw);
1161
1162 return seq_printf(s, "%d,0x%X\n",
1163 die_temp_convert, die_temp_raw);
1164}
1165
1166static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
1167{
1168 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
1169}
1170
1171static const struct file_operations ab8500_gpadc_die_temp_fops = {
1172 .open = ab8500_gpadc_die_temp_open,
1173 .read = seq_read,
1174 .llseek = seq_lseek,
1175 .release = single_release,
1176 .owner = THIS_MODULE,
1177};
1178
1179/*
1180 * return length of an ASCII numerical value, 0 is string is not a
1181 * numerical value.
1182 * string shall start at value 1st char.
1183 * string can be tailed with \0 or space or newline chars only.
1184 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1185 */
1186static int strval_len(char *b)
1187{
1188 char *s = b;
1189 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
1190 s += 2;
1191 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1192 if (!isxdigit(*s))
1193 return 0;
1194 }
1195 } else {
1196 if (*s == '-')
1197 s++;
1198 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1199 if (!isdigit(*s))
1200 return 0;
1201 }
1202 }
1203 return (int) (s-b);
1204}
1205
1206/*
1207 * parse hwreg input data.
1208 * update global hwreg_cfg only if input data syntax is ok.
1209 */
1210static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
1211 struct device *dev)
1212{
1213 uint write, val = 0;
1214 u8 regvalue;
1215 int ret;
1216 struct hwreg_cfg loc = {
1217 .bank = 0, /* default: invalid phys addr */
1218 .addr = 0, /* default: invalid phys addr */
1219 .fmt = 0, /* default: 32bit access, hex output */
1220 .mask = 0xFFFFFFFF, /* default: no mask */
1221 .shift = 0, /* default: no bit shift */
1222 };
1223
1224 /* read or write ? */
1225 if (!strncmp(b, "read ", 5)) {
1226 write = 0;
1227 b += 5;
1228 } else if (!strncmp(b, "write ", 6)) {
1229 write = 1;
1230 b += 6;
1231 } else
1232 return -EINVAL;
1233
1234 /* OPTIONS -l|-w|-b -s -m -o */
1235 while ((*b == ' ') || (*b == '-')) {
1236 if (*(b-1) != ' ') {
1237 b++;
1238 continue;
1239 }
1240 if ((!strncmp(b, "-d ", 3)) ||
1241 (!strncmp(b, "-dec ", 5))) {
1242 b += (*(b+2) == ' ') ? 3 : 5;
1243 loc.fmt |= (1<<0);
1244 } else if ((!strncmp(b, "-h ", 3)) ||
1245 (!strncmp(b, "-hex ", 5))) {
1246 b += (*(b+2) == ' ') ? 3 : 5;
1247 loc.fmt &= ~(1<<0);
1248 } else if ((!strncmp(b, "-m ", 3)) ||
1249 (!strncmp(b, "-mask ", 6))) {
1250 b += (*(b+2) == ' ') ? 3 : 6;
1251 if (strval_len(b) == 0)
1252 return -EINVAL;
1253 loc.mask = simple_strtoul(b, &b, 0);
1254 } else if ((!strncmp(b, "-s ", 3)) ||
1255 (!strncmp(b, "-shift ", 7))) {
1256 b += (*(b+2) == ' ') ? 3 : 7;
1257 if (strval_len(b) == 0)
1258 return -EINVAL;
1259 loc.shift = simple_strtol(b, &b, 0);
1260 } else {
1261 return -EINVAL;
1262 }
1263 }
1264 /* get arg BANK and ADDRESS */
1265 if (strval_len(b) == 0)
1266 return -EINVAL;
1267 loc.bank = simple_strtoul(b, &b, 0);
1268 while (*b == ' ')
1269 b++;
1270 if (strval_len(b) == 0)
1271 return -EINVAL;
1272 loc.addr = simple_strtoul(b, &b, 0);
1273
1274 if (write) {
1275 while (*b == ' ')
1276 b++;
1277 if (strval_len(b) == 0)
1278 return -EINVAL;
1279 val = simple_strtoul(b, &b, 0);
1280 }
1281
1282 /* args are ok, update target cfg (mainly for read) */
1283 *cfg = loc;
1284
1285#ifdef ABB_HWREG_DEBUG
1286 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
1287 "value=0x%X\n", (write) ? "write" : "read",
1288 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
1289 cfg->addr, cfg->mask, cfg->shift, val);
1290#endif
1291
1292 if (!write)
1293 return 0;
1294
1295 ret = abx500_get_register_interruptible(dev,
1296 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
1297 if (ret < 0) {
1298 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1299 ret, __LINE__);
1300 return -EINVAL;
1301 }
1302
1303 if (cfg->shift >= 0) {
1304 regvalue &= ~(cfg->mask << (cfg->shift));
1305 val = (val & cfg->mask) << (cfg->shift);
1306 } else {
1307 regvalue &= ~(cfg->mask >> (-cfg->shift));
1308 val = (val & cfg->mask) >> (-cfg->shift);
1309 }
1310 val = val | regvalue;
1311
1312 ret = abx500_set_register_interruptible(dev,
1313 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
1314 if (ret < 0) {
1315 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
1316 return -EINVAL;
1317 }
1318
1319 return 0;
1320}
1321
1322static ssize_t ab8500_hwreg_write(struct file *file,
1323 const char __user *user_buf, size_t count, loff_t *ppos)
1324{
1325 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1326 char buf[128];
1327 int buf_size, ret;
1328
1329 /* Get userspace string and assure termination */
1330 buf_size = min(count, (sizeof(buf)-1));
1331 if (copy_from_user(buf, user_buf, buf_size))
1332 return -EFAULT;
1333 buf[buf_size] = 0;
1334
1335 /* get args and process */
1336 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
1337 return (ret) ? ret : buf_size;
1338}
1339
1340/*
1341 * - irq subscribe/unsubscribe stuff
1342 */
1343static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
1344{
1345 seq_printf(s, "%d\n", irq_first);
1346
1347 return 0;
1348}
1349
1350static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1351 struct file *file)
1352{
1353 return single_open(file, ab8500_subscribe_unsubscribe_print,
1354 inode->i_private);
1355}
1356
1357/*
1358 * Userspace should use poll() on this file. When an event occur
1359 * the blocking poll will be released.
1360 */
1361static ssize_t show_irq(struct device *dev,
1362 struct device_attribute *attr, char *buf)
1363{
1364 unsigned long name;
1365 unsigned int irq_index;
1366 int err;
1367
1368 err = strict_strtoul(attr->attr.name, 0, &name);
1369 if (err)
1370 return err;
1371
1372 irq_index = name - irq_first;
1373 if (irq_index >= num_irqs)
1374 return -EINVAL;
1375 else
1376 return sprintf(buf, "%u\n", irq_count[irq_index]);
1377}
1378
1379static ssize_t ab8500_subscribe_write(struct file *file,
1380 const char __user *user_buf,
1381 size_t count, loff_t *ppos)
1382{
1383 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1384 char buf[32];
1385 int buf_size;
1386 unsigned long user_val;
1387 int err;
1388 unsigned int irq_index;
1389
1390 /* Get userspace string and assure termination */
1391 buf_size = min(count, (sizeof(buf)-1));
1392 if (copy_from_user(buf, user_buf, buf_size))
1393 return -EFAULT;
1394 buf[buf_size] = 0;
1395
1396 err = strict_strtoul(buf, 0, &user_val);
1397 if (err)
1398 return -EINVAL;
1399 if (user_val < irq_first) {
1400 dev_err(dev, "debugfs error input < %d\n", irq_first);
1401 return -EINVAL;
1402 }
1403 if (user_val > irq_last) {
1404 dev_err(dev, "debugfs error input > %d\n", irq_last);
1405 return -EINVAL;
1406 }
1407
1408 irq_index = user_val - irq_first;
1409 if (irq_index >= num_irqs)
1410 return -EINVAL;
1411
1412 /*
1413 * This will create a sysfs file named <irq-nr> which userspace can
1414 * use to select or poll and get the AB8500 events
1415 */
1416 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1417 GFP_KERNEL);
1418 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
1419 sprintf(event_name[irq_index], "%lu", user_val);
1420 dev_attr[irq_index]->show = show_irq;
1421 dev_attr[irq_index]->store = NULL;
1422 dev_attr[irq_index]->attr.name = event_name[irq_index];
1423 dev_attr[irq_index]->attr.mode = S_IRUGO;
1424 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
1425 if (err < 0) {
1426 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
1427 return err;
1428 }
1429
1430 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
1431 IRQF_SHARED | IRQF_NO_SUSPEND,
1432 "ab8500-debug", &dev->kobj);
1433 if (err < 0) {
1434 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
1435 err, user_val);
1436 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1437 return err;
1438 }
1439
1440 return buf_size;
1441}
1442
1443static ssize_t ab8500_unsubscribe_write(struct file *file,
1444 const char __user *user_buf,
1445 size_t count, loff_t *ppos)
1446{
1447 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1448 char buf[32];
1449 int buf_size;
1450 unsigned long user_val;
1451 int err;
1452 unsigned int irq_index;
1453
1454 /* Get userspace string and assure termination */
1455 buf_size = min(count, (sizeof(buf)-1));
1456 if (copy_from_user(buf, user_buf, buf_size))
1457 return -EFAULT;
1458 buf[buf_size] = 0;
1459
1460 err = strict_strtoul(buf, 0, &user_val);
1461 if (err)
1462 return -EINVAL;
1463 if (user_val < irq_first) {
1464 dev_err(dev, "debugfs error input < %d\n", irq_first);
1465 return -EINVAL;
1466 }
1467 if (user_val > irq_last) {
1468 dev_err(dev, "debugfs error input > %d\n", irq_last);
1469 return -EINVAL;
1470 }
1471
1472 irq_index = user_val - irq_first;
1473 if (irq_index >= num_irqs)
1474 return -EINVAL;
1475
1476 /* Set irq count to 0 when unsubscribe */
1477 irq_count[irq_index] = 0;
1478
1479 if (dev_attr[irq_index])
1480 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1481
1482
1483 free_irq(user_val, &dev->kobj);
1484 kfree(event_name[irq_index]);
1485 kfree(dev_attr[irq_index]);
1486
1487 return buf_size;
1488}
1489
1490/*
1491 * - several deubgfs nodes fops
1492 */
1493
522static const struct file_operations ab8500_bank_fops = { 1494static const struct file_operations ab8500_bank_fops = {
523 .open = ab8500_bank_open, 1495 .open = ab8500_bank_open,
524 .write = ab8500_bank_write, 1496 .write = ab8500_bank_write,
@@ -546,64 +1518,231 @@ static const struct file_operations ab8500_val_fops = {
546 .owner = THIS_MODULE, 1518 .owner = THIS_MODULE,
547}; 1519};
548 1520
1521static const struct file_operations ab8500_interrupts_fops = {
1522 .open = ab8500_interrupts_open,
1523 .read = seq_read,
1524 .llseek = seq_lseek,
1525 .release = single_release,
1526 .owner = THIS_MODULE,
1527};
1528
1529static const struct file_operations ab8500_subscribe_fops = {
1530 .open = ab8500_subscribe_unsubscribe_open,
1531 .write = ab8500_subscribe_write,
1532 .read = seq_read,
1533 .llseek = seq_lseek,
1534 .release = single_release,
1535 .owner = THIS_MODULE,
1536};
1537
1538static const struct file_operations ab8500_unsubscribe_fops = {
1539 .open = ab8500_subscribe_unsubscribe_open,
1540 .write = ab8500_unsubscribe_write,
1541 .read = seq_read,
1542 .llseek = seq_lseek,
1543 .release = single_release,
1544 .owner = THIS_MODULE,
1545};
1546
1547static const struct file_operations ab8500_hwreg_fops = {
1548 .open = ab8500_hwreg_open,
1549 .write = ab8500_hwreg_write,
1550 .read = seq_read,
1551 .llseek = seq_lseek,
1552 .release = single_release,
1553 .owner = THIS_MODULE,
1554};
1555
549static struct dentry *ab8500_dir; 1556static struct dentry *ab8500_dir;
550static struct dentry *ab8500_reg_file; 1557static struct dentry *ab8500_gpadc_dir;
551static struct dentry *ab8500_bank_file;
552static struct dentry *ab8500_address_file;
553static struct dentry *ab8500_val_file;
554 1558
555static int ab8500_debug_probe(struct platform_device *plf) 1559static int ab8500_debug_probe(struct platform_device *plf)
556{ 1560{
1561 struct dentry *file;
1562 int ret = -ENOMEM;
1563 struct ab8500 *ab8500;
557 debug_bank = AB8500_MISC; 1564 debug_bank = AB8500_MISC;
558 debug_address = AB8500_REV_REG & 0x00FF; 1565 debug_address = AB8500_REV_REG & 0x00FF;
559 1566
1567 ab8500 = dev_get_drvdata(plf->dev.parent);
1568 num_irqs = ab8500->mask_size;
1569
1570 irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
1571 if (!irq_count)
1572 return -ENOMEM;
1573
1574 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
1575 if (!dev_attr)
1576 goto out_freeirq_count;
1577
1578 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
1579 if (!event_name)
1580 goto out_freedev_attr;
1581
1582 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
1583 if (irq_first < 0) {
1584 dev_err(&plf->dev, "First irq not found, err %d\n",
1585 irq_first);
1586 ret = irq_first;
1587 goto out_freeevent_name;
1588 }
1589
1590 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
1591 if (irq_last < 0) {
1592 dev_err(&plf->dev, "Last irq not found, err %d\n",
1593 irq_last);
1594 ret = irq_last;
1595 goto out_freeevent_name;
1596 }
1597
560 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); 1598 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
561 if (!ab8500_dir) 1599 if (!ab8500_dir)
562 goto exit_no_debugfs; 1600 goto err;
1601
1602 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
1603 ab8500_dir);
1604 if (!ab8500_gpadc_dir)
1605 goto err;
1606
1607 file = debugfs_create_file("all-bank-registers", S_IRUGO,
1608 ab8500_dir, &plf->dev, &ab8500_registers_fops);
1609 if (!file)
1610 goto err;
1611
1612 file = debugfs_create_file("all-banks", S_IRUGO,
1613 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
1614 if (!file)
1615 goto err;
1616
1617 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
1618 ab8500_dir, &plf->dev, &ab8500_bank_fops);
1619 if (!file)
1620 goto err;
1621
1622 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
1623 ab8500_dir, &plf->dev, &ab8500_address_fops);
1624 if (!file)
1625 goto err;
1626
1627 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
1628 ab8500_dir, &plf->dev, &ab8500_val_fops);
1629 if (!file)
1630 goto err;
563 1631
564 ab8500_reg_file = debugfs_create_file("all-bank-registers", 1632 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
565 S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops); 1633 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
566 if (!ab8500_reg_file) 1634 if (!file)
567 goto exit_destroy_dir; 1635 goto err;
568 1636
569 ab8500_bank_file = debugfs_create_file("register-bank", 1637 if (is_ab8500(ab8500))
570 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops); 1638 num_interrupt_lines = AB8500_NR_IRQS;
571 if (!ab8500_bank_file) 1639 else if (is_ab8505(ab8500))
572 goto exit_destroy_reg; 1640 num_interrupt_lines = AB8505_NR_IRQS;
1641 else if (is_ab9540(ab8500))
1642 num_interrupt_lines = AB9540_NR_IRQS;
573 1643
574 ab8500_address_file = debugfs_create_file("register-address", 1644 file = debugfs_create_file("interrupts", (S_IRUGO),
575 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, 1645 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
576 &ab8500_address_fops); 1646 if (!file)
577 if (!ab8500_address_file) 1647 goto err;
578 goto exit_destroy_bank;
579 1648
580 ab8500_val_file = debugfs_create_file("register-value", 1649 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
581 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops); 1650 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
582 if (!ab8500_val_file) 1651 if (!file)
583 goto exit_destroy_address; 1652 goto err;
1653
1654 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
1655 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
1656 if (!file)
1657 goto err;
1658
1659 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
1660 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
1661 if (!file)
1662 goto err;
1663
1664 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
1665 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
1666 if (!file)
1667 goto err;
1668
1669 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
1670 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
1671 if (!file)
1672 goto err;
1673
1674 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
1675 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
1676 if (!file)
1677 goto err;
1678
1679 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
1680 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
1681 if (!file)
1682 goto err;
1683
1684 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
1685 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
1686 if (!file)
1687 goto err;
1688
1689 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
1690 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
1691 if (!file)
1692 goto err;
1693
1694 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
1695 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
1696 if (!file)
1697 goto err;
1698
1699 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
1700 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
1701 if (!file)
1702 goto err;
1703
1704 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
1705 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
1706 if (!file)
1707 goto err;
1708
1709 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
1710 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
1711 if (!file)
1712 goto err;
1713
1714 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
1715 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
1716 if (!file)
1717 goto err;
1718
1719 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
1720 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
1721 if (!file)
1722 goto err;
584 1723
585 return 0; 1724 return 0;
586 1725
587exit_destroy_address: 1726err:
588 debugfs_remove(ab8500_address_file); 1727 if (ab8500_dir)
589exit_destroy_bank: 1728 debugfs_remove_recursive(ab8500_dir);
590 debugfs_remove(ab8500_bank_file);
591exit_destroy_reg:
592 debugfs_remove(ab8500_reg_file);
593exit_destroy_dir:
594 debugfs_remove(ab8500_dir);
595exit_no_debugfs:
596 dev_err(&plf->dev, "failed to create debugfs entries.\n"); 1729 dev_err(&plf->dev, "failed to create debugfs entries.\n");
597 return -ENOMEM; 1730out_freeevent_name:
1731 kfree(event_name);
1732out_freedev_attr:
1733 kfree(dev_attr);
1734out_freeirq_count:
1735 kfree(irq_count);
1736
1737 return ret;
598} 1738}
599 1739
600static int ab8500_debug_remove(struct platform_device *plf) 1740static int ab8500_debug_remove(struct platform_device *plf)
601{ 1741{
602 debugfs_remove(ab8500_val_file); 1742 debugfs_remove_recursive(ab8500_dir);
603 debugfs_remove(ab8500_address_file); 1743 kfree(event_name);
604 debugfs_remove(ab8500_bank_file); 1744 kfree(dev_attr);
605 debugfs_remove(ab8500_reg_file); 1745 kfree(irq_count);
606 debugfs_remove(ab8500_dir);
607 1746
608 return 0; 1747 return 0;
609} 1748}
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 3fb1f40d6389..b1f3561b023f 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -12,6 +12,7 @@
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/pm_runtime.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
16#include <linux/completion.h> 17#include <linux/completion.h>
17#include <linux/regulator/consumer.h> 18#include <linux/regulator/consumer.h>
@@ -82,6 +83,11 @@
82/* This is used to not lose precision when dividing to get gain and offset */ 83/* This is used to not lose precision when dividing to get gain and offset */
83#define CALIB_SCALE 1000 84#define CALIB_SCALE 1000
84 85
86/* Time in ms before disabling regulator */
87#define GPADC_AUDOSUSPEND_DELAY 1
88
89#define CONVERSION_TIME 500 /* ms */
90
85enum cal_channels { 91enum cal_channels {
86 ADC_INPUT_VMAIN = 0, 92 ADC_INPUT_VMAIN = 0,
87 ADC_INPUT_BTEMP, 93 ADC_INPUT_BTEMP,
@@ -102,10 +108,10 @@ struct adc_cal_data {
102 108
103/** 109/**
104 * struct ab8500_gpadc - AB8500 GPADC device information 110 * struct ab8500_gpadc - AB8500 GPADC device information
105 * @chip_id ABB chip id
106 * @dev: pointer to the struct device 111 * @dev: pointer to the struct device
107 * @node: a list of AB8500 GPADCs, hence prepared for 112 * @node: a list of AB8500 GPADCs, hence prepared for
108 reentrance 113 reentrance
114 * @parent: pointer to the struct ab8500
109 * @ab8500_gpadc_complete: pointer to the struct completion, to indicate 115 * @ab8500_gpadc_complete: pointer to the struct completion, to indicate
110 * the completion of gpadc conversion 116 * the completion of gpadc conversion
111 * @ab8500_gpadc_lock: structure of type mutex 117 * @ab8500_gpadc_lock: structure of type mutex
@@ -114,9 +120,9 @@ struct adc_cal_data {
114 * @cal_data array of ADC calibration data structs 120 * @cal_data array of ADC calibration data structs
115 */ 121 */
116struct ab8500_gpadc { 122struct ab8500_gpadc {
117 u8 chip_id;
118 struct device *dev; 123 struct device *dev;
119 struct list_head node; 124 struct list_head node;
125 struct ab8500 *parent;
120 struct completion ab8500_gpadc_complete; 126 struct completion ab8500_gpadc_complete;
121 struct mutex ab8500_gpadc_lock; 127 struct mutex ab8500_gpadc_lock;
122 struct regulator *regu; 128 struct regulator *regu;
@@ -282,8 +288,9 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
282 return -ENODEV; 288 return -ENODEV;
283 289
284 mutex_lock(&gpadc->ab8500_gpadc_lock); 290 mutex_lock(&gpadc->ab8500_gpadc_lock);
291
285 /* Enable VTVout LDO this is required for GPADC */ 292 /* Enable VTVout LDO this is required for GPADC */
286 regulator_enable(gpadc->regu); 293 pm_runtime_get_sync(gpadc->dev);
287 294
288 /* Check if ADC is not busy, lock and proceed */ 295 /* Check if ADC is not busy, lock and proceed */
289 do { 296 do {
@@ -332,7 +339,7 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
332 EN_BUF | EN_ICHAR); 339 EN_BUF | EN_ICHAR);
333 break; 340 break;
334 case BTEMP_BALL: 341 case BTEMP_BALL:
335 if (gpadc->chip_id >= AB8500_CUT3P0) { 342 if (!is_ab8500_2p0_or_earlier(gpadc->parent)) {
336 /* Turn on btemp pull-up on ABB 3.0 */ 343 /* Turn on btemp pull-up on ABB 3.0 */
337 ret = abx500_mask_and_set_register_interruptible( 344 ret = abx500_mask_and_set_register_interruptible(
338 gpadc->dev, 345 gpadc->dev,
@@ -344,7 +351,7 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
344 * Delay might be needed for ABB8500 cut 3.0, if not, remove 351 * Delay might be needed for ABB8500 cut 3.0, if not, remove
345 * when hardware will be available 352 * when hardware will be available
346 */ 353 */
347 msleep(1); 354 usleep_range(1000, 1000);
348 break; 355 break;
349 } 356 }
350 /* Intentional fallthrough */ 357 /* Intentional fallthrough */
@@ -367,7 +374,8 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
367 goto out; 374 goto out;
368 } 375 }
369 /* wait for completion of conversion */ 376 /* wait for completion of conversion */
370 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 2*HZ)) { 377 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete,
378 msecs_to_jiffies(CONVERSION_TIME))) {
371 dev_err(gpadc->dev, 379 dev_err(gpadc->dev,
372 "timeout: didn't receive GPADC conversion interrupt\n"); 380 "timeout: didn't receive GPADC conversion interrupt\n");
373 ret = -EINVAL; 381 ret = -EINVAL;
@@ -397,8 +405,10 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
397 dev_err(gpadc->dev, "gpadc_conversion: disable gpadc failed\n"); 405 dev_err(gpadc->dev, "gpadc_conversion: disable gpadc failed\n");
398 goto out; 406 goto out;
399 } 407 }
400 /* Disable VTVout LDO this is required for GPADC */ 408
401 regulator_disable(gpadc->regu); 409 pm_runtime_mark_last_busy(gpadc->dev);
410 pm_runtime_put_autosuspend(gpadc->dev);
411
402 mutex_unlock(&gpadc->ab8500_gpadc_lock); 412 mutex_unlock(&gpadc->ab8500_gpadc_lock);
403 413
404 return (high_data << 8) | low_data; 414 return (high_data << 8) | low_data;
@@ -412,7 +422,9 @@ out:
412 */ 422 */
413 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 423 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
414 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 424 AB8500_GPADC_CTRL1_REG, DIS_GPADC);
415 regulator_disable(gpadc->regu); 425
426 pm_runtime_put(gpadc->dev);
427
416 mutex_unlock(&gpadc->ab8500_gpadc_lock); 428 mutex_unlock(&gpadc->ab8500_gpadc_lock);
417 dev_err(gpadc->dev, 429 dev_err(gpadc->dev,
418 "gpadc_conversion: Failed to AD convert channel %d\n", channel); 430 "gpadc_conversion: Failed to AD convert channel %d\n", channel);
@@ -571,6 +583,28 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
571 gpadc->cal_data[ADC_INPUT_VBAT].offset); 583 gpadc->cal_data[ADC_INPUT_VBAT].offset);
572} 584}
573 585
586static int ab8500_gpadc_runtime_suspend(struct device *dev)
587{
588 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
589
590 regulator_disable(gpadc->regu);
591 return 0;
592}
593
594static int ab8500_gpadc_runtime_resume(struct device *dev)
595{
596 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
597
598 regulator_enable(gpadc->regu);
599 return 0;
600}
601
602static int ab8500_gpadc_runtime_idle(struct device *dev)
603{
604 pm_runtime_suspend(dev);
605 return 0;
606}
607
574static int ab8500_gpadc_probe(struct platform_device *pdev) 608static int ab8500_gpadc_probe(struct platform_device *pdev)
575{ 609{
576 int ret = 0; 610 int ret = 0;
@@ -591,6 +625,7 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
591 } 625 }
592 626
593 gpadc->dev = &pdev->dev; 627 gpadc->dev = &pdev->dev;
628 gpadc->parent = dev_get_drvdata(pdev->dev.parent);
594 mutex_init(&gpadc->ab8500_gpadc_lock); 629 mutex_init(&gpadc->ab8500_gpadc_lock);
595 630
596 /* Initialize completion used to notify completion of conversion */ 631 /* Initialize completion used to notify completion of conversion */
@@ -607,14 +642,6 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
607 goto fail; 642 goto fail;
608 } 643 }
609 644
610 /* Get Chip ID of the ABB ASIC */
611 ret = abx500_get_chip_id(gpadc->dev);
612 if (ret < 0) {
613 dev_err(gpadc->dev, "failed to get chip ID\n");
614 goto fail_irq;
615 }
616 gpadc->chip_id = (u8) ret;
617
618 /* VTVout LDO used to power up ab8500-GPADC */ 645 /* VTVout LDO used to power up ab8500-GPADC */
619 gpadc->regu = regulator_get(&pdev->dev, "vddadc"); 646 gpadc->regu = regulator_get(&pdev->dev, "vddadc");
620 if (IS_ERR(gpadc->regu)) { 647 if (IS_ERR(gpadc->regu)) {
@@ -622,6 +649,16 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
622 dev_err(gpadc->dev, "failed to get vtvout LDO\n"); 649 dev_err(gpadc->dev, "failed to get vtvout LDO\n");
623 goto fail_irq; 650 goto fail_irq;
624 } 651 }
652
653 platform_set_drvdata(pdev, gpadc);
654
655 regulator_enable(gpadc->regu);
656
657 pm_runtime_set_autosuspend_delay(gpadc->dev, GPADC_AUDOSUSPEND_DELAY);
658 pm_runtime_use_autosuspend(gpadc->dev);
659 pm_runtime_set_active(gpadc->dev);
660 pm_runtime_enable(gpadc->dev);
661
625 ab8500_gpadc_read_calibration_data(gpadc); 662 ab8500_gpadc_read_calibration_data(gpadc);
626 list_add_tail(&gpadc->node, &ab8500_gpadc_list); 663 list_add_tail(&gpadc->node, &ab8500_gpadc_list);
627 dev_dbg(gpadc->dev, "probe success\n"); 664 dev_dbg(gpadc->dev, "probe success\n");
@@ -642,19 +679,34 @@ static int ab8500_gpadc_remove(struct platform_device *pdev)
642 list_del(&gpadc->node); 679 list_del(&gpadc->node);
643 /* remove interrupt - completion of Sw ADC conversion */ 680 /* remove interrupt - completion of Sw ADC conversion */
644 free_irq(gpadc->irq, gpadc); 681 free_irq(gpadc->irq, gpadc);
645 /* disable VTVout LDO that is being used by GPADC */ 682
646 regulator_put(gpadc->regu); 683 pm_runtime_get_sync(gpadc->dev);
684 pm_runtime_disable(gpadc->dev);
685
686 regulator_disable(gpadc->regu);
687
688 pm_runtime_set_suspended(gpadc->dev);
689
690 pm_runtime_put_noidle(gpadc->dev);
691
647 kfree(gpadc); 692 kfree(gpadc);
648 gpadc = NULL; 693 gpadc = NULL;
649 return 0; 694 return 0;
650} 695}
651 696
697static const struct dev_pm_ops ab8500_gpadc_pm_ops = {
698 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend,
699 ab8500_gpadc_runtime_resume,
700 ab8500_gpadc_runtime_idle)
701};
702
652static struct platform_driver ab8500_gpadc_driver = { 703static struct platform_driver ab8500_gpadc_driver = {
653 .probe = ab8500_gpadc_probe, 704 .probe = ab8500_gpadc_probe,
654 .remove = ab8500_gpadc_remove, 705 .remove = ab8500_gpadc_remove,
655 .driver = { 706 .driver = {
656 .name = "ab8500-gpadc", 707 .name = "ab8500-gpadc",
657 .owner = THIS_MODULE, 708 .owner = THIS_MODULE,
709 .pm = &ab8500_gpadc_pm_ops,
658 }, 710 },
659}; 711};
660 712
diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index 8a33b2c7eead..108fd86552f0 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -7,12 +7,73 @@
7#include <linux/err.h> 7#include <linux/err.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/platform_device.h> 9#include <linux/platform_device.h>
10#include <linux/pm.h>
11#include <linux/reboot.h>
12#include <linux/signal.h>
13#include <linux/power_supply.h>
10#include <linux/mfd/abx500.h> 14#include <linux/mfd/abx500.h>
11#include <linux/mfd/abx500/ab8500.h> 15#include <linux/mfd/abx500/ab8500.h>
12#include <linux/mfd/abx500/ab8500-sysctrl.h> 16#include <linux/mfd/abx500/ab8500-sysctrl.h>
13 17
14static struct device *sysctrl_dev; 18static struct device *sysctrl_dev;
15 19
20void ab8500_power_off(void)
21{
22 sigset_t old;
23 sigset_t all;
24 static char *pss[] = {"ab8500_ac", "ab8500_usb"};
25 int i;
26 bool charger_present = false;
27 union power_supply_propval val;
28 struct power_supply *psy;
29 int ret;
30
31 /*
32 * If we have a charger connected and we're powering off,
33 * reboot into charge-only mode.
34 */
35
36 for (i = 0; i < ARRAY_SIZE(pss); i++) {
37 psy = power_supply_get_by_name(pss[i]);
38 if (!psy)
39 continue;
40
41 ret = psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val);
42
43 if (!ret && val.intval) {
44 charger_present = true;
45 break;
46 }
47 }
48
49 if (!charger_present)
50 goto shutdown;
51
52 /* Check if battery is known */
53 psy = power_supply_get_by_name("ab8500_btemp");
54 if (psy) {
55 ret = psy->get_property(psy, POWER_SUPPLY_PROP_TECHNOLOGY,
56 &val);
57 if (!ret && val.intval != POWER_SUPPLY_TECHNOLOGY_UNKNOWN) {
58 printk(KERN_INFO
59 "Charger \"%s\" is connected with known battery."
60 " Rebooting.\n",
61 pss[i]);
62 machine_restart("charging");
63 }
64 }
65
66shutdown:
67 sigfillset(&all);
68
69 if (!sigprocmask(SIG_BLOCK, &all, &old)) {
70 (void)ab8500_sysctrl_set(AB8500_STW4500CTRL1,
71 AB8500_STW4500CTRL1_SWOFF |
72 AB8500_STW4500CTRL1_SWRESET4500N);
73 (void)sigprocmask(SIG_SETMASK, &old, NULL);
74 }
75}
76
16static inline bool valid_bank(u8 bank) 77static inline bool valid_bank(u8 bank)
17{ 78{
18 return ((bank == AB8500_SYS_CTRL1_BLOCK) || 79 return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
@@ -33,6 +94,7 @@ int ab8500_sysctrl_read(u16 reg, u8 *value)
33 return abx500_get_register_interruptible(sysctrl_dev, bank, 94 return abx500_get_register_interruptible(sysctrl_dev, bank,
34 (u8)(reg & 0xFF), value); 95 (u8)(reg & 0xFF), value);
35} 96}
97EXPORT_SYMBOL(ab8500_sysctrl_read);
36 98
37int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value) 99int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
38{ 100{
@@ -48,10 +110,40 @@ int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
48 return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank, 110 return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank,
49 (u8)(reg & 0xFF), mask, value); 111 (u8)(reg & 0xFF), mask, value);
50} 112}
113EXPORT_SYMBOL(ab8500_sysctrl_write);
51 114
52static int ab8500_sysctrl_probe(struct platform_device *pdev) 115static int ab8500_sysctrl_probe(struct platform_device *pdev)
53{ 116{
117 struct ab8500_platform_data *plat;
118 struct ab8500_sysctrl_platform_data *pdata;
119
54 sysctrl_dev = &pdev->dev; 120 sysctrl_dev = &pdev->dev;
121 plat = dev_get_platdata(pdev->dev.parent);
122 if (plat->pm_power_off)
123 pm_power_off = ab8500_power_off;
124
125 pdata = plat->sysctrl;
126
127 if (pdata) {
128 int ret, i, j;
129
130 for (i = AB8500_SYSCLKREQ1RFCLKBUF;
131 i <= AB8500_SYSCLKREQ8RFCLKBUF; i++) {
132 j = i - AB8500_SYSCLKREQ1RFCLKBUF;
133 ret = ab8500_sysctrl_write(i, 0xff,
134 pdata->initial_req_buf_config[j]);
135 dev_dbg(&pdev->dev,
136 "Setting SysClkReq%dRfClkBuf 0x%X\n",
137 j + 1,
138 pdata->initial_req_buf_config[j]);
139 if (ret < 0) {
140 dev_err(&pdev->dev,
141 "unable to set sysClkReq%dRfClkBuf: "
142 "%d\n", j + 1, ret);
143 }
144 }
145 }
146
55 return 0; 147 return 0;
56} 148}
57 149
diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
index 7ce65f49480f..9818afba2515 100644
--- a/drivers/mfd/abx500-core.c
+++ b/drivers/mfd/abx500-core.c
@@ -153,6 +153,22 @@ int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
153} 153}
154EXPORT_SYMBOL(abx500_startup_irq_enabled); 154EXPORT_SYMBOL(abx500_startup_irq_enabled);
155 155
156void abx500_dump_all_banks(void)
157{
158 struct abx500_ops *ops;
159 struct device dummy_child = {0};
160 struct abx500_device_entry *dev_entry;
161
162 list_for_each_entry(dev_entry, &abx500_list, list) {
163 dummy_child.parent = dev_entry->dev;
164 ops = &dev_entry->ops;
165
166 if ((ops != NULL) && (ops->dump_all_banks != NULL))
167 ops->dump_all_banks(&dummy_child);
168 }
169}
170EXPORT_SYMBOL(abx500_dump_all_banks);
171
156MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>"); 172MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
157MODULE_DESCRIPTION("ABX500 core driver"); 173MODULE_DESCRIPTION("ABX500 core driver");
158MODULE_LICENSE("GPL"); 174MODULE_LICENSE("GPL");