root/drivers/staging/nvec/nvec_paz00.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nvec_led_brightness_set
  2. nvec_paz00_probe

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

/* [<][>][^][v][top][bottom][index][help] */