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 "mipi-dsi.h" 13#include "dw-mipi-dsi-reg.h" 14#include "common.h" 15 16// Assigned Virtual Channel ID for Astro 17// TODO(payamm): Will need to generate and maintain VCID for multi-display 18// solutions 19 20#define MIPI_DSI_VIRTUAL_CHAN_ID (0) 21 22namespace astro_display { 23 24class DwMipiDsi { 25public: 26 DwMipiDsi() {} 27 ~DwMipiDsi() { io_buffer_release(&mmio_mipi_dsi_); } 28 zx_status_t Init(zx_device_t* parent); 29 zx_status_t Cmd(const uint8_t* tbuf, size_t tlen, uint8_t* rbuf, size_t rlen, bool is_dcs); 30 31private: 32 inline bool IsPldREmpty(); 33 inline bool IsPldRFull(); 34 inline bool IsPldWEmpty(); 35 inline bool IsPldWFull(); 36 inline bool IsCmdEmpty(); 37 inline bool IsCmdFull(); 38 zx_status_t WaitforFifo(uint32_t reg, uint32_t bit, uint32_t val); 39 zx_status_t WaitforPldWNotFull(); 40 zx_status_t WaitforPldWEmpty(); 41 zx_status_t WaitforPldRFull(); 42 zx_status_t WaitforPldRNotEmpty(); 43 zx_status_t WaitforCmdNotFull(); 44 zx_status_t WaitforCmdEmpty(); 45 void DumpCmd(const MipiDsiCmd& cmd); 46 zx_status_t GenericPayloadRead(uint32_t* data); 47 zx_status_t GenericHdrWrite(uint32_t data); 48 zx_status_t GenericPayloadWrite(uint32_t data); 49 void EnableBta(); 50 void DisableBta(); 51 zx_status_t WaitforBtaAck(); 52 zx_status_t GenWriteShort(const MipiDsiCmd& cmd); 53 zx_status_t DcsWriteShort(const MipiDsiCmd& cmd); 54 zx_status_t GenWriteLong(const MipiDsiCmd& cmd); 55 zx_status_t GenRead(const MipiDsiCmd& cmd); 56 zx_status_t SendCmd(const MipiDsiCmd& cmd); 57 58 io_buffer_t mmio_mipi_dsi_; 59 platform_device_protocol_t pdev_ = {}; 60 fbl::unique_ptr<hwreg::RegisterIo> mipi_dsi_regs_; 61 62 bool initialized_ = false; 63}; 64 65} // namespace astro_display 66