1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4  * Author: James.Qian.Wang <james.qian.wang@arm.com>
5  *
6  */
7 #ifndef _KOMEDA_DEV_H_
8 #define _KOMEDA_DEV_H_
9 
10 #include <linux/device.h>
11 #include <linux/clk.h>
12 #include "komeda_pipeline.h"
13 #include "malidp_product.h"
14 #include "komeda_format_caps.h"
15 
16 /* malidp device id */
17 enum {
18 	MALI_D71 = 0,
19 };
20 
21 /* pipeline DT ports */
22 enum {
23 	KOMEDA_OF_PORT_OUTPUT		= 0,
24 	KOMEDA_OF_PORT_COPROC		= 1,
25 };
26 
27 struct komeda_chip_info {
28 	u32 arch_id;
29 	u32 core_id;
30 	u32 core_info;
31 	u32 bus_width;
32 };
33 
34 struct komeda_product_data {
35 	u32 product_id;
36 	struct komeda_dev_funcs *(*identify)(u32 __iomem *reg,
37 					     struct komeda_chip_info *info);
38 };
39 
40 struct komeda_dev;
41 
42 /**
43  * struct komeda_dev_funcs
44  *
45  * Supplied by chip level and returned by the chip entry function xxx_identify,
46  */
47 struct komeda_dev_funcs {
48 	/**
49 	 * @init_format_table:
50 	 *
51 	 * initialize &komeda_dev->format_table, this function should be called
52 	 * before the &enum_resource
53 	 */
54 	void (*init_format_table)(struct komeda_dev *mdev);
55 	/**
56 	 * @enum_resources:
57 	 *
58 	 * for CHIP to report or add pipeline and component resources to CORE
59 	 */
60 	int (*enum_resources)(struct komeda_dev *mdev);
61 	/** @cleanup: call to chip to cleanup komeda_dev->chip data */
62 	void (*cleanup)(struct komeda_dev *mdev);
63 };
64 
65 /**
66  * struct komeda_dev
67  *
68  * Pipeline and component are used to describe how to handle the pixel data.
69  * komeda_device is for describing the whole view of the device, and the
70  * control-abilites of device.
71  */
72 struct komeda_dev {
73 	struct device *dev;
74 	u32 __iomem   *reg_base;
75 
76 	struct komeda_chip_info chip;
77 	/** @fmt_tbl: initialized by &komeda_dev_funcs->init_format_table */
78 	struct komeda_format_caps_table fmt_tbl;
79 	/** @pclk: APB clock for register access */
80 	struct clk *pclk;
81 	/** @mck: HW main engine clk */
82 	struct clk *mclk;
83 
84 	int n_pipelines;
85 	struct komeda_pipeline *pipelines[KOMEDA_MAX_PIPELINES];
86 
87 	/** @funcs: chip funcs to access to HW */
88 	struct komeda_dev_funcs *funcs;
89 	/**
90 	 * @chip_data:
91 	 *
92 	 * chip data will be added by &komeda_dev_funcs.enum_resources() and
93 	 * destroyed by &komeda_dev_funcs.cleanup()
94 	 */
95 	void *chip_data;
96 };
97 
98 static inline bool
99 komeda_product_match(struct komeda_dev *mdev, u32 target)
100 {
101 	return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) == target;
102 }
103 
104 struct komeda_dev_funcs *
105 d71_identify(u32 __iomem *reg, struct komeda_chip_info *chip);
106 
107 struct komeda_dev *komeda_dev_create(struct device *dev);
108 void komeda_dev_destroy(struct komeda_dev *mdev);
109 
110 #endif /*_KOMEDA_DEV_H_*/
111