/*
   fd788_reg.h - register definitions driver for SoftLab-NSK FD788 board

   Copyright (C) 2017 - 2023 Konstantin Oblaukhov <oblaukhov@sl.iae.nsk.su>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef FD788_REG_H
#define FD788_REG_H

#include <linux/types.h>
#include <linux/io.h>

#define __read_reg(csr, addr) ioread32(&csr[addr])
#define __write_reg(csr, addr, v) iowrite32(v, &csr[addr])

typedef struct _FD788_GlobalCSR {
	uint32_t videoReset : 1;
	uint32_t vpllReset : 1;
	uint32_t reconfigure : 1;
	uint32_t vpllClkSelect : 1;
	uint32_t icapRW : 1;
	uint32_t reboot : 1;
	uint32_t _unused1506 : 10;
	uint32_t vpllLocked : 1;
	uint32_t qpll0Locked : 1;
	uint32_t qpll1Locked : 1;
	uint32_t vpllClk1Bad : 1;
	uint32_t vpllClk2Bad : 1;
	uint32_t _unused3121 : 11;
} __attribute__((packed)) FD788_GlobalCSR;

#define FD788_GlobalCSR_A (0xC0)

FD788_GlobalCSR __always_inline FD788_GlobalCSR_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_GlobalCSR_A);
	return *((FD788_GlobalCSR *)&r);
}

void __always_inline FD788_GlobalCSR_W(uint32_t *csr, FD788_GlobalCSR v)
{
	__write_reg(csr, FD788_GlobalCSR_A, *((uint32_t *)&v));
}

typedef struct _FD788_TemperatureMonitor {
	uint32_t temperature : 10;
	uint32_t maxTemperature : 10;
	uint32_t minTemperature : 10;
	uint32_t _unused3130 : 2;
} __attribute__((packed)) FD788_TemperatureMonitor;

#define FD788_TemperatureMonitor_A (0xC2)

FD788_TemperatureMonitor __always_inline FD788_TemperatureMonitor_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_TemperatureMonitor_A);
	return *((FD788_TemperatureMonitor *)&r);
}

typedef struct _FD788_VCoreMonitor {
	uint32_t voltage : 10;
	uint32_t maxVoltage : 10;
	uint32_t minVoltage : 10;
	uint32_t _unused3130 : 2;
} __attribute__((packed)) FD788_VCoreMonitor;

#define FD788_VCoreMonitor_A (0xC3)

FD788_VCoreMonitor __always_inline FD788_VCoreMonitor_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_VCoreMonitor_A);
	return *((FD788_VCoreMonitor *)&r);
}

typedef struct _FD788_VAuxMonitor {
	uint32_t voltage : 10;
	uint32_t maxVoltage : 10;
	uint32_t minVoltage : 10;
	uint32_t _unused3130 : 2;
} __attribute__((packed)) FD788_VAuxMonitor;

#define FD788_VAuxMonitor_A (0xC4)

FD788_VAuxMonitor __always_inline FD788_VAuxMonitor_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_VAuxMonitor_A);
	return *((FD788_VAuxMonitor *)&r);
}

typedef struct _FD788_I2C {
	uint32_t data : 8;
	uint32_t subAddress : 8;
	uint32_t rw : 1;
	uint32_t address : 7;
	uint32_t cs : 1;
	uint32_t nack : 1;
	uint32_t _unused3126 : 6;
} __attribute__((packed)) FD788_I2C;

#define FD788_I2C_A (0xC6)

FD788_I2C __always_inline FD788_I2C_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_I2C_A);
	return *((FD788_I2C *)&r);
}

void __always_inline FD788_I2C_W(uint32_t *csr, FD788_I2C v)
{
	__write_reg(csr, FD788_I2C_A, *((uint32_t *)&v));
}

typedef struct _FD788_VideoClockCounter {
	uint32_t counter : 32;
} __attribute__((packed)) FD788_VideoClockCounter;

#define FD788_VideoClockCounter_A (0xC9)

FD788_VideoClockCounter __always_inline FD788_VideoClockCounter_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_VideoClockCounter_A);
	return *((FD788_VideoClockCounter *)&r);
}

typedef struct _FD788_ClockFrequency {
	uint32_t frequency : 20;
	uint32_t _unused3120 : 12;
} __attribute__((packed)) FD788_ClockFrequency;

#define FD788_ClockFrequency_A (0xCA)

FD788_ClockFrequency __always_inline FD788_ClockFrequency_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_ClockFrequency_A);
	return *((FD788_ClockFrequency *)&r);
}

typedef struct _FD788_ClockDeviation {
	uint32_t deviation : 24;
	uint32_t _unused3024 : 7;
	uint32_t direction : 1;
} __attribute__((packed)) FD788_ClockDeviation;

#define FD788_ClockDeviation_A (0xCB)

FD788_ClockDeviation __always_inline FD788_ClockDeviation_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_ClockDeviation_A);
	return *((FD788_ClockDeviation *)&r);
}

void __always_inline FD788_ClockDeviation_W(uint32_t *csr, FD788_ClockDeviation v)
{
	__write_reg(csr, FD788_ClockDeviation_A, *((uint32_t *)&v));
}

typedef struct _FD788_VideoConfig {
	uint32_t io0 : 1;
	uint32_t io1 : 1;
	uint32_t io2 : 1;
	uint32_t io3 : 1;
	uint32_t io4 : 1;
	uint32_t io5 : 1;
	uint32_t io6 : 1;
	uint32_t io7 : 1;
	uint32_t _unused3108 : 24;
} __attribute__((packed)) FD788_VideoConfig;

#define FD788_VideoConfig_A (0xCC)

FD788_VideoConfig __always_inline FD788_VideoConfig_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_VideoConfig_A);
	return *((FD788_VideoConfig *)&r);
}

void __always_inline FD788_VideoConfig_W(uint32_t *csr, FD788_VideoConfig v)
{
	__write_reg(csr, FD788_VideoConfig_A, *((uint32_t *)&v));
}

typedef struct _FD788_SoftID {
	uint32_t id : 32;
} __attribute__((packed)) FD788_SoftID;

#define FD788_SoftID_A (0xCF)

FD788_SoftID __always_inline FD788_SoftID_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_SoftID_A);
	return *((FD788_SoftID *)&r);
}

typedef struct _FD788_SPIControl {
	uint32_t txBits : 12;
	uint32_t rxBits : 12;
	uint32_t bus : 8;
} __attribute__((packed)) FD788_SPIControl;

#define FD788_SPIControl_A (0xD2)

void __always_inline FD788_SPIControl_W(uint32_t *csr, FD788_SPIControl v)
{
	__write_reg(csr, FD788_SPIControl_A, *((uint32_t *)&v));
}

typedef struct _FD788_SPIData {
	uint32_t data : 32;
} __attribute__((packed)) FD788_SPIData;

#define FD788_SPIData_A (0xD3)

FD788_SPIData __always_inline FD788_SPIData_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_SPIData_A);
	return *((FD788_SPIData *)&r);
}

void __always_inline FD788_SPIData_W(uint32_t *csr, FD788_SPIData v)
{
	__write_reg(csr, FD788_SPIData_A, *((uint32_t *)&v));
}

typedef struct _FD788_StaticVersion {
	uint32_t revision : 16;
	uint32_t minor : 8;
	uint32_t major : 4;
	uint32_t project : 4;
} __attribute__((packed)) FD788_StaticVersion;

#define FD788_StaticVersion_A (0xFF)

FD788_StaticVersion __always_inline FD788_StaticVersion_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_StaticVersion_A);
	return *((FD788_StaticVersion *)&r);
}

void __always_inline FD788_StaticVersion_W(uint32_t *csr, FD788_StaticVersion v)
{
	__write_reg(csr, 0xFF, *((uint32_t *)&v));
}

typedef struct _FD788_VDMA {
	uint32_t _unused3000 : 31;
	uint32_t enable : 1;
} __attribute__((packed)) FD788_VDMA;

#define FD788_VDMA_A (0x00)

FD788_VDMA __always_inline FD788_VDMA_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_VDMA_A);
	return *((FD788_VDMA *)&r);
}

void __always_inline FD788_VDMA_W(uint32_t *csr, FD788_VDMA v)
{
	__write_reg(csr, FD788_VDMA_A, *((uint32_t *)&v));
}

typedef struct _FD788_VDMADescriptor {
	uint32_t address : 32;
} __attribute__((packed)) FD788_VDMADescriptor;

#define FD788_VDMADescriptor_A (0x01)

FD788_VDMADescriptor __always_inline FD788_VDMADescriptor_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_VDMADescriptor_A);
	return *((FD788_VDMADescriptor *)&r);
}

void __always_inline FD788_VDMADescriptor_W(uint32_t *csr, FD788_VDMADescriptor v)
{
	__write_reg(csr, FD788_VDMADescriptor_A, *((uint32_t *)&v));
}

typedef struct _FD788_IRQEnable {
	uint32_t io0IRQ : 1;
	uint32_t _unused0201 : 2;
	uint32_t io1IRQ : 1;
	uint32_t _unused0504 : 2;
	uint32_t io2IRQ : 1;
	uint32_t _unused0807 : 2;
	uint32_t io3IRQ : 1;
	uint32_t _unused1110 : 2;
	uint32_t io4IRQ : 1;
	uint32_t _unused1413 : 2;
	uint32_t io5IRQ : 1;
	uint32_t _unused1716 : 2;
	uint32_t io6IRQ : 1;
	uint32_t _unused2019 : 2;
	uint32_t io7IRQ : 1;
	uint32_t _unused2322 : 2;
	uint32_t sync0IRQ : 1;
	uint32_t _unused2525 : 1;
	uint32_t sync1IRQ : 1;
	uint32_t _unused2727 : 1;
	uint32_t sync2IRQ : 1;
	uint32_t _unused2929 : 1;
	uint32_t sync3IRQ : 1;
	uint32_t _unused3131 : 1;
} __attribute__((packed)) FD788_IRQEnable;

#define FD788_IRQEnable_A (0x04)

FD788_IRQEnable __always_inline FD788_IRQEnable_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_IRQEnable_A);
	return *((FD788_IRQEnable *)&r);
}

void __always_inline FD788_IRQEnable_W(uint32_t *csr, FD788_IRQEnable v)
{
	__write_reg(csr, FD788_IRQEnable_A, *((uint32_t *)&v));
}

typedef struct _FD788_IRQFlags {
	uint32_t io0IRQ : 1;
	uint32_t io0Buffer : 2;
	uint32_t io1IRQ : 1;
	uint32_t io1Buffer : 2;
	uint32_t io2IRQ : 1;
	uint32_t io2Buffer : 2;
	uint32_t io3IRQ : 1;
	uint32_t io3Buffer : 2;
	uint32_t io4IRQ : 1;
	uint32_t io4Buffer : 2;
	uint32_t io5IRQ : 1;
	uint32_t io5Buffer : 2;
	uint32_t io6IRQ : 1;
	uint32_t io6Buffer : 2;
	uint32_t io7IRQ : 1;
	uint32_t io7Buffer : 2;
	uint32_t sync0IRQ : 1;
	uint32_t sync0Field : 1;
	uint32_t sync1IRQ : 1;
	uint32_t sync1Field : 1;
	uint32_t sync2IRQ : 1;
	uint32_t sync2Field : 1;
	uint32_t sync3IRQ : 1;
	uint32_t sync3Field : 1;
} __attribute__((packed)) FD788_IRQFlags;

#define FD788_IRQFlags_A (0x05)

FD788_IRQFlags __always_inline FD788_IRQFlags_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_IRQFlags_A);
	return *((FD788_IRQFlags *)&r);
}

void __always_inline FD788_IRQFlags_W(uint32_t *csr, FD788_IRQFlags v)
{
	__write_reg(csr, FD788_IRQFlags_A, *((uint32_t *)&v));
}

typedef struct _FD788_AnalogSync {
	uint32_t hsync : 11;
	uint32_t vsync : 20;
	uint32_t _unused3131 : 1;
} __attribute__((packed)) FD788_AnalogSync;

#define FD788_AnalogSync_A (0x06)

FD788_AnalogSync __always_inline FD788_AnalogSync_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_AnalogSync_A);
	return *((FD788_AnalogSync *)&r);
}

typedef struct _FD788_Genlock {
	uint32_t mode : 2;
	uint32_t lock : 1;
	uint32_t _unused0803 : 6;
	uint32_t offset : 23;
} __attribute__((packed)) FD788_Genlock;

#define FD788_Genlock_A (0x07)

FD788_Genlock __always_inline FD788_Genlock_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_Genlock_A);
	return *((FD788_Genlock *)&r);
}

void __always_inline FD788_Genlock_W(uint32_t *csr, FD788_Genlock v)
{
	__write_reg(csr, FD788_Genlock_A, *((uint32_t *)&v));
}

typedef struct _FD788_SyncGenerator {
	uint32_t frameSize : 23;
	uint32_t _unused3023 : 8;
	uint32_t sync : 1;
} __attribute__((packed)) FD788_SyncGenerator;

#define FD788_SyncGenerator_A(n) (0x08 + n * 4)

FD788_SyncGenerator __always_inline FD788_SyncGenerator_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_SyncGenerator_A(n));
	return *((FD788_SyncGenerator *)&r);
}

void __always_inline FD788_SyncGenerator_W(uint32_t *csr, unsigned int n, FD788_SyncGenerator v)
{
	__write_reg(csr, FD788_SyncGenerator_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_SyncGeneratorField {
	uint32_t fieldSize : 23;
	uint32_t _unused3123 : 9;
} __attribute__((packed)) FD788_SyncGeneratorField;

#define FD788_SyncGeneratorField_A(n) (0x09 + n * 4)

FD788_SyncGeneratorField __always_inline FD788_SyncGeneratorField_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_SyncGeneratorField_A(n));
	return *((FD788_SyncGeneratorField *)&r);
}

void __always_inline FD788_SyncGeneratorField_W(uint32_t *csr, unsigned int n,
						FD788_SyncGeneratorField v)
{
	__write_reg(csr, FD788_SyncGeneratorField_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_SyncGeneratorTime {
	uint32_t time : 32;
} __attribute__((packed)) FD788_SyncGeneratorTime;

#define FD788_SyncGeneratorTime_A(n) (0x0A + n * 4)

FD788_SyncGeneratorTime __always_inline FD788_SyncGeneratorTime_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_SyncGeneratorTime_A(n));
	return *((FD788_SyncGeneratorTime *)&r);
}

typedef struct _FD788_SyncGeneratorPhase {
	uint32_t phase : 23;
	uint32_t _unused3123 : 9;
} __attribute__((packed)) FD788_SyncGeneratorPhase;

#define FD788_SyncGeneratorPhase_A(n) (0x0B + n * 4)

void __always_inline FD788_SyncGeneratorPhase_W(uint32_t *csr, unsigned int n,
						FD788_SyncGeneratorPhase v)
{
	__write_reg(csr, FD788_SyncGeneratorPhase_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_PCIEPerfomance {
	uint32_t txCounter : 16;
	uint32_t rxCounter : 16;
} __attribute__((packed)) FD788_PCIEPerfomance;

#define FD788_PCIEPerfomance_A (0x18)

FD788_PCIEPerfomance __always_inline FD788_PCIEPerfomance_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_PCIEPerfomance_A);
	return *((FD788_PCIEPerfomance *)&r);
}

typedef struct _FD788_Video4KSwitch {
	uint32_t qi0 : 2;
	uint32_t qi1 : 2;
	uint32_t qi2 : 2;
	uint32_t qi3 : 2;
	uint32_t di0 : 2;
	uint32_t di1 : 2;
	uint32_t _unused1512 : 4;
	uint32_t qo0 : 2;
	uint32_t qo1 : 2;
	uint32_t qo2 : 2;
	uint32_t qo3 : 2;
	uint32_t do0 : 2;
	uint32_t do1 : 2;
	uint32_t _unused3128 : 4;
} __attribute__((packed)) FD788_Video4KSwitch;

#define FD788_Video4KSwitch_A (0x19)

FD788_Video4KSwitch __always_inline FD788_Video4KSwitch_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_Video4KSwitch_A);
	return *((FD788_Video4KSwitch *)&r);
}

void __always_inline FD788_Video4KSwitch_W(uint32_t *csr, FD788_Video4KSwitch v)
{
	__write_reg(csr, FD788_Video4KSwitch_A, *((uint32_t *)&v));
}

typedef struct _FD788_PCIERxMaxLatency {
	uint32_t maxLatency : 16;
	uint32_t numRequests : 16;
} __attribute__((packed)) FD788_PCIERxMaxLatency;

#define FD788_PCIERxMaxLatency_A (0x1B)

FD788_PCIERxMaxLatency __always_inline FD788_PCIERxMaxLatency_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_PCIERxMaxLatency_A);
	return *((FD788_PCIERxMaxLatency *)&r);
}

typedef struct _FD788_PCIERxTotalLatency {
	uint32_t latency : 32;
} __attribute__((packed)) FD788_PCIERxTotalLatency;

#define FD788_PCIERxTotalLatency_A (0x1C)

FD788_PCIERxTotalLatency __always_inline FD788_PCIERxTotalLatency_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_PCIERxTotalLatency_A);
	return *((FD788_PCIERxTotalLatency *)&r);
}

typedef struct _FD788_AnalogVSyncTime {
	uint32_t time : 32;
} __attribute__((packed)) FD788_AnalogVSyncTime;

#define FD788_AnalogVSyncTime_A (0x1D)

FD788_AnalogVSyncTime __always_inline FD788_AnalogVSyncTime_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_AnalogVSyncTime_A);
	return *((FD788_AnalogVSyncTime *)&r);
}

typedef struct _FD788_DynamicVersion {
	uint32_t revision : 16;
	uint32_t minor : 8;
	uint32_t hardware : 4;
	uint32_t project : 4;
} __attribute__((packed)) FD788_DynamicVersion;

#define FD788_DynamicVersion_A (0x3F)

FD788_DynamicVersion __always_inline FD788_DynamicVersion_R(uint32_t *csr)
{
	uint32_t r = __read_reg(csr, FD788_DynamicVersion_A);
	return *((FD788_DynamicVersion *)&r);
}

typedef struct _FD788_VideoInCS {
	uint32_t cd : 1;
	uint32_t modeLocked : 1;
	uint32_t levelB : 1;
	uint32_t mode : 2;
	uint32_t reset : 1;
	uint32_t formatLocked : 1;
	uint32_t progressive : 1;
	uint32_t forceMode : 1;
	uint32_t _unused0909 : 1;
	uint32_t capture : 1;
	uint32_t captureRaw : 1;
	uint32_t vbiTop : 1;
	uint32_t vbiBottom : 1;
	uint32_t vis10b : 1;
	uint32_t vbi10b : 1;
	uint32_t ycSwap : 1;
	uint32_t asiPeriod : 2;
	uint32_t _unused2518 : 7;
	uint32_t vancCapture : 1;
	uint32_t dqLocked : 1;
	uint32_t dqQuad : 1;
	uint32_t dqEnable : 1;
	uint32_t _unused3030 : 1;
	uint32_t test : 1;
} __attribute__((packed)) FD788_VideoInCS;

#define FD788_VideoInCS_A(n) (0x40 + n * 16)

FD788_VideoInCS __always_inline FD788_VideoInCS_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInCS_A(n));
	return *((FD788_VideoInCS *)&r);
}

void __always_inline FD788_VideoInCS_W(uint32_t *csr, unsigned int n, FD788_VideoInCS v)
{
	__write_reg(csr, FD788_VideoInCS_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoInLine {
	uint32_t totalLines : 12;
	uint32_t _unused1512 : 4;
	uint32_t activeLines : 12;
	uint32_t _unused3128 : 4;
} __attribute__((packed)) FD788_VideoInLine;

#define FD788_VideoInLine_A(n) (0x41 + n * 16)

FD788_VideoInLine __always_inline FD788_VideoInLine_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInLine_A(n));
	return *((FD788_VideoInLine *)&r);
}

typedef struct _FD788_VideoInPixel {
	uint32_t totalPixels : 13;
	uint32_t _unused1513 : 3;
	uint32_t activePixels : 13;
	uint32_t _unused3129 : 3;
} __attribute__((packed)) FD788_VideoInPixel;

#define FD788_VideoInPixel_A(n) (0x42 + n * 16)

FD788_VideoInPixel __always_inline FD788_VideoInPixel_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInPixel_A(n));
	return *((FD788_VideoInPixel *)&r);
}

typedef struct _FD788_VideoInIRQRefTime {
	uint32_t time : 32;
} __attribute__((packed)) FD788_VideoInIRQRefTime;

#define FD788_VideoInIRQRefTime_A(n) (0x44 + n * 16)

FD788_VideoInIRQRefTime __always_inline FD788_VideoInIRQRefTime_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInIRQRefTime_A(n));
	return *((FD788_VideoInIRQRefTime *)&r);
}

typedef struct _FD788_VideoInANCCounter {
	uint32_t counter : 20;
	uint32_t _unused3120 : 12;
} __attribute__((packed)) FD788_VideoInANCCounter;

#define FD788_VideoInANCCounter_A(n) (0x46 + n * 16)

FD788_VideoInANCCounter __always_inline FD788_VideoInANCCounter_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInANCCounter_A(n));
	return *((FD788_VideoInANCCounter *)&r);
}

typedef struct _FD788_VideoInVPID {
	uint32_t vpid : 32;
} __attribute__((packed)) FD788_VideoInVPID;

#define FD788_VideoInVPID_A(n) (0x47 + n * 16)

FD788_VideoInVPID __always_inline FD788_VideoInVPID_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInVPID_A(n));
	return *((FD788_VideoInVPID *)&r);
}

typedef struct _FD788_VideoInFrameSize {
	uint32_t size : 21;
	uint32_t _unused3121 : 11;
} __attribute__((packed)) FD788_VideoInFrameSize;

#define FD788_VideoInFrameSize_A(n) (0x48 + n * 16)

FD788_VideoInFrameSize __always_inline FD788_VideoInFrameSize_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInFrameSize_A(n));
	return *((FD788_VideoInFrameSize *)&r);
}

typedef struct _FD788_VideoInFIFOStatus {
	uint32_t videoMax : 15;
	uint32_t videoError : 1;
	uint32_t audioMax : 15;
	uint32_t audioError : 1;
} __attribute__((packed)) FD788_VideoInFIFOStatus;

#define FD788_VideoInFIFOStatus_A(n) (0x4A + n * 16)

FD788_VideoInFIFOStatus __always_inline FD788_VideoInFIFOStatus_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoInFIFOStatus_A(n));
	return *((FD788_VideoInFIFOStatus *)&r);
}

typedef struct _FD788_VideoOutCS {
	uint32_t reset : 1;
	uint32_t _unused0101 : 1;
	uint32_t levelB : 1;
	uint32_t mode : 2;
	uint32_t clockM : 1;
	uint32_t freeRunning : 1;
	uint32_t progressive : 1;
	uint32_t audioCount : 2;
	uint32_t playback : 1;
	uint32_t playbackRaw : 1;
	uint32_t vbiTop : 1;
	uint32_t vbiBottom : 1;
	uint32_t vis10b : 1;
	uint32_t vbi10b : 1;
	uint32_t dataPresent : 1;
	uint32_t syncSource : 2;
	uint32_t atcEnable : 1;
	uint32_t atcType : 2;
	uint32_t _unused2722 : 6;
	uint32_t dqQuad : 1;
	uint32_t dqEnable : 1;
	uint32_t clone : 1;
	uint32_t test : 1;
} __attribute__((packed)) FD788_VideoOutCS;

#define FD788_VideoOutCS_A(n) (0x40 + n * 16)

FD788_VideoOutCS __always_inline FD788_VideoOutCS_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutCS_A(n));
	return *((FD788_VideoOutCS *)&r);
}

void __always_inline FD788_VideoOutCS_W(uint32_t *csr, unsigned int n, FD788_VideoOutCS v)
{
	__write_reg(csr, FD788_VideoOutCS_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutLine {
	uint32_t totalLines : 12;
	uint32_t _unused3112 : 20;
} __attribute__((packed)) FD788_VideoOutLine;

#define FD788_VideoOutLine_A(n) (0x41 + n * 16)

FD788_VideoOutLine __always_inline FD788_VideoOutLine_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutLine_A(n));
	return *((FD788_VideoOutLine *)&r);
}

void __always_inline FD788_VideoOutLine_W(uint32_t *csr, unsigned int n, FD788_VideoOutLine v)
{
	__write_reg(csr, FD788_VideoOutLine_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutPixel {
	uint32_t totalPixels : 13;
	uint32_t _unused1513 : 3;
	uint32_t activePixels : 13;
	uint32_t _unused3129 : 3;
} __attribute__((packed)) FD788_VideoOutPixel;

#define FD788_VideoOutPixel_A(n) (0x42 + n * 16)

FD788_VideoOutPixel __always_inline FD788_VideoOutPixel_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutPixel_A(n));
	return *((FD788_VideoOutPixel *)&r);
}

void __always_inline FD788_VideoOutPixel_W(uint32_t *csr, unsigned int n, FD788_VideoOutPixel v)
{
	__write_reg(csr, FD788_VideoOutPixel_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutStart {
	uint32_t startOdd : 12;
	uint32_t _unused1512 : 4;
	uint32_t startEven : 12;
	uint32_t _unused3128 : 4;
} __attribute__((packed)) FD788_VideoOutStart;

#define FD788_VideoOutStart_A(n) (0x43 + n * 16)

FD788_VideoOutStart __always_inline FD788_VideoOutStart_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutStart_A(n));
	return *((FD788_VideoOutStart *)&r);
}

void __always_inline FD788_VideoOutStart_W(uint32_t *csr, unsigned int n, FD788_VideoOutStart v)
{
	__write_reg(csr, FD788_VideoOutStart_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutStop {
	uint32_t stopOdd : 12;
	uint32_t _unused1512 : 4;
	uint32_t stopEven : 12;
	uint32_t _unused3128 : 4;
} __attribute__((packed)) FD788_VideoOutStop;

#define FD788_VideoOutStop_A(n) (0x44 + n * 16)

FD788_VideoOutStop __always_inline FD788_VideoOutStop_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutStop_A(n));
	return *((FD788_VideoOutStop *)&r);
}

void __always_inline FD788_VideoOutStop_W(uint32_t *csr, unsigned int n, FD788_VideoOutStop v)
{
	__write_reg(csr, FD788_VideoOutStop_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutField {
	uint32_t switchOdd : 12;
	uint32_t _unused1512 : 4;
	uint32_t switchEven : 12;
	uint32_t _unused3128 : 4;
} __attribute__((packed)) FD788_VideoOutField;

#define FD788_VideoOutField_A(n) (0x45 + n * 16)

FD788_VideoOutField __always_inline FD788_VideoOutField_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutField_A(n));
	return *((FD788_VideoOutField *)&r);
}

void __always_inline FD788_VideoOutField_W(uint32_t *csr, unsigned int n, FD788_VideoOutField v)
{
	__write_reg(csr, FD788_VideoOutField_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutAudio {
	uint32_t address : 20;
	uint32_t _unused3120 : 12;
} __attribute__((packed)) FD788_VideoOutAudio;

#define FD788_VideoOutAudio_A(n) (0x46 + n * 16)

FD788_VideoOutAudio __always_inline FD788_VideoOutAudio_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutAudio_A(n));
	return *((FD788_VideoOutAudio *)&r);
}

void __always_inline FD788_VideoOutAudio_W(uint32_t *csr, unsigned int n, FD788_VideoOutAudio v)
{
	__write_reg(csr, FD788_VideoOutAudio_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutVPID {
	uint32_t vpid : 32;
} __attribute__((packed)) FD788_VideoOutVPID;

#define FD788_VideoOutVPID_A(n) (0x47 + n * 16)

FD788_VideoOutVPID __always_inline FD788_VideoOutVPID_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutVPID_A(n));
	return *((FD788_VideoOutVPID *)&r);
}

void __always_inline FD788_VideoOutVPID_W(uint32_t *csr, unsigned int n, FD788_VideoOutVPID v)
{
	__write_reg(csr, FD788_VideoOutVPID_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutOddDataCount {
	uint32_t count : 24;
	uint32_t _unused3124 : 8;
} __attribute__((packed)) FD788_VideoOutOddDataCount;

#define FD788_VideoOutOddDataCount_A(n) (0x48 + n * 16)

FD788_VideoOutOddDataCount __always_inline FD788_VideoOutOddDataCount_R(uint32_t *csr,
									unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutOddDataCount_A(n));
	return *((FD788_VideoOutOddDataCount *)&r);
}

void __always_inline FD788_VideoOutOddDataCount_W(uint32_t *csr, unsigned int n,
						  FD788_VideoOutOddDataCount v)
{
	__write_reg(csr, FD788_VideoOutOddDataCount_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutEvenDataCount {
	uint32_t count : 24;
	uint32_t _unused3124 : 8;
} __attribute__((packed)) FD788_VideoOutEvenDataCount;

#define FD788_VideoOutEvenDataCount_A(n) (0x49 + n * 16)

FD788_VideoOutEvenDataCount __always_inline FD788_VideoOutEvenDataCount_R(uint32_t *csr,
									  unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutEvenDataCount_A(n));
	return *((FD788_VideoOutEvenDataCount *)&r);
}

void __always_inline FD788_VideoOutEvenDataCount_W(uint32_t *csr, unsigned int n,
						   FD788_VideoOutEvenDataCount v)
{
	__write_reg(csr, FD788_VideoOutEvenDataCount_A(n), *((uint32_t *)&v));
}

typedef struct _FD788_VideoOutFIFOStatus {
	uint32_t videoMin : 15;
	uint32_t videoError : 1;
	uint32_t audioMin : 15;
	uint32_t audioError : 1;
} __attribute__((packed)) FD788_VideoOutFIFOStatus;

#define FD788_VideoOutFIFOStatus_A(n) (0x4A + n * 16)

FD788_VideoOutFIFOStatus __always_inline FD788_VideoOutFIFOStatus_R(uint32_t *csr, unsigned int n)
{
	uint32_t r = __read_reg(csr, FD788_VideoOutFIFOStatus_A(n));
	return *((FD788_VideoOutFIFOStatus *)&r);
}

#define FD788_VideoOutATC_A(n) (0x4B + n * 16)

#endif
