1 #include "nouveau_drm.h"
2 #include "nouveau_compat.h"
4 #include <subdev/bios.h>
5 #include <subdev/bios/dcb.h>
6 #include <subdev/bios/init.h>
7 #include <subdev/bios/pll.h>
8 #include <subdev/gpio.h>
9 #include <subdev/i2c.h>
10 #include <subdev/clock.h>
11 #include <subdev/mc.h>
13 void *nouveau_newpriv(struct drm_device *);
16 nvdrm_gart_init(struct drm_device *dev, u64 *base, u64 *size)
18 struct nouveau_drm *drm = nouveau_newpriv(dev);
19 if (drm->agp.stat == ENABLED) {
20 *base = drm->agp.base;
21 *size = drm->agp.base;
28 _nv_rd08(struct drm_device *dev, u32 reg)
30 struct nouveau_drm *drm = nouveau_newpriv(dev);
31 return nv_ro08(drm->device, reg);
35 _nv_wr08(struct drm_device *dev, u32 reg, u8 val)
37 struct nouveau_drm *drm = nouveau_newpriv(dev);
38 nv_wo08(drm->device, reg, val);
42 _nv_rd32(struct drm_device *dev, u32 reg)
44 struct nouveau_drm *drm = nouveau_newpriv(dev);
45 return nv_ro32(drm->device, reg);
49 _nv_wr32(struct drm_device *dev, u32 reg, u32 val)
51 struct nouveau_drm *drm = nouveau_newpriv(dev);
52 nv_wo32(drm->device, reg, val);
56 _nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
58 u32 tmp = _nv_rd32(dev, reg);
59 _nv_wr32(dev, reg, (tmp & ~mask) | val);
64 _nv_bios(struct drm_device *dev, u8 **data, u32 *size)
66 struct nouveau_drm *drm = nouveau_newpriv(dev);
67 struct nouveau_bios *bios = nouveau_bios(drm->device);
74 nouveau_gpio_reset(struct drm_device *dev)
76 struct nouveau_drm *drm = nouveau_newpriv(dev);
77 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
82 nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
83 struct dcb_gpio_func *func)
85 struct nouveau_drm *drm = nouveau_newpriv(dev);
86 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
88 return gpio->find(gpio, idx, tag, line, func);
92 nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
94 struct nouveau_drm *drm = nouveau_newpriv(dev);
95 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
96 struct dcb_gpio_func func;
98 return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
102 nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
104 struct nouveau_drm *drm = nouveau_newpriv(dev);
105 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
106 if (gpio && gpio->get)
107 return gpio->set(gpio, 0, tag, 0xff, state);
112 nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
114 struct nouveau_drm *drm = nouveau_newpriv(dev);
115 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
116 if (gpio && gpio->get)
117 return gpio->get(gpio, 0, tag, 0xff);
122 nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
124 struct nouveau_drm *drm = nouveau_newpriv(dev);
125 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
126 if (gpio && gpio->irq)
127 return gpio->irq(gpio, idx, tag, line, on);
132 nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
133 void (*exec)(void *, int state), void *data)
135 struct nouveau_drm *drm = nouveau_newpriv(dev);
136 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
137 if (gpio && gpio->isr_add)
138 return gpio->isr_add(gpio, idx, tag, line, exec, data);
143 nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
144 void (*exec)(void *, int state), void *data)
146 struct nouveau_drm *drm = nouveau_newpriv(dev);
147 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
148 if (gpio && gpio->isr_del)
149 gpio->isr_del(gpio, idx, tag, line, exec, data);
152 struct nouveau_i2c_port *
153 nouveau_i2c_find(struct drm_device *dev, u8 index)
155 struct nouveau_drm *drm = nouveau_newpriv(dev);
156 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
158 return i2c->find(i2c, index);
162 nouveau_probe_i2c_addr(struct nouveau_i2c_port *port, int addr)
164 return nv_probe_i2c(port, addr);
168 nouveau_i2c_adapter(struct nouveau_i2c_port *port)
170 return &port->adapter;
175 nouveau_i2c_identify(struct drm_device *dev, const char *what,
176 struct i2c_board_info *info,
177 bool (*match)(struct nouveau_i2c_port *,
178 struct i2c_board_info *),
181 struct nouveau_drm *drm = nouveau_newpriv(dev);
182 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
184 return i2c->identify(i2c, index, what, info, match);
188 auxch_rd(struct drm_device *dev, struct nouveau_i2c_port *port,
189 u32 addr, u8 *data, u8 size)
191 return nv_rdaux(port, addr, data, size);
195 auxch_wr(struct drm_device *dev, struct nouveau_i2c_port *port,
196 u32 addr, u8 *data, u8 size)
198 return nv_wraux(port, addr, data, size);
202 get_pll_register(struct drm_device *dev, u32 type)
204 struct nouveau_drm *drm = nouveau_newpriv(dev);
205 struct nouveau_bios *bios = nouveau_bios(drm->device);
206 struct nvbios_pll info;
208 if (nvbios_pll_parse(bios, type, &info))
214 get_pll_limits(struct drm_device *dev, u32 type, struct nvbios_pll *info)
216 struct nouveau_drm *drm = nouveau_newpriv(dev);
217 struct nouveau_bios *bios = nouveau_bios(drm->device);
219 return nvbios_pll_parse(bios, type, info);
223 setPLL(struct drm_device *dev, u32 reg, u32 freq)
225 struct nouveau_drm *drm = nouveau_newpriv(dev);
226 struct nouveau_clock *clk = nouveau_clock(drm->device);
230 ret = clk->pll_set(clk, reg, freq);
236 nouveau_calc_pll_mnp(struct drm_device *dev, struct nvbios_pll *info,
237 int freq, struct nouveau_pll_vals *pv)
239 struct nouveau_drm *drm = nouveau_newpriv(dev);
240 struct nouveau_clock *clk = nouveau_clock(drm->device);
244 ret = clk->pll_calc(clk, info, freq, pv);
249 nouveau_hw_setpll(struct drm_device *dev, u32 reg1,
250 struct nouveau_pll_vals *pv)
252 struct nouveau_drm *drm = nouveau_newpriv(dev);
253 struct nouveau_clock *clk = nouveau_clock(drm->device);
257 ret = clk->pll_prog(clk, reg1, pv);
261 int nva3_pll_calc(struct nouveau_clock *, struct nvbios_pll *, u32 freq,
262 int *N, int *fN, int *M, int *P);
265 nva3_calc_pll(struct drm_device *dev, struct nvbios_pll *info, u32 freq,
266 int *N, int *fN, int *M, int *P)
268 struct nouveau_drm *drm = nouveau_newpriv(dev);
269 struct nouveau_clock *clk = nouveau_clock(drm->device);
271 return nva3_pll_calc(clk, info, freq, N, fN, M, P);
275 nouveau_bios_run_init_table(struct drm_device *dev, uint16_t table,
276 struct dcb_output *dcbent, int crtc)
278 struct nouveau_drm *drm = nouveau_newpriv(dev);
279 struct nouveau_bios *bios = nouveau_bios(drm->device);
280 struct nvbios_init init = {
281 .subdev = nv_subdev(bios),
293 nouveau_bios_init_exec(struct drm_device *dev, uint16_t table)
295 nouveau_bios_run_init_table(dev, table, NULL, 0);
299 nv_intr(struct drm_device *dev)
301 struct nouveau_drm *drm = nouveau_newpriv(dev);
302 struct nouveau_mc *pmc = nouveau_mc(drm->device);
303 nv_subdev(pmc)->intr(pmc);