1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/leds.h>
32
33#include "nouveau_led.h"
34#include <nvkm/subdev/gpio.h>
35
36static enum led_brightness
37nouveau_led_get_brightness(struct led_classdev *led)
38{
39 struct drm_device *drm_dev = container_of(led, struct nouveau_led, led)->dev;
40 struct nouveau_drm *drm = nouveau_drm(drm_dev);
41 struct nvif_object *device = &drm->client.device.object;
42 u32 div, duty;
43
44 div = nvif_rd32(device, 0x61c880) & 0x00ffffff;
45 duty = nvif_rd32(device, 0x61c884) & 0x00ffffff;
46
47 if (div > 0)
48 return duty * LED_FULL / div;
49 else
50 return 0;
51}
52
53static void
54nouveau_led_set_brightness(struct led_classdev *led, enum led_brightness value)
55{
56 struct drm_device *drm_dev = container_of(led, struct nouveau_led, led)->dev;
57 struct nouveau_drm *drm = nouveau_drm(drm_dev);
58 struct nvif_object *device = &drm->client.device.object;
59
60 u32 input_clk = 27e6;
61 u32 freq = 100;
62 u32 div, duty;
63
64 div = input_clk / freq;
65 duty = value * div / LED_FULL;
66
67
68
69
70
71
72 nvif_wr32(device, 0x61c880, div);
73 nvif_wr32(device, 0x61c884, 0xc0000000 | duty);
74}
75
76
77int
78nouveau_led_init(struct drm_device *dev)
79{
80 struct nouveau_drm *drm = nouveau_drm(dev);
81 struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
82 struct dcb_gpio_func logo_led;
83 int ret;
84
85 if (!gpio)
86 return 0;
87
88
89 if (nvkm_gpio_find(gpio, 0, DCB_GPIO_LOGO_LED_PWM, 0xff, &logo_led))
90 return 0;
91
92 drm->led = kzalloc(sizeof(*drm->led), GFP_KERNEL);
93 if (!drm->led)
94 return -ENOMEM;
95 drm->led->dev = dev;
96
97 drm->led->led.name = "nvidia-logo";
98 drm->led->led.max_brightness = 255;
99 drm->led->led.brightness_get = nouveau_led_get_brightness;
100 drm->led->led.brightness_set = nouveau_led_set_brightness;
101
102 ret = led_classdev_register(dev->dev, &drm->led->led);
103 if (ret) {
104 kfree(drm->led);
105 drm->led = NULL;
106 return ret;
107 }
108
109 return 0;
110}
111
112void
113nouveau_led_suspend(struct drm_device *dev)
114{
115 struct nouveau_drm *drm = nouveau_drm(dev);
116
117 if (drm->led)
118 led_classdev_suspend(&drm->led->led);
119}
120
121void
122nouveau_led_resume(struct drm_device *dev)
123{
124 struct nouveau_drm *drm = nouveau_drm(dev);
125
126 if (drm->led)
127 led_classdev_resume(&drm->led->led);
128}
129
130void
131nouveau_led_fini(struct drm_device *dev)
132{
133 struct nouveau_drm *drm = nouveau_drm(dev);
134
135 if (drm->led) {
136 led_classdev_unregister(&drm->led->led);
137 kfree(drm->led);
138 drm->led = NULL;
139 }
140}
141