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 <ddk/debug.h>
6#include <ddk/device.h>
7#include <ddk/protocol/platform-bus.h>
8#include <ddk/protocol/platform-defs.h>
9#include <soc/aml-s905d2/s905d2-hw.h>
10
11#include "astro.h"
12
13static pbus_mmio_t astro_video_mmios[] = {
14    {
15        .base = S905D2_CBUS_BASE,
16        .length = S905D2_CBUS_LENGTH,
17    },
18    {
19        .base = S905D2_DOS_BASE,
20        .length = S905D2_DOS_LENGTH,
21    },
22    {
23        .base = S905D2_HIU_BASE,
24        .length = S905D2_HIU_LENGTH,
25    },
26    {
27        .base = S905D2_AOBUS_BASE,
28        .length = S905D2_AOBUS_LENGTH,
29    },
30    {
31        .base = S905D2_DMC_BASE,
32        .length = S905D2_DMC_LENGTH,
33    },
34};
35
36static const pbus_bti_t astro_video_btis[] = {
37    {
38        .iommu_index = 0,
39        .bti_id = BTI_VIDEO,
40    },
41};
42
43static const pbus_irq_t astro_video_irqs[] = {
44    {
45        .irq = S905D2_DEMUX_IRQ,
46        .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
47    },
48    {
49        .irq = S905D2_PARSER_IRQ,
50        .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
51    },
52    {
53        .irq = S905D2_DOS_MBOX_0_IRQ,
54        .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
55    },
56    {
57        .irq = S905D2_DOS_MBOX_1_IRQ,
58        .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
59    },
60    {
61        .irq = S905D2_DOS_MBOX_2_IRQ,
62        .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
63    },
64};
65
66static const uint32_t astro_video_protocols[] = {
67    ZX_PROTOCOL_AMLOGIC_CANVAS,
68};
69
70static const pbus_dev_t video_dev = {
71    .name = "aml-video",
72    .vid = PDEV_VID_AMLOGIC,
73    .pid = PDEV_PID_AMLOGIC_S905D2,
74    .did = PDEV_DID_AMLOGIC_VIDEO,
75    .mmios = astro_video_mmios,
76    .mmio_count = countof(astro_video_mmios),
77    .btis = astro_video_btis,
78    .bti_count = countof(astro_video_btis),
79    .irqs = astro_video_irqs,
80    .irq_count = countof(astro_video_irqs),
81    .protocols = astro_video_protocols,
82    .protocol_count = countof(astro_video_protocols),
83};
84
85zx_status_t aml_video_init(aml_bus_t* bus) {
86    zx_status_t status;
87    if ((status = pbus_device_add(&bus->pbus, &video_dev)) != ZX_OK) {
88        zxlogf(ERROR, "aml_video_init: pbus_device_add() failed for video: %d\n", status);
89        return status;
90    }
91    return ZX_OK;
92}
93