samsung-q10.c 3.6 KB

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