samsung-q10.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Driver for Samsung Q10 and related laptops: controls the backlight
  3. *
  4. * Copyright (c) 2011 Frederick van der Wyck <fvanderwyck@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/backlight.h>
  16. #include <linux/i8042.h>
  17. #include <linux/dmi.h>
  18. #define SAMSUNGQ10_BL_MAX_INTENSITY 255
  19. #define SAMSUNGQ10_BL_DEFAULT_INTENSITY 185
  20. #define SAMSUNGQ10_BL_8042_CMD 0xbe
  21. #define SAMSUNGQ10_BL_8042_DATA { 0x89, 0x91 }
  22. static int samsungq10_bl_brightness;
  23. static bool force;
  24. module_param(force, bool, 0);
  25. MODULE_PARM_DESC(force,
  26. "Disable the DMI check and force the driver to be loaded");
  27. static int samsungq10_bl_set_intensity(struct backlight_device *bd)
  28. {
  29. int brightness = bd->props.brightness;
  30. unsigned char c[3] = SAMSUNGQ10_BL_8042_DATA;
  31. c[2] = (unsigned char)brightness;
  32. i8042_lock_chip();
  33. i8042_command(c, (0x30 << 8) | SAMSUNGQ10_BL_8042_CMD);
  34. i8042_unlock_chip();
  35. samsungq10_bl_brightness = brightness;
  36. return 0;
  37. }
  38. static int samsungq10_bl_get_intensity(struct backlight_device *bd)
  39. {
  40. return samsungq10_bl_brightness;
  41. }
  42. static const struct backlight_ops samsungq10_bl_ops = {
  43. .get_brightness = samsungq10_bl_get_intensity,
  44. .update_status = samsungq10_bl_set_intensity,
  45. };
  46. #ifdef CONFIG_PM_SLEEP
  47. static int samsungq10_suspend(struct device *dev)
  48. {
  49. return 0;
  50. }
  51. static int samsungq10_resume(struct device *dev)
  52. {
  53. struct backlight_device *bd = dev_get_drvdata(dev);
  54. samsungq10_bl_set_intensity(bd);
  55. return 0;
  56. }
  57. #else
  58. #define samsungq10_suspend NULL
  59. #define samsungq10_resume NULL
  60. #endif
  61. static SIMPLE_DEV_PM_OPS(samsungq10_pm_ops,
  62. samsungq10_suspend, samsungq10_resume);
  63. static int __devinit samsungq10_probe(struct platform_device *pdev)
  64. {
  65. struct backlight_properties props;
  66. struct backlight_device *bd;
  67. memset(&props, 0, sizeof(struct backlight_properties));
  68. props.type = BACKLIGHT_PLATFORM;
  69. props.max_brightness = SAMSUNGQ10_BL_MAX_INTENSITY;
  70. bd = backlight_device_register("samsung", &pdev->dev, NULL,
  71. &samsungq10_bl_ops, &props);
  72. if (IS_ERR(bd))
  73. return PTR_ERR(bd);
  74. platform_set_drvdata(pdev, bd);
  75. bd->props.brightness = SAMSUNGQ10_BL_DEFAULT_INTENSITY;
  76. samsungq10_bl_set_intensity(bd);
  77. return 0;
  78. }
  79. static int __devexit samsungq10_remove(struct platform_device *pdev)
  80. {
  81. struct backlight_device *bd = platform_get_drvdata(pdev);
  82. bd->props.brightness = SAMSUNGQ10_BL_DEFAULT_INTENSITY;
  83. samsungq10_bl_set_intensity(bd);
  84. backlight_device_unregister(bd);
  85. return 0;
  86. }
  87. static struct platform_driver samsungq10_driver = {
  88. .driver = {
  89. .name = KBUILD_MODNAME,
  90. .owner = THIS_MODULE,
  91. .pm = &samsungq10_pm_ops,
  92. },
  93. .probe = samsungq10_probe,
  94. .remove = __devexit_p(samsungq10_remove),
  95. };
  96. static struct platform_device *samsungq10_device;
  97. static int __init dmi_check_callback(const struct dmi_system_id *id)
  98. {
  99. printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
  100. return 1;
  101. }
  102. static struct dmi_system_id __initdata samsungq10_dmi_table[] = {
  103. {
  104. .ident = "Samsung Q10",
  105. .matches = {
  106. DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
  107. DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
  108. },
  109. .callback = dmi_check_callback,
  110. },
  111. {
  112. .ident = "Samsung Q20",
  113. .matches = {
  114. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
  115. DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
  116. },
  117. .callback = dmi_check_callback,
  118. },
  119. {
  120. .ident = "Samsung Q25",
  121. .matches = {
  122. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
  123. DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
  124. },
  125. .callback = dmi_check_callback,
  126. },
  127. {
  128. .ident = "Dell Latitude X200",
  129. .matches = {
  130. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
  131. DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
  132. },
  133. .callback = dmi_check_callback,
  134. },
  135. { },
  136. };
  137. MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
  138. static int __init samsungq10_init(void)
  139. {
  140. if (!force && !dmi_check_system(samsungq10_dmi_table))
  141. return -ENODEV;
  142. samsungq10_device = platform_create_bundle(&samsungq10_driver,
  143. samsungq10_probe,
  144. NULL, 0, NULL, 0);
  145. if (IS_ERR(samsungq10_device))
  146. return PTR_ERR(samsungq10_device);
  147. return 0;
  148. }
  149. static void __exit samsungq10_exit(void)
  150. {
  151. platform_device_unregister(samsungq10_device);
  152. platform_driver_unregister(&samsungq10_driver);
  153. }
  154. module_init(samsungq10_init);
  155. module_exit(samsungq10_exit);
  156. MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
  157. MODULE_DESCRIPTION("Samsung Q10 Driver");
  158. MODULE_LICENSE("GPL");