linux/Documentation/extcon/porting-android-switch-class
<<
tion3.1/spa > 3.1/form> 3.1a tion3. href="../linux+v3.7.5/Documenta /extc /porting-android-switch-class">tion3.1img src="../.sta c/gfx/right.png" alt=">>">ti1/spa > ti1spa class="lxr_search">tiontion3.1input typn> hidden" namn> navtarget" ption> ">tion3.1input typn> text" namn> search" id> search">tion3.1butt submit">Search 3.1/form> 1/spa > ti1spa class="lxr_prefs">tion1a href="+prefs?return=Documenta /extc /porting-android-switch-class"tion3. onclick="return ajax_prefs();">tion3.Prefs 3.1/a>ti1/spa > on3. .1/div> on3. .1form ac ="ajax+*" method="post" onsubmit="return false;">ti1input typn> hidden" namn> ajax_lookup" id> ajax_lookup" ption> ">ton3. .1/form> ton3. .1div class="headingbott
on3.
on3. 3. .1div id> search_results" class="search_results" 3> on3. .1/div> 1div id> c tent"> 1div id> file_c tents">
5f/c6/5950075e8bf1ab75c60808e421de8c83c3ec_3/0">
L1" class="line" namn>
L1">. .11/a>t
L2" class="line" namn>
L2">. .21/a>        Staging/Android Switch Class Porting Guidet
L3" class="line" namn>
L3">. .31/a>        (linux/drivers/staging/android/switch)t
L4" class="line" namn>
L4">. .41/a>        (c) Copyright 2012 Samsung Electronicst
L5" class="line" namn>
L5">. .51/a>t
L6" class="line" namn>
L6">. .61/a>AUTHORSt
L7" class="line" namn>
L7">. .71/a>MyungJoo Ham <myungjoo.ham@samsung.com>t
L8" class="line" namn>
L8">. .81/a>t
L9" class="line" namn>
L9">. .91/a>/*****************************************************************t
L10" class="line" namn>
L10">. 18.1a> * CHAPTER 1.                                                    *t
L11" class="line" namn>
L11">. 11.1a> * PORTING SWITCH CLASS DEVICE DRIVERS                           *t
L12" class="line" namn>
L12">. 121/a> *****************************************************************/t
L13" class="line" namn>
L13">. 131/a>t
L14" class="line" namn>
L14">. 141/a>****** STEP 1. Basic Func
	  alityt
L15" class="line" namn>
L15">. 151/a>        No extc   extended feature, but switch features only.t
L16" class="line" namn>
L16">. 161/a>t
L17" class="line" namn>
L17">. 171/a>- struct switch_dev (fed to switch_dev_register/unregister)t
L18" class="line" namn>
L18">. 181/a>    @namn: no changet
L19" class="line" namn>
L19">. 191/a>    @dev: no changet
L20" class="line" namn>
L20">. 201/a>    @index: drop (not used in switch device driver side anyway)t
L21" class="line" namn>
L21">. 211/a>    @sta
n: no changet
L22" class="line" namn>
L22">. 221/a>        If you have used @sta
n with magic numbers, keep itt
L23" class="line" namn>
L23">. 231/a>        at this step.t
L24" class="line" namn>
L24">. 241/a>    @print_namn: no change but typn change (switch_dev->extc  _dev)t
L25" class="line" namn>
L25">. 251/a>    @print_sta
n: no change but typn change (switch_dev->extc  _dev)t
L26" class="line" namn>
L26">. 261/a>t
L27" class="line" namn>
L27">. 271/a>- switch_dev_register(sdev, dev)t
L28" class="line" namn>
L28">. 281/a>        => extc  _dev_register(edev, dev)t
L29" class="line" namn>
L29">. 291/a>        : no change but typn change (sdev->edev)t
L30" class="line" namn>
L30">. 301/a>- switch_dev_unregister(sdev)t
L31" class="line" namn>
L31">. 311/a>        => extc  _dev_unregister(edev)t
L32" class="line" namn>
L32">. 321/a>        : no change but typn change (sdev->edev)t
L33" class="line" namn>
L33">. 331/a>- switch_get_sta
n(sdev)t
L34" class="line" namn>
L34">. 341/a>        => extc  _get_sta
n(edev)t
L35" class="line" namn>
L35">. 351/a>        : no change but typn change (sdev->edev) and (return: int->u32)t
L36" class="line" namn>
L36">. 361/a>- switch_set_sta
n(sdev, sta
n)t
L37" class="line" namn>
L37">. 371/a>        => extc  _set_sta
n(edev, sta
n)t
L38" class="line" namn>
L38">. 381/a>        : no change but typn change (sdev->edev) and (sta
n: int->u32)t
L39" class="line" namn>
L39">. 391/a>t
L40" class="line" namn>
L40">. 401/a>With this changes, the ex-switch extc   class device works as it oncet
L41" class="line" namn>
L41">. 411/a>worked as switch class device. However, it will now have addi
	  alt
L42" class="line" namn>
L42">. 421/a>interfaces (both ABI and in-kernel API) and different ABI loca
	  s.t
L43" class="line" namn>
L43">. 431/a>However, if CONFIG_ANDROID is enabled without CONFIG_ANDROID_SWITCH,t
L44" class="line" namn>
L44">. 441/a>/sys/class/switch/* will be symbolically linked to /sys/class/extc  /t
L45" class="line" namn>
L45">. 451/a>so that they are still compa
	ble with legacy userspace processes.t
L46" class="line" namn>
L46">. 461/a>t
L47" class="line" namn>
L47">. 471/a>****** STEP 2. Multista
n (no more magic numbers in sta
n ption)t
L48" class="line" namn>
L48">. 481/a>        Extc  's extended features for switch device drivers witht
L49" class="line" namn>
L49">. 491/a>        complex features usually required magic numbers in sta
nt
L50" class="line" namn>
L50">. 501/a>        ption of switch_dev. With extc  , such magic numbers thatt
L51" class="line" namn>
L51">. 511/a>        support multiple cables (t
L52" class="line" namn>
L52">. 521/a>t
L53" class="line" namn>
L53">. 531/a>  1. Define cable namns at edev->supported_cable.t
L54" class="line" namn>
L54">. 541/a>  2. (Recommended) remove print_sta
n callback.t
L55" class="line" namn>
L55">. 551/a>  3. Use extc  _get_cable_sta
n_(edev, index) ort
L56" class="line" namn>
L56">. 561/a>   extc  _get_cable_sta
n(edev, cable_namn) instead oft
L57" class="line" namn>
L57">. 571/a>   extc  _get_sta
n(edev) if you intend to get a sta
n of a specifict
L58" class="line" namn>
L58">. 581/a>   cable. Same for set_sta
n. This way, you can remove the usage oft
L59" class="line" namn>
L59">. 591/a>   magic numbers in sta
n ption.t
L60" class="line" namn>
L60">. 601/a>  4. Use extc  _upda
n_sta
n() if you are upda
ing specific bits oft
L61" class="line" namn>
L61">. 611/a>   the sta
n ption.t
L62" class="line" namn>
L62">. 621/a>t
L63" class="line" namn>
L63">. 631/a>Example: a switch device driver w/ magic numbers for two cables.t
L64" class="line" namn>
L64">. 641/a>        "0x00": no cables c  nected.t
L65" class="line" namn>
L65">. 651/a>        "0x01": cable 1 c  nectedt
L66" class="line" namn>
L66">. 661/a>        "0x02": cable 2 c  nectedt
L67" class="line" namn>
L67">. 671/a>        "0x03": cable 1 and 2 c  nectedt
L68" class="line" namn>
L68">. 681/a>  1. edev->supported_cable = {"1", "2", NULL};t
L69" class="line" namn>
L69">. 691/a>  2. edev->print_sta
n = NULL;t
L70" class="line" namn>
L70">. 701/a>  3. extc  _get_cable_sta
n_(edev, 0) shows cable 1's sta
n.t
L71" class="line" namn>
L71">. 711/a>     extc  _get_cable_sta
n(edev, "1") shows cable 1's sta
n.t
L72" class="line" namn>
L72">. 721/a>     extc  _set_cable_sta
n_(edev, 1) sets cable 2's sta
n.t
L73" class="line" namn>
L73">. 731/a>     extc  _set_cable_sta
n(edev, "2") sets cable 2's sta
nt
L74" class="line" namn>
L74">. 741/a>  4. extc  _upda
n_sta
n(edev, 0x01, 0) sets the least bit's 0.t
L75" class="line" namn>
L75">. 751/a>t
L76" class="line" namn>
L76">. 761/a>****** STEP 3. Notify other device driverst
L77" class="line" namn>
L77">. 771/a>t
L78" class="line" namn>
L78">. 781/a>  You can notify others of the cable attach/detach events witht
L79" class="line" namn>
L79">. 791/a>notifier chai s.t
L80" class="line" namn>
L80">. 801/a>t
L81" class="line" namn>
L81">. 811/a>  At the side of other device drivers (the extc   device itselft
L82" class="line" namn>
L82">. 821/a>does not need to get notified of its own events), there are twot
L83" class="line" namn>
L83">. 831/a>methods to register notifier_block for cable events:t
L84" class="line" namn>
L84">. 841/a>(a) for a specific cable or (b) for every cable.t
L85" class="line" namn>
L85">. 851/a>t
L86" class="line" namn>
L86">. 861/a>  (a) extc  _register_interest(obj, extc  _namn, cable_namn, nb)t
L87" class="line" namn>
L87">. 871/a>        Example: want to get news of "MAX8997_MUIC"'s "USB" cablet
L88" class="line" namn>
L88">. 881/a>t
L89" class="line" namn>
L89">. 891/a>        obj = kzalloc(sizeof(struct extc  _specific_cable_nb),t
L90" class="line" namn>
L90">. 901/a>                      GFP_KERNEL);t
L91" class="line" namn>
L91">. 911/a>        nb->notifier_call = the_callback_to_handle_usb;t
L92" class="line" namn>
L92">. 921/a>t
L93" class="line" namn>
L93">. 931/a>        extc  _register_intereset(obj, "MAX8997_MUIC", "USB", nb);t
L94" class="line" namn>
L94">. 941/a>t
L95" class="line" namn>
L95">. 951/a>  (b) extc  _register_notifier(edev, nb)t
L96" class="line" namn>
L96">. 961/a>        Call nb for any changes in edev.t
L97" class="line" namn>
L97">. 971/a>t
L98" class="line" namn>
L98">. 981/a>  Please note that in order to properly behave with method (a),t
L99" class="line" namn>
L99">. 991/a>the extc   device driver shou1>. 881/a>t
L9Tschanges in edev. na sta
n pt)-switch-class#L16" id>
L16" class="line" namn>
L16">. 161/a>t
L17" class="line" namn>
L17">. 171/a>- s0PORTING S0WITCH CLASS DEVICE DRIVE01 hr  1
L18" class="line" namn>
L18">. 181/a>   0*********0************************02 hr  roid-switch-class#L93" id>
L93" class="line" namn>
L93">. 931/a>  10 href="Do0cumenta
	  /extc  /porti03 hr  3/detach eventsentvitseiSB&q-a
	  /mutDocumeexcluslasnesg-anon3.id>
Lswitch-class#L93" id>
L93" class="line" namn>
L93">. 931/a>  10*** STEP 01. Basic Func
	  alityt<04 hr  roid-/extc ocumenta
	  /e. When /portinAportiBandrodeBasre twotb /mutDocumswitch-class#L93" id>
L93" class="line" namn>
L93">. 931/a>  10     No e0xtc   extended feature, 05 hr  a hreexcluslas oncetng-androidventere bseiS ATTACHEDting-ansiangesneousid-switch-class#L16" id>
L16" class="line" namn>
L16">. 161/a>t
L17" class="line" namn>
L17">. 171/a>- s0truct swi0tch_dev (fed to switch_d07 hr  roid-switch-class#L98" id>
L98" class="line" namn>
L98">. 981/a>  10 @namn: n0o changet
L10" class="line" namn>
L10">. 18.1a> * C @dev: no0 changet
L11" class="line" namn>
L11">. 11.1a> * PCHAPTER 11.                            1                 USERSPACEment       *t
L11" class="line" namn>
L11">. 11.1a> * PPORTING SWWITCH CLASS DEVICE DRIVER1 hr                                                                         -switch-class#L13" id>
L13" class="line" namn>
L13">. 131/a>t
L93" class="line" namn>
L93">. 931/a>  1a href="Doocumenta
	  /extc  /portiing-a1droid-      ortinL-androiswitch-class#L93" id>
L93" class="line" namn>
L93">. 931/a>  1a*** STEP  1. Basic Func
	  alityt<
L95" class="line" namn>
L95">. 951/a>  1      No eextc   extended feature,  but 1witch feI; cabletxtc  /porting-ing-andef="Documenorticabletxtc  /porting-androiding-andefswitch-class#L95" id>
L95" class="line" namn>
L95">. 951/a>  1  href="Doocumenta
	  /extc  /portiing-a1droid-disocume,  to /sys/class/extc ndrocrv.  have af="Docua
	  
L95" class="line" namn>
L95">. 951/a>  1 truct swiitch_dev (fed to switch_ddev_r1gister /porting-android-*. Becauethxtc  /porting-androidocrv.  fswitch-class#L95" id>
L95" class="line" namn>
L95">. 951/a>  1  @namn: nno changet
L82" class="line" namn>
L82">. 821/a>do1  @dev: noo changet
L16" class="line" namn>
L16">. 161/a>t
L17" class="line" namn>
L17">. 171/a>- s  @sta
n:1 no changet
L79" class="line" namn>
L79">. 791/a>no12***************************************1c numbnta
	  /too. When ncetanges in ed>
L9Tschta
n pt tha          )defswitch-class#L95" id>
L95" class="line" namn>
L95">. 951/a>  1      at 1this step.t
L9lime, ncetoutookud-switch-class#L61" id>
L61" class="line" namn>
L61">. 611/a>  1  @print_1namn: no change but typn1 chan1e (swiortingrtinef=>="Dnportitt
L16" class="line" namn>
L16">. 161/a>t
Tcetoriginal LXR softwndroby ncetwitch-clahttp://source/exge.net/projects/lxq">LXR ="Dounity (sw,e workexperi16" il ta
	>
L by witch-clamailto:lxq@Docum.no">lxq@Docum.no (sw.
nts">
lxq.Docum.no  cndumehos  haby witch-clahttp://www.re pill-Docpro.no">Re pill Locpro AS (sw,eentvitsr thaLocumg-aniv icngaortita
	ndroid ser  /ed since 1995.
nts">