shmob_drm_backlight.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * shmob_drm_backlight.c -- SH Mobile DRM Backlight
  3. *
  4. * Copyright (C) 2012 Renesas Electronics Corporation
  5. *
  6. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  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 as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/backlight.h>
  14. #include "shmob_drm_backlight.h"
  15. #include "shmob_drm_crtc.h"
  16. #include "shmob_drm_drv.h"
  17. static int shmob_drm_backlight_update(struct backlight_device *bdev)
  18. {
  19. struct shmob_drm_connector *scon = bl_get_data(bdev);
  20. struct shmob_drm_device *sdev = scon->connector.dev->dev_private;
  21. const struct shmob_drm_backlight_data *bdata = &sdev->pdata->backlight;
  22. int brightness = bdev->props.brightness;
  23. if (bdev->props.power != FB_BLANK_UNBLANK ||
  24. bdev->props.state & BL_CORE_SUSPENDED)
  25. brightness = 0;
  26. return bdata->set_brightness(brightness);
  27. }
  28. static int shmob_drm_backlight_get_brightness(struct backlight_device *bdev)
  29. {
  30. struct shmob_drm_connector *scon = bl_get_data(bdev);
  31. struct shmob_drm_device *sdev = scon->connector.dev->dev_private;
  32. const struct shmob_drm_backlight_data *bdata = &sdev->pdata->backlight;
  33. return bdata->get_brightness();
  34. }
  35. static const struct backlight_ops shmob_drm_backlight_ops = {
  36. .options = BL_CORE_SUSPENDRESUME,
  37. .update_status = shmob_drm_backlight_update,
  38. .get_brightness = shmob_drm_backlight_get_brightness,
  39. };
  40. void shmob_drm_backlight_dpms(struct shmob_drm_connector *scon, int mode)
  41. {
  42. if (scon->backlight == NULL)
  43. return;
  44. scon->backlight->props.power = mode == DRM_MODE_DPMS_ON
  45. ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
  46. backlight_update_status(scon->backlight);
  47. }
  48. int shmob_drm_backlight_init(struct shmob_drm_connector *scon)
  49. {
  50. struct shmob_drm_device *sdev = scon->connector.dev->dev_private;
  51. const struct shmob_drm_backlight_data *bdata = &sdev->pdata->backlight;
  52. struct drm_connector *connector = &scon->connector;
  53. struct drm_device *dev = connector->dev;
  54. struct backlight_device *backlight;
  55. if (!bdata->max_brightness)
  56. return 0;
  57. backlight = backlight_device_register(bdata->name, dev->dev, scon,
  58. &shmob_drm_backlight_ops, NULL);
  59. if (IS_ERR(backlight)) {
  60. dev_err(dev->dev, "unable to register backlight device: %ld\n",
  61. PTR_ERR(backlight));
  62. return PTR_ERR(backlight);
  63. }
  64. backlight->props.max_brightness = bdata->max_brightness;
  65. backlight->props.brightness = bdata->max_brightness;
  66. backlight->props.power = FB_BLANK_POWERDOWN;
  67. backlight_update_status(backlight);
  68. scon->backlight = backlight;
  69. return 0;
  70. }
  71. void shmob_drm_backlight_exit(struct shmob_drm_connector *scon)
  72. {
  73. backlight_device_unregister(scon->backlight);
  74. }