aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 18:15:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 18:15:24 -0400
commit151173e8ce9b95bbbbd7eedb9035cfaffbdb7cb2 (patch)
treebca02f40bdd054fa2e30f4923e1513d40873c4d9 /drivers/mfd
parent30945669593df14692e933c557d00c4bb2727857 (diff)
parent6b170807cd5cac8dc6353f47a88ccb14bbf76c4f (diff)
Merge tag 'for-v3.10' of git://git.infradead.org/battery-2.6
Pull battery updates from Anton Vorontsov: "Highlights: - OpenFirmware/DeviceTree support for the Power Supply core: the core now automatically populates supplied_from hierarchy from the device tree. With these patches chargers and batteries can now lookup each other without the board files support shim. Rhyland Klein at NVIDIA did the work - New ST-Ericsson ABX500 hwmon driver. The driver is heavily using the AB85xx core and depends on some recent changes to it, so that is why the driver comes through the battery tree. It has an appropriate ack from the hwmon maintainer (i.e. Guenter Roeck). Martin Persson at ST-Ericsson and Hongbo Zhang at Linaro authored the driver - Final bits to sync AB85xx ST-Ericsson changes into mainline. The changes touch mfd parts, but these were acked by the appropriate MFD maintainer (ie Samuel Ortiz). Lee Jones at Linaro did most of the work and lead the submission process. Minor changes, but still worth mentioning: - Battery temperature reporting fix for Nokia N900 phones - Versatile Express poweroff driver moved into drivers/power/reset/ - Tree-wide: use devm_kzalloc() where appropriate - Tree-wide: dev_pm_ops cleanups/fixes" * tag 'for-v3.10' of git://git.infradead.org/battery-2.6: (112 commits) pm2301-charger: Fix suspend/resume charger-manager: Use kmemdup instead of kzalloc + memcpy power_supply: Populate supplied_from hierarchy from the device tree power_supply: Add core support for supplied_from power_supply: Define Binding for power-supplies rx51_battery: Fix reporting temperature hwmon: Add ST-Ericsson ABX500 hwmon driver ab8500_bmdata: Export abx500_res_to_temp tables for hwmon ab8500_{bmdata,fg}: Add const attributes to some data arrays ab8500_bmdata: Eliminate CamelCase warning of some variables ab8500_btemp: Make ab8500_btemp_get* interfaces public goldfish_battery: Use resource_size() lp8788-charger: Use PAGE_SIZE for the sysfs read operation max8925_power: Use devm_kzalloc() da9030_battery: Use devm_kzalloc() da9052-battery: Use devm_kzalloc() ds2760_battery: Use devm_kzalloc() ds2780_battery: Use devm_kzalloc() gpio-charger: Use devm_kzalloc() isp1704_charger: Use devm_kzalloc() ...
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/ab8500-core.c544
-rw-r--r--drivers/mfd/ab8500-debugfs.c1741
-rw-r--r--drivers/mfd/ab8500-gpadc.c559
-rw-r--r--drivers/mfd/ab8500-sysctrl.c98
4 files changed, 2548 insertions, 394 deletions
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 7c84ced2e01b..f276352cc9ef 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -95,6 +95,7 @@
95#define AB8500_IT_MASK22_REG 0x55 95#define AB8500_IT_MASK22_REG 0x55
96#define AB8500_IT_MASK23_REG 0x56 96#define AB8500_IT_MASK23_REG 0x56
97#define AB8500_IT_MASK24_REG 0x57 97#define AB8500_IT_MASK24_REG 0x57
98#define AB8500_IT_MASK25_REG 0x58
98 99
99/* 100/*
100 * latch hierarchy registers 101 * latch hierarchy registers
@@ -102,15 +103,25 @@
102#define AB8500_IT_LATCHHIER1_REG 0x60 103#define AB8500_IT_LATCHHIER1_REG 0x60
103#define AB8500_IT_LATCHHIER2_REG 0x61 104#define AB8500_IT_LATCHHIER2_REG 0x61
104#define AB8500_IT_LATCHHIER3_REG 0x62 105#define AB8500_IT_LATCHHIER3_REG 0x62
106#define AB8540_IT_LATCHHIER4_REG 0x63
105 107
106#define AB8500_IT_LATCHHIER_NUM 3 108#define AB8500_IT_LATCHHIER_NUM 3
109#define AB8540_IT_LATCHHIER_NUM 4
107 110
108#define AB8500_REV_REG 0x80 111#define AB8500_REV_REG 0x80
109#define AB8500_IC_NAME_REG 0x82 112#define AB8500_IC_NAME_REG 0x82
110#define AB8500_SWITCH_OFF_STATUS 0x00 113#define AB8500_SWITCH_OFF_STATUS 0x00
111 114
112#define AB8500_TURN_ON_STATUS 0x00 115#define AB8500_TURN_ON_STATUS 0x00
116#define AB8505_TURN_ON_STATUS_2 0x04
113 117
118#define AB8500_CH_USBCH_STAT1_REG 0x02
119#define VBUS_DET_DBNC100 0x02
120#define VBUS_DET_DBNC1 0x01
121
122static DEFINE_SPINLOCK(on_stat_lock);
123static u8 turn_on_stat_mask = 0xFF;
124static u8 turn_on_stat_set;
114static bool no_bm; /* No battery management */ 125static bool no_bm; /* No battery management */
115module_param(no_bm, bool, S_IRUGO); 126module_param(no_bm, bool, S_IRUGO);
116 127
@@ -130,9 +141,15 @@ static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
130 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 141 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
131}; 142};
132 143
133/* AB9540 support */ 144/* AB9540 / AB8505 support */
134static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = { 145static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
135 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, 146 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23
147};
148
149/* AB8540 support */
150static const int ab8540_irq_regoffset[AB8540_NUM_IRQ_REGS] = {
151 0, 1, 2, 3, 4, -1, -1, -1, -1, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23,
152 25, 26, 27, 28, 29, 30, 31,
136}; 153};
137 154
138static const char ab8500_version_str[][7] = { 155static const char ab8500_version_str[][7] = {
@@ -352,6 +369,9 @@ static void ab8500_irq_sync_unlock(struct irq_data *data)
352 is_ab8500_1p1_or_earlier(ab8500)) 369 is_ab8500_1p1_or_earlier(ab8500))
353 continue; 370 continue;
354 371
372 if (ab8500->irq_reg_offset[i] < 0)
373 continue;
374
355 ab8500->oldmask[i] = new; 375 ab8500->oldmask[i] = new;
356 376
357 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; 377 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
@@ -423,6 +443,18 @@ static struct irq_chip ab8500_irq_chip = {
423 .irq_set_type = ab8500_irq_set_type, 443 .irq_set_type = ab8500_irq_set_type,
424}; 444};
425 445
446static void update_latch_offset(u8 *offset, int i)
447{
448 /* Fix inconsistent ITFromLatch25 bit mapping... */
449 if (unlikely(*offset == 17))
450 *offset = 24;
451 /* Fix inconsistent ab8540 bit mapping... */
452 if (unlikely(*offset == 16))
453 *offset = 25;
454 if ((i==3) && (*offset >= 24))
455 *offset += 2;
456}
457
426static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500, 458static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
427 int latch_offset, u8 latch_val) 459 int latch_offset, u8 latch_val)
428{ 460{
@@ -474,9 +506,7 @@ static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
474 latch_bit = __ffs(hier_val); 506 latch_bit = __ffs(hier_val);
475 latch_offset = (hier_offset << 3) + latch_bit; 507 latch_offset = (hier_offset << 3) + latch_bit;
476 508
477 /* Fix inconsistent ITFromLatch25 bit mapping... */ 509 update_latch_offset(&latch_offset, hier_offset);
478 if (unlikely(latch_offset == 17))
479 latch_offset = 24;
480 510
481 status = get_register_interruptible(ab8500, 511 status = get_register_interruptible(ab8500,
482 AB8500_INTERRUPT, 512 AB8500_INTERRUPT,
@@ -504,7 +534,7 @@ static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
504 dev_vdbg(ab8500->dev, "interrupt\n"); 534 dev_vdbg(ab8500->dev, "interrupt\n");
505 535
506 /* Hierarchical interrupt version */ 536 /* Hierarchical interrupt version */
507 for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) { 537 for (i = 0; i < (ab8500->it_latchhier_num); i++) {
508 int status; 538 int status;
509 u8 hier_val; 539 u8 hier_val;
510 540
@@ -520,63 +550,6 @@ static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
520 return IRQ_HANDLED; 550 return IRQ_HANDLED;
521} 551}
522 552
523/**
524 * ab8500_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ
525 *
526 * @ab8500: ab8500_irq controller to operate on.
527 * @irq: index of the interrupt requested in the chip IRQs
528 *
529 * Useful for drivers to request their own IRQs.
530 */
531static int ab8500_irq_get_virq(struct ab8500 *ab8500, int irq)
532{
533 if (!ab8500)
534 return -EINVAL;
535
536 return irq_create_mapping(ab8500->domain, irq);
537}
538
539static irqreturn_t ab8500_irq(int irq, void *dev)
540{
541 struct ab8500 *ab8500 = dev;
542 int i;
543
544 dev_vdbg(ab8500->dev, "interrupt\n");
545
546 atomic_inc(&ab8500->transfer_ongoing);
547
548 for (i = 0; i < ab8500->mask_size; i++) {
549 int regoffset = ab8500->irq_reg_offset[i];
550 int status;
551 u8 value;
552
553 /*
554 * Interrupt register 12 doesn't exist prior to AB8500 version
555 * 2.0
556 */
557 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
558 continue;
559
560 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
561 AB8500_IT_LATCH1_REG + regoffset, &value);
562 if (status < 0 || value == 0)
563 continue;
564
565 do {
566 int bit = __ffs(value);
567 int line = i * 8 + bit;
568 int virq = ab8500_irq_get_virq(ab8500, line);
569
570 handle_nested_irq(virq);
571 ab8500_debug_register_interrupt(line);
572 value &= ~(1 << bit);
573
574 } while (value);
575 }
576 atomic_dec(&ab8500->transfer_ongoing);
577 return IRQ_HANDLED;
578}
579
580static int ab8500_irq_map(struct irq_domain *d, unsigned int virq, 553static int ab8500_irq_map(struct irq_domain *d, unsigned int virq,
581 irq_hw_number_t hwirq) 554 irq_hw_number_t hwirq)
582{ 555{
@@ -607,7 +580,9 @@ static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np)
607{ 580{
608 int num_irqs; 581 int num_irqs;
609 582
610 if (is_ab9540(ab8500)) 583 if (is_ab8540(ab8500))
584 num_irqs = AB8540_NR_IRQS;
585 else if (is_ab9540(ab8500))
611 num_irqs = AB9540_NR_IRQS; 586 num_irqs = AB9540_NR_IRQS;
612 else if (is_ab8505(ab8500)) 587 else if (is_ab8505(ab8500))
613 num_irqs = AB8505_NR_IRQS; 588 num_irqs = AB8505_NR_IRQS;
@@ -650,6 +625,15 @@ static struct resource ab8500_gpadc_resources[] = {
650 }, 625 },
651}; 626};
652 627
628static struct resource ab8505_gpadc_resources[] = {
629 {
630 .name = "SW_CONV_END",
631 .start = AB8500_INT_GP_SW_ADC_CONV_END,
632 .end = AB8500_INT_GP_SW_ADC_CONV_END,
633 .flags = IORESOURCE_IRQ,
634 },
635};
636
653static struct resource ab8500_rtc_resources[] = { 637static struct resource ab8500_rtc_resources[] = {
654 { 638 {
655 .name = "60S", 639 .name = "60S",
@@ -973,6 +957,30 @@ static struct resource ab8505_iddet_resources[] = {
973 .end = AB8505_INT_KEYSTUCK, 957 .end = AB8505_INT_KEYSTUCK,
974 .flags = IORESOURCE_IRQ, 958 .flags = IORESOURCE_IRQ,
975 }, 959 },
960 {
961 .name = "VBUS_DET_R",
962 .start = AB8500_INT_VBUS_DET_R,
963 .end = AB8500_INT_VBUS_DET_R,
964 .flags = IORESOURCE_IRQ,
965 },
966 {
967 .name = "VBUS_DET_F",
968 .start = AB8500_INT_VBUS_DET_F,
969 .end = AB8500_INT_VBUS_DET_F,
970 .flags = IORESOURCE_IRQ,
971 },
972 {
973 .name = "ID_DET_PLUGR",
974 .start = AB8500_INT_ID_DET_PLUGR,
975 .end = AB8500_INT_ID_DET_PLUGR,
976 .flags = IORESOURCE_IRQ,
977 },
978 {
979 .name = "ID_DET_PLUGF",
980 .start = AB8500_INT_ID_DET_PLUGF,
981 .end = AB8500_INT_ID_DET_PLUGF,
982 .flags = IORESOURCE_IRQ,
983 },
976}; 984};
977 985
978static struct resource ab8500_temp_resources[] = { 986static struct resource ab8500_temp_resources[] = {
@@ -984,7 +992,42 @@ static struct resource ab8500_temp_resources[] = {
984 }, 992 },
985}; 993};
986 994
987static struct mfd_cell abx500_common_devs[] = { 995static struct mfd_cell ab8500_bm_devs[] = {
996 {
997 .name = "ab8500-charger",
998 .of_compatible = "stericsson,ab8500-charger",
999 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
1000 .resources = ab8500_charger_resources,
1001 .platform_data = &ab8500_bm_data,
1002 .pdata_size = sizeof(ab8500_bm_data),
1003 },
1004 {
1005 .name = "ab8500-btemp",
1006 .of_compatible = "stericsson,ab8500-btemp",
1007 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
1008 .resources = ab8500_btemp_resources,
1009 .platform_data = &ab8500_bm_data,
1010 .pdata_size = sizeof(ab8500_bm_data),
1011 },
1012 {
1013 .name = "ab8500-fg",
1014 .of_compatible = "stericsson,ab8500-fg",
1015 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
1016 .resources = ab8500_fg_resources,
1017 .platform_data = &ab8500_bm_data,
1018 .pdata_size = sizeof(ab8500_bm_data),
1019 },
1020 {
1021 .name = "ab8500-chargalg",
1022 .of_compatible = "stericsson,ab8500-chargalg",
1023 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
1024 .resources = ab8500_chargalg_resources,
1025 .platform_data = &ab8500_bm_data,
1026 .pdata_size = sizeof(ab8500_bm_data),
1027 },
1028};
1029
1030static struct mfd_cell ab8500_devs[] = {
988#ifdef CONFIG_DEBUG_FS 1031#ifdef CONFIG_DEBUG_FS
989 { 1032 {
990 .name = "ab8500-debug", 1033 .name = "ab8500-debug",
@@ -1007,7 +1050,6 @@ static struct mfd_cell abx500_common_devs[] = {
1007 }, 1050 },
1008 { 1051 {
1009 .name = "ab8500-gpadc", 1052 .name = "ab8500-gpadc",
1010 .of_compatible = "stericsson,ab8500-gpadc",
1011 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources), 1053 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
1012 .resources = ab8500_gpadc_resources, 1054 .resources = ab8500_gpadc_resources,
1013 }, 1055 },
@@ -1024,6 +1066,7 @@ static struct mfd_cell abx500_common_devs[] = {
1024 .resources = ab8500_av_acc_detect_resources, 1066 .resources = ab8500_av_acc_detect_resources,
1025 }, 1067 },
1026 { 1068 {
1069
1027 .name = "ab8500-poweron-key", 1070 .name = "ab8500-poweron-key",
1028 .of_compatible = "stericsson,ab8500-poweron-key", 1071 .of_compatible = "stericsson,ab8500-poweron-key",
1029 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources), 1072 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
@@ -1053,82 +1096,220 @@ static struct mfd_cell abx500_common_devs[] = {
1053 .of_compatible = "stericsson,ab8500-denc", 1096 .of_compatible = "stericsson,ab8500-denc",
1054 }, 1097 },
1055 { 1098 {
1099 .name = "ab8500-gpio",
1100 .of_compatible = "stericsson,ab8500-gpio",
1101 },
1102 {
1056 .name = "abx500-temp", 1103 .name = "abx500-temp",
1057 .of_compatible = "stericsson,abx500-temp", 1104 .of_compatible = "stericsson,abx500-temp",
1058 .num_resources = ARRAY_SIZE(ab8500_temp_resources), 1105 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1059 .resources = ab8500_temp_resources, 1106 .resources = ab8500_temp_resources,
1060 }, 1107 },
1108 {
1109 .name = "ab8500-usb",
1110 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1111 .resources = ab8500_usb_resources,
1112 },
1113 {
1114 .name = "ab8500-codec",
1115 },
1061}; 1116};
1062 1117
1063static struct mfd_cell ab8500_bm_devs[] = { 1118static struct mfd_cell ab9540_devs[] = {
1119#ifdef CONFIG_DEBUG_FS
1064 { 1120 {
1065 .name = "ab8500-charger", 1121 .name = "ab8500-debug",
1066 .of_compatible = "stericsson,ab8500-charger", 1122 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
1067 .num_resources = ARRAY_SIZE(ab8500_charger_resources), 1123 .resources = ab8500_debug_resources,
1068 .resources = ab8500_charger_resources,
1069 .platform_data = &ab8500_bm_data,
1070 .pdata_size = sizeof(ab8500_bm_data),
1071 }, 1124 },
1125#endif
1072 { 1126 {
1073 .name = "ab8500-btemp", 1127 .name = "ab8500-sysctrl",
1074 .of_compatible = "stericsson,ab8500-btemp",
1075 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
1076 .resources = ab8500_btemp_resources,
1077 .platform_data = &ab8500_bm_data,
1078 .pdata_size = sizeof(ab8500_bm_data),
1079 }, 1128 },
1080 { 1129 {
1081 .name = "ab8500-fg", 1130 .name = "ab8500-regulator",
1082 .of_compatible = "stericsson,ab8500-fg",
1083 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
1084 .resources = ab8500_fg_resources,
1085 .platform_data = &ab8500_bm_data,
1086 .pdata_size = sizeof(ab8500_bm_data),
1087 }, 1131 },
1088 { 1132 {
1089 .name = "ab8500-chargalg", 1133 .name = "abx500-clk",
1090 .of_compatible = "stericsson,ab8500-chargalg", 1134 .of_compatible = "stericsson,abx500-clk",
1091 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources), 1135 },
1092 .resources = ab8500_chargalg_resources, 1136 {
1093 .platform_data = &ab8500_bm_data, 1137 .name = "ab8500-gpadc",
1094 .pdata_size = sizeof(ab8500_bm_data), 1138 .of_compatible = "stericsson,ab8500-gpadc",
1139 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
1140 .resources = ab8500_gpadc_resources,
1141 },
1142 {
1143 .name = "ab8500-rtc",
1144 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
1145 .resources = ab8500_rtc_resources,
1146 },
1147 {
1148 .name = "ab8500-acc-det",
1149 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
1150 .resources = ab8500_av_acc_detect_resources,
1151 },
1152 {
1153 .name = "ab8500-poweron-key",
1154 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1155 .resources = ab8500_poweronkey_db_resources,
1156 },
1157 {
1158 .name = "ab8500-pwm",
1159 .id = 1,
1160 },
1161 {
1162 .name = "ab8500-leds",
1163 },
1164 {
1165 .name = "abx500-temp",
1166 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1167 .resources = ab8500_temp_resources,
1168 },
1169 {
1170 .name = "pinctrl-ab9540",
1171 .of_compatible = "stericsson,ab9540-gpio",
1172 },
1173 {
1174 .name = "ab9540-usb",
1175 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1176 .resources = ab8500_usb_resources,
1177 },
1178 {
1179 .name = "ab9540-codec",
1180 },
1181 {
1182 .name = "ab-iddet",
1183 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
1184 .resources = ab8505_iddet_resources,
1095 }, 1185 },
1096}; 1186};
1097 1187
1098static struct mfd_cell ab8500_devs[] = { 1188/* Device list for ab8505 */
1189static struct mfd_cell ab8505_devs[] = {
1190#ifdef CONFIG_DEBUG_FS
1099 { 1191 {
1100 .name = "pinctrl-ab8500", 1192 .name = "ab8500-debug",
1101 .of_compatible = "stericsson,ab8500-gpio", 1193 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
1194 .resources = ab8500_debug_resources,
1195 },
1196#endif
1197 {
1198 .name = "ab8500-sysctrl",
1199 },
1200 {
1201 .name = "ab8500-regulator",
1202 },
1203 {
1204 .name = "abx500-clk",
1205 .of_compatible = "stericsson,abx500-clk",
1206 },
1207 {
1208 .name = "ab8500-gpadc",
1209 .num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
1210 .resources = ab8505_gpadc_resources,
1211 },
1212 {
1213 .name = "ab8500-rtc",
1214 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
1215 .resources = ab8500_rtc_resources,
1216 },
1217 {
1218 .name = "ab8500-acc-det",
1219 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
1220 .resources = ab8500_av_acc_detect_resources,
1221 },
1222 {
1223 .name = "ab8500-poweron-key",
1224 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1225 .resources = ab8500_poweronkey_db_resources,
1226 },
1227 {
1228 .name = "ab8500-pwm",
1229 .id = 1,
1230 },
1231 {
1232 .name = "ab8500-leds",
1233 },
1234 {
1235 .name = "ab8500-gpio",
1102 }, 1236 },
1103 { 1237 {
1104 .name = "ab8500-usb", 1238 .name = "ab8500-usb",
1105 .of_compatible = "stericsson,ab8500-usb",
1106 .num_resources = ARRAY_SIZE(ab8500_usb_resources), 1239 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1107 .resources = ab8500_usb_resources, 1240 .resources = ab8500_usb_resources,
1108 }, 1241 },
1109 { 1242 {
1110 .name = "ab8500-codec", 1243 .name = "ab8500-codec",
1111 .of_compatible = "stericsson,ab8500-codec", 1244 },
1245 {
1246 .name = "ab-iddet",
1247 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
1248 .resources = ab8505_iddet_resources,
1112 }, 1249 },
1113}; 1250};
1114 1251
1115static struct mfd_cell ab9540_devs[] = { 1252static struct mfd_cell ab8540_devs[] = {
1253#ifdef CONFIG_DEBUG_FS
1116 { 1254 {
1117 .name = "pinctrl-ab9540", 1255 .name = "ab8500-debug",
1118 .of_compatible = "stericsson,ab9540-gpio", 1256 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
1257 .resources = ab8500_debug_resources,
1258 },
1259#endif
1260 {
1261 .name = "ab8500-sysctrl",
1119 }, 1262 },
1120 { 1263 {
1121 .name = "ab9540-usb", 1264 .name = "ab8500-regulator",
1265 },
1266 {
1267 .name = "abx500-clk",
1268 .of_compatible = "stericsson,abx500-clk",
1269 },
1270 {
1271 .name = "ab8500-gpadc",
1272 .num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
1273 .resources = ab8505_gpadc_resources,
1274 },
1275 {
1276 .name = "ab8500-rtc",
1277 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
1278 .resources = ab8500_rtc_resources,
1279 },
1280 {
1281 .name = "ab8500-acc-det",
1282 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
1283 .resources = ab8500_av_acc_detect_resources,
1284 },
1285 {
1286 .name = "ab8500-poweron-key",
1287 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1288 .resources = ab8500_poweronkey_db_resources,
1289 },
1290 {
1291 .name = "ab8500-pwm",
1292 .id = 1,
1293 },
1294 {
1295 .name = "ab8500-leds",
1296 },
1297 {
1298 .name = "abx500-temp",
1299 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1300 .resources = ab8500_temp_resources,
1301 },
1302 {
1303 .name = "ab8500-gpio",
1304 },
1305 {
1306 .name = "ab8540-usb",
1122 .num_resources = ARRAY_SIZE(ab8500_usb_resources), 1307 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1123 .resources = ab8500_usb_resources, 1308 .resources = ab8500_usb_resources,
1124 }, 1309 },
1125 { 1310 {
1126 .name = "ab9540-codec", 1311 .name = "ab8540-codec",
1127 }, 1312 },
1128};
1129
1130/* Device list common to ab9540 and ab8505 */
1131static struct mfd_cell ab9540_ab8505_devs[] = {
1132 { 1313 {
1133 .name = "ab-iddet", 1314 .name = "ab-iddet",
1134 .num_resources = ARRAY_SIZE(ab8505_iddet_resources), 1315 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
@@ -1142,6 +1323,7 @@ static ssize_t show_chip_id(struct device *dev,
1142 struct ab8500 *ab8500; 1323 struct ab8500 *ab8500;
1143 1324
1144 ab8500 = dev_get_drvdata(dev); 1325 ab8500 = dev_get_drvdata(dev);
1326
1145 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); 1327 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
1146} 1328}
1147 1329
@@ -1171,6 +1353,15 @@ static ssize_t show_switch_off_status(struct device *dev,
1171 return sprintf(buf, "%#x\n", value); 1353 return sprintf(buf, "%#x\n", value);
1172} 1354}
1173 1355
1356/* use mask and set to override the register turn_on_stat value */
1357void ab8500_override_turn_on_stat(u8 mask, u8 set)
1358{
1359 spin_lock(&on_stat_lock);
1360 turn_on_stat_mask = mask;
1361 turn_on_stat_set = set;
1362 spin_unlock(&on_stat_lock);
1363}
1364
1174/* 1365/*
1175 * ab8500 has turned on due to (TURN_ON_STATUS): 1366 * ab8500 has turned on due to (TURN_ON_STATUS):
1176 * 0x01 PORnVbat 1367 * 0x01 PORnVbat
@@ -1194,9 +1385,38 @@ static ssize_t show_turn_on_status(struct device *dev,
1194 AB8500_TURN_ON_STATUS, &value); 1385 AB8500_TURN_ON_STATUS, &value);
1195 if (ret < 0) 1386 if (ret < 0)
1196 return ret; 1387 return ret;
1388
1389 /*
1390 * In L9540, turn_on_status register is not updated correctly if
1391 * the device is rebooted with AC/USB charger connected. Due to
1392 * this, the device boots android instead of entering into charge
1393 * only mode. Read the AC/USB status register to detect the charger
1394 * presence and update the turn on status manually.
1395 */
1396 if (is_ab9540(ab8500)) {
1397 spin_lock(&on_stat_lock);
1398 value = (value & turn_on_stat_mask) | turn_on_stat_set;
1399 spin_unlock(&on_stat_lock);
1400 }
1401
1197 return sprintf(buf, "%#x\n", value); 1402 return sprintf(buf, "%#x\n", value);
1198} 1403}
1199 1404
1405static ssize_t show_turn_on_status_2(struct device *dev,
1406 struct device_attribute *attr, char *buf)
1407{
1408 int ret;
1409 u8 value;
1410 struct ab8500 *ab8500;
1411
1412 ab8500 = dev_get_drvdata(dev);
1413 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
1414 AB8505_TURN_ON_STATUS_2, &value);
1415 if (ret < 0)
1416 return ret;
1417 return sprintf(buf, "%#x\n", (value & 0x1));
1418}
1419
1200static ssize_t show_ab9540_dbbrstn(struct device *dev, 1420static ssize_t show_ab9540_dbbrstn(struct device *dev,
1201 struct device_attribute *attr, char *buf) 1421 struct device_attribute *attr, char *buf)
1202{ 1422{
@@ -1253,6 +1473,7 @@ exit:
1253static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL); 1473static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
1254static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL); 1474static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
1255static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL); 1475static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
1476static DEVICE_ATTR(turn_on_status_2, S_IRUGO, show_turn_on_status_2, NULL);
1256static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR, 1477static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
1257 show_ab9540_dbbrstn, store_ab9540_dbbrstn); 1478 show_ab9540_dbbrstn, store_ab9540_dbbrstn);
1258 1479
@@ -1263,6 +1484,11 @@ static struct attribute *ab8500_sysfs_entries[] = {
1263 NULL, 1484 NULL,
1264}; 1485};
1265 1486
1487static struct attribute *ab8505_sysfs_entries[] = {
1488 &dev_attr_turn_on_status_2.attr,
1489 NULL,
1490};
1491
1266static struct attribute *ab9540_sysfs_entries[] = { 1492static struct attribute *ab9540_sysfs_entries[] = {
1267 &dev_attr_chip_id.attr, 1493 &dev_attr_chip_id.attr,
1268 &dev_attr_switch_off_status.attr, 1494 &dev_attr_switch_off_status.attr,
@@ -1275,6 +1501,10 @@ static struct attribute_group ab8500_attr_group = {
1275 .attrs = ab8500_sysfs_entries, 1501 .attrs = ab8500_sysfs_entries,
1276}; 1502};
1277 1503
1504static struct attribute_group ab8505_attr_group = {
1505 .attrs = ab8505_sysfs_entries,
1506};
1507
1278static struct attribute_group ab9540_attr_group = { 1508static struct attribute_group ab9540_attr_group = {
1279 .attrs = ab9540_sysfs_entries, 1509 .attrs = ab9540_sysfs_entries,
1280}; 1510};
@@ -1290,6 +1520,15 @@ static int ab8500_probe(struct platform_device *pdev)
1290 "Battery level lower than power on reset threshold", 1520 "Battery level lower than power on reset threshold",
1291 "Power on key 1 pressed longer than 10 seconds", 1521 "Power on key 1 pressed longer than 10 seconds",
1292 "DB8500 thermal shutdown"}; 1522 "DB8500 thermal shutdown"};
1523 static char *turn_on_status[] = {
1524 "Battery rising (Vbat)",
1525 "Power On Key 1 dbF",
1526 "Power On Key 2 dbF",
1527 "RTC Alarm",
1528 "Main Charger Detect",
1529 "Vbus Detect (USB)",
1530 "USB ID Detect",
1531 "UART Factory Mode Detect"};
1293 struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev); 1532 struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev);
1294 const struct platform_device_id *platid = platform_get_device_id(pdev); 1533 const struct platform_device_id *platid = platform_get_device_id(pdev);
1295 enum ab8500_version version = AB8500_VERSION_UNDEFINED; 1534 enum ab8500_version version = AB8500_VERSION_UNDEFINED;
@@ -1351,13 +1590,20 @@ static int ab8500_probe(struct platform_device *pdev)
1351 ab8500->chip_id >> 4, 1590 ab8500->chip_id >> 4,
1352 ab8500->chip_id & 0x0F); 1591 ab8500->chip_id & 0x0F);
1353 1592
1354 /* Configure AB8500 or AB9540 IRQ */ 1593 /* Configure AB8540 */
1355 if (is_ab9540(ab8500) || is_ab8505(ab8500)) { 1594 if (is_ab8540(ab8500)) {
1595 ab8500->mask_size = AB8540_NUM_IRQ_REGS;
1596 ab8500->irq_reg_offset = ab8540_irq_regoffset;
1597 ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM;
1598 }/* Configure AB8500 or AB9540 IRQ */
1599 else if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
1356 ab8500->mask_size = AB9540_NUM_IRQ_REGS; 1600 ab8500->mask_size = AB9540_NUM_IRQ_REGS;
1357 ab8500->irq_reg_offset = ab9540_irq_regoffset; 1601 ab8500->irq_reg_offset = ab9540_irq_regoffset;
1602 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
1358 } else { 1603 } else {
1359 ab8500->mask_size = AB8500_NUM_IRQ_REGS; 1604 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
1360 ab8500->irq_reg_offset = ab8500_irq_regoffset; 1605 ab8500->irq_reg_offset = ab8500_irq_regoffset;
1606 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
1361 } 1607 }
1362 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL); 1608 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL);
1363 if (!ab8500->mask) 1609 if (!ab8500->mask)
@@ -1396,10 +1642,36 @@ static int ab8500_probe(struct platform_device *pdev)
1396 } else { 1642 } else {
1397 printk(KERN_CONT " None\n"); 1643 printk(KERN_CONT " None\n");
1398 } 1644 }
1645 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
1646 AB8500_TURN_ON_STATUS, &value);
1647 if (ret < 0)
1648 return ret;
1649 dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value);
1650
1651 if (value) {
1652 for (i = 0; i < ARRAY_SIZE(turn_on_status); i++) {
1653 if (value & 1)
1654 printk("\"%s\" ", turn_on_status[i]);
1655 value = value >> 1;
1656 }
1657 printk("\n");
1658 } else {
1659 printk("None\n");
1660 }
1399 1661
1400 if (plat && plat->init) 1662 if (plat && plat->init)
1401 plat->init(ab8500); 1663 plat->init(ab8500);
1402 1664
1665 if (is_ab9540(ab8500)) {
1666 ret = get_register_interruptible(ab8500, AB8500_CHARGER,
1667 AB8500_CH_USBCH_STAT1_REG, &value);
1668 if (ret < 0)
1669 return ret;
1670 if ((value & VBUS_DET_DBNC1) && (value & VBUS_DET_DBNC100))
1671 ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
1672 AB8500_VBUS_DET);
1673 }
1674
1403 /* Clear and mask all interrupts */ 1675 /* Clear and mask all interrupts */
1404 for (i = 0; i < ab8500->mask_size; i++) { 1676 for (i = 0; i < ab8500->mask_size; i++) {
1405 /* 1677 /*
@@ -1410,6 +1682,9 @@ static int ab8500_probe(struct platform_device *pdev)
1410 is_ab8500_1p1_or_earlier(ab8500)) 1682 is_ab8500_1p1_or_earlier(ab8500))
1411 continue; 1683 continue;
1412 1684
1685 if (ab8500->irq_reg_offset[i] < 0)
1686 continue;
1687
1413 get_register_interruptible(ab8500, AB8500_INTERRUPT, 1688 get_register_interruptible(ab8500, AB8500_INTERRUPT,
1414 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], 1689 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
1415 &value); 1690 &value);
@@ -1428,26 +1703,10 @@ static int ab8500_probe(struct platform_device *pdev)
1428 if (ret) 1703 if (ret)
1429 return ret; 1704 return ret;
1430 1705
1431 /* Activate this feature only in ab9540 */ 1706 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
1432 /* till tests are done on ab8500 1p2 or later*/ 1707 ab8500_hierarchical_irq,
1433 if (is_ab9540(ab8500)) { 1708 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1434 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, 1709 "ab8500", ab8500);
1435 ab8500_hierarchical_irq,
1436 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1437 "ab8500", ab8500);
1438 }
1439 else {
1440 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
1441 ab8500_irq,
1442 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1443 "ab8500", ab8500);
1444 if (ret)
1445 return ret;
1446 }
1447
1448 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1449 ARRAY_SIZE(abx500_common_devs), NULL,
1450 ab8500->irq_base, ab8500->domain);
1451 if (ret) 1710 if (ret)
1452 return ret; 1711 return ret;
1453 1712
@@ -1455,6 +1714,14 @@ static int ab8500_probe(struct platform_device *pdev)
1455 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, 1714 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
1456 ARRAY_SIZE(ab9540_devs), NULL, 1715 ARRAY_SIZE(ab9540_devs), NULL,
1457 ab8500->irq_base, ab8500->domain); 1716 ab8500->irq_base, ab8500->domain);
1717 else if (is_ab8540(ab8500))
1718 ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs,
1719 ARRAY_SIZE(ab8540_devs), NULL,
1720 ab8500->irq_base, ab8500->domain);
1721 else if (is_ab8505(ab8500))
1722 ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs,
1723 ARRAY_SIZE(ab8505_devs), NULL,
1724 ab8500->irq_base, ab8500->domain);
1458 else 1725 else
1459 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, 1726 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
1460 ARRAY_SIZE(ab8500_devs), NULL, 1727 ARRAY_SIZE(ab8500_devs), NULL,
@@ -1462,13 +1729,6 @@ static int ab8500_probe(struct platform_device *pdev)
1462 if (ret) 1729 if (ret)
1463 return ret; 1730 return ret;
1464 1731
1465 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1466 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
1467 ARRAY_SIZE(ab9540_ab8505_devs), NULL,
1468 ab8500->irq_base, ab8500->domain);
1469 if (ret)
1470 return ret;
1471
1472 if (!no_bm) { 1732 if (!no_bm) {
1473 /* Add battery management devices */ 1733 /* Add battery management devices */
1474 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, 1734 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
@@ -1478,12 +1738,19 @@ static int ab8500_probe(struct platform_device *pdev)
1478 dev_err(ab8500->dev, "error adding bm devices\n"); 1738 dev_err(ab8500->dev, "error adding bm devices\n");
1479 } 1739 }
1480 1740
1481 if (is_ab9540(ab8500)) 1741 if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1742 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
1482 ret = sysfs_create_group(&ab8500->dev->kobj, 1743 ret = sysfs_create_group(&ab8500->dev->kobj,
1483 &ab9540_attr_group); 1744 &ab9540_attr_group);
1484 else 1745 else
1485 ret = sysfs_create_group(&ab8500->dev->kobj, 1746 ret = sysfs_create_group(&ab8500->dev->kobj,
1486 &ab8500_attr_group); 1747 &ab8500_attr_group);
1748
1749 if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1750 ab8500->chip_id >= AB8500_CUT2P0)
1751 ret = sysfs_create_group(&ab8500->dev->kobj,
1752 &ab8505_attr_group);
1753
1487 if (ret) 1754 if (ret)
1488 dev_err(ab8500->dev, "error creating sysfs entries\n"); 1755 dev_err(ab8500->dev, "error creating sysfs entries\n");
1489 1756
@@ -1494,11 +1761,16 @@ static int ab8500_remove(struct platform_device *pdev)
1494{ 1761{
1495 struct ab8500 *ab8500 = platform_get_drvdata(pdev); 1762 struct ab8500 *ab8500 = platform_get_drvdata(pdev);
1496 1763
1497 if (is_ab9540(ab8500)) 1764 if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1765 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
1498 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); 1766 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
1499 else 1767 else
1500 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group); 1768 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
1501 1769
1770 if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1771 ab8500->chip_id >= AB8500_CUT2P0)
1772 sysfs_remove_group(&ab8500->dev->kobj, &ab8505_attr_group);
1773
1502 mfd_remove_devices(ab8500->dev); 1774 mfd_remove_devices(ab8500->dev);
1503 1775
1504 return 0; 1776 return 0;
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 45fe3c50eb03..b88bbbc15f1e 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -80,6 +80,7 @@
80#include <linux/interrupt.h> 80#include <linux/interrupt.h>
81#include <linux/kobject.h> 81#include <linux/kobject.h>
82#include <linux/slab.h> 82#include <linux/slab.h>
83#include <linux/irq.h>
83 84
84#include <linux/mfd/abx500.h> 85#include <linux/mfd/abx500.h>
85#include <linux/mfd/abx500/ab8500.h> 86#include <linux/mfd/abx500/ab8500.h>
@@ -90,6 +91,9 @@
90#include <linux/ctype.h> 91#include <linux/ctype.h>
91#endif 92#endif
92 93
94/* TODO: this file should not reference IRQ_DB8500_AB8500! */
95#include <mach/irqs.h>
96
93static u32 debug_bank; 97static u32 debug_bank;
94static u32 debug_address; 98static u32 debug_address;
95 99
@@ -101,6 +105,11 @@ static int num_irqs;
101static struct device_attribute **dev_attr; 105static struct device_attribute **dev_attr;
102static char **event_name; 106static char **event_name;
103 107
108static u8 avg_sample = SAMPLE_16;
109static u8 trig_edge = RISING_EDGE;
110static u8 conv_type = ADC_SW;
111static u8 trig_timer;
112
104/** 113/**
105 * struct ab8500_reg_range 114 * struct ab8500_reg_range
106 * @first: the first address of the range 115 * @first: the first address of the range
@@ -150,7 +159,9 @@ static struct hwreg_cfg hwreg_cfg = {
150 159
151#define AB8500_REV_REG 0x80 160#define AB8500_REV_REG 0x80
152 161
153static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { 162static struct ab8500_prcmu_ranges *debug_ranges;
163
164struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
154 [0x0] = { 165 [0x0] = {
155 .num_ranges = 0, 166 .num_ranges = 0,
156 .range = NULL, 167 .range = NULL,
@@ -354,7 +365,7 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
354 }, 365 },
355 { 366 {
356 .first = 0xf5, 367 .first = 0xf5,
357 .last = 0xf6, 368 .last = 0xf6,
358 }, 369 },
359 }, 370 },
360 }, 371 },
@@ -479,6 +490,781 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
479 }, 490 },
480}; 491};
481 492
493struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
494 [0x0] = {
495 .num_ranges = 0,
496 .range = NULL,
497 },
498 [AB8500_SYS_CTRL1_BLOCK] = {
499 .num_ranges = 5,
500 .range = (struct ab8500_reg_range[]) {
501 {
502 .first = 0x00,
503 .last = 0x04,
504 },
505 {
506 .first = 0x42,
507 .last = 0x42,
508 },
509 {
510 .first = 0x52,
511 .last = 0x52,
512 },
513 {
514 .first = 0x54,
515 .last = 0x57,
516 },
517 {
518 .first = 0x80,
519 .last = 0x83,
520 },
521 },
522 },
523 [AB8500_SYS_CTRL2_BLOCK] = {
524 .num_ranges = 5,
525 .range = (struct ab8500_reg_range[]) {
526 {
527 .first = 0x00,
528 .last = 0x0D,
529 },
530 {
531 .first = 0x0F,
532 .last = 0x17,
533 },
534 {
535 .first = 0x20,
536 .last = 0x20,
537 },
538 {
539 .first = 0x30,
540 .last = 0x30,
541 },
542 {
543 .first = 0x32,
544 .last = 0x3A,
545 },
546 },
547 },
548 [AB8500_REGU_CTRL1] = {
549 .num_ranges = 3,
550 .range = (struct ab8500_reg_range[]) {
551 {
552 .first = 0x00,
553 .last = 0x00,
554 },
555 {
556 .first = 0x03,
557 .last = 0x11,
558 },
559 {
560 .first = 0x80,
561 .last = 0x86,
562 },
563 },
564 },
565 [AB8500_REGU_CTRL2] = {
566 .num_ranges = 6,
567 .range = (struct ab8500_reg_range[]) {
568 {
569 .first = 0x00,
570 .last = 0x06,
571 },
572 {
573 .first = 0x08,
574 .last = 0x15,
575 },
576 {
577 .first = 0x17,
578 .last = 0x19,
579 },
580 {
581 .first = 0x1B,
582 .last = 0x1D,
583 },
584 {
585 .first = 0x1F,
586 .last = 0x30,
587 },
588 {
589 .first = 0x40,
590 .last = 0x48,
591 },
592 /* 0x80-0x8B is SIM registers and should
593 * not be accessed from here */
594 },
595 },
596 [AB8500_USB] = {
597 .num_ranges = 3,
598 .range = (struct ab8500_reg_range[]) {
599 {
600 .first = 0x80,
601 .last = 0x83,
602 },
603 {
604 .first = 0x87,
605 .last = 0x8A,
606 },
607 {
608 .first = 0x91,
609 .last = 0x94,
610 },
611 },
612 },
613 [AB8500_TVOUT] = {
614 .num_ranges = 0,
615 .range = NULL,
616 },
617 [AB8500_DBI] = {
618 .num_ranges = 0,
619 .range = NULL,
620 },
621 [AB8500_ECI_AV_ACC] = {
622 .num_ranges = 1,
623 .range = (struct ab8500_reg_range[]) {
624 {
625 .first = 0x80,
626 .last = 0x82,
627 },
628 },
629 },
630 [AB8500_RESERVED] = {
631 .num_ranges = 0,
632 .range = NULL,
633 },
634 [AB8500_GPADC] = {
635 .num_ranges = 1,
636 .range = (struct ab8500_reg_range[]) {
637 {
638 .first = 0x00,
639 .last = 0x08,
640 },
641 },
642 },
643 [AB8500_CHARGER] = {
644 .num_ranges = 9,
645 .range = (struct ab8500_reg_range[]) {
646 {
647 .first = 0x02,
648 .last = 0x03,
649 },
650 {
651 .first = 0x05,
652 .last = 0x05,
653 },
654 {
655 .first = 0x40,
656 .last = 0x44,
657 },
658 {
659 .first = 0x50,
660 .last = 0x57,
661 },
662 {
663 .first = 0x60,
664 .last = 0x60,
665 },
666 {
667 .first = 0xA0,
668 .last = 0xA7,
669 },
670 {
671 .first = 0xAF,
672 .last = 0xB2,
673 },
674 {
675 .first = 0xC0,
676 .last = 0xC2,
677 },
678 {
679 .first = 0xF5,
680 .last = 0xF5,
681 },
682 },
683 },
684 [AB8500_GAS_GAUGE] = {
685 .num_ranges = 3,
686 .range = (struct ab8500_reg_range[]) {
687 {
688 .first = 0x00,
689 .last = 0x00,
690 },
691 {
692 .first = 0x07,
693 .last = 0x0A,
694 },
695 {
696 .first = 0x10,
697 .last = 0x14,
698 },
699 },
700 },
701 [AB8500_AUDIO] = {
702 .num_ranges = 1,
703 .range = (struct ab8500_reg_range[]) {
704 {
705 .first = 0x00,
706 .last = 0x83,
707 },
708 },
709 },
710 [AB8500_INTERRUPT] = {
711 .num_ranges = 11,
712 .range = (struct ab8500_reg_range[]) {
713 {
714 .first = 0x00,
715 .last = 0x04,
716 },
717 {
718 .first = 0x06,
719 .last = 0x07,
720 },
721 {
722 .first = 0x09,
723 .last = 0x09,
724 },
725 {
726 .first = 0x0B,
727 .last = 0x0C,
728 },
729 {
730 .first = 0x12,
731 .last = 0x15,
732 },
733 {
734 .first = 0x18,
735 .last = 0x18,
736 },
737 /* Latch registers should not be read here */
738 {
739 .first = 0x40,
740 .last = 0x44,
741 },
742 {
743 .first = 0x46,
744 .last = 0x49,
745 },
746 {
747 .first = 0x4B,
748 .last = 0x4D,
749 },
750 {
751 .first = 0x52,
752 .last = 0x55,
753 },
754 {
755 .first = 0x58,
756 .last = 0x58,
757 },
758 /* LatchHier registers should not be read here */
759 },
760 },
761 [AB8500_RTC] = {
762 .num_ranges = 2,
763 .range = (struct ab8500_reg_range[]) {
764 {
765 .first = 0x00,
766 .last = 0x14,
767 },
768 {
769 .first = 0x16,
770 .last = 0x17,
771 },
772 },
773 },
774 [AB8500_MISC] = {
775 .num_ranges = 8,
776 .range = (struct ab8500_reg_range[]) {
777 {
778 .first = 0x00,
779 .last = 0x06,
780 },
781 {
782 .first = 0x10,
783 .last = 0x16,
784 },
785 {
786 .first = 0x20,
787 .last = 0x26,
788 },
789 {
790 .first = 0x30,
791 .last = 0x36,
792 },
793 {
794 .first = 0x40,
795 .last = 0x46,
796 },
797 {
798 .first = 0x50,
799 .last = 0x50,
800 },
801 {
802 .first = 0x60,
803 .last = 0x6B,
804 },
805 {
806 .first = 0x80,
807 .last = 0x82,
808 },
809 },
810 },
811 [AB8500_DEVELOPMENT] = {
812 .num_ranges = 2,
813 .range = (struct ab8500_reg_range[]) {
814 {
815 .first = 0x00,
816 .last = 0x00,
817 },
818 {
819 .first = 0x05,
820 .last = 0x05,
821 },
822 },
823 },
824 [AB8500_DEBUG] = {
825 .num_ranges = 1,
826 .range = (struct ab8500_reg_range[]) {
827 {
828 .first = 0x05,
829 .last = 0x07,
830 },
831 },
832 },
833 [AB8500_PROD_TEST] = {
834 .num_ranges = 0,
835 .range = NULL,
836 },
837 [AB8500_STE_TEST] = {
838 .num_ranges = 0,
839 .range = NULL,
840 },
841 [AB8500_OTP_EMUL] = {
842 .num_ranges = 1,
843 .range = (struct ab8500_reg_range[]) {
844 {
845 .first = 0x01,
846 .last = 0x15,
847 },
848 },
849 },
850};
851
852struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
853 [AB8500_M_FSM_RANK] = {
854 .num_ranges = 1,
855 .range = (struct ab8500_reg_range[]) {
856 {
857 .first = 0x00,
858 .last = 0x0B,
859 },
860 },
861 },
862 [AB8500_SYS_CTRL1_BLOCK] = {
863 .num_ranges = 6,
864 .range = (struct ab8500_reg_range[]) {
865 {
866 .first = 0x00,
867 .last = 0x04,
868 },
869 {
870 .first = 0x42,
871 .last = 0x42,
872 },
873 {
874 .first = 0x50,
875 .last = 0x54,
876 },
877 {
878 .first = 0x57,
879 .last = 0x57,
880 },
881 {
882 .first = 0x80,
883 .last = 0x83,
884 },
885 {
886 .first = 0x90,
887 .last = 0x90,
888 },
889 },
890 },
891 [AB8500_SYS_CTRL2_BLOCK] = {
892 .num_ranges = 5,
893 .range = (struct ab8500_reg_range[]) {
894 {
895 .first = 0x00,
896 .last = 0x0D,
897 },
898 {
899 .first = 0x0F,
900 .last = 0x10,
901 },
902 {
903 .first = 0x20,
904 .last = 0x21,
905 },
906 {
907 .first = 0x32,
908 .last = 0x3C,
909 },
910 {
911 .first = 0x40,
912 .last = 0x42,
913 },
914 },
915 },
916 [AB8500_REGU_CTRL1] = {
917 .num_ranges = 4,
918 .range = (struct ab8500_reg_range[]) {
919 {
920 .first = 0x03,
921 .last = 0x15,
922 },
923 {
924 .first = 0x20,
925 .last = 0x20,
926 },
927 {
928 .first = 0x80,
929 .last = 0x85,
930 },
931 {
932 .first = 0x87,
933 .last = 0x88,
934 },
935 },
936 },
937 [AB8500_REGU_CTRL2] = {
938 .num_ranges = 8,
939 .range = (struct ab8500_reg_range[]) {
940 {
941 .first = 0x00,
942 .last = 0x06,
943 },
944 {
945 .first = 0x08,
946 .last = 0x15,
947 },
948 {
949 .first = 0x17,
950 .last = 0x19,
951 },
952 {
953 .first = 0x1B,
954 .last = 0x1D,
955 },
956 {
957 .first = 0x1F,
958 .last = 0x2F,
959 },
960 {
961 .first = 0x31,
962 .last = 0x3A,
963 },
964 {
965 .first = 0x43,
966 .last = 0x44,
967 },
968 {
969 .first = 0x48,
970 .last = 0x49,
971 },
972 },
973 },
974 [AB8500_USB] = {
975 .num_ranges = 3,
976 .range = (struct ab8500_reg_range[]) {
977 {
978 .first = 0x80,
979 .last = 0x83,
980 },
981 {
982 .first = 0x87,
983 .last = 0x8A,
984 },
985 {
986 .first = 0x91,
987 .last = 0x94,
988 },
989 },
990 },
991 [AB8500_TVOUT] = {
992 .num_ranges = 0,
993 .range = NULL
994 },
995 [AB8500_DBI] = {
996 .num_ranges = 4,
997 .range = (struct ab8500_reg_range[]) {
998 {
999 .first = 0x00,
1000 .last = 0x07,
1001 },
1002 {
1003 .first = 0x10,
1004 .last = 0x11,
1005 },
1006 {
1007 .first = 0x20,
1008 .last = 0x21,
1009 },
1010 {
1011 .first = 0x30,
1012 .last = 0x43,
1013 },
1014 },
1015 },
1016 [AB8500_ECI_AV_ACC] = {
1017 .num_ranges = 2,
1018 .range = (struct ab8500_reg_range[]) {
1019 {
1020 .first = 0x00,
1021 .last = 0x03,
1022 },
1023 {
1024 .first = 0x80,
1025 .last = 0x82,
1026 },
1027 },
1028 },
1029 [AB8500_RESERVED] = {
1030 .num_ranges = 0,
1031 .range = NULL,
1032 },
1033 [AB8500_GPADC] = {
1034 .num_ranges = 4,
1035 .range = (struct ab8500_reg_range[]) {
1036 {
1037 .first = 0x00,
1038 .last = 0x01,
1039 },
1040 {
1041 .first = 0x04,
1042 .last = 0x06,
1043 },
1044 {
1045 .first = 0x09,
1046 .last = 0x0A,
1047 },
1048 {
1049 .first = 0x10,
1050 .last = 0x14,
1051 },
1052 },
1053 },
1054 [AB8500_CHARGER] = {
1055 .num_ranges = 10,
1056 .range = (struct ab8500_reg_range[]) {
1057 {
1058 .first = 0x00,
1059 .last = 0x00,
1060 },
1061 {
1062 .first = 0x02,
1063 .last = 0x05,
1064 },
1065 {
1066 .first = 0x40,
1067 .last = 0x44,
1068 },
1069 {
1070 .first = 0x50,
1071 .last = 0x57,
1072 },
1073 {
1074 .first = 0x60,
1075 .last = 0x60,
1076 },
1077 {
1078 .first = 0x70,
1079 .last = 0x70,
1080 },
1081 {
1082 .first = 0xA0,
1083 .last = 0xA9,
1084 },
1085 {
1086 .first = 0xAF,
1087 .last = 0xB2,
1088 },
1089 {
1090 .first = 0xC0,
1091 .last = 0xC6,
1092 },
1093 {
1094 .first = 0xF5,
1095 .last = 0xF5,
1096 },
1097 },
1098 },
1099 [AB8500_GAS_GAUGE] = {
1100 .num_ranges = 3,
1101 .range = (struct ab8500_reg_range[]) {
1102 {
1103 .first = 0x00,
1104 .last = 0x00,
1105 },
1106 {
1107 .first = 0x07,
1108 .last = 0x0A,
1109 },
1110 {
1111 .first = 0x10,
1112 .last = 0x14,
1113 },
1114 },
1115 },
1116 [AB8500_AUDIO] = {
1117 .num_ranges = 1,
1118 .range = (struct ab8500_reg_range[]) {
1119 {
1120 .first = 0x00,
1121 .last = 0x9f,
1122 },
1123 },
1124 },
1125 [AB8500_INTERRUPT] = {
1126 .num_ranges = 6,
1127 .range = (struct ab8500_reg_range[]) {
1128 {
1129 .first = 0x00,
1130 .last = 0x05,
1131 },
1132 {
1133 .first = 0x0B,
1134 .last = 0x0D,
1135 },
1136 {
1137 .first = 0x12,
1138 .last = 0x20,
1139 },
1140 /* Latch registers should not be read here */
1141 {
1142 .first = 0x40,
1143 .last = 0x45,
1144 },
1145 {
1146 .first = 0x4B,
1147 .last = 0x4D,
1148 },
1149 {
1150 .first = 0x52,
1151 .last = 0x60,
1152 },
1153 /* LatchHier registers should not be read here */
1154 },
1155 },
1156 [AB8500_RTC] = {
1157 .num_ranges = 3,
1158 .range = (struct ab8500_reg_range[]) {
1159 {
1160 .first = 0x00,
1161 .last = 0x07,
1162 },
1163 {
1164 .first = 0x0B,
1165 .last = 0x18,
1166 },
1167 {
1168 .first = 0x20,
1169 .last = 0x25,
1170 },
1171 },
1172 },
1173 [AB8500_MISC] = {
1174 .num_ranges = 9,
1175 .range = (struct ab8500_reg_range[]) {
1176 {
1177 .first = 0x00,
1178 .last = 0x06,
1179 },
1180 {
1181 .first = 0x10,
1182 .last = 0x16,
1183 },
1184 {
1185 .first = 0x20,
1186 .last = 0x26,
1187 },
1188 {
1189 .first = 0x30,
1190 .last = 0x36,
1191 },
1192 {
1193 .first = 0x40,
1194 .last = 0x49,
1195 },
1196 {
1197 .first = 0x50,
1198 .last = 0x50,
1199 },
1200 {
1201 .first = 0x60,
1202 .last = 0x6B,
1203 },
1204 {
1205 .first = 0x70,
1206 .last = 0x74,
1207 },
1208 {
1209 .first = 0x80,
1210 .last = 0x82,
1211 },
1212 },
1213 },
1214 [AB8500_DEVELOPMENT] = {
1215 .num_ranges = 3,
1216 .range = (struct ab8500_reg_range[]) {
1217 {
1218 .first = 0x00,
1219 .last = 0x01,
1220 },
1221 {
1222 .first = 0x06,
1223 .last = 0x06,
1224 },
1225 {
1226 .first = 0x10,
1227 .last = 0x21,
1228 },
1229 },
1230 },
1231 [AB8500_DEBUG] = {
1232 .num_ranges = 3,
1233 .range = (struct ab8500_reg_range[]) {
1234 {
1235 .first = 0x01,
1236 .last = 0x0C,
1237 },
1238 {
1239 .first = 0x0E,
1240 .last = 0x11,
1241 },
1242 {
1243 .first = 0x80,
1244 .last = 0x81,
1245 },
1246 },
1247 },
1248 [AB8500_PROD_TEST] = {
1249 .num_ranges = 0,
1250 .range = NULL,
1251 },
1252 [AB8500_STE_TEST] = {
1253 .num_ranges = 0,
1254 .range = NULL,
1255 },
1256 [AB8500_OTP_EMUL] = {
1257 .num_ranges = 1,
1258 .range = (struct ab8500_reg_range[]) {
1259 {
1260 .first = 0x00,
1261 .last = 0x3F,
1262 },
1263 },
1264 },
1265};
1266
1267
482static irqreturn_t ab8500_debug_handler(int irq, void *data) 1268static irqreturn_t ab8500_debug_handler(int irq, void *data)
483{ 1269{
484 char buf[16]; 1270 char buf[16];
@@ -520,19 +1306,16 @@ static int ab8500_registers_print(struct device *dev, u32 bank,
520 } 1306 }
521 1307
522 if (s) { 1308 if (s) {
523 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", 1309 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
524 bank, reg, value); 1310 bank, reg, value);
525 if (err < 0) { 1311 if (err < 0) {
526 dev_err(dev,
527 "seq_printf overflow bank=%d reg=%d\n",
528 bank, reg);
529 /* Error is not returned here since 1312 /* Error is not returned here since
530 * the output is wanted in any case */ 1313 * the output is wanted in any case */
531 return 0; 1314 return 0;
532 } 1315 }
533 } else { 1316 } else {
534 printk(KERN_INFO" [%u/0x%02X]: 0x%02X\n", bank, 1317 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
535 reg, value); 1318 bank, reg, value);
536 } 1319 }
537 } 1320 }
538 } 1321 }
@@ -546,7 +1329,7 @@ static int ab8500_print_bank_registers(struct seq_file *s, void *p)
546 1329
547 seq_printf(s, AB8500_NAME_STRING " register values:\n"); 1330 seq_printf(s, AB8500_NAME_STRING " register values:\n");
548 1331
549 seq_printf(s, " bank %u:\n", bank); 1332 seq_printf(s, " bank 0x%02X:\n", bank);
550 1333
551 ab8500_registers_print(dev, bank, s); 1334 ab8500_registers_print(dev, bank, s);
552 return 0; 1335 return 0;
@@ -573,10 +1356,8 @@ static int ab8500_print_all_banks(struct seq_file *s, void *p)
573 1356
574 seq_printf(s, AB8500_NAME_STRING " register values:\n"); 1357 seq_printf(s, AB8500_NAME_STRING " register values:\n");
575 1358
576 for (i = 1; i < AB8500_NUM_BANKS; i++) { 1359 for (i = 0; i < AB8500_NUM_BANKS; i++) {
577 err = seq_printf(s, " bank %u:\n", i); 1360 err = seq_printf(s, " bank 0x%02X:\n", i);
578 if (err < 0)
579 dev_err(dev, "seq_printf overflow, bank=%d\n", i);
580 1361
581 ab8500_registers_print(dev, i, s); 1362 ab8500_registers_print(dev, i, s);
582 } 1363 }
@@ -591,11 +1372,68 @@ void ab8500_dump_all_banks(struct device *dev)
591 printk(KERN_INFO"ab8500 register values:\n"); 1372 printk(KERN_INFO"ab8500 register values:\n");
592 1373
593 for (i = 1; i < AB8500_NUM_BANKS; i++) { 1374 for (i = 1; i < AB8500_NUM_BANKS; i++) {
594 printk(KERN_INFO" bank %u:\n", i); 1375 printk(KERN_INFO" bank 0x%02X:\n", i);
595 ab8500_registers_print(dev, i, NULL); 1376 ab8500_registers_print(dev, i, NULL);
596 } 1377 }
597} 1378}
598 1379
1380/* Space for 500 registers. */
1381#define DUMP_MAX_REGS 700
1382struct ab8500_register_dump
1383{
1384 u8 bank;
1385 u8 reg;
1386 u8 value;
1387} ab8500_complete_register_dump[DUMP_MAX_REGS];
1388
1389extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
1390
1391/* This shall only be called upon kernel panic! */
1392void ab8500_dump_all_banks_to_mem(void)
1393{
1394 int i, r = 0;
1395 u8 bank;
1396 int err = 0;
1397
1398 pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
1399 "for crash analyze.\n");
1400
1401 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
1402 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1403 u8 reg;
1404
1405 for (reg = debug_ranges[bank].range[i].first;
1406 reg <= debug_ranges[bank].range[i].last;
1407 reg++) {
1408 u8 value;
1409
1410 err = prcmu_abb_read(bank, reg, &value, 1);
1411
1412 if (err < 0)
1413 goto out;
1414
1415 ab8500_complete_register_dump[r].bank = bank;
1416 ab8500_complete_register_dump[r].reg = reg;
1417 ab8500_complete_register_dump[r].value = value;
1418
1419 r++;
1420
1421 if (r >= DUMP_MAX_REGS) {
1422 pr_err("%s: too many register to dump!\n",
1423 __func__);
1424 err = -EINVAL;
1425 goto out;
1426 }
1427 }
1428 }
1429 }
1430out:
1431 if (err >= 0)
1432 pr_info("Saved all ABB registers.\n");
1433 else
1434 pr_info("Failed to save all ABB registers.\n");
1435}
1436
599static int ab8500_all_banks_open(struct inode *inode, struct file *file) 1437static int ab8500_all_banks_open(struct inode *inode, struct file *file)
600{ 1438{
601 struct seq_file *s; 1439 struct seq_file *s;
@@ -625,7 +1463,7 @@ static const struct file_operations ab8500_all_banks_fops = {
625 1463
626static int ab8500_bank_print(struct seq_file *s, void *p) 1464static int ab8500_bank_print(struct seq_file *s, void *p)
627{ 1465{
628 return seq_printf(s, "%d\n", debug_bank); 1466 return seq_printf(s, "0x%02X\n", debug_bank);
629} 1467}
630 1468
631static int ab8500_bank_open(struct inode *inode, struct file *file) 1469static int ab8500_bank_open(struct inode *inode, struct file *file)
@@ -641,7 +1479,6 @@ static ssize_t ab8500_bank_write(struct file *file,
641 unsigned long user_bank; 1479 unsigned long user_bank;
642 int err; 1480 int err;
643 1481
644 /* Get userspace string and assure termination */
645 err = kstrtoul_from_user(user_buf, count, 0, &user_bank); 1482 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
646 if (err) 1483 if (err)
647 return err; 1484 return err;
@@ -667,14 +1504,13 @@ static int ab8500_address_open(struct inode *inode, struct file *file)
667} 1504}
668 1505
669static ssize_t ab8500_address_write(struct file *file, 1506static ssize_t ab8500_address_write(struct file *file,
670 const char __user *user_buf, 1507 const char __user *user_buf,
671 size_t count, loff_t *ppos) 1508 size_t count, loff_t *ppos)
672{ 1509{
673 struct device *dev = ((struct seq_file *)(file->private_data))->private; 1510 struct device *dev = ((struct seq_file *)(file->private_data))->private;
674 unsigned long user_address; 1511 unsigned long user_address;
675 int err; 1512 int err;
676 1513
677 /* Get userspace string and assure termination */
678 err = kstrtoul_from_user(user_buf, count, 0, &user_address); 1514 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
679 if (err) 1515 if (err)
680 return err; 1516 return err;
@@ -684,6 +1520,7 @@ static ssize_t ab8500_address_write(struct file *file,
684 return -EINVAL; 1520 return -EINVAL;
685 } 1521 }
686 debug_address = user_address; 1522 debug_address = user_address;
1523
687 return count; 1524 return count;
688} 1525}
689 1526
@@ -711,14 +1548,13 @@ static int ab8500_val_open(struct inode *inode, struct file *file)
711} 1548}
712 1549
713static ssize_t ab8500_val_write(struct file *file, 1550static ssize_t ab8500_val_write(struct file *file,
714 const char __user *user_buf, 1551 const char __user *user_buf,
715 size_t count, loff_t *ppos) 1552 size_t count, loff_t *ppos)
716{ 1553{
717 struct device *dev = ((struct seq_file *)(file->private_data))->private; 1554 struct device *dev = ((struct seq_file *)(file->private_data))->private;
718 unsigned long user_val; 1555 unsigned long user_val;
719 int err; 1556 int err;
720 1557
721 /* Get userspace string and assure termination */
722 err = kstrtoul_from_user(user_buf, count, 0, &user_val); 1558 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
723 if (err) 1559 if (err)
724 return err; 1560 return err;
@@ -741,22 +1577,46 @@ static ssize_t ab8500_val_write(struct file *file,
741 * Interrupt status 1577 * Interrupt status
742 */ 1578 */
743static u32 num_interrupts[AB8500_MAX_NR_IRQS]; 1579static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1580static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
744static int num_interrupt_lines; 1581static int num_interrupt_lines;
745 1582
1583bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1584{
1585 return false;
1586}
1587
746void ab8500_debug_register_interrupt(int line) 1588void ab8500_debug_register_interrupt(int line)
747{ 1589{
748 if (line < num_interrupt_lines) 1590 if (line < num_interrupt_lines) {
749 num_interrupts[line]++; 1591 num_interrupts[line]++;
1592 if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
1593 num_wake_interrupts[line]++;
1594 }
750} 1595}
751 1596
752static int ab8500_interrupts_print(struct seq_file *s, void *p) 1597static int ab8500_interrupts_print(struct seq_file *s, void *p)
753{ 1598{
754 int line; 1599 int line;
755 1600
756 seq_printf(s, "irq: number of\n"); 1601 seq_printf(s, "name: number: number of: wake:\n");
757 1602
758 for (line = 0; line < num_interrupt_lines; line++) 1603 for (line = 0; line < num_interrupt_lines; line++) {
759 seq_printf(s, "%3i: %6i\n", line, num_interrupts[line]); 1604 struct irq_desc *desc = irq_to_desc(line + irq_first);
1605 struct irqaction *action = desc->action;
1606
1607 seq_printf(s, "%3i: %6i %4i", line,
1608 num_interrupts[line],
1609 num_wake_interrupts[line]);
1610
1611 if (desc && desc->name)
1612 seq_printf(s, "-%-8s", desc->name);
1613 if (action) {
1614 seq_printf(s, " %s", action->name);
1615 while ((action = action->next) != NULL)
1616 seq_printf(s, ", %s", action->name);
1617 }
1618 seq_putc(s, '\n');
1619 }
760 1620
761 return 0; 1621 return 0;
762} 1622}
@@ -801,6 +1661,79 @@ static int ab8500_hwreg_open(struct inode *inode, struct file *file)
801 return single_open(file, ab8500_hwreg_print, inode->i_private); 1661 return single_open(file, ab8500_hwreg_print, inode->i_private);
802} 1662}
803 1663
1664#define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1665#define AB8500_SUPPLY_CONTROL_REG 0x00
1666#define AB8500_FIRST_SIM_REG 0x80
1667#define AB8500_LAST_SIM_REG 0x8B
1668#define AB8505_LAST_SIM_REG 0x8C
1669
1670static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1671{
1672 struct device *dev = s->private;
1673 struct ab8500 *ab8500;
1674 int err;
1675 u8 value;
1676 u8 orig_value;
1677 u32 bank = AB8500_REGU_CTRL2;
1678 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1679 u32 reg;
1680
1681 ab8500 = dev_get_drvdata(dev->parent);
1682 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1683 "and should only be done with care\n");
1684
1685 err = abx500_get_register_interruptible(dev,
1686 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1687 if (err < 0) {
1688 dev_err(dev, "ab->read fail %d\n", err);
1689 return err;
1690 }
1691 /* Config 1 will allow APE side to read SIM registers */
1692 err = abx500_set_register_interruptible(dev,
1693 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1694 AB8500_SUPPLY_CONTROL_CONFIG_1);
1695 if (err < 0) {
1696 dev_err(dev, "ab->write fail %d\n", err);
1697 return err;
1698 }
1699
1700 seq_printf(s, " bank 0x%02X:\n", bank);
1701
1702 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1703 last_sim_reg = AB8505_LAST_SIM_REG;
1704
1705 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1706 err = abx500_get_register_interruptible(dev,
1707 bank, reg, &value);
1708 if (err < 0) {
1709 dev_err(dev, "ab->read fail %d\n", err);
1710 return err;
1711 }
1712 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1713 bank, reg, value);
1714 }
1715 err = abx500_set_register_interruptible(dev,
1716 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1717 if (err < 0) {
1718 dev_err(dev, "ab->write fail %d\n", err);
1719 return err;
1720 }
1721 return 0;
1722}
1723
1724static int ab8500_modem_open(struct inode *inode, struct file *file)
1725{
1726 return single_open(file, ab8500_print_modem_registers, inode->i_private);
1727}
1728
1729static const struct file_operations ab8500_modem_fops = {
1730 .open = ab8500_modem_open,
1731 .read = seq_read,
1732 .llseek = seq_lseek,
1733 .release = single_release,
1734 .owner = THIS_MODULE,
1735};
1736
804static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p) 1737static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
805{ 1738{
806 int bat_ctrl_raw; 1739 int bat_ctrl_raw;
@@ -808,12 +1741,13 @@ static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
808 struct ab8500_gpadc *gpadc; 1741 struct ab8500_gpadc *gpadc;
809 1742
810 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1743 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
811 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL); 1744 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1745 avg_sample, trig_edge, trig_timer, conv_type);
812 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, 1746 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
813 BAT_CTRL, bat_ctrl_raw); 1747 BAT_CTRL, bat_ctrl_raw);
814 1748
815 return seq_printf(s, "%d,0x%X\n", 1749 return seq_printf(s, "%d,0x%X\n",
816 bat_ctrl_convert, bat_ctrl_raw); 1750 bat_ctrl_convert, bat_ctrl_raw);
817} 1751}
818 1752
819static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file) 1753static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
@@ -836,16 +1770,17 @@ static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
836 struct ab8500_gpadc *gpadc; 1770 struct ab8500_gpadc *gpadc;
837 1771
838 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1772 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
839 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL); 1773 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1774 avg_sample, trig_edge, trig_timer, conv_type);
840 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, 1775 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
841 btemp_ball_raw); 1776 btemp_ball_raw);
842 1777
843 return seq_printf(s, 1778 return seq_printf(s,
844 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw); 1779 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
845} 1780}
846 1781
847static int ab8500_gpadc_btemp_ball_open(struct inode *inode, 1782static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
848 struct file *file) 1783 struct file *file)
849{ 1784{
850 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private); 1785 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
851} 1786}
@@ -865,19 +1800,20 @@ static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
865 struct ab8500_gpadc *gpadc; 1800 struct ab8500_gpadc *gpadc;
866 1801
867 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1802 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
868 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V); 1803 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1804 avg_sample, trig_edge, trig_timer, conv_type);
869 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, 1805 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
870 MAIN_CHARGER_V, main_charger_v_raw); 1806 MAIN_CHARGER_V, main_charger_v_raw);
871 1807
872 return seq_printf(s, "%d,0x%X\n", 1808 return seq_printf(s, "%d,0x%X\n",
873 main_charger_v_convert, main_charger_v_raw); 1809 main_charger_v_convert, main_charger_v_raw);
874} 1810}
875 1811
876static int ab8500_gpadc_main_charger_v_open(struct inode *inode, 1812static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
877 struct file *file) 1813 struct file *file)
878{ 1814{
879 return single_open(file, ab8500_gpadc_main_charger_v_print, 1815 return single_open(file, ab8500_gpadc_main_charger_v_print,
880 inode->i_private); 1816 inode->i_private);
881} 1817}
882 1818
883static const struct file_operations ab8500_gpadc_main_charger_v_fops = { 1819static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
@@ -895,19 +1831,20 @@ static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
895 struct ab8500_gpadc *gpadc; 1831 struct ab8500_gpadc *gpadc;
896 1832
897 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1833 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
898 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1); 1834 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1835 avg_sample, trig_edge, trig_timer, conv_type);
899 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1, 1836 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
900 acc_detect1_raw); 1837 acc_detect1_raw);
901 1838
902 return seq_printf(s, "%d,0x%X\n", 1839 return seq_printf(s, "%d,0x%X\n",
903 acc_detect1_convert, acc_detect1_raw); 1840 acc_detect1_convert, acc_detect1_raw);
904} 1841}
905 1842
906static int ab8500_gpadc_acc_detect1_open(struct inode *inode, 1843static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
907 struct file *file) 1844 struct file *file)
908{ 1845{
909 return single_open(file, ab8500_gpadc_acc_detect1_print, 1846 return single_open(file, ab8500_gpadc_acc_detect1_print,
910 inode->i_private); 1847 inode->i_private);
911} 1848}
912 1849
913static const struct file_operations ab8500_gpadc_acc_detect1_fops = { 1850static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
@@ -925,19 +1862,20 @@ static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
925 struct ab8500_gpadc *gpadc; 1862 struct ab8500_gpadc *gpadc;
926 1863
927 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1864 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
928 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2); 1865 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1866 avg_sample, trig_edge, trig_timer, conv_type);
929 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc, 1867 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
930 ACC_DETECT2, acc_detect2_raw); 1868 ACC_DETECT2, acc_detect2_raw);
931 1869
932 return seq_printf(s, "%d,0x%X\n", 1870 return seq_printf(s, "%d,0x%X\n",
933 acc_detect2_convert, acc_detect2_raw); 1871 acc_detect2_convert, acc_detect2_raw);
934} 1872}
935 1873
936static int ab8500_gpadc_acc_detect2_open(struct inode *inode, 1874static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
937 struct file *file) 1875 struct file *file)
938{ 1876{
939 return single_open(file, ab8500_gpadc_acc_detect2_print, 1877 return single_open(file, ab8500_gpadc_acc_detect2_print,
940 inode->i_private); 1878 inode->i_private);
941} 1879}
942 1880
943static const struct file_operations ab8500_gpadc_acc_detect2_fops = { 1881static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
@@ -955,12 +1893,13 @@ static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
955 struct ab8500_gpadc *gpadc; 1893 struct ab8500_gpadc *gpadc;
956 1894
957 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1895 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
958 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1); 1896 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1897 avg_sample, trig_edge, trig_timer, conv_type);
959 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1, 1898 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
960 aux1_raw); 1899 aux1_raw);
961 1900
962 return seq_printf(s, "%d,0x%X\n", 1901 return seq_printf(s, "%d,0x%X\n",
963 aux1_convert, aux1_raw); 1902 aux1_convert, aux1_raw);
964} 1903}
965 1904
966static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file) 1905static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
@@ -983,9 +1922,10 @@ static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
983 struct ab8500_gpadc *gpadc; 1922 struct ab8500_gpadc *gpadc;
984 1923
985 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1924 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
986 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2); 1925 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1926 avg_sample, trig_edge, trig_timer, conv_type);
987 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2, 1927 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
988 aux2_raw); 1928 aux2_raw);
989 1929
990 return seq_printf(s, "%d,0x%X\n", 1930 return seq_printf(s, "%d,0x%X\n",
991 aux2_convert, aux2_raw); 1931 aux2_convert, aux2_raw);
@@ -1011,16 +1951,17 @@ static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1011 struct ab8500_gpadc *gpadc; 1951 struct ab8500_gpadc *gpadc;
1012 1952
1013 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1953 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1014 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V); 1954 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1955 avg_sample, trig_edge, trig_timer, conv_type);
1015 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, 1956 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1016 main_bat_v_raw); 1957 main_bat_v_raw);
1017 1958
1018 return seq_printf(s, "%d,0x%X\n", 1959 return seq_printf(s, "%d,0x%X\n",
1019 main_bat_v_convert, main_bat_v_raw); 1960 main_bat_v_convert, main_bat_v_raw);
1020} 1961}
1021 1962
1022static int ab8500_gpadc_main_bat_v_open(struct inode *inode, 1963static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1023 struct file *file) 1964 struct file *file)
1024{ 1965{
1025 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private); 1966 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1026} 1967}
@@ -1040,12 +1981,13 @@ static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1040 struct ab8500_gpadc *gpadc; 1981 struct ab8500_gpadc *gpadc;
1041 1982
1042 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1983 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1043 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V); 1984 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1985 avg_sample, trig_edge, trig_timer, conv_type);
1044 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V, 1986 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1045 vbus_v_raw); 1987 vbus_v_raw);
1046 1988
1047 return seq_printf(s, "%d,0x%X\n", 1989 return seq_printf(s, "%d,0x%X\n",
1048 vbus_v_convert, vbus_v_raw); 1990 vbus_v_convert, vbus_v_raw);
1049} 1991}
1050 1992
1051static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file) 1993static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
@@ -1068,19 +2010,20 @@ static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1068 struct ab8500_gpadc *gpadc; 2010 struct ab8500_gpadc *gpadc;
1069 2011
1070 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2012 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1071 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C); 2013 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2014 avg_sample, trig_edge, trig_timer, conv_type);
1072 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, 2015 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1073 MAIN_CHARGER_C, main_charger_c_raw); 2016 MAIN_CHARGER_C, main_charger_c_raw);
1074 2017
1075 return seq_printf(s, "%d,0x%X\n", 2018 return seq_printf(s, "%d,0x%X\n",
1076 main_charger_c_convert, main_charger_c_raw); 2019 main_charger_c_convert, main_charger_c_raw);
1077} 2020}
1078 2021
1079static int ab8500_gpadc_main_charger_c_open(struct inode *inode, 2022static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1080 struct file *file) 2023 struct file *file)
1081{ 2024{
1082 return single_open(file, ab8500_gpadc_main_charger_c_print, 2025 return single_open(file, ab8500_gpadc_main_charger_c_print,
1083 inode->i_private); 2026 inode->i_private);
1084} 2027}
1085 2028
1086static const struct file_operations ab8500_gpadc_main_charger_c_fops = { 2029static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
@@ -1098,19 +2041,20 @@ static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1098 struct ab8500_gpadc *gpadc; 2041 struct ab8500_gpadc *gpadc;
1099 2042
1100 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2043 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1101 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C); 2044 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2045 avg_sample, trig_edge, trig_timer, conv_type);
1102 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, 2046 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1103 USB_CHARGER_C, usb_charger_c_raw); 2047 USB_CHARGER_C, usb_charger_c_raw);
1104 2048
1105 return seq_printf(s, "%d,0x%X\n", 2049 return seq_printf(s, "%d,0x%X\n",
1106 usb_charger_c_convert, usb_charger_c_raw); 2050 usb_charger_c_convert, usb_charger_c_raw);
1107} 2051}
1108 2052
1109static int ab8500_gpadc_usb_charger_c_open(struct inode *inode, 2053static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
1110 struct file *file) 2054 struct file *file)
1111{ 2055{
1112 return single_open(file, ab8500_gpadc_usb_charger_c_print, 2056 return single_open(file, ab8500_gpadc_usb_charger_c_print,
1113 inode->i_private); 2057 inode->i_private);
1114} 2058}
1115 2059
1116static const struct file_operations ab8500_gpadc_usb_charger_c_fops = { 2060static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
@@ -1128,12 +2072,13 @@ static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
1128 struct ab8500_gpadc *gpadc; 2072 struct ab8500_gpadc *gpadc;
1129 2073
1130 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2074 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1131 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V); 2075 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2076 avg_sample, trig_edge, trig_timer, conv_type);
1132 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, 2077 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1133 BK_BAT_V, bk_bat_v_raw); 2078 BK_BAT_V, bk_bat_v_raw);
1134 2079
1135 return seq_printf(s, "%d,0x%X\n", 2080 return seq_printf(s, "%d,0x%X\n",
1136 bk_bat_v_convert, bk_bat_v_raw); 2081 bk_bat_v_convert, bk_bat_v_raw);
1137} 2082}
1138 2083
1139static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file) 2084static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
@@ -1156,12 +2101,13 @@ static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
1156 struct ab8500_gpadc *gpadc; 2101 struct ab8500_gpadc *gpadc;
1157 2102
1158 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2103 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1159 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP); 2104 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2105 avg_sample, trig_edge, trig_timer, conv_type);
1160 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP, 2106 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
1161 die_temp_raw); 2107 die_temp_raw);
1162 2108
1163 return seq_printf(s, "%d,0x%X\n", 2109 return seq_printf(s, "%d,0x%X\n",
1164 die_temp_convert, die_temp_raw); 2110 die_temp_convert, die_temp_raw);
1165} 2111}
1166 2112
1167static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file) 2113static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
@@ -1177,6 +2123,453 @@ static const struct file_operations ab8500_gpadc_die_temp_fops = {
1177 .owner = THIS_MODULE, 2123 .owner = THIS_MODULE,
1178}; 2124};
1179 2125
2126static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2127{
2128 int usb_id_raw;
2129 int usb_id_convert;
2130 struct ab8500_gpadc *gpadc;
2131
2132 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2133 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2134 avg_sample, trig_edge, trig_timer, conv_type);
2135 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2136 usb_id_raw);
2137
2138 return seq_printf(s, "%d,0x%X\n",
2139 usb_id_convert, usb_id_raw);
2140}
2141
2142static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2143{
2144 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2145}
2146
2147static const struct file_operations ab8500_gpadc_usb_id_fops = {
2148 .open = ab8500_gpadc_usb_id_open,
2149 .read = seq_read,
2150 .llseek = seq_lseek,
2151 .release = single_release,
2152 .owner = THIS_MODULE,
2153};
2154
2155static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2156{
2157 int xtal_temp_raw;
2158 int xtal_temp_convert;
2159 struct ab8500_gpadc *gpadc;
2160
2161 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2162 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2163 avg_sample, trig_edge, trig_timer, conv_type);
2164 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2165 xtal_temp_raw);
2166
2167 return seq_printf(s, "%d,0x%X\n",
2168 xtal_temp_convert, xtal_temp_raw);
2169}
2170
2171static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2172{
2173 return single_open(file, ab8540_gpadc_xtal_temp_print,
2174 inode->i_private);
2175}
2176
2177static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2178 .open = ab8540_gpadc_xtal_temp_open,
2179 .read = seq_read,
2180 .llseek = seq_lseek,
2181 .release = single_release,
2182 .owner = THIS_MODULE,
2183};
2184
2185static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2186{
2187 int vbat_true_meas_raw;
2188 int vbat_true_meas_convert;
2189 struct ab8500_gpadc *gpadc;
2190
2191 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2192 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2193 avg_sample, trig_edge, trig_timer, conv_type);
2194 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2195 vbat_true_meas_raw);
2196
2197 return seq_printf(s, "%d,0x%X\n",
2198 vbat_true_meas_convert, vbat_true_meas_raw);
2199}
2200
2201static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2202 struct file *file)
2203{
2204 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2205 inode->i_private);
2206}
2207
2208static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2209 .open = ab8540_gpadc_vbat_true_meas_open,
2210 .read = seq_read,
2211 .llseek = seq_lseek,
2212 .release = single_release,
2213 .owner = THIS_MODULE,
2214};
2215
2216static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2217{
2218 int bat_ctrl_raw;
2219 int bat_ctrl_convert;
2220 int ibat_raw;
2221 int ibat_convert;
2222 struct ab8500_gpadc *gpadc;
2223
2224 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2225 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2226 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2227
2228 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2229 bat_ctrl_raw);
2230 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2231 ibat_raw);
2232
2233 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2234 bat_ctrl_convert, bat_ctrl_raw,
2235 ibat_convert, ibat_raw);
2236}
2237
2238static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2239 struct file *file)
2240{
2241 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2242 inode->i_private);
2243}
2244
2245static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2246 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2247 .read = seq_read,
2248 .llseek = seq_lseek,
2249 .release = single_release,
2250 .owner = THIS_MODULE,
2251};
2252
2253static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2254{
2255 int vbat_meas_raw;
2256 int vbat_meas_convert;
2257 int ibat_raw;
2258 int ibat_convert;
2259 struct ab8500_gpadc *gpadc;
2260
2261 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2262 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2263 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2264 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2265 vbat_meas_raw);
2266 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2267 ibat_raw);
2268
2269 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2270 vbat_meas_convert, vbat_meas_raw,
2271 ibat_convert, ibat_raw);
2272}
2273
2274static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2275 struct file *file)
2276{
2277 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2278 inode->i_private);
2279}
2280
2281static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2282 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2283 .read = seq_read,
2284 .llseek = seq_lseek,
2285 .release = single_release,
2286 .owner = THIS_MODULE,
2287};
2288
2289static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p)
2290{
2291 int vbat_true_meas_raw;
2292 int vbat_true_meas_convert;
2293 int ibat_raw;
2294 int ibat_convert;
2295 struct ab8500_gpadc *gpadc;
2296
2297 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2298 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2299 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2300 trig_timer, conv_type, &ibat_raw);
2301 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2302 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2303 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2304 ibat_raw);
2305
2306 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2307 vbat_true_meas_convert, vbat_true_meas_raw,
2308 ibat_convert, ibat_raw);
2309}
2310
2311static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2312 struct file *file)
2313{
2314 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2315 inode->i_private);
2316}
2317
2318static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2319 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2320 .read = seq_read,
2321 .llseek = seq_lseek,
2322 .release = single_release,
2323 .owner = THIS_MODULE,
2324};
2325
2326static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2327{
2328 int bat_temp_raw;
2329 int bat_temp_convert;
2330 int ibat_raw;
2331 int ibat_convert;
2332 struct ab8500_gpadc *gpadc;
2333
2334 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2335 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2336 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2337 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2338 bat_temp_raw);
2339 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2340 ibat_raw);
2341
2342 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2343 bat_temp_convert, bat_temp_raw,
2344 ibat_convert, ibat_raw);
2345}
2346
2347static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2348 struct file *file)
2349{
2350 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2351 inode->i_private);
2352}
2353
2354static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2355 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2356 .read = seq_read,
2357 .llseek = seq_lseek,
2358 .release = single_release,
2359 .owner = THIS_MODULE,
2360};
2361
2362static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2363{
2364 struct ab8500_gpadc *gpadc;
2365 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2366 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2367
2368 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2369 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2370 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2371 return seq_printf(s, "VMAIN_L:0x%X\n"
2372 "VMAIN_H:0x%X\n"
2373 "BTEMP_L:0x%X\n"
2374 "BTEMP_H:0x%X\n"
2375 "VBAT_L:0x%X\n"
2376 "VBAT_H:0x%X\n"
2377 "IBAT_L:0x%X\n"
2378 "IBAT_H:0x%X\n",
2379 vmain_l, vmain_h, btemp_l, btemp_h, vbat_l, vbat_h, ibat_l, ibat_h);
2380}
2381
2382static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2383{
2384 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2385}
2386
2387static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2388 .open = ab8540_gpadc_otp_cal_open,
2389 .read = seq_read,
2390 .llseek = seq_lseek,
2391 .release = single_release,
2392 .owner = THIS_MODULE,
2393};
2394
2395static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2396{
2397 return seq_printf(s, "%d\n", avg_sample);
2398}
2399
2400static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2401{
2402 return single_open(file, ab8500_gpadc_avg_sample_print,
2403 inode->i_private);
2404}
2405
2406static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2407 const char __user *user_buf,
2408 size_t count, loff_t *ppos)
2409{
2410 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2411 unsigned long user_avg_sample;
2412 int err;
2413
2414 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2415 if (err)
2416 return err;
2417
2418 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2419 || (user_avg_sample == SAMPLE_8)
2420 || (user_avg_sample == SAMPLE_16)) {
2421 avg_sample = (u8) user_avg_sample;
2422 } else {
2423 dev_err(dev, "debugfs error input: "
2424 "should be egal to 1, 4, 8 or 16\n");
2425 return -EINVAL;
2426 }
2427
2428 return count;
2429}
2430
2431static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2432 .open = ab8500_gpadc_avg_sample_open,
2433 .read = seq_read,
2434 .write = ab8500_gpadc_avg_sample_write,
2435 .llseek = seq_lseek,
2436 .release = single_release,
2437 .owner = THIS_MODULE,
2438};
2439
2440static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2441{
2442 return seq_printf(s, "%d\n", trig_edge);
2443}
2444
2445static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2446{
2447 return single_open(file, ab8500_gpadc_trig_edge_print,
2448 inode->i_private);
2449}
2450
2451static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2452 const char __user *user_buf,
2453 size_t count, loff_t *ppos)
2454{
2455 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2456 unsigned long user_trig_edge;
2457 int err;
2458
2459 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2460 if (err)
2461 return err;
2462
2463 if ((user_trig_edge == RISING_EDGE)
2464 || (user_trig_edge == FALLING_EDGE)) {
2465 trig_edge = (u8) user_trig_edge;
2466 } else {
2467 dev_err(dev, "Wrong input:\n"
2468 "Enter 0. Rising edge\n"
2469 "Enter 1. Falling edge\n");
2470 return -EINVAL;
2471 }
2472
2473 return count;
2474}
2475
2476static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2477 .open = ab8500_gpadc_trig_edge_open,
2478 .read = seq_read,
2479 .write = ab8500_gpadc_trig_edge_write,
2480 .llseek = seq_lseek,
2481 .release = single_release,
2482 .owner = THIS_MODULE,
2483};
2484
2485static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2486{
2487 return seq_printf(s, "%d\n", trig_timer);
2488}
2489
2490static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2491{
2492 return single_open(file, ab8500_gpadc_trig_timer_print,
2493 inode->i_private);
2494}
2495
2496static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2497 const char __user *user_buf,
2498 size_t count, loff_t *ppos)
2499{
2500 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2501 unsigned long user_trig_timer;
2502 int err;
2503
2504 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2505 if (err)
2506 return err;
2507
2508 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2509 trig_timer = (u8) user_trig_timer;
2510 } else {
2511 dev_err(dev, "debugfs error input: "
2512 "should be beetween 0 to 255\n");
2513 return -EINVAL;
2514 }
2515
2516 return count;
2517}
2518
2519static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2520 .open = ab8500_gpadc_trig_timer_open,
2521 .read = seq_read,
2522 .write = ab8500_gpadc_trig_timer_write,
2523 .llseek = seq_lseek,
2524 .release = single_release,
2525 .owner = THIS_MODULE,
2526};
2527
2528static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2529{
2530 return seq_printf(s, "%d\n", conv_type);
2531}
2532
2533static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2534{
2535 return single_open(file, ab8500_gpadc_conv_type_print,
2536 inode->i_private);
2537}
2538
2539static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2540 const char __user *user_buf,
2541 size_t count, loff_t *ppos)
2542{
2543 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2544 unsigned long user_conv_type;
2545 int err;
2546
2547 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2548 if (err)
2549 return err;
2550
2551 if ((user_conv_type == ADC_SW)
2552 || (user_conv_type == ADC_HW)) {
2553 conv_type = (u8) user_conv_type;
2554 } else {
2555 dev_err(dev, "Wrong input:\n"
2556 "Enter 0. ADC SW conversion\n"
2557 "Enter 1. ADC HW conversion\n");
2558 return -EINVAL;
2559 }
2560
2561 return count;
2562}
2563
2564static const struct file_operations ab8500_gpadc_conv_type_fops = {
2565 .open = ab8500_gpadc_conv_type_open,
2566 .read = seq_read,
2567 .write = ab8500_gpadc_conv_type_write,
2568 .llseek = seq_lseek,
2569 .release = single_release,
2570 .owner = THIS_MODULE,
2571};
2572
1180/* 2573/*
1181 * return length of an ASCII numerical value, 0 is string is not a 2574 * return length of an ASCII numerical value, 0 is string is not a
1182 * numerical value. 2575 * numerical value.
@@ -1352,7 +2745,7 @@ static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1352 struct file *file) 2745 struct file *file)
1353{ 2746{
1354 return single_open(file, ab8500_subscribe_unsubscribe_print, 2747 return single_open(file, ab8500_subscribe_unsubscribe_print,
1355 inode->i_private); 2748 inode->i_private);
1356} 2749}
1357 2750
1358/* 2751/*
@@ -1382,21 +2775,14 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1382 size_t count, loff_t *ppos) 2775 size_t count, loff_t *ppos)
1383{ 2776{
1384 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2777 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1385 char buf[32];
1386 int buf_size;
1387 unsigned long user_val; 2778 unsigned long user_val;
1388 int err; 2779 int err;
1389 unsigned int irq_index; 2780 unsigned int irq_index;
1390 2781
1391 /* Get userspace string and assure termination */ 2782 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1392 buf_size = min(count, (sizeof(buf)-1));
1393 if (copy_from_user(buf, user_buf, buf_size))
1394 return -EFAULT;
1395 buf[buf_size] = 0;
1396
1397 err = strict_strtoul(buf, 0, &user_val);
1398 if (err) 2783 if (err)
1399 return -EINVAL; 2784 return err;
2785
1400 if (user_val < irq_first) { 2786 if (user_val < irq_first) {
1401 dev_err(dev, "debugfs error input < %d\n", irq_first); 2787 dev_err(dev, "debugfs error input < %d\n", irq_first);
1402 return -EINVAL; 2788 return -EINVAL;
@@ -1416,7 +2802,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1416 */ 2802 */
1417 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), 2803 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1418 GFP_KERNEL); 2804 GFP_KERNEL);
1419 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); 2805 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
1420 sprintf(event_name[irq_index], "%lu", user_val); 2806 sprintf(event_name[irq_index], "%lu", user_val);
1421 dev_attr[irq_index]->show = show_irq; 2807 dev_attr[irq_index]->show = show_irq;
1422 dev_attr[irq_index]->store = NULL; 2808 dev_attr[irq_index]->store = NULL;
@@ -1438,7 +2824,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1438 return err; 2824 return err;
1439 } 2825 }
1440 2826
1441 return buf_size; 2827 return count;
1442} 2828}
1443 2829
1444static ssize_t ab8500_unsubscribe_write(struct file *file, 2830static ssize_t ab8500_unsubscribe_write(struct file *file,
@@ -1446,21 +2832,14 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
1446 size_t count, loff_t *ppos) 2832 size_t count, loff_t *ppos)
1447{ 2833{
1448 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2834 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1449 char buf[32];
1450 int buf_size;
1451 unsigned long user_val; 2835 unsigned long user_val;
1452 int err; 2836 int err;
1453 unsigned int irq_index; 2837 unsigned int irq_index;
1454 2838
1455 /* Get userspace string and assure termination */ 2839 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1456 buf_size = min(count, (sizeof(buf)-1));
1457 if (copy_from_user(buf, user_buf, buf_size))
1458 return -EFAULT;
1459 buf[buf_size] = 0;
1460
1461 err = strict_strtoul(buf, 0, &user_val);
1462 if (err) 2840 if (err)
1463 return -EINVAL; 2841 return err;
2842
1464 if (user_val < irq_first) { 2843 if (user_val < irq_first) {
1465 dev_err(dev, "debugfs error input < %d\n", irq_first); 2844 dev_err(dev, "debugfs error input < %d\n", irq_first);
1466 return -EINVAL; 2845 return -EINVAL;
@@ -1485,7 +2864,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
1485 kfree(event_name[irq_index]); 2864 kfree(event_name[irq_index]);
1486 kfree(dev_attr[irq_index]); 2865 kfree(dev_attr[irq_index]);
1487 2866
1488 return buf_size; 2867 return count;
1489} 2868}
1490 2869
1491/* 2870/*
@@ -1583,7 +2962,7 @@ static int ab8500_debug_probe(struct platform_device *plf)
1583 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); 2962 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
1584 if (irq_first < 0) { 2963 if (irq_first < 0) {
1585 dev_err(&plf->dev, "First irq not found, err %d\n", 2964 dev_err(&plf->dev, "First irq not found, err %d\n",
1586 irq_first); 2965 irq_first);
1587 ret = irq_first; 2966 ret = irq_first;
1588 goto out_freeevent_name; 2967 goto out_freeevent_name;
1589 } 2968 }
@@ -1591,9 +2970,9 @@ static int ab8500_debug_probe(struct platform_device *plf)
1591 irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); 2970 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
1592 if (irq_last < 0) { 2971 if (irq_last < 0) {
1593 dev_err(&plf->dev, "Last irq not found, err %d\n", 2972 dev_err(&plf->dev, "Last irq not found, err %d\n",
1594 irq_last); 2973 irq_last);
1595 ret = irq_last; 2974 ret = irq_last;
1596 goto out_freeevent_name; 2975 goto out_freeevent_name;
1597 } 2976 }
1598 2977
1599 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); 2978 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
@@ -1601,124 +2980,198 @@ static int ab8500_debug_probe(struct platform_device *plf)
1601 goto err; 2980 goto err;
1602 2981
1603 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING, 2982 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
1604 ab8500_dir); 2983 ab8500_dir);
1605 if (!ab8500_gpadc_dir) 2984 if (!ab8500_gpadc_dir)
1606 goto err; 2985 goto err;
1607 2986
1608 file = debugfs_create_file("all-bank-registers", S_IRUGO, 2987 file = debugfs_create_file("all-bank-registers", S_IRUGO,
1609 ab8500_dir, &plf->dev, &ab8500_registers_fops); 2988 ab8500_dir, &plf->dev, &ab8500_registers_fops);
1610 if (!file) 2989 if (!file)
1611 goto err; 2990 goto err;
1612 2991
1613 file = debugfs_create_file("all-banks", S_IRUGO, 2992 file = debugfs_create_file("all-banks", S_IRUGO,
1614 ab8500_dir, &plf->dev, &ab8500_all_banks_fops); 2993 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
1615 if (!file) 2994 if (!file)
1616 goto err; 2995 goto err;
1617 2996
1618 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), 2997 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
1619 ab8500_dir, &plf->dev, &ab8500_bank_fops); 2998 ab8500_dir, &plf->dev, &ab8500_bank_fops);
1620 if (!file) 2999 if (!file)
1621 goto err; 3000 goto err;
1622 3001
1623 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR), 3002 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
1624 ab8500_dir, &plf->dev, &ab8500_address_fops); 3003 ab8500_dir, &plf->dev, &ab8500_address_fops);
1625 if (!file) 3004 if (!file)
1626 goto err; 3005 goto err;
1627 3006
1628 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR), 3007 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
1629 ab8500_dir, &plf->dev, &ab8500_val_fops); 3008 ab8500_dir, &plf->dev, &ab8500_val_fops);
1630 if (!file) 3009 if (!file)
1631 goto err; 3010 goto err;
1632 3011
1633 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR), 3012 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
1634 ab8500_dir, &plf->dev, &ab8500_subscribe_fops); 3013 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
1635 if (!file) 3014 if (!file)
1636 goto err; 3015 goto err;
1637 3016
1638 if (is_ab8500(ab8500)) 3017 if (is_ab8500(ab8500)) {
3018 debug_ranges = ab8500_debug_ranges;
1639 num_interrupt_lines = AB8500_NR_IRQS; 3019 num_interrupt_lines = AB8500_NR_IRQS;
1640 else if (is_ab8505(ab8500)) 3020 } else if (is_ab8505(ab8500)) {
3021 debug_ranges = ab8505_debug_ranges;
1641 num_interrupt_lines = AB8505_NR_IRQS; 3022 num_interrupt_lines = AB8505_NR_IRQS;
1642 else if (is_ab9540(ab8500)) 3023 } else if (is_ab9540(ab8500)) {
3024 debug_ranges = ab8505_debug_ranges;
1643 num_interrupt_lines = AB9540_NR_IRQS; 3025 num_interrupt_lines = AB9540_NR_IRQS;
3026 } else if (is_ab8540(ab8500)) {
3027 debug_ranges = ab8540_debug_ranges;
3028 num_interrupt_lines = AB8540_NR_IRQS;
3029 }
1644 3030
1645 file = debugfs_create_file("interrupts", (S_IRUGO), 3031 file = debugfs_create_file("interrupts", (S_IRUGO),
1646 ab8500_dir, &plf->dev, &ab8500_interrupts_fops); 3032 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
1647 if (!file) 3033 if (!file)
1648 goto err; 3034 goto err;
1649 3035
1650 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR), 3036 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
1651 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops); 3037 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
1652 if (!file) 3038 if (!file)
1653 goto err; 3039 goto err;
1654 3040
1655 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR), 3041 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
1656 ab8500_dir, &plf->dev, &ab8500_hwreg_fops); 3042 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
1657 if (!file) 3043 if (!file)
1658 goto err; 3044 goto err;
1659 3045
1660 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR), 3046 file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
1661 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops); 3047 ab8500_dir, &plf->dev, &ab8500_modem_fops);
1662 if (!file) 3048 if (!file)
1663 goto err; 3049 goto err;
1664 3050
1665 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR), 3051 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
1666 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops); 3052 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
1667 if (!file) 3053 if (!file)
1668 goto err; 3054 goto err;
1669 3055
1670 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR), 3056 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
1671 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops); 3057 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
1672 if (!file) 3058 if (!file)
1673 goto err; 3059 goto err;
1674 3060
1675 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR), 3061 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR | S_IWGRP),
1676 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops); 3062 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
1677 if (!file) 3063 if (!file)
1678 goto err; 3064 goto err;
1679 3065
1680 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR), 3066 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR | S_IWGRP),
1681 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops); 3067 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
1682 if (!file) 3068 if (!file)
1683 goto err; 3069 goto err;
1684 3070
1685 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR), 3071 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR | S_IWGRP),
1686 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops); 3072 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
1687 if (!file) 3073 if (!file)
1688 goto err; 3074 goto err;
1689 3075
1690 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR), 3076 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
1691 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops); 3077 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
1692 if (!file) 3078 if (!file)
1693 goto err; 3079 goto err;
1694 3080
1695 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR), 3081 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
1696 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops); 3082 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
1697 if (!file) 3083 if (!file)
1698 goto err; 3084 goto err;
1699 3085
1700 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR), 3086 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
1701 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops); 3087 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
1702 if (!file) 3088 if (!file)
1703 goto err; 3089 goto err;
1704 3090
1705 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR), 3091 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
1706 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops); 3092 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
3093 if (!file)
3094 goto err;
3095
3096 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
3097 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
3098 if (!file)
3099 goto err;
3100
3101 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
3102 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3103 if (!file)
3104 goto err;
3105
3106 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3107 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
3108 if (!file)
3109 goto err;
3110
3111 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3112 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
3113 if (!file)
3114 goto err;
3115
3116 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3117 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops);
3118 if (!file)
3119 goto err;
3120
3121 if (is_ab8540(ab8500)) {
3122 file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3123 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops);
3124 if (!file)
3125 goto err;
3126 file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUSR | S_IWGRP),
3127 ab8500_gpadc_dir, &plf->dev,
3128 &ab8540_gpadc_vbat_true_meas_fops);
3129 if (!file)
3130 goto err;
3131 file = debugfs_create_file("batctrl_and_ibat",
3132 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3133 &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3134 if (!file)
3135 goto err;
3136 file = debugfs_create_file("vbatmeas_and_ibat",
3137 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3138 &plf->dev,
3139 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3140 if (!file)
3141 goto err;
3142 file = debugfs_create_file("vbattruemeas_and_ibat",
3143 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3144 &plf->dev,
3145 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3146 if (!file)
3147 goto err;
3148 file = debugfs_create_file("battemp_and_ibat",
3149 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3150 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3151 if (!file)
3152 goto err;
3153 file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUSR | S_IWGRP),
3154 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops);
3155 if (!file)
3156 goto err;
3157 }
3158 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3159 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
1707 if (!file) 3160 if (!file)
1708 goto err; 3161 goto err;
1709 3162
1710 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR), 3163 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
1711 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops); 3164 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
1712 if (!file) 3165 if (!file)
1713 goto err; 3166 goto err;
1714 3167
1715 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR), 3168 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
1716 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops); 3169 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
1717 if (!file) 3170 if (!file)
1718 goto err; 3171 goto err;
1719 3172
1720 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR), 3173 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
1721 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops); 3174 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
1722 if (!file) 3175 if (!file)
1723 goto err; 3176 goto err;
1724 3177
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 5f341a50ee5a..65f72284185d 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -37,6 +37,13 @@
37#define AB8500_GPADC_AUTODATAL_REG 0x07 37#define AB8500_GPADC_AUTODATAL_REG 0x07
38#define AB8500_GPADC_AUTODATAH_REG 0x08 38#define AB8500_GPADC_AUTODATAH_REG 0x08
39#define AB8500_GPADC_MUX_CTRL_REG 0x09 39#define AB8500_GPADC_MUX_CTRL_REG 0x09
40#define AB8540_GPADC_MANDATA2L_REG 0x09
41#define AB8540_GPADC_MANDATA2H_REG 0x0A
42#define AB8540_GPADC_APEAAX_REG 0x10
43#define AB8540_GPADC_APEAAT_REG 0x11
44#define AB8540_GPADC_APEAAM_REG 0x12
45#define AB8540_GPADC_APEAAH_REG 0x13
46#define AB8540_GPADC_APEAAL_REG 0x14
40 47
41/* 48/*
42 * OTP register offsets 49 * OTP register offsets
@@ -49,19 +56,29 @@
49#define AB8500_GPADC_CAL_5 0x13 56#define AB8500_GPADC_CAL_5 0x13
50#define AB8500_GPADC_CAL_6 0x14 57#define AB8500_GPADC_CAL_6 0x14
51#define AB8500_GPADC_CAL_7 0x15 58#define AB8500_GPADC_CAL_7 0x15
59/* New calibration for 8540 */
60#define AB8540_GPADC_OTP4_REG_7 0x38
61#define AB8540_GPADC_OTP4_REG_6 0x39
62#define AB8540_GPADC_OTP4_REG_5 0x3A
52 63
53/* gpadc constants */ 64/* gpadc constants */
54#define EN_VINTCORE12 0x04 65#define EN_VINTCORE12 0x04
55#define EN_VTVOUT 0x02 66#define EN_VTVOUT 0x02
56#define EN_GPADC 0x01 67#define EN_GPADC 0x01
57#define DIS_GPADC 0x00 68#define DIS_GPADC 0x00
58#define SW_AVG_16 0x60 69#define AVG_1 0x00
70#define AVG_4 0x20
71#define AVG_8 0x40
72#define AVG_16 0x60
59#define ADC_SW_CONV 0x04 73#define ADC_SW_CONV 0x04
60#define EN_ICHAR 0x80 74#define EN_ICHAR 0x80
61#define BTEMP_PULL_UP 0x08 75#define BTEMP_PULL_UP 0x08
62#define EN_BUF 0x40 76#define EN_BUF 0x40
63#define DIS_ZERO 0x00 77#define DIS_ZERO 0x00
64#define GPADC_BUSY 0x01 78#define GPADC_BUSY 0x01
79#define EN_FALLING 0x10
80#define EN_TRIG_EDGE 0x02
81#define EN_VBIAS_XTAL_TEMP 0x02
65 82
66/* GPADC constants from AB8500 spec, UM0836 */ 83/* GPADC constants from AB8500 spec, UM0836 */
67#define ADC_RESOLUTION 1024 84#define ADC_RESOLUTION 1024
@@ -80,8 +97,21 @@
80#define ADC_CH_BKBAT_MIN 0 97#define ADC_CH_BKBAT_MIN 0
81#define ADC_CH_BKBAT_MAX 3200 98#define ADC_CH_BKBAT_MAX 3200
82 99
100/* GPADC constants from AB8540 spec */
101#define ADC_CH_IBAT_MIN (-6000) /* mA range measured by ADC for ibat*/
102#define ADC_CH_IBAT_MAX 6000
103#define ADC_CH_IBAT_MIN_V (-60) /* mV range measured by ADC for ibat*/
104#define ADC_CH_IBAT_MAX_V 60
105#define IBAT_VDROP_L (-56) /* mV */
106#define IBAT_VDROP_H 56
107
83/* This is used to not lose precision when dividing to get gain and offset */ 108/* This is used to not lose precision when dividing to get gain and offset */
84#define CALIB_SCALE 1000 109#define CALIB_SCALE 1000
110/*
111 * Number of bits shift used to not lose precision
112 * when dividing to get ibat gain.
113 */
114#define CALIB_SHIFT_IBAT 20
85 115
86/* Time in ms before disabling regulator */ 116/* Time in ms before disabling regulator */
87#define GPADC_AUDOSUSPEND_DELAY 1 117#define GPADC_AUDOSUSPEND_DELAY 1
@@ -92,6 +122,7 @@ enum cal_channels {
92 ADC_INPUT_VMAIN = 0, 122 ADC_INPUT_VMAIN = 0,
93 ADC_INPUT_BTEMP, 123 ADC_INPUT_BTEMP,
94 ADC_INPUT_VBAT, 124 ADC_INPUT_VBAT,
125 ADC_INPUT_IBAT,
95 NBR_CAL_INPUTS, 126 NBR_CAL_INPUTS,
96}; 127};
97 128
@@ -102,8 +133,10 @@ enum cal_channels {
102 * @offset: Offset of the ADC channel 133 * @offset: Offset of the ADC channel
103 */ 134 */
104struct adc_cal_data { 135struct adc_cal_data {
105 u64 gain; 136 s64 gain;
106 u64 offset; 137 s64 offset;
138 u16 otp_calib_hi;
139 u16 otp_calib_lo;
107}; 140};
108 141
109/** 142/**
@@ -116,7 +149,10 @@ struct adc_cal_data {
116 * the completion of gpadc conversion 149 * the completion of gpadc conversion
117 * @ab8500_gpadc_lock: structure of type mutex 150 * @ab8500_gpadc_lock: structure of type mutex
118 * @regu: pointer to the struct regulator 151 * @regu: pointer to the struct regulator
119 * @irq: interrupt number that is used by gpadc 152 * @irq_sw: interrupt number that is used by gpadc for Sw
153 * conversion
154 * @irq_hw: interrupt number that is used by gpadc for Hw
155 * conversion
120 * @cal_data array of ADC calibration data structs 156 * @cal_data array of ADC calibration data structs
121 */ 157 */
122struct ab8500_gpadc { 158struct ab8500_gpadc {
@@ -126,7 +162,8 @@ struct ab8500_gpadc {
126 struct completion ab8500_gpadc_complete; 162 struct completion ab8500_gpadc_complete;
127 struct mutex ab8500_gpadc_lock; 163 struct mutex ab8500_gpadc_lock;
128 struct regulator *regu; 164 struct regulator *regu;
129 int irq; 165 int irq_sw;
166 int irq_hw;
130 struct adc_cal_data cal_data[NBR_CAL_INPUTS]; 167 struct adc_cal_data cal_data[NBR_CAL_INPUTS];
131}; 168};
132 169
@@ -171,6 +208,7 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
171 gpadc->cal_data[ADC_INPUT_VMAIN].offset) / CALIB_SCALE; 208 gpadc->cal_data[ADC_INPUT_VMAIN].offset) / CALIB_SCALE;
172 break; 209 break;
173 210
211 case XTAL_TEMP:
174 case BAT_CTRL: 212 case BAT_CTRL:
175 case BTEMP_BALL: 213 case BTEMP_BALL:
176 case ACC_DETECT1: 214 case ACC_DETECT1:
@@ -189,6 +227,7 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
189 break; 227 break;
190 228
191 case MAIN_BAT_V: 229 case MAIN_BAT_V:
230 case VBAT_TRUE_MEAS:
192 /* For some reason we don't have calibrated data */ 231 /* For some reason we don't have calibrated data */
193 if (!gpadc->cal_data[ADC_INPUT_VBAT].gain) { 232 if (!gpadc->cal_data[ADC_INPUT_VBAT].gain) {
194 res = ADC_CH_VBAT_MIN + (ADC_CH_VBAT_MAX - 233 res = ADC_CH_VBAT_MIN + (ADC_CH_VBAT_MAX -
@@ -232,6 +271,20 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
232 ADC_RESOLUTION; 271 ADC_RESOLUTION;
233 break; 272 break;
234 273
274 case IBAT_VIRTUAL_CHANNEL:
275 /* For some reason we don't have calibrated data */
276 if (!gpadc->cal_data[ADC_INPUT_IBAT].gain) {
277 res = ADC_CH_IBAT_MIN + (ADC_CH_IBAT_MAX -
278 ADC_CH_IBAT_MIN) * ad_value /
279 ADC_RESOLUTION;
280 break;
281 }
282 /* Here we can use the calibrated data */
283 res = (int) (ad_value * gpadc->cal_data[ADC_INPUT_IBAT].gain +
284 gpadc->cal_data[ADC_INPUT_IBAT].offset)
285 >> CALIB_SHIFT_IBAT;
286 break;
287
235 default: 288 default:
236 dev_err(gpadc->dev, 289 dev_err(gpadc->dev,
237 "unknown channel, not possible to convert\n"); 290 "unknown channel, not possible to convert\n");
@@ -244,25 +297,35 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
244EXPORT_SYMBOL(ab8500_gpadc_ad_to_voltage); 297EXPORT_SYMBOL(ab8500_gpadc_ad_to_voltage);
245 298
246/** 299/**
247 * ab8500_gpadc_convert() - gpadc conversion 300 * ab8500_gpadc_sw_hw_convert() - gpadc conversion
248 * @channel: analog channel to be converted to digital data 301 * @channel: analog channel to be converted to digital data
302 * @avg_sample: number of ADC sample to average
303 * @trig_egde: selected ADC trig edge
304 * @trig_timer: selected ADC trigger delay timer
305 * @conv_type: selected conversion type (HW or SW conversion)
249 * 306 *
250 * This function converts the selected analog i/p to digital 307 * This function converts the selected analog i/p to digital
251 * data. 308 * data.
252 */ 309 */
253int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel) 310int ab8500_gpadc_sw_hw_convert(struct ab8500_gpadc *gpadc, u8 channel,
311 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type)
254{ 312{
255 int ad_value; 313 int ad_value;
256 int voltage; 314 int voltage;
257 315
258 ad_value = ab8500_gpadc_read_raw(gpadc, channel); 316 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample,
259 if (ad_value < 0) { 317 trig_edge, trig_timer, conv_type);
260 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n", channel); 318/* On failure retry a second time */
319 if (ad_value < 0)
320 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample,
321 trig_edge, trig_timer, conv_type);
322if (ad_value < 0) {
323 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n",
324 channel);
261 return ad_value; 325 return ad_value;
262 } 326 }
263 327
264 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value); 328 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value);
265
266 if (voltage < 0) 329 if (voltage < 0)
267 dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:" 330 dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:"
268 " %d AD: 0x%x\n", channel, ad_value); 331 " %d AD: 0x%x\n", channel, ad_value);
@@ -274,21 +337,46 @@ EXPORT_SYMBOL(ab8500_gpadc_convert);
274/** 337/**
275 * ab8500_gpadc_read_raw() - gpadc read 338 * ab8500_gpadc_read_raw() - gpadc read
276 * @channel: analog channel to be read 339 * @channel: analog channel to be read
340 * @avg_sample: number of ADC sample to average
341 * @trig_edge: selected trig edge
342 * @trig_timer: selected ADC trigger delay timer
343 * @conv_type: selected conversion type (HW or SW conversion)
277 * 344 *
278 * This function obtains the raw ADC value, this then needs 345 * This function obtains the raw ADC value for an hardware conversion,
279 * to be converted by calling ab8500_gpadc_ad_to_voltage() 346 * this then needs to be converted by calling ab8500_gpadc_ad_to_voltage()
280 */ 347 */
281int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel) 348int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
349 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type)
350{
351 int raw_data;
352 raw_data = ab8500_gpadc_double_read_raw(gpadc, channel,
353 avg_sample, trig_edge, trig_timer, conv_type, NULL);
354 return raw_data;
355}
356
357int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
358 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type,
359 int *ibat)
282{ 360{
283 int ret; 361 int ret;
284 int looplimit = 0; 362 int looplimit = 0;
285 u8 val, low_data, high_data; 363 unsigned long completion_timeout;
364 u8 val, low_data, high_data, low_data2, high_data2;
365 u8 val_reg1 = 0;
366 unsigned int delay_min = 0;
367 unsigned int delay_max = 0;
368 u8 data_low_addr, data_high_addr;
286 369
287 if (!gpadc) 370 if (!gpadc)
288 return -ENODEV; 371 return -ENODEV;
289 372
290 mutex_lock(&gpadc->ab8500_gpadc_lock); 373 /* check if convertion is supported */
374 if ((gpadc->irq_sw < 0) && (conv_type == ADC_SW))
375 return -ENOTSUPP;
376 if ((gpadc->irq_hw < 0) && (conv_type == ADC_HW))
377 return -ENOTSUPP;
291 378
379 mutex_lock(&gpadc->ab8500_gpadc_lock);
292 /* Enable VTVout LDO this is required for GPADC */ 380 /* Enable VTVout LDO this is required for GPADC */
293 pm_runtime_get_sync(gpadc->dev); 381 pm_runtime_get_sync(gpadc->dev);
294 382
@@ -309,16 +397,34 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
309 } 397 }
310 398
311 /* Enable GPADC */ 399 /* Enable GPADC */
312 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 400 val_reg1 |= EN_GPADC;
313 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, EN_GPADC, EN_GPADC); 401
314 if (ret < 0) { 402 /* Select the channel source and set average samples */
315 dev_err(gpadc->dev, "gpadc_conversion: enable gpadc failed\n"); 403 switch (avg_sample) {
316 goto out; 404 case SAMPLE_1:
405 val = channel | AVG_1;
406 break;
407 case SAMPLE_4:
408 val = channel | AVG_4;
409 break;
410 case SAMPLE_8:
411 val = channel | AVG_8;
412 break;
413 default:
414 val = channel | AVG_16;
415 break;
317 } 416 }
318 417
319 /* Select the channel source and set average samples to 16 */ 418 if (conv_type == ADC_HW) {
320 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 419 ret = abx500_set_register_interruptible(gpadc->dev,
321 AB8500_GPADC_CTRL2_REG, (channel | SW_AVG_16)); 420 AB8500_GPADC, AB8500_GPADC_CTRL3_REG, val);
421 val_reg1 |= EN_TRIG_EDGE;
422 if (trig_edge)
423 val_reg1 |= EN_FALLING;
424 }
425 else
426 ret = abx500_set_register_interruptible(gpadc->dev,
427 AB8500_GPADC, AB8500_GPADC_CTRL2_REG, val);
322 if (ret < 0) { 428 if (ret < 0) {
323 dev_err(gpadc->dev, 429 dev_err(gpadc->dev,
324 "gpadc_conversion: set avg samples failed\n"); 430 "gpadc_conversion: set avg samples failed\n");
@@ -333,71 +439,129 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
333 switch (channel) { 439 switch (channel) {
334 case MAIN_CHARGER_C: 440 case MAIN_CHARGER_C:
335 case USB_CHARGER_C: 441 case USB_CHARGER_C:
336 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 442 val_reg1 |= EN_BUF | EN_ICHAR;
337 AB8500_GPADC, AB8500_GPADC_CTRL1_REG,
338 EN_BUF | EN_ICHAR,
339 EN_BUF | EN_ICHAR);
340 break; 443 break;
341 case BTEMP_BALL: 444 case BTEMP_BALL:
342 if (!is_ab8500_2p0_or_earlier(gpadc->parent)) { 445 if (!is_ab8500_2p0_or_earlier(gpadc->parent)) {
343 /* Turn on btemp pull-up on ABB 3.0 */ 446 val_reg1 |= EN_BUF | BTEMP_PULL_UP;
344 ret = abx500_mask_and_set_register_interruptible( 447 /*
345 gpadc->dev, 448 * Delay might be needed for ABB8500 cut 3.0, if not,
346 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 449 * remove when hardware will be availible
347 EN_BUF | BTEMP_PULL_UP, 450 */
348 EN_BUF | BTEMP_PULL_UP); 451 delay_min = 1000; /* Delay in micro seconds */
349 452 delay_max = 10000; /* large range to optimise sleep mode */
350 /*
351 * Delay might be needed for ABB8500 cut 3.0, if not, remove
352 * when hardware will be available
353 */
354 usleep_range(1000, 1000);
355 break; 453 break;
356 } 454 }
357 /* Intentional fallthrough */ 455 /* Intentional fallthrough */
358 default: 456 default:
359 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 457 val_reg1 |= EN_BUF;
360 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, EN_BUF, EN_BUF);
361 break; 458 break;
362 } 459 }
460
461 /* Write configuration to register */
462 ret = abx500_set_register_interruptible(gpadc->dev,
463 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, val_reg1);
363 if (ret < 0) { 464 if (ret < 0) {
364 dev_err(gpadc->dev, 465 dev_err(gpadc->dev,
365 "gpadc_conversion: select falling edge failed\n"); 466 "gpadc_conversion: set Control register failed\n");
366 goto out; 467 goto out;
367 } 468 }
368 469
369 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 470 if (delay_min != 0)
370 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, ADC_SW_CONV, ADC_SW_CONV); 471 usleep_range(delay_min, delay_max);
371 if (ret < 0) { 472
372 dev_err(gpadc->dev, 473 if (conv_type == ADC_HW) {
373 "gpadc_conversion: start s/w conversion failed\n"); 474 /* Set trigger delay timer */
374 goto out; 475 ret = abx500_set_register_interruptible(gpadc->dev,
476 AB8500_GPADC, AB8500_GPADC_AUTO_TIMER_REG, trig_timer);
477 if (ret < 0) {
478 dev_err(gpadc->dev,
479 "gpadc_conversion: trig timer failed\n");
480 goto out;
481 }
482 completion_timeout = 2 * HZ;
483 data_low_addr = AB8500_GPADC_AUTODATAL_REG;
484 data_high_addr = AB8500_GPADC_AUTODATAH_REG;
485 } else {
486 /* Start SW conversion */
487 ret = abx500_mask_and_set_register_interruptible(gpadc->dev,
488 AB8500_GPADC, AB8500_GPADC_CTRL1_REG,
489 ADC_SW_CONV, ADC_SW_CONV);
490 if (ret < 0) {
491 dev_err(gpadc->dev,
492 "gpadc_conversion: start s/w conv failed\n");
493 goto out;
494 }
495 completion_timeout = msecs_to_jiffies(CONVERSION_TIME);
496 data_low_addr = AB8500_GPADC_MANDATAL_REG;
497 data_high_addr = AB8500_GPADC_MANDATAH_REG;
375 } 498 }
499
376 /* wait for completion of conversion */ 500 /* wait for completion of conversion */
377 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 501 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete,
378 msecs_to_jiffies(CONVERSION_TIME))) { 502 completion_timeout)) {
379 dev_err(gpadc->dev, 503 dev_err(gpadc->dev,
380 "timeout: didn't receive GPADC conversion interrupt\n"); 504 "timeout didn't receive GPADC conv interrupt\n");
381 ret = -EINVAL; 505 ret = -EINVAL;
382 goto out; 506 goto out;
383 } 507 }
384 508
385 /* Read the converted RAW data */ 509 /* Read the converted RAW data */
386 ret = abx500_get_register_interruptible(gpadc->dev, AB8500_GPADC, 510 ret = abx500_get_register_interruptible(gpadc->dev,
387 AB8500_GPADC_MANDATAL_REG, &low_data); 511 AB8500_GPADC, data_low_addr, &low_data);
388 if (ret < 0) { 512 if (ret < 0) {
389 dev_err(gpadc->dev, "gpadc_conversion: read low data failed\n"); 513 dev_err(gpadc->dev, "gpadc_conversion: read low data failed\n");
390 goto out; 514 goto out;
391 } 515 }
392 516
393 ret = abx500_get_register_interruptible(gpadc->dev, AB8500_GPADC, 517 ret = abx500_get_register_interruptible(gpadc->dev,
394 AB8500_GPADC_MANDATAH_REG, &high_data); 518 AB8500_GPADC, data_high_addr, &high_data);
395 if (ret < 0) { 519 if (ret < 0) {
396 dev_err(gpadc->dev, 520 dev_err(gpadc->dev, "gpadc_conversion: read high data failed\n");
397 "gpadc_conversion: read high data failed\n");
398 goto out; 521 goto out;
399 } 522 }
400 523
524 /* Check if double convertion is required */
525 if ((channel == BAT_CTRL_AND_IBAT) ||
526 (channel == VBAT_MEAS_AND_IBAT) ||
527 (channel == VBAT_TRUE_MEAS_AND_IBAT) ||
528 (channel == BAT_TEMP_AND_IBAT)) {
529
530 if (conv_type == ADC_HW) {
531 /* not supported */
532 ret = -ENOTSUPP;
533 dev_err(gpadc->dev,
534 "gpadc_conversion: only SW double conversion supported\n");
535 goto out;
536 } else {
537 /* Read the converted RAW data 2 */
538 ret = abx500_get_register_interruptible(gpadc->dev,
539 AB8500_GPADC, AB8540_GPADC_MANDATA2L_REG,
540 &low_data2);
541 if (ret < 0) {
542 dev_err(gpadc->dev,
543 "gpadc_conversion: read sw low data 2 failed\n");
544 goto out;
545 }
546
547 ret = abx500_get_register_interruptible(gpadc->dev,
548 AB8500_GPADC, AB8540_GPADC_MANDATA2H_REG,
549 &high_data2);
550 if (ret < 0) {
551 dev_err(gpadc->dev,
552 "gpadc_conversion: read sw high data 2 failed\n");
553 goto out;
554 }
555 if (ibat != NULL) {
556 *ibat = (high_data2 << 8) | low_data2;
557 } else {
558 dev_warn(gpadc->dev,
559 "gpadc_conversion: ibat not stored\n");
560 }
561
562 }
563 }
564
401 /* Disable GPADC */ 565 /* Disable GPADC */
402 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 566 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
403 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 567 AB8500_GPADC_CTRL1_REG, DIS_GPADC);
@@ -406,6 +570,7 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
406 goto out; 570 goto out;
407 } 571 }
408 572
573 /* Disable VTVout LDO this is required for GPADC */
409 pm_runtime_mark_last_busy(gpadc->dev); 574 pm_runtime_mark_last_busy(gpadc->dev);
410 pm_runtime_put_autosuspend(gpadc->dev); 575 pm_runtime_put_autosuspend(gpadc->dev);
411 576
@@ -422,9 +587,7 @@ out:
422 */ 587 */
423 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 588 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
424 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 589 AB8500_GPADC_CTRL1_REG, DIS_GPADC);
425
426 pm_runtime_put(gpadc->dev); 590 pm_runtime_put(gpadc->dev);
427
428 mutex_unlock(&gpadc->ab8500_gpadc_lock); 591 mutex_unlock(&gpadc->ab8500_gpadc_lock);
429 dev_err(gpadc->dev, 592 dev_err(gpadc->dev,
430 "gpadc_conversion: Failed to AD convert channel %d\n", channel); 593 "gpadc_conversion: Failed to AD convert channel %d\n", channel);
@@ -433,16 +596,16 @@ out:
433EXPORT_SYMBOL(ab8500_gpadc_read_raw); 596EXPORT_SYMBOL(ab8500_gpadc_read_raw);
434 597
435/** 598/**
436 * ab8500_bm_gpswadcconvend_handler() - isr for s/w gpadc conversion completion 599 * ab8500_bm_gpadcconvend_handler() - isr for gpadc conversion completion
437 * @irq: irq number 600 * @irq: irq number
438 * @data: pointer to the data passed during request irq 601 * @data: pointer to the data passed during request irq
439 * 602 *
440 * This is a interrupt service routine for s/w gpadc conversion completion. 603 * This is a interrupt service routine for gpadc conversion completion.
441 * Notifies the gpadc completion is completed and the converted raw value 604 * Notifies the gpadc completion is completed and the converted raw value
442 * can be read from the registers. 605 * can be read from the registers.
443 * Returns IRQ status(IRQ_HANDLED) 606 * Returns IRQ status(IRQ_HANDLED)
444 */ 607 */
445static irqreturn_t ab8500_bm_gpswadcconvend_handler(int irq, void *_gpadc) 608static irqreturn_t ab8500_bm_gpadcconvend_handler(int irq, void *_gpadc)
446{ 609{
447 struct ab8500_gpadc *gpadc = _gpadc; 610 struct ab8500_gpadc *gpadc = _gpadc;
448 611
@@ -461,15 +624,27 @@ static int otp_cal_regs[] = {
461 AB8500_GPADC_CAL_7, 624 AB8500_GPADC_CAL_7,
462}; 625};
463 626
627static int otp4_cal_regs[] = {
628 AB8540_GPADC_OTP4_REG_7,
629 AB8540_GPADC_OTP4_REG_6,
630 AB8540_GPADC_OTP4_REG_5,
631};
632
464static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc) 633static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
465{ 634{
466 int i; 635 int i;
467 int ret[ARRAY_SIZE(otp_cal_regs)]; 636 int ret[ARRAY_SIZE(otp_cal_regs)];
468 u8 gpadc_cal[ARRAY_SIZE(otp_cal_regs)]; 637 u8 gpadc_cal[ARRAY_SIZE(otp_cal_regs)];
469 638 int ret_otp4[ARRAY_SIZE(otp4_cal_regs)];
639 u8 gpadc_otp4[ARRAY_SIZE(otp4_cal_regs)];
470 int vmain_high, vmain_low; 640 int vmain_high, vmain_low;
471 int btemp_high, btemp_low; 641 int btemp_high, btemp_low;
472 int vbat_high, vbat_low; 642 int vbat_high, vbat_low;
643 int ibat_high, ibat_low;
644 s64 V_gain, V_offset, V2A_gain, V2A_offset;
645 struct ab8500 *ab8500;
646
647 ab8500 = gpadc->parent;
473 648
474 /* First we read all OTP registers and store the error code */ 649 /* First we read all OTP registers and store the error code */
475 for (i = 0; i < ARRAY_SIZE(otp_cal_regs); i++) { 650 for (i = 0; i < ARRAY_SIZE(otp_cal_regs); i++) {
@@ -489,7 +664,7 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
489 * bt_h/l = btemp_high/low 664 * bt_h/l = btemp_high/low
490 * vb_h/l = vbat_high/low 665 * vb_h/l = vbat_high/low
491 * 666 *
492 * Data bits: 667 * Data bits 8500/9540:
493 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 668 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
494 * |.......|.......|.......|.......|.......|.......|.......|....... 669 * |.......|.......|.......|.......|.......|.......|.......|.......
495 * | | vm_h9 | vm_h8 670 * | | vm_h9 | vm_h8
@@ -507,6 +682,35 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
507 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 | 682 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 |
508 * |.......|.......|.......|.......|.......|.......|.......|....... 683 * |.......|.......|.......|.......|.......|.......|.......|.......
509 * 684 *
685 * Data bits 8540:
686 * OTP2
687 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
688 * |.......|.......|.......|.......|.......|.......|.......|.......
689 * |
690 * |.......|.......|.......|.......|.......|.......|.......|.......
691 * | vm_h9 | vm_h8 | vm_h7 | vm_h6 | vm_h5 | vm_h4 | vm_h3 | vm_h2
692 * |.......|.......|.......|.......|.......|.......|.......|.......
693 * | vm_h1 | vm_h0 | vm_l4 | vm_l3 | vm_l2 | vm_l1 | vm_l0 | bt_h9
694 * |.......|.......|.......|.......|.......|.......|.......|.......
695 * | bt_h8 | bt_h7 | bt_h6 | bt_h5 | bt_h4 | bt_h3 | bt_h2 | bt_h1
696 * |.......|.......|.......|.......|.......|.......|.......|.......
697 * | bt_h0 | bt_l4 | bt_l3 | bt_l2 | bt_l1 | bt_l0 | vb_h9 | vb_h8
698 * |.......|.......|.......|.......|.......|.......|.......|.......
699 * | vb_h7 | vb_h6 | vb_h5 | vb_h4 | vb_h3 | vb_h2 | vb_h1 | vb_h0
700 * |.......|.......|.......|.......|.......|.......|.......|.......
701 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 |
702 * |.......|.......|.......|.......|.......|.......|.......|.......
703 *
704 * Data bits 8540:
705 * OTP4
706 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
707 * |.......|.......|.......|.......|.......|.......|.......|.......
708 * | | ib_h9 | ib_h8 | ib_h7
709 * |.......|.......|.......|.......|.......|.......|.......|.......
710 * | ib_h6 | ib_h5 | ib_h4 | ib_h3 | ib_h2 | ib_h1 | ib_h0 | ib_l5
711 * |.......|.......|.......|.......|.......|.......|.......|.......
712 * | ib_l4 | ib_l3 | ib_l2 | ib_l1 | ib_l0 |
713 *
510 * 714 *
511 * Ideal output ADC codes corresponding to injected input voltages 715 * Ideal output ADC codes corresponding to injected input voltages
512 * during manufacturing is: 716 * during manufacturing is:
@@ -519,38 +723,116 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
519 * vbat_low: Vin = 2380mV / ADC ideal code = 33 723 * vbat_low: Vin = 2380mV / ADC ideal code = 33
520 */ 724 */
521 725
522 /* Calculate gain and offset for VMAIN if all reads succeeded */ 726 if (is_ab8540(ab8500)) {
523 if (!(ret[0] < 0 || ret[1] < 0 || ret[2] < 0)) { 727 /* Calculate gain and offset for VMAIN if all reads succeeded*/
524 vmain_high = (((gpadc_cal[0] & 0x03) << 8) | 728 if (!(ret[1] < 0 || ret[2] < 0)) {
525 ((gpadc_cal[1] & 0x3F) << 2) | 729 vmain_high = (((gpadc_cal[1] & 0xFF) << 2) |
526 ((gpadc_cal[2] & 0xC0) >> 6)); 730 ((gpadc_cal[2] & 0xC0) >> 6));
731 vmain_low = ((gpadc_cal[2] & 0x3E) >> 1);
732
733 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi =
734 (u16)vmain_high;
735 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_lo =
736 (u16)vmain_low;
737
738 gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE *
739 (19500 - 315) / (vmain_high - vmain_low);
740 gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE *
741 19500 - (CALIB_SCALE * (19500 - 315) /
742 (vmain_high - vmain_low)) * vmain_high;
743 } else {
744 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0;
745 }
527 746
528 vmain_low = ((gpadc_cal[2] & 0x3E) >> 1); 747 /* Read IBAT calibration Data */
748 for (i = 0; i < ARRAY_SIZE(otp4_cal_regs); i++) {
749 ret_otp4[i] = abx500_get_register_interruptible(
750 gpadc->dev, AB8500_OTP_EMUL,
751 otp4_cal_regs[i], &gpadc_otp4[i]);
752 if (ret_otp4[i] < 0)
753 dev_err(gpadc->dev,
754 "%s: read otp4 reg 0x%02x failed\n",
755 __func__, otp4_cal_regs[i]);
756 }
529 757
530 gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE * 758 /* Calculate gain and offset for IBAT if all reads succeeded */
531 (19500 - 315) / (vmain_high - vmain_low); 759 if (!(ret_otp4[0] < 0 || ret_otp4[1] < 0 || ret_otp4[2] < 0)) {
760 ibat_high = (((gpadc_otp4[0] & 0x07) << 7) |
761 ((gpadc_otp4[1] & 0xFE) >> 1));
762 ibat_low = (((gpadc_otp4[1] & 0x01) << 5) |
763 ((gpadc_otp4[2] & 0xF8) >> 3));
764
765 gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_hi =
766 (u16)ibat_high;
767 gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_lo =
768 (u16)ibat_low;
769
770 V_gain = ((IBAT_VDROP_H - IBAT_VDROP_L)
771 << CALIB_SHIFT_IBAT) / (ibat_high - ibat_low);
772
773 V_offset = (IBAT_VDROP_H << CALIB_SHIFT_IBAT) -
774 (((IBAT_VDROP_H - IBAT_VDROP_L) <<
775 CALIB_SHIFT_IBAT) / (ibat_high - ibat_low))
776 * ibat_high;
777 /*
778 * Result obtained is in mV (at a scale factor),
779 * we need to calculate gain and offset to get mA
780 */
781 V2A_gain = (ADC_CH_IBAT_MAX - ADC_CH_IBAT_MIN)/
782 (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V);
783 V2A_offset = ((ADC_CH_IBAT_MAX_V * ADC_CH_IBAT_MIN -
784 ADC_CH_IBAT_MAX * ADC_CH_IBAT_MIN_V)
785 << CALIB_SHIFT_IBAT)
786 / (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V);
787
788 gpadc->cal_data[ADC_INPUT_IBAT].gain = V_gain * V2A_gain;
789 gpadc->cal_data[ADC_INPUT_IBAT].offset = V_offset *
790 V2A_gain + V2A_offset;
791 } else {
792 gpadc->cal_data[ADC_INPUT_IBAT].gain = 0;
793 }
532 794
533 gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE * 19500 - 795 dev_dbg(gpadc->dev, "IBAT gain %llu offset %llu\n",
534 (CALIB_SCALE * (19500 - 315) / 796 gpadc->cal_data[ADC_INPUT_IBAT].gain,
535 (vmain_high - vmain_low)) * vmain_high; 797 gpadc->cal_data[ADC_INPUT_IBAT].offset);
536 } else { 798 } else {
537 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0; 799 /* Calculate gain and offset for VMAIN if all reads succeeded */
800 if (!(ret[0] < 0 || ret[1] < 0 || ret[2] < 0)) {
801 vmain_high = (((gpadc_cal[0] & 0x03) << 8) |
802 ((gpadc_cal[1] & 0x3F) << 2) |
803 ((gpadc_cal[2] & 0xC0) >> 6));
804 vmain_low = ((gpadc_cal[2] & 0x3E) >> 1);
805
806 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi =
807 (u16)vmain_high;
808 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_lo =
809 (u16)vmain_low;
810
811 gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE *
812 (19500 - 315) / (vmain_high - vmain_low);
813
814 gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE *
815 19500 - (CALIB_SCALE * (19500 - 315) /
816 (vmain_high - vmain_low)) * vmain_high;
817 } else {
818 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0;
819 }
538 } 820 }
539 821
540 /* Calculate gain and offset for BTEMP if all reads succeeded */ 822 /* Calculate gain and offset for BTEMP if all reads succeeded */
541 if (!(ret[2] < 0 || ret[3] < 0 || ret[4] < 0)) { 823 if (!(ret[2] < 0 || ret[3] < 0 || ret[4] < 0)) {
542 btemp_high = (((gpadc_cal[2] & 0x01) << 9) | 824 btemp_high = (((gpadc_cal[2] & 0x01) << 9) |
543 (gpadc_cal[3] << 1) | 825 (gpadc_cal[3] << 1) | ((gpadc_cal[4] & 0x80) >> 7));
544 ((gpadc_cal[4] & 0x80) >> 7));
545
546 btemp_low = ((gpadc_cal[4] & 0x7C) >> 2); 826 btemp_low = ((gpadc_cal[4] & 0x7C) >> 2);
547 827
828 gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_hi = (u16)btemp_high;
829 gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_lo = (u16)btemp_low;
830
548 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 831 gpadc->cal_data[ADC_INPUT_BTEMP].gain =
549 CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low); 832 CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low);
550
551 gpadc->cal_data[ADC_INPUT_BTEMP].offset = CALIB_SCALE * 1300 - 833 gpadc->cal_data[ADC_INPUT_BTEMP].offset = CALIB_SCALE * 1300 -
552 (CALIB_SCALE * (1300 - 21) / 834 (CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low))
553 (btemp_high - btemp_low)) * btemp_high; 835 * btemp_high;
554 } else { 836 } else {
555 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 0; 837 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 0;
556 } 838 }
@@ -560,9 +842,11 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
560 vbat_high = (((gpadc_cal[4] & 0x03) << 8) | gpadc_cal[5]); 842 vbat_high = (((gpadc_cal[4] & 0x03) << 8) | gpadc_cal[5]);
561 vbat_low = ((gpadc_cal[6] & 0xFC) >> 2); 843 vbat_low = ((gpadc_cal[6] & 0xFC) >> 2);
562 844
845 gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_hi = (u16)vbat_high;
846 gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_lo = (u16)vbat_low;
847
563 gpadc->cal_data[ADC_INPUT_VBAT].gain = CALIB_SCALE * 848 gpadc->cal_data[ADC_INPUT_VBAT].gain = CALIB_SCALE *
564 (4700 - 2380) / (vbat_high - vbat_low); 849 (4700 - 2380) / (vbat_high - vbat_low);
565
566 gpadc->cal_data[ADC_INPUT_VBAT].offset = CALIB_SCALE * 4700 - 850 gpadc->cal_data[ADC_INPUT_VBAT].offset = CALIB_SCALE * 4700 -
567 (CALIB_SCALE * (4700 - 2380) / 851 (CALIB_SCALE * (4700 - 2380) /
568 (vbat_high - vbat_low)) * vbat_high; 852 (vbat_high - vbat_low)) * vbat_high;
@@ -608,6 +892,31 @@ static int ab8500_gpadc_runtime_idle(struct device *dev)
608 return 0; 892 return 0;
609} 893}
610 894
895static int ab8500_gpadc_suspend(struct device *dev)
896{
897 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
898
899 mutex_lock(&gpadc->ab8500_gpadc_lock);
900
901 pm_runtime_get_sync(dev);
902
903 regulator_disable(gpadc->regu);
904 return 0;
905}
906
907static int ab8500_gpadc_resume(struct device *dev)
908{
909 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
910
911 regulator_enable(gpadc->regu);
912
913 pm_runtime_mark_last_busy(gpadc->dev);
914 pm_runtime_put_autosuspend(gpadc->dev);
915
916 mutex_unlock(&gpadc->ab8500_gpadc_lock);
917 return 0;
918}
919
611static int ab8500_gpadc_probe(struct platform_device *pdev) 920static int ab8500_gpadc_probe(struct platform_device *pdev)
612{ 921{
613 int ret = 0; 922 int ret = 0;
@@ -619,13 +928,13 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
619 return -ENOMEM; 928 return -ENOMEM;
620 } 929 }
621 930
622 gpadc->irq = platform_get_irq_byname(pdev, "SW_CONV_END"); 931 gpadc->irq_sw = platform_get_irq_byname(pdev, "SW_CONV_END");
623 if (gpadc->irq < 0) { 932 if (gpadc->irq_sw < 0)
624 dev_err(&pdev->dev, "failed to get platform irq-%d\n", 933 dev_err(gpadc->dev, "failed to get platform sw_conv_end irq\n");
625 gpadc->irq); 934
626 ret = gpadc->irq; 935 gpadc->irq_hw = platform_get_irq_byname(pdev, "HW_CONV_END");
627 goto fail; 936 if (gpadc->irq_hw < 0)
628 } 937 dev_err(gpadc->dev, "failed to get platform hw_conv_end irq\n");
629 938
630 gpadc->dev = &pdev->dev; 939 gpadc->dev = &pdev->dev;
631 gpadc->parent = dev_get_drvdata(pdev->dev.parent); 940 gpadc->parent = dev_get_drvdata(pdev->dev.parent);
@@ -634,15 +943,31 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
634 /* Initialize completion used to notify completion of conversion */ 943 /* Initialize completion used to notify completion of conversion */
635 init_completion(&gpadc->ab8500_gpadc_complete); 944 init_completion(&gpadc->ab8500_gpadc_complete);
636 945
637 /* Register interrupt - SwAdcComplete */ 946 /* Register interrupts */
638 ret = request_threaded_irq(gpadc->irq, NULL, 947 if (gpadc->irq_sw >= 0) {
639 ab8500_bm_gpswadcconvend_handler, 948 ret = request_threaded_irq(gpadc->irq_sw, NULL,
640 IRQF_ONESHOT | IRQF_NO_SUSPEND | IRQF_SHARED, 949 ab8500_bm_gpadcconvend_handler,
641 "ab8500-gpadc", gpadc); 950 IRQF_NO_SUSPEND | IRQF_SHARED, "ab8500-gpadc-sw",
642 if (ret < 0) { 951 gpadc);
643 dev_err(gpadc->dev, "Failed to register interrupt, irq: %d\n", 952 if (ret < 0) {
644 gpadc->irq); 953 dev_err(gpadc->dev,
645 goto fail; 954 "Failed to register interrupt irq: %d\n",
955 gpadc->irq_sw);
956 goto fail;
957 }
958 }
959
960 if (gpadc->irq_hw >= 0) {
961 ret = request_threaded_irq(gpadc->irq_hw, NULL,
962 ab8500_bm_gpadcconvend_handler,
963 IRQF_NO_SUSPEND | IRQF_SHARED, "ab8500-gpadc-hw",
964 gpadc);
965 if (ret < 0) {
966 dev_err(gpadc->dev,
967 "Failed to register interrupt irq: %d\n",
968 gpadc->irq_hw);
969 goto fail_irq;
970 }
646 } 971 }
647 972
648 /* VTVout LDO used to power up ab8500-GPADC */ 973 /* VTVout LDO used to power up ab8500-GPADC */
@@ -669,11 +994,13 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
669 ab8500_gpadc_read_calibration_data(gpadc); 994 ab8500_gpadc_read_calibration_data(gpadc);
670 list_add_tail(&gpadc->node, &ab8500_gpadc_list); 995 list_add_tail(&gpadc->node, &ab8500_gpadc_list);
671 dev_dbg(gpadc->dev, "probe success\n"); 996 dev_dbg(gpadc->dev, "probe success\n");
997
672 return 0; 998 return 0;
673 999
674fail_enable: 1000fail_enable:
675fail_irq: 1001fail_irq:
676 free_irq(gpadc->irq, gpadc); 1002 free_irq(gpadc->irq_sw, gpadc);
1003 free_irq(gpadc->irq_hw, gpadc);
677fail: 1004fail:
678 kfree(gpadc); 1005 kfree(gpadc);
679 gpadc = NULL; 1006 gpadc = NULL;
@@ -687,7 +1014,10 @@ static int ab8500_gpadc_remove(struct platform_device *pdev)
687 /* remove this gpadc entry from the list */ 1014 /* remove this gpadc entry from the list */
688 list_del(&gpadc->node); 1015 list_del(&gpadc->node);
689 /* remove interrupt - completion of Sw ADC conversion */ 1016 /* remove interrupt - completion of Sw ADC conversion */
690 free_irq(gpadc->irq, gpadc); 1017 if (gpadc->irq_sw >= 0)
1018 free_irq(gpadc->irq_sw, gpadc);
1019 if (gpadc->irq_hw >= 0)
1020 free_irq(gpadc->irq_hw, gpadc);
691 1021
692 pm_runtime_get_sync(gpadc->dev); 1022 pm_runtime_get_sync(gpadc->dev);
693 pm_runtime_disable(gpadc->dev); 1023 pm_runtime_disable(gpadc->dev);
@@ -707,6 +1037,9 @@ static const struct dev_pm_ops ab8500_gpadc_pm_ops = {
707 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend, 1037 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend,
708 ab8500_gpadc_runtime_resume, 1038 ab8500_gpadc_runtime_resume,
709 ab8500_gpadc_runtime_idle) 1039 ab8500_gpadc_runtime_idle)
1040 SET_SYSTEM_SLEEP_PM_OPS(ab8500_gpadc_suspend,
1041 ab8500_gpadc_resume)
1042
710}; 1043};
711 1044
712static struct platform_driver ab8500_gpadc_driver = { 1045static struct platform_driver ab8500_gpadc_driver = {
@@ -729,10 +1062,30 @@ static void __exit ab8500_gpadc_exit(void)
729 platform_driver_unregister(&ab8500_gpadc_driver); 1062 platform_driver_unregister(&ab8500_gpadc_driver);
730} 1063}
731 1064
1065/**
1066 * ab8540_gpadc_get_otp() - returns OTP values
1067 *
1068 */
1069void ab8540_gpadc_get_otp(struct ab8500_gpadc *gpadc,
1070 u16 *vmain_l, u16 *vmain_h, u16 *btemp_l, u16 *btemp_h,
1071 u16 *vbat_l, u16 *vbat_h, u16 *ibat_l, u16 *ibat_h)
1072{
1073 *vmain_l = gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_lo;
1074 *vmain_h = gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi;
1075 *btemp_l = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_lo;
1076 *btemp_h = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_hi;
1077 *vbat_l = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_lo;
1078 *vbat_h = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_hi;
1079 *ibat_l = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_lo;
1080 *ibat_h = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_hi;
1081 return ;
1082}
1083
732subsys_initcall_sync(ab8500_gpadc_init); 1084subsys_initcall_sync(ab8500_gpadc_init);
733module_exit(ab8500_gpadc_exit); 1085module_exit(ab8500_gpadc_exit);
734 1086
735MODULE_LICENSE("GPL v2"); 1087MODULE_LICENSE("GPL v2");
736MODULE_AUTHOR("Arun R Murthy, Daniel Willerud, Johan Palsson"); 1088MODULE_AUTHOR("Arun R Murthy, Daniel Willerud, Johan Palsson,"
1089 "M'boumba Cedric Madianga");
737MODULE_ALIAS("platform:ab8500_gpadc"); 1090MODULE_ALIAS("platform:ab8500_gpadc");
738MODULE_DESCRIPTION("AB8500 GPADC driver"); 1091MODULE_DESCRIPTION("AB8500 GPADC driver");
diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index 108fd86552f0..272479cdb107 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -15,19 +15,30 @@
15#include <linux/mfd/abx500/ab8500.h> 15#include <linux/mfd/abx500/ab8500.h>
16#include <linux/mfd/abx500/ab8500-sysctrl.h> 16#include <linux/mfd/abx500/ab8500-sysctrl.h>
17 17
18/* RtcCtrl bits */
19#define AB8500_ALARM_MIN_LOW 0x08
20#define AB8500_ALARM_MIN_MID 0x09
21#define RTC_CTRL 0x0B
22#define RTC_ALARM_ENABLE 0x4
23
18static struct device *sysctrl_dev; 24static struct device *sysctrl_dev;
19 25
20void ab8500_power_off(void) 26void ab8500_power_off(void)
21{ 27{
22 sigset_t old; 28 sigset_t old;
23 sigset_t all; 29 sigset_t all;
24 static char *pss[] = {"ab8500_ac", "ab8500_usb"}; 30 static char *pss[] = {"ab8500_ac", "pm2301", "ab8500_usb"};
25 int i; 31 int i;
26 bool charger_present = false; 32 bool charger_present = false;
27 union power_supply_propval val; 33 union power_supply_propval val;
28 struct power_supply *psy; 34 struct power_supply *psy;
29 int ret; 35 int ret;
30 36
37 if (sysctrl_dev == NULL) {
38 pr_err("%s: sysctrl not initialized\n", __func__);
39 return;
40 }
41
31 /* 42 /*
32 * If we have a charger connected and we're powering off, 43 * If we have a charger connected and we're powering off,
33 * reboot into charge-only mode. 44 * reboot into charge-only mode.
@@ -74,6 +85,63 @@ shutdown:
74 } 85 }
75} 86}
76 87
88/*
89 * Use the AB WD to reset the platform. It will perform a hard
90 * reset instead of a soft reset. Write the reset reason to
91 * the AB before reset, which can be read upon restart.
92 */
93void ab8500_restart(char mode, const char *cmd)
94{
95 struct ab8500_platform_data *plat;
96 struct ab8500_sysctrl_platform_data *pdata;
97 u16 reason = 0;
98 u8 val;
99
100 if (sysctrl_dev == NULL) {
101 pr_err("%s: sysctrl not initialized\n", __func__);
102 return;
103 }
104
105 plat = dev_get_platdata(sysctrl_dev->parent);
106 pdata = plat->sysctrl;
107 if (pdata->reboot_reason_code)
108 reason = pdata->reboot_reason_code(cmd);
109 else
110 pr_warn("[%s] No reboot reason set. Default reason %d\n",
111 __func__, reason);
112
113 /*
114 * Disable RTC alarm, just a precaution so that no alarm
115 * is running when WD reset is executed.
116 */
117 abx500_get_register_interruptible(sysctrl_dev, AB8500_RTC,
118 RTC_CTRL , &val);
119 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
120 RTC_CTRL , (val & ~RTC_ALARM_ENABLE));
121
122 /*
123 * Android is not using the RTC alarm registers during reboot
124 * so we borrow them for writing the reason of reset
125 */
126
127 /* reason[8 LSB] */
128 val = reason & 0xFF;
129 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
130 AB8500_ALARM_MIN_LOW , val);
131
132 /* reason[8 MSB] */
133 val = (reason>>8) & 0xFF;
134 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
135 AB8500_ALARM_MIN_MID , val);
136
137 /* Setting WD timeout to 0 */
138 ab8500_sysctrl_write(AB8500_MAINWDOGTIMER, 0xFF, 0x0);
139
140 /* Setting the parameters to AB8500 WD*/
141 ab8500_sysctrl_write(AB8500_MAINWDOGCTRL, 0xFF, (AB8500_ENABLE_WD |
142 AB8500_WD_RESTART_ON_EXPIRE | AB8500_KICK_WD));
143}
144
77static inline bool valid_bank(u8 bank) 145static inline bool valid_bank(u8 bank)
78{ 146{
79 return ((bank == AB8500_SYS_CTRL1_BLOCK) || 147 return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
@@ -85,7 +153,7 @@ int ab8500_sysctrl_read(u16 reg, u8 *value)
85 u8 bank; 153 u8 bank;
86 154
87 if (sysctrl_dev == NULL) 155 if (sysctrl_dev == NULL)
88 return -EAGAIN; 156 return -EINVAL;
89 157
90 bank = (reg >> 8); 158 bank = (reg >> 8);
91 if (!valid_bank(bank)) 159 if (!valid_bank(bank))
@@ -101,7 +169,7 @@ int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
101 u8 bank; 169 u8 bank;
102 170
103 if (sysctrl_dev == NULL) 171 if (sysctrl_dev == NULL)
104 return -EAGAIN; 172 return -EINVAL;
105 173
106 bank = (reg >> 8); 174 bank = (reg >> 8);
107 if (!valid_bank(bank)) 175 if (!valid_bank(bank))
@@ -114,28 +182,36 @@ EXPORT_SYMBOL(ab8500_sysctrl_write);
114 182
115static int ab8500_sysctrl_probe(struct platform_device *pdev) 183static int ab8500_sysctrl_probe(struct platform_device *pdev)
116{ 184{
185 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
117 struct ab8500_platform_data *plat; 186 struct ab8500_platform_data *plat;
118 struct ab8500_sysctrl_platform_data *pdata; 187 struct ab8500_sysctrl_platform_data *pdata;
119 188
120 sysctrl_dev = &pdev->dev;
121 plat = dev_get_platdata(pdev->dev.parent); 189 plat = dev_get_platdata(pdev->dev.parent);
190
191 if (!(plat && plat->sysctrl))
192 return -EINVAL;
193
122 if (plat->pm_power_off) 194 if (plat->pm_power_off)
123 pm_power_off = ab8500_power_off; 195 pm_power_off = ab8500_power_off;
124 196
125 pdata = plat->sysctrl; 197 pdata = plat->sysctrl;
126 198
127 if (pdata) { 199 if (pdata) {
128 int ret, i, j; 200 int last, ret, i, j;
201
202 if (is_ab8505(ab8500))
203 last = AB8500_SYSCLKREQ4RFCLKBUF;
204 else
205 last = AB8500_SYSCLKREQ8RFCLKBUF;
129 206
130 for (i = AB8500_SYSCLKREQ1RFCLKBUF; 207 for (i = AB8500_SYSCLKREQ1RFCLKBUF; i <= last; i++) {
131 i <= AB8500_SYSCLKREQ8RFCLKBUF; i++) {
132 j = i - AB8500_SYSCLKREQ1RFCLKBUF; 208 j = i - AB8500_SYSCLKREQ1RFCLKBUF;
133 ret = ab8500_sysctrl_write(i, 0xff, 209 ret = ab8500_sysctrl_write(i, 0xff,
134 pdata->initial_req_buf_config[j]); 210 pdata->initial_req_buf_config[j]);
135 dev_dbg(&pdev->dev, 211 dev_dbg(&pdev->dev,
136 "Setting SysClkReq%dRfClkBuf 0x%X\n", 212 "Setting SysClkReq%dRfClkBuf 0x%X\n",
137 j + 1, 213 j + 1,
138 pdata->initial_req_buf_config[j]); 214 pdata->initial_req_buf_config[j]);
139 if (ret < 0) { 215 if (ret < 0) {
140 dev_err(&pdev->dev, 216 dev_err(&pdev->dev,
141 "unable to set sysClkReq%dRfClkBuf: " 217 "unable to set sysClkReq%dRfClkBuf: "