sony-laptop.c 58 KB

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