cr_bllcd.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/mutex.h>
  35. #include <linux/fb.h>
  36. #include <linux/backlight.h>
  37. #include <linux/lcd.h>
  38. #include <linux/pci.h>
  39. #include <linux/slab.h>
  40. /* The LVDS- and panel power controls sits on the
  41. * GPIO port of the ISA bridge.
  42. */
  43. #define CRVML_DEVICE_LPC 0x27B8
  44. #define CRVML_REG_GPIOBAR 0x48
  45. #define CRVML_REG_GPIOEN 0x4C
  46. #define CRVML_GPIOEN_BIT (1 << 4)
  47. #define CRVML_PANEL_PORT 0x38
  48. #define CRVML_LVDS_ON 0x00000001
  49. #define CRVML_PANEL_ON 0x00000002
  50. #define CRVML_BACKLIGHT_OFF 0x00000004
  51. /* The PLL Clock register sits on Host bridge */
  52. #define CRVML_DEVICE_MCH 0x5001
  53. #define CRVML_REG_MCHBAR 0x44
  54. #define CRVML_REG_MCHEN 0x54
  55. #define CRVML_MCHEN_BIT (1 << 28)
  56. #define CRVML_MCHMAP_SIZE 4096
  57. #define CRVML_REG_CLOCK 0xc3c
  58. #define CRVML_CLOCK_SHIFT 8
  59. #define CRVML_CLOCK_MASK 0x00000f00
  60. static struct pci_dev *lpc_dev;
  61. static u32 gpio_bar;
  62. struct cr_panel {
  63. struct backlight_device *cr_backlight_device;
  64. struct lcd_device *cr_lcd_device;
  65. };
  66. static int cr_backlight_set_intensity(struct backlight_device *bd)
  67. {
  68. int intensity = bd->props.brightness;
  69. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  70. u32 cur = inl(addr);
  71. if (bd->props.power == FB_BLANK_UNBLANK)
  72. intensity = FB_BLANK_UNBLANK;
  73. if (bd->props.fb_blank == FB_BLANK_UNBLANK)
  74. intensity = FB_BLANK_UNBLANK;
  75. if (bd->props.power == FB_BLANK_POWERDOWN)
  76. intensity = FB_BLANK_POWERDOWN;
  77. if (bd->props.fb_blank == FB_BLANK_POWERDOWN)
  78. intensity = FB_BLANK_POWERDOWN;
  79. if (intensity == FB_BLANK_UNBLANK) { /* FULL ON */
  80. cur &= ~CRVML_BACKLIGHT_OFF;
  81. outl(cur, addr);
  82. } else if (intensity == FB_BLANK_POWERDOWN) { /* OFF */
  83. cur |= CRVML_BACKLIGHT_OFF;
  84. outl(cur, addr);
  85. } /* anything else, don't bother */
  86. return 0;
  87. }
  88. static int cr_backlight_get_intensity(struct backlight_device *bd)
  89. {
  90. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  91. u32 cur = inl(addr);
  92. u8 intensity;
  93. if (cur & CRVML_BACKLIGHT_OFF)
  94. intensity = FB_BLANK_POWERDOWN;
  95. else
  96. intensity = FB_BLANK_UNBLANK;
  97. return intensity;
  98. }
  99. static const struct backlight_ops cr_backlight_ops = {
  100. .get_brightness = cr_backlight_get_intensity,
  101. .update_status = cr_backlight_set_intensity,
  102. };
  103. static void cr_panel_on(void)
  104. {
  105. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  106. u32 cur = inl(addr);
  107. if (!(cur & CRVML_PANEL_ON)) {
  108. /* Make sure LVDS controller is down. */
  109. if (cur & 0x00000001) {
  110. cur &= ~CRVML_LVDS_ON;
  111. outl(cur, addr);
  112. }
  113. /* Power up Panel */
  114. schedule_timeout(HZ / 10);
  115. cur |= CRVML_PANEL_ON;
  116. outl(cur, addr);
  117. }
  118. /* Power up LVDS controller */
  119. if (!(cur & CRVML_LVDS_ON)) {
  120. schedule_timeout(HZ / 10);
  121. outl(cur | CRVML_LVDS_ON, addr);
  122. }
  123. }
  124. static void cr_panel_off(void)
  125. {
  126. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  127. u32 cur = inl(addr);
  128. /* Power down LVDS controller first to avoid high currents */
  129. if (cur & CRVML_LVDS_ON) {
  130. cur &= ~CRVML_LVDS_ON;
  131. outl(cur, addr);
  132. }
  133. if (cur & CRVML_PANEL_ON) {
  134. schedule_timeout(HZ / 10);
  135. outl(cur & ~CRVML_PANEL_ON, addr);
  136. }
  137. }
  138. static int cr_lcd_set_power(struct lcd_device *ld, int power)
  139. {
  140. if (power == FB_BLANK_UNBLANK)
  141. cr_panel_on();
  142. if (power == FB_BLANK_POWERDOWN)
  143. cr_panel_off();
  144. return 0;
  145. }
  146. static struct lcd_ops cr_lcd_ops = {
  147. .set_power = cr_lcd_set_power,
  148. };
  149. static int cr_backlight_probe(struct platform_device *pdev)
  150. {
  151. struct backlight_properties props;
  152. struct backlight_device *bdp;
  153. struct lcd_device *ldp;
  154. struct cr_panel *crp;
  155. u8 dev_en;
  156. lpc_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
  157. CRVML_DEVICE_LPC, NULL);
  158. if (!lpc_dev) {
  159. pr_err("INTEL CARILLO RANCH LPC not found.\n");
  160. return -ENODEV;
  161. }
  162. pci_read_config_byte(lpc_dev, CRVML_REG_GPIOEN, &dev_en);
  163. if (!(dev_en & CRVML_GPIOEN_BIT)) {
  164. pr_err("Carillo Ranch GPIO device was not enabled.\n");
  165. pci_dev_put(lpc_dev);
  166. return -ENODEV;
  167. }
  168. memset(&props, 0, sizeof(struct backlight_properties));
  169. props.type = BACKLIGHT_RAW;
  170. bdp = backlight_device_register("cr-backlight", &pdev->dev, NULL,
  171. &cr_backlight_ops, &props);
  172. if (IS_ERR(bdp)) {
  173. pci_dev_put(lpc_dev);
  174. return PTR_ERR(bdp);
  175. }
  176. ldp = lcd_device_register("cr-lcd", &pdev->dev, NULL, &cr_lcd_ops);
  177. if (IS_ERR(ldp)) {
  178. backlight_device_unregister(bdp);
  179. pci_dev_put(lpc_dev);
  180. return PTR_ERR(ldp);
  181. }
  182. pci_read_config_dword(lpc_dev, CRVML_REG_GPIOBAR,
  183. &gpio_bar);
  184. gpio_bar &= ~0x3F;
  185. crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL);
  186. if (!crp) {
  187. lcd_device_unregister(ldp);
  188. backlight_device_unregister(bdp);
  189. pci_dev_put(lpc_dev);
  190. return -ENOMEM;
  191. }
  192. crp->cr_backlight_device = bdp;
  193. crp->cr_lcd_device = ldp;
  194. crp->cr_backlight_device->props.power = FB_BLANK_UNBLANK;
  195. crp->cr_backlight_device->props.brightness = 0;
  196. cr_backlight_set_intensity(crp->cr_backlight_device);
  197. cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_UNBLANK);
  198. platform_set_drvdata(pdev, crp);
  199. return 0;
  200. }
  201. static int cr_backlight_remove(struct platform_device *pdev)
  202. {
  203. struct cr_panel *crp = platform_get_drvdata(pdev);
  204. crp->cr_backlight_device->props.power = FB_BLANK_POWERDOWN;
  205. crp->cr_backlight_device->props.brightness = 0;
  206. crp->cr_backlight_device->props.max_brightness = 0;
  207. cr_backlight_set_intensity(crp->cr_backlight_device);
  208. cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN);
  209. backlight_device_unregister(crp->cr_backlight_device);
  210. lcd_device_unregister(crp->cr_lcd_device);
  211. pci_dev_put(lpc_dev);
  212. return 0;
  213. }
  214. static struct platform_driver cr_backlight_driver = {
  215. .probe = cr_backlight_probe,
  216. .remove = cr_backlight_remove,
  217. .driver = {
  218. .name = "cr_backlight",
  219. },
  220. };
  221. static struct platform_device *crp;
  222. static int __init cr_backlight_init(void)
  223. {
  224. int ret = platform_driver_register(&cr_backlight_driver);
  225. if (ret)
  226. return ret;
  227. crp = platform_device_register_simple("cr_backlight", -1, NULL, 0);
  228. if (IS_ERR(crp)) {
  229. platform_driver_unregister(&cr_backlight_driver);
  230. return PTR_ERR(crp);
  231. }
  232. pr_info("Carillo Ranch Backlight Driver Initialized.\n");
  233. return 0;
  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");