1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2020 Intel Corporation
5 #include <linux/debugfs.h>
6 #include <linux/pm_runtime.h>
9 #include "ipu-platform-regs.h"
11 #define IPU_ISYS_GPC_NUM 16
14 #define pm_runtime_get_sync(d) 0
15 #define pm_runtime_put(d) 0
23 unsigned int gpcindex
;
27 struct ipu_isys_gpcs
{
29 struct ipu_isys_gpc gpc
[IPU_ISYS_GPC_NUM
];
33 static int ipu6_isys_gpc_global_enable_get(void *data
, u64
*val
)
35 struct ipu_isys_gpcs
*isys_gpcs
= data
;
36 struct ipu_isys
*isys
= isys_gpcs
->prit
;
38 mutex_lock(&isys
->mutex
);
40 *val
= isys_gpcs
->gpc_enable
;
42 mutex_unlock(&isys
->mutex
);
46 static int ipu6_isys_gpc_global_enable_set(void *data
, u64 val
)
48 struct ipu_isys_gpcs
*isys_gpcs
= data
;
49 struct ipu_isys
*isys
= isys_gpcs
->prit
;
53 if (val
!= 0 && val
!= 1)
56 if (!isys
|| !isys
->pdata
|| !isys
->pdata
->base
)
59 mutex_lock(&isys
->mutex
);
61 base
= isys
->pdata
->base
+ IPU_ISYS_GPC_BASE
;
63 ret
= pm_runtime_get_sync(&isys
->adev
->dev
);
65 pm_runtime_put(&isys
->adev
->dev
);
66 mutex_unlock(&isys
->mutex
);
71 writel(0x0, base
+ IPU_ISYS_GPREG_TRACE_TIMER_RST
);
72 writel(0x0, base
+ IPU_ISF_CDC_MMU_GPC_OVERALL_ENABLE
);
73 writel(0xffff, base
+ IPU_ISF_CDC_MMU_GPC_SOFT_RESET
);
74 isys_gpcs
->gpc_enable
= false;
75 for (i
= 0; i
< IPU_ISYS_GPC_NUM
; i
++) {
76 isys_gpcs
->gpc
[i
].enable
= 0;
77 isys_gpcs
->gpc
[i
].sense
= 0;
78 isys_gpcs
->gpc
[i
].route
= 0;
79 isys_gpcs
->gpc
[i
].source
= 0;
81 pm_runtime_mark_last_busy(&isys
->adev
->dev
);
82 pm_runtime_put_autosuspend(&isys
->adev
->dev
);
85 * Set gpc reg and start all gpc here.
86 * RST free running local timer.
88 writel(0x0, base
+ IPU_ISYS_GPREG_TRACE_TIMER_RST
);
89 writel(0x1, base
+ IPU_ISYS_GPREG_TRACE_TIMER_RST
);
91 for (i
= 0; i
< IPU_ISYS_GPC_NUM
; i
++) {
93 writel(isys_gpcs
->gpc
[i
].enable
,
94 base
+ IPU_ISF_CDC_MMU_GPC_ENABLE0
+ 4 * i
);
95 /* Setting (route/source/sense) */
96 writel((isys_gpcs
->gpc
[i
].sense
97 << IPU_GPC_SENSE_OFFSET
)
98 + (isys_gpcs
->gpc
[i
].route
99 << IPU_GPC_ROUTE_OFFSET
)
100 + (isys_gpcs
->gpc
[i
].source
101 << IPU_GPC_SOURCE_OFFSET
),
102 base
+ IPU_ISF_CDC_MMU_GPC_CNT_SEL0
+ 4 * i
);
105 /* Soft reset and Overall Enable. */
106 writel(0x0, base
+ IPU_ISF_CDC_MMU_GPC_OVERALL_ENABLE
);
107 writel(0xffff, base
+ IPU_ISF_CDC_MMU_GPC_SOFT_RESET
);
108 writel(0x1, base
+ IPU_ISF_CDC_MMU_GPC_OVERALL_ENABLE
);
110 isys_gpcs
->gpc_enable
= true;
113 mutex_unlock(&isys
->mutex
);
117 DEFINE_SIMPLE_ATTRIBUTE(isys_gpc_globe_enable_fops
,
118 ipu6_isys_gpc_global_enable_get
,
119 ipu6_isys_gpc_global_enable_set
, "%llu\n");
121 static int ipu6_isys_gpc_count_get(void *data
, u64
*val
)
123 struct ipu_isys_gpc
*isys_gpc
= data
;
124 struct ipu_isys
*isys
= isys_gpc
->prit
;
127 if (!isys
|| !isys
->pdata
|| !isys
->pdata
->base
)
130 spin_lock(&isys
->power_lock
);
132 base
= isys
->pdata
->base
+ IPU_ISYS_GPC_BASE
;
133 *val
= readl(base
+ IPU_ISF_CDC_MMU_GPC_VALUE0
134 + 4 * isys_gpc
->gpcindex
);
138 spin_unlock(&isys
->power_lock
);
143 DEFINE_SIMPLE_ATTRIBUTE(isys_gpc_count_fops
, ipu6_isys_gpc_count_get
,
146 int ipu_isys_gpc_init_debugfs(struct ipu_isys
*isys
)
148 struct dentry
*gpcdir
;
153 struct ipu_isys_gpcs
*isys_gpcs
;
155 isys_gpcs
= devm_kzalloc(&isys
->adev
->dev
, sizeof(*isys_gpcs
),
160 gpcdir
= debugfs_create_dir("gpcs", isys
->debugfsdir
);
164 isys_gpcs
->prit
= isys
;
165 file
= debugfs_create_file("enable", 0600, gpcdir
, isys_gpcs
,
166 &isys_gpc_globe_enable_fops
);
170 for (i
= 0; i
< IPU_ISYS_GPC_NUM
; i
++) {
171 sprintf(gpcname
, "gpc%d", i
);
172 dir
= debugfs_create_dir(gpcname
, gpcdir
);
176 file
= debugfs_create_bool("enable", 0600, dir
,
177 &isys_gpcs
->gpc
[i
].enable
);
181 debugfs_create_u32("source", 0600, dir
,
182 &isys_gpcs
->gpc
[i
].source
);
184 debugfs_create_u32("route", 0600, dir
,
185 &isys_gpcs
->gpc
[i
].route
);
187 debugfs_create_u32("sense", 0600, dir
,
188 &isys_gpcs
->gpc
[i
].sense
);
190 isys_gpcs
->gpc
[i
].gpcindex
= i
;
191 isys_gpcs
->gpc
[i
].prit
= isys
;
192 file
= debugfs_create_file("count", 0400, dir
,
194 &isys_gpc_count_fops
);
202 debugfs_remove_recursive(gpcdir
);