sony-laptop.c 58 KB

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