File drivers/gpu/alga/amd/atombios/cm.c changed (mode: 100644) (index 8a76eea..79c4b50) |
21 |
21 |
#include "tables/firmware_info.h" |
#include "tables/firmware_info.h" |
22 |
22 |
#include "tables/i2c.h" |
#include "tables/i2c.h" |
23 |
23 |
#include "tables/pp.h" |
#include "tables/pp.h" |
|
24 |
|
#include "tables/eng_mem_pll_compute.h" |
24 |
25 |
|
|
25 |
26 |
#include "atb.h" |
#include "atb.h" |
26 |
27 |
|
|
|
... |
... |
unlock_mutex: |
231 |
232 |
} |
} |
232 |
233 |
EXPORT_SYMBOL_GPL(atb_core_ref_clk_get); |
EXPORT_SYMBOL_GPL(atb_core_ref_clk_get); |
233 |
234 |
|
|
234 |
|
long atb_eng_clk_get(struct atombios *atb, u32 *clk) |
|
|
235 |
|
long atb_eng_clk_set(struct atombios *atb, u32 clk) |
235 |
236 |
{ |
{ |
236 |
237 |
u16 of; |
u16 of; |
237 |
238 |
struct master_cmd_tbl *cmd_tbl; |
struct master_cmd_tbl *cmd_tbl; |
238 |
239 |
struct common_cmd_tbl_hdr *eng_clk_set; |
struct common_cmd_tbl_hdr *eng_clk_set; |
239 |
|
struct mem_eng_clk_get_params *ps; |
|
|
240 |
|
struct mem_eng_clk_set_params *ps; |
240 |
241 |
long r; |
long r; |
241 |
242 |
|
|
242 |
243 |
mutex_lock(&atb->mutex); |
mutex_lock(&atb->mutex); |
|
... |
... |
long atb_eng_clk_get(struct atombios *atb, u32 *clk) |
246 |
247 |
of = get_unaligned_le16(&cmd_tbl->list.eng_clk_set); |
of = get_unaligned_le16(&cmd_tbl->list.eng_clk_set); |
247 |
248 |
|
|
248 |
249 |
eng_clk_set = atb->adev.rom + of; |
eng_clk_set = atb->adev.rom + of; |
249 |
|
dev_info(atb->adev.dev, "atombios:eng_clk_get (0x%04x) revision %u.%u\n", |
|
|
250 |
|
dev_info(atb->adev.dev, "atombios:eng_clk_set (0x%04x) revision %u.%u\n", |
250 |
251 |
of, eng_clk_set->hdr.tbl_fmt_rev, |
of, eng_clk_set->hdr.tbl_fmt_rev, |
251 |
252 |
eng_clk_set->hdr.tbl_content_rev); |
eng_clk_set->hdr.tbl_content_rev); |
252 |
253 |
|
|
|
... |
... |
long atb_eng_clk_get(struct atombios *atb, u32 *clk) |
257 |
258 |
r = -ATB_ERR; |
r = -ATB_ERR; |
258 |
259 |
goto unlock_mutex; |
goto unlock_mutex; |
259 |
260 |
} |
} |
260 |
|
ps = (struct mem_eng_clk_get_params *)atb->g_ctx.ps_top; |
|
|
261 |
|
ps = (struct mem_eng_clk_set_params *)atb->g_ctx.ps_top; |
|
262 |
|
put_unaligned_le32(clk, &ps->clk); |
261 |
263 |
|
|
262 |
264 |
atb->g_ctx.fb_wnd = 0; |
atb->g_ctx.fb_wnd = 0; |
263 |
265 |
atb->g_ctx.regs_blk = 0; |
atb->g_ctx.regs_blk = 0; |
264 |
266 |
atb->g_ctx.io_mode = IO_MM; |
atb->g_ctx.io_mode = IO_MM; |
265 |
267 |
|
|
266 |
268 |
r = interpret(atb, of, 0, 0); |
r = interpret(atb, of, 0, 0); |
267 |
|
|
|
268 |
|
ps = (struct mem_eng_clk_get_params *)atb->g_ctx.ps_top; |
|
269 |
|
*clk = get_unaligned_le32(&ps->clk); |
|
270 |
269 |
kfree(atb->g_ctx.ps_top); |
kfree(atb->g_ctx.ps_top); |
271 |
270 |
|
|
272 |
271 |
unlock_mutex: |
unlock_mutex: |
273 |
272 |
mutex_unlock(&atb->mutex); |
mutex_unlock(&atb->mutex); |
274 |
273 |
return r; |
return r; |
275 |
274 |
} |
} |
276 |
|
EXPORT_SYMBOL_GPL(atb_eng_clk_get); |
|
|
275 |
|
EXPORT_SYMBOL_GPL(atb_eng_clk_set); |
277 |
276 |
|
|
278 |
|
long atb_mem_clk_get(struct atombios *atb, u32 *clk) |
|
|
277 |
|
long atb_mem_clk_set(struct atombios *atb, u32 clk) |
279 |
278 |
{ |
{ |
280 |
279 |
u16 of; |
u16 of; |
281 |
280 |
struct master_cmd_tbl *cmd_tbl; |
struct master_cmd_tbl *cmd_tbl; |
282 |
281 |
struct common_cmd_tbl_hdr *mem_clk_set; |
struct common_cmd_tbl_hdr *mem_clk_set; |
283 |
|
struct mem_eng_clk_get_params *ps; |
|
|
282 |
|
struct mem_eng_clk_set_params *ps; |
284 |
283 |
long r; |
long r; |
285 |
284 |
|
|
286 |
285 |
mutex_lock(&atb->mutex); |
mutex_lock(&atb->mutex); |
|
... |
... |
long atb_mem_clk_get(struct atombios *atb, u32 *clk) |
290 |
289 |
of = get_unaligned_le16(&cmd_tbl->list.mem_clk_set); |
of = get_unaligned_le16(&cmd_tbl->list.mem_clk_set); |
291 |
290 |
|
|
292 |
291 |
mem_clk_set = atb->adev.rom + of; |
mem_clk_set = atb->adev.rom + of; |
293 |
|
dev_info(atb->adev.dev, "atombios:mem_clk_get (0x%04x) revision %u.%u\n", |
|
|
292 |
|
dev_info(atb->adev.dev, "atombios:mem_clk_set (0x%04x) revision %u.%u\n", |
294 |
293 |
of, mem_clk_set->hdr.tbl_fmt_rev, |
of, mem_clk_set->hdr.tbl_fmt_rev, |
295 |
294 |
mem_clk_set->hdr.tbl_content_rev); |
mem_clk_set->hdr.tbl_content_rev); |
296 |
295 |
|
|
|
... |
... |
long atb_mem_clk_get(struct atombios *atb, u32 *clk) |
301 |
300 |
r = -ATB_ERR; |
r = -ATB_ERR; |
302 |
301 |
goto unlock_mutex; |
goto unlock_mutex; |
303 |
302 |
} |
} |
304 |
|
ps = (struct mem_eng_clk_get_params *)atb->g_ctx.ps_top; |
|
|
303 |
|
ps = (struct mem_eng_clk_set_params *)atb->g_ctx.ps_top; |
|
304 |
|
put_unaligned_le32(clk, &ps->clk); |
305 |
305 |
|
|
306 |
306 |
atb->g_ctx.fb_wnd = 0; |
atb->g_ctx.fb_wnd = 0; |
307 |
307 |
atb->g_ctx.regs_blk = 0; |
atb->g_ctx.regs_blk = 0; |
308 |
308 |
atb->g_ctx.io_mode = IO_MM; |
atb->g_ctx.io_mode = IO_MM; |
309 |
309 |
|
|
310 |
310 |
r = interpret(atb, of, 0, 0); |
r = interpret(atb, of, 0, 0); |
311 |
|
|
|
312 |
|
ps = (struct mem_eng_clk_get_params *)atb->g_ctx.ps_top; |
|
313 |
|
*clk = get_unaligned_le32(&ps->clk); |
|
314 |
311 |
kfree(atb->g_ctx.ps_top); |
kfree(atb->g_ctx.ps_top); |
315 |
312 |
|
|
316 |
313 |
unlock_mutex: |
unlock_mutex: |
317 |
314 |
mutex_unlock(&atb->mutex); |
mutex_unlock(&atb->mutex); |
318 |
315 |
return r; |
return r; |
319 |
316 |
} |
} |
320 |
|
EXPORT_SYMBOL_GPL(atb_mem_clk_get); |
|
|
317 |
|
EXPORT_SYMBOL_GPL(atb_mem_clk_set); |
321 |
318 |
|
|
322 |
|
long atb_eng_clk_set(struct atombios *atb, u32 clk) |
|
|
319 |
|
static inline u32 set(u32 mask, u32 v) |
323 |
320 |
{ |
{ |
324 |
|
u16 of; |
|
325 |
|
struct master_cmd_tbl *cmd_tbl; |
|
326 |
|
struct common_cmd_tbl_hdr *eng_clk_set; |
|
327 |
|
struct mem_eng_clk_set_params *ps; |
|
328 |
|
long r; |
|
329 |
|
|
|
330 |
|
mutex_lock(&atb->mutex); |
|
331 |
|
|
|
332 |
|
of = get_unaligned_le16(&atb->hdr->master_cmd_tbl_of); |
|
333 |
|
cmd_tbl = atb->adev.rom + of; |
|
334 |
|
of = get_unaligned_le16(&cmd_tbl->list.eng_clk_set); |
|
335 |
|
|
|
336 |
|
eng_clk_set = atb->adev.rom + of; |
|
337 |
|
dev_info(atb->adev.dev, "atombios:eng_clk_set (0x%04x) revision %u.%u\n", |
|
338 |
|
of, eng_clk_set->hdr.tbl_fmt_rev, |
|
339 |
|
eng_clk_set->hdr.tbl_content_rev); |
|
340 |
|
|
|
341 |
|
atb->g_ctx.ps_dws = 0x80;/* max for ps index */ |
|
342 |
|
atb->g_ctx.ps_top = kzalloc(atb->g_ctx.ps_dws * 4, GFP_KERNEL); |
|
343 |
|
if (!atb->g_ctx.ps_top) { |
|
344 |
|
dev_err(atb->adev.dev, "atombios:unable to allocate parameter space (stack)\n"); |
|
345 |
|
r = -ATB_ERR; |
|
346 |
|
goto unlock_mutex; |
|
347 |
|
} |
|
348 |
|
ps = (struct mem_eng_clk_set_params *)atb->g_ctx.ps_top; |
|
349 |
|
put_unaligned_le32(clk, &ps->clk); |
|
350 |
|
|
|
351 |
|
atb->g_ctx.fb_wnd = 0; |
|
352 |
|
atb->g_ctx.regs_blk = 0; |
|
353 |
|
atb->g_ctx.io_mode = IO_MM; |
|
354 |
|
|
|
355 |
|
r = interpret(atb, of, 0, 0); |
|
356 |
|
kfree(atb->g_ctx.ps_top); |
|
|
321 |
|
u8 shift; |
357 |
322 |
|
|
358 |
|
unlock_mutex: |
|
359 |
|
mutex_unlock(&atb->mutex); |
|
360 |
|
return r; |
|
|
323 |
|
shift = ffs(mask) - 1; |
|
324 |
|
return (v << shift) & mask; |
361 |
325 |
} |
} |
362 |
|
EXPORT_SYMBOL_GPL(atb_eng_clk_set); |
|
363 |
326 |
|
|
364 |
|
long atb_mem_clk_set(struct atombios *atb, u32 clk) |
|
|
327 |
|
long atb_eng_mem_timings_program(struct atombios *atb, u32 eng_clk, |
|
328 |
|
u32 mem_clk) |
365 |
329 |
{ |
{ |
366 |
330 |
u16 of; |
u16 of; |
367 |
331 |
struct master_cmd_tbl *cmd_tbl; |
struct master_cmd_tbl *cmd_tbl; |
368 |
|
struct common_cmd_tbl_hdr *mem_clk_set; |
|
|
332 |
|
struct common_cmd_tbl_hdr *dyn_mem_settings; |
369 |
333 |
struct mem_eng_clk_set_params *ps; |
struct mem_eng_clk_set_params *ps; |
370 |
334 |
long r; |
long r; |
371 |
335 |
|
|
|
... |
... |
long atb_mem_clk_set(struct atombios *atb, u32 clk) |
373 |
337 |
|
|
374 |
338 |
of = get_unaligned_le16(&atb->hdr->master_cmd_tbl_of); |
of = get_unaligned_le16(&atb->hdr->master_cmd_tbl_of); |
375 |
339 |
cmd_tbl = atb->adev.rom + of; |
cmd_tbl = atb->adev.rom + of; |
376 |
|
of = get_unaligned_le16(&cmd_tbl->list.mem_clk_set); |
|
|
340 |
|
of = get_unaligned_le16(&cmd_tbl->list.dyn_mem_settings); |
377 |
341 |
|
|
378 |
|
mem_clk_set = atb->adev.rom + of; |
|
379 |
|
dev_info(atb->adev.dev, "atombios:mem_clk_set (0x%04x) revision %u.%u\n", |
|
380 |
|
of, mem_clk_set->hdr.tbl_fmt_rev, |
|
381 |
|
mem_clk_set->hdr.tbl_content_rev); |
|
|
342 |
|
dyn_mem_settings = atb->adev.rom + of; |
|
343 |
|
dev_info(atb->adev.dev, "atombios:dyn_mem_settings (0x%04x) revision %u.%u\n", |
|
344 |
|
of,dyn_mem_settings->hdr.tbl_fmt_rev, |
|
345 |
|
dyn_mem_settings->hdr.tbl_content_rev); |
|
346 |
|
/* FIXME: lock a revision */ |
382 |
347 |
|
|
383 |
348 |
atb->g_ctx.ps_dws = 0x80;/* max for ps index */ |
atb->g_ctx.ps_dws = 0x80;/* max for ps index */ |
384 |
349 |
atb->g_ctx.ps_top = kzalloc(atb->g_ctx.ps_dws * 4, GFP_KERNEL); |
atb->g_ctx.ps_top = kzalloc(atb->g_ctx.ps_dws * 4, GFP_KERNEL); |
|
... |
... |
long atb_mem_clk_set(struct atombios *atb, u32 clk) |
388 |
353 |
goto unlock_mutex; |
goto unlock_mutex; |
389 |
354 |
} |
} |
390 |
355 |
ps = (struct mem_eng_clk_set_params *)atb->g_ctx.ps_top; |
ps = (struct mem_eng_clk_set_params *)atb->g_ctx.ps_top; |
391 |
|
put_unaligned_le32(clk, &ps->clk); |
|
|
356 |
|
eng_clk |= set(MEM_ENG_COMPUTE_OP, COMPUTE_ENGINE_PLL); |
|
357 |
|
put_unaligned_le32(eng_clk, &ps->clk); |
|
358 |
|
put_unaligned_le32(mem_clk, &ps->mem_eng_pll_compute_params.mem_clk); |
392 |
359 |
|
|
393 |
360 |
atb->g_ctx.fb_wnd = 0; |
atb->g_ctx.fb_wnd = 0; |
394 |
361 |
atb->g_ctx.regs_blk = 0; |
atb->g_ctx.regs_blk = 0; |
|
... |
... |
unlock_mutex: |
401 |
368 |
mutex_unlock(&atb->mutex); |
mutex_unlock(&atb->mutex); |
402 |
369 |
return r; |
return r; |
403 |
370 |
} |
} |
404 |
|
EXPORT_SYMBOL_GPL(atb_mem_clk_set); |
|
405 |
|
|
|
406 |
|
static inline u32 set(u32 mask, u32 v) |
|
407 |
|
{ |
|
408 |
|
u8 shift; |
|
409 |
|
|
|
410 |
|
shift = ffs(mask) - 1; |
|
411 |
|
return (v << shift) & mask; |
|
412 |
|
} |
|
|
371 |
|
EXPORT_SYMBOL_GPL(atb_eng_mem_timings_program); |
413 |
372 |
|
|
414 |
|
long atb_eng_mem_set(struct atombios *atb, u32 eng_clk, u32 mem_clk) |
|
|
373 |
|
long atb_eng_mem_pll_compute(struct atombios *atb, u32 eng_clk, |
|
374 |
|
struct atb_clk_div *atb_clk_div) |
415 |
375 |
{ |
{ |
416 |
376 |
u16 of; |
u16 of; |
417 |
377 |
struct master_cmd_tbl *cmd_tbl; |
struct master_cmd_tbl *cmd_tbl; |
418 |
|
struct common_cmd_tbl_hdr *eng_clk_set; |
|
419 |
|
struct mem_eng_clk_set_params *ps; |
|
|
378 |
|
struct common_cmd_tbl_hdr *eng_mem_pll_compute; |
|
379 |
|
struct eng_mem_pll_compute_params *ps; |
420 |
380 |
long r; |
long r; |
421 |
381 |
|
|
422 |
382 |
mutex_lock(&atb->mutex); |
mutex_lock(&atb->mutex); |
423 |
383 |
|
|
424 |
384 |
of = get_unaligned_le16(&atb->hdr->master_cmd_tbl_of); |
of = get_unaligned_le16(&atb->hdr->master_cmd_tbl_of); |
425 |
385 |
cmd_tbl = atb->adev.rom + of; |
cmd_tbl = atb->adev.rom + of; |
426 |
|
of = get_unaligned_le16(&cmd_tbl->list.dyn_mem_settings); |
|
427 |
|
|
|
428 |
|
eng_clk_set = atb->adev.rom + of; |
|
429 |
|
dev_info(atb->adev.dev, "atombios:eng_clk_set (0x%04x) revision %u.%u\n", |
|
430 |
|
of, eng_clk_set->hdr.tbl_fmt_rev, |
|
431 |
|
eng_clk_set->hdr.tbl_content_rev); |
|
|
386 |
|
of = get_unaligned_le16(&cmd_tbl->list.eng_mem_pll_compute); |
|
387 |
|
|
|
388 |
|
eng_mem_pll_compute = atb->adev.rom + of; |
|
389 |
|
dev_info(atb->adev.dev, "atombios:eng_mem_pll_compute(0x%04x) revision %u.%u\n", |
|
390 |
|
of,eng_mem_pll_compute->hdr.tbl_fmt_rev, |
|
391 |
|
eng_mem_pll_compute->hdr.tbl_content_rev); |
|
392 |
|
//FIXME: lock the info->hdr.tbl_fmt_rev |
|
393 |
|
if (eng_mem_pll_compute->hdr.tbl_content_rev != 5) { |
|
394 |
|
dev_err(atb->adev.dev, "atombios:eng_mem_pll_compute revision not supported"); |
|
395 |
|
r = -ATB_ERR; |
|
396 |
|
goto unlock_mutex; |
|
397 |
|
} |
432 |
398 |
|
|
433 |
399 |
atb->g_ctx.ps_dws = 0x80;/* max for ps index */ |
atb->g_ctx.ps_dws = 0x80;/* max for ps index */ |
434 |
400 |
atb->g_ctx.ps_top = kzalloc(atb->g_ctx.ps_dws * 4, GFP_KERNEL); |
atb->g_ctx.ps_top = kzalloc(atb->g_ctx.ps_dws * 4, GFP_KERNEL); |
|
... |
... |
long atb_eng_mem_set(struct atombios *atb, u32 eng_clk, u32 mem_clk) |
437 |
403 |
r = -ATB_ERR; |
r = -ATB_ERR; |
438 |
404 |
goto unlock_mutex; |
goto unlock_mutex; |
439 |
405 |
} |
} |
440 |
|
ps = (struct mem_eng_clk_set_params *)atb->g_ctx.ps_top; |
|
|
406 |
|
ps = (struct eng_mem_pll_compute_params*)atb->g_ctx.ps_top; |
441 |
407 |
eng_clk |= set(MEM_ENG_COMPUTE_OP, COMPUTE_ENGINE_PLL); |
eng_clk |= set(MEM_ENG_COMPUTE_OP, COMPUTE_ENGINE_PLL); |
442 |
|
put_unaligned_le32(eng_clk, &ps->clk); |
|
443 |
|
put_unaligned_le32(mem_clk, &ps->mem_eng_pll_compute_params.mem_clk); |
|
|
408 |
|
put_unaligned_le32(eng_clk, &ps->u.clk); |
444 |
409 |
|
|
445 |
410 |
atb->g_ctx.fb_wnd = 0; |
atb->g_ctx.fb_wnd = 0; |
446 |
411 |
atb->g_ctx.regs_blk = 0; |
atb->g_ctx.regs_blk = 0; |
447 |
412 |
atb->g_ctx.io_mode = IO_MM; |
atb->g_ctx.io_mode = IO_MM; |
448 |
413 |
|
|
449 |
414 |
r = interpret(atb, of, 0, 0); |
r = interpret(atb, of, 0, 0); |
|
415 |
|
|
|
416 |
|
if (r == 0) { |
|
417 |
|
memset(atb_clk_div, 0, sizeof(*atb_clk_div)); |
|
418 |
|
|
|
419 |
|
atb_clk_div->post_div = ps->post_div; |
|
420 |
|
if (ps->flgs & PLL_POST_DIV_ENA) |
|
421 |
|
atb_clk_div->flgs |= ATB_CLK_DIV_POST_DIV_ENA; |
|
422 |
|
if (!(ps->flgs & FRAC_DIS)) |
|
423 |
|
atb_clk_div->flgs |= ATB_CLK_DIV_DITHEN_ENA; |
|
424 |
|
atb_clk_div->whole = get_unaligned_le16( |
|
425 |
|
&ps->u.fb_div.whole); |
|
426 |
|
atb_clk_div->frac = get_unaligned_le16( |
|
427 |
|
&ps->u.fb_div.frac); |
|
428 |
|
atb_clk_div->ref_div = ps->ref_div; |
|
429 |
|
if (ps->flgs & MEM_PLL_VCO_MODE) |
|
430 |
|
atb_clk_div->flgs |= ATB_CLK_DIV_VCO_MODE; |
|
431 |
|
} |
450 |
432 |
kfree(atb->g_ctx.ps_top); |
kfree(atb->g_ctx.ps_top); |
451 |
433 |
|
|
452 |
434 |
unlock_mutex: |
unlock_mutex: |
453 |
435 |
mutex_unlock(&atb->mutex); |
mutex_unlock(&atb->mutex); |
454 |
436 |
return r; |
return r; |
455 |
437 |
} |
} |
456 |
|
EXPORT_SYMBOL_GPL(atb_eng_mem_set); |
|
|
438 |
|
EXPORT_SYMBOL_GPL(atb_eng_mem_pll_compute); |