1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <stdlib.h>
6
7#include <soc/aml-common/aml-gpu.h>
8#include <soc/aml-s905d2/s905d2-hiu.h>
9
10zx_status_t aml_gp0_init(aml_gpu_t* gpu) {
11    gpu->hiu_dev = calloc(1, sizeof(*gpu->hiu_dev));
12    gpu->gp0_pll_dev = calloc(1, sizeof(*gpu->gp0_pll_dev));
13    // HIU Init.
14    zx_status_t status = s905d2_hiu_init(gpu->bti, gpu->hiu_dev);
15    if (status != ZX_OK) {
16        zxlogf(ERROR, "aml_gp0_init: hiu_init failed: %d\n", status);
17        return status;
18    }
19
20    status = s905d2_pll_init(gpu->hiu_dev, gpu->gp0_pll_dev, GP0_PLL);
21    if (status != ZX_OK) {
22        zxlogf(ERROR, "aml_gp0_init: pll_init failed: %d\n", status);
23        return status;
24    }
25
26    status = s905d2_pll_set_rate(gpu->gp0_pll_dev, 846000000);
27    if (status != ZX_OK) {
28        zxlogf(ERROR, "aml_gp0_init: pll_set_rate failed: %d\n", status);
29        return status;
30    }
31    status = s905d2_pll_ena(gpu->gp0_pll_dev);
32    if (status != ZX_OK) {
33        zxlogf(ERROR, "aml_gp0_init: pll_ena failed: %d\n", status);
34        return status;
35    }
36    return ZX_OK;
37}
38
39void aml_gp0_release(aml_gpu_t* gpu) {
40    // TODO: turn off PLL
41    free(gpu->gp0_pll_dev);
42    free(gpu->hiu_dev);
43}
44