18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * cobalt driver internal defines and structures 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Derived from cx18-driver.h 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates. 88c2ecf20Sopenharmony_ci * All rights reserved. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef COBALT_DRIVER_H 128c2ecf20Sopenharmony_ci#define COBALT_DRIVER_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/bitops.h> 158c2ecf20Sopenharmony_ci#include <linux/module.h> 168c2ecf20Sopenharmony_ci#include <linux/pci.h> 178c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 188c2ecf20Sopenharmony_ci#include <linux/i2c.h> 198c2ecf20Sopenharmony_ci#include <linux/list.h> 208c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 218c2ecf20Sopenharmony_ci#include <linux/mutex.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include <media/v4l2-common.h> 248c2ecf20Sopenharmony_ci#include <media/v4l2-ioctl.h> 258c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 268c2ecf20Sopenharmony_ci#include <media/v4l2-fh.h> 278c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h> 288c2ecf20Sopenharmony_ci#include <media/videobuf2-dma-sg.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include "m00233_video_measure_memmap_package.h" 318c2ecf20Sopenharmony_ci#include "m00235_fdma_packer_memmap_package.h" 328c2ecf20Sopenharmony_ci#include "m00389_cvi_memmap_package.h" 338c2ecf20Sopenharmony_ci#include "m00460_evcnt_memmap_package.h" 348c2ecf20Sopenharmony_ci#include "m00473_freewheel_memmap_package.h" 358c2ecf20Sopenharmony_ci#include "m00479_clk_loss_detector_memmap_package.h" 368c2ecf20Sopenharmony_ci#include "m00514_syncgen_flow_evcnt_memmap_package.h" 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* System device ID */ 398c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COBALT 0x2732 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* Number of cobalt device nodes. */ 428c2ecf20Sopenharmony_ci#define COBALT_NUM_INPUTS 4 438c2ecf20Sopenharmony_ci#define COBALT_NUM_NODES 6 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Number of cobalt device streams. */ 468c2ecf20Sopenharmony_ci#define COBALT_NUM_STREAMS 12 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define COBALT_HSMA_IN_NODE 4 498c2ecf20Sopenharmony_ci#define COBALT_HSMA_OUT_NODE 5 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* Cobalt audio streams */ 528c2ecf20Sopenharmony_ci#define COBALT_AUDIO_IN_STREAM 6 538c2ecf20Sopenharmony_ci#define COBALT_AUDIO_OUT_STREAM 11 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* DMA stuff */ 568c2ecf20Sopenharmony_ci#define DMA_CHANNELS_MAX 16 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* i2c stuff */ 598c2ecf20Sopenharmony_ci#define I2C_CLIENTS_MAX 16 608c2ecf20Sopenharmony_ci#define COBALT_NUM_ADAPTERS 5 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define COBALT_CLK 50000000 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* System status register */ 658c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_DIP0_MSK BIT(0) 668c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_DIP1_MSK BIT(1) 678c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_HSMA_PRSNTN_MSK BIT(2) 688c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_FLASH_RDYBSYN_MSK BIT(3) 698c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI0_5V_MSK BIT(4) 708c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI0_INT1_MSK BIT(5) 718c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI0_INT2_MSK BIT(6) 728c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI0_LOST_DATA_MSK BIT(7) 738c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI1_5V_MSK BIT(8) 748c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI1_INT1_MSK BIT(9) 758c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI1_INT2_MSK BIT(10) 768c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI1_LOST_DATA_MSK BIT(11) 778c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI2_5V_MSK BIT(12) 788c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI2_INT1_MSK BIT(13) 798c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI2_INT2_MSK BIT(14) 808c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI2_LOST_DATA_MSK BIT(15) 818c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI3_5V_MSK BIT(16) 828c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI3_INT1_MSK BIT(17) 838c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI3_INT2_MSK BIT(18) 848c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VI3_LOST_DATA_MSK BIT(19) 858c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VIHSMA_5V_MSK BIT(20) 868c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VIHSMA_INT1_MSK BIT(21) 878c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VIHSMA_INT2_MSK BIT(22) 888c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VIHSMA_LOST_DATA_MSK BIT(23) 898c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VOHSMA_INT1_MSK BIT(24) 908c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VOHSMA_PLL_LOCKED_MSK BIT(25) 918c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK BIT(26) 928c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_AUD_PLL_LOCKED_MSK BIT(28) 938c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK BIT(29) 948c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK BIT(30) 958c2ecf20Sopenharmony_ci#define COBALT_SYSSTAT_PCIE_SMBCLK_MSK BIT(31) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* Cobalt memory map */ 988c2ecf20Sopenharmony_ci#define COBALT_I2C_0_BASE 0x0 998c2ecf20Sopenharmony_ci#define COBALT_I2C_1_BASE 0x080 1008c2ecf20Sopenharmony_ci#define COBALT_I2C_2_BASE 0x100 1018c2ecf20Sopenharmony_ci#define COBALT_I2C_3_BASE 0x180 1028c2ecf20Sopenharmony_ci#define COBALT_I2C_HSMA_BASE 0x200 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_BASE 0x400 1058c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT 1 1068c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(n) (4 + 4 * (n)) 1078c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(n) (5 + 4 * (n)) 1088c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(n) (6 + 4 * (n)) 1098c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_AUDIO_IPP_RESETN_BIT(n) (7 + 4 * (n)) 1108c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_PWRDN0_TO_HSMA_TX_BIT 24 1118c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_VIDEO_TX_RESETN_BIT 25 1128c2ecf20Sopenharmony_ci#define COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT 27 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#define COBALT_SYS_STAT_BASE 0x500 1158c2ecf20Sopenharmony_ci#define COBALT_SYS_STAT_MASK (COBALT_SYS_STAT_BASE + 0x08) 1168c2ecf20Sopenharmony_ci#define COBALT_SYS_STAT_EDGE (COBALT_SYS_STAT_BASE + 0x0c) 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#define COBALT_HDL_INFO_BASE 0x4800 1198c2ecf20Sopenharmony_ci#define COBALT_HDL_INFO_SIZE 0x200 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define COBALT_VID_BASE 0x10000 1228c2ecf20Sopenharmony_ci#define COBALT_VID_SIZE 0x1000 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define COBALT_CVI(cobalt, c) \ 1258c2ecf20Sopenharmony_ci (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE) 1268c2ecf20Sopenharmony_ci#define COBALT_CVI_VMR(cobalt, c) \ 1278c2ecf20Sopenharmony_ci (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x100) 1288c2ecf20Sopenharmony_ci#define COBALT_CVI_EVCNT(cobalt, c) \ 1298c2ecf20Sopenharmony_ci (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x200) 1308c2ecf20Sopenharmony_ci#define COBALT_CVI_FREEWHEEL(cobalt, c) \ 1318c2ecf20Sopenharmony_ci (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x300) 1328c2ecf20Sopenharmony_ci#define COBALT_CVI_CLK_LOSS(cobalt, c) \ 1338c2ecf20Sopenharmony_ci (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x400) 1348c2ecf20Sopenharmony_ci#define COBALT_CVI_PACKER(cobalt, c) \ 1358c2ecf20Sopenharmony_ci (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x500) 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define COBALT_TX_BASE(cobalt) (cobalt->bar1 + COBALT_VID_BASE + 0x5000) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define DMA_INTERRUPT_STATUS_REG 0x08 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#define COBALT_HDL_SEARCH_STR "** HDL version info **" 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/* Cobalt CPU bus interface */ 1448c2ecf20Sopenharmony_ci#define COBALT_BUS_BAR1_BASE 0x600 1458c2ecf20Sopenharmony_ci#define COBALT_BUS_SRAM_BASE 0x0 1468c2ecf20Sopenharmony_ci#define COBALT_BUS_CPLD_BASE 0x00600000 1478c2ecf20Sopenharmony_ci#define COBALT_BUS_FLASH_BASE 0x08000000 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* FDMA to PCIe packing */ 1508c2ecf20Sopenharmony_ci#define COBALT_BYTES_PER_PIXEL_YUYV 2 1518c2ecf20Sopenharmony_ci#define COBALT_BYTES_PER_PIXEL_RGB24 3 1528c2ecf20Sopenharmony_ci#define COBALT_BYTES_PER_PIXEL_RGB32 4 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci/* debugging */ 1558c2ecf20Sopenharmony_ciextern int cobalt_debug; 1568c2ecf20Sopenharmony_ciextern int cobalt_ignore_err; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define cobalt_err(fmt, arg...) v4l2_err(&cobalt->v4l2_dev, fmt, ## arg) 1598c2ecf20Sopenharmony_ci#define cobalt_warn(fmt, arg...) v4l2_warn(&cobalt->v4l2_dev, fmt, ## arg) 1608c2ecf20Sopenharmony_ci#define cobalt_info(fmt, arg...) v4l2_info(&cobalt->v4l2_dev, fmt, ## arg) 1618c2ecf20Sopenharmony_ci#define cobalt_dbg(level, fmt, arg...) \ 1628c2ecf20Sopenharmony_ci v4l2_dbg(level, cobalt_debug, &cobalt->v4l2_dev, fmt, ## arg) 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistruct cobalt; 1658c2ecf20Sopenharmony_cistruct cobalt_i2c_regs; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/* Per I2C bus private algo callback data */ 1688c2ecf20Sopenharmony_cistruct cobalt_i2c_data { 1698c2ecf20Sopenharmony_ci struct cobalt *cobalt; 1708c2ecf20Sopenharmony_ci struct cobalt_i2c_regs __iomem *regs; 1718c2ecf20Sopenharmony_ci}; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistruct pci_consistent_buffer { 1748c2ecf20Sopenharmony_ci void *virt; 1758c2ecf20Sopenharmony_ci dma_addr_t bus; 1768c2ecf20Sopenharmony_ci size_t bytes; 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistruct sg_dma_desc_info { 1808c2ecf20Sopenharmony_ci void *virt; 1818c2ecf20Sopenharmony_ci dma_addr_t bus; 1828c2ecf20Sopenharmony_ci unsigned size; 1838c2ecf20Sopenharmony_ci void *last_desc_virt; 1848c2ecf20Sopenharmony_ci struct device *dev; 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define COBALT_MAX_WIDTH 1920 1888c2ecf20Sopenharmony_ci#define COBALT_MAX_HEIGHT 1200 1898c2ecf20Sopenharmony_ci#define COBALT_MAX_BPP 3 1908c2ecf20Sopenharmony_ci#define COBALT_MAX_FRAMESZ \ 1918c2ecf20Sopenharmony_ci (COBALT_MAX_WIDTH * COBALT_MAX_HEIGHT * COBALT_MAX_BPP) 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define NR_BUFS VIDEO_MAX_FRAME 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#define COBALT_STREAM_FL_DMA_IRQ 0 1968c2ecf20Sopenharmony_ci#define COBALT_STREAM_FL_ADV_IRQ 1 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistruct cobalt_buffer { 1998c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer vb; 2008c2ecf20Sopenharmony_ci struct list_head list; 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic inline 2048c2ecf20Sopenharmony_cistruct cobalt_buffer *to_cobalt_buffer(struct vb2_v4l2_buffer *vb2) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci return container_of(vb2, struct cobalt_buffer, vb); 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistruct cobalt_stream { 2108c2ecf20Sopenharmony_ci struct video_device vdev; 2118c2ecf20Sopenharmony_ci struct vb2_queue q; 2128c2ecf20Sopenharmony_ci struct list_head bufs; 2138c2ecf20Sopenharmony_ci struct i2c_adapter *i2c_adap; 2148c2ecf20Sopenharmony_ci struct v4l2_subdev *sd; 2158c2ecf20Sopenharmony_ci struct mutex lock; 2168c2ecf20Sopenharmony_ci spinlock_t irqlock; 2178c2ecf20Sopenharmony_ci struct v4l2_dv_timings timings; 2188c2ecf20Sopenharmony_ci u32 input; 2198c2ecf20Sopenharmony_ci u32 pad_source; 2208c2ecf20Sopenharmony_ci u32 width, height, bpp; 2218c2ecf20Sopenharmony_ci u32 stride; 2228c2ecf20Sopenharmony_ci u32 pixfmt; 2238c2ecf20Sopenharmony_ci u32 sequence; 2248c2ecf20Sopenharmony_ci u32 colorspace; 2258c2ecf20Sopenharmony_ci u32 xfer_func; 2268c2ecf20Sopenharmony_ci u32 ycbcr_enc; 2278c2ecf20Sopenharmony_ci u32 quantization; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci u8 dma_channel; 2308c2ecf20Sopenharmony_ci int video_channel; 2318c2ecf20Sopenharmony_ci unsigned dma_fifo_mask; 2328c2ecf20Sopenharmony_ci unsigned adv_irq_mask; 2338c2ecf20Sopenharmony_ci struct sg_dma_desc_info dma_desc_info[NR_BUFS]; 2348c2ecf20Sopenharmony_ci unsigned long flags; 2358c2ecf20Sopenharmony_ci bool unstable_frame; 2368c2ecf20Sopenharmony_ci bool enable_cvi; 2378c2ecf20Sopenharmony_ci bool enable_freewheel; 2388c2ecf20Sopenharmony_ci unsigned skip_first_frames; 2398c2ecf20Sopenharmony_ci bool is_output; 2408c2ecf20Sopenharmony_ci bool is_audio; 2418c2ecf20Sopenharmony_ci bool is_dummy; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci struct cobalt *cobalt; 2448c2ecf20Sopenharmony_ci struct snd_cobalt_card *alsa; 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistruct snd_cobalt_card; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci/* Struct to hold info about cobalt cards */ 2508c2ecf20Sopenharmony_cistruct cobalt { 2518c2ecf20Sopenharmony_ci int instance; 2528c2ecf20Sopenharmony_ci struct pci_dev *pci_dev; 2538c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 2548c2ecf20Sopenharmony_ci /* serialize PCI access in cobalt_s_bit_sysctrl() */ 2558c2ecf20Sopenharmony_ci struct mutex pci_lock; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci void __iomem *bar0, *bar1; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci u8 card_rev; 2608c2ecf20Sopenharmony_ci u16 device_id; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci /* device nodes */ 2638c2ecf20Sopenharmony_ci struct cobalt_stream streams[DMA_CHANNELS_MAX]; 2648c2ecf20Sopenharmony_ci struct i2c_adapter i2c_adap[COBALT_NUM_ADAPTERS]; 2658c2ecf20Sopenharmony_ci struct cobalt_i2c_data i2c_data[COBALT_NUM_ADAPTERS]; 2668c2ecf20Sopenharmony_ci bool have_hsma_rx; 2678c2ecf20Sopenharmony_ci bool have_hsma_tx; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci /* irq */ 2708c2ecf20Sopenharmony_ci struct workqueue_struct *irq_work_queues; 2718c2ecf20Sopenharmony_ci struct work_struct irq_work_queue; /* work entry */ 2728c2ecf20Sopenharmony_ci /* irq counters */ 2738c2ecf20Sopenharmony_ci u32 irq_adv1; 2748c2ecf20Sopenharmony_ci u32 irq_adv2; 2758c2ecf20Sopenharmony_ci u32 irq_advout; 2768c2ecf20Sopenharmony_ci u32 irq_dma_tot; 2778c2ecf20Sopenharmony_ci u32 irq_dma[COBALT_NUM_STREAMS]; 2788c2ecf20Sopenharmony_ci u32 irq_none; 2798c2ecf20Sopenharmony_ci u32 irq_full_fifo; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* omnitek dma */ 2828c2ecf20Sopenharmony_ci int dma_channels; 2838c2ecf20Sopenharmony_ci int first_fifo_channel; 2848c2ecf20Sopenharmony_ci bool pci_32_bit; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci char hdl_info[COBALT_HDL_INFO_SIZE]; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci /* NOR flash */ 2898c2ecf20Sopenharmony_ci struct mtd_info *mtd; 2908c2ecf20Sopenharmony_ci}; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_cistatic inline struct cobalt *to_cobalt(struct v4l2_device *v4l2_dev) 2938c2ecf20Sopenharmony_ci{ 2948c2ecf20Sopenharmony_ci return container_of(v4l2_dev, struct cobalt, v4l2_dev); 2958c2ecf20Sopenharmony_ci} 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_cistatic inline void cobalt_write_bar0(struct cobalt *cobalt, u32 reg, u32 val) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci iowrite32(val, cobalt->bar0 + reg); 3008c2ecf20Sopenharmony_ci} 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_cistatic inline u32 cobalt_read_bar0(struct cobalt *cobalt, u32 reg) 3038c2ecf20Sopenharmony_ci{ 3048c2ecf20Sopenharmony_ci return ioread32(cobalt->bar0 + reg); 3058c2ecf20Sopenharmony_ci} 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_cistatic inline void cobalt_write_bar1(struct cobalt *cobalt, u32 reg, u32 val) 3088c2ecf20Sopenharmony_ci{ 3098c2ecf20Sopenharmony_ci iowrite32(val, cobalt->bar1 + reg); 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistatic inline u32 cobalt_read_bar1(struct cobalt *cobalt, u32 reg) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci return ioread32(cobalt->bar1 + reg); 3158c2ecf20Sopenharmony_ci} 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_cistatic inline u32 cobalt_g_sysctrl(struct cobalt *cobalt) 3188c2ecf20Sopenharmony_ci{ 3198c2ecf20Sopenharmony_ci return cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE); 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistatic inline void cobalt_s_bit_sysctrl(struct cobalt *cobalt, 3238c2ecf20Sopenharmony_ci int bit, int val) 3248c2ecf20Sopenharmony_ci{ 3258c2ecf20Sopenharmony_ci u32 ctrl; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci mutex_lock(&cobalt->pci_lock); 3288c2ecf20Sopenharmony_ci ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE); 3298c2ecf20Sopenharmony_ci cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE, 3308c2ecf20Sopenharmony_ci (ctrl & ~(1UL << bit)) | (val << bit)); 3318c2ecf20Sopenharmony_ci mutex_unlock(&cobalt->pci_lock); 3328c2ecf20Sopenharmony_ci} 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_cistatic inline u32 cobalt_g_sysstat(struct cobalt *cobalt) 3358c2ecf20Sopenharmony_ci{ 3368c2ecf20Sopenharmony_ci return cobalt_read_bar1(cobalt, COBALT_SYS_STAT_BASE); 3378c2ecf20Sopenharmony_ci} 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci#define ADRS_REG (bar1 + COBALT_BUS_BAR1_BASE + 0) 3408c2ecf20Sopenharmony_ci#define LOWER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 4) 3418c2ecf20Sopenharmony_ci#define UPPER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 6) 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_cistatic inline u32 cobalt_bus_read32(void __iomem *bar1, u32 bus_adrs) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci iowrite32(bus_adrs, ADRS_REG); 3468c2ecf20Sopenharmony_ci return ioread32(LOWER_DATA); 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistatic inline void cobalt_bus_write16(void __iomem *bar1, 3508c2ecf20Sopenharmony_ci u32 bus_adrs, u16 data) 3518c2ecf20Sopenharmony_ci{ 3528c2ecf20Sopenharmony_ci iowrite32(bus_adrs, ADRS_REG); 3538c2ecf20Sopenharmony_ci if (bus_adrs & 2) 3548c2ecf20Sopenharmony_ci iowrite16(data, UPPER_DATA); 3558c2ecf20Sopenharmony_ci else 3568c2ecf20Sopenharmony_ci iowrite16(data, LOWER_DATA); 3578c2ecf20Sopenharmony_ci} 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_cistatic inline void cobalt_bus_write32(void __iomem *bar1, 3608c2ecf20Sopenharmony_ci u32 bus_adrs, u16 data) 3618c2ecf20Sopenharmony_ci{ 3628c2ecf20Sopenharmony_ci iowrite32(bus_adrs, ADRS_REG); 3638c2ecf20Sopenharmony_ci if (bus_adrs & 2) 3648c2ecf20Sopenharmony_ci iowrite32(data, UPPER_DATA); 3658c2ecf20Sopenharmony_ci else 3668c2ecf20Sopenharmony_ci iowrite32(data, LOWER_DATA); 3678c2ecf20Sopenharmony_ci} 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci/*==============Prototypes==================*/ 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_civoid cobalt_pcie_status_show(struct cobalt *cobalt); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci#endif 374