sony-laptop.c 72 KB

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