1 #include "nouveau_drm.h"
2 #include "nouveau_compat.h"
4 #include <subdev/bios.h>
5 #include <subdev/bios/pll.h>
6 #include <subdev/gpio.h>
7 #include <subdev/i2c.h>
8 #include <subdev/clock.h>
10 void *nouveau_newpriv(struct drm_device *);
13 _nv_rd08(struct drm_device *dev, u32 reg)
15 struct nouveau_drm *drm = nouveau_newpriv(dev);
16 return nv_ro08(drm->device, reg);
20 _nv_wr08(struct drm_device *dev, u32 reg, u8 val)
22 struct nouveau_drm *drm = nouveau_newpriv(dev);
23 nv_wo08(drm->device, reg, val);
27 _nv_rd32(struct drm_device *dev, u32 reg)
29 struct nouveau_drm *drm = nouveau_newpriv(dev);
30 return nv_ro32(drm->device, reg);
34 _nv_wr32(struct drm_device *dev, u32 reg, u32 val)
36 struct nouveau_drm *drm = nouveau_newpriv(dev);
37 nv_wo32(drm->device, reg, val);
41 _nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
43 u32 tmp = _nv_rd32(dev, reg);
44 _nv_wr32(dev, reg, (tmp & ~mask) | val);
49 _nv_bios(struct drm_device *dev, u8 **data, u32 *size)
51 struct nouveau_drm *drm = nouveau_newpriv(dev);
52 struct nouveau_bios *bios = nouveau_bios(drm->device);
59 nouveau_gpio_reset(struct drm_device *dev)
61 struct nouveau_drm *drm = nouveau_newpriv(dev);
62 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
67 nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
68 struct dcb_gpio_func *func)
70 struct nouveau_drm *drm = nouveau_newpriv(dev);
71 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
73 return gpio->find(gpio, idx, tag, line, func);
77 nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
79 struct nouveau_drm *drm = nouveau_newpriv(dev);
80 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
81 struct dcb_gpio_func func;
83 return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
87 nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
89 struct nouveau_drm *drm = nouveau_newpriv(dev);
90 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
91 if (gpio && gpio->get)
92 return gpio->set(gpio, 0, tag, 0xff, state);
97 nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
99 struct nouveau_drm *drm = nouveau_newpriv(dev);
100 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
101 if (gpio && gpio->get)
102 return gpio->get(gpio, 0, tag, 0xff);
107 nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
109 struct nouveau_drm *drm = nouveau_newpriv(dev);
110 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
111 if (gpio && gpio->irq)
112 return gpio->irq(gpio, idx, tag, line, on);
117 nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
118 void (*exec)(void *, int state), void *data)
120 struct nouveau_drm *drm = nouveau_newpriv(dev);
121 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
122 if (gpio && gpio->isr_add)
123 return gpio->isr_add(gpio, idx, tag, line, exec, data);
128 nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
129 void (*exec)(void *, int state), void *data)
131 struct nouveau_drm *drm = nouveau_newpriv(dev);
132 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
133 if (gpio && gpio->isr_del)
134 gpio->isr_del(gpio, idx, tag, line, exec, data);
137 struct nouveau_i2c_port *
138 nouveau_i2c_find(struct drm_device *dev, u8 index)
140 struct nouveau_drm *drm = nouveau_newpriv(dev);
141 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
143 return i2c->find(i2c, index);
147 nouveau_probe_i2c_addr(struct nouveau_i2c_port *port, int addr)
149 return nv_probe_i2c(port, addr);
153 nouveau_i2c_adapter(struct nouveau_i2c_port *port)
155 return &port->adapter;
160 nouveau_i2c_identify(struct drm_device *dev, const char *what,
161 struct i2c_board_info *info,
162 bool (*match)(struct nouveau_i2c_port *,
163 struct i2c_board_info *),
166 struct nouveau_drm *drm = nouveau_newpriv(dev);
167 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
169 return i2c->identify(i2c, index, what, info, match);
173 auxch_rd(struct drm_device *dev, struct nouveau_i2c_port *port,
174 u32 addr, u8 *data, u8 size)
176 return nv_rdaux(port, addr, data, size);
180 auxch_wr(struct drm_device *dev, struct nouveau_i2c_port *port,
181 u32 addr, u8 *data, u8 size)
183 return nv_wraux(port, addr, data, size);
187 get_pll_register(struct drm_device *dev, u32 type)
189 struct nouveau_drm *drm = nouveau_newpriv(dev);
190 struct nouveau_bios *bios = nouveau_bios(drm->device);
191 struct nvbios_pll info;
193 if (nvbios_pll_parse(bios, type, &info))
199 get_pll_limits(struct drm_device *dev, u32 type, struct nvbios_pll *info)
201 struct nouveau_drm *drm = nouveau_newpriv(dev);
202 struct nouveau_bios *bios = nouveau_bios(drm->device);
204 return nvbios_pll_parse(bios, type, info);
208 setPLL(struct drm_device *dev, u32 reg, u32 freq)
210 struct nouveau_drm *drm = nouveau_newpriv(dev);
211 struct nouveau_clock *clk = nouveau_clock(drm->device);
215 ret = clk->pll_set(clk, reg, freq);
221 nouveau_calc_pll_mnp(struct drm_device *dev, struct nvbios_pll *info,
222 int freq, struct nouveau_pll_vals *pv)
224 struct nouveau_drm *drm = nouveau_newpriv(dev);
225 struct nouveau_clock *clk = nouveau_clock(drm->device);
229 ret = clk->pll_calc(clk, info, freq, pv);
234 nouveau_hw_setpll(struct drm_device *dev, u32 reg1,
235 struct nouveau_pll_vals *pv)
237 struct nouveau_drm *drm = nouveau_newpriv(dev);
238 struct nouveau_clock *clk = nouveau_clock(drm->device);
242 ret = clk->pll_prog(clk, reg1, pv);
246 int nva3_pll_calc(struct nouveau_clock *, struct nvbios_pll *, u32 freq,
247 int *N, int *fN, int *M, int *P);
250 nva3_calc_pll(struct drm_device *dev, struct nvbios_pll *info, u32 freq,
251 int *N, int *fN, int *M, int *P)
253 struct nouveau_drm *drm = nouveau_newpriv(dev);
254 struct nouveau_clock *clk = nouveau_clock(drm->device);
256 return nva3_pll_calc(clk, info, freq, N, fN, M, P);