progear_bl.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 const 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. struct backlight_properties props;
  54. u8 temp;
  55. struct backlight_device *progear_backlight_device;
  56. int ret;
  57. pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, NULL);
  58. if (!pmu_dev) {
  59. printk("ALI M7101 PMU not found.\n");
  60. return -ENODEV;
  61. }
  62. sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  63. if (!sb_dev) {
  64. printk("ALI 1533 SB not found.\n");
  65. ret = -ENODEV;
  66. goto put_pmu;
  67. }
  68. /* Set SB_MPS1 to enable brightness control. */
  69. pci_read_config_byte(sb_dev, SB_MPS1, &temp);
  70. pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20);
  71. memset(&props, 0, sizeof(struct backlight_properties));
  72. props.type = BACKLIGHT_RAW;
  73. props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  74. progear_backlight_device = backlight_device_register("progear-bl",
  75. &pdev->dev, NULL,
  76. &progearbl_ops,
  77. &props);
  78. if (IS_ERR(progear_backlight_device)) {
  79. ret = PTR_ERR(progear_backlight_device);
  80. goto put_sb;
  81. }
  82. platform_set_drvdata(pdev, progear_backlight_device);
  83. progear_backlight_device->props.power = FB_BLANK_UNBLANK;
  84. progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  85. progearbl_set_intensity(progear_backlight_device);
  86. return 0;
  87. put_sb:
  88. pci_dev_put(sb_dev);
  89. put_pmu:
  90. pci_dev_put(pmu_dev);
  91. return ret;
  92. }
  93. static int progearbl_remove(struct platform_device *pdev)
  94. {
  95. struct backlight_device *bd = platform_get_drvdata(pdev);
  96. backlight_device_unregister(bd);
  97. return 0;
  98. }
  99. static struct platform_driver progearbl_driver = {
  100. .probe = progearbl_probe,
  101. .remove = progearbl_remove,
  102. .driver = {
  103. .name = "progear-bl",
  104. },
  105. };
  106. static struct platform_device *progearbl_device;
  107. static int __init progearbl_init(void)
  108. {
  109. int ret = platform_driver_register(&progearbl_driver);
  110. if (ret)
  111. return ret;
  112. progearbl_device = platform_device_register_simple("progear-bl", -1,
  113. NULL, 0);
  114. if (IS_ERR(progearbl_device)) {
  115. platform_driver_unregister(&progearbl_driver);
  116. return PTR_ERR(progearbl_device);
  117. }
  118. return 0;
  119. }
  120. static void __exit progearbl_exit(void)
  121. {
  122. pci_dev_put(pmu_dev);
  123. pci_dev_put(sb_dev);
  124. platform_device_unregister(progearbl_device);
  125. platform_driver_unregister(&progearbl_driver);
  126. }
  127. module_init(progearbl_init);
  128. module_exit(progearbl_exit);
  129. MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
  130. MODULE_DESCRIPTION("ProGear Backlight Driver");
  131. MODULE_LICENSE("GPL");