sony-laptop.c 71 KB

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