dev-backlight.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* linux/arch/arm/plat-samsung/dev-backlight.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Common infrastructure for PWM Backlight for Samsung boards
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/gpio.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/slab.h>
  15. #include <linux/io.h>
  16. #include <linux/pwm_backlight.h>
  17. #include <plat/devs.h>
  18. #include <plat/gpio-cfg.h>
  19. #include <plat/backlight.h>
  20. static int samsung_bl_init(struct device *dev)
  21. {
  22. int ret = 0;
  23. struct platform_device *timer_dev =
  24. container_of(dev->parent, struct platform_device, dev);
  25. struct samsung_bl_gpio_info *bl_gpio_info =
  26. timer_dev->dev.platform_data;
  27. ret = gpio_request(bl_gpio_info->no, "Backlight");
  28. if (ret) {
  29. printk(KERN_ERR "failed to request GPIO for LCD Backlight\n");
  30. return ret;
  31. }
  32. /* Configure GPIO pin with specific GPIO function for PWM timer */
  33. s3c_gpio_cfgpin(bl_gpio_info->no, bl_gpio_info->func);
  34. return 0;
  35. }
  36. static void samsung_bl_exit(struct device *dev)
  37. {
  38. struct platform_device *timer_dev =
  39. container_of(dev->parent, struct platform_device, dev);
  40. struct samsung_bl_gpio_info *bl_gpio_info =
  41. timer_dev->dev.platform_data;
  42. s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
  43. gpio_free(bl_gpio_info->no);
  44. }
  45. /* Initialize few important fields of platform_pwm_backlight_data
  46. * structure with default values. These fields can be overridden by
  47. * board-specific values sent from machine file.
  48. * For ease of operation, these fields are initialized with values
  49. * used by most samsung boards.
  50. * Users has the option of sending info about other parameters
  51. * for their specific boards
  52. */
  53. static struct platform_pwm_backlight_data samsung_dfl_bl_data __initdata = {
  54. .max_brightness = 255,
  55. .dft_brightness = 255,
  56. .pwm_period_ns = 78770,
  57. .init = samsung_bl_init,
  58. .exit = samsung_bl_exit,
  59. };
  60. static struct platform_device samsung_dfl_bl_device __initdata = {
  61. .name = "pwm-backlight",
  62. };
  63. /* samsung_bl_set - Set board specific data (if any) provided by user for
  64. * PWM Backlight control and register specific PWM and backlight device.
  65. * @gpio_info: structure containing GPIO info for PWM timer
  66. * @bl_data: structure containing Backlight control data
  67. */
  68. void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
  69. struct platform_pwm_backlight_data *bl_data)
  70. {
  71. int ret = 0;
  72. struct platform_device *samsung_bl_device;
  73. struct platform_pwm_backlight_data *samsung_bl_data;
  74. samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
  75. sizeof(struct platform_device), GFP_KERNEL);
  76. if (!samsung_bl_device) {
  77. printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
  78. return;
  79. }
  80. samsung_bl_data = s3c_set_platdata(&samsung_dfl_bl_data,
  81. sizeof(struct platform_pwm_backlight_data), samsung_bl_device);
  82. if (!samsung_bl_data) {
  83. printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
  84. goto err_data;
  85. }
  86. /* Copy board specific data provided by user */
  87. samsung_bl_data->pwm_id = bl_data->pwm_id;
  88. samsung_bl_device->dev.parent =
  89. &s3c_device_timer[samsung_bl_data->pwm_id].dev;
  90. if (bl_data->max_brightness)
  91. samsung_bl_data->max_brightness = bl_data->max_brightness;
  92. if (bl_data->dft_brightness)
  93. samsung_bl_data->dft_brightness = bl_data->dft_brightness;
  94. if (bl_data->lth_brightness)
  95. samsung_bl_data->lth_brightness = bl_data->lth_brightness;
  96. if (bl_data->pwm_period_ns)
  97. samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns;
  98. if (bl_data->init)
  99. samsung_bl_data->init = bl_data->init;
  100. if (bl_data->notify)
  101. samsung_bl_data->notify = bl_data->notify;
  102. if (bl_data->notify_after)
  103. samsung_bl_data->notify_after = bl_data->notify_after;
  104. if (bl_data->exit)
  105. samsung_bl_data->exit = bl_data->exit;
  106. if (bl_data->check_fb)
  107. samsung_bl_data->check_fb = bl_data->check_fb;
  108. /* Keep the GPIO info for future use */
  109. s3c_device_timer[samsung_bl_data->pwm_id].dev.platform_data = gpio_info;
  110. /* Register the specific PWM timer dev for Backlight control */
  111. ret = platform_device_register(
  112. &s3c_device_timer[samsung_bl_data->pwm_id]);
  113. if (ret) {
  114. printk(KERN_ERR "failed to register pwm timer for backlight: %d\n", ret);
  115. goto err_plat_reg1;
  116. }
  117. /* Register the Backlight dev */
  118. ret = platform_device_register(samsung_bl_device);
  119. if (ret) {
  120. printk(KERN_ERR "failed to register backlight device: %d\n", ret);
  121. goto err_plat_reg2;
  122. }
  123. return;
  124. err_plat_reg2:
  125. platform_device_unregister(&s3c_device_timer[samsung_bl_data->pwm_id]);
  126. err_plat_reg1:
  127. kfree(samsung_bl_data);
  128. err_data:
  129. kfree(samsung_bl_device);
  130. return;
  131. }