linux/drivers/extcon/extcon-gpio.c
<<
n va1.1/spa 1.1/form 1.1a n va1. href="../linux+v3.7.4/drivers/extcon/extcon-gpio.c">n va1.1img src="../.static/gfx/right.png" alt=">>">n 1/spa n 1spa class="lxr_search">n va ="+search" method="post" onsubmit="return do_search(this);">n va1.1input typ hidden" nam navtarget" on> ">n va1.1input typ text" nam search" id search">n va1.1buttptityp submit">Searchn va1.Prefs 1.1/a>n 1/spa va1. .1/div va1. .1form ac > ="ajax+*" method="post" onsubmit="return false;">n 1input typ hidden" nam ajax_lookup" id ajax_lookup" on> ">nva1. .1/form nva1. .1div class="headingbottpm">
1div id file_contents"
. .11/a>1spa
 class="comment">/*1/spa
  . .21/a>1spa
 class="comment"> *  drivers/extcon/extcon_gpio.c1/spa
  . .31/a>1spa
 class="comment"> *1/spa
  . .41/a>1spa
 class="comment"> *  Single-state GPIO extcon driver based on extcon class1/spa
  . .51/a>1spa
 class="comment"> *1/spa
  . .61/a>1spa
 class="comment"> * Copyright (C) 2008 Google, Inc.1/spa
  . .71/a>1spa
 class="comment"> * Author: Mike Lockwood <lockwood@android.com>1/spa
  . .81/a>1spa
 class="comment"> *1/spa
  . .91/a>1spa
 class="comment"> * Modified by MyungJoo Ham <myungjoo.ham@samsung.com> to support extcon1/spa
  . .9"
a>1spa
 class="comment"> * (originally switch class is supported)1/spa
  . 111/a>1spa
 class="comment"> *1/spa
  . 121/a>1spa
 class="comment"> * This software is licensed under the terms of the GNU General Public1/spa
  . 131/a>1spa
 class="comment"> * License versopti2, as published by the Free Software Founda  >
, and1/spa
  . 141/a>1spa
 class="comment"> * may be copied, distributed, and modified under those terms.1/spa
  . 151/a>1spa
 class="comment"> *1/spa
  . 161/a>1spa
 class="comment"> * This program is distributed in the hope that it will be useful,1/spa
  . 171/a>1spa
 class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of1/spa
  . 181/a>1spa
 class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the1/spa
  . 191/a>1spa
 class="comment"> * GNU General Public License for more details.1/spa
  . 29"
a>1spa
 class="comment"> *1/spa
  . 211/a>1spa
 class="comment">*/1/spa
  . 221/a> . 231/a>#include <linux/module.h1/a>> . 241/a>#include <linux/kernel.h1/a>> . 251/a>#include <linux/init.h1/a>> . 261/a>#include <linux/interrupt.h1/a>> . 271/a>#include <linux/platform_device.h1/a>> . 281/a>#include <linux/slab.h1/a>> . 291/a>#include <linux/workqueue.h1/a>> . 301/a>#include <linux/gpio.h1/a>> . 311/a>#include <linux/extcon.h1/a>> . 321/a>#include <linux/extcon/extcon_gpio.h1/a>> . 331/a> . 341/a>struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a> { . 351/a>        struct.1a href="+code=extcon_dev" class="sref">extcon_dev1/a> 1a href="+code=edev" class="sref">edev1/a>; . 361/a>        unsigned 1a href="+code=gpio" class="sref">gpio1/a>; . 371/a>        const char *1a href="+code=state_on" class="sref">state_on1/a>; . 381/a>        const char *1a href="+code=state_off" class="sref">state_off1/a>; . 391/a>        int 1a href="+code=irq" class="sref">irq1/a>; . 401/a>        struct.1a href="+code=delayed_work" class="sref">delayed_work1/a> 1a href="+code=work" class="sref">work1/a>; . 411/a>        unsigned long.1a href="+code=debounce_jiffies" class="sref">debounce_jiffies1/a>; . 421/a>}; . 431/a> . 441/a>static void 1a href="+code=gpio_extcon_work" class="sref">gpio_extcon_work1/a>(struct.1a href="+code=work_struct" class="sref">work_struct1/a> *1a href="+code=work" class="sref">work1/a>) . 451/a>{ . 461/a>        int 1a href="+code=state" class="sref">state1/a>; . 471/a>        struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a> *1a href="+code=da a" class="sref">da a1/a> = . 481/a>                1a href="+code=container_of" class="sref">container_of1/a>(1a href="+code=to_delayed_work" class="sref">to_delayed_work1/a>(1a href="+code=work" class="sref">work1/a>), struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a>, . 491/a>                             1a href="+code=work" class="sref">work1/a>); . 501/a> . 511/a>        1a href="+code=state" class="sref">state1/a> =.1a href="+code=gpio_get_on>
 " class="sref">gpio_get_on>
 1/a>(1a href="+code=da a" class="sref">da a1/a>->1a href="+code=gpio" class="sref">gpio1/a>); . 521/a>        1a href="+code=extcon_set_state" class="sref">extcon_set_state1/a>(&1a href="+code=da a" class="sref">da a1/a>->1a href="+code=edev" class="sref">edev1/a>, 1a href="+code=state" class="sref">state1/a>); . 531/a>} . 541/a> . 551/a>static 1a href="+code=irqreturn_t" class="sref">irqreturn_t1/a> 1a href="+code=gpio_irq_handler" class="sref">gpio_irq_handler1/a>(int 1a href="+code=irq" class="sref">irq1/a>, void *1a href="+code=dev_id" class="sref">dev_id1/a>) . 561/a>{ . 571/a>        struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a> *1a href="+code=extcon_da a" class="sref">extcon_da a1/a> =.1a href="+code=dev_id" class="sref">dev_id1/a>; . 581/a> . 591/a>        1a href="+code=schedule_delayed_work" class="sref">schedule_delayed_work1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=work" class="sref">work1/a>, . 601/a>                             .1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=debounce_jiffies" class="sref">debounce_jiffies1/a>); . 611/a>        return 1a href="+code=IRQ_HANDLED" class="sref">IRQ_HANDLED1/a>; . 621/a>} . 631/a> . 641/a>static 1a href="+code=ssize_t" class="sref">ssize_t1/a> 1a href="+code=extcon_gpio_print_state" class="sref">extcon_gpio_print_state1/a>(struct.1a href="+code=extcon_dev" class="sref">extcon_dev1/a> *1a href="+code=edev" class="sref">edev1/a>, char *1a href="+code=buf" class="sref">buf1/a>) . 651/a>{ . 661/a>        struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a> *1a href="+code=extcon_da a" class="sref">extcon_da a1/a> = . 671/a>                1a href="+code=container_of" class="sref">container_of1/a>(1a href="+code=edev" class="sref">edev1/a>, struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a>, 1a href="+code=edev" class="sref">edev1/a>); . 681/a>        const char *1a href="+code=state" class="sref">state1/a>; . 691/a>        if (1a href="+code=extcon_get_state" class="sref">extcon_get_state1/a>(1a href="+code=edev" class="sref">edev1/a>)) . 701/a>                1a href="+code=state" class="sref">state1/a> =.1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=state_on" class="sref">state_on1/a>; . 711/a>        else . 721/a>                1a href="+code=state" class="sref">state1/a> =.1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=state_off" class="sref">state_off1/a>; . 731/a> . 741/a>        if (1a href="+code=state" class="sref">state1/a>) . 751/a>                return 1a href="+code=sprintf" class="sref">sprintf1/a>(1a href="+code=buf" class="sref">buf1/a>, 1spa
 class="string">"%s\n"1/spa
 , 1a href="+code=state" class="sref">state1/a>); . 761/a>        return -1a href="+code=EINVAL" class="sref">EINVAL1/a>; . 771/a>} . 781/a> . 791/a>static int 1a href="+code=__devinit" class="sref">__devinit1/a> 1a href="+code=gpio_extcon_prob " class="sref">gpio_extcon_prob 1/a>(struct.1a href="+code=platform_device" class="sref">platform_device1/a> *1a href="+code=pdev" class="sref">pdev1/a>) . 801/a>{ . 811/a>        struct.1a href="+code=gpio_extcon_platform_da a" class="sref">gpio_extcon_platform_da a1/a> *1a href="+code=pda a" class="sref">pda a1/a> =.1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=dev" class="sref">dev1/a>.1a href="+code=platform_da a" class="sref">platform_da a1/a>; . 821/a>        struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a> *1a href="+code=extcon_da a" class="sref">extcon_da a1/a>; . 831/a>        int 1a href="+code=ret" class="sref">ret1/a> =.0; . 841/a> . 851/a>        if (!1a href="+code=pda a" class="sref">pda a1/a>) . 861/a>                return -1a href="+code=EBUSY" class="sref">EBUSY1/a>; . 871/a>        if (!1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=irq_flags" class="sref">irq_flags1/a>) { . 881/a>                1a href="+code=dev_err" class="sref">dev_err1/a>(&1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=dev" class="sref">dev1/a>, 1spa
 class="string">"IRQ flag is not specified.\n"1/spa
 ); . 891/a>                return -1a href="+code=EINVAL" class="sref">EINVAL1/a>; . 901/a>        } . 911/a> . 921/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a> =.1a href="+code=devm_kzalloc" class="sref">devm_kzalloc1/a>(&1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=dev" class="sref">dev1/a>, sizeof(struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a>), . 931/a>                                   1a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL1/a>); . 941/a>        if (!1a href="+code=extcon_da a" class="sref">extcon_da a1/a>) . 951/a>                return -1a href="+code=ENOMEM" class="sref">ENOMEM1/a>; . 961/a> . 971/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=edev" class="sref">edev1/a>.1a href="+code=nam " class="sref">nam 1/a> =.1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=nam " class="sref">nam 1/a>; . 981/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=gpio" class="sref">gpio1/a> =.1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=gpio" class="sref">gpio1/a>; . 991/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=state_on" class="sref">state_on1/a> =.1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=state_on" class="sref">state_on1/a>; .1001/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=state_off" class="sref">state_off1/a> =.1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=state_off" class="sref">state_off1/a>; .1011/a>        if (1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=state_on" class="sref">state_on1/a> &&.1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=state_off" class="sref">state_off1/a>) .1021/a>                1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=edev" class="sref">edev1/a>.1a href="+code=print_state" class="sref">print_state1/a> =.1a href="+code=extcon_gpio_print_state" class="sref">extcon_gpio_print_state1/a>; .1031/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=debounce_jiffies" class="sref">debounce_jiffies1/a> =.1a href="+code=msecs_to_jiffies" class="sref">msecs_to_jiffies1/a>(1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=debounce" class="sref">debounce1/a>); .1041/a> .1051/a>        1a href="+code=ret" class="sref">ret1/a> =.1a href="+code=extcon_dev_register" class="sref">extcon_dev_register1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=edev" class="sref">edev1/a>, &1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=dev" class="sref">dev1/a>); .1061/a>        if (1a href="+code=ret" class="sref">ret1/a> < 0) .1071/a>                return 1a href="+code=ret" class="sref">ret1/a>; .1081/a> .1091/a>        1a href="+code=ret" class="sref">ret1/a> =.1a href="+code=devm_gpio_request_one" class="sref">devm_gpio_request_one1/a>(&1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=dev" class="sref">dev1/a>, 1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=gpio" class="sref">gpio1/a>, 1a href="+code=GPIOF_DIR_IN" class="sref">GPIOF_DIR_IN1/a>, .1101/a>                             .      1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=nam " class="sref">nam 1/a>); .1111/a>        if (1a href="+code=ret" class="sref">ret1/a> < 0) .1121/a>                goto 1a href="+code=err" class="sref">err1/a>; .1131/a> .1141/a>        1a href="+code=INIT_DELAYED_WORK" class="sref">INIT_DELAYED_WORK1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=work" class="sref">work1/a>, 1a href="+code=gpio_extcon_work" class="sref">gpio_extcon_work1/a>); .1151/a> .1161/a>        1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=irq" class="sref">irq1/a> =.1a href="+code=gpio_to_irq" class="sref">gpio_to_irq1/a>(1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=gpio" class="sref">gpio1/a>); .1171/a>        if (1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=irq" class="sref">irq1/a> < 0) { .1181/a>                1a href="+code=ret" class="sref">ret1/a> =.1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=irq" class="sref">irq1/a>; .1191/a>                goto 1a href="+code=err" class="sref">err1/a>; .1201/a>        } .1211/a> .1221/a>        1a href="+code=ret" class="sref">ret1/a> =.1a href="+code=request_any_context_irq" class="sref">request_any_context_irq1/a>(1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=irq" class="sref">irq1/a>, 1a href="+code=gpio_irq_handler" class="sref">gpio_irq_handler1/a>, .1231/a>                                      1a href="+code=pda a" class="sref">pda a1/a>->1a href="+code=irq_flags" class="sref">irq_flags1/a>, 1a href="+code=pdev" class="sref">pdev1/a>->1a href="+code=nam " class="sref">nam 1/a>, .1241/a>                                      1a href="+code=extcon_da a" class="sref">extcon_da a1/a>); .1251/a>        if (1a href="+code=ret" class="sref">ret1/a> < 0) .1261/a>                goto 1a href="+code=err" class="sref">err1/a>; .1271/a> .1281/a>        1a href="+code=platform_set_drvda a" class="sref">platform_set_drvda a1/a>(1a href="+code=pdev" class="sref">pdev1/a>, 1a href="+code=extcon_da a" class="sref">extcon_da a1/a>); .1291/a>        1spa
 class="comment">/* Perform initial detec  >
 */1/spa
  .1301/a>        1a href="+code=gpio_extcon_work" class="sref">gpio_extcon_work1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=work" class="sref">work1/a>.1a href="+code=work" class="sref">work1/a>); .1311/a> .1321/a>        return 0; .1331/a> .1341/a>1a href="+code=err" class="sref">err1/a>: .1351/a>        1a href="+code=extcon_dev_unregister" class="sref">extcon_dev_unregister1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=edev" class="sref">edev1/a>); .1361/a> .1371/a>        return 1a href="+code=ret" class="sref">ret1/a>; .1381/a>} .1391/a> .1401/a>static int 1a href="+code=__devexit" class="sref">__devexit1/a> 1a href="+code=gpio_extcon_remov " class="sref">gpio_extcon_remov 1/a>(struct.1a href="+code=platform_device" class="sref">platform_device1/a> *1a href="+code=pdev" class="sref">pdev1/a>) .1411/a>{ .1421/a>        struct.1a href="+code=gpio_extcon_da a" class="sref">gpio_extcon_da a1/a> *1a href="+code=extcon_da a" class="sref">extcon_da a1/a> =.1a href="+code=platform_get_drvda a" class="sref">platform_get_drvda a1/a>(1a href="+code=pdev" class="sref">pdev1/a>); .1431/a> .1441/a>        1a href="+code=cancel_delayed_work_sync" class="sref">cancel_delayed_work_sync1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=work" class="sref">work1/a>); .1451/a>        1a href="+code=free_irq" class="sref">free_irq1/a>(1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=irq" class="sref">irq1/a>, 1a href="+code=extcon_da a" class="sref">extcon_da a1/a>); .1461/a>        1a href="+code=extcon_dev_unregister" class="sref">extcon_dev_unregister1/a>(&1a href="+code=extcon_da a" class="sref">extcon_da a1/a>->1a href="+code=edev" class="sref">edev1/a>); .1471/a> .1481/a>        return 0; .1491/a>} .1501/a> .1511/a>static struct.1a href="+code=platform_driver" class="sref">platform_driver1/a> 1a href="+code=gpio_extcon_driver" class="sref">gpio_extcon_driver1/a> =.{ .1521/a>        .1a href="+code=prob " class="sref">prob 1/a>          =.1a href="+code=gpio_extcon_prob " class="sref">gpio_extcon_prob 1/a>, .1531/a>        .1a href="+code=remov " class="sref">remov 1/a>         =.1a href="+code=__devexit_p" class="sref">__devexit_p1/a>(1a href="+code=gpio_extcon_remov " class="sref">gpio_extcon_remov 1/a>), .1541/a>        .1a href="+code=driver" class="sref">driver1/a>         =.{ .1551/a>                .1a href="+code=nam " class="sref">nam 1/a>   =.1spa
 class="string">"extcon-gpio"1/spa
 , .1561/a>                .1a href="+code=owner" class="sref">owner1/a>  =.1a href="+code=THIS_MODULE" class="sref">THIS_MODULE1/a>, .1571/a>        }, .1581/a>}; .1591/a> .1601/a>1a href="+code=module_platform_driver" class="sref">module_platform_driver1/a>(1a href="+code=gpio_extcon_driver" class="sref">gpio_extcon_driver1/a>); .1611/a> .1621/a>1a href="+code=MODULE_AUTHOR" class="sref">MODULE_AUTHOR1/a>(1spa
 class="string">"Mike Lockwood <lockwood@android.com>"1/spa
 ); .1631/a>1a href="+code=MODULE_DESCRIPTION" class="sref">MODULE_DESCRIPTION1/a>(1spa
 class="string">"GPIO extcon driver"1/spa
 ); .1641/a>1a href="+code=MODULE_LICENSE" class="sref">MODULE_LICENSE1/a>(1spa
 class="string">"GPL"1/spa
 ); .1651/a>
The original LXR software by the LXR community1/a>, this experimental vers > by lxr@linux.no1/a>. 1/div 1div class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro AS1/a>, provider of Linux consulting and opera > s services since 1995. 1/div 1/body 1/html