progear_bl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Backlight Driver for Frontpath ProGear HX1050+
  3. *
  4. * Copyright (c) 2006 Marcin Juszkiewicz
  5. *
  6. * Based on Progear LCD driver by M Schacht
  7. * <mschacht at alumni dot washington dot edu>
  8. *
  9. * Based on Sharp's Corgi Backlight Driver
  10. * Based on Backlight Driver for HP Jornada 680
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mutex.h>
  22. #include <linux/fb.h>
  23. #include <linux/backlight.h>
  24. #include <linux/pci.h>
  25. #define PMU_LPCR 0xB0
  26. #define SB_MPS1 0x61
  27. #define HW_LEVEL_MAX 0x77
  28. #define HW_LEVEL_MIN 0x4f
  29. static struct pci_dev *pmu_dev = NULL;
  30. static struct pci_dev *sb_dev = NULL;
  31. static int progearbl_set_intensity(struct backlight_device *bd)
  32. {
  33. int intensity = bd->props.brightness;
  34. if (bd->props.power != FB_BLANK_UNBLANK)
  35. intensity = 0;
  36. if (bd->props.fb_blank != FB_BLANK_UNBLANK)
  37. intensity = 0;
  38. pci_write_config_byte(pmu_dev, PMU_LPCR, intensity + HW_LEVEL_MIN);
  39. return 0;
  40. }
  41. static int progearbl_get_intensity(struct backlight_device *bd)
  42. {
  43. u8 intensity;
  44. pci_read_config_byte(pmu_dev, PMU_LPCR, &intensity);
  45. return intensity - HW_LEVEL_MIN;
  46. }
  47. static struct backlight_ops progearbl_ops = {
  48. .get_brightness = progearbl_get_intensity,
  49. .update_status = progearbl_set_intensity,
  50. };
  51. static int progearbl_probe(struct platform_device *pdev)
  52. {
  53. u8 temp;
  54. struct backlight_device *progear_backlight_device;
  55. pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, NULL);
  56. if (!pmu_dev) {
  57. printk("ALI M7101 PMU not found.\n");
  58. return -ENODEV;
  59. }
  60. sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  61. if (!sb_dev) {
  62. printk("ALI 1533 SB not found.\n");
  63. pci_dev_put(pmu_dev);
  64. return -ENODEV;
  65. }
  66. /* Set SB_MPS1 to enable brightness control. */
  67. pci_read_config_byte(sb_dev, SB_MPS1, &temp);
  68. pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20);
  69. progear_backlight_device = backlight_device_register("progear-bl",
  70. &pdev->dev, NULL,
  71. &progearbl_ops);
  72. if (IS_ERR(progear_backlight_device))
  73. return PTR_ERR(progear_backlight_device);
  74. platform_set_drvdata(pdev, progear_backlight_device);
  75. progear_backlight_device->props.power = FB_BLANK_UNBLANK;
  76. progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  77. progear_backlight_device->props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  78. progearbl_set_intensity(progear_backlight_device);
  79. return 0;
  80. }
  81. static int progearbl_remove(struct platform_device *pdev)
  82. {
  83. struct backlight_device *bd = platform_get_drvdata(pdev);
  84. backlight_device_unregister(bd);
  85. return 0;
  86. }
  87. static struct platform_driver progearbl_driver = {
  88. .probe = progearbl_probe,
  89. .remove = progearbl_remove,
  90. .driver = {
  91. .name = "progear-bl",
  92. },
  93. };
  94. static struct platform_device *progearbl_device;
  95. static int __init progearbl_init(void)
  96. {
  97. int ret = platform_driver_register(&progearbl_driver);
  98. if (!ret) {
  99. progearbl_device = platform_device_alloc("progear-bl", -1);
  100. if (!progearbl_device)
  101. return -ENOMEM;
  102. ret = platform_device_add(progearbl_device);
  103. if (ret) {
  104. platform_device_put(progearbl_device);
  105. platform_driver_unregister(&progearbl_driver);
  106. }
  107. }
  108. return ret;
  109. }
  110. static void __exit progearbl_exit(void)
  111. {
  112. pci_dev_put(pmu_dev);
  113. pci_dev_put(sb_dev);
  114. platform_device_unregister(progearbl_device);
  115. platform_driver_unregister(&progearbl_driver);
  116. }
  117. module_init(progearbl_init);
  118. module_exit(progearbl_exit);
  119. MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
  120. MODULE_DESCRIPTION("ProGear Backlight Driver");
  121. MODULE_LICENSE("GPL");