samsung-q10.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/dmi.h>
  17. #include <acpi/acpi_drivers.h>
  18. #define SAMSUNGQ10_BL_MAX_INTENSITY 7
  19. static acpi_handle ec_handle;
  20. static bool force;
  21. module_param(force, bool, 0);
  22. MODULE_PARM_DESC(force,
  23. "Disable the DMI check and force the driver to be loaded");
  24. static int samsungq10_bl_set_intensity(struct backlight_device *bd)
  25. {
  26. acpi_status status;
  27. int i;
  28. for (i = 0; i < SAMSUNGQ10_BL_MAX_INTENSITY; i++) {
  29. status = acpi_evaluate_object(ec_handle, "_Q63", NULL, NULL);
  30. if (ACPI_FAILURE(status))
  31. return -EIO;
  32. }
  33. for (i = 0; i < bd->props.brightness; i++) {
  34. status = acpi_evaluate_object(ec_handle, "_Q64", NULL, NULL);
  35. if (ACPI_FAILURE(status))
  36. return -EIO;
  37. }
  38. return 0;
  39. }
  40. static int samsungq10_bl_get_intensity(struct backlight_device *bd)
  41. {
  42. return bd->props.brightness;
  43. }
  44. static const struct backlight_ops samsungq10_bl_ops = {
  45. .get_brightness = samsungq10_bl_get_intensity,
  46. .update_status = samsungq10_bl_set_intensity,
  47. };
  48. static int samsungq10_probe(struct platform_device *pdev)
  49. {
  50. struct backlight_properties props;
  51. struct backlight_device *bd;
  52. memset(&props, 0, sizeof(struct backlight_properties));
  53. props.type = BACKLIGHT_PLATFORM;
  54. props.max_brightness = SAMSUNGQ10_BL_MAX_INTENSITY;
  55. bd = backlight_device_register("samsung", &pdev->dev, NULL,
  56. &samsungq10_bl_ops, &props);
  57. if (IS_ERR(bd))
  58. return PTR_ERR(bd);
  59. platform_set_drvdata(pdev, bd);
  60. return 0;
  61. }
  62. static int samsungq10_remove(struct platform_device *pdev)
  63. {
  64. struct backlight_device *bd = platform_get_drvdata(pdev);
  65. backlight_device_unregister(bd);
  66. return 0;
  67. }
  68. static struct platform_driver samsungq10_driver = {
  69. .driver = {
  70. .name = KBUILD_MODNAME,
  71. .owner = THIS_MODULE,
  72. },
  73. .probe = samsungq10_probe,
  74. .remove = samsungq10_remove,
  75. };
  76. static struct platform_device *samsungq10_device;
  77. static int __init dmi_check_callback(const struct dmi_system_id *id)
  78. {
  79. printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
  80. return 1;
  81. }
  82. static struct dmi_system_id __initdata samsungq10_dmi_table[] = {
  83. {
  84. .ident = "Samsung Q10",
  85. .matches = {
  86. DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
  87. DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
  88. },
  89. .callback = dmi_check_callback,
  90. },
  91. {
  92. .ident = "Samsung Q20",
  93. .matches = {
  94. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
  95. DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
  96. },
  97. .callback = dmi_check_callback,
  98. },
  99. {
  100. .ident = "Samsung Q25",
  101. .matches = {
  102. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
  103. DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
  104. },
  105. .callback = dmi_check_callback,
  106. },
  107. {
  108. .ident = "Dell Latitude X200",
  109. .matches = {
  110. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
  111. DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
  112. },
  113. .callback = dmi_check_callback,
  114. },
  115. { },
  116. };
  117. MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
  118. static int __init samsungq10_init(void)
  119. {
  120. if (!force && !dmi_check_system(samsungq10_dmi_table))
  121. return -ENODEV;
  122. ec_handle = ec_get_handle();
  123. if (!ec_handle)
  124. return -ENODEV;
  125. samsungq10_device = platform_create_bundle(&samsungq10_driver,
  126. samsungq10_probe,
  127. NULL, 0, NULL, 0);
  128. return PTR_ERR_OR_ZERO(samsungq10_device);
  129. }
  130. static void __exit samsungq10_exit(void)
  131. {
  132. platform_device_unregister(samsungq10_device);
  133. platform_driver_unregister(&samsungq10_driver);
  134. }
  135. module_init(samsungq10_init);
  136. module_exit(samsungq10_exit);
  137. MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
  138. MODULE_DESCRIPTION("Samsung Q10 Driver");
  139. MODULE_LICENSE("GPL");