2 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "linux/component.h"
20 #include "linux/pm_runtime.h"
24 #ifdef CONFIG_DEBUG_FS
25 #define REGDEF(reg) { reg, #reg }
110 int vc4_v3d_debugfs_regs(struct seq_file
*m
, void *unused
)
112 struct drm_info_node
*node
= (struct drm_info_node
*)m
->private;
113 struct drm_device
*dev
= node
->minor
->dev
;
114 struct vc4_dev
*vc4
= to_vc4_dev(dev
);
117 for (i
= 0; i
< ARRAY_SIZE(vc4_reg_defs
); i
++) {
118 seq_printf(m
, "%s (0x%04x): 0x%08x\n",
119 vc4_reg_defs
[i
].name
, vc4_reg_defs
[i
].reg
,
120 V3D_READ(vc4_reg_defs
[i
].reg
));
126 int vc4_v3d_debugfs_ident(struct seq_file
*m
, void *unused
)
128 struct drm_info_node
*node
= (struct drm_info_node
*)m
->private;
129 struct drm_device
*dev
= node
->minor
->dev
;
130 struct vc4_dev
*vc4
= to_vc4_dev(dev
);
131 uint32_t ident1
= V3D_READ(V3D_IDENT1
);
132 uint32_t nslc
= VC4_GET_FIELD(ident1
, V3D_IDENT1_NSLC
);
133 uint32_t tups
= VC4_GET_FIELD(ident1
, V3D_IDENT1_TUPS
);
134 uint32_t qups
= VC4_GET_FIELD(ident1
, V3D_IDENT1_QUPS
);
136 seq_printf(m
, "Revision: %d\n",
137 VC4_GET_FIELD(ident1
, V3D_IDENT1_REV
));
138 seq_printf(m
, "Slices: %d\n", nslc
);
139 seq_printf(m
, "TMUs: %d\n", nslc
* tups
);
140 seq_printf(m
, "QPUs: %d\n", nslc
* qups
);
141 seq_printf(m
, "Semaphores: %d\n",
142 VC4_GET_FIELD(ident1
, V3D_IDENT1_NSEM
));
146 #endif /* CONFIG_DEBUG_FS */
149 vc4_v3d_set_power(struct vc4_dev
*vc4
, bool on
)
151 /* XXX: This interface is needed for GPU reset, and the way to
152 * do it is to turn our power domain off and back on. We
153 * can't just reset from within the driver, because the reset
154 * bits are in the power domain's register area, and get set
155 * during the poweron process.
160 static void vc4_v3d_init_hw(struct drm_device
*dev
)
162 struct vc4_dev
*vc4
= to_vc4_dev(dev
);
164 /* Take all the memory that would have been reserved for user
165 * QPU programs, since we don't have an interface for running
168 V3D_WRITE(V3D_VPMBASE
, 0);
172 static int vc4_v3d_runtime_suspend(struct device
*dev
)
174 struct vc4_v3d
*v3d
= dev_get_drvdata(dev
);
175 struct vc4_dev
*vc4
= v3d
->vc4
;
177 vc4_irq_uninstall(vc4
->dev
);
182 static int vc4_v3d_runtime_resume(struct device
*dev
)
184 struct vc4_v3d
*v3d
= dev_get_drvdata(dev
);
185 struct vc4_dev
*vc4
= v3d
->vc4
;
187 vc4_v3d_init_hw(vc4
->dev
);
188 vc4_irq_postinstall(vc4
->dev
);
194 static int vc4_v3d_bind(struct device
*dev
, struct device
*master
, void *data
)
196 struct platform_device
*pdev
= to_platform_device(dev
);
197 struct drm_device
*drm
= dev_get_drvdata(master
);
198 struct vc4_dev
*vc4
= to_vc4_dev(drm
);
199 struct vc4_v3d
*v3d
= NULL
;
202 v3d
= devm_kzalloc(&pdev
->dev
, sizeof(*v3d
), GFP_KERNEL
);
206 dev_set_drvdata(dev
, v3d
);
210 v3d
->regs
= vc4_ioremap_regs(pdev
, 0);
211 if (IS_ERR(v3d
->regs
))
212 return PTR_ERR(v3d
->regs
);
217 if (V3D_READ(V3D_IDENT0
) != V3D_EXPECTED_IDENT0
) {
218 DRM_ERROR("V3D_IDENT0 read 0x%08x instead of 0x%08x\n",
219 V3D_READ(V3D_IDENT0
), V3D_EXPECTED_IDENT0
);
223 /* Reset the binner overflow address/size at setup, to be sure
224 * we don't reuse an old one.
226 V3D_WRITE(V3D_BPOA
, 0);
227 V3D_WRITE(V3D_BPOS
, 0);
229 vc4_v3d_init_hw(drm
);
231 ret
= drm_irq_install(drm
, platform_get_irq(pdev
, 0));
233 DRM_ERROR("Failed to install IRQ handler\n");
237 pm_runtime_enable(dev
);
242 static void vc4_v3d_unbind(struct device
*dev
, struct device
*master
,
245 struct drm_device
*drm
= dev_get_drvdata(master
);
246 struct vc4_dev
*vc4
= to_vc4_dev(drm
);
248 pm_runtime_disable(dev
);
250 drm_irq_uninstall(drm
);
252 /* Disable the binner's overflow memory address, so the next
253 * driver probe (if any) doesn't try to reuse our old
256 V3D_WRITE(V3D_BPOA
, 0);
257 V3D_WRITE(V3D_BPOS
, 0);
262 static const struct dev_pm_ops vc4_v3d_pm_ops
= {
263 SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend
, vc4_v3d_runtime_resume
, NULL
)
266 static const struct component_ops vc4_v3d_ops
= {
267 .bind
= vc4_v3d_bind
,
268 .unbind
= vc4_v3d_unbind
,
271 static int vc4_v3d_dev_probe(struct platform_device
*pdev
)
273 return component_add(&pdev
->dev
, &vc4_v3d_ops
);
276 static int vc4_v3d_dev_remove(struct platform_device
*pdev
)
278 component_del(&pdev
->dev
, &vc4_v3d_ops
);
282 static const struct of_device_id vc4_v3d_dt_match
[] = {
283 { .compatible
= "brcm,vc4-v3d" },
287 struct platform_driver vc4_v3d_driver
= {
288 .probe
= vc4_v3d_dev_probe
,
289 .remove
= vc4_v3d_dev_remove
,
292 .of_match_table
= vc4_v3d_dt_match
,
293 .pm
= &vc4_v3d_pm_ops
,