sony-laptop.c 85 KB

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