sony-laptop.c 77 KB

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