drm/nouveau/gpio: port gpio to subdev interfaces
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / nouveau_compat.c
1 #include "nouveau_drm.h"
2 #include "nouveau_compat.h"
3
4 #include <subdev/bios.h>
5 #include <subdev/gpio.h>
6
7 void *nouveau_newpriv(struct drm_device *);
8
9 u8
10 _nv_rd08(struct drm_device *dev, u32 reg)
11 {
12         struct nouveau_drm *drm = nouveau_newpriv(dev);
13         return nv_ro08(drm->device, reg);
14 }
15
16 void
17 _nv_wr08(struct drm_device *dev, u32 reg, u8 val)
18 {
19         struct nouveau_drm *drm = nouveau_newpriv(dev);
20         nv_wo08(drm->device, reg, val);
21 }
22
23 u32
24 _nv_rd32(struct drm_device *dev, u32 reg)
25 {
26         struct nouveau_drm *drm = nouveau_newpriv(dev);
27         return nv_ro32(drm->device, reg);
28 }
29
30 void
31 _nv_wr32(struct drm_device *dev, u32 reg, u32 val)
32 {
33         struct nouveau_drm *drm = nouveau_newpriv(dev);
34         nv_wo32(drm->device, reg, val);
35 }
36
37 u32
38 _nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
39 {
40         u32 tmp = _nv_rd32(dev, reg);
41         _nv_wr32(dev, reg, (tmp & ~mask) | val);
42         return tmp;
43 }
44
45 bool
46 _nv_bios(struct drm_device *dev, u8 **data, u32 *size)
47 {
48         struct nouveau_drm *drm = nouveau_newpriv(dev);
49         struct nouveau_bios *bios = nouveau_bios(drm->device);
50         *data = bios->data;
51         *size = bios->size;
52         return true;
53 }
54
55 void
56 nouveau_gpio_reset(struct drm_device *dev)
57 {
58         struct nouveau_drm *drm = nouveau_newpriv(dev);
59         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
60         gpio->reset(gpio);
61 }
62
63 int
64 nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
65                   struct dcb_gpio_func *func)
66 {
67         struct nouveau_drm *drm = nouveau_newpriv(dev);
68         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
69
70         return gpio->find(gpio, idx, tag, line, func);
71 }
72
73 bool
74 nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
75 {
76         struct nouveau_drm *drm = nouveau_newpriv(dev);
77         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
78         struct dcb_gpio_func func;
79
80         return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
81 }
82
83 int
84 nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
85 {
86         struct nouveau_drm *drm = nouveau_newpriv(dev);
87         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
88         if (gpio && gpio->get)
89                 return gpio->set(gpio, 0, tag, 0xff, state);
90         return -ENODEV;
91 }
92
93 int
94 nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
95 {
96         struct nouveau_drm *drm = nouveau_newpriv(dev);
97         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
98         if (gpio && gpio->get)
99                 return gpio->get(gpio, 0, tag, 0xff);
100         return -ENODEV;
101 }
102
103 int
104 nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
105 {
106         struct nouveau_drm *drm = nouveau_newpriv(dev);
107         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
108         if (gpio && gpio->irq)
109                 return gpio->irq(gpio, idx, tag, line, on);
110         return -ENODEV;
111 }
112
113 int
114 nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
115                      void (*exec)(void *, int state), void *data)
116 {
117         struct nouveau_drm *drm = nouveau_newpriv(dev);
118         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
119         if (gpio && gpio->isr_add)
120                 return gpio->isr_add(gpio, idx, tag, line, exec, data);
121         return -ENODEV;
122 }
123
124 void
125 nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
126                      void (*exec)(void *, int state), void *data)
127 {
128         struct nouveau_drm *drm = nouveau_newpriv(dev);
129         struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
130         if (gpio && gpio->isr_del)
131                 gpio->isr_del(gpio, idx, tag, line, exec, data);
132 }