// SPDX-License-Identifier: GPL-2.0
/*
* Greybus Camera protocol driver.
*
* Copyright 2015 Google Inc.
* Copyright 2015 Linaro Ltd.
*/
#include <linux/debugfs.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include <linux/greybus.h>
#include "gb-camera.h"
#include "greybus_protocols.h"
enum gb_camera_debugs_buffer_id {
GB_CAMERA_DEBUGFS_BUFFER_CAPABILITIES,
GB_CAMERA_DEBUGFS_BUFFER_STREAMS,
GB_CAMERA_DEBUGFS_BUFFER_CAPTURE,
GB_CAMERA_DEBUGFS_BUFFER_FLUSH,
GB_CAMERA_DEBUGFS_BUFFER_MAX,
};
struct gb_camera_debugfs_buffer {
char data[PAGE_SIZE];
size_t length;
};
enum gb_camera_state {
GB_CAMERA_STATE_UNCONFIGURED,
GB_CAMERA_STATE_CONFIGURED,
};
/**
* struct gb_camera - A Greybus Camera Device
* @connection: the greybus connection for camera management
* @data_connection: the greybus connection for camera data
* @data_cport_id: the data CPort ID on the module side
* @mutex: protects the connection and state fields
* @state: the current module state
* @debugfs: debugfs entries for camera protocol operations testing
* @module: Greybus camera module registered to HOST processor.
*/
struct gb_camera {
struct gb_bundle *bundle;
struct gb_connection *connection;
struct gb_connection *data_connection;
u16 data_cport_id;
struct mutex mutex;
enum gb_camera_state state;
struct {
struct dentry *root;
struct gb_camera_debugfs_buffer *buffers;
} debugfs;
struct gb_camera_module module;
};
struct gb_camera_stream_config {
unsigned int width;
unsigned int height;
unsigned int format;
unsigned int vc;
unsigned int dt[2];
unsigned int max_size;
};
struct gb_camera_fmt_info {
enum v4l2_mbus_pixelcode mbus_code;
unsigned int gb_format;
unsigned int bpp;
};
/* GB format to media code map */
static const struct gb_camera_fmt_info gb_fmt_info[] = {
{