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#pragma once
6
7#include <unistd.h>
8#include <zircon/compiler.h>
9#include <ddk/protocol/platform-device.h>
10#include <fbl/unique_ptr.h>
11#include <hwreg/mmio.h>
12#include <ddktl/device.h>
13
14#include "common.h"
15#include "hhi-regs.h"
16#include "vpu-regs.h"
17#include "lcd.h"
18#include "aml-mipi-phy.h"
19
20namespace astro_display {
21
22class AmlDsiHost {
23public:
24    AmlDsiHost(zx_device_t* parent, uint32_t bitrate, uint8_t panel_type)
25        : parent_(parent), bitrate_(bitrate), panel_type_(panel_type) {}
26
27    ~AmlDsiHost() {
28        io_buffer_release(&mmio_hhi_);
29        io_buffer_release(&mmio_mipi_dsi_);
30    }
31
32    // This function sets up mipi dsi interface. It includes both DWC and AmLogic blocks
33    // The DesignWare setup could technically be moved to the dw_mipi_dsi driver. However,
34    // given the highly configurable nature of this block, we'd have to provide a lot of
35    // information to the generic driver. Therefore, it's just simpler to configure it here
36    zx_status_t Init();
37    zx_status_t HostOn(const DisplaySetting& disp_setting);
38    // This function will turn off DSI Host. It is a "best-effort" function. We will attempt
39    // to shutdown whatever we can. Error during shutdown path is ignored and function proceeds
40    // with shutting down.
41    void HostOff(const DisplaySetting& disp_setting);
42    void Dump();
43private:
44    void PhyEnable();
45    void PhyDisable();
46    zx_status_t HostModeInit(uint32_t opp, const DisplaySetting& disp_setting);
47
48    io_buffer_t                                 mmio_mipi_dsi_;
49    io_buffer_t                                 mmio_hhi_;
50
51    platform_device_protocol_t                  pdev_ = {};
52
53    fbl::unique_ptr<hwreg::RegisterIo>          mipi_dsi_regs_;
54    fbl::unique_ptr<hwreg::RegisterIo>          hhi_regs_;
55
56    zx_device_t*                                parent_;
57
58    uint32_t                                    bitrate_;
59    uint8_t                                     panel_type_;
60
61    bool                                        initialized_ = false;
62    bool                                        host_on_ = false;
63
64    fbl::unique_ptr<Lcd>         lcd_;
65    fbl::unique_ptr<AmlMipiPhy>  phy_;
66
67};
68
69} // namespace astro_display
70