drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c

Source file repositories/reference/linux-study-clean/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c

File Facts

System
Linux kernel
Corpus path
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c
Extension
.c
Size
13529 bytes
Lines
552
Domain
Driver Families
Bucket
drivers/staging
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2021-2022 Bootlin
 * Author: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
 */

#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/reset.h>
#include <media/v4l2-device.h>
#include <media/v4l2-mc.h>

#include "sun6i_isp.h"
#include "sun6i_isp_capture.h"
#include "sun6i_isp_params.h"
#include "sun6i_isp_proc.h"
#include "sun6i_isp_reg.h"

/* Helpers */

u32 sun6i_isp_load_read(struct sun6i_isp_device *isp_dev, u32 offset)
{
	u32 *data = (u32 *)(isp_dev->tables.load.data + offset);

	return *data;
}

void sun6i_isp_load_write(struct sun6i_isp_device *isp_dev, u32 offset,
			  u32 value)
{
	u32 *data = (u32 *)(isp_dev->tables.load.data + offset);

	*data = value;
}

/* State */

/*
 * The ISP works with a load buffer, which gets copied to the actual registers
 * by the hardware before processing a frame when a specific flag is set.
 * This is represented by tracking the ISP state in the different parts of
 * the code with explicit sync points:
 * - state update: to update the load buffer for the next frame if necessary;
 * - state complete: to indicate that the state update was applied.
 */

static void sun6i_isp_state_ready(struct sun6i_isp_device *isp_dev)
{
	struct regmap *regmap = isp_dev->regmap;
	u32 value;

	regmap_read(regmap, SUN6I_ISP_FE_CTRL_REG, &value);
	value |= SUN6I_ISP_FE_CTRL_PARA_READY;
	regmap_write(regmap, SUN6I_ISP_FE_CTRL_REG, value);
}

static void sun6i_isp_state_complete(struct sun6i_isp_device *isp_dev)
{
	unsigned long flags;

	spin_lock_irqsave(&isp_dev->state_lock, flags);

	sun6i_isp_capture_state_complete(isp_dev);
	sun6i_isp_params_state_complete(isp_dev);

	spin_unlock_irqrestore(&isp_dev->state_lock, flags);
}

void sun6i_isp_state_update(struct sun6i_isp_device *isp_dev, bool ready_hold)
{
	bool update = false;
	unsigned long flags;

	spin_lock_irqsave(&isp_dev->state_lock, flags);

	sun6i_isp_capture_state_update(isp_dev, &update);
	sun6i_isp_params_state_update(isp_dev, &update);

	if (update && !ready_hold)
		sun6i_isp_state_ready(isp_dev);

	spin_unlock_irqrestore(&isp_dev->state_lock, flags);
}

Annotation

Implementation Notes