1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * vsp1.h  --  R-Car VSP1 Driver
4  *
5  * Copyright (C) 2013-2014 Renesas Electronics Corporation
6  *
7  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8  */
9 #ifndef __VSP1_H__
10 #define __VSP1_H__
11 
12 #include <linux/io.h>
13 #include <linux/list.h>
14 #include <linux/mutex.h>
15 
16 #include <media/media-device.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-subdev.h>
19 
20 #include "vsp1_regs.h"
21 
22 struct clk;
23 struct device;
24 struct rcar_fcp_device;
25 
26 struct vsp1_drm;
27 struct vsp1_entity;
28 struct vsp1_platform_data;
29 struct vsp1_brx;
30 struct vsp1_clu;
31 struct vsp1_hgo;
32 struct vsp1_hgt;
33 struct vsp1_hsit;
34 struct vsp1_lif;
35 struct vsp1_lut;
36 struct vsp1_rwpf;
37 struct vsp1_sru;
38 struct vsp1_uds;
39 struct vsp1_uif;
40 
41 #define VSP1_MAX_LIF		2
42 #define VSP1_MAX_RPF		5
43 #define VSP1_MAX_UDS		3
44 #define VSP1_MAX_UIF		2
45 #define VSP1_MAX_WPF		4
46 
47 #define VSP1_HAS_LUT		BIT(1)
48 #define VSP1_HAS_SRU		BIT(2)
49 #define VSP1_HAS_BRU		BIT(3)
50 #define VSP1_HAS_CLU		BIT(4)
51 #define VSP1_HAS_WPF_VFLIP	BIT(5)
52 #define VSP1_HAS_WPF_HFLIP	BIT(6)
53 #define VSP1_HAS_HGO		BIT(7)
54 #define VSP1_HAS_HGT		BIT(8)
55 #define VSP1_HAS_BRS		BIT(9)
56 #define VSP1_HAS_EXT_DL		BIT(10)
57 
58 struct vsp1_device_info {
59 	u32 version;
60 	const char *model;
61 	unsigned int gen;
62 	unsigned int features;
63 	unsigned int lif_count;
64 	unsigned int rpf_count;
65 	unsigned int uds_count;
66 	unsigned int uif_count;
67 	unsigned int wpf_count;
68 	unsigned int num_bru_inputs;
69 	bool uapi;
70 };
71 
72 #define vsp1_feature(vsp1, f) ((vsp1)->info->features & (f))
73 
74 struct vsp1_device {
75 	struct device *dev;
76 	const struct vsp1_device_info *info;
77 	u32 version;
78 
79 	void __iomem *mmio;
80 	struct rcar_fcp_device *fcp;
81 	struct device *bus_master;
82 
83 	struct vsp1_brx *brs;
84 	struct vsp1_brx *bru;
85 	struct vsp1_clu *clu;
86 	struct vsp1_hgo *hgo;
87 	struct vsp1_hgt *hgt;
88 	struct vsp1_hsit *hsi;
89 	struct vsp1_hsit *hst;
90 	struct vsp1_lif *lif[VSP1_MAX_LIF];
91 	struct vsp1_lut *lut;
92 	struct vsp1_rwpf *rpf[VSP1_MAX_RPF];
93 	struct vsp1_sru *sru;
94 	struct vsp1_uds *uds[VSP1_MAX_UDS];
95 	struct vsp1_uif *uif[VSP1_MAX_UIF];
96 	struct vsp1_rwpf *wpf[VSP1_MAX_WPF];
97 
98 	struct list_head entities;
99 	struct list_head videos;
100 
101 	struct v4l2_device v4l2_dev;
102 	struct media_device media_dev;
103 	struct media_entity_operations media_ops;
104 
105 	struct vsp1_drm *drm;
106 };
107 
108 int vsp1_device_get(struct vsp1_device *vsp1);
109 void vsp1_device_put(struct vsp1_device *vsp1);
110 
111 int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index);
112 
113 static inline u32 vsp1_read(struct vsp1_device *vsp1, u32 reg)
114 {
115 	return ioread32(vsp1->mmio + reg);
116 }
117 
118 static inline void vsp1_write(struct vsp1_device *vsp1, u32 reg, u32 data)
119 {
120 	iowrite32(data, vsp1->mmio + reg);
121 }
122 
123 #endif /* __VSP1_H__ */
124