cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

nvec_paz00.c (1905B)


      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
     24struct nvec_led {
     25	struct led_classdev cdev;
     26	struct nvec_chip *nvec;
     27};
     28
     29static 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
     42static 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
     71static struct platform_driver nvec_paz00_driver = {
     72	.probe  = nvec_paz00_probe,
     73	.driver = {
     74		.name  = "nvec-paz00",
     75	},
     76};
     77
     78module_platform_driver(nvec_paz00_driver);
     79
     80MODULE_AUTHOR("Ilya Petrov <ilya.muromec@gmail.com>");
     81MODULE_DESCRIPTION("Tegra NVEC PAZ00 driver");
     82MODULE_LICENSE("GPL");
     83MODULE_ALIAS("platform:nvec-paz00");