sony-laptop.c 58 KB

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