162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Xilinx Video Timing Controller 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2013-2015 Ideas on Board 662306a36Sopenharmony_ci * Copyright (C) 2013-2015 Xilinx, Inc. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Contacts: Hyun Kwon <hyun.kwon@xilinx.com> 962306a36Sopenharmony_ci * Laurent Pinchart <laurent.pinchart@ideasonboard.com> 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/clk.h> 1362306a36Sopenharmony_ci#include <linux/module.h> 1462306a36Sopenharmony_ci#include <linux/of.h> 1562306a36Sopenharmony_ci#include <linux/platform_device.h> 1662306a36Sopenharmony_ci#include <linux/slab.h> 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#include "xilinx-vip.h" 1962306a36Sopenharmony_ci#include "xilinx-vtc.h" 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define XVTC_CONTROL_FIELD_ID_POL_SRC (1 << 26) 2262306a36Sopenharmony_ci#define XVTC_CONTROL_ACTIVE_CHROMA_POL_SRC (1 << 25) 2362306a36Sopenharmony_ci#define XVTC_CONTROL_ACTIVE_VIDEO_POL_SRC (1 << 24) 2462306a36Sopenharmony_ci#define XVTC_CONTROL_HSYNC_POL_SRC (1 << 23) 2562306a36Sopenharmony_ci#define XVTC_CONTROL_VSYNC_POL_SRC (1 << 22) 2662306a36Sopenharmony_ci#define XVTC_CONTROL_HBLANK_POL_SRC (1 << 21) 2762306a36Sopenharmony_ci#define XVTC_CONTROL_VBLANK_POL_SRC (1 << 20) 2862306a36Sopenharmony_ci#define XVTC_CONTROL_CHROMA_SRC (1 << 18) 2962306a36Sopenharmony_ci#define XVTC_CONTROL_VBLANK_HOFF_SRC (1 << 17) 3062306a36Sopenharmony_ci#define XVTC_CONTROL_VSYNC_END_SRC (1 << 16) 3162306a36Sopenharmony_ci#define XVTC_CONTROL_VSYNC_START_SRC (1 << 15) 3262306a36Sopenharmony_ci#define XVTC_CONTROL_ACTIVE_VSIZE_SRC (1 << 14) 3362306a36Sopenharmony_ci#define XVTC_CONTROL_FRAME_VSIZE_SRC (1 << 13) 3462306a36Sopenharmony_ci#define XVTC_CONTROL_HSYNC_END_SRC (1 << 11) 3562306a36Sopenharmony_ci#define XVTC_CONTROL_HSYNC_START_SRC (1 << 10) 3662306a36Sopenharmony_ci#define XVTC_CONTROL_ACTIVE_HSIZE_SRC (1 << 9) 3762306a36Sopenharmony_ci#define XVTC_CONTROL_FRAME_HSIZE_SRC (1 << 8) 3862306a36Sopenharmony_ci#define XVTC_CONTROL_SYNC_ENABLE (1 << 5) 3962306a36Sopenharmony_ci#define XVTC_CONTROL_DET_ENABLE (1 << 3) 4062306a36Sopenharmony_ci#define XVTC_CONTROL_GEN_ENABLE (1 << 2) 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#define XVTC_STATUS_FSYNC(n) ((n) << 16) 4362306a36Sopenharmony_ci#define XVTC_STATUS_GEN_ACTIVE_VIDEO (1 << 13) 4462306a36Sopenharmony_ci#define XVTC_STATUS_GEN_VBLANK (1 << 12) 4562306a36Sopenharmony_ci#define XVTC_STATUS_DET_ACTIVE_VIDEO (1 << 11) 4662306a36Sopenharmony_ci#define XVTC_STATUS_DET_VBLANK (1 << 10) 4762306a36Sopenharmony_ci#define XVTC_STATUS_LOCK_LOSS (1 << 9) 4862306a36Sopenharmony_ci#define XVTC_STATUS_LOCK (1 << 8) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define XVTC_ERROR_ACTIVE_CHROMA_LOCK (1 << 21) 5162306a36Sopenharmony_ci#define XVTC_ERROR_ACTIVE_VIDEO_LOCK (1 << 20) 5262306a36Sopenharmony_ci#define XVTC_ERROR_HSYNC_LOCK (1 << 19) 5362306a36Sopenharmony_ci#define XVTC_ERROR_VSYNC_LOCK (1 << 18) 5462306a36Sopenharmony_ci#define XVTC_ERROR_HBLANK_LOCK (1 << 17) 5562306a36Sopenharmony_ci#define XVTC_ERROR_VBLANK_LOCK (1 << 16) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_FSYNC(n) ((n) << 16) 5862306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_GEN_ACTIVE_VIDEO (1 << 13) 5962306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_GEN_VBLANK (1 << 12) 6062306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_DET_ACTIVE_VIDEO (1 << 11) 6162306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_DET_VBLANK (1 << 10) 6262306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_LOCK_LOSS (1 << 9) 6362306a36Sopenharmony_ci#define XVTC_IRQ_ENABLE_LOCK (1 << 8) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* 6662306a36Sopenharmony_ci * The following registers exist in two blocks, one at 0x0020 for the detector 6762306a36Sopenharmony_ci * and one at 0x0060 for the generator. 6862306a36Sopenharmony_ci */ 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci#define XVTC_DETECTOR_OFFSET 0x0020 7162306a36Sopenharmony_ci#define XVTC_GENERATOR_OFFSET 0x0060 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#define XVTC_ACTIVE_SIZE 0x0000 7462306a36Sopenharmony_ci#define XVTC_ACTIVE_VSIZE_SHIFT 16 7562306a36Sopenharmony_ci#define XVTC_ACTIVE_VSIZE_MASK (0x1fff << 16) 7662306a36Sopenharmony_ci#define XVTC_ACTIVE_HSIZE_SHIFT 0 7762306a36Sopenharmony_ci#define XVTC_ACTIVE_HSIZE_MASK (0x1fff << 0) 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci#define XVTC_TIMING_STATUS 0x0004 8062306a36Sopenharmony_ci#define XVTC_TIMING_STATUS_ACTIVE_VIDEO (1 << 2) 8162306a36Sopenharmony_ci#define XVTC_TIMING_STATUS_VBLANK (1 << 1) 8262306a36Sopenharmony_ci#define XVTC_TIMING_STATUS_LOCKED (1 << 0) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci#define XVTC_ENCODING 0x0008 8562306a36Sopenharmony_ci#define XVTC_ENCODING_CHROMA_PARITY_SHIFT 8 8662306a36Sopenharmony_ci#define XVTC_ENCODING_CHROMA_PARITY_MASK (3 << 8) 8762306a36Sopenharmony_ci#define XVTC_ENCODING_CHROMA_PARITY_EVEN_ALL (0 << 8) 8862306a36Sopenharmony_ci#define XVTC_ENCODING_CHROMA_PARITY_ODD_ALL (1 << 8) 8962306a36Sopenharmony_ci#define XVTC_ENCODING_CHROMA_PARITY_EVEN_EVEN (2 << 8) 9062306a36Sopenharmony_ci#define XVTC_ENCODING_CHROMA_PARITY_ODD_EVEN (3 << 8) 9162306a36Sopenharmony_ci#define XVTC_ENCODING_VIDEO_FORMAT_SHIFT 0 9262306a36Sopenharmony_ci#define XVTC_ENCODING_VIDEO_FORMAT_MASK (0xf << 0) 9362306a36Sopenharmony_ci#define XVTC_ENCODING_VIDEO_FORMAT_YUV422 (0 << 0) 9462306a36Sopenharmony_ci#define XVTC_ENCODING_VIDEO_FORMAT_YUV444 (1 << 0) 9562306a36Sopenharmony_ci#define XVTC_ENCODING_VIDEO_FORMAT_RGB (2 << 0) 9662306a36Sopenharmony_ci#define XVTC_ENCODING_VIDEO_FORMAT_YUV420 (3 << 0) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define XVTC_POLARITY 0x000c 9962306a36Sopenharmony_ci#define XVTC_POLARITY_ACTIVE_CHROMA_POL (1 << 5) 10062306a36Sopenharmony_ci#define XVTC_POLARITY_ACTIVE_VIDEO_POL (1 << 4) 10162306a36Sopenharmony_ci#define XVTC_POLARITY_HSYNC_POL (1 << 3) 10262306a36Sopenharmony_ci#define XVTC_POLARITY_VSYNC_POL (1 << 2) 10362306a36Sopenharmony_ci#define XVTC_POLARITY_HBLANK_POL (1 << 1) 10462306a36Sopenharmony_ci#define XVTC_POLARITY_VBLANK_POL (1 << 0) 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#define XVTC_HSIZE 0x0010 10762306a36Sopenharmony_ci#define XVTC_HSIZE_MASK (0x1fff << 0) 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#define XVTC_VSIZE 0x0014 11062306a36Sopenharmony_ci#define XVTC_VSIZE_MASK (0x1fff << 0) 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#define XVTC_HSYNC 0x0018 11362306a36Sopenharmony_ci#define XVTC_HSYNC_END_SHIFT 16 11462306a36Sopenharmony_ci#define XVTC_HSYNC_END_MASK (0x1fff << 16) 11562306a36Sopenharmony_ci#define XVTC_HSYNC_START_SHIFT 0 11662306a36Sopenharmony_ci#define XVTC_HSYNC_START_MASK (0x1fff << 0) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci#define XVTC_F0_VBLANK_H 0x001c 11962306a36Sopenharmony_ci#define XVTC_F0_VBLANK_HEND_SHIFT 16 12062306a36Sopenharmony_ci#define XVTC_F0_VBLANK_HEND_MASK (0x1fff << 16) 12162306a36Sopenharmony_ci#define XVTC_F0_VBLANK_HSTART_SHIFT 0 12262306a36Sopenharmony_ci#define XVTC_F0_VBLANK_HSTART_MASK (0x1fff << 0) 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#define XVTC_F0_VSYNC_V 0x0020 12562306a36Sopenharmony_ci#define XVTC_F0_VSYNC_VEND_SHIFT 16 12662306a36Sopenharmony_ci#define XVTC_F0_VSYNC_VEND_MASK (0x1fff << 16) 12762306a36Sopenharmony_ci#define XVTC_F0_VSYNC_VSTART_SHIFT 0 12862306a36Sopenharmony_ci#define XVTC_F0_VSYNC_VSTART_MASK (0x1fff << 0) 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci#define XVTC_F0_VSYNC_H 0x0024 13162306a36Sopenharmony_ci#define XVTC_F0_VSYNC_HEND_SHIFT 16 13262306a36Sopenharmony_ci#define XVTC_F0_VSYNC_HEND_MASK (0x1fff << 16) 13362306a36Sopenharmony_ci#define XVTC_F0_VSYNC_HSTART_SHIFT 0 13462306a36Sopenharmony_ci#define XVTC_F0_VSYNC_HSTART_MASK (0x1fff << 0) 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#define XVTC_FRAME_SYNC_CONFIG(n) (0x0100 + 4 * (n)) 13762306a36Sopenharmony_ci#define XVTC_FRAME_SYNC_V_START_SHIFT 16 13862306a36Sopenharmony_ci#define XVTC_FRAME_SYNC_V_START_MASK (0x1fff << 16) 13962306a36Sopenharmony_ci#define XVTC_FRAME_SYNC_H_START_SHIFT 0 14062306a36Sopenharmony_ci#define XVTC_FRAME_SYNC_H_START_MASK (0x1fff << 0) 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci#define XVTC_GENERATOR_GLOBAL_DELAY 0x0104 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci/** 14562306a36Sopenharmony_ci * struct xvtc_device - Xilinx Video Timing Controller device structure 14662306a36Sopenharmony_ci * @xvip: Xilinx Video IP device 14762306a36Sopenharmony_ci * @list: entry in the global VTC list 14862306a36Sopenharmony_ci * @has_detector: the VTC has a timing detector 14962306a36Sopenharmony_ci * @has_generator: the VTC has a timing generator 15062306a36Sopenharmony_ci * @config: generator timings configuration 15162306a36Sopenharmony_ci */ 15262306a36Sopenharmony_cistruct xvtc_device { 15362306a36Sopenharmony_ci struct xvip_device xvip; 15462306a36Sopenharmony_ci struct list_head list; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci bool has_detector; 15762306a36Sopenharmony_ci bool has_generator; 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci struct xvtc_config config; 16062306a36Sopenharmony_ci}; 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_cistatic LIST_HEAD(xvtc_list); 16362306a36Sopenharmony_cistatic DEFINE_MUTEX(xvtc_lock); 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_cistatic inline void xvtc_gen_write(struct xvtc_device *xvtc, u32 addr, u32 value) 16662306a36Sopenharmony_ci{ 16762306a36Sopenharmony_ci xvip_write(&xvtc->xvip, XVTC_GENERATOR_OFFSET + addr, value); 16862306a36Sopenharmony_ci} 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci/* ----------------------------------------------------------------------------- 17162306a36Sopenharmony_ci * Generator Operations 17262306a36Sopenharmony_ci */ 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ciint xvtc_generator_start(struct xvtc_device *xvtc, 17562306a36Sopenharmony_ci const struct xvtc_config *config) 17662306a36Sopenharmony_ci{ 17762306a36Sopenharmony_ci int ret; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci if (!xvtc->has_generator) 18062306a36Sopenharmony_ci return -ENXIO; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci ret = clk_prepare_enable(xvtc->xvip.clk); 18362306a36Sopenharmony_ci if (ret < 0) 18462306a36Sopenharmony_ci return ret; 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci /* We don't care about the chroma active signal, encoding parameters are 18762306a36Sopenharmony_ci * not important for now. 18862306a36Sopenharmony_ci */ 18962306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_POLARITY, 19062306a36Sopenharmony_ci XVTC_POLARITY_ACTIVE_CHROMA_POL | 19162306a36Sopenharmony_ci XVTC_POLARITY_ACTIVE_VIDEO_POL | 19262306a36Sopenharmony_ci XVTC_POLARITY_HSYNC_POL | XVTC_POLARITY_VSYNC_POL | 19362306a36Sopenharmony_ci XVTC_POLARITY_HBLANK_POL | XVTC_POLARITY_VBLANK_POL); 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci /* Hardcode the polarity to active high, as required by the video in to 19662306a36Sopenharmony_ci * AXI4-stream core. 19762306a36Sopenharmony_ci */ 19862306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_ENCODING, 0); 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci /* Configure the timings. The VBLANK and VSYNC signals assertion and 20162306a36Sopenharmony_ci * deassertion are hardcoded to the first pixel of the line. 20262306a36Sopenharmony_ci */ 20362306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_ACTIVE_SIZE, 20462306a36Sopenharmony_ci (config->vblank_start << XVTC_ACTIVE_VSIZE_SHIFT) | 20562306a36Sopenharmony_ci (config->hblank_start << XVTC_ACTIVE_HSIZE_SHIFT)); 20662306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_HSIZE, config->hsize); 20762306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_VSIZE, config->vsize); 20862306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_HSYNC, 20962306a36Sopenharmony_ci (config->hsync_end << XVTC_HSYNC_END_SHIFT) | 21062306a36Sopenharmony_ci (config->hsync_start << XVTC_HSYNC_START_SHIFT)); 21162306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_F0_VBLANK_H, 0); 21262306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_F0_VSYNC_V, 21362306a36Sopenharmony_ci (config->vsync_end << XVTC_F0_VSYNC_VEND_SHIFT) | 21462306a36Sopenharmony_ci (config->vsync_start << XVTC_F0_VSYNC_VSTART_SHIFT)); 21562306a36Sopenharmony_ci xvtc_gen_write(xvtc, XVTC_F0_VSYNC_H, 0); 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci /* Enable the generator. Set the source of all generator parameters to 21862306a36Sopenharmony_ci * generator registers. 21962306a36Sopenharmony_ci */ 22062306a36Sopenharmony_ci xvip_write(&xvtc->xvip, XVIP_CTRL_CONTROL, 22162306a36Sopenharmony_ci XVTC_CONTROL_ACTIVE_CHROMA_POL_SRC | 22262306a36Sopenharmony_ci XVTC_CONTROL_ACTIVE_VIDEO_POL_SRC | 22362306a36Sopenharmony_ci XVTC_CONTROL_HSYNC_POL_SRC | XVTC_CONTROL_VSYNC_POL_SRC | 22462306a36Sopenharmony_ci XVTC_CONTROL_HBLANK_POL_SRC | XVTC_CONTROL_VBLANK_POL_SRC | 22562306a36Sopenharmony_ci XVTC_CONTROL_CHROMA_SRC | XVTC_CONTROL_VBLANK_HOFF_SRC | 22662306a36Sopenharmony_ci XVTC_CONTROL_VSYNC_END_SRC | XVTC_CONTROL_VSYNC_START_SRC | 22762306a36Sopenharmony_ci XVTC_CONTROL_ACTIVE_VSIZE_SRC | 22862306a36Sopenharmony_ci XVTC_CONTROL_FRAME_VSIZE_SRC | XVTC_CONTROL_HSYNC_END_SRC | 22962306a36Sopenharmony_ci XVTC_CONTROL_HSYNC_START_SRC | 23062306a36Sopenharmony_ci XVTC_CONTROL_ACTIVE_HSIZE_SRC | 23162306a36Sopenharmony_ci XVTC_CONTROL_FRAME_HSIZE_SRC | XVTC_CONTROL_GEN_ENABLE | 23262306a36Sopenharmony_ci XVIP_CTRL_CONTROL_REG_UPDATE); 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci return 0; 23562306a36Sopenharmony_ci} 23662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xvtc_generator_start); 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ciint xvtc_generator_stop(struct xvtc_device *xvtc) 23962306a36Sopenharmony_ci{ 24062306a36Sopenharmony_ci if (!xvtc->has_generator) 24162306a36Sopenharmony_ci return -ENXIO; 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci xvip_write(&xvtc->xvip, XVIP_CTRL_CONTROL, 0); 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci clk_disable_unprepare(xvtc->xvip.clk); 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci return 0; 24862306a36Sopenharmony_ci} 24962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xvtc_generator_stop); 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_cistruct xvtc_device *xvtc_of_get(struct device_node *np) 25262306a36Sopenharmony_ci{ 25362306a36Sopenharmony_ci struct device_node *xvtc_node; 25462306a36Sopenharmony_ci struct xvtc_device *found = NULL; 25562306a36Sopenharmony_ci struct xvtc_device *xvtc; 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci if (!of_property_present(np, "xlnx,vtc")) 25862306a36Sopenharmony_ci return NULL; 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci xvtc_node = of_parse_phandle(np, "xlnx,vtc", 0); 26162306a36Sopenharmony_ci if (xvtc_node == NULL) 26262306a36Sopenharmony_ci return ERR_PTR(-EINVAL); 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci mutex_lock(&xvtc_lock); 26562306a36Sopenharmony_ci list_for_each_entry(xvtc, &xvtc_list, list) { 26662306a36Sopenharmony_ci if (xvtc->xvip.dev->of_node == xvtc_node) { 26762306a36Sopenharmony_ci found = xvtc; 26862306a36Sopenharmony_ci break; 26962306a36Sopenharmony_ci } 27062306a36Sopenharmony_ci } 27162306a36Sopenharmony_ci mutex_unlock(&xvtc_lock); 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci of_node_put(xvtc_node); 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci if (!found) 27662306a36Sopenharmony_ci return ERR_PTR(-EPROBE_DEFER); 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci return found; 27962306a36Sopenharmony_ci} 28062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xvtc_of_get); 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_civoid xvtc_put(struct xvtc_device *xvtc) 28362306a36Sopenharmony_ci{ 28462306a36Sopenharmony_ci} 28562306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(xvtc_put); 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ci/* ----------------------------------------------------------------------------- 28862306a36Sopenharmony_ci * Registration and Unregistration 28962306a36Sopenharmony_ci */ 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_cistatic void xvtc_register_device(struct xvtc_device *xvtc) 29262306a36Sopenharmony_ci{ 29362306a36Sopenharmony_ci mutex_lock(&xvtc_lock); 29462306a36Sopenharmony_ci list_add_tail(&xvtc->list, &xvtc_list); 29562306a36Sopenharmony_ci mutex_unlock(&xvtc_lock); 29662306a36Sopenharmony_ci} 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_cistatic void xvtc_unregister_device(struct xvtc_device *xvtc) 29962306a36Sopenharmony_ci{ 30062306a36Sopenharmony_ci mutex_lock(&xvtc_lock); 30162306a36Sopenharmony_ci list_del(&xvtc->list); 30262306a36Sopenharmony_ci mutex_unlock(&xvtc_lock); 30362306a36Sopenharmony_ci} 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci/* ----------------------------------------------------------------------------- 30662306a36Sopenharmony_ci * Platform Device Driver 30762306a36Sopenharmony_ci */ 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_cistatic int xvtc_parse_of(struct xvtc_device *xvtc) 31062306a36Sopenharmony_ci{ 31162306a36Sopenharmony_ci struct device_node *node = xvtc->xvip.dev->of_node; 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci xvtc->has_detector = of_property_read_bool(node, "xlnx,detector"); 31462306a36Sopenharmony_ci xvtc->has_generator = of_property_read_bool(node, "xlnx,generator"); 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_ci return 0; 31762306a36Sopenharmony_ci} 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_cistatic int xvtc_probe(struct platform_device *pdev) 32062306a36Sopenharmony_ci{ 32162306a36Sopenharmony_ci struct xvtc_device *xvtc; 32262306a36Sopenharmony_ci int ret; 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci xvtc = devm_kzalloc(&pdev->dev, sizeof(*xvtc), GFP_KERNEL); 32562306a36Sopenharmony_ci if (!xvtc) 32662306a36Sopenharmony_ci return -ENOMEM; 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci xvtc->xvip.dev = &pdev->dev; 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci ret = xvtc_parse_of(xvtc); 33162306a36Sopenharmony_ci if (ret < 0) 33262306a36Sopenharmony_ci return ret; 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci ret = xvip_init_resources(&xvtc->xvip); 33562306a36Sopenharmony_ci if (ret < 0) 33662306a36Sopenharmony_ci return ret; 33762306a36Sopenharmony_ci 33862306a36Sopenharmony_ci platform_set_drvdata(pdev, xvtc); 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ci xvip_print_version(&xvtc->xvip); 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ci xvtc_register_device(xvtc); 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci return 0; 34562306a36Sopenharmony_ci} 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_cistatic void xvtc_remove(struct platform_device *pdev) 34862306a36Sopenharmony_ci{ 34962306a36Sopenharmony_ci struct xvtc_device *xvtc = platform_get_drvdata(pdev); 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci xvtc_unregister_device(xvtc); 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci xvip_cleanup_resources(&xvtc->xvip); 35462306a36Sopenharmony_ci} 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_cistatic const struct of_device_id xvtc_of_id_table[] = { 35762306a36Sopenharmony_ci { .compatible = "xlnx,v-tc-6.1" }, 35862306a36Sopenharmony_ci { } 35962306a36Sopenharmony_ci}; 36062306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, xvtc_of_id_table); 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_cistatic struct platform_driver xvtc_driver = { 36362306a36Sopenharmony_ci .driver = { 36462306a36Sopenharmony_ci .name = "xilinx-vtc", 36562306a36Sopenharmony_ci .of_match_table = xvtc_of_id_table, 36662306a36Sopenharmony_ci }, 36762306a36Sopenharmony_ci .probe = xvtc_probe, 36862306a36Sopenharmony_ci .remove_new = xvtc_remove, 36962306a36Sopenharmony_ci}; 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_cimodule_platform_driver(xvtc_driver); 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ciMODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>"); 37462306a36Sopenharmony_ciMODULE_DESCRIPTION("Xilinx Video Timing Controller Driver"); 37562306a36Sopenharmony_ciMODULE_LICENSE("GPL v2"); 376