sony-laptop.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784
  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_device_info *info;
  809. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  810. if (ACPI_SUCCESS(acpi_get_object_info(handle, &buffer))) {
  811. info = buffer.pointer;
  812. printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n",
  813. (char *)&info->name, info->param_count);
  814. kfree(buffer.pointer);
  815. }
  816. return AE_OK;
  817. }
  818. /*
  819. * ACPI device
  820. */
  821. static int sony_nc_resume(struct acpi_device *device)
  822. {
  823. struct sony_nc_value *item;
  824. for (item = sony_nc_values; item->name; item++) {
  825. int ret;
  826. if (!item->valid)
  827. continue;
  828. ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
  829. item->value, NULL);
  830. if (ret < 0) {
  831. printk("%s: %d\n", __func__, ret);
  832. break;
  833. }
  834. }
  835. /* set the last requested brightness level */
  836. if (sony_backlight_device &&
  837. !sony_backlight_update_status(sony_backlight_device))
  838. printk(KERN_WARNING DRV_PFX "unable to restore brightness level\n");
  839. /* re-initialize models with specific requirements */
  840. dmi_check_system(sony_nc_ids);
  841. return 0;
  842. }
  843. static int sony_nc_add(struct acpi_device *device)
  844. {
  845. acpi_status status;
  846. int result = 0;
  847. acpi_handle handle;
  848. struct sony_nc_value *item;
  849. printk(KERN_INFO DRV_PFX "%s v%s.\n",
  850. SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
  851. sony_nc_acpi_device = device;
  852. strcpy(acpi_device_class(device), "sony/hotkey");
  853. sony_nc_acpi_handle = device->handle;
  854. /* read device status */
  855. result = acpi_bus_get_status(device);
  856. /* bail IFF the above call was successful and the device is not present */
  857. if (!result && !device->status.present) {
  858. dprintk("Device not present\n");
  859. result = -ENODEV;
  860. goto outwalk;
  861. }
  862. if (debug) {
  863. status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
  864. 1, sony_walk_callback, NULL, NULL);
  865. if (ACPI_FAILURE(status)) {
  866. printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
  867. result = -ENODEV;
  868. goto outwalk;
  869. }
  870. }
  871. /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1
  872. * should be respected as we already checked for the device presence above */
  873. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) {
  874. dprintk("Invoking _INI\n");
  875. if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI,
  876. NULL, NULL)))
  877. dprintk("_INI Method failed\n");
  878. }
  879. /* setup input devices and helper fifo */
  880. result = sony_laptop_setup_input(device);
  881. if (result) {
  882. printk(KERN_ERR DRV_PFX
  883. "Unabe to create input devices.\n");
  884. goto outwalk;
  885. }
  886. status = acpi_install_notify_handler(sony_nc_acpi_handle,
  887. ACPI_DEVICE_NOTIFY,
  888. sony_acpi_notify, NULL);
  889. if (ACPI_FAILURE(status)) {
  890. printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status);
  891. result = -ENODEV;
  892. goto outinput;
  893. }
  894. if (acpi_video_backlight_support()) {
  895. printk(KERN_INFO DRV_PFX "brightness ignored, must be "
  896. "controlled by ACPI video driver\n");
  897. } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT",
  898. &handle))) {
  899. sony_backlight_device = backlight_device_register("sony", NULL,
  900. NULL,
  901. &sony_backlight_ops);
  902. if (IS_ERR(sony_backlight_device)) {
  903. printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
  904. sony_backlight_device = NULL;
  905. } else {
  906. sony_backlight_device->props.brightness =
  907. sony_backlight_get_brightness
  908. (sony_backlight_device);
  909. sony_backlight_device->props.max_brightness =
  910. SONY_MAX_BRIGHTNESS - 1;
  911. }
  912. }
  913. /* initialize models with specific requirements */
  914. dmi_check_system(sony_nc_ids);
  915. result = sony_pf_add();
  916. if (result)
  917. goto outbacklight;
  918. /* create sony_pf sysfs attributes related to the SNC device */
  919. for (item = sony_nc_values; item->name; ++item) {
  920. if (!debug && item->debug)
  921. continue;
  922. /* find the available acpiget as described in the DSDT */
  923. for (; item->acpiget && *item->acpiget; ++item->acpiget) {
  924. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
  925. *item->acpiget,
  926. &handle))) {
  927. dprintk("Found %s getter: %s\n",
  928. item->name, *item->acpiget);
  929. item->devattr.attr.mode |= S_IRUGO;
  930. break;
  931. }
  932. }
  933. /* find the available acpiset as described in the DSDT */
  934. for (; item->acpiset && *item->acpiset; ++item->acpiset) {
  935. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
  936. *item->acpiset,
  937. &handle))) {
  938. dprintk("Found %s setter: %s\n",
  939. item->name, *item->acpiset);
  940. item->devattr.attr.mode |= S_IWUSR;
  941. break;
  942. }
  943. }
  944. if (item->devattr.attr.mode != 0) {
  945. result =
  946. device_create_file(&sony_pf_device->dev,
  947. &item->devattr);
  948. if (result)
  949. goto out_sysfs;
  950. }
  951. }
  952. return 0;
  953. out_sysfs:
  954. for (item = sony_nc_values; item->name; ++item) {
  955. device_remove_file(&sony_pf_device->dev, &item->devattr);
  956. }
  957. sony_pf_remove();
  958. outbacklight:
  959. if (sony_backlight_device)
  960. backlight_device_unregister(sony_backlight_device);
  961. status = acpi_remove_notify_handler(sony_nc_acpi_handle,
  962. ACPI_DEVICE_NOTIFY,
  963. sony_acpi_notify);
  964. if (ACPI_FAILURE(status))
  965. printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
  966. outinput:
  967. sony_laptop_remove_input();
  968. outwalk:
  969. return result;
  970. }
  971. static int sony_nc_remove(struct acpi_device *device, int type)
  972. {
  973. acpi_status status;
  974. struct sony_nc_value *item;
  975. if (sony_backlight_device)
  976. backlight_device_unregister(sony_backlight_device);
  977. sony_nc_acpi_device = NULL;
  978. status = acpi_remove_notify_handler(sony_nc_acpi_handle,
  979. ACPI_DEVICE_NOTIFY,
  980. sony_acpi_notify);
  981. if (ACPI_FAILURE(status))
  982. printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
  983. for (item = sony_nc_values; item->name; ++item) {
  984. device_remove_file(&sony_pf_device->dev, &item->devattr);
  985. }
  986. sony_pf_remove();
  987. sony_laptop_remove_input();
  988. dprintk(SONY_NC_DRIVER_NAME " removed.\n");
  989. return 0;
  990. }
  991. static const struct acpi_device_id sony_device_ids[] = {
  992. {SONY_NC_HID, 0},
  993. {SONY_PIC_HID, 0},
  994. {"", 0},
  995. };
  996. MODULE_DEVICE_TABLE(acpi, sony_device_ids);
  997. static const struct acpi_device_id sony_nc_device_ids[] = {
  998. {SONY_NC_HID, 0},
  999. {"", 0},
  1000. };
  1001. static struct acpi_driver sony_nc_driver = {
  1002. .name = SONY_NC_DRIVER_NAME,
  1003. .class = SONY_NC_CLASS,
  1004. .ids = sony_nc_device_ids,
  1005. .owner = THIS_MODULE,
  1006. .ops = {
  1007. .add = sony_nc_add,
  1008. .remove = sony_nc_remove,
  1009. .resume = sony_nc_resume,
  1010. },
  1011. };
  1012. /*********** SPIC (SNY6001) Device ***********/
  1013. #define SONYPI_DEVICE_TYPE1 0x00000001
  1014. #define SONYPI_DEVICE_TYPE2 0x00000002
  1015. #define SONYPI_DEVICE_TYPE3 0x00000004
  1016. #define SONYPI_DEVICE_TYPE4 0x00000008
  1017. #define SONYPI_TYPE1_OFFSET 0x04
  1018. #define SONYPI_TYPE2_OFFSET 0x12
  1019. #define SONYPI_TYPE3_OFFSET 0x12
  1020. #define SONYPI_TYPE4_OFFSET 0x12
  1021. struct sony_pic_ioport {
  1022. struct acpi_resource_io io1;
  1023. struct acpi_resource_io io2;
  1024. struct list_head list;
  1025. };
  1026. struct sony_pic_irq {
  1027. struct acpi_resource_irq irq;
  1028. struct list_head list;
  1029. };
  1030. struct sonypi_eventtypes {
  1031. u8 data;
  1032. unsigned long mask;
  1033. struct sonypi_event *events;
  1034. };
  1035. struct device_ctrl {
  1036. int model;
  1037. int (*handle_irq)(const u8, const u8);
  1038. u16 evport_offset;
  1039. u8 has_camera;
  1040. u8 has_bluetooth;
  1041. u8 has_wwan;
  1042. struct sonypi_eventtypes *event_types;
  1043. };
  1044. struct sony_pic_dev {
  1045. struct device_ctrl *control;
  1046. struct acpi_device *acpi_dev;
  1047. struct sony_pic_irq *cur_irq;
  1048. struct sony_pic_ioport *cur_ioport;
  1049. struct list_head interrupts;
  1050. struct list_head ioports;
  1051. struct mutex lock;
  1052. u8 camera_power;
  1053. u8 bluetooth_power;
  1054. u8 wwan_power;
  1055. };
  1056. static struct sony_pic_dev spic_dev = {
  1057. .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
  1058. .ioports = LIST_HEAD_INIT(spic_dev.ioports),
  1059. };
  1060. /* Event masks */
  1061. #define SONYPI_JOGGER_MASK 0x00000001
  1062. #define SONYPI_CAPTURE_MASK 0x00000002
  1063. #define SONYPI_FNKEY_MASK 0x00000004
  1064. #define SONYPI_BLUETOOTH_MASK 0x00000008
  1065. #define SONYPI_PKEY_MASK 0x00000010
  1066. #define SONYPI_BACK_MASK 0x00000020
  1067. #define SONYPI_HELP_MASK 0x00000040
  1068. #define SONYPI_LID_MASK 0x00000080
  1069. #define SONYPI_ZOOM_MASK 0x00000100
  1070. #define SONYPI_THUMBPHRASE_MASK 0x00000200
  1071. #define SONYPI_MEYE_MASK 0x00000400
  1072. #define SONYPI_MEMORYSTICK_MASK 0x00000800
  1073. #define SONYPI_BATTERY_MASK 0x00001000
  1074. #define SONYPI_WIRELESS_MASK 0x00002000
  1075. struct sonypi_event {
  1076. u8 data;
  1077. u8 event;
  1078. };
  1079. /* The set of possible button release events */
  1080. static struct sonypi_event sonypi_releaseev[] = {
  1081. { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
  1082. { 0, 0 }
  1083. };
  1084. /* The set of possible jogger events */
  1085. static struct sonypi_event sonypi_joggerev[] = {
  1086. { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
  1087. { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
  1088. { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
  1089. { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
  1090. { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
  1091. { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
  1092. { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
  1093. { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
  1094. { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
  1095. { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
  1096. { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
  1097. { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
  1098. { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
  1099. { 0, 0 }
  1100. };
  1101. /* The set of possible capture button events */
  1102. static struct sonypi_event sonypi_captureev[] = {
  1103. { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
  1104. { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
  1105. { 0x40, SONYPI_EVENT_CAPTURE_PRESSED },
  1106. { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
  1107. { 0, 0 }
  1108. };
  1109. /* The set of possible fnkeys events */
  1110. static struct sonypi_event sonypi_fnkeyev[] = {
  1111. { 0x10, SONYPI_EVENT_FNKEY_ESC },
  1112. { 0x11, SONYPI_EVENT_FNKEY_F1 },
  1113. { 0x12, SONYPI_EVENT_FNKEY_F2 },
  1114. { 0x13, SONYPI_EVENT_FNKEY_F3 },
  1115. { 0x14, SONYPI_EVENT_FNKEY_F4 },
  1116. { 0x15, SONYPI_EVENT_FNKEY_F5 },
  1117. { 0x16, SONYPI_EVENT_FNKEY_F6 },
  1118. { 0x17, SONYPI_EVENT_FNKEY_F7 },
  1119. { 0x18, SONYPI_EVENT_FNKEY_F8 },
  1120. { 0x19, SONYPI_EVENT_FNKEY_F9 },
  1121. { 0x1a, SONYPI_EVENT_FNKEY_F10 },
  1122. { 0x1b, SONYPI_EVENT_FNKEY_F11 },
  1123. { 0x1c, SONYPI_EVENT_FNKEY_F12 },
  1124. { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
  1125. { 0x21, SONYPI_EVENT_FNKEY_1 },
  1126. { 0x22, SONYPI_EVENT_FNKEY_2 },
  1127. { 0x31, SONYPI_EVENT_FNKEY_D },
  1128. { 0x32, SONYPI_EVENT_FNKEY_E },
  1129. { 0x33, SONYPI_EVENT_FNKEY_F },
  1130. { 0x34, SONYPI_EVENT_FNKEY_S },
  1131. { 0x35, SONYPI_EVENT_FNKEY_B },
  1132. { 0x36, SONYPI_EVENT_FNKEY_ONLY },
  1133. { 0, 0 }
  1134. };
  1135. /* The set of possible program key events */
  1136. static struct sonypi_event sonypi_pkeyev[] = {
  1137. { 0x01, SONYPI_EVENT_PKEY_P1 },
  1138. { 0x02, SONYPI_EVENT_PKEY_P2 },
  1139. { 0x04, SONYPI_EVENT_PKEY_P3 },
  1140. { 0, 0 }
  1141. };
  1142. /* The set of possible bluetooth events */
  1143. static struct sonypi_event sonypi_blueev[] = {
  1144. { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
  1145. { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
  1146. { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
  1147. { 0, 0 }
  1148. };
  1149. /* The set of possible wireless events */
  1150. static struct sonypi_event sonypi_wlessev[] = {
  1151. { 0x59, SONYPI_EVENT_WIRELESS_ON },
  1152. { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
  1153. { 0, 0 }
  1154. };
  1155. /* The set of possible back button events */
  1156. static struct sonypi_event sonypi_backev[] = {
  1157. { 0x20, SONYPI_EVENT_BACK_PRESSED },
  1158. { 0, 0 }
  1159. };
  1160. /* The set of possible help button events */
  1161. static struct sonypi_event sonypi_helpev[] = {
  1162. { 0x3b, SONYPI_EVENT_HELP_PRESSED },
  1163. { 0, 0 }
  1164. };
  1165. /* The set of possible lid events */
  1166. static struct sonypi_event sonypi_lidev[] = {
  1167. { 0x51, SONYPI_EVENT_LID_CLOSED },
  1168. { 0x50, SONYPI_EVENT_LID_OPENED },
  1169. { 0, 0 }
  1170. };
  1171. /* The set of possible zoom events */
  1172. static struct sonypi_event sonypi_zoomev[] = {
  1173. { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
  1174. { 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED },
  1175. { 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED },
  1176. { 0, 0 }
  1177. };
  1178. /* The set of possible thumbphrase events */
  1179. static struct sonypi_event sonypi_thumbphraseev[] = {
  1180. { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
  1181. { 0, 0 }
  1182. };
  1183. /* The set of possible motioneye camera events */
  1184. static struct sonypi_event sonypi_meyeev[] = {
  1185. { 0x00, SONYPI_EVENT_MEYE_FACE },
  1186. { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
  1187. { 0, 0 }
  1188. };
  1189. /* The set of possible memorystick events */
  1190. static struct sonypi_event sonypi_memorystickev[] = {
  1191. { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
  1192. { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
  1193. { 0, 0 }
  1194. };
  1195. /* The set of possible battery events */
  1196. static struct sonypi_event sonypi_batteryev[] = {
  1197. { 0x20, SONYPI_EVENT_BATTERY_INSERT },
  1198. { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
  1199. { 0, 0 }
  1200. };
  1201. static struct sonypi_eventtypes type1_events[] = {
  1202. { 0, 0xffffffff, sonypi_releaseev },
  1203. { 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
  1204. { 0x30, SONYPI_LID_MASK, sonypi_lidev },
  1205. { 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
  1206. { 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
  1207. { 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1208. { 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
  1209. { 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1210. { 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1211. { 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1212. { 0 },
  1213. };
  1214. static struct sonypi_eventtypes type2_events[] = {
  1215. { 0, 0xffffffff, sonypi_releaseev },
  1216. { 0x38, SONYPI_LID_MASK, sonypi_lidev },
  1217. { 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
  1218. { 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
  1219. { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1220. { 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
  1221. { 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1222. { 0x11, SONYPI_BACK_MASK, sonypi_backev },
  1223. { 0x21, SONYPI_HELP_MASK, sonypi_helpev },
  1224. { 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
  1225. { 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
  1226. { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1227. { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1228. { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1229. { 0 },
  1230. };
  1231. static struct sonypi_eventtypes type3_events[] = {
  1232. { 0, 0xffffffff, sonypi_releaseev },
  1233. { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1234. { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
  1235. { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1236. { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1237. { 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1238. { 0 },
  1239. };
  1240. static struct sonypi_eventtypes type4_events[] = {
  1241. { 0, 0xffffffff, sonypi_releaseev },
  1242. { 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  1243. { 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
  1244. { 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  1245. { 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  1246. { 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev },
  1247. { 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev },
  1248. { 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev },
  1249. { 0 },
  1250. };
  1251. /* low level spic calls */
  1252. #define ITERATIONS_LONG 10000
  1253. #define ITERATIONS_SHORT 10
  1254. #define wait_on_command(command, iterations) { \
  1255. unsigned int n = iterations; \
  1256. while (--n && (command)) \
  1257. udelay(1); \
  1258. if (!n) \
  1259. dprintk("command failed at %s : %s (line %d)\n", \
  1260. __FILE__, __func__, __LINE__); \
  1261. }
  1262. static u8 sony_pic_call1(u8 dev)
  1263. {
  1264. u8 v1, v2;
  1265. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
  1266. ITERATIONS_LONG);
  1267. outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
  1268. v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4);
  1269. v2 = inb_p(spic_dev.cur_ioport->io1.minimum);
  1270. dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1);
  1271. return v2;
  1272. }
  1273. static u8 sony_pic_call2(u8 dev, u8 fn)
  1274. {
  1275. u8 v1;
  1276. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
  1277. ITERATIONS_LONG);
  1278. outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
  1279. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
  1280. ITERATIONS_LONG);
  1281. outb(fn, spic_dev.cur_ioport->io1.minimum);
  1282. v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
  1283. dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1);
  1284. return v1;
  1285. }
  1286. static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
  1287. {
  1288. u8 v1;
  1289. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
  1290. outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
  1291. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
  1292. outb(fn, spic_dev.cur_ioport->io1.minimum);
  1293. wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
  1294. outb(v, spic_dev.cur_ioport->io1.minimum);
  1295. v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
  1296. dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
  1297. dev, fn, v, v1);
  1298. return v1;
  1299. }
  1300. /*
  1301. * minidrivers for SPIC models
  1302. */
  1303. static int type4_handle_irq(const u8 data_mask, const u8 ev)
  1304. {
  1305. /*
  1306. * 0x31 could mean we have to take some extra action and wait for
  1307. * the next irq for some Type4 models, it will generate a new
  1308. * irq and we can read new data from the device:
  1309. * - 0x5c and 0x5f requires 0xA0
  1310. * - 0x61 requires 0xB3
  1311. */
  1312. if (data_mask == 0x31) {
  1313. if (ev == 0x5c || ev == 0x5f)
  1314. sony_pic_call1(0xA0);
  1315. else if (ev == 0x61)
  1316. sony_pic_call1(0xB3);
  1317. return 0;
  1318. }
  1319. return 1;
  1320. }
  1321. static struct device_ctrl spic_types[] = {
  1322. {
  1323. .model = SONYPI_DEVICE_TYPE1,
  1324. .handle_irq = NULL,
  1325. .evport_offset = SONYPI_TYPE1_OFFSET,
  1326. .event_types = type1_events,
  1327. },
  1328. {
  1329. .model = SONYPI_DEVICE_TYPE2,
  1330. .handle_irq = NULL,
  1331. .evport_offset = SONYPI_TYPE2_OFFSET,
  1332. .event_types = type2_events,
  1333. },
  1334. {
  1335. .model = SONYPI_DEVICE_TYPE3,
  1336. .handle_irq = NULL,
  1337. .evport_offset = SONYPI_TYPE3_OFFSET,
  1338. .event_types = type3_events,
  1339. },
  1340. {
  1341. .model = SONYPI_DEVICE_TYPE4,
  1342. .handle_irq = type4_handle_irq,
  1343. .evport_offset = SONYPI_TYPE4_OFFSET,
  1344. .event_types = type4_events,
  1345. },
  1346. };
  1347. static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
  1348. {
  1349. struct pci_dev *pcidev;
  1350. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1351. PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
  1352. if (pcidev) {
  1353. dev->control = &spic_types[0];
  1354. goto out;
  1355. }
  1356. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1357. PCI_DEVICE_ID_INTEL_ICH6_1, NULL);
  1358. if (pcidev) {
  1359. dev->control = &spic_types[2];
  1360. goto out;
  1361. }
  1362. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1363. PCI_DEVICE_ID_INTEL_ICH7_1, NULL);
  1364. if (pcidev) {
  1365. dev->control = &spic_types[3];
  1366. goto out;
  1367. }
  1368. pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1369. PCI_DEVICE_ID_INTEL_ICH8_4, NULL);
  1370. if (pcidev) {
  1371. dev->control = &spic_types[3];
  1372. goto out;
  1373. }
  1374. /* default */
  1375. dev->control = &spic_types[1];
  1376. out:
  1377. if (pcidev)
  1378. pci_dev_put(pcidev);
  1379. printk(KERN_INFO DRV_PFX "detected Type%d model\n",
  1380. dev->control->model == SONYPI_DEVICE_TYPE1 ? 1 :
  1381. dev->control->model == SONYPI_DEVICE_TYPE2 ? 2 :
  1382. dev->control->model == SONYPI_DEVICE_TYPE3 ? 3 : 4);
  1383. }
  1384. /* camera tests and poweron/poweroff */
  1385. #define SONYPI_CAMERA_PICTURE 5
  1386. #define SONYPI_CAMERA_CONTROL 0x10
  1387. #define SONYPI_CAMERA_BRIGHTNESS 0
  1388. #define SONYPI_CAMERA_CONTRAST 1
  1389. #define SONYPI_CAMERA_HUE 2
  1390. #define SONYPI_CAMERA_COLOR 3
  1391. #define SONYPI_CAMERA_SHARPNESS 4
  1392. #define SONYPI_CAMERA_EXPOSURE_MASK 0xC
  1393. #define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
  1394. #define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
  1395. #define SONYPI_CAMERA_MUTE_MASK 0x40
  1396. /* the rest don't need a loop until not 0xff */
  1397. #define SONYPI_CAMERA_AGC 6
  1398. #define SONYPI_CAMERA_AGC_MASK 0x30
  1399. #define SONYPI_CAMERA_SHUTTER_MASK 0x7
  1400. #define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
  1401. #define SONYPI_CAMERA_CONTROL 0x10
  1402. #define SONYPI_CAMERA_STATUS 7
  1403. #define SONYPI_CAMERA_STATUS_READY 0x2
  1404. #define SONYPI_CAMERA_STATUS_POSITION 0x4
  1405. #define SONYPI_DIRECTION_BACKWARDS 0x4
  1406. #define SONYPI_CAMERA_REVISION 8
  1407. #define SONYPI_CAMERA_ROMVERSION 9
  1408. static int __sony_pic_camera_ready(void)
  1409. {
  1410. u8 v;
  1411. v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
  1412. return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
  1413. }
  1414. static int __sony_pic_camera_off(void)
  1415. {
  1416. if (!camera) {
  1417. printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
  1418. return -ENODEV;
  1419. }
  1420. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
  1421. SONYPI_CAMERA_MUTE_MASK),
  1422. ITERATIONS_SHORT);
  1423. if (spic_dev.camera_power) {
  1424. sony_pic_call2(0x91, 0);
  1425. spic_dev.camera_power = 0;
  1426. }
  1427. return 0;
  1428. }
  1429. static int __sony_pic_camera_on(void)
  1430. {
  1431. int i, j, x;
  1432. if (!camera) {
  1433. printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
  1434. return -ENODEV;
  1435. }
  1436. if (spic_dev.camera_power)
  1437. return 0;
  1438. for (j = 5; j > 0; j--) {
  1439. for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
  1440. msleep(10);
  1441. sony_pic_call1(0x93);
  1442. for (i = 400; i > 0; i--) {
  1443. if (__sony_pic_camera_ready())
  1444. break;
  1445. msleep(10);
  1446. }
  1447. if (i)
  1448. break;
  1449. }
  1450. if (j == 0) {
  1451. printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
  1452. return -ENODEV;
  1453. }
  1454. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
  1455. 0x5a),
  1456. ITERATIONS_SHORT);
  1457. spic_dev.camera_power = 1;
  1458. return 0;
  1459. }
  1460. /* External camera command (exported to the motion eye v4l driver) */
  1461. int sony_pic_camera_command(int command, u8 value)
  1462. {
  1463. if (!camera)
  1464. return -EIO;
  1465. mutex_lock(&spic_dev.lock);
  1466. switch (command) {
  1467. case SONY_PIC_COMMAND_SETCAMERA:
  1468. if (value)
  1469. __sony_pic_camera_on();
  1470. else
  1471. __sony_pic_camera_off();
  1472. break;
  1473. case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
  1474. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
  1475. ITERATIONS_SHORT);
  1476. break;
  1477. case SONY_PIC_COMMAND_SETCAMERACONTRAST:
  1478. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
  1479. ITERATIONS_SHORT);
  1480. break;
  1481. case SONY_PIC_COMMAND_SETCAMERAHUE:
  1482. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
  1483. ITERATIONS_SHORT);
  1484. break;
  1485. case SONY_PIC_COMMAND_SETCAMERACOLOR:
  1486. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
  1487. ITERATIONS_SHORT);
  1488. break;
  1489. case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
  1490. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
  1491. ITERATIONS_SHORT);
  1492. break;
  1493. case SONY_PIC_COMMAND_SETCAMERAPICTURE:
  1494. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
  1495. ITERATIONS_SHORT);
  1496. break;
  1497. case SONY_PIC_COMMAND_SETCAMERAAGC:
  1498. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
  1499. ITERATIONS_SHORT);
  1500. break;
  1501. default:
  1502. printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
  1503. command);
  1504. break;
  1505. }
  1506. mutex_unlock(&spic_dev.lock);
  1507. return 0;
  1508. }
  1509. EXPORT_SYMBOL(sony_pic_camera_command);
  1510. /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
  1511. static void sony_pic_set_wwanpower(u8 state)
  1512. {
  1513. state = !!state;
  1514. mutex_lock(&spic_dev.lock);
  1515. if (spic_dev.wwan_power == state) {
  1516. mutex_unlock(&spic_dev.lock);
  1517. return;
  1518. }
  1519. sony_pic_call2(0xB0, state);
  1520. spic_dev.wwan_power = state;
  1521. mutex_unlock(&spic_dev.lock);
  1522. }
  1523. static ssize_t sony_pic_wwanpower_store(struct device *dev,
  1524. struct device_attribute *attr,
  1525. const char *buffer, size_t count)
  1526. {
  1527. unsigned long value;
  1528. if (count > 31)
  1529. return -EINVAL;
  1530. value = simple_strtoul(buffer, NULL, 10);
  1531. sony_pic_set_wwanpower(value);
  1532. return count;
  1533. }
  1534. static ssize_t sony_pic_wwanpower_show(struct device *dev,
  1535. struct device_attribute *attr, char *buffer)
  1536. {
  1537. ssize_t count;
  1538. mutex_lock(&spic_dev.lock);
  1539. count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
  1540. mutex_unlock(&spic_dev.lock);
  1541. return count;
  1542. }
  1543. /* bluetooth subsystem power state */
  1544. static void __sony_pic_set_bluetoothpower(u8 state)
  1545. {
  1546. state = !!state;
  1547. if (spic_dev.bluetooth_power == state)
  1548. return;
  1549. sony_pic_call2(0x96, state);
  1550. sony_pic_call1(0x82);
  1551. spic_dev.bluetooth_power = state;
  1552. }
  1553. static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
  1554. struct device_attribute *attr,
  1555. const char *buffer, size_t count)
  1556. {
  1557. unsigned long value;
  1558. if (count > 31)
  1559. return -EINVAL;
  1560. value = simple_strtoul(buffer, NULL, 10);
  1561. mutex_lock(&spic_dev.lock);
  1562. __sony_pic_set_bluetoothpower(value);
  1563. mutex_unlock(&spic_dev.lock);
  1564. return count;
  1565. }
  1566. static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
  1567. struct device_attribute *attr, char *buffer)
  1568. {
  1569. ssize_t count = 0;
  1570. mutex_lock(&spic_dev.lock);
  1571. count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
  1572. mutex_unlock(&spic_dev.lock);
  1573. return count;
  1574. }
  1575. /* fan speed */
  1576. /* FAN0 information (reverse engineered from ACPI tables) */
  1577. #define SONY_PIC_FAN0_STATUS 0x93
  1578. static int sony_pic_set_fanspeed(unsigned long value)
  1579. {
  1580. return ec_write(SONY_PIC_FAN0_STATUS, value);
  1581. }
  1582. static int sony_pic_get_fanspeed(u8 *value)
  1583. {
  1584. return ec_read(SONY_PIC_FAN0_STATUS, value);
  1585. }
  1586. static ssize_t sony_pic_fanspeed_store(struct device *dev,
  1587. struct device_attribute *attr,
  1588. const char *buffer, size_t count)
  1589. {
  1590. unsigned long value;
  1591. if (count > 31)
  1592. return -EINVAL;
  1593. value = simple_strtoul(buffer, NULL, 10);
  1594. if (sony_pic_set_fanspeed(value))
  1595. return -EIO;
  1596. return count;
  1597. }
  1598. static ssize_t sony_pic_fanspeed_show(struct device *dev,
  1599. struct device_attribute *attr, char *buffer)
  1600. {
  1601. u8 value = 0;
  1602. if (sony_pic_get_fanspeed(&value))
  1603. return -EIO;
  1604. return snprintf(buffer, PAGE_SIZE, "%d\n", value);
  1605. }
  1606. #define SPIC_ATTR(_name, _mode) \
  1607. struct device_attribute spic_attr_##_name = __ATTR(_name, \
  1608. _mode, sony_pic_## _name ##_show, \
  1609. sony_pic_## _name ##_store)
  1610. static SPIC_ATTR(bluetoothpower, 0644);
  1611. static SPIC_ATTR(wwanpower, 0644);
  1612. static SPIC_ATTR(fanspeed, 0644);
  1613. static struct attribute *spic_attributes[] = {
  1614. &spic_attr_bluetoothpower.attr,
  1615. &spic_attr_wwanpower.attr,
  1616. &spic_attr_fanspeed.attr,
  1617. NULL
  1618. };
  1619. static struct attribute_group spic_attribute_group = {
  1620. .attrs = spic_attributes
  1621. };
  1622. /******** SONYPI compatibility **********/
  1623. #ifdef CONFIG_SONYPI_COMPAT
  1624. /* battery / brightness / temperature addresses */
  1625. #define SONYPI_BAT_FLAGS 0x81
  1626. #define SONYPI_LCD_LIGHT 0x96
  1627. #define SONYPI_BAT1_PCTRM 0xa0
  1628. #define SONYPI_BAT1_LEFT 0xa2
  1629. #define SONYPI_BAT1_MAXRT 0xa4
  1630. #define SONYPI_BAT2_PCTRM 0xa8
  1631. #define SONYPI_BAT2_LEFT 0xaa
  1632. #define SONYPI_BAT2_MAXRT 0xac
  1633. #define SONYPI_BAT1_MAXTK 0xb0
  1634. #define SONYPI_BAT1_FULL 0xb2
  1635. #define SONYPI_BAT2_MAXTK 0xb8
  1636. #define SONYPI_BAT2_FULL 0xba
  1637. #define SONYPI_TEMP_STATUS 0xC1
  1638. struct sonypi_compat_s {
  1639. struct fasync_struct *fifo_async;
  1640. struct kfifo *fifo;
  1641. spinlock_t fifo_lock;
  1642. wait_queue_head_t fifo_proc_list;
  1643. atomic_t open_count;
  1644. };
  1645. static struct sonypi_compat_s sonypi_compat = {
  1646. .open_count = ATOMIC_INIT(0),
  1647. };
  1648. static int sonypi_misc_fasync(int fd, struct file *filp, int on)
  1649. {
  1650. int retval;
  1651. retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
  1652. if (retval < 0)
  1653. return retval;
  1654. return 0;
  1655. }
  1656. static int sonypi_misc_release(struct inode *inode, struct file *file)
  1657. {
  1658. atomic_dec(&sonypi_compat.open_count);
  1659. return 0;
  1660. }
  1661. static int sonypi_misc_open(struct inode *inode, struct file *file)
  1662. {
  1663. /* Flush input queue on first open */
  1664. lock_kernel();
  1665. if (atomic_inc_return(&sonypi_compat.open_count) == 1)
  1666. kfifo_reset(sonypi_compat.fifo);
  1667. unlock_kernel();
  1668. return 0;
  1669. }
  1670. static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
  1671. size_t count, loff_t *pos)
  1672. {
  1673. ssize_t ret;
  1674. unsigned char c;
  1675. if ((kfifo_len(sonypi_compat.fifo) == 0) &&
  1676. (file->f_flags & O_NONBLOCK))
  1677. return -EAGAIN;
  1678. ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
  1679. kfifo_len(sonypi_compat.fifo) != 0);
  1680. if (ret)
  1681. return ret;
  1682. while (ret < count &&
  1683. (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
  1684. if (put_user(c, buf++))
  1685. return -EFAULT;
  1686. ret++;
  1687. }
  1688. if (ret > 0) {
  1689. struct inode *inode = file->f_path.dentry->d_inode;
  1690. inode->i_atime = current_fs_time(inode->i_sb);
  1691. }
  1692. return ret;
  1693. }
  1694. static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
  1695. {
  1696. poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
  1697. if (kfifo_len(sonypi_compat.fifo))
  1698. return POLLIN | POLLRDNORM;
  1699. return 0;
  1700. }
  1701. static int ec_read16(u8 addr, u16 *value)
  1702. {
  1703. u8 val_lb, val_hb;
  1704. if (ec_read(addr, &val_lb))
  1705. return -1;
  1706. if (ec_read(addr + 1, &val_hb))
  1707. return -1;
  1708. *value = val_lb | (val_hb << 8);
  1709. return 0;
  1710. }
  1711. static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
  1712. unsigned int cmd, unsigned long arg)
  1713. {
  1714. int ret = 0;
  1715. void __user *argp = (void __user *)arg;
  1716. u8 val8;
  1717. u16 val16;
  1718. int value;
  1719. mutex_lock(&spic_dev.lock);
  1720. switch (cmd) {
  1721. case SONYPI_IOCGBRT:
  1722. if (sony_backlight_device == NULL) {
  1723. ret = -EIO;
  1724. break;
  1725. }
  1726. if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
  1727. ret = -EIO;
  1728. break;
  1729. }
  1730. val8 = ((value & 0xff) - 1) << 5;
  1731. if (copy_to_user(argp, &val8, sizeof(val8)))
  1732. ret = -EFAULT;
  1733. break;
  1734. case SONYPI_IOCSBRT:
  1735. if (sony_backlight_device == NULL) {
  1736. ret = -EIO;
  1737. break;
  1738. }
  1739. if (copy_from_user(&val8, argp, sizeof(val8))) {
  1740. ret = -EFAULT;
  1741. break;
  1742. }
  1743. if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
  1744. (val8 >> 5) + 1, NULL)) {
  1745. ret = -EIO;
  1746. break;
  1747. }
  1748. /* sync the backlight device status */
  1749. sony_backlight_device->props.brightness =
  1750. sony_backlight_get_brightness(sony_backlight_device);
  1751. break;
  1752. case SONYPI_IOCGBAT1CAP:
  1753. if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
  1754. ret = -EIO;
  1755. break;
  1756. }
  1757. if (copy_to_user(argp, &val16, sizeof(val16)))
  1758. ret = -EFAULT;
  1759. break;
  1760. case SONYPI_IOCGBAT1REM:
  1761. if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
  1762. ret = -EIO;
  1763. break;
  1764. }
  1765. if (copy_to_user(argp, &val16, sizeof(val16)))
  1766. ret = -EFAULT;
  1767. break;
  1768. case SONYPI_IOCGBAT2CAP:
  1769. if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
  1770. ret = -EIO;
  1771. break;
  1772. }
  1773. if (copy_to_user(argp, &val16, sizeof(val16)))
  1774. ret = -EFAULT;
  1775. break;
  1776. case SONYPI_IOCGBAT2REM:
  1777. if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
  1778. ret = -EIO;
  1779. break;
  1780. }
  1781. if (copy_to_user(argp, &val16, sizeof(val16)))
  1782. ret = -EFAULT;
  1783. break;
  1784. case SONYPI_IOCGBATFLAGS:
  1785. if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
  1786. ret = -EIO;
  1787. break;
  1788. }
  1789. val8 &= 0x07;
  1790. if (copy_to_user(argp, &val8, sizeof(val8)))
  1791. ret = -EFAULT;
  1792. break;
  1793. case SONYPI_IOCGBLUE:
  1794. val8 = spic_dev.bluetooth_power;
  1795. if (copy_to_user(argp, &val8, sizeof(val8)))
  1796. ret = -EFAULT;
  1797. break;
  1798. case SONYPI_IOCSBLUE:
  1799. if (copy_from_user(&val8, argp, sizeof(val8))) {
  1800. ret = -EFAULT;
  1801. break;
  1802. }
  1803. __sony_pic_set_bluetoothpower(val8);
  1804. break;
  1805. /* FAN Controls */
  1806. case SONYPI_IOCGFAN:
  1807. if (sony_pic_get_fanspeed(&val8)) {
  1808. ret = -EIO;
  1809. break;
  1810. }
  1811. if (copy_to_user(argp, &val8, sizeof(val8)))
  1812. ret = -EFAULT;
  1813. break;
  1814. case SONYPI_IOCSFAN:
  1815. if (copy_from_user(&val8, argp, sizeof(val8))) {
  1816. ret = -EFAULT;
  1817. break;
  1818. }
  1819. if (sony_pic_set_fanspeed(val8))
  1820. ret = -EIO;
  1821. break;
  1822. /* GET Temperature (useful under APM) */
  1823. case SONYPI_IOCGTEMP:
  1824. if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
  1825. ret = -EIO;
  1826. break;
  1827. }
  1828. if (copy_to_user(argp, &val8, sizeof(val8)))
  1829. ret = -EFAULT;
  1830. break;
  1831. default:
  1832. ret = -EINVAL;
  1833. }
  1834. mutex_unlock(&spic_dev.lock);
  1835. return ret;
  1836. }
  1837. static const struct file_operations sonypi_misc_fops = {
  1838. .owner = THIS_MODULE,
  1839. .read = sonypi_misc_read,
  1840. .poll = sonypi_misc_poll,
  1841. .open = sonypi_misc_open,
  1842. .release = sonypi_misc_release,
  1843. .fasync = sonypi_misc_fasync,
  1844. .ioctl = sonypi_misc_ioctl,
  1845. };
  1846. static struct miscdevice sonypi_misc_device = {
  1847. .minor = MISC_DYNAMIC_MINOR,
  1848. .name = "sonypi",
  1849. .fops = &sonypi_misc_fops,
  1850. };
  1851. static void sonypi_compat_report_event(u8 event)
  1852. {
  1853. kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
  1854. kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
  1855. wake_up_interruptible(&sonypi_compat.fifo_proc_list);
  1856. }
  1857. static int sonypi_compat_init(void)
  1858. {
  1859. int error;
  1860. spin_lock_init(&sonypi_compat.fifo_lock);
  1861. sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
  1862. &sonypi_compat.fifo_lock);
  1863. if (IS_ERR(sonypi_compat.fifo)) {
  1864. printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
  1865. return PTR_ERR(sonypi_compat.fifo);
  1866. }
  1867. init_waitqueue_head(&sonypi_compat.fifo_proc_list);
  1868. if (minor != -1)
  1869. sonypi_misc_device.minor = minor;
  1870. error = misc_register(&sonypi_misc_device);
  1871. if (error) {
  1872. printk(KERN_ERR DRV_PFX "misc_register failed\n");
  1873. goto err_free_kfifo;
  1874. }
  1875. if (minor == -1)
  1876. printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
  1877. sonypi_misc_device.minor);
  1878. return 0;
  1879. err_free_kfifo:
  1880. kfifo_free(sonypi_compat.fifo);
  1881. return error;
  1882. }
  1883. static void sonypi_compat_exit(void)
  1884. {
  1885. misc_deregister(&sonypi_misc_device);
  1886. kfifo_free(sonypi_compat.fifo);
  1887. }
  1888. #else
  1889. static int sonypi_compat_init(void) { return 0; }
  1890. static void sonypi_compat_exit(void) { }
  1891. static void sonypi_compat_report_event(u8 event) { }
  1892. #endif /* CONFIG_SONYPI_COMPAT */
  1893. /*
  1894. * ACPI callbacks
  1895. */
  1896. static acpi_status
  1897. sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
  1898. {
  1899. u32 i;
  1900. struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
  1901. switch (resource->type) {
  1902. case ACPI_RESOURCE_TYPE_START_DEPENDENT:
  1903. {
  1904. /* start IO enumeration */
  1905. struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
  1906. if (!ioport)
  1907. return AE_ERROR;
  1908. list_add(&ioport->list, &dev->ioports);
  1909. return AE_OK;
  1910. }
  1911. case ACPI_RESOURCE_TYPE_END_DEPENDENT:
  1912. /* end IO enumeration */
  1913. return AE_OK;
  1914. case ACPI_RESOURCE_TYPE_IRQ:
  1915. {
  1916. struct acpi_resource_irq *p = &resource->data.irq;
  1917. struct sony_pic_irq *interrupt = NULL;
  1918. if (!p || !p->interrupt_count) {
  1919. /*
  1920. * IRQ descriptors may have no IRQ# bits set,
  1921. * particularly those those w/ _STA disabled
  1922. */
  1923. dprintk("Blank IRQ resource\n");
  1924. return AE_OK;
  1925. }
  1926. for (i = 0; i < p->interrupt_count; i++) {
  1927. if (!p->interrupts[i]) {
  1928. printk(KERN_WARNING DRV_PFX
  1929. "Invalid IRQ %d\n",
  1930. p->interrupts[i]);
  1931. continue;
  1932. }
  1933. interrupt = kzalloc(sizeof(*interrupt),
  1934. GFP_KERNEL);
  1935. if (!interrupt)
  1936. return AE_ERROR;
  1937. list_add(&interrupt->list, &dev->interrupts);
  1938. interrupt->irq.triggering = p->triggering;
  1939. interrupt->irq.polarity = p->polarity;
  1940. interrupt->irq.sharable = p->sharable;
  1941. interrupt->irq.interrupt_count = 1;
  1942. interrupt->irq.interrupts[0] = p->interrupts[i];
  1943. }
  1944. return AE_OK;
  1945. }
  1946. case ACPI_RESOURCE_TYPE_IO:
  1947. {
  1948. struct acpi_resource_io *io = &resource->data.io;
  1949. struct sony_pic_ioport *ioport =
  1950. list_first_entry(&dev->ioports, struct sony_pic_ioport, list);
  1951. if (!io) {
  1952. dprintk("Blank IO resource\n");
  1953. return AE_OK;
  1954. }
  1955. if (!ioport->io1.minimum) {
  1956. memcpy(&ioport->io1, io, sizeof(*io));
  1957. dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum,
  1958. ioport->io1.address_length);
  1959. }
  1960. else if (!ioport->io2.minimum) {
  1961. memcpy(&ioport->io2, io, sizeof(*io));
  1962. dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum,
  1963. ioport->io2.address_length);
  1964. }
  1965. else {
  1966. printk(KERN_ERR DRV_PFX "Unknown SPIC Type, more than 2 IO Ports\n");
  1967. return AE_ERROR;
  1968. }
  1969. return AE_OK;
  1970. }
  1971. default:
  1972. dprintk("Resource %d isn't an IRQ nor an IO port\n",
  1973. resource->type);
  1974. case ACPI_RESOURCE_TYPE_END_TAG:
  1975. return AE_OK;
  1976. }
  1977. return AE_CTRL_TERMINATE;
  1978. }
  1979. static int sony_pic_possible_resources(struct acpi_device *device)
  1980. {
  1981. int result = 0;
  1982. acpi_status status = AE_OK;
  1983. if (!device)
  1984. return -EINVAL;
  1985. /* get device status */
  1986. /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
  1987. dprintk("Evaluating _STA\n");
  1988. result = acpi_bus_get_status(device);
  1989. if (result) {
  1990. printk(KERN_WARNING DRV_PFX "Unable to read status\n");
  1991. goto end;
  1992. }
  1993. if (!device->status.enabled)
  1994. dprintk("Device disabled\n");
  1995. else
  1996. dprintk("Device enabled\n");
  1997. /*
  1998. * Query and parse 'method'
  1999. */
  2000. dprintk("Evaluating %s\n", METHOD_NAME__PRS);
  2001. status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
  2002. sony_pic_read_possible_resource, &spic_dev);
  2003. if (ACPI_FAILURE(status)) {
  2004. printk(KERN_WARNING DRV_PFX
  2005. "Failure evaluating %s\n",
  2006. METHOD_NAME__PRS);
  2007. result = -ENODEV;
  2008. }
  2009. end:
  2010. return result;
  2011. }
  2012. /*
  2013. * Disable the spic device by calling its _DIS method
  2014. */
  2015. static int sony_pic_disable(struct acpi_device *device)
  2016. {
  2017. acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL,
  2018. NULL);
  2019. if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND)
  2020. return -ENXIO;
  2021. dprintk("Device disabled\n");
  2022. return 0;
  2023. }
  2024. /*
  2025. * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
  2026. *
  2027. * Call _SRS to set current resources
  2028. */
  2029. static int sony_pic_enable(struct acpi_device *device,
  2030. struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
  2031. {
  2032. acpi_status status;
  2033. int result = 0;
  2034. /* Type 1 resource layout is:
  2035. * IO
  2036. * IO
  2037. * IRQNoFlags
  2038. * End
  2039. *
  2040. * Type 2 and 3 resource layout is:
  2041. * IO
  2042. * IRQNoFlags
  2043. * End
  2044. */
  2045. struct {
  2046. struct acpi_resource res1;
  2047. struct acpi_resource res2;
  2048. struct acpi_resource res3;
  2049. struct acpi_resource res4;
  2050. } *resource;
  2051. struct acpi_buffer buffer = { 0, NULL };
  2052. if (!ioport || !irq)
  2053. return -EINVAL;
  2054. /* init acpi_buffer */
  2055. resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
  2056. if (!resource)
  2057. return -ENOMEM;
  2058. buffer.length = sizeof(*resource) + 1;
  2059. buffer.pointer = resource;
  2060. /* setup Type 1 resources */
  2061. if (spic_dev.control->model == SONYPI_DEVICE_TYPE1) {
  2062. /* setup io resources */
  2063. resource->res1.type = ACPI_RESOURCE_TYPE_IO;
  2064. resource->res1.length = sizeof(struct acpi_resource);
  2065. memcpy(&resource->res1.data.io, &ioport->io1,
  2066. sizeof(struct acpi_resource_io));
  2067. resource->res2.type = ACPI_RESOURCE_TYPE_IO;
  2068. resource->res2.length = sizeof(struct acpi_resource);
  2069. memcpy(&resource->res2.data.io, &ioport->io2,
  2070. sizeof(struct acpi_resource_io));
  2071. /* setup irq resource */
  2072. resource->res3.type = ACPI_RESOURCE_TYPE_IRQ;
  2073. resource->res3.length = sizeof(struct acpi_resource);
  2074. memcpy(&resource->res3.data.irq, &irq->irq,
  2075. sizeof(struct acpi_resource_irq));
  2076. /* we requested a shared irq */
  2077. resource->res3.data.irq.sharable = ACPI_SHARED;
  2078. resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
  2079. }
  2080. /* setup Type 2/3 resources */
  2081. else {
  2082. /* setup io resource */
  2083. resource->res1.type = ACPI_RESOURCE_TYPE_IO;
  2084. resource->res1.length = sizeof(struct acpi_resource);
  2085. memcpy(&resource->res1.data.io, &ioport->io1,
  2086. sizeof(struct acpi_resource_io));
  2087. /* setup irq resource */
  2088. resource->res2.type = ACPI_RESOURCE_TYPE_IRQ;
  2089. resource->res2.length = sizeof(struct acpi_resource);
  2090. memcpy(&resource->res2.data.irq, &irq->irq,
  2091. sizeof(struct acpi_resource_irq));
  2092. /* we requested a shared irq */
  2093. resource->res2.data.irq.sharable = ACPI_SHARED;
  2094. resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
  2095. }
  2096. /* Attempt to set the resource */
  2097. dprintk("Evaluating _SRS\n");
  2098. status = acpi_set_current_resources(device->handle, &buffer);
  2099. /* check for total failure */
  2100. if (ACPI_FAILURE(status)) {
  2101. printk(KERN_ERR DRV_PFX "Error evaluating _SRS\n");
  2102. result = -ENODEV;
  2103. goto end;
  2104. }
  2105. /* Necessary device initializations calls (from sonypi) */
  2106. sony_pic_call1(0x82);
  2107. sony_pic_call2(0x81, 0xff);
  2108. sony_pic_call1(compat ? 0x92 : 0x82);
  2109. end:
  2110. kfree(resource);
  2111. return result;
  2112. }
  2113. /*****************
  2114. *
  2115. * ISR: some event is available
  2116. *
  2117. *****************/
  2118. static irqreturn_t sony_pic_irq(int irq, void *dev_id)
  2119. {
  2120. int i, j;
  2121. u8 ev = 0;
  2122. u8 data_mask = 0;
  2123. u8 device_event = 0;
  2124. struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
  2125. ev = inb_p(dev->cur_ioport->io1.minimum);
  2126. if (dev->cur_ioport->io2.minimum)
  2127. data_mask = inb_p(dev->cur_ioport->io2.minimum);
  2128. else
  2129. data_mask = inb_p(dev->cur_ioport->io1.minimum +
  2130. dev->control->evport_offset);
  2131. dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
  2132. ev, data_mask, dev->cur_ioport->io1.minimum,
  2133. dev->control->evport_offset);
  2134. if (ev == 0x00 || ev == 0xff)
  2135. return IRQ_HANDLED;
  2136. for (i = 0; dev->control->event_types[i].mask; i++) {
  2137. if ((data_mask & dev->control->event_types[i].data) !=
  2138. dev->control->event_types[i].data)
  2139. continue;
  2140. if (!(mask & dev->control->event_types[i].mask))
  2141. continue;
  2142. for (j = 0; dev->control->event_types[i].events[j].event; j++) {
  2143. if (ev == dev->control->event_types[i].events[j].data) {
  2144. device_event =
  2145. dev->control->
  2146. event_types[i].events[j].event;
  2147. goto found;
  2148. }
  2149. }
  2150. }
  2151. /* Still not able to decode the event try to pass
  2152. * it over to the minidriver
  2153. */
  2154. if (dev->control->handle_irq &&
  2155. dev->control->handle_irq(data_mask, ev) == 0)
  2156. return IRQ_HANDLED;
  2157. dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
  2158. ev, data_mask, dev->cur_ioport->io1.minimum,
  2159. dev->control->evport_offset);
  2160. return IRQ_HANDLED;
  2161. found:
  2162. sony_laptop_report_input_event(device_event);
  2163. acpi_bus_generate_proc_event(dev->acpi_dev, 1, device_event);
  2164. sonypi_compat_report_event(device_event);
  2165. return IRQ_HANDLED;
  2166. }
  2167. /*****************
  2168. *
  2169. * ACPI driver
  2170. *
  2171. *****************/
  2172. static int sony_pic_remove(struct acpi_device *device, int type)
  2173. {
  2174. struct sony_pic_ioport *io, *tmp_io;
  2175. struct sony_pic_irq *irq, *tmp_irq;
  2176. if (sony_pic_disable(device)) {
  2177. printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
  2178. return -ENXIO;
  2179. }
  2180. free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
  2181. release_region(spic_dev.cur_ioport->io1.minimum,
  2182. spic_dev.cur_ioport->io1.address_length);
  2183. if (spic_dev.cur_ioport->io2.minimum)
  2184. release_region(spic_dev.cur_ioport->io2.minimum,
  2185. spic_dev.cur_ioport->io2.address_length);
  2186. sonypi_compat_exit();
  2187. sony_laptop_remove_input();
  2188. /* pf attrs */
  2189. sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
  2190. sony_pf_remove();
  2191. list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
  2192. list_del(&io->list);
  2193. kfree(io);
  2194. }
  2195. list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
  2196. list_del(&irq->list);
  2197. kfree(irq);
  2198. }
  2199. spic_dev.cur_ioport = NULL;
  2200. spic_dev.cur_irq = NULL;
  2201. dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
  2202. return 0;
  2203. }
  2204. static int sony_pic_add(struct acpi_device *device)
  2205. {
  2206. int result;
  2207. struct sony_pic_ioport *io, *tmp_io;
  2208. struct sony_pic_irq *irq, *tmp_irq;
  2209. printk(KERN_INFO DRV_PFX "%s v%s.\n",
  2210. SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
  2211. spic_dev.acpi_dev = device;
  2212. strcpy(acpi_device_class(device), "sony/hotkey");
  2213. sony_pic_detect_device_type(&spic_dev);
  2214. mutex_init(&spic_dev.lock);
  2215. /* read _PRS resources */
  2216. result = sony_pic_possible_resources(device);
  2217. if (result) {
  2218. printk(KERN_ERR DRV_PFX
  2219. "Unabe to read possible resources.\n");
  2220. goto err_free_resources;
  2221. }
  2222. /* setup input devices and helper fifo */
  2223. result = sony_laptop_setup_input(device);
  2224. if (result) {
  2225. printk(KERN_ERR DRV_PFX
  2226. "Unabe to create input devices.\n");
  2227. goto err_free_resources;
  2228. }
  2229. if (sonypi_compat_init())
  2230. goto err_remove_input;
  2231. /* request io port */
  2232. list_for_each_entry_reverse(io, &spic_dev.ioports, list) {
  2233. if (request_region(io->io1.minimum, io->io1.address_length,
  2234. "Sony Programable I/O Device")) {
  2235. dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
  2236. io->io1.minimum, io->io1.maximum,
  2237. io->io1.address_length);
  2238. /* Type 1 have 2 ioports */
  2239. if (io->io2.minimum) {
  2240. if (request_region(io->io2.minimum,
  2241. io->io2.address_length,
  2242. "Sony Programable I/O Device")) {
  2243. dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
  2244. io->io2.minimum, io->io2.maximum,
  2245. io->io2.address_length);
  2246. spic_dev.cur_ioport = io;
  2247. break;
  2248. }
  2249. else {
  2250. dprintk("Unable to get I/O port2: "
  2251. "0x%.4x (0x%.4x) + 0x%.2x\n",
  2252. io->io2.minimum, io->io2.maximum,
  2253. io->io2.address_length);
  2254. release_region(io->io1.minimum,
  2255. io->io1.address_length);
  2256. }
  2257. }
  2258. else {
  2259. spic_dev.cur_ioport = io;
  2260. break;
  2261. }
  2262. }
  2263. }
  2264. if (!spic_dev.cur_ioport) {
  2265. printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
  2266. result = -ENODEV;
  2267. goto err_remove_compat;
  2268. }
  2269. /* request IRQ */
  2270. list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) {
  2271. if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
  2272. IRQF_SHARED, "sony-laptop", &spic_dev)) {
  2273. dprintk("IRQ: %d - triggering: %d - "
  2274. "polarity: %d - shr: %d\n",
  2275. irq->irq.interrupts[0],
  2276. irq->irq.triggering,
  2277. irq->irq.polarity,
  2278. irq->irq.sharable);
  2279. spic_dev.cur_irq = irq;
  2280. break;
  2281. }
  2282. }
  2283. if (!spic_dev.cur_irq) {
  2284. printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
  2285. result = -ENODEV;
  2286. goto err_release_region;
  2287. }
  2288. /* set resource status _SRS */
  2289. result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
  2290. if (result) {
  2291. printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
  2292. goto err_free_irq;
  2293. }
  2294. spic_dev.bluetooth_power = -1;
  2295. /* create device attributes */
  2296. result = sony_pf_add();
  2297. if (result)
  2298. goto err_disable_device;
  2299. result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
  2300. if (result)
  2301. goto err_remove_pf;
  2302. return 0;
  2303. err_remove_pf:
  2304. sony_pf_remove();
  2305. err_disable_device:
  2306. sony_pic_disable(device);
  2307. err_free_irq:
  2308. free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
  2309. err_release_region:
  2310. release_region(spic_dev.cur_ioport->io1.minimum,
  2311. spic_dev.cur_ioport->io1.address_length);
  2312. if (spic_dev.cur_ioport->io2.minimum)
  2313. release_region(spic_dev.cur_ioport->io2.minimum,
  2314. spic_dev.cur_ioport->io2.address_length);
  2315. err_remove_compat:
  2316. sonypi_compat_exit();
  2317. err_remove_input:
  2318. sony_laptop_remove_input();
  2319. err_free_resources:
  2320. list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
  2321. list_del(&io->list);
  2322. kfree(io);
  2323. }
  2324. list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
  2325. list_del(&irq->list);
  2326. kfree(irq);
  2327. }
  2328. spic_dev.cur_ioport = NULL;
  2329. spic_dev.cur_irq = NULL;
  2330. return result;
  2331. }
  2332. static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
  2333. {
  2334. if (sony_pic_disable(device))
  2335. return -ENXIO;
  2336. return 0;
  2337. }
  2338. static int sony_pic_resume(struct acpi_device *device)
  2339. {
  2340. sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
  2341. return 0;
  2342. }
  2343. static const struct acpi_device_id sony_pic_device_ids[] = {
  2344. {SONY_PIC_HID, 0},
  2345. {"", 0},
  2346. };
  2347. static struct acpi_driver sony_pic_driver = {
  2348. .name = SONY_PIC_DRIVER_NAME,
  2349. .class = SONY_PIC_CLASS,
  2350. .ids = sony_pic_device_ids,
  2351. .owner = THIS_MODULE,
  2352. .ops = {
  2353. .add = sony_pic_add,
  2354. .remove = sony_pic_remove,
  2355. .suspend = sony_pic_suspend,
  2356. .resume = sony_pic_resume,
  2357. },
  2358. };
  2359. static struct dmi_system_id __initdata sonypi_dmi_table[] = {
  2360. {
  2361. .ident = "Sony Vaio",
  2362. .matches = {
  2363. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  2364. DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
  2365. },
  2366. },
  2367. {
  2368. .ident = "Sony Vaio",
  2369. .matches = {
  2370. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  2371. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
  2372. },
  2373. },
  2374. { }
  2375. };
  2376. static int __init sony_laptop_init(void)
  2377. {
  2378. int result;
  2379. if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
  2380. result = acpi_bus_register_driver(&sony_pic_driver);
  2381. if (result) {
  2382. printk(KERN_ERR DRV_PFX
  2383. "Unable to register SPIC driver.");
  2384. goto out;
  2385. }
  2386. }
  2387. result = acpi_bus_register_driver(&sony_nc_driver);
  2388. if (result) {
  2389. printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
  2390. goto out_unregister_pic;
  2391. }
  2392. return 0;
  2393. out_unregister_pic:
  2394. if (!no_spic)
  2395. acpi_bus_unregister_driver(&sony_pic_driver);
  2396. out:
  2397. return result;
  2398. }
  2399. static void __exit sony_laptop_exit(void)
  2400. {
  2401. acpi_bus_unregister_driver(&sony_nc_driver);
  2402. if (!no_spic)
  2403. acpi_bus_unregister_driver(&sony_pic_driver);
  2404. }
  2405. module_init(sony_laptop_init);
  2406. module_exit(sony_laptop_exit);