Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: ab8500-gpadc: Add support for the AB8540

This patch enables the GPADC to work on AB8540 based platforms.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Samuel Ortiz <sameo@linux.intel.com>

Lee Jones e4bffe8d 75932094

+308 -57
+279 -43
drivers/mfd/ab8500-gpadc.c
··· 37 37 #define AB8500_GPADC_AUTODATAL_REG 0x07 38 38 #define AB8500_GPADC_AUTODATAH_REG 0x08 39 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 49 * OTP register offsets ··· 56 49 #define AB8500_GPADC_CAL_5 0x13 57 50 #define AB8500_GPADC_CAL_6 0x14 58 51 #define AB8500_GPADC_CAL_7 0x15 52 + /* New calibration for 8540 */ 53 + #define AB8540_GPADC_OTP4_REG_7 0x38 54 + #define AB8540_GPADC_OTP4_REG_6 0x39 55 + #define AB8540_GPADC_OTP4_REG_5 0x3A 59 56 60 57 /* gpadc constants */ 61 58 #define EN_VINTCORE12 0x04 ··· 78 67 #define GPADC_BUSY 0x01 79 68 #define EN_FALLING 0x10 80 69 #define EN_TRIG_EDGE 0x02 70 + #define EN_VBIAS_XTAL_TEMP 0x02 81 71 82 72 /* GPADC constants from AB8500 spec, UM0836 */ 83 73 #define ADC_RESOLUTION 1024 ··· 97 85 #define ADC_CH_BKBAT_MIN 0 98 86 #define ADC_CH_BKBAT_MAX 3200 99 87 88 + /* GPADC constants from AB8540 spec */ 89 + #define ADC_CH_IBAT_MIN (-6000) /* mA range measured by ADC for ibat*/ 90 + #define ADC_CH_IBAT_MAX 6000 91 + #define ADC_CH_IBAT_MIN_V (-60) /* mV range measured by ADC for ibat*/ 92 + #define ADC_CH_IBAT_MAX_V 60 93 + #define IBAT_VDROP_L (-56) /* mV */ 94 + #define IBAT_VDROP_H 56 95 + 100 96 /* This is used to not lose precision when dividing to get gain and offset */ 101 - #define CALIB_SCALE 1000 97 + #define CALIB_SCALE 1000 98 + /* 99 + * Number of bits shift used to not lose precision 100 + * when dividing to get ibat gain. 101 + */ 102 + #define CALIB_SHIFT_IBAT 20 102 103 103 104 /* Time in ms before disabling regulator */ 104 105 #define GPADC_AUDOSUSPEND_DELAY 1 ··· 122 97 ADC_INPUT_VMAIN = 0, 123 98 ADC_INPUT_BTEMP, 124 99 ADC_INPUT_VBAT, 100 + ADC_INPUT_IBAT, 125 101 NBR_CAL_INPUTS, 126 102 }; 127 103 ··· 133 107 * @offset: Offset of the ADC channel 134 108 */ 135 109 struct adc_cal_data { 136 - u64 gain; 137 - u64 offset; 110 + s64 gain; 111 + s64 offset; 138 112 }; 139 113 140 114 /** ··· 206 180 gpadc->cal_data[ADC_INPUT_VMAIN].offset) / CALIB_SCALE; 207 181 break; 208 182 183 + case XTAL_TEMP: 209 184 case BAT_CTRL: 210 185 case BTEMP_BALL: 211 186 case ACC_DETECT1: ··· 225 198 break; 226 199 227 200 case MAIN_BAT_V: 201 + case VBAT_TRUE_MEAS: 228 202 /* For some reason we don't have calibrated data */ 229 203 if (!gpadc->cal_data[ADC_INPUT_VBAT].gain) { 230 204 res = ADC_CH_VBAT_MIN + (ADC_CH_VBAT_MAX - ··· 267 239 res = ADC_CH_BKBAT_MIN + 268 240 (ADC_CH_BKBAT_MAX - ADC_CH_BKBAT_MIN) * ad_value / 269 241 ADC_RESOLUTION; 242 + break; 243 + 244 + case IBAT_VIRTUAL_CHANNEL: 245 + /* For some reason we don't have calibrated data */ 246 + if (!gpadc->cal_data[ADC_INPUT_IBAT].gain) { 247 + res = ADC_CH_IBAT_MIN + (ADC_CH_IBAT_MAX - 248 + ADC_CH_IBAT_MIN) * ad_value / 249 + ADC_RESOLUTION; 250 + break; 251 + } 252 + /* Here we can use the calibrated data */ 253 + res = (int) (ad_value * gpadc->cal_data[ADC_INPUT_IBAT].gain + 254 + gpadc->cal_data[ADC_INPUT_IBAT].offset) 255 + >> CALIB_SHIFT_IBAT; 270 256 break; 271 257 272 258 default: ··· 346 304 int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 347 305 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type) 348 306 { 307 + int raw_data; 308 + raw_data = ab8500_gpadc_double_read_raw(gpadc, channel, 309 + avg_sample, trig_edge, trig_timer, conv_type, NULL); 310 + return raw_data; 311 + } 312 + 313 + int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 314 + u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type, 315 + int *ibat) 316 + { 349 317 int ret; 350 318 int looplimit = 0; 351 - u8 val, low_data, high_data; 319 + u8 val, low_data, high_data, low_data2, high_data2; 352 320 353 321 if (!gpadc) 354 322 return -ENODEV; ··· 411 359 default: 412 360 val = channel | AVG_16; 413 361 break; 414 - 415 362 } 416 363 417 364 if (conv_type == ADC_HW) ··· 434 383 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 435 384 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 436 385 EN_FALLING, EN_FALLING); 437 - 438 386 } 387 + 439 388 switch (channel) { 440 389 case MAIN_CHARGER_C: 441 390 case USB_CHARGER_C: ··· 452 401 EN_BUF | EN_ICHAR, 453 402 EN_BUF | EN_ICHAR); 454 403 break; 404 + 405 + case XTAL_TEMP: 406 + if (conv_type == ADC_HW) 407 + ret = abx500_mask_and_set_register_interruptible( 408 + gpadc->dev, 409 + AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 410 + EN_BUF | EN_TRIG_EDGE, 411 + EN_BUF | EN_TRIG_EDGE); 412 + else 413 + ret = abx500_mask_and_set_register_interruptible( 414 + gpadc->dev, 415 + AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 416 + EN_BUF , 417 + EN_BUF); 418 + break; 419 + 420 + case VBAT_TRUE_MEAS: 421 + if (conv_type == ADC_HW) 422 + ret = abx500_mask_and_set_register_interruptible( 423 + gpadc->dev, 424 + AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 425 + EN_BUF | EN_TRIG_EDGE, 426 + EN_BUF | EN_TRIG_EDGE); 427 + else 428 + ret = abx500_mask_and_set_register_interruptible( 429 + gpadc->dev, 430 + AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 431 + EN_BUF , 432 + EN_BUF); 433 + break; 434 + 435 + case BAT_CTRL_AND_IBAT: 436 + case VBAT_MEAS_AND_IBAT: 437 + case VBAT_TRUE_MEAS_AND_IBAT: 438 + case BAT_TEMP_AND_IBAT: 439 + if (conv_type == ADC_HW) 440 + ret = abx500_mask_and_set_register_interruptible( 441 + gpadc->dev, 442 + AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 443 + EN_TRIG_EDGE, 444 + EN_TRIG_EDGE); 445 + else 446 + ret = abx500_mask_and_set_register_interruptible( 447 + gpadc->dev, 448 + AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 449 + EN_BUF, 450 + 0); 451 + break; 452 + 455 453 case BTEMP_BALL: 456 454 if (!is_ab8500_2p0_or_earlier(gpadc->parent)) { 457 455 if (conv_type == ADC_HW) ··· 571 471 /* wait for completion of conversion */ 572 472 if (conv_type == ADC_HW) { 573 473 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 574 - 2*HZ)) { 575 - dev_err(gpadc->dev, 576 - "timeout didn't receive" 577 - " hw GPADC conv interrupt\n"); 578 - ret = -EINVAL; 579 - goto out; 474 + 2 * HZ)) { 475 + dev_err(gpadc->dev, 476 + "timeout didn't receive hw GPADC conv interrupt\n"); 477 + ret = -EINVAL; 478 + goto out; 580 479 } 581 480 } else { 582 481 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 583 - msecs_to_jiffies(CONVERSION_TIME))) { 584 - dev_err(gpadc->dev, 585 - "timeout didn't receive" 586 - " sw GPADC conv interrupt\n"); 587 - ret = -EINVAL; 588 - goto out; 482 + msecs_to_jiffies(CONVERSION_TIME))) { 483 + dev_err(gpadc->dev, 484 + "timeout didn't receive sw GPADC conv interrupt\n"); 485 + ret = -EINVAL; 486 + goto out; 589 487 } 590 488 } 591 489 ··· 619 521 dev_err(gpadc->dev, 620 522 "gpadc_conversion: read sw high data failed\n"); 621 523 goto out; 524 + } 525 + } 526 + /* Check if double convertion is required */ 527 + if ((channel == BAT_CTRL_AND_IBAT) || 528 + (channel == VBAT_MEAS_AND_IBAT) || 529 + (channel == VBAT_TRUE_MEAS_AND_IBAT) || 530 + (channel == BAT_TEMP_AND_IBAT)) { 531 + 532 + if (conv_type == ADC_HW) { 533 + /* not supported */ 534 + ret = -ENOTSUPP; 535 + dev_err(gpadc->dev, 536 + "gpadc_conversion: only SW double conversion supported\n"); 537 + goto out; 538 + } else { 539 + /* Read the converted RAW data 2 */ 540 + ret = abx500_get_register_interruptible(gpadc->dev, 541 + AB8500_GPADC, AB8540_GPADC_MANDATA2L_REG, 542 + &low_data2); 543 + if (ret < 0) { 544 + dev_err(gpadc->dev, 545 + "gpadc_conversion: read sw low data 2 failed\n"); 546 + goto out; 547 + } 548 + 549 + ret = abx500_get_register_interruptible(gpadc->dev, 550 + AB8500_GPADC, AB8540_GPADC_MANDATA2H_REG, 551 + &high_data2); 552 + if (ret < 0) { 553 + dev_err(gpadc->dev, 554 + "gpadc_conversion: read sw high data 2 failed\n"); 555 + goto out; 556 + } 557 + if (ibat != NULL) { 558 + *ibat = (high_data2 << 8) | low_data2; 559 + } else { 560 + dev_warn(gpadc->dev, 561 + "gpadc_conversion: ibat not stored\n"); 562 + } 563 + 622 564 } 623 565 } 624 566 ··· 724 586 AB8500_GPADC_CAL_7, 725 587 }; 726 588 589 + static int otp4_cal_regs[] = { 590 + AB8540_GPADC_OTP4_REG_7, 591 + AB8540_GPADC_OTP4_REG_6, 592 + AB8540_GPADC_OTP4_REG_5, 593 + }; 594 + 727 595 static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc) 728 596 { 729 597 int i; 730 598 int ret[ARRAY_SIZE(otp_cal_regs)]; 731 599 u8 gpadc_cal[ARRAY_SIZE(otp_cal_regs)]; 732 - 600 + int ret_otp4[ARRAY_SIZE(otp4_cal_regs)]; 601 + u8 gpadc_otp4[ARRAY_SIZE(otp4_cal_regs)]; 733 602 int vmain_high, vmain_low; 734 603 int btemp_high, btemp_low; 735 604 int vbat_high, vbat_low; 605 + int ibat_high, ibat_low; 606 + s64 V_gain, V_offset, V2A_gain, V2A_offset; 607 + struct ab8500 *ab8500; 608 + 609 + ab8500 = gpadc->parent; 736 610 737 611 /* First we read all OTP registers and store the error code */ 738 612 for (i = 0; i < ARRAY_SIZE(otp_cal_regs); i++) { ··· 764 614 * bt_h/l = btemp_high/low 765 615 * vb_h/l = vbat_high/low 766 616 * 767 - * Data bits: 617 + * Data bits 8500/9540: 768 618 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 769 619 * |.......|.......|.......|.......|.......|.......|.......|....... 770 620 * | | vm_h9 | vm_h8 ··· 782 632 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 | 783 633 * |.......|.......|.......|.......|.......|.......|.......|....... 784 634 * 635 + * Data bits 8540: 636 + * OTP2 637 + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 638 + * |.......|.......|.......|.......|.......|.......|.......|....... 639 + * | 640 + * |.......|.......|.......|.......|.......|.......|.......|....... 641 + * | vm_h9 | vm_h8 | vm_h7 | vm_h6 | vm_h5 | vm_h4 | vm_h3 | vm_h2 642 + * |.......|.......|.......|.......|.......|.......|.......|....... 643 + * | vm_h1 | vm_h0 | vm_l4 | vm_l3 | vm_l2 | vm_l1 | vm_l0 | bt_h9 644 + * |.......|.......|.......|.......|.......|.......|.......|....... 645 + * | bt_h8 | bt_h7 | bt_h6 | bt_h5 | bt_h4 | bt_h3 | bt_h2 | bt_h1 646 + * |.......|.......|.......|.......|.......|.......|.......|....... 647 + * | bt_h0 | bt_l4 | bt_l3 | bt_l2 | bt_l1 | bt_l0 | vb_h9 | vb_h8 648 + * |.......|.......|.......|.......|.......|.......|.......|....... 649 + * | vb_h7 | vb_h6 | vb_h5 | vb_h4 | vb_h3 | vb_h2 | vb_h1 | vb_h0 650 + * |.......|.......|.......|.......|.......|.......|.......|....... 651 + * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 | 652 + * |.......|.......|.......|.......|.......|.......|.......|....... 653 + * 654 + * Data bits 8540: 655 + * OTP4 656 + * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 657 + * |.......|.......|.......|.......|.......|.......|.......|....... 658 + * | | ib_h9 | ib_h8 | ib_h7 659 + * |.......|.......|.......|.......|.......|.......|.......|....... 660 + * | ib_h6 | ib_h5 | ib_h4 | ib_h3 | ib_h2 | ib_h1 | ib_h0 | ib_l5 661 + * |.......|.......|.......|.......|.......|.......|.......|....... 662 + * | ib_l4 | ib_l3 | ib_l2 | ib_l1 | ib_l0 | 663 + * 785 664 * 786 665 * Ideal output ADC codes corresponding to injected input voltages 787 666 * during manufacturing is: ··· 823 644 * vbat_low: Vin = 2380mV / ADC ideal code = 33 824 645 */ 825 646 826 - /* Calculate gain and offset for VMAIN if all reads succeeded */ 827 - if (!(ret[0] < 0 || ret[1] < 0 || ret[2] < 0)) { 828 - vmain_high = (((gpadc_cal[0] & 0x03) << 8) | 829 - ((gpadc_cal[1] & 0x3F) << 2) | 830 - ((gpadc_cal[2] & 0xC0) >> 6)); 831 - 832 - vmain_low = ((gpadc_cal[2] & 0x3E) >> 1); 833 - 834 - gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE * 835 - (19500 - 315) / (vmain_high - vmain_low); 836 - 837 - gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE * 19500 - 838 - (CALIB_SCALE * (19500 - 315) / 839 - (vmain_high - vmain_low)) * vmain_high; 840 - } else { 647 + if (is_ab8540(ab8500)) { 648 + /* Calculate gain and offset for VMAIN if all reads succeeded*/ 649 + if (!(ret[1] < 0 || ret[2] < 0)) { 650 + vmain_high = (((gpadc_cal[1] & 0xFF) << 2) | 651 + ((gpadc_cal[2] & 0xC0) >> 6)); 652 + vmain_low = ((gpadc_cal[2] & 0x3E) >> 1); 653 + gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE * 654 + (19500 - 315) / (vmain_high - vmain_low); 655 + gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE * 656 + 19500 - (CALIB_SCALE * (19500 - 315) / 657 + (vmain_high - vmain_low)) * vmain_high; 658 + } else { 841 659 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0; 842 - } 660 + } 843 661 662 + /* Read IBAT calibration Data */ 663 + for (i = 0; i < ARRAY_SIZE(otp4_cal_regs); i++) { 664 + ret_otp4[i] = abx500_get_register_interruptible( 665 + gpadc->dev, AB8500_OTP_EMUL, 666 + otp4_cal_regs[i], &gpadc_otp4[i]); 667 + if (ret_otp4[i] < 0) 668 + dev_err(gpadc->dev, 669 + "%s: read otp4 reg 0x%02x failed\n", 670 + __func__, otp4_cal_regs[i]); 671 + } 672 + 673 + /* Calculate gain and offset for IBAT if all reads succeeded */ 674 + if (!(ret_otp4[0] < 0 || ret_otp4[1] < 0 || ret_otp4[2] < 0)) { 675 + ibat_high = (((gpadc_otp4[0] & 0x07) << 7) | 676 + ((gpadc_otp4[1] & 0xFE) >> 1)); 677 + ibat_low = (((gpadc_otp4[1] & 0x01) << 5) | 678 + ((gpadc_otp4[2] & 0xF8) >> 3)); 679 + 680 + V_gain = ((IBAT_VDROP_H - IBAT_VDROP_L) 681 + << CALIB_SHIFT_IBAT) / (ibat_high - ibat_low); 682 + 683 + V_offset = (IBAT_VDROP_H << CALIB_SHIFT_IBAT) - 684 + (((IBAT_VDROP_H - IBAT_VDROP_L) << 685 + CALIB_SHIFT_IBAT) / (ibat_high - ibat_low)) 686 + * ibat_high; 687 + /* 688 + * Result obtained is in mV (at a scale factor), 689 + * we need to calculate gain and offset to get mA 690 + */ 691 + V2A_gain = (ADC_CH_IBAT_MAX - ADC_CH_IBAT_MIN)/ 692 + (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V); 693 + V2A_offset = ((ADC_CH_IBAT_MAX_V * ADC_CH_IBAT_MIN - 694 + ADC_CH_IBAT_MAX * ADC_CH_IBAT_MIN_V) 695 + << CALIB_SHIFT_IBAT) 696 + / (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V); 697 + 698 + gpadc->cal_data[ADC_INPUT_IBAT].gain = V_gain * V2A_gain; 699 + gpadc->cal_data[ADC_INPUT_IBAT].offset = V_offset * 700 + V2A_gain + V2A_offset; 701 + } else { 702 + gpadc->cal_data[ADC_INPUT_IBAT].gain = 0; 703 + } 704 + 705 + dev_dbg(gpadc->dev, "IBAT gain %llu offset %llu\n", 706 + gpadc->cal_data[ADC_INPUT_IBAT].gain, 707 + gpadc->cal_data[ADC_INPUT_IBAT].offset); 708 + } else { 709 + /* Calculate gain and offset for VMAIN if all reads succeeded */ 710 + if (!(ret[0] < 0 || ret[1] < 0 || ret[2] < 0)) { 711 + vmain_high = (((gpadc_cal[0] & 0x03) << 8) | 712 + ((gpadc_cal[1] & 0x3F) << 2) | 713 + ((gpadc_cal[2] & 0xC0) >> 6)); 714 + vmain_low = ((gpadc_cal[2] & 0x3E) >> 1); 715 + 716 + gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE * 717 + (19500 - 315) / (vmain_high - vmain_low); 718 + 719 + gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE * 720 + 19500 - (CALIB_SCALE * (19500 - 315) / 721 + (vmain_high - vmain_low)) * vmain_high; 722 + } else { 723 + gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0; 724 + } 725 + } 844 726 /* Calculate gain and offset for BTEMP if all reads succeeded */ 845 727 if (!(ret[2] < 0 || ret[3] < 0 || ret[4] < 0)) { 846 728 btemp_high = (((gpadc_cal[2] & 0x01) << 9) | 847 - (gpadc_cal[3] << 1) | 848 - ((gpadc_cal[4] & 0x80) >> 7)); 849 - 729 + (gpadc_cal[3] << 1) | ((gpadc_cal[4] & 0x80) >> 7)); 850 730 btemp_low = ((gpadc_cal[4] & 0x7C) >> 2); 851 731 852 732 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 853 733 CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low); 854 - 855 734 gpadc->cal_data[ADC_INPUT_BTEMP].offset = CALIB_SCALE * 1300 - 856 - (CALIB_SCALE * (1300 - 21) / 857 - (btemp_high - btemp_low)) * btemp_high; 735 + (CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low)) 736 + * btemp_high; 858 737 } else { 859 738 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 0; 860 739 } ··· 924 687 925 688 gpadc->cal_data[ADC_INPUT_VBAT].gain = CALIB_SCALE * 926 689 (4700 - 2380) / (vbat_high - vbat_low); 927 - 928 690 gpadc->cal_data[ADC_INPUT_VBAT].offset = CALIB_SCALE * 4700 - 929 691 (CALIB_SCALE * (4700 - 2380) / 930 692 (vbat_high - vbat_low)) * vbat_high;
+29 -14
include/linux/mfd/abx500/ab8500-gpadc.h
··· 12 12 13 13 /* GPADC source: From datasheet(ADCSwSel[4:0] in GPADCCtrl2 14 14 * and ADCHwSel[4:0] in GPADCCtrl3 ) */ 15 - #define BAT_CTRL 0x01 16 - #define BTEMP_BALL 0x02 17 - #define MAIN_CHARGER_V 0x03 18 - #define ACC_DETECT1 0x04 19 - #define ACC_DETECT2 0x05 20 - #define ADC_AUX1 0x06 21 - #define ADC_AUX2 0x07 22 - #define MAIN_BAT_V 0x08 23 - #define VBUS_V 0x09 24 - #define MAIN_CHARGER_C 0x0A 25 - #define USB_CHARGER_C 0x0B 26 - #define BK_BAT_V 0x0C 27 - #define DIE_TEMP 0x0D 15 + #define BAT_CTRL 0x01 16 + #define BTEMP_BALL 0x02 17 + #define MAIN_CHARGER_V 0x03 18 + #define ACC_DETECT1 0x04 19 + #define ACC_DETECT2 0x05 20 + #define ADC_AUX1 0x06 21 + #define ADC_AUX2 0x07 22 + #define MAIN_BAT_V 0x08 23 + #define VBUS_V 0x09 24 + #define MAIN_CHARGER_C 0x0A 25 + #define USB_CHARGER_C 0x0B 26 + #define BK_BAT_V 0x0C 27 + #define DIE_TEMP 0x0D 28 + #define USB_ID 0x0E 29 + #define XTAL_TEMP 0x12 30 + #define VBAT_TRUE_MEAS 0x13 31 + #define BAT_CTRL_AND_IBAT 0x1C 32 + #define VBAT_MEAS_AND_IBAT 0x1D 33 + #define VBAT_TRUE_MEAS_AND_IBAT 0x1E 34 + #define BAT_TEMP_AND_IBAT 0x1F 35 + 36 + /* Virtual channel used only for ibat convertion to ampere 37 + * Battery current conversion (ibat) cannot be requested as a single conversion 38 + * but it is always in combination with other input requests 39 + */ 40 + #define IBAT_VIRTUAL_CHANNEL 0xFF 28 41 29 42 #define SAMPLE_1 1 30 43 #define SAMPLE_4 4 ··· 49 36 /* Arbitrary ADC conversion type constants */ 50 37 #define ADC_SW 0 51 38 #define ADC_HW 1 52 - 53 39 54 40 struct ab8500_gpadc; 55 41 ··· 63 51 64 52 int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 65 53 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type); 54 + int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 55 + u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type, 56 + int *ibat); 66 57 int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, 67 58 u8 channel, int ad_value); 68 59