18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017 NVIDIA CORPORATION.  All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef TEGRA_HUB_H
78c2ecf20Sopenharmony_ci#define TEGRA_HUB_H 1
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <drm/drm_plane.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "plane.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistruct tegra_dc;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct tegra_windowgroup {
168c2ecf20Sopenharmony_ci	unsigned int usecount;
178c2ecf20Sopenharmony_ci	struct mutex lock;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	unsigned int index;
208c2ecf20Sopenharmony_ci	struct host1x_client *parent;
218c2ecf20Sopenharmony_ci	struct reset_control *rst;
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistruct tegra_shared_plane {
258c2ecf20Sopenharmony_ci	struct tegra_plane base;
268c2ecf20Sopenharmony_ci	struct tegra_windowgroup *wgrp;
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic inline struct tegra_shared_plane *
308c2ecf20Sopenharmony_cito_tegra_shared_plane(struct drm_plane *plane)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	return container_of(plane, struct tegra_shared_plane, base.base);
338c2ecf20Sopenharmony_ci}
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct tegra_display_hub_soc {
368c2ecf20Sopenharmony_ci	unsigned int num_wgrps;
378c2ecf20Sopenharmony_ci	bool supports_dsc;
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct tegra_display_hub {
418c2ecf20Sopenharmony_ci	struct drm_private_obj base;
428c2ecf20Sopenharmony_ci	struct host1x_client client;
438c2ecf20Sopenharmony_ci	struct clk *clk_disp;
448c2ecf20Sopenharmony_ci	struct clk *clk_dsc;
458c2ecf20Sopenharmony_ci	struct clk *clk_hub;
468c2ecf20Sopenharmony_ci	struct reset_control *rst;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	unsigned int num_heads;
498c2ecf20Sopenharmony_ci	struct clk **clk_heads;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	const struct tegra_display_hub_soc *soc;
528c2ecf20Sopenharmony_ci	struct tegra_windowgroup *wgrps;
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic inline struct tegra_display_hub *
568c2ecf20Sopenharmony_cito_tegra_display_hub(struct host1x_client *client)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	return container_of(client, struct tegra_display_hub, client);
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistruct tegra_display_hub_state {
628c2ecf20Sopenharmony_ci	struct drm_private_state base;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	struct tegra_dc *dc;
658c2ecf20Sopenharmony_ci	unsigned long rate;
668c2ecf20Sopenharmony_ci	struct clk *clk;
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline struct tegra_display_hub_state *
708c2ecf20Sopenharmony_cito_tegra_display_hub_state(struct drm_private_state *priv)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	return container_of(priv, struct tegra_display_hub_state, base);
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistruct tegra_dc;
768c2ecf20Sopenharmony_cistruct tegra_plane;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciint tegra_display_hub_prepare(struct tegra_display_hub *hub);
798c2ecf20Sopenharmony_civoid tegra_display_hub_cleanup(struct tegra_display_hub *hub);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct drm_plane *tegra_shared_plane_create(struct drm_device *drm,
828c2ecf20Sopenharmony_ci					    struct tegra_dc *dc,
838c2ecf20Sopenharmony_ci					    unsigned int wgrp,
848c2ecf20Sopenharmony_ci					    unsigned int index);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciint tegra_display_hub_atomic_check(struct drm_device *drm,
878c2ecf20Sopenharmony_ci				   struct drm_atomic_state *state);
888c2ecf20Sopenharmony_civoid tegra_display_hub_atomic_commit(struct drm_device *drm,
898c2ecf20Sopenharmony_ci				     struct drm_atomic_state *state);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define DC_CMD_IHUB_COMMON_MISC_CTL 0x068
928c2ecf20Sopenharmony_ci#define  LATENCY_EVENT (1 << 3)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define DC_DISP_IHUB_COMMON_DISPLAY_FETCH_METER 0x451
958c2ecf20Sopenharmony_ci#define  CURS_SLOTS(x) (((x) & 0xff) << 8)
968c2ecf20Sopenharmony_ci#define  WGRP_SLOTS(x) (((x) & 0xff) << 0)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#endif /* TEGRA_HUB_H */
99