/*
* Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have eeceived a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "soc/tegra/camrtc-dbg-messages.h"
#include "soc/tegra/camrtc-commands.h"
#include <linux/debugfs.h>
#include <linux/io.h>
#include <linux/iommu.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/sched.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
#include <linux/sched/signal.h>
#include <linux/sched/clock.h>
#endif
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/tegra-camera-rtcpu.h>
#include <linux/tegra-ivc.h>
#include <linux/tegra-ivc-bus.h>
#include <linux/platform/tegra/emc_bwmgr.h>
#include <linux/platform/tegra/tegra-mc-sid.h>
struct camrtc_debug {
struct tegra_ivc_channel *channel;
struct mutex mutex;
struct dentry *root;
wait_queue_head_t waitq;
struct {
u32 completion_timeout;
u32 mods_loops;
char *test_case;
size_t test_case_size;
u32 test_timeout;
unsigned long test_bw;
} parameters;
struct camrtc_test_mem {
u32 index;
size_t used;
size_t size;
void *ptr;
dma_addr_t iova;
} mem[CAMRTC_DBG_NUM_MEM_TEST_MEM];
struct device *mem_devices[3];
struct camrtc_dbg_streamids streamids;
struct ast_regset {
struct debugfs_regset32 common, region[8];
} ast_regsets[2];
};
#define NV(x) "nvidia," #x
/* Get a camera-rtcpu device */
static struct device *camrtc_get_device(struct tegra_ivc_channel *ch)
{
if (unlikely(ch == NULL))
return NULL;
BUG_ON(ch->dev.parent == NULL);
BUG_ON(ch->dev.parent->parent == NULL);
return ch->dev.parent->parent;
}
#define INIT_OPEN_FOPS(_open) { \
.open = _open, \
.read = seq_read, \
.llseek = seq_lseek, \
.release = single_release \
}
#define DEFINE_SEQ_FOPS(_fops_, _show_) \
static int _fops_ ## _open(struct inode *inode, struct file *file) \
{ \
return single_open(file, _show_, inode->i_private); \
} \
static const struct file_operations _fops_ = INIT_OPEN_FOPS(_fops_ ## _open)
static int camrtc_show_version(struct seq_file *file, void *data)
{
struct tegra_ivc_channel *ch = file->private;
struct device *rce_dev = camrtc_get_device(ch);
char version[TEGRA_CAMRTC_VERSION_LEN];
tegra_camrtc_print_version(rce_dev, version, sizeof(version));
seq_puts(file, version);
seq_puts(file, "\n");
return 0;
}
DEFINE_SEQ_FOPS(camrtc_dbgfs_fops_version, camrtc_show_version);
static int camrtc_show_reboot(struct seq_file *file, void *data)
{
struct tegra_ivc_channel *ch = file->private;
struct device *rce_dev = camrtc_get_device(ch);
int ret = 0;
/* Make rtcpu online */
ret = tegra_ivc_channel_runtime_get(ch);
if (ret < 0)
goto error;
ret = tegra_camrtc_reboot(rce_dev);
if (ret)
goto error;
seq_puts(file, "0\n");
error:
tegra_ivc_channel_runtime_put(ch);
return ret;
}
DEFINE_SEQ_FOPS(camrtc_dbgfs_fops_reboot, camrtc_show_reboot);
static void camrtc_debug_notify(struct tegra_ivc_channel *ch)
{
struct camrtc_debug *crd = tegra_ivc_channel_get_drvdata(ch);
wake_up_all(&crd->waitq);
}
static int camrtc_show_forced_reset_restore(struct seq_file *file, void *data)
{
struct tegra_ivc_channel *ch = file->private;
struct device *rce_dev = camrtc_get_device(ch);
int ret = 0;
/* Make rtcpu online */
ret = tegra_ivc_channel_runtime_get(ch);
if (ret < 0)
goto error;
ret = tegra_camrtc_restore(rce_dev);
if (ret)
goto error;
seq_puts(file, "0\n");
error:
tegra_ivc_channel_runtime_put(ch);
return ret;
}
DEFINE_SEQ_FOPS(camrtc_dbgfs_fops_forced_reset_restore,
camrtc_show_forced_reset_restore);
static int camrtc_ivc_dbg_full_frame_xact(
struct tegra_ivc_channel <
|