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 <zircon/compiler.h>
8#include <ddk/protocol/platform-device.h>
9#include <fbl/unique_ptr.h>
10#include <hwreg/mmio.h>
11#include "common.h"
12
13namespace astro_display {
14
15class Osd {
16public:
17    Osd(uint32_t fb_width, uint32_t fb_height, uint32_t display_width, uint32_t display_height)
18        : fb_width_(fb_width), fb_height_(fb_height),
19          display_width_(display_width), display_height_(display_height) {}
20
21    ~Osd(){ io_buffer_release(&mmio_vpu_); }
22    zx_status_t Init(zx_device_t* parent);
23    void HwInit();
24    zx_status_t Configure();
25    void Disable();
26    void Flip(uint8_t idx);
27    void Dump();
28private:
29    void DefaultSetup();
30    // this function sets up scaling based on framebuffer and actual display
31    // dimensions. The scaling IP and registers and undocumented.
32    void EnableScaling(bool enable);
33    void Enable();
34
35    io_buffer_t                         mmio_vpu_;
36    platform_device_protocol_t          pdev_ = {};
37    fbl::unique_ptr<hwreg::RegisterIo>  vpu_regs_;
38
39    // Framebuffer dimension
40    uint32_t                            fb_width_;
41    uint32_t                            fb_height_;
42    // Actual display dimension
43    uint32_t                            display_width_;
44    uint32_t                            display_height_;
45
46    bool                                initialized_ = false;
47};
48
49} // namespace astro_display
50