blob: 05c1a95526563e56e7d1631f79071db5873542ff [file] [log] [blame]
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that 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.
*/
#include <linux/of.h>
#include <linux/debugfs.h>
#include <linux/videodev2.h>
#include <linux/uaccess.h>
#include <linux/platform_device.h>
#include <linux/firmware.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include "cam_io_util.h"
#include "cam_hw.h"
#include "cam_hw_intf.h"
#include "jpeg_dma_core.h"
#include "jpeg_dma_soc.h"
#include "cam_soc_util.h"
#include "cam_io_util.h"
#include "cam_dma_hw_intf.h"
#include "cam_jpeg_hw_intf.h"
#include "cam_jpeg_hw_mgr_intf.h"
#include "cam_cpas_api.h"
#include "cam_debug_util.h"
int cam_jpeg_dma_init_hw(void *device_priv,
void *init_hw_args, uint32_t arg_size)
{
struct cam_hw_info *jpeg_dma_dev = device_priv;
struct cam_hw_soc_info *soc_info = NULL;
struct cam_jpeg_dma_device_core_info *core_info = NULL;
struct cam_jpeg_cpas_vote cpas_vote;
int rc;
if (!device_priv) {
CAM_ERR(CAM_JPEG, "Invalid cam_dev_info");
return -EINVAL;
}
soc_info = &jpeg_dma_dev->soc_info;
core_info =
(struct cam_jpeg_dma_device_core_info *)jpeg_dma_dev->
core_info;
if (!soc_info || !core_info) {
CAM_ERR(CAM_JPEG, "soc_info = %pK core_info = %pK",
soc_info, core_info);
return -EINVAL;
}
cpas_vote.ahb_vote.type = CAM_VOTE_ABSOLUTE;
cpas_vote.ahb_vote.vote.level = CAM_SVS_VOTE;
cpas_vote.axi_vote.compressed_bw = JPEG_TURBO_VOTE;
cpas_vote.axi_vote.uncompressed_bw = JPEG_TURBO_VOTE;
rc = cam_cpas_start(core_info->cpas_handle,
&cpas_vote.ahb_vote, &cpas_vote.axi_vote);
if (rc)
CAM_ERR(CAM_JPEG, "cpass start failed: %d", rc);
rc = cam_jpeg_dma_enable_soc_resources(soc_info);
if (rc) {
CAM_ERR(CAM_JPEG, "soc enable is failed %d", rc);
cam_cpas_stop(core_info->cpas_handle);
}
return rc;
}
int cam_jpeg_dma_deinit_hw(void *device_priv,
void *init_hw_args, uint32_t arg_size)
{
struct cam_hw_info *jpeg_dma_dev = device_priv;
struct cam_hw_soc_info *soc_info = NULL;
struct cam_jpeg_dma_device_core_info *core_info = NULL;
int rc;
if (!device_priv) {
CAM_ERR(CAM_JPEG, "Invalid cam_dev_info");
return -EINVAL;
}
soc_info = &jpeg_dma_dev->soc_info;
core_info = (struct cam_jpeg_dma_device_core_info *)
jpeg_dma_dev->core_info;
if (!soc_info || !core_info) {
CAM_ERR(CAM_JPEG, "soc_info = %pK core_info = %pK",
soc_info, core_info);
return -EINVAL;
}
rc = cam_jpeg_dma_disable_soc_resources(soc_info);
if (rc)
CAM_ERR(CAM_JPEG, "soc enable failed %d", rc);
rc = cam_cpas_stop(core_info->cpas_handle);
if (rc)
CAM_ERR(CAM_JPEG, "cpas stop failed: %d", rc);
return 0;
}
int cam_jpeg_dma_process_cmd(void *device_priv, uint32_t cmd_type,
void *cmd_args, uint32_t arg_size)
{
struct cam_hw_info *jpeg_dma_dev = device_priv;
struct cam_jpeg_dma_device_core_info *core_info = NULL;
int rc;
if (!device_priv) {
CAM_ERR(CAM_JPEG, "Invalid arguments");
return -EINVAL;
}
if (cmd_type >= CAM_JPEG_DMA_CMD_MAX) {
CAM_ERR(CAM_JPEG, "Invalid command : %x", cmd_type);
return -EINVAL;
}
core_info =
(struct cam_jpeg_dma_device_core_info *)jpeg_dma_dev->
core_info;
switch (cmd_type) {
case CAM_JPEG_DMA_CMD_SET_IRQ_CB:
{
struct cam_jpeg_set_irq_cb *irq_cb = cmd_args;
if (!cmd_args) {
CAM_ERR(CAM_JPEG, "cmd args NULL");
return -EINVAL;
}
if (irq_cb->b_set_cb) {
core_info->irq_cb.jpeg_hw_mgr_cb =
irq_cb->jpeg_hw_mgr_cb;
core_info->irq_cb.data = irq_cb->data;
} else {
core_info->irq_cb.jpeg_hw_mgr_cb = NULL;
core_info->irq_cb.data = NULL;
}
rc = 0;
break;
}
default:
rc = -EINVAL;
break;
}
return rc;
}
irqreturn_t cam_jpeg_dma_irq(int irq_num, void *data)
{
return IRQ_HANDLED;
}