sony-laptop.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781
  1. /*
  2. * ACPI Sony Notebook Control Driver (SNC and SPIC)
  3. *
  4. * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
  5. * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
  6. *
  7. * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
  8. * which are copyrighted by their respective authors.
  9. *
  10. * The SNY6001 driver part is based on the sonypi driver which includes
  11. * material from:
  12. *
  13. * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
  14. *
  15. * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
  16. *
  17. * Copyright (C) 2001-2002 Alcôve <www.alcove.com>
  18. *
  19. * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
  20. *
  21. * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
  22. *
  23. * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
  24. *
  25. * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
  26. *
  27. * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
  28. *
  29. * This program is free software; you can redistribute it and/or modify
  30. * it under the terms of the GNU General Public License as published by
  31. * the Free Software Foundation; either version 2 of the License, or
  32. * (at your option) any later version.
  33. *
  34. * This program is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. * GNU General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU General Public License
  40. * along with this program; if not, write to the Free Software
  41. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42. *
  43. */
  44. #include <linux/kernel.h>
  45. #include <linux/module.h>
  46. #include <linux/moduleparam.h>
  47. #include <linux/init.h>
  48. #include <linux/smp_lock.h>
  49. #include <linux/types.h>
  50. #include <linux/backlight.h>
  51. #include <linux/platform_device.h>
  52. #include <linux/err.h>
  53. #include <linux/dmi.h>
  54. #include <linux/pci.h>
  55. #include <linux/interrupt.h>
  56. #include <linux/delay.h>
  57. #include <linux/input.h>
  58. #include <linux/kfifo.h>
  59. #include <linux/workqueue.h>
  60. #include <linux/acpi.h>
  61. #include <acpi/acpi_drivers.h>
  62. #include <acpi/acpi_bus.h>
  63. #include <asm/uaccess.h>
  64. #include <linux/sonypi.h>
  65. #include <linux/sony-laptop.h>
  66. #ifdef CONFIG_SONYPI_COMPAT
  67. #include <linux/poll.h>
  68. #include <linux/miscdevice.h>
  69. #endif
  70. #define DRV_PFX "sony-laptop: "
  71. #define dprintk(msg...) do { \
  72. if (debug) printk(KERN_WARNING DRV_PFX msg); \
  73. } while (0)
  74. #define SONY_LAPTOP_DRIVER_VERSION "0.6"
  75. #define SONY_NC_CLASS "sony-nc"
  76. #define SONY_NC_HID "SNY5001"
  77. #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
  78. #define SONY_PIC_CLASS "sony-pic"
  79. #define SONY_PIC_HID "SNY6001"
  80. #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
  81. MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
  82. MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
  85. static int debug;
  86. module_param(debug, int, 0);
  87. MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
  88. "the development of this driver");
  89. static int no_spic; /* = 0 */
  90. module_param(no_spic, int, 0444);
  91. MODULE_PARM_DESC(no_spic,
  92. "set this if you don't want to enable the SPIC device");
  93. static int compat; /* = 0 */
  94. module_param(compat, int, 0444);
  95. MODULE_PARM_DESC(compat,
  96. "set this if you want to enable backward compatibility mode");
  97. static unsigned long mask = 0xffffffff;
  98. module_param(mask, ulong, 0644);
  99. MODULE_PARM_DESC(mask,
  100. "set this to the mask of event you want to enable (see doc)");
  101. static int camera; /* = 0 */
  102. module_param(camera, int, 0444);
  103. MODULE_PARM_DESC(camera,
  104. "set this to 1 to enable Motion Eye camera controls "
  105. "(only use it if you have a C1VE or C1VN model)");
  106. #ifdef CONFIG_SONYPI_COMPAT
  107. static int minor = -1;
  108. module_param(minor, int, 0);
  109. MODULE_PARM_DESC(minor,
  110. "minor number of the misc device for the SPIC compatibility code, "
  111. "default is -1 (automatic)");
  112. #endif
  113. /*********** Input Devices ***********/
  114. #define SONY_LAPTOP_BUF_SIZE 128
  115. struct sony_laptop_input_s {
  116. atomic_t users;
  117. struct input_dev *jog_dev;
  118. struct input_dev *key_dev;
  119. struct kfifo *fifo;
  120. spinlock_t fifo_lock;
  121. struct workqueue_struct *wq;
  122. };
  123. static struct sony_laptop_input_s sony_laptop_input = {
  124. .users = ATOMIC_INIT(0),
  125. };
  126. struct sony_laptop_keypress {
  127. struct input_dev *dev;
  128. int key;
  129. };
  130. /* Correspondance table between sonypi events
  131. * and input layer indexes in the keymap
  132. */
  133. static int sony_laptop_input_index[] = {
  134. -1, /* 0 no event */
  135. -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */
  136. -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */
  137. -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
  138. -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
  139. -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */
  140. -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */
  141. 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */
  142. 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */
  143. 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
  144. 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
  145. 4, /* 11 SONYPI_EVENT_FNKEY_ESC */
  146. 5, /* 12 SONYPI_EVENT_FNKEY_F1 */
  147. 6, /* 13 SONYPI_EVENT_FNKEY_F2 */
  148. 7, /* 14 SONYPI_EVENT_FNKEY_F3 */
  149. 8, /* 15 SONYPI_EVENT_FNKEY_F4 */
  150. 9, /* 16 SONYPI_EVENT_FNKEY_F5 */
  151. 10, /* 17 SONYPI_EVENT_FNKEY_F6 */
  152. 11, /* 18 SONYPI_EVENT_FNKEY_F7 */
  153. 12, /* 19 SONYPI_EVENT_FNKEY_F8 */
  154. 13, /* 20 SONYPI_EVENT_FNKEY_F9 */
  155. 14, /* 21 SONYPI_EVENT_FNKEY_F10 */
  156. 15, /* 22 SONYPI_EVENT_FNKEY_F11 */
  157. 16, /* 23 SONYPI_EVENT_FNKEY_F12 */
  158. 17, /* 24 SONYPI_EVENT_FNKEY_1 */
  159. 18, /* 25 SONYPI_EVENT_FNKEY_2 */
  160. 19, /* 26 SONYPI_EVENT_FNKEY_D */
  161. 20, /* 27 SONYPI_EVENT_FNKEY_E */
  162. 21, /* 28 SONYPI_EVENT_FNKEY_F */
  163. 22, /* 29 SONYPI_EVENT_FNKEY_S */
  164. 23, /* 30 SONYPI_EVENT_FNKEY_B */
  165. 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
  166. 25, /* 32 SONYPI_EVENT_PKEY_P1 */
  167. 26, /* 33 SONYPI_EVENT_PKEY_P2 */
  168. 27, /* 34 SONYPI_EVENT_PKEY_P3 */
  169. 28, /* 35 SONYPI_EVENT_BACK_PRESSED */
  170. -1, /* 36 SONYPI_EVENT_LID_CLOSED */
  171. -1, /* 37 SONYPI_EVENT_LID_OPENED */
  172. 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */
  173. 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */
  174. 31, /* 40 SONYPI_EVENT_HELP_PRESSED */
  175. 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */
  176. 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
  177. 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
  178. 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
  179. 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
  180. 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
  181. 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
  182. 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
  183. 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
  184. 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */
  185. 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
  186. 43, /* 52 SONYPI_EVENT_MEYE_FACE */
  187. 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */
  188. 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
  189. 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
  190. -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
  191. -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */
  192. -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */
  193. -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */
  194. 47, /* 60 SONYPI_EVENT_WIRELESS_ON */
  195. 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */
  196. 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
  197. 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
  198. };
  199. static int sony_laptop_input_keycode_map[] = {
  200. KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
  201. KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
  202. KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
  203. KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
  204. KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */
  205. KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */
  206. KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */
  207. KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */
  208. KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */
  209. KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */
  210. KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */
  211. KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */
  212. KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */
  213. KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */
  214. KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */
  215. KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */
  216. KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */
  217. KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */
  218. KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */
  219. KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */
  220. KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */
  221. KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */
  222. KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */
  223. KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */
  224. KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
  225. KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */
  226. KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */
  227. KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */
  228. KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */
  229. KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
  230. KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
  231. KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */
  232. KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */
  233. KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
  234. KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
  235. KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
  236. KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
  237. KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
  238. KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
  239. KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
  240. KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
  241. KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
  242. BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
  243. KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */
  244. KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
  245. KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
  246. KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
  247. KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */
  248. KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */
  249. KEY_ZOOMIN, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
  250. KEY_ZOOMOUT /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
  251. };
  252. /* release buttons after a short delay if pressed */
  253. static void do_sony_laptop_release_key(struct work_struct *work)
  254. {
  255. struct sony_laptop_keypress kp;
  256. while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
  257. sizeof(kp)) == sizeof(kp)) {
  258. msleep(10);
  259. input_report_key(kp.dev, kp.key, 0);
  260. input_sync(kp.dev);
  261. }
  262. }
  263. static DECLARE_WORK(sony_laptop_release_key_work,
  264. do_sony_laptop_release_key);
  265. /* forward event to the input subsystem */
  266. static void sony_laptop_report_input_event(u8 event)
  267. {
  268. struct input_dev *jog_dev = sony_laptop_input.jog_dev;
  269. struct input_dev *key_dev = sony_laptop_input.key_dev;
  270. struct sony_laptop_keypress kp = { NULL };
  271. if (event == SONYPI_EVENT_FNKEY_RELEASED) {
  272. /* Nothing, not all VAIOs generate this event */
  273. return;
  274. }
  275. /* report events */
  276. switch (event) {
  277. /* jog_dev events */
  278. case SONYPI_EVENT_JOGDIAL_UP:
  279. case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
  280. input_report_rel(jog_dev, REL_WHEEL, 1);
  281. input_sync(jog_dev);
  282. return;
  283. case SONYPI_EVENT_JOGDIAL_DOWN:
  284. case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
  285. input_report_rel(jog_dev, REL_WHEEL, -1);
  286. input_sync(jog_dev);
  287. return;
  288. /* key_dev events */
  289. case SONYPI_EVENT_JOGDIAL_PRESSED:
  290. kp.key = BTN_MIDDLE;
  291. kp.dev = jog_dev;
  292. break;
  293. default:
  294. if (event >= ARRAY_SIZE(sony_laptop_input_index)) {
  295. dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
  296. break;
  297. }
  298. if (sony_laptop_input_index[event] != -1) {
  299. kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]];
  300. if (kp.key != KEY_UNKNOWN)
  301. kp.dev = key_dev;
  302. }
  303. break;
  304. }
  305. if (kp.dev) {
  306. input_report_key(kp.dev, kp.key, 1);
  307. /* we emit the scancode so we can always remap the key */
  308. input_event(kp.dev, EV_MSC, MSC_SCAN, event);
  309. input_sync(kp.dev);
  310. kfifo_put(sony_laptop_input.fifo,
  311. (unsigned char *)&kp, sizeof(kp));
  312. if (!work_pending(&sony_laptop_release_key_work))
  313. queue_work(sony_laptop_input.wq,
  314. &sony_laptop_release_key_work);
  315. } else
  316. dprintk("unknown input event %.2x\n", event);
  317. }
  318. static int sony_laptop_setup_input(struct acpi_device *acpi_device)
  319. {
  320. struct input_dev *jog_dev;
  321. struct input_dev *key_dev;
  322. int i;
  323. int error;
  324. /* don't run again if already initialized */
  325. if (atomic_add_return(1, &sony_laptop_input.users) > 1)
  326. return 0;
  327. /* kfifo */
  328. spin_lock_init(&sony_laptop_input.fifo_lock);
  329. sony_laptop_input.fifo =
  330. kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
  331. &sony_laptop_input.fifo_lock);
  332. if (IS_ERR(sony_laptop_input.fifo)) {
  333. printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
  334. error = PTR_ERR(sony_laptop_input.fifo);
  335. goto err_dec_users;
  336. }
  337. /* init workqueue */
  338. sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop");
  339. if (!sony_laptop_input.wq) {
  340. printk(KERN_ERR DRV_PFX
  341. "Unabe to create workqueue.\n");
  342. error = -ENXIO;
  343. goto err_free_kfifo;
  344. }
  345. /* input keys */
  346. key_dev = input_allocate_device();
  347. if (!key_dev) {
  348. error = -ENOMEM;
  349. goto err_destroy_wq;
  350. }
  351. key_dev->name = "Sony Vaio Keys";
  352. key_dev->id.bustype = BUS_ISA;
  353. key_dev->id.vendor = PCI_VENDOR_ID_SONY;
  354. key_dev->dev.parent = &acpi_device->dev;
  355. /* Initialize the Input Drivers: special keys */
  356. set_bit(EV_KEY, key_dev->evbit);
  357. set_bit(EV_MSC, key_dev->evbit);
  358. set_bit(MSC_SCAN, key_dev->mscbit);
  359. key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
  360. key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
  361. key_dev->keycode = &sony_laptop_input_keycode_map;
  362. for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) {
  363. if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) {
  364. set_bit(sony_laptop_input_keycode_map[i],
  365. key_dev->keybit);
  366. }
  367. }
  368. error = input_register_device(key_dev);
  369. if (error)
  370. goto err_free_keydev;
  371. sony_laptop_input.key_dev = key_dev;
  372. /* jogdial */
  373. jog_dev = input_allocate_device();
  374. if (!jog_dev) {
  375. error = -ENOMEM;
  376. goto err_unregister_keydev;
  377. }
  378. jog_dev->name = "Sony Vaio Jogdial";
  379. jog_dev->id.bustype = BUS_ISA;
  380. jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
  381. key_dev->dev.parent = &acpi_device->dev;
  382. jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  383. jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE);
  384. jog_dev->relbit[0] = BIT_MASK(REL_WHEEL);
  385. error = input_register_device(jog_dev);
  386. if (error)
  387. goto err_free_jogdev;
  388. sony_laptop_input.jog_dev = jog_dev;
  389. return 0;
  390. err_free_jogdev:
  391. input_free_device(jog_dev);
  392. err_unregister_keydev:
  393. input_unregister_device(key_dev);
  394. /* to avoid kref underflow below at input_free_device */
  395. key_dev = NULL;
  396. err_free_keydev:
  397. input_free_device(key_dev);
  398. err_destroy_wq:
  399. destroy_workqueue(sony_laptop_input.wq);
  400. err_free_kfifo:
  401. kfifo_free(sony_laptop_input.fifo);
  402. err_dec_users:
  403. atomic_dec(&sony_laptop_input.users);
  404. return error;
  405. }
  406. static void sony_laptop_remove_input(void)
  407. {
  408. /* cleanup only after the last user has gone */
  409. if (!atomic_dec_and_test(&sony_laptop_input.users))
  410. return;
  411. /* flush workqueue first */
  412. flush_workqueue(sony_laptop_input.wq);
  413. /* destroy input devs */
  414. input_unregister_device(sony_laptop_input.key_dev);
  415. sony_laptop_input.key_dev = NULL;
  416. if (sony_laptop_input.jog_dev) {
  417. input_unregister_device(sony_laptop_input.jog_dev);
  418. sony_laptop_input.jog_dev = NULL;
  419. }
  420. destroy_workqueue(sony_laptop_input.wq);
  421. kfifo_free(sony_laptop_input.fifo);
  422. }
  423. /*********** Platform Device ***********/
  424. static atomic_t sony_pf_users = ATOMIC_INIT(0);
  425. static struct platform_driver sony_pf_driver = {
  426. .driver = {
  427. .name = "sony-laptop",
  428. .owner = THIS_MODULE,
  429. }
  430. };
  431. static struct platform_device *sony_pf_device;
  432. static int sony_pf_add(void)
  433. {
  434. int ret = 0;
  435. /* don't run again if already initialized */
  436. if (atomic_add_return(1, &sony_pf_users) > 1)
  437. return 0;
  438. ret = platform_driver_register(&sony_pf_driver);
  439. if (ret)
  440. goto out;
  441. sony_pf_device = platform_device_alloc("sony-laptop", -1);
  442. if (!sony_pf_device) {
  443. ret = -ENOMEM;
  444. goto out_platform_registered;
  445. }
  446. ret = platform_device_add(sony_pf_device);
  447. if (ret)
  448. goto out_platform_alloced;
  449. return 0;
  450. out_platform_alloced:
  451. platform_device_put(sony_pf_device);
  452. sony_pf_device = NULL;
  453. out_platform_registered:
  454. platform_driver_unregister(&sony_pf_driver);
  455. out:
  456. atomic_dec(&sony_pf_users);
  457. return ret;
  458. }
  459. static void sony_pf_remove(void)
  460. {
  461. /* deregister only after the last user has gone */
  462. if (!atomic_dec_and_test(&sony_pf_users))
  463. return;
  464. platform_device_del(sony_pf_device);
  465. platform_device_put(sony_pf_device);
  466. platform_driver_unregister(&sony_pf_driver);
  467. }
  468. /*********** SNC (SNY5001) Device ***********/
  469. /* the device uses 1-based values, while the backlight subsystem uses
  470. 0-based values */
  471. #define SONY_MAX_BRIGHTNESS 8
  472. #define SNC_VALIDATE_IN 0
  473. #define SNC_VALIDATE_OUT 1
  474. static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
  475. char *);
  476. static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
  477. const char *, size_t);
  478. static int boolean_validate(const int, const int);
  479. static int brightness_default_validate(const int, const int);
  480. struct sony_nc_value {
  481. char *name; /* name of the entry */
  482. char **acpiget; /* names of the ACPI get function */
  483. char **acpiset; /* names of the ACPI set function */
  484. int (*validate)(const int, const int); /* input/output validation */
  485. int value; /* current setting */
  486. int valid; /* Has ever been set */
  487. int debug; /* active only in debug mode ? */
  488. struct device_attribute devattr; /* sysfs atribute */
  489. };
  490. #define SNC_HANDLE_NAMES(_name, _values...) \
  491. static char *snc_##_name[] = { _values, NULL }
  492. #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
  493. { \
  494. .name = __stringify(_name), \
  495. .acpiget = _getters, \
  496. .acpiset = _setters, \
  497. .validate = _validate, \
  498. .debug = _debug, \
  499. .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
  500. }
  501. #define SNC_HANDLE_NULL { .name = NULL }
  502. SNC_HANDLE_NAMES(fnkey_get, "GHKE");
  503. SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
  504. SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
  505. SNC_HANDLE_NAMES(cdpower_get, "GCDP");
  506. SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
  507. SNC_HANDLE_NAMES(audiopower_get, "GAZP");
  508. SNC_HANDLE_NAMES(audiopower_set, "AZPW");
  509. SNC_HANDLE_NAMES(lanpower_get, "GLNP");
  510. SNC_HANDLE_NAMES(lanpower_set, "LNPW");
  511. SNC_HANDLE_NAMES(lidstate_get, "GLID");
  512. SNC_HANDLE_NAMES(indicatorlamp_get, "GILS");
  513. SNC_HANDLE_NAMES(indicatorlamp_set, "SILS");
  514. SNC_HANDLE_NAMES(gainbass_get, "GMGB");
  515. SNC_HANDLE_NAMES(gainbass_set, "CMGB");
  516. SNC_HANDLE_NAMES(PID_get, "GPID");
  517. SNC_HANDLE_NAMES(CTR_get, "GCTR");
  518. SNC_HANDLE_NAMES(CTR_set, "SCTR");
  519. SNC_HANDLE_NAMES(PCR_get, "GPCR");
  520. SNC_HANDLE_NAMES(PCR_set, "SPCR");
  521. SNC_HANDLE_NAMES(CMI_get, "GCMI");
  522. SNC_HANDLE_NAMES(CMI_set, "SCMI");
  523. static struct sony_nc_value sony_nc_values[] = {
  524. SNC_HANDLE(brightness_default, snc_brightness_def_get,
  525. snc_brightness_def_set, brightness_default_validate, 0),
  526. SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
  527. SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
  528. SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
  529. boolean_validate, 0),
  530. SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
  531. boolean_validate, 1),
  532. SNC_HANDLE(lidstate, snc_lidstate_get, NULL,
  533. boolean_validate, 0),
  534. SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set,
  535. boolean_validate, 0),
  536. SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set,
  537. boolean_validate, 0),
  538. /* unknown methods */
  539. SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
  540. SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
  541. SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
  542. SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
  543. SNC_HANDLE_NULL
  544. };
  545. static acpi_handle sony_nc_acpi_handle;
  546. static struct acpi_device *sony_nc_acpi_device = NULL;
  547. /*
  548. * acpi_evaluate_object wrappers
  549. */
  550. static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
  551. {
  552. struct acpi_buffer output;
  553. union acpi_object out_obj;
  554. acpi_status status;
  555. output.length = sizeof(out_obj);
  556. output.pointer = &out_obj;
  557. status = acpi_evaluate_object(handle, name, NULL, &output);
  558. if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
  559. *result = out_obj.integer.value;
  560. return 0;
  561. }
  562. printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n");
  563. return -1;
  564. }
  565. static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
  566. int *result)
  567. {
  568. struct acpi_object_list params;
  569. union acpi_object in_obj;
  570. struct acpi_buffer output;
  571. union acpi_object out_obj;
  572. acpi_status status;
  573. params.count = 1;
  574. params.pointer = &in_obj;
  575. in_obj.type = ACPI_TYPE_INTEGER;
  576. in_obj.integer.value = value;
  577. output.length = sizeof(out_obj);
  578. output.pointer = &out_obj;
  579. status = acpi_evaluate_object(handle, name, &params, &output);
  580. if (status == AE_OK) {
  581. if (result != NULL) {
  582. if (out_obj.type != ACPI_TYPE_INTEGER) {
  583. printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad "
  584. "return type\n");
  585. return -1;
  586. }
  587. *result = out_obj.integer.value;
  588. }
  589. return 0;
  590. }
  591. printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n");
  592. return -1;
  593. }
  594. /*
  595. * sony_nc_values input/output validate functions
  596. */
  597. /* brightness_default_validate:
  598. *
  599. * manipulate input output values to keep consistency with the
  600. * backlight framework for which brightness values are 0-based.
  601. */
  602. static int brightness_default_validate(const int direction, const int value)
  603. {
  604. switch (direction) {
  605. case SNC_VALIDATE_OUT:
  606. return value - 1;
  607. case SNC_VALIDATE_IN:
  608. if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
  609. return value + 1;
  610. }
  611. return -EINVAL;
  612. }
  613. /* boolean_validate:
  614. *
  615. * on input validate boolean values 0/1, on output just pass the
  616. * received value.
  617. */
  618. static int boolean_validate(const int direction, const int value)
  619. {
  620. if (direction == SNC_VALIDATE_IN) {
  621. if (value != 0 && value != 1)
  622. return -EINVAL;
  623. }
  624. return value;
  625. }
  626. /*
  627. * Sysfs show/store common to all sony_nc_values
  628. */
  629. static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
  630. char *buffer)
  631. {
  632. int value;
  633. struct sony_nc_value *item =
  634. container_of(attr, struct sony_nc_value, devattr);
  635. if (!*item->acpiget)
  636. return -EIO;
  637. if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
  638. return -EIO;
  639. if (item->validate)
  640. value = item->validate(SNC_VALIDATE_OUT, value);
  641. return snprintf(buffer, PAGE_SIZE, "%d\n", value);
  642. }
  643. static ssize_t sony_nc_sysfs_store(struct device *dev,
  644. struct device_attribute *attr,
  645. const char *buffer, size_t count)
  646. {
  647. int value;
  648. struct sony_nc_value *item =
  649. container_of(attr, struct sony_nc_value, devattr);
  650. if (!item->acpiset)
  651. return -EIO;
  652. if (count > 31)
  653. return -EINVAL;
  654. value = simple_strtoul(buffer, NULL, 10);
  655. if (item->validate)
  656. value = item->validate(SNC_VALIDATE_IN, value);
  657. if (value < 0)
  658. return value;
  659. if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
  660. return -EIO;
  661. item->value = value;
  662. item->valid = 1;
  663. return count;
  664. }
  665. /*
  666. * Backlight device
  667. */
  668. static int sony_backlight_update_status(struct backlight_device *bd)
  669. {
  670. return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
  671. bd->props.brightness + 1, NULL);
  672. }
  673. static int sony_backlight_get_brightness(struct backlight_device *bd)
  674. {
  675. int value;
  676. if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
  677. return 0;
  678. /* brightness levels are 1-based, while backlight ones are 0-based */
  679. return value - 1;
  680. }
  681. static struct backlight_device *sony_backlight_device;
  682. static struct backlight_ops sony_backlight_ops = {
  683. .update_status = sony_backlight_update_status,
  684. .get_brightness = sony_backlight_get_brightness,
  685. };
  686. /*
  687. * New SNC-only Vaios event mapping to driver known keys
  688. */
  689. struct sony_nc_event {
  690. u8 data;
  691. u8 event;
  692. };
  693. static struct sony_nc_event *sony_nc_events;
  694. /* Vaio C* --maybe also FE*, N* and AR* ?-- special init sequence
  695. * for Fn keys
  696. */
  697. static int sony_nc_C_enable(const struct dmi_system_id *id)
  698. {
  699. int result = 0;
  700. printk(KERN_NOTICE DRV_PFX "detected %s\n", id->ident);
  701. sony_nc_events = id->driver_data;
  702. if (acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x4, &result) < 0
  703. || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x2, &result) < 0
  704. || acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x10, &result) < 0
  705. || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x0, &result) < 0
  706. || acpi_callsetfunc(sony_nc_acpi_handle, "SN03", 0x2, &result) < 0
  707. || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x101, &result) < 0) {
  708. printk(KERN_WARNING DRV_PFX "failed to initialize SNC, some "
  709. "functionalities may be missing\n");
  710. return 1;
  711. }
  712. return 0;
  713. }
  714. static struct sony_nc_event sony_C_events[] = {
  715. { 0x81, SONYPI_EVENT_FNKEY_F1 },
  716. { 0x01, SONYPI_EVENT_FNKEY_RELEASED },
  717. { 0x85, SONYPI_EVENT_FNKEY_F5 },
  718. { 0x05, SONYPI_EVENT_FNKEY_RELEASED },
  719. { 0x86, SONYPI_EVENT_FNKEY_F6 },
  720. { 0x06, SONYPI_EVENT_FNKEY_RELEASED },
  721. { 0x87, SONYPI_EVENT_FNKEY_F7 },
  722. { 0x07, SONYPI_EVENT_FNKEY_RELEASED },
  723. { 0x8A, SONYPI_EVENT_FNKEY_F10 },
  724. { 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
  725. { 0x8C, SONYPI_EVENT_FNKEY_F12 },
  726. { 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
  727. { 0, 0 },
  728. };
  729. /* SNC-only model map */
  730. static const struct dmi_system_id sony_nc_ids[] = {
  731. {
  732. .ident = "Sony Vaio FE Series",
  733. .callback = sony_nc_C_enable,
  734. .driver_data = sony_C_events,
  735. .matches = {
  736. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  737. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FE"),
  738. },
  739. },
  740. {
  741. .ident = "Sony Vaio FZ Series",
  742. .callback = sony_nc_C_enable,
  743. .driver_data = sony_C_events,
  744. .matches = {
  745. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  746. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FZ"),
  747. },
  748. },
  749. {
  750. .ident = "Sony Vaio C Series",
  751. .callback = sony_nc_C_enable,
  752. .driver_data = sony_C_events,
  753. .matches = {
  754. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  755. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-C"),
  756. },
  757. },
  758. {
  759. .ident = "Sony Vaio N Series",
  760. .callback = sony_nc_C_enable,
  761. .driver_data = sony_C_events,
  762. .matches = {
  763. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  764. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-N"),
  765. },
  766. },
  767. { }
  768. };
  769. /*
  770. * ACPI callbacks
  771. */
  772. static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
  773. {
  774. struct sony_nc_event *evmap;
  775. u32 ev = event;
  776. int result;
  777. if (ev == 0x92) {
  778. /* read the key pressed from EC.GECR
  779. * A call to SN07 with 0x0202 will do it as well respecting
  780. * the current protocol on different OSes
  781. *
  782. * Note: the path for GECR may be
  783. * \_SB.PCI0.LPCB.EC (C, FE, AR, N and friends)
  784. * \_SB.PCI0.PIB.EC0 (VGN-FR notifications are sent directly, no GECR)
  785. *
  786. * TODO: we may want to do the same for the older GHKE -need
  787. * dmi list- so this snippet may become one more callback.
  788. */
  789. if (acpi_callsetfunc(handle, "SN07", 0x0202, &result) < 0)
  790. dprintk("sony_acpi_notify, unable to decode event 0x%.2x\n", ev);
  791. else
  792. ev = result & 0xFF;
  793. }
  794. if (sony_nc_events)
  795. for (evmap = sony_nc_events; evmap->event; evmap++) {
  796. if (evmap->data == ev) {
  797. ev = evmap->event;
  798. break;
  799. }
  800. }
  801. dprintk("sony_acpi_notify, event: 0x%.2x\n", ev);
  802. sony_laptop_report_input_event(ev);
  803. acpi_bus_generate_proc_event(sony_nc_acpi_device, 1, ev);
  804. }
  805. static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
  806. void *context, void **return_value)
  807. {
  808. struct acpi_namespace_node *node;
  809. union acpi_operand_object *operand;
  810. node = (struct acpi_namespace_node *)handle;
  811. operand = (union acpi_operand_object *)node->object;
  812. printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
  813. (u32) operand->method.param_count);
  814. return AE_OK;
  815. }
  816. /*
  817. * ACPI device
  818. */
  819. static int sony_nc_resume(struct acpi_device *device)
  820. {
  821. struct sony_nc_value *item;
  822. for (item = sony_nc_values; item->name; item++) {
  823. int ret;
  824. if (!item->valid)
  825. continue;
  826. ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
  827. item->value, NULL);
  828. if (ret < 0) {
  829. printk("%s: %d\n", __func__, ret);
  830. break;
  831. }
  832. }
  833. /* set the last requested brightness level */
  834. if (sony_backlight_device &&
  835. !sony_backlight_update_status(sony_backlight_device))
  836. printk(KERN_WARNING DRV_PFX "unable to restore brightness level\n");
  837. /* re-initialize models with specific requirements */
  838. dmi_check_system(sony_nc_ids);
  839. return 0;
  840. }
  841. static int sony_nc_add(struct acpi_device *device)
  842. {
  843. acpi_status status;
  844. int result = 0;
  845. acpi_handle handle;
  846. struct sony_nc_value *item;
  847. printk(KERN_INFO DRV_PFX "%s v%s.\n",
  848. SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
  849. sony_nc_acpi_device = device;
  850. strcpy(acpi_device_class(device), "sony/hotkey");
  851. sony_nc_acpi_handle = device->handle;
  852. /* read device status */
  853. result = acpi_bus_get_status(device);
  854. /* bail IFF the above call was successful and the device is not present */
  855. if (!result && !device->status.present) {
  856. dprintk("Device not present\n");
  857. result = -ENODEV;
  858. goto outwalk;
  859. }
  860. if (debug) {
  861. status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
  862. 1, sony_walk_callback, NULL, NULL);
  863. if (ACPI_FAILURE(status)) {
  864. printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
  865. result = -ENODEV;
  866. goto outwalk;
  867. }
  868. }
  869. /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1
  870. * should be respected as we already checked for the device presence above */
  871. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) {
  872. dprintk("Invoking _INI\n");
  873. if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI,
  874. NULL, NULL)))
  875. dprintk("_INI Method failed\n");
  876. }
  877. /* setup input devices and helper fifo */
  878. result = sony_laptop_setup_input(device);
  879. if (result) {
  880. printk(KERN_ERR DRV_PFX
  881. "Unabe to create input devices.\n");
  882. goto outwalk;
  883. }
  884. status = acpi_install_notify_handler(sony_nc_acpi_handle,
  885. ACPI_DEVICE_NOTIFY,
  886. sony_acpi_notify, NULL);
  887. if (ACPI_FAILURE(status)) {
  888. printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status);
  889. result = -ENODEV;
  890. goto outinput;
  891. }
  892. if (acpi_video_backlight_support()) {
  893. printk(KERN_INFO DRV_PFX "brightness ignored, must be "
  894. "controlled by ACPI video driver\n");
  895. } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT",
  896. &handle))) {
  897. sony_backlight_device = backlight_device_register("sony", NULL,
  898. NULL,
  899. &sony_backlight_ops);
  900. if (IS_ERR(sony_backlight_device)) {
  901. printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
  902. sony_backlight_device = NULL;
  903. } else {
  904. sony_backlight_device->props.brightness =
  905. sony_backlight_get_brightness
  906. (sony_backlight_device);
  907. sony_backlight_device->props.max_brightness =
  908. SONY_MAX_BRIGHTNESS - 1;
  909. }
  910. }
  911. /* initialize models with specific requirements */
  912. dmi_check_system(sony_nc_ids);
  913. result = sony_pf_add();
  914. if (result)
  915. goto outbacklight;
  916. /* create sony_pf sysfs attributes related to the SNC device */
  917. for (item = sony_nc_values; item->name; ++item) {
  918. if (!debug && item->debug)
  919. continue;
  920. /* find the available acpiget as described in the DSDT */
  921. for (; item->acpiget && *item->acpiget; ++item->acpiget) {
  922. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
  923. *item->acpiget,
  924. &handle))) {
  925. dprintk("Found %s getter: %s\n",
  926. item->name, *item->acpiget);
  927. item->devattr.attr.mode |= S_IRUGO;
  928. break;
  929. }
  930. }
  931. /* find the available acpiset as described in the DSDT */
  932. for (; item->acpiset && *item->acpiset; ++item->acpiset) {
  933. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
  934. *item->acpiset,
  935. &handle))) {
  936. dprintk("Found %s setter: %s\n",
  937. item->name, *item->acpiset);
  938. item->devattr.attr.mode |= S_IWUSR;
  939. break;
  940. }
  941. }
  942. if (item->devattr.attr.mode != 0) {
  943. result =
  944. device_create_file(&sony_pf_device->dev,
  945. &item->devattr);
  946. if (result)
  947. goto out_sysfs;
  948. }
  949. }
  950. return 0;
  951. out_sysfs:
  952. for (item = sony_nc_values; item->name; ++item) {
  953. device_remove_file(&sony_pf_device->dev, &item->devattr);
  954. }
  955. sony_pf_remove();
  956. outbacklight:
  957. if (sony_backlight_device)
  958. backlight_device_unregister(sony_backlight_device);
  959. status = acpi_remove_notify_handler(sony_nc_acpi_handle,
  960. ACPI_DEVICE_NOTIFY,
  961. sony_acpi_notify);
  962. if (ACPI_FAILURE(status))
  963. printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
  964. outinput:
  965. sony_laptop_remove_input();
  966. outwalk:
  967. return result;
  968. }
  969. static int sony_nc_remove(struct acpi_device *device, int type)
  970. {
  971. acpi_status status;
  972. struct sony_nc_value *item;
  973. if (sony_backlight_device)
  974. backlight_device_unregister(sony_backlight_device);
  975. sony_nc_acpi_device = NULL;
  976. status = acpi_remove_notify_handler(sony_nc_acpi_handle,
  977. ACPI_DEVICE_NOTIFY,
  978. sony_acpi_notify);
  979. if (ACPI_FAILURE(status))
  980. printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
  981. for (item = sony_nc_values; item->name; ++item) {
  982. device_remove_file(&sony_pf_device->dev, &item->devattr);
  983. }
  984. sony_pf_remove();
  985. sony_laptop_remove_input();
  986. dprintk(SONY_NC_DRIVER_NAME " removed.\n");
  987. return 0;
  988. }
  989. static const struct acpi_device_id sony_device_ids[] = {
  990. {SONY_NC_HID, 0},
  991. {SONY_PIC_HID, 0},
  992. {"", 0},
  993. };
  994. MODULE_DEVICE_TABLE(acpi, sony_device_ids);
  995. static const struct acpi_device_id sony_nc_device_ids[] = {
  996. {SONY_NC_HID, 0},
  997. {"", 0},
  998. };
  999. static struct acpi_driver sony_nc_driver = {
  1000. .name = SONY_NC_DRIVER_NAME,
  1001. .class = SONY_NC_CLASS,
  1002. .ids = sony_nc_device_ids,
  1003. .owner = THIS_MODULE,
  1004. .ops = {
  1005. .add = sony_nc_add,
  1006. .remove = sony_nc_remove,
  1007. .resume = sony_nc_resume,
  1008. },
  1009. };
  1010. /*********** SPIC (SNY6001) Device ***********/
  1011. #define SONYPI_DEVICE_TYPE1 0x00000001
  1012. #define SONYPI_DEVICE_TYPE2 0x00000002
  1013. #define SONYPI_DEVICE_TYPE3 0x00000004
  1014. #define SONYPI_DEVICE_TYPE4 0x00000008
  1015. #define SONYPI_TYPE1_OFFSET 0x04
  1016. #define SONYPI_TYPE2_OFFSET 0x12
  1017. #define SONYPI_TYPE3_OFFSET 0x12
  1018. #define SONYPI_TYPE4_OFFSET 0x12
  1019. struct sony_pic_ioport {
  1020. struct acpi_resource_io io1;
  1021. struct acpi_resource_io io2;
  1022. struct list_head list;
  1023. };
  1024. struct sony_pic_irq {
  1025. struct acpi_resource_irq irq;
  1026. struct list_head list;
  1027. };
  1028. struct sonypi_eventtypes {
  1029. u8 data;
  1030. unsigned long mask;
  1031. struct sonypi_event *events;
  1032. };
  1033. struct device_ctrl {
  1034. int model;
  1035. int (*handle_irq)(const u8, const u8);
  1036. u16 evport_offset;
  1037. u8 has_camera;
  1038. u8 has_bluetooth;
  1039. u8 has_wwan;
  1040. struct sonypi_eventtypes *event_types;
  1041. };
  1042. struct sony_pic_dev {
  1043. struct device_ctrl *control;
  1044. struct acpi_device *acpi_dev;
  1045. struct sony_pic_irq *cur_irq;
  1046. struct sony_pic_ioport *cur_ioport;
  1047. struct list_head interrupts;
  1048. struct list_head ioports;
  1049. struct mutex lock;
  1050. u8 camera_power;
  1051. u8 bluetooth_power;
  1052. u8 wwan_power;
  1053. };
  1054. static struct sony_pic_dev spic_dev = {
  1055. .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
  1056. .ioports = LIST_HEAD_INIT(spic_dev.ioports),
  1057. };
  1058. /* Event masks */
  1059. #define SONYPI_JOGGER_MASK 0x00000001
  1060. #define SONYPI_CAPTURE_MASK 0x00000002
  1061. #define SONYPI_FNKEY_MASK 0x00000004
  1062. #define SONYPI_BLUETOOTH_MASK 0x00000008
  1063. #define SONYPI_PKEY_MASK 0x00000010
  1064. #define SONYPI_BACK_MASK 0x00000020
  1065. #define SONYPI_HELP_MASK 0x00000040
  1066. #define SONYPI_LID_MASK 0x00000080
  1067. #define SONYPI_ZOOM_MASK 0x00000100
  1068. #define SONYPI_THUMBPHRASE_MASK 0x00000200
  1069. #define SONYPI_MEYE_MASK 0x00000400
  1070. #define SONYPI_MEMORYSTICK_MASK 0x00000800
  1071. #define SONYPI_BATTERY_MASK 0x00001000
  1072. #define SONYPI_WIRELESS_MASK 0x00002000
  1073. struct sonypi_event {
  1074. u8 data;
  1075. u8 event;
  1076. };
  1077. /* The set of possible button release events */
  1078. static struct sonypi_event sonypi_releaseev[] = {
  1079. { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
  1080. { 0, 0 }
  1081. };
  1082. /* The set of possible jogger events */
  1083. static struct sonypi_event sonypi_joggerev[] = {
  1084. { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
  1085. { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
  1086. { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
  1087. { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
  1088. { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
  1089. { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
  1090. { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
  1091. { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
  1092. { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
  1093. { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
  1094. { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
  1095. { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
  1096. { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
  1097. { 0, 0 }
  1098. };
  1099. /* The set of possible capture button events */
  1100. static struct sonypi_event sonypi_captureev[] = {
  1101. { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
  1102. { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
  1103. { 0x40, SONYPI_EVENT_CAPTURE_PRESSED },
  1104. { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
  1105. { 0, 0 }
  1106. };
  1107. /* The set of possible fnkeys events */
  1108. static struct sonypi_event sonypi_fnkeyev[] = {
  1109. { 0x10, SONYPI_EVENT_FNKEY_ESC },
  1110. { 0x11, SONYPI_EVENT_FNKEY_F1 },
  1111. { 0x12, SONYPI_EVENT_FNKEY_F2 },
  1112. { 0x13, SONYPI_EVENT_FNKEY_F3 },
  1113. { 0x14, SONYPI_EVENT_FNKEY_F4 },
  1114. { 0x15, SONYPI_EVENT_FNKEY_F5 },
  1115. { 0x16, SONYPI_EVENT_FNKEY_F6 },
  1116. { 0x17, SONYPI_EVENT_FNKEY_F7 },
  1117. { 0x18, SONYPI_EVENT_FNKEY_F8 },
  1118. { 0x19, SONYPI_EVENT_FNKEY_F9 },
  1119. { 0x1a, SONYPI_EVENT_FNKEY_F10 },
  1120. { 0x1b, SONYPI_EVENT_FNKEY_F11 },
  1121. { 0x1c, SONYPI_EVENT_FNKEY_F12 },
  1122. { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
  1123. { 0x21, SONYPI_EVENT_FNKEY_1 },
  1124. { 0x22, SONYPI_EVENT_FNKEY_2 },
  1125. { 0x31, SONYPI_EVENT_FNKEY_D },
  1126. { 0x32, SONYPI_EVENT_FNKEY_E },
  1127. { 0x33, SONYPI_EVENT_FNKEY_F },
  1128. { 0x34, SONYPI_EVENT_FNKEY_S },
  1129. { 0x35, SONYPI_EVENT_FNKEY_B },
  1130. { 0x36, SONYPI_EVENT_FNKEY_ONLY },
  1131. { 0, 0 }
  1132. };
  1133. /* The set of possible program key events */
  1134. static struct sonypi_event sonypi_pkeyev[] = {
  1135. { 0x01, SONYPI_EVENT_PKEY_P1 },
  1136. { 0x02, SONYPI_EVENT_PKEY_P2 },
  1137. { 0x04, SONYPI_EVENT_PKEY_P3 },
  1138. { 0, 0 }
  1139. };
  1140. /* The set of possible bluetooth events */
  1141. static struct sonypi_event sonypi_blueev[] = {
  1142. { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
  1143. { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
  1144. { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
  1145. { 0, 0 }
  1146. };
  1147. /* The set of possible wireless events */
  1148. static struct sonypi_event sonypi_wlessev[] = {
  1149. { 0x59, SONYPI_EVENT_WIRELESS_ON },
  1150. { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
  1151. { 0, 0 }
  1152. };
  1153. /* The set of possible back button events */
  1154. static struct sonypi_event sonypi_backev[] = {
  1155. { 0x20, SONYPI_EVENT_BACK_PRESSED },
  1156. { 0, 0 }
  1157. };
  1158. /* The set of possible help button events */
  1159. static struct sonypi_event sonypi_helpev[] = {
  1160. { 0x3b, SONYPI_EVENT_HELP_PRESSED },
  1161. { 0, 0 }
  1162. };
  1163. /* The set of possible lid events */
  1164. static struct sonypi_event sonypi_lidev[] = {
  1165. { 0x51, SONYPI_EVENT_LID_CLOSED },
  1166. { 0x50, SONYPI_EVENT_LID_OPENED },
  1167. { 0, 0 }
  1168. };
  1169. /* The set of possible zoom events */
  1170. static struct sonypi_event sonypi_zoomev[] = {
  1171. { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
  1172. { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED },
  1173. { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED },
  1174. { 0, 0 }
  1175. };
  1176. /* The set of possible thumbphrase events */
  1177. static struct sonypi_event sonypi_thumbphraseev[] = {
  1178. { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
  1179. { 0, 0 }
  1180. };
  1181. /* The set of possible motioneye camera events */
  1182. static struct sonypi_event sonypi_meyeev[] = {
  1183. { 0x00, SONYPI_EVENT_MEYE_FACE },
  1184. { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
  1185. { 0, 0 }
  1186. };
  1187. /* The set of possible memorystick events */
  1188. static struct sonypi_event sonypi_memorystickev[] = {
  1189. { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
  1190. { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
  1191. { 0, 0 }
  1192. };
  1193. /* The set of possible battery events */
  1194. static struct sonypi_event sonypi_batteryev[] = {
  1195. { 0x20, SONYPI_EVENT_BATTERY_INSERT },
  1196. { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
  1197. { 0, 0 }
  1198. };
  1199. static struct sonypi_eventtypes type1_events[] = {
  1200. { 0, 0xffffffff, sonypi_releaseev },
  1201. { 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
  1202. { 0x30, SONYPI_LID_MASK, sonypi_lidev },
  1203. { 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
  1204. { 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
  1205. { 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1206. { 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
  1207. { 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1208. { 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1209. { 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1210. { 0 },
  1211. };
  1212. static struct sonypi_eventtypes type2_events[] = {
  1213. { 0, 0xffffffff, sonypi_releaseev },
  1214. { 0x38, SONYPI_LID_MASK, sonypi_lidev },
  1215. { 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
  1216. { 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
  1217. { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1218. { 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
  1219. { 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1220. { 0x11, SONYPI_BACK_MASK, sonypi_backev },
  1221. { 0x21, SONYPI_HELP_MASK, sonypi_helpev },
  1222. { 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
  1223. { 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
  1224. { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1225. { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1226. { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1227. { 0 },
  1228. };
  1229. static struct sonypi_eventtypes type3_events[] = {
  1230. { 0, 0xffffffff, sonypi_releaseev },
  1231. { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1232. { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
  1233. { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1234. { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1235. { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1236. { 0 },
  1237. };
  1238. static struct sonypi_eventtypes type4_events[] = {
  1239. { 0, 0xffffffff, sonypi_releaseev },
  1240. { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1241. { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
  1242. { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1243. { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1244. { 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1245. { 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev },
  1246. { 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev },
  1247. { 0 },
  1248. };
  1249. /* low level spic calls */
  1250. #define ITERATIONS_LONG 10000
  1251. #define ITERATIONS_SHORT 10
  1252. #define wait_on_command(command, iterations) { \
  1253. unsigned int n = iterations; \
  1254. while (--n && (command)) \
  1255. udelay(1); \
  1256. if (!n) \
  1257. dprintk("command failed at %s : %s (line %d)\n", \
  1258. __FILE__, __func__, __LINE__); \
  1259. }
  1260. static u8 sony_pic_call1(u8 dev)
  1261. {
  1262. u8 v1, v2;
  1263. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
  1264. ITERATIONS_LONG);
  1265. outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
  1266. v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4);
  1267. v2 = inb_p(spic_dev.cur_ioport->io1.minimum);
  1268. dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1);
  1269. return v2;
  1270. }
  1271. static u8 sony_pic_call2(u8 dev, u8 fn)
  1272. {
  1273. u8 v1;
  1274. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
  1275. ITERATIONS_LONG);
  1276. outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
  1277. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
  1278. ITERATIONS_LONG);
  1279. outb(fn, spic_dev.cur_ioport->io1.minimum);
  1280. v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
  1281. dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1);
  1282. return v1;
  1283. }
  1284. static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
  1285. {
  1286. u8 v1;
  1287. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
  1288. outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
  1289. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
  1290. outb(fn, spic_dev.cur_ioport->io1.minimum);
  1291. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
  1292. outb(v, spic_dev.cur_ioport->io1.minimum);
  1293. v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
  1294. dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
  1295. dev, fn, v, v1);
  1296. return v1;
  1297. }
  1298. /*
  1299. * minidrivers for SPIC models
  1300. */
  1301. static int type4_handle_irq(const u8 data_mask, const u8 ev)
  1302. {
  1303. /*
  1304. * 0x31 could mean we have to take some extra action and wait for
  1305. * the next irq for some Type4 models, it will generate a new
  1306. * irq and we can read new data from the device:
  1307. * - 0x5c and 0x5f requires 0xA0
  1308. * - 0x61 requires 0xB3
  1309. */
  1310. if (data_mask == 0x31) {
  1311. if (ev == 0x5c || ev == 0x5f)
  1312. sony_pic_call1(0xA0);
  1313. else if (ev == 0x61)
  1314. sony_pic_call1(0xB3);
  1315. return 0;
  1316. }
  1317. return 1;
  1318. }
  1319. static struct device_ctrl spic_types[] = {
  1320. {
  1321. .model = SONYPI_DEVICE_TYPE1,
  1322. .handle_irq = NULL,
  1323. .evport_offset = SONYPI_TYPE1_OFFSET,
  1324. .event_types = type1_events,
  1325. },
  1326. {
  1327. .model = SONYPI_DEVICE_TYPE2,
  1328. .handle_irq = NULL,
  1329. .evport_offset = SONYPI_TYPE2_OFFSET,
  1330. .event_types = type2_events,
  1331. },
  1332. {
  1333. .model = SONYPI_DEVICE_TYPE3,
  1334. .handle_irq = NULL,
  1335. .evport_offset = SONYPI_TYPE3_OFFSET,
  1336. .event_types = type3_events,
  1337. },
  1338. {
  1339. .model = SONYPI_DEVICE_TYPE4,
  1340. .handle_irq = type4_handle_irq,
  1341. .evport_offset = SONYPI_TYPE4_OFFSET,
  1342. .event_types = type4_events,
  1343. },
  1344. };
  1345. static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
  1346. {
  1347. struct pci_dev *pcidev;
  1348. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1349. PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
  1350. if (pcidev) {
  1351. dev->control = &spic_types[0];
  1352. goto out;
  1353. }
  1354. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1355. PCI_DEVICE_ID_INTEL_ICH6_1, NULL);
  1356. if (pcidev) {
  1357. dev->control = &spic_types[2];
  1358. goto out;
  1359. }
  1360. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1361. PCI_DEVICE_ID_INTEL_ICH7_1, NULL);
  1362. if (pcidev) {
  1363. dev->control = &spic_types[3];
  1364. goto out;
  1365. }
  1366. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1367. PCI_DEVICE_ID_INTEL_ICH8_4, NULL);
  1368. if (pcidev) {
  1369. dev->control = &spic_types[3];
  1370. goto out;
  1371. }
  1372. /* default */
  1373. dev->control = &spic_types[1];
  1374. out:
  1375. if (pcidev)
  1376. pci_dev_put(pcidev);
  1377. printk(KERN_INFO DRV_PFX "detected Type%d model\n",
  1378. dev->control->model == SONYPI_DEVICE_TYPE1 ? 1 :
  1379. dev->control->model == SONYPI_DEVICE_TYPE2 ? 2 :
  1380. dev->control->model == SONYPI_DEVICE_TYPE3 ? 3 : 4);
  1381. }
  1382. /* camera tests and poweron/poweroff */
  1383. #define SONYPI_CAMERA_PICTURE 5
  1384. #define SONYPI_CAMERA_CONTROL 0x10
  1385. #define SONYPI_CAMERA_BRIGHTNESS 0
  1386. #define SONYPI_CAMERA_CONTRAST 1
  1387. #define SONYPI_CAMERA_HUE 2
  1388. #define SONYPI_CAMERA_COLOR 3
  1389. #define SONYPI_CAMERA_SHARPNESS 4
  1390. #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
  1391. #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
  1392. #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
  1393. #define SONYPI_CAMERA_MUTE_MASK 0x40
  1394. /* the rest don't need a loop until not 0xff */
  1395. #define SONYPI_CAMERA_AGC 6
  1396. #define SONYPI_CAMERA_AGC_MASK 0x30
  1397. #define SONYPI_CAMERA_SHUTTER_MASK 0x7
  1398. #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
  1399. #define SONYPI_CAMERA_CONTROL 0x10
  1400. #define SONYPI_CAMERA_STATUS 7
  1401. #define SONYPI_CAMERA_STATUS_READY 0x2
  1402. #define SONYPI_CAMERA_STATUS_POSITION 0x4
  1403. #define SONYPI_DIRECTION_BACKWARDS 0x4
  1404. #define SONYPI_CAMERA_REVISION 8
  1405. #define SONYPI_CAMERA_ROMVERSION 9
  1406. static int __sony_pic_camera_ready(void)
  1407. {
  1408. u8 v;
  1409. v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
  1410. return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
  1411. }
  1412. static int __sony_pic_camera_off(void)
  1413. {
  1414. if (!camera) {
  1415. printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
  1416. return -ENODEV;
  1417. }
  1418. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
  1419. SONYPI_CAMERA_MUTE_MASK),
  1420. ITERATIONS_SHORT);
  1421. if (spic_dev.camera_power) {
  1422. sony_pic_call2(0x91, 0);
  1423. spic_dev.camera_power = 0;
  1424. }
  1425. return 0;
  1426. }
  1427. static int __sony_pic_camera_on(void)
  1428. {
  1429. int i, j, x;
  1430. if (!camera) {
  1431. printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
  1432. return -ENODEV;
  1433. }
  1434. if (spic_dev.camera_power)
  1435. return 0;
  1436. for (j = 5; j > 0; j--) {
  1437. for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
  1438. msleep(10);
  1439. sony_pic_call1(0x93);
  1440. for (i = 400; i > 0; i--) {
  1441. if (__sony_pic_camera_ready())
  1442. break;
  1443. msleep(10);
  1444. }
  1445. if (i)
  1446. break;
  1447. }
  1448. if (j == 0) {
  1449. printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
  1450. return -ENODEV;
  1451. }
  1452. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
  1453. 0x5a),
  1454. ITERATIONS_SHORT);
  1455. spic_dev.camera_power = 1;
  1456. return 0;
  1457. }
  1458. /* External camera command (exported to the motion eye v4l driver) */
  1459. int sony_pic_camera_command(int command, u8 value)
  1460. {
  1461. if (!camera)
  1462. return -EIO;
  1463. mutex_lock(&spic_dev.lock);
  1464. switch (command) {
  1465. case SONY_PIC_COMMAND_SETCAMERA:
  1466. if (value)
  1467. __sony_pic_camera_on();
  1468. else
  1469. __sony_pic_camera_off();
  1470. break;
  1471. case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
  1472. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
  1473. ITERATIONS_SHORT);
  1474. break;
  1475. case SONY_PIC_COMMAND_SETCAMERACONTRAST:
  1476. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
  1477. ITERATIONS_SHORT);
  1478. break;
  1479. case SONY_PIC_COMMAND_SETCAMERAHUE:
  1480. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
  1481. ITERATIONS_SHORT);
  1482. break;
  1483. case SONY_PIC_COMMAND_SETCAMERACOLOR:
  1484. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
  1485. ITERATIONS_SHORT);
  1486. break;
  1487. case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
  1488. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
  1489. ITERATIONS_SHORT);
  1490. break;
  1491. case SONY_PIC_COMMAND_SETCAMERAPICTURE:
  1492. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
  1493. ITERATIONS_SHORT);
  1494. break;
  1495. case SONY_PIC_COMMAND_SETCAMERAAGC:
  1496. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
  1497. ITERATIONS_SHORT);
  1498. break;
  1499. default:
  1500. printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
  1501. command);
  1502. break;
  1503. }
  1504. mutex_unlock(&spic_dev.lock);
  1505. return 0;
  1506. }
  1507. EXPORT_SYMBOL(sony_pic_camera_command);
  1508. /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
  1509. static void sony_pic_set_wwanpower(u8 state)
  1510. {
  1511. state = !!state;
  1512. mutex_lock(&spic_dev.lock);
  1513. if (spic_dev.wwan_power == state) {
  1514. mutex_unlock(&spic_dev.lock);
  1515. return;
  1516. }
  1517. sony_pic_call2(0xB0, state);
  1518. spic_dev.wwan_power = state;
  1519. mutex_unlock(&spic_dev.lock);
  1520. }
  1521. static ssize_t sony_pic_wwanpower_store(struct device *dev,
  1522. struct device_attribute *attr,
  1523. const char *buffer, size_t count)
  1524. {
  1525. unsigned long value;
  1526. if (count > 31)
  1527. return -EINVAL;
  1528. value = simple_strtoul(buffer, NULL, 10);
  1529. sony_pic_set_wwanpower(value);
  1530. return count;
  1531. }
  1532. static ssize_t sony_pic_wwanpower_show(struct device *dev,
  1533. struct device_attribute *attr, char *buffer)
  1534. {
  1535. ssize_t count;
  1536. mutex_lock(&spic_dev.lock);
  1537. count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
  1538. mutex_unlock(&spic_dev.lock);
  1539. return count;
  1540. }
  1541. /* bluetooth subsystem power state */
  1542. static void __sony_pic_set_bluetoothpower(u8 state)
  1543. {
  1544. state = !!state;
  1545. if (spic_dev.bluetooth_power == state)
  1546. return;
  1547. sony_pic_call2(0x96, state);
  1548. sony_pic_call1(0x82);
  1549. spic_dev.bluetooth_power = state;
  1550. }
  1551. static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
  1552. struct device_attribute *attr,
  1553. const char *buffer, size_t count)
  1554. {
  1555. unsigned long value;
  1556. if (count > 31)
  1557. return -EINVAL;
  1558. value = simple_strtoul(buffer, NULL, 10);
  1559. mutex_lock(&spic_dev.lock);
  1560. __sony_pic_set_bluetoothpower(value);
  1561. mutex_unlock(&spic_dev.lock);
  1562. return count;
  1563. }
  1564. static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
  1565. struct device_attribute *attr, char *buffer)
  1566. {
  1567. ssize_t count = 0;
  1568. mutex_lock(&spic_dev.lock);
  1569. count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
  1570. mutex_unlock(&spic_dev.lock);
  1571. return count;
  1572. }
  1573. /* fan speed */
  1574. /* FAN0 information (reverse engineered from ACPI tables) */
  1575. #define SONY_PIC_FAN0_STATUS 0x93
  1576. static int sony_pic_set_fanspeed(unsigned long value)
  1577. {
  1578. return ec_write(SONY_PIC_FAN0_STATUS, value);
  1579. }
  1580. static int sony_pic_get_fanspeed(u8 *value)
  1581. {
  1582. return ec_read(SONY_PIC_FAN0_STATUS, value);
  1583. }
  1584. static ssize_t sony_pic_fanspeed_store(struct device *dev,
  1585. struct device_attribute *attr,
  1586. const char *buffer, size_t count)
  1587. {
  1588. unsigned long value;
  1589. if (count > 31)
  1590. return -EINVAL;
  1591. value = simple_strtoul(buffer, NULL, 10);
  1592. if (sony_pic_set_fanspeed(value))
  1593. return -EIO;
  1594. return count;
  1595. }
  1596. static ssize_t sony_pic_fanspeed_show(struct device *dev,
  1597. struct device_attribute *attr, char *buffer)
  1598. {
  1599. u8 value = 0;
  1600. if (sony_pic_get_fanspeed(&value))
  1601. return -EIO;
  1602. return snprintf(buffer, PAGE_SIZE, "%d\n", value);
  1603. }
  1604. #define SPIC_ATTR(_name, _mode) \
  1605. struct device_attribute spic_attr_##_name = __ATTR(_name, \
  1606. _mode, sony_pic_## _name ##_show, \
  1607. sony_pic_## _name ##_store)
  1608. static SPIC_ATTR(bluetoothpower, 0644);
  1609. static SPIC_ATTR(wwanpower, 0644);
  1610. static SPIC_ATTR(fanspeed, 0644);
  1611. static struct attribute *spic_attributes[] = {
  1612. &spic_attr_bluetoothpower.attr,
  1613. &spic_attr_wwanpower.attr,
  1614. &spic_attr_fanspeed.attr,
  1615. NULL
  1616. };
  1617. static struct attribute_group spic_attribute_group = {
  1618. .attrs = spic_attributes
  1619. };
  1620. /******** SONYPI compatibility **********/
  1621. #ifdef CONFIG_SONYPI_COMPAT
  1622. /* battery / brightness / temperature addresses */
  1623. #define SONYPI_BAT_FLAGS 0x81
  1624. #define SONYPI_LCD_LIGHT 0x96
  1625. #define SONYPI_BAT1_PCTRM 0xa0
  1626. #define SONYPI_BAT1_LEFT 0xa2
  1627. #define SONYPI_BAT1_MAXRT 0xa4
  1628. #define SONYPI_BAT2_PCTRM 0xa8
  1629. #define SONYPI_BAT2_LEFT 0xaa
  1630. #define SONYPI_BAT2_MAXRT 0xac
  1631. #define SONYPI_BAT1_MAXTK 0xb0
  1632. #define SONYPI_BAT1_FULL 0xb2
  1633. #define SONYPI_BAT2_MAXTK 0xb8
  1634. #define SONYPI_BAT2_FULL 0xba
  1635. #define SONYPI_TEMP_STATUS 0xC1
  1636. struct sonypi_compat_s {
  1637. struct fasync_struct *fifo_async;
  1638. struct kfifo *fifo;
  1639. spinlock_t fifo_lock;
  1640. wait_queue_head_t fifo_proc_list;
  1641. atomic_t open_count;
  1642. };
  1643. static struct sonypi_compat_s sonypi_compat = {
  1644. .open_count = ATOMIC_INIT(0),
  1645. };
  1646. static int sonypi_misc_fasync(int fd, struct file *filp, int on)
  1647. {
  1648. int retval;
  1649. retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
  1650. if (retval < 0)
  1651. return retval;
  1652. return 0;
  1653. }
  1654. static int sonypi_misc_release(struct inode *inode, struct file *file)
  1655. {
  1656. atomic_dec(&sonypi_compat.open_count);
  1657. return 0;
  1658. }
  1659. static int sonypi_misc_open(struct inode *inode, struct file *file)
  1660. {
  1661. /* Flush input queue on first open */
  1662. lock_kernel();
  1663. if (atomic_inc_return(&sonypi_compat.open_count) == 1)
  1664. kfifo_reset(sonypi_compat.fifo);
  1665. unlock_kernel();
  1666. return 0;
  1667. }
  1668. static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
  1669. size_t count, loff_t *pos)
  1670. {
  1671. ssize_t ret;
  1672. unsigned char c;
  1673. if ((kfifo_len(sonypi_compat.fifo) == 0) &&
  1674. (file->f_flags & O_NONBLOCK))
  1675. return -EAGAIN;
  1676. ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
  1677. kfifo_len(sonypi_compat.fifo) != 0);
  1678. if (ret)
  1679. return ret;
  1680. while (ret < count &&
  1681. (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
  1682. if (put_user(c, buf++))
  1683. return -EFAULT;
  1684. ret++;
  1685. }
  1686. if (ret > 0) {
  1687. struct inode *inode = file->f_path.dentry->d_inode;
  1688. inode->i_atime = current_fs_time(inode->i_sb);
  1689. }
  1690. return ret;
  1691. }
  1692. static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
  1693. {
  1694. poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
  1695. if (kfifo_len(sonypi_compat.fifo))
  1696. return POLLIN | POLLRDNORM;
  1697. return 0;
  1698. }
  1699. static int ec_read16(u8 addr, u16 *value)
  1700. {
  1701. u8 val_lb, val_hb;
  1702. if (ec_read(addr, &val_lb))
  1703. return -1;
  1704. if (ec_read(addr + 1, &val_hb))
  1705. return -1;
  1706. *value = val_lb | (val_hb << 8);
  1707. return 0;
  1708. }
  1709. static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
  1710. unsigned int cmd, unsigned long arg)
  1711. {
  1712. int ret = 0;
  1713. void __user *argp = (void __user *)arg;
  1714. u8 val8;
  1715. u16 val16;
  1716. int value;
  1717. mutex_lock(&spic_dev.lock);
  1718. switch (cmd) {
  1719. case SONYPI_IOCGBRT:
  1720. if (sony_backlight_device == NULL) {
  1721. ret = -EIO;
  1722. break;
  1723. }
  1724. if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
  1725. ret = -EIO;
  1726. break;
  1727. }
  1728. val8 = ((value & 0xff) - 1) << 5;
  1729. if (copy_to_user(argp, &val8, sizeof(val8)))
  1730. ret = -EFAULT;
  1731. break;
  1732. case SONYPI_IOCSBRT:
  1733. if (sony_backlight_device == NULL) {
  1734. ret = -EIO;
  1735. break;
  1736. }
  1737. if (copy_from_user(&val8, argp, sizeof(val8))) {
  1738. ret = -EFAULT;
  1739. break;
  1740. }
  1741. if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
  1742. (val8 >> 5) + 1, NULL)) {
  1743. ret = -EIO;
  1744. break;
  1745. }
  1746. /* sync the backlight device status */
  1747. sony_backlight_device->props.brightness =
  1748. sony_backlight_get_brightness(sony_backlight_device);
  1749. break;
  1750. case SONYPI_IOCGBAT1CAP:
  1751. if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
  1752. ret = -EIO;
  1753. break;
  1754. }
  1755. if (copy_to_user(argp, &val16, sizeof(val16)))
  1756. ret = -EFAULT;
  1757. break;
  1758. case SONYPI_IOCGBAT1REM:
  1759. if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
  1760. ret = -EIO;
  1761. break;
  1762. }
  1763. if (copy_to_user(argp, &val16, sizeof(val16)))
  1764. ret = -EFAULT;
  1765. break;
  1766. case SONYPI_IOCGBAT2CAP:
  1767. if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
  1768. ret = -EIO;
  1769. break;
  1770. }
  1771. if (copy_to_user(argp, &val16, sizeof(val16)))
  1772. ret = -EFAULT;
  1773. break;
  1774. case SONYPI_IOCGBAT2REM:
  1775. if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
  1776. ret = -EIO;
  1777. break;
  1778. }
  1779. if (copy_to_user(argp, &val16, sizeof(val16)))
  1780. ret = -EFAULT;
  1781. break;
  1782. case SONYPI_IOCGBATFLAGS:
  1783. if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
  1784. ret = -EIO;
  1785. break;
  1786. }
  1787. val8 &= 0x07;
  1788. if (copy_to_user(argp, &val8, sizeof(val8)))
  1789. ret = -EFAULT;
  1790. break;
  1791. case SONYPI_IOCGBLUE:
  1792. val8 = spic_dev.bluetooth_power;
  1793. if (copy_to_user(argp, &val8, sizeof(val8)))
  1794. ret = -EFAULT;
  1795. break;
  1796. case SONYPI_IOCSBLUE:
  1797. if (copy_from_user(&val8, argp, sizeof(val8))) {
  1798. ret = -EFAULT;
  1799. break;
  1800. }
  1801. __sony_pic_set_bluetoothpower(val8);
  1802. break;
  1803. /* FAN Controls */
  1804. case SONYPI_IOCGFAN:
  1805. if (sony_pic_get_fanspeed(&val8)) {
  1806. ret = -EIO;
  1807. break;
  1808. }
  1809. if (copy_to_user(argp, &val8, sizeof(val8)))
  1810. ret = -EFAULT;
  1811. break;
  1812. case SONYPI_IOCSFAN:
  1813. if (copy_from_user(&val8, argp, sizeof(val8))) {
  1814. ret = -EFAULT;
  1815. break;
  1816. }
  1817. if (sony_pic_set_fanspeed(val8))
  1818. ret = -EIO;
  1819. break;
  1820. /* GET Temperature (useful under APM) */
  1821. case SONYPI_IOCGTEMP:
  1822. if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
  1823. ret = -EIO;
  1824. break;
  1825. }
  1826. if (copy_to_user(argp, &val8, sizeof(val8)))
  1827. ret = -EFAULT;
  1828. break;
  1829. default:
  1830. ret = -EINVAL;
  1831. }
  1832. mutex_unlock(&spic_dev.lock);
  1833. return ret;
  1834. }
  1835. static const struct file_operations sonypi_misc_fops = {
  1836. .owner = THIS_MODULE,
  1837. .read = sonypi_misc_read,
  1838. .poll = sonypi_misc_poll,
  1839. .open = sonypi_misc_open,
  1840. .release = sonypi_misc_release,
  1841. .fasync = sonypi_misc_fasync,
  1842. .ioctl = sonypi_misc_ioctl,
  1843. };
  1844. static struct miscdevice sonypi_misc_device = {
  1845. .minor = MISC_DYNAMIC_MINOR,
  1846. .name = "sonypi",
  1847. .fops = &sonypi_misc_fops,
  1848. };
  1849. static void sonypi_compat_report_event(u8 event)
  1850. {
  1851. kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
  1852. kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
  1853. wake_up_interruptible(&sonypi_compat.fifo_proc_list);
  1854. }
  1855. static int sonypi_compat_init(void)
  1856. {
  1857. int error;
  1858. spin_lock_init(&sonypi_compat.fifo_lock);
  1859. sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
  1860. &sonypi_compat.fifo_lock);
  1861. if (IS_ERR(sonypi_compat.fifo)) {
  1862. printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
  1863. return PTR_ERR(sonypi_compat.fifo);
  1864. }
  1865. init_waitqueue_head(&sonypi_compat.fifo_proc_list);
  1866. if (minor != -1)
  1867. sonypi_misc_device.minor = minor;
  1868. error = misc_register(&sonypi_misc_device);
  1869. if (error) {
  1870. printk(KERN_ERR DRV_PFX "misc_register failed\n");
  1871. goto err_free_kfifo;
  1872. }
  1873. if (minor == -1)
  1874. printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
  1875. sonypi_misc_device.minor);
  1876. return 0;
  1877. err_free_kfifo:
  1878. kfifo_free(sonypi_compat.fifo);
  1879. return error;
  1880. }
  1881. static void sonypi_compat_exit(void)
  1882. {
  1883. misc_deregister(&sonypi_misc_device);
  1884. kfifo_free(sonypi_compat.fifo);
  1885. }
  1886. #else
  1887. static int sonypi_compat_init(void) { return 0; }
  1888. static void sonypi_compat_exit(void) { }
  1889. static void sonypi_compat_report_event(u8 event) { }
  1890. #endif /* CONFIG_SONYPI_COMPAT */
  1891. /*
  1892. * ACPI callbacks
  1893. */
  1894. static acpi_status
  1895. sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
  1896. {
  1897. u32 i;
  1898. struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
  1899. switch (resource->type) {
  1900. case ACPI_RESOURCE_TYPE_START_DEPENDENT:
  1901. {
  1902. /* start IO enumeration */
  1903. struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
  1904. if (!ioport)
  1905. return AE_ERROR;
  1906. list_add(&ioport->list, &dev->ioports);
  1907. return AE_OK;
  1908. }
  1909. case ACPI_RESOURCE_TYPE_END_DEPENDENT:
  1910. /* end IO enumeration */
  1911. return AE_OK;
  1912. case ACPI_RESOURCE_TYPE_IRQ:
  1913. {
  1914. struct acpi_resource_irq *p = &resource->data.irq;
  1915. struct sony_pic_irq *interrupt = NULL;
  1916. if (!p || !p->interrupt_count) {
  1917. /*
  1918. * IRQ descriptors may have no IRQ# bits set,
  1919. * particularly those those w/ _STA disabled
  1920. */
  1921. dprintk("Blank IRQ resource\n");
  1922. return AE_OK;
  1923. }
  1924. for (i = 0; i < p->interrupt_count; i++) {
  1925. if (!p->interrupts[i]) {
  1926. printk(KERN_WARNING DRV_PFX
  1927. "Invalid IRQ %d\n",
  1928. p->interrupts[i]);
  1929. continue;
  1930. }
  1931. interrupt = kzalloc(sizeof(*interrupt),
  1932. GFP_KERNEL);
  1933. if (!interrupt)
  1934. return AE_ERROR;
  1935. list_add(&interrupt->list, &dev->interrupts);
  1936. interrupt->irq.triggering = p->triggering;
  1937. interrupt->irq.polarity = p->polarity;
  1938. interrupt->irq.sharable = p->sharable;
  1939. interrupt->irq.interrupt_count = 1;
  1940. interrupt->irq.interrupts[0] = p->interrupts[i];
  1941. }
  1942. return AE_OK;
  1943. }
  1944. case ACPI_RESOURCE_TYPE_IO:
  1945. {
  1946. struct acpi_resource_io *io = &resource->data.io;
  1947. struct sony_pic_ioport *ioport =
  1948. list_first_entry(&dev->ioports, struct sony_pic_ioport, list);
  1949. if (!io) {
  1950. dprintk("Blank IO resource\n");
  1951. return AE_OK;
  1952. }
  1953. if (!ioport->io1.minimum) {
  1954. memcpy(&ioport->io1, io, sizeof(*io));
  1955. dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum,
  1956. ioport->io1.address_length);
  1957. }
  1958. else if (!ioport->io2.minimum) {
  1959. memcpy(&ioport->io2, io, sizeof(*io));
  1960. dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum,
  1961. ioport->io2.address_length);
  1962. }
  1963. else {
  1964. printk(KERN_ERR DRV_PFX "Unknown SPIC Type, more than 2 IO Ports\n");
  1965. return AE_ERROR;
  1966. }
  1967. return AE_OK;
  1968. }
  1969. default:
  1970. dprintk("Resource %d isn't an IRQ nor an IO port\n",
  1971. resource->type);
  1972. case ACPI_RESOURCE_TYPE_END_TAG:
  1973. return AE_OK;
  1974. }
  1975. return AE_CTRL_TERMINATE;
  1976. }
  1977. static int sony_pic_possible_resources(struct acpi_device *device)
  1978. {
  1979. int result = 0;
  1980. acpi_status status = AE_OK;
  1981. if (!device)
  1982. return -EINVAL;
  1983. /* get device status */
  1984. /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
  1985. dprintk("Evaluating _STA\n");
  1986. result = acpi_bus_get_status(device);
  1987. if (result) {
  1988. printk(KERN_WARNING DRV_PFX "Unable to read status\n");
  1989. goto end;
  1990. }
  1991. if (!device->status.enabled)
  1992. dprintk("Device disabled\n");
  1993. else
  1994. dprintk("Device enabled\n");
  1995. /*
  1996. * Query and parse 'method'
  1997. */
  1998. dprintk("Evaluating %s\n", METHOD_NAME__PRS);
  1999. status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
  2000. sony_pic_read_possible_resource, &spic_dev);
  2001. if (ACPI_FAILURE(status)) {
  2002. printk(KERN_WARNING DRV_PFX
  2003. "Failure evaluating %s\n",
  2004. METHOD_NAME__PRS);
  2005. result = -ENODEV;
  2006. }
  2007. end:
  2008. return result;
  2009. }
  2010. /*
  2011. * Disable the spic device by calling its _DIS method
  2012. */
  2013. static int sony_pic_disable(struct acpi_device *device)
  2014. {
  2015. acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL,
  2016. NULL);
  2017. if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND)
  2018. return -ENXIO;
  2019. dprintk("Device disabled\n");
  2020. return 0;
  2021. }
  2022. /*
  2023. * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
  2024. *
  2025. * Call _SRS to set current resources
  2026. */
  2027. static int sony_pic_enable(struct acpi_device *device,
  2028. struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
  2029. {
  2030. acpi_status status;
  2031. int result = 0;
  2032. /* Type 1 resource layout is:
  2033. * IO
  2034. * IO
  2035. * IRQNoFlags
  2036. * End
  2037. *
  2038. * Type 2 and 3 resource layout is:
  2039. * IO
  2040. * IRQNoFlags
  2041. * End
  2042. */
  2043. struct {
  2044. struct acpi_resource res1;
  2045. struct acpi_resource res2;
  2046. struct acpi_resource res3;
  2047. struct acpi_resource res4;
  2048. } *resource;
  2049. struct acpi_buffer buffer = { 0, NULL };
  2050. if (!ioport || !irq)
  2051. return -EINVAL;
  2052. /* init acpi_buffer */
  2053. resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
  2054. if (!resource)
  2055. return -ENOMEM;
  2056. buffer.length = sizeof(*resource) + 1;
  2057. buffer.pointer = resource;
  2058. /* setup Type 1 resources */
  2059. if (spic_dev.control->model == SONYPI_DEVICE_TYPE1) {
  2060. /* setup io resources */
  2061. resource->res1.type = ACPI_RESOURCE_TYPE_IO;
  2062. resource->res1.length = sizeof(struct acpi_resource);
  2063. memcpy(&resource->res1.data.io, &ioport->io1,
  2064. sizeof(struct acpi_resource_io));
  2065. resource->res2.type = ACPI_RESOURCE_TYPE_IO;
  2066. resource->res2.length = sizeof(struct acpi_resource);
  2067. memcpy(&resource->res2.data.io, &ioport->io2,
  2068. sizeof(struct acpi_resource_io));
  2069. /* setup irq resource */
  2070. resource->res3.type = ACPI_RESOURCE_TYPE_IRQ;
  2071. resource->res3.length = sizeof(struct acpi_resource);
  2072. memcpy(&resource->res3.data.irq, &irq->irq,
  2073. sizeof(struct acpi_resource_irq));
  2074. /* we requested a shared irq */
  2075. resource->res3.data.irq.sharable = ACPI_SHARED;
  2076. resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
  2077. }
  2078. /* setup Type 2/3 resources */
  2079. else {
  2080. /* setup io resource */
  2081. resource->res1.type = ACPI_RESOURCE_TYPE_IO;
  2082. resource->res1.length = sizeof(struct acpi_resource);
  2083. memcpy(&resource->res1.data.io, &ioport->io1,
  2084. sizeof(struct acpi_resource_io));
  2085. /* setup irq resource */
  2086. resource->res2.type = ACPI_RESOURCE_TYPE_IRQ;
  2087. resource->res2.length = sizeof(struct acpi_resource);
  2088. memcpy(&resource->res2.data.irq, &irq->irq,
  2089. sizeof(struct acpi_resource_irq));
  2090. /* we requested a shared irq */
  2091. resource->res2.data.irq.sharable = ACPI_SHARED;
  2092. resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
  2093. }
  2094. /* Attempt to set the resource */
  2095. dprintk("Evaluating _SRS\n");
  2096. status = acpi_set_current_resources(device->handle, &buffer);
  2097. /* check for total failure */
  2098. if (ACPI_FAILURE(status)) {
  2099. printk(KERN_ERR DRV_PFX "Error evaluating _SRS\n");
  2100. result = -ENODEV;
  2101. goto end;
  2102. }
  2103. /* Necessary device initializations calls (from sonypi) */
  2104. sony_pic_call1(0x82);
  2105. sony_pic_call2(0x81, 0xff);
  2106. sony_pic_call1(compat ? 0x92 : 0x82);
  2107. end:
  2108. kfree(resource);
  2109. return result;
  2110. }
  2111. /*****************
  2112. *
  2113. * ISR: some event is available
  2114. *
  2115. *****************/
  2116. static irqreturn_t sony_pic_irq(int irq, void *dev_id)
  2117. {
  2118. int i, j;
  2119. u8 ev = 0;
  2120. u8 data_mask = 0;
  2121. u8 device_event = 0;
  2122. struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
  2123. ev = inb_p(dev->cur_ioport->io1.minimum);
  2124. if (dev->cur_ioport->io2.minimum)
  2125. data_mask = inb_p(dev->cur_ioport->io2.minimum);
  2126. else
  2127. data_mask = inb_p(dev->cur_ioport->io1.minimum +
  2128. dev->control->evport_offset);
  2129. dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
  2130. ev, data_mask, dev->cur_ioport->io1.minimum,
  2131. dev->control->evport_offset);
  2132. if (ev == 0x00 || ev == 0xff)
  2133. return IRQ_HANDLED;
  2134. for (i = 0; dev->control->event_types[i].mask; i++) {
  2135. if ((data_mask & dev->control->event_types[i].data) !=
  2136. dev->control->event_types[i].data)
  2137. continue;
  2138. if (!(mask & dev->control->event_types[i].mask))
  2139. continue;
  2140. for (j = 0; dev->control->event_types[i].events[j].event; j++) {
  2141. if (ev == dev->control->event_types[i].events[j].data) {
  2142. device_event =
  2143. dev->control->
  2144. event_types[i].events[j].event;
  2145. goto found;
  2146. }
  2147. }
  2148. }
  2149. /* Still not able to decode the event try to pass
  2150. * it over to the minidriver
  2151. */
  2152. if (dev->control->handle_irq &&
  2153. dev->control->handle_irq(data_mask, ev) == 0)
  2154. return IRQ_HANDLED;
  2155. dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
  2156. ev, data_mask, dev->cur_ioport->io1.minimum,
  2157. dev->control->evport_offset);
  2158. return IRQ_HANDLED;
  2159. found:
  2160. sony_laptop_report_input_event(device_event);
  2161. acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event);
  2162. sonypi_compat_report_event(device_event);
  2163. return IRQ_HANDLED;
  2164. }
  2165. /*****************
  2166. *
  2167. * ACPI driver
  2168. *
  2169. *****************/
  2170. static int sony_pic_remove(struct acpi_device *device, int type)
  2171. {
  2172. struct sony_pic_ioport *io, *tmp_io;
  2173. struct sony_pic_irq *irq, *tmp_irq;
  2174. if (sony_pic_disable(device)) {
  2175. printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
  2176. return -ENXIO;
  2177. }
  2178. free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
  2179. release_region(spic_dev.cur_ioport->io1.minimum,
  2180. spic_dev.cur_ioport->io1.address_length);
  2181. if (spic_dev.cur_ioport->io2.minimum)
  2182. release_region(spic_dev.cur_ioport->io2.minimum,
  2183. spic_dev.cur_ioport->io2.address_length);
  2184. sonypi_compat_exit();
  2185. sony_laptop_remove_input();
  2186. /* pf attrs */
  2187. sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
  2188. sony_pf_remove();
  2189. list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
  2190. list_del(&io->list);
  2191. kfree(io);
  2192. }
  2193. list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
  2194. list_del(&irq->list);
  2195. kfree(irq);
  2196. }
  2197. spic_dev.cur_ioport = NULL;
  2198. spic_dev.cur_irq = NULL;
  2199. dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
  2200. return 0;
  2201. }
  2202. static int sony_pic_add(struct acpi_device *device)
  2203. {
  2204. int result;
  2205. struct sony_pic_ioport *io, *tmp_io;
  2206. struct sony_pic_irq *irq, *tmp_irq;
  2207. printk(KERN_INFO DRV_PFX "%s v%s.\n",
  2208. SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
  2209. spic_dev.acpi_dev = device;
  2210. strcpy(acpi_device_class(device), "sony/hotkey");
  2211. sony_pic_detect_device_type(&spic_dev);
  2212. mutex_init(&spic_dev.lock);
  2213. /* read _PRS resources */
  2214. result = sony_pic_possible_resources(device);
  2215. if (result) {
  2216. printk(KERN_ERR DRV_PFX
  2217. "Unabe to read possible resources.\n");
  2218. goto err_free_resources;
  2219. }
  2220. /* setup input devices and helper fifo */
  2221. result = sony_laptop_setup_input(device);
  2222. if (result) {
  2223. printk(KERN_ERR DRV_PFX
  2224. "Unabe to create input devices.\n");
  2225. goto err_free_resources;
  2226. }
  2227. if (sonypi_compat_init())
  2228. goto err_remove_input;
  2229. /* request io port */
  2230. list_for_each_entry_reverse(io, &spic_dev.ioports, list) {
  2231. if (request_region(io->io1.minimum, io->io1.address_length,
  2232. "Sony Programable I/O Device")) {
  2233. dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
  2234. io->io1.minimum, io->io1.maximum,
  2235. io->io1.address_length);
  2236. /* Type 1 have 2 ioports */
  2237. if (io->io2.minimum) {
  2238. if (request_region(io->io2.minimum,
  2239. io->io2.address_length,
  2240. "Sony Programable I/O Device")) {
  2241. dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
  2242. io->io2.minimum, io->io2.maximum,
  2243. io->io2.address_length);
  2244. spic_dev.cur_ioport = io;
  2245. break;
  2246. }
  2247. else {
  2248. dprintk("Unable to get I/O port2: "
  2249. "0x%.4x (0x%.4x) + 0x%.2x\n",
  2250. io->io2.minimum, io->io2.maximum,
  2251. io->io2.address_length);
  2252. release_region(io->io1.minimum,
  2253. io->io1.address_length);
  2254. }
  2255. }
  2256. else {
  2257. spic_dev.cur_ioport = io;
  2258. break;
  2259. }
  2260. }
  2261. }
  2262. if (!spic_dev.cur_ioport) {
  2263. printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
  2264. result = -ENODEV;
  2265. goto err_remove_compat;
  2266. }
  2267. /* request IRQ */
  2268. list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) {
  2269. if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
  2270. IRQF_SHARED, "sony-laptop", &spic_dev)) {
  2271. dprintk("IRQ: %d - triggering: %d - "
  2272. "polarity: %d - shr: %d\n",
  2273. irq->irq.interrupts[0],
  2274. irq->irq.triggering,
  2275. irq->irq.polarity,
  2276. irq->irq.sharable);
  2277. spic_dev.cur_irq = irq;
  2278. break;
  2279. }
  2280. }
  2281. if (!spic_dev.cur_irq) {
  2282. printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
  2283. result = -ENODEV;
  2284. goto err_release_region;
  2285. }
  2286. /* set resource status _SRS */
  2287. result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
  2288. if (result) {
  2289. printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
  2290. goto err_free_irq;
  2291. }
  2292. spic_dev.bluetooth_power = -1;
  2293. /* create device attributes */
  2294. result = sony_pf_add();
  2295. if (result)
  2296. goto err_disable_device;
  2297. result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
  2298. if (result)
  2299. goto err_remove_pf;
  2300. return 0;
  2301. err_remove_pf:
  2302. sony_pf_remove();
  2303. err_disable_device:
  2304. sony_pic_disable(device);
  2305. err_free_irq:
  2306. free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
  2307. err_release_region:
  2308. release_region(spic_dev.cur_ioport->io1.minimum,
  2309. spic_dev.cur_ioport->io1.address_length);
  2310. if (spic_dev.cur_ioport->io2.minimum)
  2311. release_region(spic_dev.cur_ioport->io2.minimum,
  2312. spic_dev.cur_ioport->io2.address_length);
  2313. err_remove_compat:
  2314. sonypi_compat_exit();
  2315. err_remove_input:
  2316. sony_laptop_remove_input();
  2317. err_free_resources:
  2318. list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
  2319. list_del(&io->list);
  2320. kfree(io);
  2321. }
  2322. list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
  2323. list_del(&irq->list);
  2324. kfree(irq);
  2325. }
  2326. spic_dev.cur_ioport = NULL;
  2327. spic_dev.cur_irq = NULL;
  2328. return result;
  2329. }
  2330. static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
  2331. {
  2332. if (sony_pic_disable(device))
  2333. return -ENXIO;
  2334. return 0;
  2335. }
  2336. static int sony_pic_resume(struct acpi_device *device)
  2337. {
  2338. sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
  2339. return 0;
  2340. }
  2341. static const struct acpi_device_id sony_pic_device_ids[] = {
  2342. {SONY_PIC_HID, 0},
  2343. {"", 0},
  2344. };
  2345. static struct acpi_driver sony_pic_driver = {
  2346. .name = SONY_PIC_DRIVER_NAME,
  2347. .class = SONY_PIC_CLASS,
  2348. .ids = sony_pic_device_ids,
  2349. .owner = THIS_MODULE,
  2350. .ops = {
  2351. .add = sony_pic_add,
  2352. .remove = sony_pic_remove,
  2353. .suspend = sony_pic_suspend,
  2354. .resume = sony_pic_resume,
  2355. },
  2356. };
  2357. static struct dmi_system_id __initdata sonypi_dmi_table[] = {
  2358. {
  2359. .ident = "Sony Vaio",
  2360. .matches = {
  2361. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  2362. DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
  2363. },
  2364. },
  2365. {
  2366. .ident = "Sony Vaio",
  2367. .matches = {
  2368. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  2369. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
  2370. },
  2371. },
  2372. { }
  2373. };
  2374. static int __init sony_laptop_init(void)
  2375. {
  2376. int result;
  2377. if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
  2378. result = acpi_bus_register_driver(&sony_pic_driver);
  2379. if (result) {
  2380. printk(KERN_ERR DRV_PFX
  2381. "Unable to register SPIC driver.");
  2382. goto out;
  2383. }
  2384. }
  2385. result = acpi_bus_register_driver(&sony_nc_driver);
  2386. if (result) {
  2387. printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
  2388. goto out_unregister_pic;
  2389. }
  2390. return 0;
  2391. out_unregister_pic:
  2392. if (!no_spic)
  2393. acpi_bus_unregister_driver(&sony_pic_driver);
  2394. out:
  2395. return result;
  2396. }
  2397. static void __exit sony_laptop_exit(void)
  2398. {
  2399. acpi_bus_unregister_driver(&sony_nc_driver);
  2400. if (!no_spic)
  2401. acpi_bus_unregister_driver(&sony_pic_driver);
  2402. }
  2403. module_init(sony_laptop_init);
  2404. module_exit(sony_laptop_exit);