sony-laptop.c 71 KB

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