samsung-q10.c 3.6 KB

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