samsung-q10.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 <linux/acpi.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 const struct backlight_ops samsungq10_bl_ops = {
  41. .update_status = samsungq10_bl_set_intensity,
  42. };
  43. static int samsungq10_probe(struct platform_device *pdev)
  44. {
  45. struct backlight_properties props;
  46. struct backlight_device *bd;
  47. memset(&props, 0, sizeof(struct backlight_properties));
  48. props.type = BACKLIGHT_PLATFORM;
  49. props.max_brightness = SAMSUNGQ10_BL_MAX_INTENSITY;
  50. bd = backlight_device_register("samsung", &pdev->dev, NULL,
  51. &samsungq10_bl_ops, &props);
  52. if (IS_ERR(bd))
  53. return PTR_ERR(bd);
  54. platform_set_drvdata(pdev, bd);
  55. return 0;
  56. }
  57. static int samsungq10_remove(struct platform_device *pdev)
  58. {
  59. struct backlight_device *bd = platform_get_drvdata(pdev);
  60. backlight_device_unregister(bd);
  61. return 0;
  62. }
  63. static struct platform_driver samsungq10_driver = {
  64. .driver = {
  65. .name = KBUILD_MODNAME,
  66. },
  67. .probe = samsungq10_probe,
  68. .remove = samsungq10_remove,
  69. };
  70. static struct platform_device *samsungq10_device;
  71. static int __init dmi_check_callback(const struct dmi_system_id *id)
  72. {
  73. printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
  74. return 1;
  75. }
  76. static struct dmi_system_id __initdata samsungq10_dmi_table[] = {
  77. {
  78. .ident = "Samsung Q10",
  79. .matches = {
  80. DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
  81. DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
  82. },
  83. .callback = dmi_check_callback,
  84. },
  85. {
  86. .ident = "Samsung Q20",
  87. .matches = {
  88. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
  89. DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
  90. },
  91. .callback = dmi_check_callback,
  92. },
  93. {
  94. .ident = "Samsung Q25",
  95. .matches = {
  96. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
  97. DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
  98. },
  99. .callback = dmi_check_callback,
  100. },
  101. {
  102. .ident = "Dell Latitude X200",
  103. .matches = {
  104. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
  105. DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
  106. },
  107. .callback = dmi_check_callback,
  108. },
  109. { },
  110. };
  111. MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
  112. static int __init samsungq10_init(void)
  113. {
  114. if (!force && !dmi_check_system(samsungq10_dmi_table))
  115. return -ENODEV;
  116. ec_handle = ec_get_handle();
  117. if (!ec_handle)
  118. return -ENODEV;
  119. samsungq10_device = platform_create_bundle(&samsungq10_driver,
  120. samsungq10_probe,
  121. NULL, 0, NULL, 0);
  122. return PTR_ERR_OR_ZERO(samsungq10_device);
  123. }
  124. static void __exit samsungq10_exit(void)
  125. {
  126. platform_device_unregister(samsungq10_device);
  127. platform_driver_unregister(&samsungq10_driver);
  128. }
  129. module_init(samsungq10_init);
  130. module_exit(samsungq10_exit);
  131. MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
  132. MODULE_DESCRIPTION("Samsung Q10 Driver");
  133. MODULE_LICENSE("GPL");