nvec_paz00.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * nvec_paz00: OEM specific driver for Compal PAZ00 based devices
  3. *
  4. * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
  5. *
  6. * Authors: Ilya Petrov <ilya.muromec@gmail.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/err.h>
  15. #include <linux/slab.h>
  16. #include <linux/leds.h>
  17. #include <linux/platform_device.h>
  18. #include "nvec.h"
  19. #define to_nvec_led(led_cdev) \
  20. container_of(led_cdev, struct nvec_led, cdev)
  21. #define NVEC_LED_REQ {'\x0d', '\x10', '\x45', '\x10', '\x00'}
  22. #define NVEC_LED_MAX 8
  23. struct nvec_led {
  24. struct led_classdev cdev;
  25. struct nvec_chip *nvec;
  26. };
  27. static void nvec_led_brightness_set(struct led_classdev *led_cdev,
  28. enum led_brightness value)
  29. {
  30. struct nvec_led *led = to_nvec_led(led_cdev);
  31. unsigned char buf[] = NVEC_LED_REQ;
  32. buf[4] = value;
  33. nvec_write_async(led->nvec, buf, sizeof(buf));
  34. led->cdev.brightness = value;
  35. }
  36. static int nvec_paz00_probe(struct platform_device *pdev)
  37. {
  38. struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
  39. struct nvec_led *led;
  40. int ret = 0;
  41. led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
  42. if (!led)
  43. return -ENOMEM;
  44. led->cdev.max_brightness = NVEC_LED_MAX;
  45. led->cdev.brightness_set = nvec_led_brightness_set;
  46. led->cdev.name = "paz00-led";
  47. led->cdev.flags |= LED_CORE_SUSPENDRESUME;
  48. led->nvec = nvec;
  49. platform_set_drvdata(pdev, led);
  50. ret = led_classdev_register(&pdev->dev, &led->cdev);
  51. if (ret < 0)
  52. return ret;
  53. /* to expose the default value to userspace */
  54. led->cdev.brightness = 0;
  55. return 0;
  56. }
  57. static int nvec_paz00_remove(struct platform_device *pdev)
  58. {
  59. struct nvec_led *led = platform_get_drvdata(pdev);
  60. led_classdev_unregister(&led->cdev);
  61. return 0;
  62. }
  63. static struct platform_driver nvec_paz00_driver = {
  64. .probe = nvec_paz00_probe,
  65. .remove = nvec_paz00_remove,
  66. .driver = {
  67. .name = "nvec-paz00",
  68. },
  69. };
  70. module_platform_driver(nvec_paz00_driver);
  71. MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
  72. MODULE_DESCRIPTION("Tegra NVEC PAZ00 driver");
  73. MODULE_LICENSE("GPL");
  74. MODULE_ALIAS("platform:nvec-paz00");