1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2021-2023 Digiteq Automotive
4  *     author: Martin Tuma <martin.tuma@digiteqautomotive.com>
5  */
6 
7 #ifndef __MGB4_CORE_H__
8 #define __MGB4_CORE_H__
9 
10 #include <linux/spi/flash.h>
11 #include <linux/mtd/partitions.h>
12 #include <linux/mutex.h>
13 #include <linux/dmaengine.h>
14 #include "mgb4_regs.h"
15 
16 #define MGB4_HW_FREQ 125000000
17 
18 #define MGB4_VIN_DEVICES  2
19 #define MGB4_VOUT_DEVICES 2
20 
21 #define MGB4_IS_GMSL(mgbdev) \
22 	((((mgbdev)->module_version >> 4) >= 2) && \
23 	 (((mgbdev)->module_version >> 4) <= 4))
24 #define MGB4_IS_FPDL3(mgbdev) \
25 	(((mgbdev)->module_version >> 4) == 1)
26 #define MGB4_HAS_VOUT(mgbdev) \
27 	((((mgbdev)->module_version >> 4) >= 1) && \
28 	 (((mgbdev)->module_version >> 4) <= 3))
29 
30 struct mgb4_dma_channel {
31 	struct dma_chan *chan;
32 	struct completion req_compl;
33 };
34 
35 struct mgb4_dev {
36 	struct pci_dev *pdev;
37 	struct platform_device *xdev;
38 	struct mgb4_vin_dev *vin[MGB4_VIN_DEVICES];
39 	struct mgb4_vout_dev *vout[MGB4_VOUT_DEVICES];
40 
41 	struct mgb4_dma_channel c2h_chan[MGB4_VIN_DEVICES];
42 	struct mgb4_dma_channel h2c_chan[MGB4_VOUT_DEVICES];
43 	struct dma_slave_map slave_map[MGB4_VIN_DEVICES + MGB4_VOUT_DEVICES];
44 
45 	struct mgb4_regs video;
46 	struct mgb4_regs cmt;
47 
48 	struct clk_hw *i2c_clk;
49 	struct clk_lookup *i2c_cl;
50 	struct platform_device *i2c_pdev;
51 	struct i2c_adapter *i2c_adap;
52 	struct mutex i2c_lock; /* I2C bus access lock */
53 
54 	struct platform_device *spi_pdev;
55 	struct flash_platform_data flash_data;
56 	struct mtd_partition partitions[2];
57 	char flash_name[16];
58 	char fw_part_name[16];
59 	char data_part_name[16];
60 	char channel_names[MGB4_VIN_DEVICES + MGB4_VOUT_DEVICES][16];
61 
62 	struct iio_dev *indio_dev;
63 #if IS_REACHABLE(CONFIG_HWMON)
64 	struct device *hwmon_dev;
65 #endif
66 
67 	unsigned long io_reconfig;
68 
69 	u8 module_version;
70 	u32 serial_number;
71 
72 	struct dentry *debugfs;
73 };
74 
75 #endif
76