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 NVEC_LED_REQ {'\x0d', '\x10', '\x45', '\x10', '\x00'} 18 19#define NVEC_LED_MAX 8 20 21struct nvec_led { 22 struct led_classdev cdev; 23 struct nvec_chip *nvec; 24}; 25 26static void nvec_led_brightness_set(struct led_classdev *led_cdev, 27 enum led_brightness value) 28{ 29 struct nvec_led *led = container_of(led_cdev, struct nvec_led, cdev); 30 unsigned char buf[] = NVEC_LED_REQ; 31 32 buf[4] = value; 33 34 nvec_write_async(led->nvec, buf, sizeof(buf)); 35 36 led->cdev.brightness = value; 37} 38 39static int nvec_paz00_probe(struct platform_device *pdev) 40{ 41 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 42 struct nvec_led *led; 43 int ret = 0; 44 45 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); 46 if (!led) 47 return -ENOMEM; 48 49 led->cdev.max_brightness = NVEC_LED_MAX; 50 51 led->cdev.brightness_set = nvec_led_brightness_set; 52 led->cdev.name = "paz00-led"; 53 led->cdev.flags |= LED_CORE_SUSPENDRESUME; 54 led->nvec = nvec; 55 56 platform_set_drvdata(pdev, led); 57 58 ret = devm_led_classdev_register(&pdev->dev, &led->cdev); 59 if (ret < 0) 60 return ret; 61 62 /* to expose the default value to userspace */ 63 led->cdev.brightness = 0; 64 65 return 0; 66} 67 68static struct platform_driver nvec_paz00_driver = { 69 .probe = nvec_paz00_probe, 70 .driver = { 71 .name = "nvec-paz00", 72 }, 73}; 74 75module_platform_driver(nvec_paz00_driver); 76 77MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>"); 78MODULE_DESCRIPTION("Tegra NVEC PAZ00 driver"); 79MODULE_LICENSE("GPL"); 80MODULE_ALIAS("platform:nvec-paz00"); 81