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/platform-defs.h>
8 #include <ddk/protocol/platform/bus.h>
9 
10 #include <soc/aml-s905d2/s905d2-gpio.h>
11 #include <soc/aml-s905d2/s905d2-hw.h>
12 
13 #include <limits.h>
14 
15 #include "astro.h"
16 
17 static const pbus_mmio_t display_mmios[] = {
18     {
19         // VBUS/VPU
20         .base = S905D2_VPU_BASE,
21         .length = S905D2_VPU_LENGTH,
22     },
23     {
24         // DSI Host Controller
25         .base = S905D2_MIPI_DSI_BASE,
26         .length = S905D2_MIPI_DSI_LENGTH,
27     },
28     {
29         // DSI PHY
30         .base = S905D2_DSI_PHY_BASE,
31         .length = S905D2_DSI_PHY_LENGTH,
32     },
33     {
34         // HHI
35         .base = S905D2_HIU_BASE,
36         .length = S905D2_HIU_LENGTH,
37     },
38     {
39         // AOBUS
40         .base = S905D2_AOBUS_BASE,
41         .length = S905D2_AOBUS_LENGTH,
42     },
43     {
44         // CBUS
45         .base = S905D2_CBUS_BASE,
46         .length = S905D2_CBUS_LENGTH,
47     },
48 };
49 
50 static const pbus_irq_t display_irqs[] = {
51     {
52         .irq = S905D2_VIU1_VSYNC_IRQ,
53         .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
54     },
55     {
56         .irq = S905D2_RDMA_DONE,
57         .mode = ZX_INTERRUPT_MODE_EDGE_HIGH,
58     },
59 };
60 
61 static const pbus_gpio_t display_gpios[] = {
62     {
63         // Backlight Enable
64         .gpio = S905D2_GPIOA(10),
65     },
66     {
67         // LCD Reset
68         .gpio = S905D2_GPIOH(6),
69     },
70     {
71         // Panel detection
72         .gpio = S905D2_GPIOH(5),
73     },
74 };
75 
76 static const pbus_bti_t display_btis[] = {
77     {
78         .iommu_index = 0,
79         .bti_id = BTI_DISPLAY,
80     },
81 };
82 
83 static const pbus_i2c_channel_t display_i2c_channels[] = {
84     {
85         .bus_id = ASTRO_I2C_3,
86         .address = I2C_BACKLIGHT_ADDR,
87     },
88 };
89 
90 static const uint32_t display_protocols[] = {
91     ZX_PROTOCOL_AMLOGIC_CANVAS,
92 };
93 
94 static pbus_dev_t display_dev = {
95     .name = "display",
96     .vid = PDEV_VID_AMLOGIC,
97     .pid = PDEV_PID_AMLOGIC_S905D2,
98     .did = PDEV_DID_AMLOGIC_DISPLAY,
99     .mmio_list = display_mmios,
100     .mmio_count = countof(display_mmios),
101     .irq_list = display_irqs,
102     .irq_count = countof(display_irqs),
103     .gpio_list = display_gpios,
104     .gpio_count = countof(display_gpios),
105     .i2c_channel_list = display_i2c_channels,
106     .i2c_channel_count = countof(display_i2c_channels),
107     .bti_list = display_btis,
108     .bti_count = countof(display_btis),
109     .protocol_list = display_protocols,
110     .protocol_count = countof(display_protocols),
111 };
112 
aml_display_init(aml_bus_t * bus)113 zx_status_t aml_display_init(aml_bus_t* bus) {
114     zx_status_t status = pbus_device_add(&bus->pbus, &display_dev);
115     if (status != ZX_OK) {
116         zxlogf(ERROR, "%s: Could not add display dev: %d\n", __FUNCTION__, status);
117         return status;
118     }
119     return ZX_OK;
120 }
121