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

Merge branch 'for-mfd' of git://git.linaro.org/people/ljones/linux-3.0-ux500 into for-next

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

+1394 -74
+2
drivers/mfd/ab8500-core.c
··· 320 320 .mask_and_set_register = ab8500_mask_and_set_register, 321 321 .event_registers_startup_state_get = NULL, 322 322 .startup_irq_enabled = NULL, 323 + .dump_all_banks = ab8500_dump_all_banks, 323 324 }; 324 325 325 326 static void ab8500_irq_lock(struct irq_data *data) ··· 522 521 int virq = ab8500_irq_get_virq(ab8500, line); 523 522 524 523 handle_nested_irq(virq); 524 + ab8500_debug_register_interrupt(line); 525 525 value &= ~(1 << bit); 526 526 527 527 } while (value);
+1194 -55
drivers/mfd/ab8500-debugfs.c
··· 4 4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson. 5 5 * License Terms: GNU General Public License v2 6 6 */ 7 + /* 8 + * AB8500 register access 9 + * ====================== 10 + * 11 + * read: 12 + * # echo BANK > <debugfs>/ab8500/register-bank 13 + * # echo ADDR > <debugfs>/ab8500/register-address 14 + * # cat <debugfs>/ab8500/register-value 15 + * 16 + * write: 17 + * # echo BANK > <debugfs>/ab8500/register-bank 18 + * # echo ADDR > <debugfs>/ab8500/register-address 19 + * # echo VALUE > <debugfs>/ab8500/register-value 20 + * 21 + * read all registers from a bank: 22 + * # echo BANK > <debugfs>/ab8500/register-bank 23 + * # cat <debugfs>/ab8500/all-bank-register 24 + * 25 + * BANK target AB8500 register bank 26 + * ADDR target AB8500 register address 27 + * VALUE decimal or 0x-prefixed hexadecimal 28 + * 29 + * 30 + * User Space notification on AB8500 IRQ 31 + * ===================================== 32 + * 33 + * Allows user space entity to be notified when target AB8500 IRQ occurs. 34 + * When subscribed, a sysfs entry is created in ab8500.i2c platform device. 35 + * One can pool this file to get target IRQ occurence information. 36 + * 37 + * subscribe to an AB8500 IRQ: 38 + * # echo IRQ > <debugfs>/ab8500/irq-subscribe 39 + * 40 + * unsubscribe from an AB8500 IRQ: 41 + * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe 42 + * 43 + * 44 + * AB8500 register formated read/write access 45 + * ========================================== 46 + * 47 + * Read: read data, data>>SHIFT, data&=MASK, output data 48 + * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE 49 + * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data 50 + * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98] 51 + * 52 + * Usage: 53 + * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg 54 + * 55 + * CMD read read access 56 + * write write access 57 + * 58 + * BANK target reg bank 59 + * ADDRESS target reg address 60 + * VALUE (write) value to be updated 61 + * 62 + * OPTIONS 63 + * -d|-dec (read) output in decimal 64 + * -h|-hexa (read) output in 0x-hexa (default) 65 + * -l|-w|-b 32bit (default), 16bit or 8bit reg access 66 + * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF) 67 + * -s|-shift SHIFT bit shift value (read:left, write:right) 68 + * -o|-offset OFFSET address offset to add to ADDRESS value 69 + * 70 + * Warning: bit shift operation is applied to bit-mask. 71 + * Warning: bit shift direction depends on read or right command. 72 + */ 7 73 8 74 #include <linux/seq_file.h> 9 75 #include <linux/uaccess.h> ··· 77 11 #include <linux/module.h> 78 12 #include <linux/debugfs.h> 79 13 #include <linux/platform_device.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/kobject.h> 16 + #include <linux/slab.h> 80 17 81 18 #include <linux/mfd/abx500.h> 82 - #include <linux/mfd/abx500/ab8500.h> 19 + #include <linux/mfd/abx500/ab8500-gpadc.h> 20 + 21 + #ifdef CONFIG_DEBUG_FS 22 + #include <linux/string.h> 23 + #include <linux/ctype.h> 24 + #endif 83 25 84 26 static u32 debug_bank; 85 27 static u32 debug_address; 28 + 29 + static int irq_first; 30 + static int irq_last; 31 + static u32 *irq_count; 32 + static int num_irqs; 33 + 34 + static struct device_attribute **dev_attr; 35 + static char **event_name; 86 36 87 37 /** 88 38 * struct ab8500_reg_range ··· 124 42 const struct ab8500_reg_range *range; 125 43 }; 126 44 45 + /* hwreg- "mask" and "shift" entries ressources */ 46 + struct hwreg_cfg { 47 + u32 bank; /* target bank */ 48 + u32 addr; /* target address */ 49 + uint fmt; /* format */ 50 + uint mask; /* read/write mask, applied before any bit shift */ 51 + int shift; /* bit shift (read:right shift, write:left shift */ 52 + }; 53 + /* fmt bit #0: 0=hexa, 1=dec */ 54 + #define REG_FMT_DEC(c) ((c)->fmt & 0x1) 55 + #define REG_FMT_HEX(c) (!REG_FMT_DEC(c)) 56 + 57 + static struct hwreg_cfg hwreg_cfg = { 58 + .addr = 0, /* default: invalid phys addr */ 59 + .fmt = 0, /* default: 32bit access, hex output */ 60 + .mask = 0xFFFFFFFF, /* default: no mask */ 61 + .shift = 0, /* default: no bit shift */ 62 + }; 63 + 127 64 #define AB8500_NAME_STRING "ab8500" 128 - #define AB8500_NUM_BANKS 22 65 + #define AB8500_ADC_NAME_STRING "gpadc" 66 + #define AB8500_NUM_BANKS 24 129 67 130 68 #define AB8500_REV_REG 0x80 131 69 132 70 static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { 133 71 [0x0] = { 134 72 .num_ranges = 0, 135 - .range = 0, 73 + .range = NULL, 136 74 }, 137 75 [AB8500_SYS_CTRL1_BLOCK] = { 138 76 .num_ranges = 3, ··· 317 215 }, 318 216 }, 319 217 [AB8500_CHARGER] = { 320 - .num_ranges = 8, 218 + .num_ranges = 9, 321 219 .range = (struct ab8500_reg_range[]) { 322 220 { 323 221 .first = 0x00, ··· 351 249 .first = 0xC0, 352 250 .last = 0xC2, 353 251 }, 252 + { 253 + .first = 0xf5, 254 + .last = 0xf6, 255 + }, 354 256 }, 355 257 }, 356 258 [AB8500_GAS_GAUGE] = { ··· 371 265 { 372 266 .first = 0x10, 373 267 .last = 0x14, 268 + }, 269 + }, 270 + }, 271 + [AB8500_DEVELOPMENT] = { 272 + .num_ranges = 1, 273 + .range = (struct ab8500_reg_range[]) { 274 + { 275 + .first = 0x00, 276 + .last = 0x00, 277 + }, 278 + }, 279 + }, 280 + [AB8500_DEBUG] = { 281 + .num_ranges = 1, 282 + .range = (struct ab8500_reg_range[]) { 283 + { 284 + .first = 0x05, 285 + .last = 0x07, 374 286 }, 375 287 }, 376 288 }, ··· 478 354 }, 479 355 }; 480 356 481 - static int ab8500_registers_print(struct seq_file *s, void *p) 357 + static irqreturn_t ab8500_debug_handler(int irq, void *data) 482 358 { 483 - struct device *dev = s->private; 359 + char buf[16]; 360 + struct kobject *kobj = (struct kobject *)data; 361 + unsigned int irq_abb = irq - irq_first; 362 + 363 + if (irq_abb < num_irqs) 364 + irq_count[irq_abb]++; 365 + /* 366 + * This makes it possible to use poll for events (POLLPRI | POLLERR) 367 + * from userspace on sysfs file named <irq-nr> 368 + */ 369 + sprintf(buf, "%d", irq); 370 + sysfs_notify(kobj, NULL, buf); 371 + 372 + return IRQ_HANDLED; 373 + } 374 + 375 + /* Prints to seq_file or log_buf */ 376 + static int ab8500_registers_print(struct device *dev, u32 bank, 377 + struct seq_file *s) 378 + { 484 379 unsigned int i; 485 - u32 bank = debug_bank; 486 380 487 - seq_printf(s, AB8500_NAME_STRING " register values:\n"); 488 - 489 - seq_printf(s, " bank %u:\n", bank); 490 381 for (i = 0; i < debug_ranges[bank].num_ranges; i++) { 491 382 u32 reg; 492 383 ··· 518 379 return err; 519 380 } 520 381 521 - err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, 522 - reg, value); 523 - if (err < 0) { 524 - dev_err(dev, "seq_printf overflow\n"); 525 - /* Error is not returned here since 526 - * the output is wanted in any case */ 527 - return 0; 382 + if (s) { 383 + err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", 384 + bank, reg, value); 385 + if (err < 0) { 386 + dev_err(dev, 387 + "seq_printf overflow bank=%d reg=%d\n", 388 + bank, reg); 389 + /* Error is not returned here since 390 + * the output is wanted in any case */ 391 + return 0; 392 + } 393 + } else { 394 + printk(KERN_INFO" [%u/0x%02X]: 0x%02X\n", bank, 395 + reg, value); 528 396 } 529 397 } 530 398 } 531 399 return 0; 532 400 } 533 401 402 + static int ab8500_print_bank_registers(struct seq_file *s, void *p) 403 + { 404 + struct device *dev = s->private; 405 + u32 bank = debug_bank; 406 + 407 + seq_printf(s, AB8500_NAME_STRING " register values:\n"); 408 + 409 + seq_printf(s, " bank %u:\n", bank); 410 + 411 + ab8500_registers_print(dev, bank, s); 412 + return 0; 413 + } 414 + 534 415 static int ab8500_registers_open(struct inode *inode, struct file *file) 535 416 { 536 - return single_open(file, ab8500_registers_print, inode->i_private); 417 + return single_open(file, ab8500_print_bank_registers, inode->i_private); 537 418 } 538 419 539 420 static const struct file_operations ab8500_registers_fops = { 540 421 .open = ab8500_registers_open, 422 + .read = seq_read, 423 + .llseek = seq_lseek, 424 + .release = single_release, 425 + .owner = THIS_MODULE, 426 + }; 427 + 428 + static int ab8500_print_all_banks(struct seq_file *s, void *p) 429 + { 430 + struct device *dev = s->private; 431 + unsigned int i; 432 + int err; 433 + 434 + seq_printf(s, AB8500_NAME_STRING " register values:\n"); 435 + 436 + for (i = 1; i < AB8500_NUM_BANKS; i++) { 437 + err = seq_printf(s, " bank %u:\n", i); 438 + if (err < 0) 439 + dev_err(dev, "seq_printf overflow, bank=%d\n", i); 440 + 441 + ab8500_registers_print(dev, i, s); 442 + } 443 + return 0; 444 + } 445 + 446 + /* Dump registers to kernel log */ 447 + void ab8500_dump_all_banks(struct device *dev) 448 + { 449 + unsigned int i; 450 + 451 + printk(KERN_INFO"ab8500 register values:\n"); 452 + 453 + for (i = 1; i < AB8500_NUM_BANKS; i++) { 454 + printk(KERN_INFO" bank %u:\n", i); 455 + ab8500_registers_print(dev, i, NULL); 456 + } 457 + } 458 + 459 + static int ab8500_all_banks_open(struct inode *inode, struct file *file) 460 + { 461 + struct seq_file *s; 462 + int err; 463 + 464 + err = single_open(file, ab8500_print_all_banks, inode->i_private); 465 + if (!err) { 466 + /* Default buf size in seq_read is not enough */ 467 + s = (struct seq_file *)file->private_data; 468 + s->size = (PAGE_SIZE * 2); 469 + s->buf = kmalloc(s->size, GFP_KERNEL); 470 + if (!s->buf) { 471 + single_release(inode, file); 472 + err = -ENOMEM; 473 + } 474 + } 475 + return err; 476 + } 477 + 478 + static const struct file_operations ab8500_all_banks_fops = { 479 + .open = ab8500_all_banks_open, 541 480 .read = seq_read, 542 481 .llseek = seq_lseek, 543 482 .release = single_release, ··· 736 519 return count; 737 520 } 738 521 522 + /* 523 + * Interrupt status 524 + */ 525 + static u32 num_interrupts[AB8500_MAX_NR_IRQS]; 526 + static int num_interrupt_lines; 527 + 528 + void ab8500_debug_register_interrupt(int line) 529 + { 530 + if (line < num_interrupt_lines) 531 + num_interrupts[line]++; 532 + } 533 + 534 + static int ab8500_interrupts_print(struct seq_file *s, void *p) 535 + { 536 + int line; 537 + 538 + seq_printf(s, "irq: number of\n"); 539 + 540 + for (line = 0; line < num_interrupt_lines; line++) 541 + seq_printf(s, "%3i: %6i\n", line, num_interrupts[line]); 542 + 543 + return 0; 544 + } 545 + 546 + static int ab8500_interrupts_open(struct inode *inode, struct file *file) 547 + { 548 + return single_open(file, ab8500_interrupts_print, inode->i_private); 549 + } 550 + 551 + /* 552 + * - HWREG DB8500 formated routines 553 + */ 554 + static int ab8500_hwreg_print(struct seq_file *s, void *d) 555 + { 556 + struct device *dev = s->private; 557 + int ret; 558 + u8 regvalue; 559 + 560 + ret = abx500_get_register_interruptible(dev, 561 + (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue); 562 + if (ret < 0) { 563 + dev_err(dev, "abx500_get_reg fail %d, %d\n", 564 + ret, __LINE__); 565 + return -EINVAL; 566 + } 567 + 568 + if (hwreg_cfg.shift >= 0) 569 + regvalue >>= hwreg_cfg.shift; 570 + else 571 + regvalue <<= -hwreg_cfg.shift; 572 + regvalue &= hwreg_cfg.mask; 573 + 574 + if (REG_FMT_DEC(&hwreg_cfg)) 575 + seq_printf(s, "%d\n", regvalue); 576 + else 577 + seq_printf(s, "0x%02X\n", regvalue); 578 + return 0; 579 + } 580 + 581 + static int ab8500_hwreg_open(struct inode *inode, struct file *file) 582 + { 583 + return single_open(file, ab8500_hwreg_print, inode->i_private); 584 + } 585 + 586 + static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p) 587 + { 588 + int bat_ctrl_raw; 589 + int bat_ctrl_convert; 590 + struct ab8500_gpadc *gpadc; 591 + 592 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 593 + bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL); 594 + bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, 595 + BAT_CTRL, bat_ctrl_raw); 596 + 597 + return seq_printf(s, "%d,0x%X\n", 598 + bat_ctrl_convert, bat_ctrl_raw); 599 + } 600 + 601 + static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file) 602 + { 603 + return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private); 604 + } 605 + 606 + static const struct file_operations ab8500_gpadc_bat_ctrl_fops = { 607 + .open = ab8500_gpadc_bat_ctrl_open, 608 + .read = seq_read, 609 + .llseek = seq_lseek, 610 + .release = single_release, 611 + .owner = THIS_MODULE, 612 + }; 613 + 614 + static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p) 615 + { 616 + int btemp_ball_raw; 617 + int btemp_ball_convert; 618 + struct ab8500_gpadc *gpadc; 619 + 620 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 621 + btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL); 622 + btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, 623 + btemp_ball_raw); 624 + 625 + return seq_printf(s, 626 + "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw); 627 + } 628 + 629 + static int ab8500_gpadc_btemp_ball_open(struct inode *inode, 630 + struct file *file) 631 + { 632 + return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private); 633 + } 634 + 635 + static const struct file_operations ab8500_gpadc_btemp_ball_fops = { 636 + .open = ab8500_gpadc_btemp_ball_open, 637 + .read = seq_read, 638 + .llseek = seq_lseek, 639 + .release = single_release, 640 + .owner = THIS_MODULE, 641 + }; 642 + 643 + static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p) 644 + { 645 + int main_charger_v_raw; 646 + int main_charger_v_convert; 647 + struct ab8500_gpadc *gpadc; 648 + 649 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 650 + main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V); 651 + main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, 652 + MAIN_CHARGER_V, main_charger_v_raw); 653 + 654 + return seq_printf(s, "%d,0x%X\n", 655 + main_charger_v_convert, main_charger_v_raw); 656 + } 657 + 658 + static int ab8500_gpadc_main_charger_v_open(struct inode *inode, 659 + struct file *file) 660 + { 661 + return single_open(file, ab8500_gpadc_main_charger_v_print, 662 + inode->i_private); 663 + } 664 + 665 + static const struct file_operations ab8500_gpadc_main_charger_v_fops = { 666 + .open = ab8500_gpadc_main_charger_v_open, 667 + .read = seq_read, 668 + .llseek = seq_lseek, 669 + .release = single_release, 670 + .owner = THIS_MODULE, 671 + }; 672 + 673 + static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p) 674 + { 675 + int acc_detect1_raw; 676 + int acc_detect1_convert; 677 + struct ab8500_gpadc *gpadc; 678 + 679 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 680 + acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1); 681 + acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1, 682 + acc_detect1_raw); 683 + 684 + return seq_printf(s, "%d,0x%X\n", 685 + acc_detect1_convert, acc_detect1_raw); 686 + } 687 + 688 + static int ab8500_gpadc_acc_detect1_open(struct inode *inode, 689 + struct file *file) 690 + { 691 + return single_open(file, ab8500_gpadc_acc_detect1_print, 692 + inode->i_private); 693 + } 694 + 695 + static const struct file_operations ab8500_gpadc_acc_detect1_fops = { 696 + .open = ab8500_gpadc_acc_detect1_open, 697 + .read = seq_read, 698 + .llseek = seq_lseek, 699 + .release = single_release, 700 + .owner = THIS_MODULE, 701 + }; 702 + 703 + static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p) 704 + { 705 + int acc_detect2_raw; 706 + int acc_detect2_convert; 707 + struct ab8500_gpadc *gpadc; 708 + 709 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 710 + acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2); 711 + acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc, 712 + ACC_DETECT2, acc_detect2_raw); 713 + 714 + return seq_printf(s, "%d,0x%X\n", 715 + acc_detect2_convert, acc_detect2_raw); 716 + } 717 + 718 + static int ab8500_gpadc_acc_detect2_open(struct inode *inode, 719 + struct file *file) 720 + { 721 + return single_open(file, ab8500_gpadc_acc_detect2_print, 722 + inode->i_private); 723 + } 724 + 725 + static const struct file_operations ab8500_gpadc_acc_detect2_fops = { 726 + .open = ab8500_gpadc_acc_detect2_open, 727 + .read = seq_read, 728 + .llseek = seq_lseek, 729 + .release = single_release, 730 + .owner = THIS_MODULE, 731 + }; 732 + 733 + static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p) 734 + { 735 + int aux1_raw; 736 + int aux1_convert; 737 + struct ab8500_gpadc *gpadc; 738 + 739 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 740 + aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1); 741 + aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1, 742 + aux1_raw); 743 + 744 + return seq_printf(s, "%d,0x%X\n", 745 + aux1_convert, aux1_raw); 746 + } 747 + 748 + static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file) 749 + { 750 + return single_open(file, ab8500_gpadc_aux1_print, inode->i_private); 751 + } 752 + 753 + static const struct file_operations ab8500_gpadc_aux1_fops = { 754 + .open = ab8500_gpadc_aux1_open, 755 + .read = seq_read, 756 + .llseek = seq_lseek, 757 + .release = single_release, 758 + .owner = THIS_MODULE, 759 + }; 760 + 761 + static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p) 762 + { 763 + int aux2_raw; 764 + int aux2_convert; 765 + struct ab8500_gpadc *gpadc; 766 + 767 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 768 + aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2); 769 + aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2, 770 + aux2_raw); 771 + 772 + return seq_printf(s, "%d,0x%X\n", 773 + aux2_convert, aux2_raw); 774 + } 775 + 776 + static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file) 777 + { 778 + return single_open(file, ab8500_gpadc_aux2_print, inode->i_private); 779 + } 780 + 781 + static const struct file_operations ab8500_gpadc_aux2_fops = { 782 + .open = ab8500_gpadc_aux2_open, 783 + .read = seq_read, 784 + .llseek = seq_lseek, 785 + .release = single_release, 786 + .owner = THIS_MODULE, 787 + }; 788 + 789 + static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p) 790 + { 791 + int main_bat_v_raw; 792 + int main_bat_v_convert; 793 + struct ab8500_gpadc *gpadc; 794 + 795 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 796 + main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V); 797 + main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, 798 + main_bat_v_raw); 799 + 800 + return seq_printf(s, "%d,0x%X\n", 801 + main_bat_v_convert, main_bat_v_raw); 802 + } 803 + 804 + static int ab8500_gpadc_main_bat_v_open(struct inode *inode, 805 + struct file *file) 806 + { 807 + return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private); 808 + } 809 + 810 + static const struct file_operations ab8500_gpadc_main_bat_v_fops = { 811 + .open = ab8500_gpadc_main_bat_v_open, 812 + .read = seq_read, 813 + .llseek = seq_lseek, 814 + .release = single_release, 815 + .owner = THIS_MODULE, 816 + }; 817 + 818 + static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p) 819 + { 820 + int vbus_v_raw; 821 + int vbus_v_convert; 822 + struct ab8500_gpadc *gpadc; 823 + 824 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 825 + vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V); 826 + vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V, 827 + vbus_v_raw); 828 + 829 + return seq_printf(s, "%d,0x%X\n", 830 + vbus_v_convert, vbus_v_raw); 831 + } 832 + 833 + static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file) 834 + { 835 + return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private); 836 + } 837 + 838 + static const struct file_operations ab8500_gpadc_vbus_v_fops = { 839 + .open = ab8500_gpadc_vbus_v_open, 840 + .read = seq_read, 841 + .llseek = seq_lseek, 842 + .release = single_release, 843 + .owner = THIS_MODULE, 844 + }; 845 + 846 + static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p) 847 + { 848 + int main_charger_c_raw; 849 + int main_charger_c_convert; 850 + struct ab8500_gpadc *gpadc; 851 + 852 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 853 + main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C); 854 + main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, 855 + MAIN_CHARGER_C, main_charger_c_raw); 856 + 857 + return seq_printf(s, "%d,0x%X\n", 858 + main_charger_c_convert, main_charger_c_raw); 859 + } 860 + 861 + static int ab8500_gpadc_main_charger_c_open(struct inode *inode, 862 + struct file *file) 863 + { 864 + return single_open(file, ab8500_gpadc_main_charger_c_print, 865 + inode->i_private); 866 + } 867 + 868 + static const struct file_operations ab8500_gpadc_main_charger_c_fops = { 869 + .open = ab8500_gpadc_main_charger_c_open, 870 + .read = seq_read, 871 + .llseek = seq_lseek, 872 + .release = single_release, 873 + .owner = THIS_MODULE, 874 + }; 875 + 876 + static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p) 877 + { 878 + int usb_charger_c_raw; 879 + int usb_charger_c_convert; 880 + struct ab8500_gpadc *gpadc; 881 + 882 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 883 + usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C); 884 + usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, 885 + USB_CHARGER_C, usb_charger_c_raw); 886 + 887 + return seq_printf(s, "%d,0x%X\n", 888 + usb_charger_c_convert, usb_charger_c_raw); 889 + } 890 + 891 + static int ab8500_gpadc_usb_charger_c_open(struct inode *inode, 892 + struct file *file) 893 + { 894 + return single_open(file, ab8500_gpadc_usb_charger_c_print, 895 + inode->i_private); 896 + } 897 + 898 + static const struct file_operations ab8500_gpadc_usb_charger_c_fops = { 899 + .open = ab8500_gpadc_usb_charger_c_open, 900 + .read = seq_read, 901 + .llseek = seq_lseek, 902 + .release = single_release, 903 + .owner = THIS_MODULE, 904 + }; 905 + 906 + static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p) 907 + { 908 + int bk_bat_v_raw; 909 + int bk_bat_v_convert; 910 + struct ab8500_gpadc *gpadc; 911 + 912 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 913 + bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V); 914 + bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, 915 + BK_BAT_V, bk_bat_v_raw); 916 + 917 + return seq_printf(s, "%d,0x%X\n", 918 + bk_bat_v_convert, bk_bat_v_raw); 919 + } 920 + 921 + static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file) 922 + { 923 + return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private); 924 + } 925 + 926 + static const struct file_operations ab8500_gpadc_bk_bat_v_fops = { 927 + .open = ab8500_gpadc_bk_bat_v_open, 928 + .read = seq_read, 929 + .llseek = seq_lseek, 930 + .release = single_release, 931 + .owner = THIS_MODULE, 932 + }; 933 + 934 + static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p) 935 + { 936 + int die_temp_raw; 937 + int die_temp_convert; 938 + struct ab8500_gpadc *gpadc; 939 + 940 + gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 941 + die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP); 942 + die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP, 943 + die_temp_raw); 944 + 945 + return seq_printf(s, "%d,0x%X\n", 946 + die_temp_convert, die_temp_raw); 947 + } 948 + 949 + static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file) 950 + { 951 + return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private); 952 + } 953 + 954 + static const struct file_operations ab8500_gpadc_die_temp_fops = { 955 + .open = ab8500_gpadc_die_temp_open, 956 + .read = seq_read, 957 + .llseek = seq_lseek, 958 + .release = single_release, 959 + .owner = THIS_MODULE, 960 + }; 961 + 962 + /* 963 + * return length of an ASCII numerical value, 0 is string is not a 964 + * numerical value. 965 + * string shall start at value 1st char. 966 + * string can be tailed with \0 or space or newline chars only. 967 + * value can be decimal or hexadecimal (prefixed 0x or 0X). 968 + */ 969 + static int strval_len(char *b) 970 + { 971 + char *s = b; 972 + if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) { 973 + s += 2; 974 + for (; *s && (*s != ' ') && (*s != '\n'); s++) { 975 + if (!isxdigit(*s)) 976 + return 0; 977 + } 978 + } else { 979 + if (*s == '-') 980 + s++; 981 + for (; *s && (*s != ' ') && (*s != '\n'); s++) { 982 + if (!isdigit(*s)) 983 + return 0; 984 + } 985 + } 986 + return (int) (s-b); 987 + } 988 + 989 + /* 990 + * parse hwreg input data. 991 + * update global hwreg_cfg only if input data syntax is ok. 992 + */ 993 + static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg, 994 + struct device *dev) 995 + { 996 + uint write, val = 0; 997 + u8 regvalue; 998 + int ret; 999 + struct hwreg_cfg loc = { 1000 + .bank = 0, /* default: invalid phys addr */ 1001 + .addr = 0, /* default: invalid phys addr */ 1002 + .fmt = 0, /* default: 32bit access, hex output */ 1003 + .mask = 0xFFFFFFFF, /* default: no mask */ 1004 + .shift = 0, /* default: no bit shift */ 1005 + }; 1006 + 1007 + /* read or write ? */ 1008 + if (!strncmp(b, "read ", 5)) { 1009 + write = 0; 1010 + b += 5; 1011 + } else if (!strncmp(b, "write ", 6)) { 1012 + write = 1; 1013 + b += 6; 1014 + } else 1015 + return -EINVAL; 1016 + 1017 + /* OPTIONS -l|-w|-b -s -m -o */ 1018 + while ((*b == ' ') || (*b == '-')) { 1019 + if (*(b-1) != ' ') { 1020 + b++; 1021 + continue; 1022 + } 1023 + if ((!strncmp(b, "-d ", 3)) || 1024 + (!strncmp(b, "-dec ", 5))) { 1025 + b += (*(b+2) == ' ') ? 3 : 5; 1026 + loc.fmt |= (1<<0); 1027 + } else if ((!strncmp(b, "-h ", 3)) || 1028 + (!strncmp(b, "-hex ", 5))) { 1029 + b += (*(b+2) == ' ') ? 3 : 5; 1030 + loc.fmt &= ~(1<<0); 1031 + } else if ((!strncmp(b, "-m ", 3)) || 1032 + (!strncmp(b, "-mask ", 6))) { 1033 + b += (*(b+2) == ' ') ? 3 : 6; 1034 + if (strval_len(b) == 0) 1035 + return -EINVAL; 1036 + loc.mask = simple_strtoul(b, &b, 0); 1037 + } else if ((!strncmp(b, "-s ", 3)) || 1038 + (!strncmp(b, "-shift ", 7))) { 1039 + b += (*(b+2) == ' ') ? 3 : 7; 1040 + if (strval_len(b) == 0) 1041 + return -EINVAL; 1042 + loc.shift = simple_strtol(b, &b, 0); 1043 + } else { 1044 + return -EINVAL; 1045 + } 1046 + } 1047 + /* get arg BANK and ADDRESS */ 1048 + if (strval_len(b) == 0) 1049 + return -EINVAL; 1050 + loc.bank = simple_strtoul(b, &b, 0); 1051 + while (*b == ' ') 1052 + b++; 1053 + if (strval_len(b) == 0) 1054 + return -EINVAL; 1055 + loc.addr = simple_strtoul(b, &b, 0); 1056 + 1057 + if (write) { 1058 + while (*b == ' ') 1059 + b++; 1060 + if (strval_len(b) == 0) 1061 + return -EINVAL; 1062 + val = simple_strtoul(b, &b, 0); 1063 + } 1064 + 1065 + /* args are ok, update target cfg (mainly for read) */ 1066 + *cfg = loc; 1067 + 1068 + #ifdef ABB_HWREG_DEBUG 1069 + pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d" 1070 + "value=0x%X\n", (write) ? "write" : "read", 1071 + REG_FMT_DEC(cfg) ? "decimal" : "hexa", 1072 + cfg->addr, cfg->mask, cfg->shift, val); 1073 + #endif 1074 + 1075 + if (!write) 1076 + return 0; 1077 + 1078 + ret = abx500_get_register_interruptible(dev, 1079 + (u8)cfg->bank, (u8)cfg->addr, &regvalue); 1080 + if (ret < 0) { 1081 + dev_err(dev, "abx500_get_reg fail %d, %d\n", 1082 + ret, __LINE__); 1083 + return -EINVAL; 1084 + } 1085 + 1086 + if (cfg->shift >= 0) { 1087 + regvalue &= ~(cfg->mask << (cfg->shift)); 1088 + val = (val & cfg->mask) << (cfg->shift); 1089 + } else { 1090 + regvalue &= ~(cfg->mask >> (-cfg->shift)); 1091 + val = (val & cfg->mask) >> (-cfg->shift); 1092 + } 1093 + val = val | regvalue; 1094 + 1095 + ret = abx500_set_register_interruptible(dev, 1096 + (u8)cfg->bank, (u8)cfg->addr, (u8)val); 1097 + if (ret < 0) { 1098 + pr_err("abx500_set_reg failed %d, %d", ret, __LINE__); 1099 + return -EINVAL; 1100 + } 1101 + 1102 + return 0; 1103 + } 1104 + 1105 + static ssize_t ab8500_hwreg_write(struct file *file, 1106 + const char __user *user_buf, size_t count, loff_t *ppos) 1107 + { 1108 + struct device *dev = ((struct seq_file *)(file->private_data))->private; 1109 + char buf[128]; 1110 + int buf_size, ret; 1111 + 1112 + /* Get userspace string and assure termination */ 1113 + buf_size = min(count, (sizeof(buf)-1)); 1114 + if (copy_from_user(buf, user_buf, buf_size)) 1115 + return -EFAULT; 1116 + buf[buf_size] = 0; 1117 + 1118 + /* get args and process */ 1119 + ret = hwreg_common_write(buf, &hwreg_cfg, dev); 1120 + return (ret) ? ret : buf_size; 1121 + } 1122 + 1123 + /* 1124 + * - irq subscribe/unsubscribe stuff 1125 + */ 1126 + static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p) 1127 + { 1128 + seq_printf(s, "%d\n", irq_first); 1129 + 1130 + return 0; 1131 + } 1132 + 1133 + static int ab8500_subscribe_unsubscribe_open(struct inode *inode, 1134 + struct file *file) 1135 + { 1136 + return single_open(file, ab8500_subscribe_unsubscribe_print, 1137 + inode->i_private); 1138 + } 1139 + 1140 + /* 1141 + * Userspace should use poll() on this file. When an event occur 1142 + * the blocking poll will be released. 1143 + */ 1144 + static ssize_t show_irq(struct device *dev, 1145 + struct device_attribute *attr, char *buf) 1146 + { 1147 + unsigned long name; 1148 + unsigned int irq_index; 1149 + int err; 1150 + 1151 + err = strict_strtoul(attr->attr.name, 0, &name); 1152 + if (err) 1153 + return err; 1154 + 1155 + irq_index = name - irq_first; 1156 + if (irq_index >= num_irqs) 1157 + return -EINVAL; 1158 + else 1159 + return sprintf(buf, "%u\n", irq_count[irq_index]); 1160 + } 1161 + 1162 + static ssize_t ab8500_subscribe_write(struct file *file, 1163 + const char __user *user_buf, 1164 + size_t count, loff_t *ppos) 1165 + { 1166 + struct device *dev = ((struct seq_file *)(file->private_data))->private; 1167 + char buf[32]; 1168 + int buf_size; 1169 + unsigned long user_val; 1170 + int err; 1171 + unsigned int irq_index; 1172 + 1173 + /* Get userspace string and assure termination */ 1174 + buf_size = min(count, (sizeof(buf)-1)); 1175 + if (copy_from_user(buf, user_buf, buf_size)) 1176 + return -EFAULT; 1177 + buf[buf_size] = 0; 1178 + 1179 + err = strict_strtoul(buf, 0, &user_val); 1180 + if (err) 1181 + return -EINVAL; 1182 + if (user_val < irq_first) { 1183 + dev_err(dev, "debugfs error input < %d\n", irq_first); 1184 + return -EINVAL; 1185 + } 1186 + if (user_val > irq_last) { 1187 + dev_err(dev, "debugfs error input > %d\n", irq_last); 1188 + return -EINVAL; 1189 + } 1190 + 1191 + irq_index = user_val - irq_first; 1192 + if (irq_index >= num_irqs) 1193 + return -EINVAL; 1194 + 1195 + /* 1196 + * This will create a sysfs file named <irq-nr> which userspace can 1197 + * use to select or poll and get the AB8500 events 1198 + */ 1199 + dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), 1200 + GFP_KERNEL); 1201 + event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); 1202 + sprintf(event_name[irq_index], "%lu", user_val); 1203 + dev_attr[irq_index]->show = show_irq; 1204 + dev_attr[irq_index]->store = NULL; 1205 + dev_attr[irq_index]->attr.name = event_name[irq_index]; 1206 + dev_attr[irq_index]->attr.mode = S_IRUGO; 1207 + err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr); 1208 + if (err < 0) { 1209 + printk(KERN_ERR "sysfs_create_file failed %d\n", err); 1210 + return err; 1211 + } 1212 + 1213 + err = request_threaded_irq(user_val, NULL, ab8500_debug_handler, 1214 + IRQF_SHARED | IRQF_NO_SUSPEND, 1215 + "ab8500-debug", &dev->kobj); 1216 + if (err < 0) { 1217 + printk(KERN_ERR "request_threaded_irq failed %d, %lu\n", 1218 + err, user_val); 1219 + sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); 1220 + return err; 1221 + } 1222 + 1223 + return buf_size; 1224 + } 1225 + 1226 + static ssize_t ab8500_unsubscribe_write(struct file *file, 1227 + const char __user *user_buf, 1228 + size_t count, loff_t *ppos) 1229 + { 1230 + struct device *dev = ((struct seq_file *)(file->private_data))->private; 1231 + char buf[32]; 1232 + int buf_size; 1233 + unsigned long user_val; 1234 + int err; 1235 + unsigned int irq_index; 1236 + 1237 + /* Get userspace string and assure termination */ 1238 + buf_size = min(count, (sizeof(buf)-1)); 1239 + if (copy_from_user(buf, user_buf, buf_size)) 1240 + return -EFAULT; 1241 + buf[buf_size] = 0; 1242 + 1243 + err = strict_strtoul(buf, 0, &user_val); 1244 + if (err) 1245 + return -EINVAL; 1246 + if (user_val < irq_first) { 1247 + dev_err(dev, "debugfs error input < %d\n", irq_first); 1248 + return -EINVAL; 1249 + } 1250 + if (user_val > irq_last) { 1251 + dev_err(dev, "debugfs error input > %d\n", irq_last); 1252 + return -EINVAL; 1253 + } 1254 + 1255 + irq_index = user_val - irq_first; 1256 + if (irq_index >= num_irqs) 1257 + return -EINVAL; 1258 + 1259 + /* Set irq count to 0 when unsubscribe */ 1260 + irq_count[irq_index] = 0; 1261 + 1262 + if (dev_attr[irq_index]) 1263 + sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); 1264 + 1265 + 1266 + free_irq(user_val, &dev->kobj); 1267 + kfree(event_name[irq_index]); 1268 + kfree(dev_attr[irq_index]); 1269 + 1270 + return buf_size; 1271 + } 1272 + 1273 + /* 1274 + * - several deubgfs nodes fops 1275 + */ 1276 + 739 1277 static const struct file_operations ab8500_bank_fops = { 740 1278 .open = ab8500_bank_open, 741 1279 .write = ab8500_bank_write, ··· 1518 546 .owner = THIS_MODULE, 1519 547 }; 1520 548 549 + static const struct file_operations ab8500_interrupts_fops = { 550 + .open = ab8500_interrupts_open, 551 + .read = seq_read, 552 + .llseek = seq_lseek, 553 + .release = single_release, 554 + .owner = THIS_MODULE, 555 + }; 556 + 557 + static const struct file_operations ab8500_subscribe_fops = { 558 + .open = ab8500_subscribe_unsubscribe_open, 559 + .write = ab8500_subscribe_write, 560 + .read = seq_read, 561 + .llseek = seq_lseek, 562 + .release = single_release, 563 + .owner = THIS_MODULE, 564 + }; 565 + 566 + static const struct file_operations ab8500_unsubscribe_fops = { 567 + .open = ab8500_subscribe_unsubscribe_open, 568 + .write = ab8500_unsubscribe_write, 569 + .read = seq_read, 570 + .llseek = seq_lseek, 571 + .release = single_release, 572 + .owner = THIS_MODULE, 573 + }; 574 + 575 + static const struct file_operations ab8500_hwreg_fops = { 576 + .open = ab8500_hwreg_open, 577 + .write = ab8500_hwreg_write, 578 + .read = seq_read, 579 + .llseek = seq_lseek, 580 + .release = single_release, 581 + .owner = THIS_MODULE, 582 + }; 583 + 1521 584 static struct dentry *ab8500_dir; 1522 - static struct dentry *ab8500_reg_file; 1523 - static struct dentry *ab8500_bank_file; 1524 - static struct dentry *ab8500_address_file; 1525 - static struct dentry *ab8500_val_file; 585 + static struct dentry *ab8500_gpadc_dir; 1526 586 1527 587 static int ab8500_debug_probe(struct platform_device *plf) 1528 588 { 589 + struct dentry *file; 590 + int ret = -ENOMEM; 591 + struct ab8500 *ab8500; 1529 592 debug_bank = AB8500_MISC; 1530 593 debug_address = AB8500_REV_REG & 0x00FF; 1531 594 595 + ab8500 = dev_get_drvdata(plf->dev.parent); 596 + num_irqs = ab8500->mask_size; 597 + 598 + irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL); 599 + if (!irq_count) 600 + return -ENOMEM; 601 + 602 + dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL); 603 + if (!dev_attr) 604 + goto out_freeirq_count; 605 + 606 + event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL); 607 + if (!event_name) 608 + goto out_freedev_attr; 609 + 610 + irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); 611 + if (irq_first < 0) { 612 + dev_err(&plf->dev, "First irq not found, err %d\n", 613 + irq_first); 614 + ret = irq_first; 615 + goto out_freeevent_name; 616 + } 617 + 618 + irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); 619 + if (irq_last < 0) { 620 + dev_err(&plf->dev, "Last irq not found, err %d\n", 621 + irq_last); 622 + ret = irq_last; 623 + goto out_freeevent_name; 624 + } 625 + 1532 626 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); 1533 627 if (!ab8500_dir) 1534 - goto exit_no_debugfs; 628 + goto err; 1535 629 1536 - ab8500_reg_file = debugfs_create_file("all-bank-registers", 1537 - S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops); 1538 - if (!ab8500_reg_file) 1539 - goto exit_destroy_dir; 630 + ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING, 631 + ab8500_dir); 632 + if (!ab8500_gpadc_dir) 633 + goto err; 1540 634 1541 - ab8500_bank_file = debugfs_create_file("register-bank", 1542 - (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops); 1543 - if (!ab8500_bank_file) 1544 - goto exit_destroy_reg; 635 + file = debugfs_create_file("all-bank-registers", S_IRUGO, 636 + ab8500_dir, &plf->dev, &ab8500_registers_fops); 637 + if (!file) 638 + goto err; 1545 639 1546 - ab8500_address_file = debugfs_create_file("register-address", 1547 - (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, 1548 - &ab8500_address_fops); 1549 - if (!ab8500_address_file) 1550 - goto exit_destroy_bank; 640 + file = debugfs_create_file("all-banks", S_IRUGO, 641 + ab8500_dir, &plf->dev, &ab8500_all_banks_fops); 642 + if (!file) 643 + goto err; 1551 644 1552 - ab8500_val_file = debugfs_create_file("register-value", 1553 - (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops); 1554 - if (!ab8500_val_file) 1555 - goto exit_destroy_address; 645 + file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), 646 + ab8500_dir, &plf->dev, &ab8500_bank_fops); 647 + if (!file) 648 + goto err; 649 + 650 + file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR), 651 + ab8500_dir, &plf->dev, &ab8500_address_fops); 652 + if (!file) 653 + goto err; 654 + 655 + file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR), 656 + ab8500_dir, &plf->dev, &ab8500_val_fops); 657 + if (!file) 658 + goto err; 659 + 660 + file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR), 661 + ab8500_dir, &plf->dev, &ab8500_subscribe_fops); 662 + if (!file) 663 + goto err; 664 + 665 + if (is_ab8500(ab8500)) 666 + num_interrupt_lines = AB8500_NR_IRQS; 667 + else if (is_ab8505(ab8500)) 668 + num_interrupt_lines = AB8505_NR_IRQS; 669 + else if (is_ab9540(ab8500)) 670 + num_interrupt_lines = AB9540_NR_IRQS; 671 + 672 + file = debugfs_create_file("interrupts", (S_IRUGO), 673 + ab8500_dir, &plf->dev, &ab8500_interrupts_fops); 674 + if (!file) 675 + goto err; 676 + 677 + file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR), 678 + ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops); 679 + if (!file) 680 + goto err; 681 + 682 + file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR), 683 + ab8500_dir, &plf->dev, &ab8500_hwreg_fops); 684 + if (!file) 685 + goto err; 686 + 687 + file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR), 688 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops); 689 + if (!file) 690 + goto err; 691 + 692 + file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR), 693 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops); 694 + if (!file) 695 + goto err; 696 + 697 + file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR), 698 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops); 699 + if (!file) 700 + goto err; 701 + 702 + file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR), 703 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops); 704 + if (!file) 705 + goto err; 706 + 707 + file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR), 708 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops); 709 + if (!file) 710 + goto err; 711 + 712 + file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR), 713 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops); 714 + if (!file) 715 + goto err; 716 + 717 + file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR), 718 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops); 719 + if (!file) 720 + goto err; 721 + 722 + file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR), 723 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops); 724 + if (!file) 725 + goto err; 726 + 727 + file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR), 728 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops); 729 + if (!file) 730 + goto err; 731 + 732 + file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR), 733 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops); 734 + if (!file) 735 + goto err; 736 + 737 + file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR), 738 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops); 739 + if (!file) 740 + goto err; 741 + 742 + file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR), 743 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops); 744 + if (!file) 745 + goto err; 746 + 747 + file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR), 748 + ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops); 749 + if (!file) 750 + goto err; 1556 751 1557 752 return 0; 1558 753 1559 - exit_destroy_address: 1560 - debugfs_remove(ab8500_address_file); 1561 - exit_destroy_bank: 1562 - debugfs_remove(ab8500_bank_file); 1563 - exit_destroy_reg: 1564 - debugfs_remove(ab8500_reg_file); 1565 - exit_destroy_dir: 1566 - debugfs_remove(ab8500_dir); 1567 - exit_no_debugfs: 754 + err: 755 + if (ab8500_dir) 756 + debugfs_remove_recursive(ab8500_dir); 1568 757 dev_err(&plf->dev, "failed to create debugfs entries.\n"); 1569 - return -ENOMEM; 758 + out_freeevent_name: 759 + kfree(event_name); 760 + out_freedev_attr: 761 + kfree(dev_attr); 762 + out_freeirq_count: 763 + kfree(irq_count); 764 + 765 + return ret; 1570 766 } 1571 767 1572 768 static int ab8500_debug_remove(struct platform_device *plf) 1573 769 { 1574 - debugfs_remove(ab8500_val_file); 1575 - debugfs_remove(ab8500_address_file); 1576 - debugfs_remove(ab8500_bank_file); 1577 - debugfs_remove(ab8500_reg_file); 1578 - debugfs_remove(ab8500_dir); 770 + debugfs_remove_recursive(ab8500_dir); 771 + kfree(event_name); 772 + kfree(dev_attr); 773 + kfree(irq_count); 1579 774 1580 775 return 0; 1581 776 }
+71 -19
drivers/mfd/ab8500-gpadc.c
··· 12 12 #include <linux/interrupt.h> 13 13 #include <linux/spinlock.h> 14 14 #include <linux/delay.h> 15 + #include <linux/pm_runtime.h> 15 16 #include <linux/platform_device.h> 16 17 #include <linux/completion.h> 17 18 #include <linux/regulator/consumer.h> ··· 83 82 /* This is used to not lose precision when dividing to get gain and offset */ 84 83 #define CALIB_SCALE 1000 85 84 85 + /* Time in ms before disabling regulator */ 86 + #define GPADC_AUDOSUSPEND_DELAY 1 87 + 88 + #define CONVERSION_TIME 500 /* ms */ 89 + 86 90 enum cal_channels { 87 91 ADC_INPUT_VMAIN = 0, 88 92 ADC_INPUT_BTEMP, ··· 108 102 109 103 /** 110 104 * struct ab8500_gpadc - AB8500 GPADC device information 111 - * @chip_id ABB chip id 112 105 * @dev: pointer to the struct device 113 106 * @node: a list of AB8500 GPADCs, hence prepared for 114 107 reentrance 108 + * @parent: pointer to the struct ab8500 115 109 * @ab8500_gpadc_complete: pointer to the struct completion, to indicate 116 110 * the completion of gpadc conversion 117 111 * @ab8500_gpadc_lock: structure of type mutex ··· 120 114 * @cal_data array of ADC calibration data structs 121 115 */ 122 116 struct ab8500_gpadc { 123 - u8 chip_id; 124 117 struct device *dev; 125 118 struct list_head node; 119 + struct ab8500 *parent; 126 120 struct completion ab8500_gpadc_complete; 127 121 struct mutex ab8500_gpadc_lock; 128 122 struct regulator *regu; ··· 288 282 return -ENODEV; 289 283 290 284 mutex_lock(&gpadc->ab8500_gpadc_lock); 285 + 291 286 /* Enable VTVout LDO this is required for GPADC */ 292 - regulator_enable(gpadc->regu); 287 + pm_runtime_get_sync(gpadc->dev); 293 288 294 289 /* Check if ADC is not busy, lock and proceed */ 295 290 do { ··· 339 332 EN_BUF | EN_ICHAR); 340 333 break; 341 334 case BTEMP_BALL: 342 - if (gpadc->chip_id >= AB8500_CUT3P0) { 335 + if (!is_ab8500_2p0_or_earlier(gpadc->parent)) { 343 336 /* Turn on btemp pull-up on ABB 3.0 */ 344 337 ret = abx500_mask_and_set_register_interruptible( 345 338 gpadc->dev, ··· 351 344 * Delay might be needed for ABB8500 cut 3.0, if not, remove 352 345 * when hardware will be available 353 346 */ 354 - msleep(1); 347 + usleep_range(1000, 1000); 355 348 break; 356 349 } 357 350 /* Intentional fallthrough */ ··· 374 367 goto out; 375 368 } 376 369 /* wait for completion of conversion */ 377 - if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 2*HZ)) { 370 + if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 371 + msecs_to_jiffies(CONVERSION_TIME))) { 378 372 dev_err(gpadc->dev, 379 373 "timeout: didn't receive GPADC conversion interrupt\n"); 380 374 ret = -EINVAL; ··· 405 397 dev_err(gpadc->dev, "gpadc_conversion: disable gpadc failed\n"); 406 398 goto out; 407 399 } 408 - /* Disable VTVout LDO this is required for GPADC */ 409 - regulator_disable(gpadc->regu); 400 + 401 + pm_runtime_mark_last_busy(gpadc->dev); 402 + pm_runtime_put_autosuspend(gpadc->dev); 403 + 410 404 mutex_unlock(&gpadc->ab8500_gpadc_lock); 411 405 412 406 return (high_data << 8) | low_data; ··· 422 412 */ 423 413 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 424 414 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 425 - regulator_disable(gpadc->regu); 415 + 416 + pm_runtime_put(gpadc->dev); 417 + 426 418 mutex_unlock(&gpadc->ab8500_gpadc_lock); 427 419 dev_err(gpadc->dev, 428 420 "gpadc_conversion: Failed to AD convert channel %d\n", channel); ··· 583 571 gpadc->cal_data[ADC_INPUT_VBAT].offset); 584 572 } 585 573 574 + static int ab8500_gpadc_runtime_suspend(struct device *dev) 575 + { 576 + struct ab8500_gpadc *gpadc = dev_get_drvdata(dev); 577 + 578 + regulator_disable(gpadc->regu); 579 + return 0; 580 + } 581 + 582 + static int ab8500_gpadc_runtime_resume(struct device *dev) 583 + { 584 + struct ab8500_gpadc *gpadc = dev_get_drvdata(dev); 585 + 586 + regulator_enable(gpadc->regu); 587 + return 0; 588 + } 589 + 590 + static int ab8500_gpadc_runtime_idle(struct device *dev) 591 + { 592 + pm_runtime_suspend(dev); 593 + return 0; 594 + } 595 + 586 596 static int ab8500_gpadc_probe(struct platform_device *pdev) 587 597 { 588 598 int ret = 0; ··· 625 591 } 626 592 627 593 gpadc->dev = &pdev->dev; 594 + gpadc->parent = dev_get_drvdata(pdev->dev.parent); 628 595 mutex_init(&gpadc->ab8500_gpadc_lock); 629 596 630 597 /* Initialize completion used to notify completion of conversion */ ··· 642 607 goto fail; 643 608 } 644 609 645 - /* Get Chip ID of the ABB ASIC */ 646 - ret = abx500_get_chip_id(gpadc->dev); 647 - if (ret < 0) { 648 - dev_err(gpadc->dev, "failed to get chip ID\n"); 649 - goto fail_irq; 650 - } 651 - gpadc->chip_id = (u8) ret; 652 - 653 610 /* VTVout LDO used to power up ab8500-GPADC */ 654 611 gpadc->regu = regulator_get(&pdev->dev, "vddadc"); 655 612 if (IS_ERR(gpadc->regu)) { ··· 649 622 dev_err(gpadc->dev, "failed to get vtvout LDO\n"); 650 623 goto fail_irq; 651 624 } 625 + 626 + platform_set_drvdata(pdev, gpadc); 627 + 628 + regulator_enable(gpadc->regu); 629 + 630 + pm_runtime_set_autosuspend_delay(gpadc->dev, GPADC_AUDOSUSPEND_DELAY); 631 + pm_runtime_use_autosuspend(gpadc->dev); 632 + pm_runtime_set_active(gpadc->dev); 633 + pm_runtime_enable(gpadc->dev); 634 + 652 635 ab8500_gpadc_read_calibration_data(gpadc); 653 636 list_add_tail(&gpadc->node, &ab8500_gpadc_list); 654 637 dev_dbg(gpadc->dev, "probe success\n"); ··· 679 642 list_del(&gpadc->node); 680 643 /* remove interrupt - completion of Sw ADC conversion */ 681 644 free_irq(gpadc->irq, gpadc); 682 - /* disable VTVout LDO that is being used by GPADC */ 683 - regulator_put(gpadc->regu); 645 + 646 + pm_runtime_get_sync(gpadc->dev); 647 + pm_runtime_disable(gpadc->dev); 648 + 649 + regulator_disable(gpadc->regu); 650 + 651 + pm_runtime_set_suspended(gpadc->dev); 652 + 653 + pm_runtime_put_noidle(gpadc->dev); 654 + 684 655 kfree(gpadc); 685 656 gpadc = NULL; 686 657 return 0; 687 658 } 659 + 660 + static const struct dev_pm_ops ab8500_gpadc_pm_ops = { 661 + SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend, 662 + ab8500_gpadc_runtime_resume, 663 + ab8500_gpadc_runtime_idle) 664 + }; 688 665 689 666 static struct platform_driver ab8500_gpadc_driver = { 690 667 .probe = ab8500_gpadc_probe, ··· 706 655 .driver = { 707 656 .name = "ab8500-gpadc", 708 657 .owner = THIS_MODULE, 658 + .pm = &ab8500_gpadc_pm_ops, 709 659 }, 710 660 }; 711 661
+92
drivers/mfd/ab8500-sysctrl.c
··· 7 7 #include <linux/err.h> 8 8 #include <linux/module.h> 9 9 #include <linux/platform_device.h> 10 + #include <linux/pm.h> 11 + #include <linux/reboot.h> 12 + #include <linux/signal.h> 13 + #include <linux/power_supply.h> 10 14 #include <linux/mfd/abx500.h> 11 15 #include <linux/mfd/abx500/ab8500.h> 12 16 #include <linux/mfd/abx500/ab8500-sysctrl.h> 13 17 14 18 static struct device *sysctrl_dev; 19 + 20 + void ab8500_power_off(void) 21 + { 22 + sigset_t old; 23 + sigset_t all; 24 + static char *pss[] = {"ab8500_ac", "ab8500_usb"}; 25 + int i; 26 + bool charger_present = false; 27 + union power_supply_propval val; 28 + struct power_supply *psy; 29 + int ret; 30 + 31 + /* 32 + * If we have a charger connected and we're powering off, 33 + * reboot into charge-only mode. 34 + */ 35 + 36 + for (i = 0; i < ARRAY_SIZE(pss); i++) { 37 + psy = power_supply_get_by_name(pss[i]); 38 + if (!psy) 39 + continue; 40 + 41 + ret = psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val); 42 + 43 + if (!ret && val.intval) { 44 + charger_present = true; 45 + break; 46 + } 47 + } 48 + 49 + if (!charger_present) 50 + goto shutdown; 51 + 52 + /* Check if battery is known */ 53 + psy = power_supply_get_by_name("ab8500_btemp"); 54 + if (psy) { 55 + ret = psy->get_property(psy, POWER_SUPPLY_PROP_TECHNOLOGY, 56 + &val); 57 + if (!ret && val.intval != POWER_SUPPLY_TECHNOLOGY_UNKNOWN) { 58 + printk(KERN_INFO 59 + "Charger \"%s\" is connected with known battery." 60 + " Rebooting.\n", 61 + pss[i]); 62 + machine_restart("charging"); 63 + } 64 + } 65 + 66 + shutdown: 67 + sigfillset(&all); 68 + 69 + if (!sigprocmask(SIG_BLOCK, &all, &old)) { 70 + (void)ab8500_sysctrl_set(AB8500_STW4500CTRL1, 71 + AB8500_STW4500CTRL1_SWOFF | 72 + AB8500_STW4500CTRL1_SWRESET4500N); 73 + (void)sigprocmask(SIG_SETMASK, &old, NULL); 74 + } 75 + } 15 76 16 77 static inline bool valid_bank(u8 bank) 17 78 { ··· 94 33 return abx500_get_register_interruptible(sysctrl_dev, bank, 95 34 (u8)(reg & 0xFF), value); 96 35 } 36 + EXPORT_SYMBOL(ab8500_sysctrl_read); 97 37 98 38 int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value) 99 39 { ··· 110 48 return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank, 111 49 (u8)(reg & 0xFF), mask, value); 112 50 } 51 + EXPORT_SYMBOL(ab8500_sysctrl_write); 113 52 114 53 static int ab8500_sysctrl_probe(struct platform_device *pdev) 115 54 { 55 + struct ab8500_platform_data *plat; 56 + struct ab8500_sysctrl_platform_data *pdata; 57 + 116 58 sysctrl_dev = &pdev->dev; 59 + plat = dev_get_platdata(pdev->dev.parent); 60 + if (plat->pm_power_off) 61 + pm_power_off = ab8500_power_off; 62 + 63 + pdata = plat->sysctrl; 64 + 65 + if (pdata) { 66 + int ret, i, j; 67 + 68 + for (i = AB8500_SYSCLKREQ1RFCLKBUF; 69 + i <= AB8500_SYSCLKREQ8RFCLKBUF; i++) { 70 + j = i - AB8500_SYSCLKREQ1RFCLKBUF; 71 + ret = ab8500_sysctrl_write(i, 0xff, 72 + pdata->initial_req_buf_config[j]); 73 + dev_dbg(&pdev->dev, 74 + "Setting SysClkReq%dRfClkBuf 0x%X\n", 75 + j + 1, 76 + pdata->initial_req_buf_config[j]); 77 + if (ret < 0) { 78 + dev_err(&pdev->dev, 79 + "unable to set sysClkReq%dRfClkBuf: " 80 + "%d\n", j + 1, ret); 81 + } 82 + } 83 + } 84 + 117 85 return 0; 118 86 } 119 87
+16
drivers/mfd/abx500-core.c
··· 153 153 } 154 154 EXPORT_SYMBOL(abx500_startup_irq_enabled); 155 155 156 + void abx500_dump_all_banks(void) 157 + { 158 + struct abx500_ops *ops; 159 + struct device dummy_child = {0}; 160 + struct abx500_device_entry *dev_entry; 161 + 162 + list_for_each_entry(dev_entry, &abx500_list, list) { 163 + dummy_child.parent = dev_entry->dev; 164 + ops = &dev_entry->ops; 165 + 166 + if ((ops != NULL) && (ops->dump_all_banks != NULL)) 167 + ops->dump_all_banks(&dummy_child); 168 + } 169 + } 170 + EXPORT_SYMBOL(abx500_dump_all_banks); 171 + 156 172 MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>"); 157 173 MODULE_DESCRIPTION("ABX500 core driver"); 158 174 MODULE_LICENSE("GPL");
+2
include/linux/mfd/abx500.h
··· 306 306 int abx500_get_chip_id(struct device *dev); 307 307 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event); 308 308 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq); 309 + void abx500_dump_all_banks(void); 309 310 310 311 struct abx500_ops { 311 312 int (*get_chip_id) (struct device *); ··· 317 316 int (*mask_and_set_register) (struct device *, u8, u8, u8, u8); 318 317 int (*event_registers_startup_state_get) (struct device *, u8 *); 319 318 int (*startup_irq_enabled) (struct device *, unsigned int); 319 + void (*dump_all_banks) (struct device *); 320 320 }; 321 321 322 322 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
+5
include/linux/mfd/abx500/ab8500-sysctrl.h
··· 37 37 return ab8500_sysctrl_write(reg, bits, 0); 38 38 } 39 39 40 + /* Configuration data for SysClkReq1RfClkBuf - SysClkReq8RfClkBuf */ 41 + struct ab8500_sysctrl_platform_data { 42 + u8 initial_req_buf_config[8]; 43 + }; 44 + 40 45 /* Registers */ 41 46 #define AB8500_TURNONSTATUS 0x100 42 47 #define AB8500_RESETSTATUS 0x101
+12
include/linux/mfd/abx500/ab8500.h
··· 270 270 struct regulator_init_data; 271 271 struct ab8500_gpio_platform_data; 272 272 struct ab8500_codec_platform_data; 273 + struct ab8500_sysctrl_platform_data; 273 274 274 275 /** 275 276 * struct ab8500_platform_data - AB8500 platform data 276 277 * @irq_base: start of AB8500 IRQs, AB8500_NR_IRQS will be used 278 + * @pm_power_off: Should machine pm power off hook be registered or not 277 279 * @init: board-specific initialization after detection of ab8500 278 280 * @num_regulator_reg_init: number of regulator init registers 279 281 * @regulator_reg_init: regulator init registers ··· 284 282 */ 285 283 struct ab8500_platform_data { 286 284 int irq_base; 285 + bool pm_power_off; 287 286 void (*init) (struct ab8500 *); 288 287 int num_regulator_reg_init; 289 288 struct ab8500_regulator_reg_init *regulator_reg_init; ··· 292 289 struct regulator_init_data *regulator; 293 290 struct ab8500_gpio_platform_data *gpio; 294 291 struct ab8500_codec_platform_data *codec; 292 + struct ab8500_sysctrl_platform_data *sysctrl; 295 293 }; 296 294 297 295 extern int ab8500_init(struct ab8500 *ab8500, ··· 344 340 { 345 341 return (is_ab8500(ab) && (ab->chip_id == AB8500_CUT2P0)); 346 342 } 343 + 344 + #ifdef CONFIG_AB8500_DEBUG 345 + void ab8500_dump_all_banks(struct device *dev); 346 + void ab8500_debug_register_interrupt(int line); 347 + #else 348 + static inline void ab8500_dump_all_banks(struct device *dev) {} 349 + static inline void ab8500_debug_register_interrupt(int line) {} 350 + #endif 347 351 348 352 #endif /* MFD_AB8500_H */