sony-laptop.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  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. #define DRV_PFX "sony-laptop: "
  65. #define dprintk(msg...) do { \
  66. if (debug) printk(KERN_WARNING DRV_PFX msg); \
  67. } while (0)
  68. #define SONY_LAPTOP_DRIVER_VERSION "0.5"
  69. #define SONY_NC_CLASS "sony-nc"
  70. #define SONY_NC_HID "SNY5001"
  71. #define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
  72. #define SONY_PIC_CLASS "sony-pic"
  73. #define SONY_PIC_HID "SNY6001"
  74. #define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
  75. MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
  76. MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
  77. MODULE_LICENSE("GPL");
  78. MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
  79. static int debug;
  80. module_param(debug, int, 0);
  81. MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
  82. "the development of this driver");
  83. static int no_spic; /* = 0 */
  84. module_param(no_spic, int, 0444);
  85. MODULE_PARM_DESC(no_spic,
  86. "set this if you don't want to enable the SPIC device");
  87. static int compat; /* = 0 */
  88. module_param(compat, int, 0444);
  89. MODULE_PARM_DESC(compat,
  90. "set this if you want to enable backward compatibility mode for SPIC");
  91. static unsigned long mask = 0xffffffff;
  92. module_param(mask, ulong, 0644);
  93. MODULE_PARM_DESC(mask,
  94. "set this to the mask of event you want to enable (see doc)");
  95. /*********** Input Devices ***********/
  96. #define SONY_LAPTOP_BUF_SIZE 128
  97. struct sony_laptop_input_s {
  98. atomic_t users;
  99. struct input_dev *jog_dev;
  100. struct input_dev *key_dev;
  101. struct kfifo *fifo;
  102. spinlock_t fifo_lock;
  103. struct workqueue_struct *wq;
  104. };
  105. static struct sony_laptop_input_s sony_laptop_input = {
  106. .users = ATOMIC_INIT(0),
  107. };
  108. struct sony_laptop_keypress {
  109. struct input_dev *dev;
  110. int key;
  111. };
  112. /* Correspondance table between sonypi events and input layer events */
  113. static struct {
  114. int sonypiev;
  115. int inputev;
  116. } sony_laptop_inputkeys[] = {
  117. { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA },
  118. { SONYPI_EVENT_FNKEY_ONLY, KEY_FN },
  119. { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC },
  120. { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 },
  121. { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 },
  122. { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 },
  123. { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 },
  124. { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 },
  125. { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 },
  126. { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 },
  127. { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 },
  128. { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 },
  129. { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 },
  130. { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 },
  131. { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 },
  132. { SONYPI_EVENT_FNKEY_1, KEY_FN_1 },
  133. { SONYPI_EVENT_FNKEY_2, KEY_FN_2 },
  134. { SONYPI_EVENT_FNKEY_D, KEY_FN_D },
  135. { SONYPI_EVENT_FNKEY_E, KEY_FN_E },
  136. { SONYPI_EVENT_FNKEY_F, KEY_FN_F },
  137. { SONYPI_EVENT_FNKEY_S, KEY_FN_S },
  138. { SONYPI_EVENT_FNKEY_B, KEY_FN_B },
  139. { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE },
  140. { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE },
  141. { SONYPI_EVENT_PKEY_P1, KEY_PROG1 },
  142. { SONYPI_EVENT_PKEY_P2, KEY_PROG2 },
  143. { SONYPI_EVENT_PKEY_P3, KEY_PROG3 },
  144. { SONYPI_EVENT_BACK_PRESSED, KEY_BACK },
  145. { SONYPI_EVENT_HELP_PRESSED, KEY_HELP },
  146. { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM },
  147. { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB },
  148. { 0, 0 },
  149. };
  150. /* release buttons after a short delay if pressed */
  151. static void do_sony_laptop_release_key(struct work_struct *work)
  152. {
  153. struct sony_laptop_keypress kp;
  154. while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
  155. sizeof(kp)) == sizeof(kp)) {
  156. msleep(10);
  157. input_report_key(kp.dev, kp.key, 0);
  158. input_sync(kp.dev);
  159. }
  160. }
  161. static DECLARE_WORK(sony_laptop_release_key_work,
  162. do_sony_laptop_release_key);
  163. /* forward event to the input subsytem */
  164. static void sony_laptop_report_input_event(u8 event)
  165. {
  166. struct input_dev *jog_dev = sony_laptop_input.jog_dev;
  167. struct input_dev *key_dev = sony_laptop_input.key_dev;
  168. struct sony_laptop_keypress kp = { NULL };
  169. int i;
  170. if (event == SONYPI_EVENT_FNKEY_RELEASED) {
  171. /* Nothing, not all VAIOs generate this event */
  172. return;
  173. }
  174. /* report events */
  175. switch (event) {
  176. /* jog_dev events */
  177. case SONYPI_EVENT_JOGDIAL_UP:
  178. case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
  179. input_report_rel(jog_dev, REL_WHEEL, 1);
  180. input_sync(jog_dev);
  181. return;
  182. case SONYPI_EVENT_JOGDIAL_DOWN:
  183. case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
  184. input_report_rel(jog_dev, REL_WHEEL, -1);
  185. input_sync(jog_dev);
  186. return;
  187. /* key_dev events */
  188. case SONYPI_EVENT_JOGDIAL_PRESSED:
  189. kp.key = BTN_MIDDLE;
  190. kp.dev = jog_dev;
  191. break;
  192. default:
  193. for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++)
  194. if (event == sony_laptop_inputkeys[i].sonypiev) {
  195. kp.dev = key_dev;
  196. kp.key = sony_laptop_inputkeys[i].inputev;
  197. break;
  198. }
  199. break;
  200. }
  201. if (kp.dev) {
  202. input_report_key(kp.dev, kp.key, 1);
  203. input_sync(kp.dev);
  204. kfifo_put(sony_laptop_input.fifo,
  205. (unsigned char *)&kp, sizeof(kp));
  206. if (!work_pending(&sony_laptop_release_key_work))
  207. queue_work(sony_laptop_input.wq,
  208. &sony_laptop_release_key_work);
  209. } else
  210. dprintk("unknown input event %.2x\n", event);
  211. }
  212. static int sony_laptop_setup_input(void)
  213. {
  214. struct input_dev *jog_dev;
  215. struct input_dev *key_dev;
  216. int i;
  217. int error;
  218. /* don't run again if already initialized */
  219. if (atomic_add_return(1, &sony_laptop_input.users) > 1)
  220. return 0;
  221. /* kfifo */
  222. spin_lock_init(&sony_laptop_input.fifo_lock);
  223. sony_laptop_input.fifo =
  224. kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
  225. &sony_laptop_input.fifo_lock);
  226. if (IS_ERR(sony_laptop_input.fifo)) {
  227. printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
  228. error = PTR_ERR(sony_laptop_input.fifo);
  229. goto err_dec_users;
  230. }
  231. /* init workqueue */
  232. sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop");
  233. if (!sony_laptop_input.wq) {
  234. printk(KERN_ERR DRV_PFX
  235. "Unabe to create workqueue.\n");
  236. error = -ENXIO;
  237. goto err_free_kfifo;
  238. }
  239. /* input keys */
  240. key_dev = input_allocate_device();
  241. if (!key_dev) {
  242. error = -ENOMEM;
  243. goto err_destroy_wq;
  244. }
  245. key_dev->name = "Sony Vaio Keys";
  246. key_dev->id.bustype = BUS_ISA;
  247. key_dev->id.vendor = PCI_VENDOR_ID_SONY;
  248. /* Initialize the Input Drivers: special keys */
  249. key_dev->evbit[0] = BIT(EV_KEY);
  250. for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++)
  251. if (sony_laptop_inputkeys[i].inputev)
  252. set_bit(sony_laptop_inputkeys[i].inputev,
  253. key_dev->keybit);
  254. error = input_register_device(key_dev);
  255. if (error)
  256. goto err_free_keydev;
  257. sony_laptop_input.key_dev = key_dev;
  258. /* jogdial */
  259. jog_dev = input_allocate_device();
  260. if (!jog_dev) {
  261. error = -ENOMEM;
  262. goto err_unregister_keydev;
  263. }
  264. jog_dev->name = "Sony Vaio Jogdial";
  265. jog_dev->id.bustype = BUS_ISA;
  266. jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
  267. jog_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  268. jog_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
  269. jog_dev->relbit[0] = BIT(REL_WHEEL);
  270. error = input_register_device(jog_dev);
  271. if (error)
  272. goto err_free_jogdev;
  273. sony_laptop_input.jog_dev = jog_dev;
  274. return 0;
  275. err_free_jogdev:
  276. input_free_device(jog_dev);
  277. err_unregister_keydev:
  278. input_unregister_device(key_dev);
  279. /* to avoid kref underflow below at input_free_device */
  280. key_dev = NULL;
  281. err_free_keydev:
  282. input_free_device(key_dev);
  283. err_destroy_wq:
  284. destroy_workqueue(sony_laptop_input.wq);
  285. err_free_kfifo:
  286. kfifo_free(sony_laptop_input.fifo);
  287. err_dec_users:
  288. atomic_dec(&sony_laptop_input.users);
  289. return error;
  290. }
  291. static void sony_laptop_remove_input(void)
  292. {
  293. /* cleanup only after the last user has gone */
  294. if (!atomic_dec_and_test(&sony_laptop_input.users))
  295. return;
  296. /* flush workqueue first */
  297. flush_workqueue(sony_laptop_input.wq);
  298. /* destroy input devs */
  299. input_unregister_device(sony_laptop_input.key_dev);
  300. sony_laptop_input.key_dev = NULL;
  301. if (sony_laptop_input.jog_dev) {
  302. input_unregister_device(sony_laptop_input.jog_dev);
  303. sony_laptop_input.jog_dev = NULL;
  304. }
  305. destroy_workqueue(sony_laptop_input.wq);
  306. kfifo_free(sony_laptop_input.fifo);
  307. }
  308. /*********** Platform Device ***********/
  309. static atomic_t sony_pf_users = ATOMIC_INIT(0);
  310. static struct platform_driver sony_pf_driver = {
  311. .driver = {
  312. .name = "sony-laptop",
  313. .owner = THIS_MODULE,
  314. }
  315. };
  316. static struct platform_device *sony_pf_device;
  317. static int sony_pf_add(void)
  318. {
  319. int ret = 0;
  320. /* don't run again if already initialized */
  321. if (atomic_add_return(1, &sony_pf_users) > 1)
  322. return 0;
  323. ret = platform_driver_register(&sony_pf_driver);
  324. if (ret)
  325. goto out;
  326. sony_pf_device = platform_device_alloc("sony-laptop", -1);
  327. if (!sony_pf_device) {
  328. ret = -ENOMEM;
  329. goto out_platform_registered;
  330. }
  331. ret = platform_device_add(sony_pf_device);
  332. if (ret)
  333. goto out_platform_alloced;
  334. return 0;
  335. out_platform_alloced:
  336. platform_device_put(sony_pf_device);
  337. sony_pf_device = NULL;
  338. out_platform_registered:
  339. platform_driver_unregister(&sony_pf_driver);
  340. out:
  341. atomic_dec(&sony_pf_users);
  342. return ret;
  343. }
  344. static void sony_pf_remove(void)
  345. {
  346. /* deregister only after the last user has gone */
  347. if (!atomic_dec_and_test(&sony_pf_users))
  348. return;
  349. platform_device_del(sony_pf_device);
  350. platform_device_put(sony_pf_device);
  351. platform_driver_unregister(&sony_pf_driver);
  352. }
  353. /*********** SNC (SNY5001) Device ***********/
  354. /* the device uses 1-based values, while the backlight subsystem uses
  355. 0-based values */
  356. #define SONY_MAX_BRIGHTNESS 8
  357. #define SNC_VALIDATE_IN 0
  358. #define SNC_VALIDATE_OUT 1
  359. static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
  360. char *);
  361. static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
  362. const char *, size_t);
  363. static int boolean_validate(const int, const int);
  364. static int brightness_default_validate(const int, const int);
  365. struct sony_nc_value {
  366. char *name; /* name of the entry */
  367. char **acpiget; /* names of the ACPI get function */
  368. char **acpiset; /* names of the ACPI set function */
  369. int (*validate)(const int, const int); /* input/output validation */
  370. int value; /* current setting */
  371. int valid; /* Has ever been set */
  372. int debug; /* active only in debug mode ? */
  373. struct device_attribute devattr; /* sysfs atribute */
  374. };
  375. #define SNC_HANDLE_NAMES(_name, _values...) \
  376. static char *snc_##_name[] = { _values, NULL }
  377. #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
  378. { \
  379. .name = __stringify(_name), \
  380. .acpiget = _getters, \
  381. .acpiset = _setters, \
  382. .validate = _validate, \
  383. .debug = _debug, \
  384. .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
  385. }
  386. #define SNC_HANDLE_NULL { .name = NULL }
  387. SNC_HANDLE_NAMES(fnkey_get, "GHKE");
  388. SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
  389. SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
  390. SNC_HANDLE_NAMES(cdpower_get, "GCDP");
  391. SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
  392. SNC_HANDLE_NAMES(audiopower_get, "GAZP");
  393. SNC_HANDLE_NAMES(audiopower_set, "AZPW");
  394. SNC_HANDLE_NAMES(lanpower_get, "GLNP");
  395. SNC_HANDLE_NAMES(lanpower_set, "LNPW");
  396. SNC_HANDLE_NAMES(PID_get, "GPID");
  397. SNC_HANDLE_NAMES(CTR_get, "GCTR");
  398. SNC_HANDLE_NAMES(CTR_set, "SCTR");
  399. SNC_HANDLE_NAMES(PCR_get, "GPCR");
  400. SNC_HANDLE_NAMES(PCR_set, "SPCR");
  401. SNC_HANDLE_NAMES(CMI_get, "GCMI");
  402. SNC_HANDLE_NAMES(CMI_set, "SCMI");
  403. static struct sony_nc_value sony_nc_values[] = {
  404. SNC_HANDLE(brightness_default, snc_brightness_def_get,
  405. snc_brightness_def_set, brightness_default_validate, 0),
  406. SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
  407. SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
  408. SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
  409. boolean_validate, 0),
  410. SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
  411. boolean_validate, 1),
  412. /* unknown methods */
  413. SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
  414. SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
  415. SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
  416. SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
  417. SNC_HANDLE_NULL
  418. };
  419. static acpi_handle sony_nc_acpi_handle;
  420. static struct acpi_device *sony_nc_acpi_device = NULL;
  421. /*
  422. * acpi_evaluate_object wrappers
  423. */
  424. static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
  425. {
  426. struct acpi_buffer output;
  427. union acpi_object out_obj;
  428. acpi_status status;
  429. output.length = sizeof(out_obj);
  430. output.pointer = &out_obj;
  431. status = acpi_evaluate_object(handle, name, NULL, &output);
  432. if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
  433. *result = out_obj.integer.value;
  434. return 0;
  435. }
  436. printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n");
  437. return -1;
  438. }
  439. static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
  440. int *result)
  441. {
  442. struct acpi_object_list params;
  443. union acpi_object in_obj;
  444. struct acpi_buffer output;
  445. union acpi_object out_obj;
  446. acpi_status status;
  447. params.count = 1;
  448. params.pointer = &in_obj;
  449. in_obj.type = ACPI_TYPE_INTEGER;
  450. in_obj.integer.value = value;
  451. output.length = sizeof(out_obj);
  452. output.pointer = &out_obj;
  453. status = acpi_evaluate_object(handle, name, &params, &output);
  454. if (status == AE_OK) {
  455. if (result != NULL) {
  456. if (out_obj.type != ACPI_TYPE_INTEGER) {
  457. printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad "
  458. "return type\n");
  459. return -1;
  460. }
  461. *result = out_obj.integer.value;
  462. }
  463. return 0;
  464. }
  465. printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n");
  466. return -1;
  467. }
  468. /*
  469. * sony_nc_values input/output validate functions
  470. */
  471. /* brightness_default_validate:
  472. *
  473. * manipulate input output values to keep consistency with the
  474. * backlight framework for which brightness values are 0-based.
  475. */
  476. static int brightness_default_validate(const int direction, const int value)
  477. {
  478. switch (direction) {
  479. case SNC_VALIDATE_OUT:
  480. return value - 1;
  481. case SNC_VALIDATE_IN:
  482. if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
  483. return value + 1;
  484. }
  485. return -EINVAL;
  486. }
  487. /* boolean_validate:
  488. *
  489. * on input validate boolean values 0/1, on output just pass the
  490. * received value.
  491. */
  492. static int boolean_validate(const int direction, const int value)
  493. {
  494. if (direction == SNC_VALIDATE_IN) {
  495. if (value != 0 && value != 1)
  496. return -EINVAL;
  497. }
  498. return value;
  499. }
  500. /*
  501. * Sysfs show/store common to all sony_nc_values
  502. */
  503. static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
  504. char *buffer)
  505. {
  506. int value;
  507. struct sony_nc_value *item =
  508. container_of(attr, struct sony_nc_value, devattr);
  509. if (!*item->acpiget)
  510. return -EIO;
  511. if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
  512. return -EIO;
  513. if (item->validate)
  514. value = item->validate(SNC_VALIDATE_OUT, value);
  515. return snprintf(buffer, PAGE_SIZE, "%d\n", value);
  516. }
  517. static ssize_t sony_nc_sysfs_store(struct device *dev,
  518. struct device_attribute *attr,
  519. const char *buffer, size_t count)
  520. {
  521. int value;
  522. struct sony_nc_value *item =
  523. container_of(attr, struct sony_nc_value, devattr);
  524. if (!item->acpiset)
  525. return -EIO;
  526. if (count > 31)
  527. return -EINVAL;
  528. value = simple_strtoul(buffer, NULL, 10);
  529. if (item->validate)
  530. value = item->validate(SNC_VALIDATE_IN, value);
  531. if (value < 0)
  532. return value;
  533. if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
  534. return -EIO;
  535. item->value = value;
  536. item->valid = 1;
  537. return count;
  538. }
  539. /*
  540. * Backlight device
  541. */
  542. static int sony_backlight_update_status(struct backlight_device *bd)
  543. {
  544. return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
  545. bd->props.brightness + 1, NULL);
  546. }
  547. static int sony_backlight_get_brightness(struct backlight_device *bd)
  548. {
  549. int value;
  550. if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
  551. return 0;
  552. /* brightness levels are 1-based, while backlight ones are 0-based */
  553. return value - 1;
  554. }
  555. static struct backlight_device *sony_backlight_device;
  556. static struct backlight_ops sony_backlight_ops = {
  557. .update_status = sony_backlight_update_status,
  558. .get_brightness = sony_backlight_get_brightness,
  559. };
  560. /*
  561. * ACPI callbacks
  562. */
  563. static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
  564. {
  565. dprintk("sony_acpi_notify, event: %d\n", event);
  566. sony_laptop_report_input_event(event);
  567. acpi_bus_generate_event(sony_nc_acpi_device, 1, event);
  568. }
  569. static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
  570. void *context, void **return_value)
  571. {
  572. struct acpi_namespace_node *node;
  573. union acpi_operand_object *operand;
  574. node = (struct acpi_namespace_node *)handle;
  575. operand = (union acpi_operand_object *)node->object;
  576. printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
  577. (u32) operand->method.param_count);
  578. return AE_OK;
  579. }
  580. /*
  581. * ACPI device
  582. */
  583. static int sony_nc_resume(struct acpi_device *device)
  584. {
  585. struct sony_nc_value *item;
  586. for (item = sony_nc_values; item->name; item++) {
  587. int ret;
  588. if (!item->valid)
  589. continue;
  590. ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
  591. item->value, NULL);
  592. if (ret < 0) {
  593. printk("%s: %d\n", __FUNCTION__, ret);
  594. break;
  595. }
  596. }
  597. return 0;
  598. }
  599. static int sony_nc_add(struct acpi_device *device)
  600. {
  601. acpi_status status;
  602. int result = 0;
  603. acpi_handle handle;
  604. struct sony_nc_value *item;
  605. printk(KERN_INFO DRV_PFX "%s v%s.\n",
  606. SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
  607. sony_nc_acpi_device = device;
  608. strcpy(acpi_device_class(device), "sony/hotkey");
  609. sony_nc_acpi_handle = device->handle;
  610. if (debug) {
  611. status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
  612. 1, sony_walk_callback, NULL, NULL);
  613. if (ACPI_FAILURE(status)) {
  614. printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
  615. result = -ENODEV;
  616. goto outwalk;
  617. }
  618. }
  619. /* setup input devices and helper fifo */
  620. result = sony_laptop_setup_input();
  621. if (result) {
  622. printk(KERN_ERR DRV_PFX
  623. "Unabe to create input devices.\n");
  624. goto outwalk;
  625. }
  626. status = acpi_install_notify_handler(sony_nc_acpi_handle,
  627. ACPI_DEVICE_NOTIFY,
  628. sony_acpi_notify, NULL);
  629. if (ACPI_FAILURE(status)) {
  630. printk(KERN_WARNING DRV_PFX "unable to install notify handler\n");
  631. result = -ENODEV;
  632. goto outinput;
  633. }
  634. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", &handle))) {
  635. sony_backlight_device = backlight_device_register("sony", NULL,
  636. NULL,
  637. &sony_backlight_ops);
  638. if (IS_ERR(sony_backlight_device)) {
  639. printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
  640. sony_backlight_device = NULL;
  641. } else {
  642. sony_backlight_device->props.brightness =
  643. sony_backlight_get_brightness
  644. (sony_backlight_device);
  645. sony_backlight_device->props.max_brightness =
  646. SONY_MAX_BRIGHTNESS - 1;
  647. }
  648. }
  649. result = sony_pf_add();
  650. if (result)
  651. goto outbacklight;
  652. /* create sony_pf sysfs attributes related to the SNC device */
  653. for (item = sony_nc_values; item->name; ++item) {
  654. if (!debug && item->debug)
  655. continue;
  656. /* find the available acpiget as described in the DSDT */
  657. for (; item->acpiget && *item->acpiget; ++item->acpiget) {
  658. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
  659. *item->acpiget,
  660. &handle))) {
  661. dprintk("Found %s getter: %s\n",
  662. item->name, *item->acpiget);
  663. item->devattr.attr.mode |= S_IRUGO;
  664. break;
  665. }
  666. }
  667. /* find the available acpiset as described in the DSDT */
  668. for (; item->acpiset && *item->acpiset; ++item->acpiset) {
  669. if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
  670. *item->acpiset,
  671. &handle))) {
  672. dprintk("Found %s setter: %s\n",
  673. item->name, *item->acpiset);
  674. item->devattr.attr.mode |= S_IWUSR;
  675. break;
  676. }
  677. }
  678. if (item->devattr.attr.mode != 0) {
  679. result =
  680. device_create_file(&sony_pf_device->dev,
  681. &item->devattr);
  682. if (result)
  683. goto out_sysfs;
  684. }
  685. }
  686. return 0;
  687. out_sysfs:
  688. for (item = sony_nc_values; item->name; ++item) {
  689. device_remove_file(&sony_pf_device->dev, &item->devattr);
  690. }
  691. sony_pf_remove();
  692. outbacklight:
  693. if (sony_backlight_device)
  694. backlight_device_unregister(sony_backlight_device);
  695. status = acpi_remove_notify_handler(sony_nc_acpi_handle,
  696. ACPI_DEVICE_NOTIFY,
  697. sony_acpi_notify);
  698. if (ACPI_FAILURE(status))
  699. printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
  700. outinput:
  701. sony_laptop_remove_input();
  702. outwalk:
  703. return result;
  704. }
  705. static int sony_nc_remove(struct acpi_device *device, int type)
  706. {
  707. acpi_status status;
  708. struct sony_nc_value *item;
  709. if (sony_backlight_device)
  710. backlight_device_unregister(sony_backlight_device);
  711. sony_nc_acpi_device = NULL;
  712. status = acpi_remove_notify_handler(sony_nc_acpi_handle,
  713. ACPI_DEVICE_NOTIFY,
  714. sony_acpi_notify);
  715. if (ACPI_FAILURE(status))
  716. printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
  717. for (item = sony_nc_values; item->name; ++item) {
  718. device_remove_file(&sony_pf_device->dev, &item->devattr);
  719. }
  720. sony_pf_remove();
  721. sony_laptop_remove_input();
  722. dprintk(SONY_NC_DRIVER_NAME " removed.\n");
  723. return 0;
  724. }
  725. static struct acpi_driver sony_nc_driver = {
  726. .name = SONY_NC_DRIVER_NAME,
  727. .class = SONY_NC_CLASS,
  728. .ids = SONY_NC_HID,
  729. .owner = THIS_MODULE,
  730. .ops = {
  731. .add = sony_nc_add,
  732. .remove = sony_nc_remove,
  733. .resume = sony_nc_resume,
  734. },
  735. };
  736. /*********** SPIC (SNY6001) Device ***********/
  737. #define SONYPI_DEVICE_TYPE1 0x00000001
  738. #define SONYPI_DEVICE_TYPE2 0x00000002
  739. #define SONYPI_DEVICE_TYPE3 0x00000004
  740. #define SONY_PIC_EV_MASK 0xff
  741. struct sony_pic_ioport {
  742. struct acpi_resource_io io;
  743. struct list_head list;
  744. };
  745. struct sony_pic_irq {
  746. struct acpi_resource_irq irq;
  747. struct list_head list;
  748. };
  749. struct sony_pic_dev {
  750. int model;
  751. u8 camera_power;
  752. u8 bluetooth_power;
  753. struct acpi_device *acpi_dev;
  754. struct sony_pic_irq *cur_irq;
  755. struct sony_pic_ioport *cur_ioport;
  756. struct list_head interrupts;
  757. struct list_head ioports;
  758. };
  759. static struct sony_pic_dev spic_dev = {
  760. .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
  761. .ioports = LIST_HEAD_INIT(spic_dev.ioports),
  762. };
  763. /* Event masks */
  764. #define SONYPI_JOGGER_MASK 0x00000001
  765. #define SONYPI_CAPTURE_MASK 0x00000002
  766. #define SONYPI_FNKEY_MASK 0x00000004
  767. #define SONYPI_BLUETOOTH_MASK 0x00000008
  768. #define SONYPI_PKEY_MASK 0x00000010
  769. #define SONYPI_BACK_MASK 0x00000020
  770. #define SONYPI_HELP_MASK 0x00000040
  771. #define SONYPI_LID_MASK 0x00000080
  772. #define SONYPI_ZOOM_MASK 0x00000100
  773. #define SONYPI_THUMBPHRASE_MASK 0x00000200
  774. #define SONYPI_MEYE_MASK 0x00000400
  775. #define SONYPI_MEMORYSTICK_MASK 0x00000800
  776. #define SONYPI_BATTERY_MASK 0x00001000
  777. #define SONYPI_WIRELESS_MASK 0x00002000
  778. struct sonypi_event {
  779. u8 data;
  780. u8 event;
  781. };
  782. /* The set of possible button release events */
  783. static struct sonypi_event sonypi_releaseev[] = {
  784. { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
  785. { 0, 0 }
  786. };
  787. /* The set of possible jogger events */
  788. static struct sonypi_event sonypi_joggerev[] = {
  789. { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
  790. { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
  791. { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
  792. { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
  793. { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
  794. { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
  795. { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
  796. { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
  797. { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
  798. { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
  799. { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
  800. { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
  801. { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
  802. { 0, 0 }
  803. };
  804. /* The set of possible capture button events */
  805. static struct sonypi_event sonypi_captureev[] = {
  806. { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
  807. { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
  808. { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
  809. { 0, 0 }
  810. };
  811. /* The set of possible fnkeys events */
  812. static struct sonypi_event sonypi_fnkeyev[] = {
  813. { 0x10, SONYPI_EVENT_FNKEY_ESC },
  814. { 0x11, SONYPI_EVENT_FNKEY_F1 },
  815. { 0x12, SONYPI_EVENT_FNKEY_F2 },
  816. { 0x13, SONYPI_EVENT_FNKEY_F3 },
  817. { 0x14, SONYPI_EVENT_FNKEY_F4 },
  818. { 0x15, SONYPI_EVENT_FNKEY_F5 },
  819. { 0x16, SONYPI_EVENT_FNKEY_F6 },
  820. { 0x17, SONYPI_EVENT_FNKEY_F7 },
  821. { 0x18, SONYPI_EVENT_FNKEY_F8 },
  822. { 0x19, SONYPI_EVENT_FNKEY_F9 },
  823. { 0x1a, SONYPI_EVENT_FNKEY_F10 },
  824. { 0x1b, SONYPI_EVENT_FNKEY_F11 },
  825. { 0x1c, SONYPI_EVENT_FNKEY_F12 },
  826. { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
  827. { 0x21, SONYPI_EVENT_FNKEY_1 },
  828. { 0x22, SONYPI_EVENT_FNKEY_2 },
  829. { 0x31, SONYPI_EVENT_FNKEY_D },
  830. { 0x32, SONYPI_EVENT_FNKEY_E },
  831. { 0x33, SONYPI_EVENT_FNKEY_F },
  832. { 0x34, SONYPI_EVENT_FNKEY_S },
  833. { 0x35, SONYPI_EVENT_FNKEY_B },
  834. { 0x36, SONYPI_EVENT_FNKEY_ONLY },
  835. { 0, 0 }
  836. };
  837. /* The set of possible program key events */
  838. static struct sonypi_event sonypi_pkeyev[] = {
  839. { 0x01, SONYPI_EVENT_PKEY_P1 },
  840. { 0x02, SONYPI_EVENT_PKEY_P2 },
  841. { 0x04, SONYPI_EVENT_PKEY_P3 },
  842. { 0x5c, SONYPI_EVENT_PKEY_P1 },
  843. { 0, 0 }
  844. };
  845. /* The set of possible bluetooth events */
  846. static struct sonypi_event sonypi_blueev[] = {
  847. { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
  848. { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
  849. { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
  850. { 0, 0 }
  851. };
  852. /* The set of possible wireless events */
  853. static struct sonypi_event sonypi_wlessev[] = {
  854. { 0x59, SONYPI_EVENT_WIRELESS_ON },
  855. { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
  856. { 0, 0 }
  857. };
  858. /* The set of possible back button events */
  859. static struct sonypi_event sonypi_backev[] = {
  860. { 0x20, SONYPI_EVENT_BACK_PRESSED },
  861. { 0, 0 }
  862. };
  863. /* The set of possible help button events */
  864. static struct sonypi_event sonypi_helpev[] = {
  865. { 0x3b, SONYPI_EVENT_HELP_PRESSED },
  866. { 0, 0 }
  867. };
  868. /* The set of possible lid events */
  869. static struct sonypi_event sonypi_lidev[] = {
  870. { 0x51, SONYPI_EVENT_LID_CLOSED },
  871. { 0x50, SONYPI_EVENT_LID_OPENED },
  872. { 0, 0 }
  873. };
  874. /* The set of possible zoom events */
  875. static struct sonypi_event sonypi_zoomev[] = {
  876. { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
  877. { 0, 0 }
  878. };
  879. /* The set of possible thumbphrase events */
  880. static struct sonypi_event sonypi_thumbphraseev[] = {
  881. { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
  882. { 0, 0 }
  883. };
  884. /* The set of possible motioneye camera events */
  885. static struct sonypi_event sonypi_meyeev[] = {
  886. { 0x00, SONYPI_EVENT_MEYE_FACE },
  887. { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
  888. { 0, 0 }
  889. };
  890. /* The set of possible memorystick events */
  891. static struct sonypi_event sonypi_memorystickev[] = {
  892. { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
  893. { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
  894. { 0, 0 }
  895. };
  896. /* The set of possible battery events */
  897. static struct sonypi_event sonypi_batteryev[] = {
  898. { 0x20, SONYPI_EVENT_BATTERY_INSERT },
  899. { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
  900. { 0, 0 }
  901. };
  902. static struct sonypi_eventtypes {
  903. int model;
  904. u8 data;
  905. unsigned long mask;
  906. struct sonypi_event * events;
  907. } sony_pic_eventtypes[] = {
  908. { SONYPI_DEVICE_TYPE1, 0, 0xffffffff, sonypi_releaseev },
  909. { SONYPI_DEVICE_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
  910. { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
  911. { SONYPI_DEVICE_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
  912. { SONYPI_DEVICE_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
  913. { SONYPI_DEVICE_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  914. { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
  915. { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
  916. { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  917. { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
  918. { SONYPI_DEVICE_TYPE2, 0, 0xffffffff, sonypi_releaseev },
  919. { SONYPI_DEVICE_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
  920. { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
  921. { SONYPI_DEVICE_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
  922. { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  923. { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
  924. { SONYPI_DEVICE_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
  925. { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
  926. { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
  927. { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
  928. { SONYPI_DEVICE_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
  929. { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  930. { SONYPI_DEVICE_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  931. { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
  932. { SONYPI_DEVICE_TYPE3, 0, 0xffffffff, sonypi_releaseev },
  933. { SONYPI_DEVICE_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
  934. { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
  935. { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
  936. { SONYPI_DEVICE_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
  937. { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
  938. { 0 }
  939. };
  940. static int sony_pic_detect_device_type(void)
  941. {
  942. struct pci_dev *pcidev;
  943. int model = 0;
  944. if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  945. PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
  946. model = SONYPI_DEVICE_TYPE1;
  947. else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  948. PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
  949. model = SONYPI_DEVICE_TYPE3;
  950. else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
  951. PCI_DEVICE_ID_INTEL_ICH7_1, NULL)))
  952. model = SONYPI_DEVICE_TYPE3;
  953. else
  954. model = SONYPI_DEVICE_TYPE2;
  955. if (pcidev)
  956. pci_dev_put(pcidev);
  957. printk(KERN_INFO DRV_PFX "detected Type%d model\n",
  958. model == SONYPI_DEVICE_TYPE1 ? 1 :
  959. model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
  960. return model;
  961. }
  962. #define ITERATIONS_LONG 10000
  963. #define ITERATIONS_SHORT 10
  964. #define wait_on_command(command, iterations) { \
  965. unsigned int n = iterations; \
  966. while (--n && (command)) \
  967. udelay(1); \
  968. if (!n) \
  969. dprintk("command failed at %s : %s (line %d)\n", \
  970. __FILE__, __FUNCTION__, __LINE__); \
  971. }
  972. static u8 sony_pic_call1(u8 dev)
  973. {
  974. u8 v1, v2;
  975. wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
  976. ITERATIONS_LONG);
  977. outb(dev, spic_dev.cur_ioport->io.minimum + 4);
  978. v1 = inb_p(spic_dev.cur_ioport->io.minimum + 4);
  979. v2 = inb_p(spic_dev.cur_ioport->io.minimum);
  980. dprintk("sony_pic_call1: 0x%.4x\n", (v2 << 8) | v1);
  981. return v2;
  982. }
  983. static u8 sony_pic_call2(u8 dev, u8 fn)
  984. {
  985. u8 v1;
  986. wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
  987. ITERATIONS_LONG);
  988. outb(dev, spic_dev.cur_ioport->io.minimum + 4);
  989. wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
  990. ITERATIONS_LONG);
  991. outb(fn, spic_dev.cur_ioport->io.minimum);
  992. v1 = inb_p(spic_dev.cur_ioport->io.minimum);
  993. dprintk("sony_pic_call2: 0x%.4x\n", v1);
  994. return v1;
  995. }
  996. static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
  997. {
  998. u8 v1;
  999. wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
  1000. outb(dev, spic_dev.cur_ioport->io.minimum + 4);
  1001. wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
  1002. outb(fn, spic_dev.cur_ioport->io.minimum);
  1003. wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
  1004. outb(v, spic_dev.cur_ioport->io.minimum);
  1005. v1 = inb_p(spic_dev.cur_ioport->io.minimum);
  1006. dprintk("sony_pic_call3: 0x%.4x\n", v1);
  1007. return v1;
  1008. }
  1009. /* camera tests and poweron/poweroff */
  1010. #define SONYPI_CAMERA_PICTURE 5
  1011. #define SONYPI_CAMERA_MUTE_MASK 0x40
  1012. #define SONYPI_CAMERA_CONTROL 0x10
  1013. #define SONYPI_CAMERA_STATUS 7
  1014. #define SONYPI_CAMERA_STATUS_READY 0x2
  1015. #define SONYPI_CAMERA_STATUS_POSITION 0x4
  1016. static int sony_pic_camera_ready(void)
  1017. {
  1018. u8 v;
  1019. v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
  1020. return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
  1021. }
  1022. static void sony_pic_camera_off(void)
  1023. {
  1024. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
  1025. SONYPI_CAMERA_MUTE_MASK),
  1026. ITERATIONS_SHORT);
  1027. if (!spic_dev.camera_power)
  1028. return;
  1029. sony_pic_call2(0x91, 0);
  1030. spic_dev.camera_power = 0;
  1031. }
  1032. static void sony_pic_camera_on(void)
  1033. {
  1034. int i, j;
  1035. if (spic_dev.camera_power)
  1036. return;
  1037. for (j = 5; j > 0; j--) {
  1038. while (sony_pic_call2(0x91, 0x1))
  1039. msleep(10);
  1040. sony_pic_call1(0x93);
  1041. for (i = 400; i > 0; i--) {
  1042. if (sony_pic_camera_ready())
  1043. break;
  1044. msleep(10);
  1045. }
  1046. if (i)
  1047. break;
  1048. }
  1049. if (j == 0) {
  1050. printk(KERN_WARNING "sonypi: failed to power on camera\n");
  1051. return;
  1052. }
  1053. wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
  1054. 0x5a),
  1055. ITERATIONS_SHORT);
  1056. spic_dev.camera_power = 1;
  1057. }
  1058. static ssize_t sony_pic_camerapower_store(struct device *dev,
  1059. struct device_attribute *attr,
  1060. const char *buffer, size_t count)
  1061. {
  1062. unsigned long value;
  1063. if (count > 31)
  1064. return -EINVAL;
  1065. value = simple_strtoul(buffer, NULL, 10);
  1066. if (value)
  1067. sony_pic_camera_on();
  1068. else
  1069. sony_pic_camera_off();
  1070. return count;
  1071. }
  1072. static ssize_t sony_pic_camerapower_show(struct device *dev,
  1073. struct device_attribute *attr, char *buffer)
  1074. {
  1075. return snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.camera_power);
  1076. }
  1077. /* bluetooth subsystem power state */
  1078. static void sony_pic_set_bluetoothpower(u8 state)
  1079. {
  1080. state = !!state;
  1081. if (spic_dev.bluetooth_power == state)
  1082. return;
  1083. sony_pic_call2(0x96, state);
  1084. sony_pic_call1(0x82);
  1085. spic_dev.bluetooth_power = state;
  1086. }
  1087. static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
  1088. struct device_attribute *attr,
  1089. const char *buffer, size_t count)
  1090. {
  1091. unsigned long value;
  1092. if (count > 31)
  1093. return -EINVAL;
  1094. value = simple_strtoul(buffer, NULL, 10);
  1095. sony_pic_set_bluetoothpower(value);
  1096. return count;
  1097. }
  1098. static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
  1099. struct device_attribute *attr, char *buffer)
  1100. {
  1101. return snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
  1102. }
  1103. /* fan speed */
  1104. /* FAN0 information (reverse engineered from ACPI tables) */
  1105. #define SONY_PIC_FAN0_STATUS 0x93
  1106. static ssize_t sony_pic_fanspeed_store(struct device *dev,
  1107. struct device_attribute *attr,
  1108. const char *buffer, size_t count)
  1109. {
  1110. unsigned long value;
  1111. if (count > 31)
  1112. return -EINVAL;
  1113. value = simple_strtoul(buffer, NULL, 10);
  1114. if (ec_write(SONY_PIC_FAN0_STATUS, value))
  1115. return -EIO;
  1116. return count;
  1117. }
  1118. static ssize_t sony_pic_fanspeed_show(struct device *dev,
  1119. struct device_attribute *attr, char *buffer)
  1120. {
  1121. u8 value = 0;
  1122. if (ec_read(SONY_PIC_FAN0_STATUS, &value))
  1123. return -EIO;
  1124. return snprintf(buffer, PAGE_SIZE, "%d\n", value);
  1125. }
  1126. #define SPIC_ATTR(_name, _mode) \
  1127. struct device_attribute spic_attr_##_name = __ATTR(_name, \
  1128. _mode, sony_pic_## _name ##_show, \
  1129. sony_pic_## _name ##_store)
  1130. static SPIC_ATTR(camerapower, 0644);
  1131. static SPIC_ATTR(bluetoothpower, 0644);
  1132. static SPIC_ATTR(fanspeed, 0644);
  1133. static struct attribute *spic_attributes[] = {
  1134. &spic_attr_camerapower.attr,
  1135. &spic_attr_bluetoothpower.attr,
  1136. &spic_attr_fanspeed.attr,
  1137. NULL
  1138. };
  1139. static struct attribute_group spic_attribute_group = {
  1140. .attrs = spic_attributes
  1141. };
  1142. /*
  1143. * ACPI callbacks
  1144. */
  1145. static acpi_status
  1146. sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
  1147. {
  1148. u32 i;
  1149. struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
  1150. switch (resource->type) {
  1151. case ACPI_RESOURCE_TYPE_START_DEPENDENT:
  1152. case ACPI_RESOURCE_TYPE_END_DEPENDENT:
  1153. return AE_OK;
  1154. case ACPI_RESOURCE_TYPE_IRQ:
  1155. {
  1156. struct acpi_resource_irq *p = &resource->data.irq;
  1157. struct sony_pic_irq *interrupt = NULL;
  1158. if (!p || !p->interrupt_count) {
  1159. /*
  1160. * IRQ descriptors may have no IRQ# bits set,
  1161. * particularly those those w/ _STA disabled
  1162. */
  1163. dprintk("Blank IRQ resource\n");
  1164. return AE_OK;
  1165. }
  1166. for (i = 0; i < p->interrupt_count; i++) {
  1167. if (!p->interrupts[i]) {
  1168. printk(KERN_WARNING DRV_PFX
  1169. "Invalid IRQ %d\n",
  1170. p->interrupts[i]);
  1171. continue;
  1172. }
  1173. interrupt = kzalloc(sizeof(*interrupt),
  1174. GFP_KERNEL);
  1175. if (!interrupt)
  1176. return AE_ERROR;
  1177. list_add(&interrupt->list, &dev->interrupts);
  1178. interrupt->irq.triggering = p->triggering;
  1179. interrupt->irq.polarity = p->polarity;
  1180. interrupt->irq.sharable = p->sharable;
  1181. interrupt->irq.interrupt_count = 1;
  1182. interrupt->irq.interrupts[0] = p->interrupts[i];
  1183. }
  1184. return AE_OK;
  1185. }
  1186. case ACPI_RESOURCE_TYPE_IO:
  1187. {
  1188. struct acpi_resource_io *io = &resource->data.io;
  1189. struct sony_pic_ioport *ioport = NULL;
  1190. if (!io) {
  1191. dprintk("Blank IO resource\n");
  1192. return AE_OK;
  1193. }
  1194. ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
  1195. if (!ioport)
  1196. return AE_ERROR;
  1197. list_add(&ioport->list, &dev->ioports);
  1198. memcpy(&ioport->io, io, sizeof(*io));
  1199. return AE_OK;
  1200. }
  1201. default:
  1202. dprintk("Resource %d isn't an IRQ nor an IO port\n",
  1203. resource->type);
  1204. case ACPI_RESOURCE_TYPE_END_TAG:
  1205. return AE_OK;
  1206. }
  1207. return AE_CTRL_TERMINATE;
  1208. }
  1209. static int sony_pic_possible_resources(struct acpi_device *device)
  1210. {
  1211. int result = 0;
  1212. acpi_status status = AE_OK;
  1213. if (!device)
  1214. return -EINVAL;
  1215. /* get device status */
  1216. /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
  1217. dprintk("Evaluating _STA\n");
  1218. result = acpi_bus_get_status(device);
  1219. if (result) {
  1220. printk(KERN_WARNING DRV_PFX "Unable to read status\n");
  1221. goto end;
  1222. }
  1223. if (!device->status.enabled)
  1224. dprintk("Device disabled\n");
  1225. else
  1226. dprintk("Device enabled\n");
  1227. /*
  1228. * Query and parse 'method'
  1229. */
  1230. dprintk("Evaluating %s\n", METHOD_NAME__PRS);
  1231. status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
  1232. sony_pic_read_possible_resource, &spic_dev);
  1233. if (ACPI_FAILURE(status)) {
  1234. printk(KERN_WARNING DRV_PFX
  1235. "Failure evaluating %s\n",
  1236. METHOD_NAME__PRS);
  1237. result = -ENODEV;
  1238. }
  1239. end:
  1240. return result;
  1241. }
  1242. /*
  1243. * Disable the spic device by calling its _DIS method
  1244. */
  1245. static int sony_pic_disable(struct acpi_device *device)
  1246. {
  1247. if (ACPI_FAILURE(acpi_evaluate_object(device->handle, "_DIS", 0, NULL)))
  1248. return -ENXIO;
  1249. dprintk("Device disabled\n");
  1250. return 0;
  1251. }
  1252. /*
  1253. * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
  1254. *
  1255. * Call _SRS to set current resources
  1256. */
  1257. static int sony_pic_enable(struct acpi_device *device,
  1258. struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
  1259. {
  1260. acpi_status status;
  1261. int result = 0;
  1262. struct {
  1263. struct acpi_resource io_res;
  1264. struct acpi_resource irq_res;
  1265. struct acpi_resource end;
  1266. } *resource;
  1267. struct acpi_buffer buffer = { 0, NULL };
  1268. if (!ioport || !irq)
  1269. return -EINVAL;
  1270. /* init acpi_buffer */
  1271. resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
  1272. if (!resource)
  1273. return -ENOMEM;
  1274. buffer.length = sizeof(*resource) + 1;
  1275. buffer.pointer = resource;
  1276. /* setup io resource */
  1277. resource->io_res.type = ACPI_RESOURCE_TYPE_IO;
  1278. resource->io_res.length = sizeof(struct acpi_resource);
  1279. memcpy(&resource->io_res.data.io, &ioport->io,
  1280. sizeof(struct acpi_resource_io));
  1281. /* setup irq resource */
  1282. resource->irq_res.type = ACPI_RESOURCE_TYPE_IRQ;
  1283. resource->irq_res.length = sizeof(struct acpi_resource);
  1284. memcpy(&resource->irq_res.data.irq, &irq->irq,
  1285. sizeof(struct acpi_resource_irq));
  1286. /* we requested a shared irq */
  1287. resource->irq_res.data.irq.sharable = ACPI_SHARED;
  1288. resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
  1289. /* Attempt to set the resource */
  1290. dprintk("Evaluating _SRS\n");
  1291. status = acpi_set_current_resources(device->handle, &buffer);
  1292. /* check for total failure */
  1293. if (ACPI_FAILURE(status)) {
  1294. printk(KERN_ERR DRV_PFX "Error evaluating _SRS");
  1295. result = -ENODEV;
  1296. goto end;
  1297. }
  1298. /* Necessary device initializations calls (from sonypi) */
  1299. sony_pic_call1(0x82);
  1300. sony_pic_call2(0x81, 0xff);
  1301. sony_pic_call1(compat ? 0x92 : 0x82);
  1302. end:
  1303. kfree(resource);
  1304. return result;
  1305. }
  1306. /*****************
  1307. *
  1308. * ISR: some event is available
  1309. *
  1310. *****************/
  1311. static irqreturn_t sony_pic_irq(int irq, void *dev_id)
  1312. {
  1313. int i, j;
  1314. u32 port_val = 0;
  1315. u8 ev = 0;
  1316. u8 data_mask = 0;
  1317. u8 device_event = 0;
  1318. struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
  1319. acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val,
  1320. dev->cur_ioport->io.address_length);
  1321. ev = port_val & SONY_PIC_EV_MASK;
  1322. data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8));
  1323. dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n",
  1324. port_val, ev, data_mask, dev->cur_ioport->io.minimum);
  1325. if (ev == 0x00 || ev == 0xff)
  1326. return IRQ_HANDLED;
  1327. for (i = 0; sony_pic_eventtypes[i].model; i++) {
  1328. if (spic_dev.model != sony_pic_eventtypes[i].model)
  1329. continue;
  1330. if ((data_mask & sony_pic_eventtypes[i].data) !=
  1331. sony_pic_eventtypes[i].data)
  1332. continue;
  1333. if (!(mask & sony_pic_eventtypes[i].mask))
  1334. continue;
  1335. for (j = 0; sony_pic_eventtypes[i].events[j].event; j++) {
  1336. if (ev == sony_pic_eventtypes[i].events[j].data) {
  1337. device_event =
  1338. sony_pic_eventtypes[i].events[j].event;
  1339. goto found;
  1340. }
  1341. }
  1342. }
  1343. return IRQ_HANDLED;
  1344. found:
  1345. sony_laptop_report_input_event(device_event);
  1346. acpi_bus_generate_event(spic_dev.acpi_dev, 1, device_event);
  1347. return IRQ_HANDLED;
  1348. }
  1349. /*****************
  1350. *
  1351. * ACPI driver
  1352. *
  1353. *****************/
  1354. static int sony_pic_remove(struct acpi_device *device, int type)
  1355. {
  1356. struct sony_pic_ioport *io, *tmp_io;
  1357. struct sony_pic_irq *irq, *tmp_irq;
  1358. if (sony_pic_disable(device)) {
  1359. printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
  1360. return -ENXIO;
  1361. }
  1362. free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
  1363. release_region(spic_dev.cur_ioport->io.minimum,
  1364. spic_dev.cur_ioport->io.address_length);
  1365. sony_laptop_remove_input();
  1366. /* pf attrs */
  1367. sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
  1368. sony_pf_remove();
  1369. list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
  1370. list_del(&io->list);
  1371. kfree(io);
  1372. }
  1373. list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
  1374. list_del(&irq->list);
  1375. kfree(irq);
  1376. }
  1377. spic_dev.cur_ioport = NULL;
  1378. spic_dev.cur_irq = NULL;
  1379. dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
  1380. return 0;
  1381. }
  1382. static int sony_pic_add(struct acpi_device *device)
  1383. {
  1384. int result;
  1385. struct sony_pic_ioport *io, *tmp_io;
  1386. struct sony_pic_irq *irq, *tmp_irq;
  1387. printk(KERN_INFO DRV_PFX "%s v%s.\n",
  1388. SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
  1389. spic_dev.acpi_dev = device;
  1390. strcpy(acpi_device_class(device), "sony/hotkey");
  1391. spic_dev.model = sony_pic_detect_device_type();
  1392. /* read _PRS resources */
  1393. result = sony_pic_possible_resources(device);
  1394. if (result) {
  1395. printk(KERN_ERR DRV_PFX
  1396. "Unabe to read possible resources.\n");
  1397. goto err_free_resources;
  1398. }
  1399. /* setup input devices and helper fifo */
  1400. result = sony_laptop_setup_input();
  1401. if (result) {
  1402. printk(KERN_ERR DRV_PFX
  1403. "Unabe to create input devices.\n");
  1404. goto err_free_resources;
  1405. }
  1406. /* request io port */
  1407. list_for_each_entry(io, &spic_dev.ioports, list) {
  1408. if (request_region(io->io.minimum, io->io.address_length,
  1409. "Sony Programable I/O Device")) {
  1410. dprintk("I/O port: 0x%.4x (0x%.4x) + 0x%.2x\n",
  1411. io->io.minimum, io->io.maximum,
  1412. io->io.address_length);
  1413. spic_dev.cur_ioport = io;
  1414. break;
  1415. }
  1416. }
  1417. if (!spic_dev.cur_ioport) {
  1418. printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
  1419. result = -ENODEV;
  1420. goto err_remove_input;
  1421. }
  1422. /* request IRQ */
  1423. list_for_each_entry(irq, &spic_dev.interrupts, list) {
  1424. if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
  1425. IRQF_SHARED, "sony-laptop", &spic_dev)) {
  1426. dprintk("IRQ: %d - triggering: %d - "
  1427. "polarity: %d - shr: %d\n",
  1428. irq->irq.interrupts[0],
  1429. irq->irq.triggering,
  1430. irq->irq.polarity,
  1431. irq->irq.sharable);
  1432. spic_dev.cur_irq = irq;
  1433. break;
  1434. }
  1435. }
  1436. if (!spic_dev.cur_irq) {
  1437. printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
  1438. result = -ENODEV;
  1439. goto err_release_region;
  1440. }
  1441. /* set resource status _SRS */
  1442. result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
  1443. if (result) {
  1444. printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
  1445. goto err_free_irq;
  1446. }
  1447. spic_dev.bluetooth_power = -1;
  1448. /* create device attributes */
  1449. result = sony_pf_add();
  1450. if (result)
  1451. goto err_disable_device;
  1452. result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
  1453. if (result)
  1454. goto err_remove_pf;
  1455. return 0;
  1456. err_remove_pf:
  1457. sony_pf_remove();
  1458. err_disable_device:
  1459. sony_pic_disable(device);
  1460. err_free_irq:
  1461. free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
  1462. err_release_region:
  1463. release_region(spic_dev.cur_ioport->io.minimum,
  1464. spic_dev.cur_ioport->io.address_length);
  1465. err_remove_input:
  1466. sony_laptop_remove_input();
  1467. err_free_resources:
  1468. list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
  1469. list_del(&io->list);
  1470. kfree(io);
  1471. }
  1472. list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
  1473. list_del(&irq->list);
  1474. kfree(irq);
  1475. }
  1476. spic_dev.cur_ioport = NULL;
  1477. spic_dev.cur_irq = NULL;
  1478. return result;
  1479. }
  1480. static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
  1481. {
  1482. if (sony_pic_disable(device))
  1483. return -ENXIO;
  1484. return 0;
  1485. }
  1486. static int sony_pic_resume(struct acpi_device *device)
  1487. {
  1488. sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
  1489. return 0;
  1490. }
  1491. static struct acpi_driver sony_pic_driver = {
  1492. .name = SONY_PIC_DRIVER_NAME,
  1493. .class = SONY_PIC_CLASS,
  1494. .ids = SONY_PIC_HID,
  1495. .owner = THIS_MODULE,
  1496. .ops = {
  1497. .add = sony_pic_add,
  1498. .remove = sony_pic_remove,
  1499. .suspend = sony_pic_suspend,
  1500. .resume = sony_pic_resume,
  1501. },
  1502. };
  1503. static struct dmi_system_id __initdata sonypi_dmi_table[] = {
  1504. {
  1505. .ident = "Sony Vaio",
  1506. .matches = {
  1507. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  1508. DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
  1509. },
  1510. },
  1511. {
  1512. .ident = "Sony Vaio",
  1513. .matches = {
  1514. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  1515. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
  1516. },
  1517. },
  1518. { }
  1519. };
  1520. static int __init sony_laptop_init(void)
  1521. {
  1522. int result;
  1523. if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
  1524. result = acpi_bus_register_driver(&sony_pic_driver);
  1525. if (result) {
  1526. printk(KERN_ERR DRV_PFX
  1527. "Unable to register SPIC driver.");
  1528. goto out;
  1529. }
  1530. }
  1531. result = acpi_bus_register_driver(&sony_nc_driver);
  1532. if (result) {
  1533. printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
  1534. goto out_unregister_pic;
  1535. }
  1536. return 0;
  1537. out_unregister_pic:
  1538. if (!no_spic)
  1539. acpi_bus_unregister_driver(&sony_pic_driver);
  1540. out:
  1541. return result;
  1542. }
  1543. static void __exit sony_laptop_exit(void)
  1544. {
  1545. acpi_bus_unregister_driver(&sony_nc_driver);
  1546. if (!no_spic)
  1547. acpi_bus_unregister_driver(&sony_pic_driver);
  1548. }
  1549. module_init(sony_laptop_init);
  1550. module_exit(sony_laptop_exit);