cr_bllcd.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright (c) Intel Corp. 2007.
  3. * All Rights Reserved.
  4. *
  5. * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
  6. * develop this driver.
  7. *
  8. * This file is part of the Carillo Ranch video subsystem driver.
  9. * The Carillo Ranch video subsystem driver is free software;
  10. * you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * The Carillo Ranch video subsystem driver is distributed
  16. * in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this driver; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Authors:
  26. * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
  27. * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/init.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/mutex.h>
  34. #include <linux/fb.h>
  35. #include <linux/backlight.h>
  36. #include <linux/lcd.h>
  37. #include <linux/pci.h>
  38. /* The LVDS- and panel power controls sits on the
  39. * GPIO port of the ISA bridge.
  40. */
  41. #define CRVML_DEVICE_LPC 0x27B8
  42. #define CRVML_REG_GPIOBAR 0x48
  43. #define CRVML_REG_GPIOEN 0x4C
  44. #define CRVML_GPIOEN_BIT (1 << 4)
  45. #define CRVML_PANEL_PORT 0x38
  46. #define CRVML_LVDS_ON 0x00000001
  47. #define CRVML_PANEL_ON 0x00000002
  48. #define CRVML_BACKLIGHT_OFF 0x00000004
  49. /* The PLL Clock register sits on Host bridge */
  50. #define CRVML_DEVICE_MCH 0x5001
  51. #define CRVML_REG_MCHBAR 0x44
  52. #define CRVML_REG_MCHEN 0x54
  53. #define CRVML_MCHEN_BIT (1 << 28)
  54. #define CRVML_MCHMAP_SIZE 4096
  55. #define CRVML_REG_CLOCK 0xc3c
  56. #define CRVML_CLOCK_SHIFT 8
  57. #define CRVML_CLOCK_MASK 0x00000f00
  58. static struct pci_dev *lpc_dev;
  59. static u32 gpio_bar;
  60. struct cr_panel {
  61. struct backlight_device *cr_backlight_device;
  62. struct lcd_device *cr_lcd_device;
  63. };
  64. static int cr_backlight_set_intensity(struct backlight_device *bd)
  65. {
  66. int intensity = bd->props.brightness;
  67. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  68. u32 cur = inl(addr);
  69. if (bd->props.power == FB_BLANK_UNBLANK)
  70. intensity = FB_BLANK_UNBLANK;
  71. if (bd->props.fb_blank == FB_BLANK_UNBLANK)
  72. intensity = FB_BLANK_UNBLANK;
  73. if (bd->props.power == FB_BLANK_POWERDOWN)
  74. intensity = FB_BLANK_POWERDOWN;
  75. if (bd->props.fb_blank == FB_BLANK_POWERDOWN)
  76. intensity = FB_BLANK_POWERDOWN;
  77. if (intensity == FB_BLANK_UNBLANK) { /* FULL ON */
  78. cur &= ~CRVML_BACKLIGHT_OFF;
  79. outl(cur, addr);
  80. } else if (intensity == FB_BLANK_POWERDOWN) { /* OFF */
  81. cur |= CRVML_BACKLIGHT_OFF;
  82. outl(cur, addr);
  83. } /* anything else, don't bother */
  84. return 0;
  85. }
  86. static int cr_backlight_get_intensity(struct backlight_device *bd)
  87. {
  88. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  89. u32 cur = inl(addr);
  90. u8 intensity;
  91. if (cur & CRVML_BACKLIGHT_OFF)
  92. intensity = FB_BLANK_POWERDOWN;
  93. else
  94. intensity = FB_BLANK_UNBLANK;
  95. return intensity;
  96. }
  97. static struct backlight_ops cr_backlight_ops = {
  98. .get_brightness = cr_backlight_get_intensity,
  99. .update_status = cr_backlight_set_intensity,
  100. };
  101. static void cr_panel_on(void)
  102. {
  103. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  104. u32 cur = inl(addr);
  105. if (!(cur & CRVML_PANEL_ON)) {
  106. /* Make sure LVDS controller is down. */
  107. if (cur & 0x00000001) {
  108. cur &= ~CRVML_LVDS_ON;
  109. outl(cur, addr);
  110. }
  111. /* Power up Panel */
  112. schedule_timeout(HZ / 10);
  113. cur |= CRVML_PANEL_ON;
  114. outl(cur, addr);
  115. }
  116. /* Power up LVDS controller */
  117. if (!(cur & CRVML_LVDS_ON)) {
  118. schedule_timeout(HZ / 10);
  119. outl(cur | CRVML_LVDS_ON, addr);
  120. }
  121. }
  122. static void cr_panel_off(void)
  123. {
  124. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  125. u32 cur = inl(addr);
  126. /* Power down LVDS controller first to avoid high currents */
  127. if (cur & CRVML_LVDS_ON) {
  128. cur &= ~CRVML_LVDS_ON;
  129. outl(cur, addr);
  130. }
  131. if (cur & CRVML_PANEL_ON) {
  132. schedule_timeout(HZ / 10);
  133. outl(cur & ~CRVML_PANEL_ON, addr);
  134. }
  135. }
  136. static int cr_lcd_set_power(struct lcd_device *ld, int power)
  137. {
  138. if (power == FB_BLANK_UNBLANK)
  139. cr_panel_on();
  140. if (power == FB_BLANK_POWERDOWN)
  141. cr_panel_off();
  142. return 0;
  143. }
  144. static struct lcd_ops cr_lcd_ops = {
  145. .set_power = cr_lcd_set_power,
  146. };
  147. static int cr_backlight_probe(struct platform_device *pdev)
  148. {
  149. struct backlight_device *bdp;
  150. struct lcd_device *ldp;
  151. struct cr_panel *crp;
  152. u8 dev_en;
  153. lpc_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
  154. CRVML_DEVICE_LPC, NULL);
  155. if (!lpc_dev) {
  156. printk("INTEL CARILLO RANCH LPC not found.\n");
  157. return -ENODEV;
  158. }
  159. pci_read_config_byte(lpc_dev, CRVML_REG_GPIOEN, &dev_en);
  160. if (!(dev_en & CRVML_GPIOEN_BIT)) {
  161. printk(KERN_ERR
  162. "Carillo Ranch GPIO device was not enabled.\n");
  163. pci_dev_put(lpc_dev);
  164. return -ENODEV;
  165. }
  166. bdp = backlight_device_register("cr-backlight",
  167. &pdev->dev, NULL, &cr_backlight_ops);
  168. if (IS_ERR(bdp)) {
  169. pci_dev_put(lpc_dev);
  170. return PTR_ERR(bdp);
  171. }
  172. ldp = lcd_device_register("cr-lcd", &pdev->dev, NULL, &cr_lcd_ops);
  173. if (IS_ERR(ldp)) {
  174. backlight_device_unregister(bdp);
  175. pci_dev_put(lpc_dev);
  176. return PTR_ERR(bdp);
  177. }
  178. pci_read_config_dword(lpc_dev, CRVML_REG_GPIOBAR,
  179. &gpio_bar);
  180. gpio_bar &= ~0x3F;
  181. crp = kzalloc(sizeof(*crp), GFP_KERNEL);
  182. if (!crp) {
  183. lcd_device_unregister(ldp);
  184. backlight_device_unregister(bdp);
  185. pci_dev_put(lpc_dev);
  186. return -ENOMEM;
  187. }
  188. crp->cr_backlight_device = bdp;
  189. crp->cr_lcd_device = ldp;
  190. crp->cr_backlight_device->props.power = FB_BLANK_UNBLANK;
  191. crp->cr_backlight_device->props.brightness = 0;
  192. crp->cr_backlight_device->props.max_brightness = 0;
  193. cr_backlight_set_intensity(crp->cr_backlight_device);
  194. cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_UNBLANK);
  195. platform_set_drvdata(pdev, crp);
  196. return 0;
  197. }
  198. static int cr_backlight_remove(struct platform_device *pdev)
  199. {
  200. struct cr_panel *crp = platform_get_drvdata(pdev);
  201. crp->cr_backlight_device->props.power = FB_BLANK_POWERDOWN;
  202. crp->cr_backlight_device->props.brightness = 0;
  203. crp->cr_backlight_device->props.max_brightness = 0;
  204. cr_backlight_set_intensity(crp->cr_backlight_device);
  205. cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN);
  206. backlight_device_unregister(crp->cr_backlight_device);
  207. lcd_device_unregister(crp->cr_lcd_device);
  208. pci_dev_put(lpc_dev);
  209. return 0;
  210. }
  211. static struct platform_driver cr_backlight_driver = {
  212. .probe = cr_backlight_probe,
  213. .remove = cr_backlight_remove,
  214. .driver = {
  215. .name = "cr_backlight",
  216. },
  217. };
  218. static struct platform_device *crp;
  219. static int __init cr_backlight_init(void)
  220. {
  221. int ret = platform_driver_register(&cr_backlight_driver);
  222. if (!ret) {
  223. crp = platform_device_alloc("cr_backlight", -1);
  224. if (!crp)
  225. return -ENOMEM;
  226. ret = platform_device_add(crp);
  227. if (ret) {
  228. platform_device_put(crp);
  229. platform_driver_unregister(&cr_backlight_driver);
  230. }
  231. }
  232. printk("Carillo Ranch Backlight Driver Initialized.\n");
  233. return ret;
  234. }
  235. static void __exit cr_backlight_exit(void)
  236. {
  237. platform_device_unregister(crp);
  238. platform_driver_unregister(&cr_backlight_driver);
  239. }
  240. module_init(cr_backlight_init);
  241. module_exit(cr_backlight_exit);
  242. MODULE_AUTHOR("Tungsten Graphics Inc.");
  243. MODULE_DESCRIPTION("Carillo Ranch Backlight Driver");
  244. MODULE_LICENSE("GPL");