Release 4.7 drivers/media/v4l2-core/v4l2-common.c
/*
* Video for Linux Two
*
* A generic video device interface for the LINUX operating system
* using a set of device structures/vectors for low level operations.
*
* This file replaces the videodev.c file that comes with the
* regular kernel distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Author: Bill Dirks <bill@thedirks.org>
* based on code by Alan Cox, <alan@cymru.net>
*
*/
/*
* Video capture interface for Linux
*
* A generic video device interface for the LINUX operating system
* using a set of device structures/vectors for low level operations.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Author: Alan Cox, <alan@lxorguk.ukuu.org.uk>
*
* Fixes:
*/
/*
* Video4linux 1/2 integration by Justin Schoeman
* <justin@suntiger.ee.up.ac.za>
* 2.4 PROCFS support ported from 2.4 kernels by
* Iñaki GarcÃa Etxebarria <garetxe@euskalnet.net>
* Makefile fix by "W. Michael Petullo" <mike@flyn.org>
* 2.4 devfs support ported from 2.4 kernels by
* Dan Merillat <dan@merillat.org>
* Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/i2c.h>
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
#endif
#include <asm/uaccess.h>
#include <asm/pgtable.h>
#include <asm/io.h>
#include <asm/div64.h>
#include <media/v4l2-common.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <linux/videodev2.h>
MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
MODULE_LICENSE("GPL");
/*
*
* V 4 L 2 D R I V E R H E L P E R A P I
*
*/
/*
* Video Standard Operations (contributed by Michael Schimek)
*/
/* Helper functions for control handling */
/* Fill in a struct v4l2_queryctrl */
int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 _min, s32 _max, s32 _step, s32 _def)
{
const char *name;
s64 min = _min;
s64 max = _max;
u64 step = _step;
s64 def = _def;
v4l2_ctrl_fill(qctrl->id, &name, &qctrl->type,
&min, &max, &step, &def, &qctrl->flags);
if (name == NULL)
return -EINVAL;
qctrl->minimum = min;
qctrl->maximum = max;
qctrl->step = step;
qctrl->default_value = def;
qctrl->reserved[0] = qctrl->reserved[1] = 0;
strlcpy(qctrl->name, name, sizeof(qctrl->name));
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 141 | 95.27% | 6 | 75.00% |
eduardo valentin | eduardo valentin | 4 | 2.70% | 1 | 12.50% |
mauro carvalho chehab | mauro carvalho chehab | 3 | 2.03% | 1 | 12.50% |
| Total | 148 | 100.00% | 8 | 100.00% |
EXPORT_SYMBOL(v4l2_ctrl_query_fill);
/* I2C Helper functions */
#if IS_ENABLED(CONFIG_I2C)
void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
const struct v4l2_subdev_ops *ops)
{
v4l2_subdev_init(sd, ops);
sd->flags |= V4L2_SUBDEV_FL_IS_I2C;
/* the owner is the same as the i2c_client's driver owner */
sd->owner = client->dev.driver->owner;
sd->dev = &client->dev;
/* i2c_client and v4l2_subdev point to one another */
v4l2_set_subdevdata(sd, client);
i2c_set_clientdata(client, sd);
/* initialize name */
snprintf(sd->name, sizeof(sd->name), "%s %d-%04x",
client->dev.driver->name, i2c_adapter_id(client->adapter),
client->addr);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 94 | 87.85% | 2 | 50.00% |
guennadi liakhovetski | guennadi liakhovetski | 9 | 8.41% | 1 | 25.00% |
lars-peter clausen | lars-peter clausen | 4 | 3.74% | 1 | 25.00% |
| Total | 107 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
/* Load an i2c sub-device. */
struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, struct i2c_board_info *info,
const unsigned short *probe_addrs)
{
struct v4l2_subdev *sd = NULL;
struct i2c_client *client;
BUG_ON(!v4l2_dev);
request_module(I2C_MODULE_PREFIX "%s", info->type);
/* Create the i2c client */
if (info->addr == 0 && probe_addrs)
client = i2c_new_probed_device(adapter, info, probe_addrs,
NULL);
else
client = i2c_new_device(adapter, info);
/* Note: by loading the module first we are certain that c->driver
will be set if the driver was found. If the module was not loaded
first, then the i2c core tries to delay-load the module for us,
and then c->driver is still NULL until the module is finally
loaded. This delay-load mechanism doesn't work if other drivers
want to use the i2c device, so explicitly loading the module
is the best alternative. */
if (client == NULL || client->dev.driver == NULL)
goto error;
/* Lock the module so we can safely get the v4l2_subdev pointer */
if (!try_module_get(client->dev.driver->owner))
goto error;
sd = i2c_get_clientdata(client);
/* Register with the v4l2_device which increases the module's
use count as well. */
if (v4l2_device_register_subdev(v4l2_dev, sd))
sd = NULL;
/* Decrease the module use count to match the first try_module_get. */
module_put(client->dev.driver->owner);
error:
/* If we have a client but no subdev, then something went wrong and
we must unregister the client. */
if (client && sd == NULL)
i2c_unregister_device(client);
return sd;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 160 | 89.89% | 1 | 25.00% |
laurent pinchart | laurent pinchart | 10 | 5.62% | 1 | 25.00% |
lars-peter clausen | lars-peter clausen | 6 | 3.37% | 1 | 25.00% |
jean delvare | jean delvare | 2 | 1.12% | 1 | 25.00% |
| Total | 178 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board);
struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, const char *client_type,
u8 addr, const unsigned short *probe_addrs)
{
struct i2c_board_info info;
/* Setup the i2c board info with the device type and
the device address. */
memset(&info, 0, sizeof(info));
strlcpy(info.type, client_type, sizeof(info.type));
info.addr = addr;
return v4l2_i2c_new_subdev_board(v4l2_dev, adapter, &info, probe_addrs);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 84 | 100.00% | 2 | 100.00% |
| Total | 84 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
/* Return i2c client address of v4l2_subdev. */
unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
return client ? client->addr : I2C_CLIENT_END;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 30 | 100.00% | 1 | 100.00% |
| Total | 30 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_addr);
/* Return a list of I2C tuner addresses to probe. Use only if the tuner
addresses are unknown. */
const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
{
static const unsigned short radio_addrs[] = {
#if IS_ENABLED(CONFIG_MEDIA_TUNER_TEA5761)
0x10,
#endif
0x60,
I2C_CLIENT_END
};
static const unsigned short demod_addrs[] = {
0x42, 0x43, 0x4a, 0x4b,
I2C_CLIENT_END
};
static const unsigned short tv_addrs[] = {
0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
0x60, 0x61, 0x62, 0x63, 0x64,
I2C_CLIENT_END
};
switch (type) {
case ADDRS_RADIO:
return radio_addrs;
case ADDRS_DEMOD:
return demod_addrs;
case ADDRS_TV:
return tv_addrs;
case ADDRS_TV_WITH_DEMOD:
return tv_addrs + 4;
}
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 118 | 99.16% | 1 | 50.00% |
peter senna tschudin | peter senna tschudin | 1 | 0.84% | 1 | 50.00% |
| Total | 119 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs);
#endif /* defined(CONFIG_I2C) */
#if defined(CONFIG_SPI)
/* Load an spi sub-device. */
void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
const struct v4l2_subdev_ops *ops)
{
v4l2_subdev_init(sd, ops);
sd->flags |= V4L2_SUBDEV_FL_IS_SPI;
/* the owner is the same as the spi_device's driver owner */
sd->owner = spi->dev.driver->owner;
sd->dev = &spi->dev;
/* spi_device and v4l2_subdev point to one another */
v4l2_set_subdevdata(sd, spi);
spi_set_drvdata(spi, sd);
/* initialize name */
strlcpy(sd->name, spi->dev.driver->name, sizeof(sd->name));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
dmitry belimov | dmitry belimov | 85 | 90.43% | 1 | 50.00% |
guennadi liakhovetski | guennadi liakhovetski | 9 | 9.57% | 1 | 50.00% |
| Total | 94 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_spi_subdev_init);
struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
struct spi_master *master, struct spi_board_info *info)
{
struct v4l2_subdev *sd = NULL;
struct spi_device *spi = NULL;
BUG_ON(!v4l2_dev);
if (info->modalias[0])
request_module(info->modalias);
spi = spi_new_device(master, info);
if (spi == NULL || spi->dev.driver == NULL)
goto error;
if (!try_module_get(spi->dev.driver->owner))
goto error;
sd = spi_get_drvdata(spi);
/* Register with the v4l2_device which increases the module's
use count as well. */
if (v4l2_device_register_subdev(v4l2_dev, sd))
sd = NULL;
/* Decrease the module use count to match the first try_module_get. */
module_put(spi->dev.driver->owner);
error:
/* If we have a client but no subdev, then something went wrong and
we must unregister the client. */
if (spi && sd == NULL)
spi_unregister_device(spi);
return sd;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
dmitry belimov | dmitry belimov | 150 | 98.04% | 1 | 50.00% |
alan cox | alan cox | 3 | 1.96% | 1 | 50.00% |
| Total | 153 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_spi_new_subdev);
#endif /* defined(CONFIG_SPI) */
/* Clamp x to be between min and max, aligned to a multiple of 2^align. min
* and max don't have to be aligned, but there must be at least one valid
* value. E.g., min=17,max=31,align=4 is not allowed as there are no multiples
* of 16 between 17 and 31. */
static unsigned int clamp_align(unsigned int x, unsigned int min,
unsigned int max, unsigned int align)
{
/* Bits that must be zero to be aligned */
unsigned int mask = ~((1 << align) - 1);
/* Clamp to aligned min and max */
x = clamp(x, (min + ~mask) & mask, max & mask);
/* Round to nearest aligned value */
if (align)
x = (x + (1 << (align - 1))) & mask;
return x;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
trent piepho | trent piepho | 65 | 75.58% | 1 | 50.00% |
maciej matraszek | maciej matraszek | 21 | 24.42% | 1 | 50.00% |
| Total | 86 | 100.00% | 2 | 100.00% |
/* Bound an image to have a width between wmin and wmax, and height between
* hmin and hmax, inclusive. Additionally, the width will be a multiple of
* 2^walign, the height will be a multiple of 2^halign, and the overall size
* (width*height) will be a multiple of 2^salign. The image may be shrunk
* or enlarged to fit the alignment constraints.
*
* The width or height maximum must not be smaller than the corresponding
* minimum. The alignments must not be so high there are no possible image
* sizes within the allowed bounds. wmin and hmin must be at least 1
* (don't use 0). If you don't care about a certain alignment, specify 0,
* as 2^0 is 1 and one byte alignment is equivalent to no alignment. If
* you only want to adjust downward, specify a maximum that's the same as
* the initial value.
*/
void v4l_bound_align_image(u32 *w, unsigned int wmin, unsigned int wmax,
unsigned int walign,
u32 *h, unsigned int hmin, unsigned int hmax,
unsigned int halign, unsigned int salign)
{
*w = clamp_align(*w, wmin, wmax, walign);
*h = clamp_align(*h, hmin, hmax, halign);
/* Usually we don't need to align the size and are done now. */
if (!salign)
return;
/* How much alignment do we have? */
walign = __ffs(*w);
halign = __ffs(*h);
/* Enough to satisfy the image alignment? */
if (walign + halign < salign) {
/* Max walign where there is still a valid width */
unsigned int wmaxa = __fls(wmax ^ (wmin - 1));
/* Max halign where there is still a valid height */
unsigned int hmaxa = __fls(hmax ^ (hmin - 1));
/* up the smaller alignment until we have enough */
do {
if (halign >= hmaxa ||
(walign <= halign && walign < wmaxa)) {
*w = clamp_align(*w, wmin, wmax, walign + 1);
walign = __ffs(*w);
} else {
*h = clamp_align(*h, hmin, hmax, halign + 1);
halign = __ffs(*h);
}
} while (halign + walign < salign);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
trent piepho | trent piepho | 222 | 100.00% | 1 | 100.00% |
| Total | 222 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(v4l_bound_align_image);
const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
const struct v4l2_discrete_probe *probe,
s32 width, s32 height)
{
int i;
u32 error, min_error = UINT_MAX;
const struct v4l2_frmsize_discrete *size, *best = NULL;
if (!probe)
return best;
for (i = 0, size = probe->sizes; i < probe->num_sizes; i++, size++) {
error = abs(size->width - width) + abs(size->height - height);
if (error < min_error) {
min_error = error;
best = size;
}
if (!error)
break;
}
return best;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
guennadi liakhovetski | guennadi liakhovetski | 117 | 97.50% | 1 | 50.00% |
hans verkuil | hans verkuil | 3 | 2.50% | 1 | 50.00% |
| Total | 120 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_find_nearest_format);
void v4l2_get_timestamp(struct timeval *tv)
{
struct timespec ts;
ktime_get_ts(&ts);
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sakari ailus | sakari ailus | 38 | 100.00% | 1 | 100.00% |
| Total | 38 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
hans verkuil | hans verkuil | 673 | 43.79% | 18 | 46.15% |
trent piepho | trent piepho | 297 | 19.32% | 2 | 5.13% |
dmitry belimov | dmitry belimov | 265 | 17.24% | 1 | 2.56% |
guennadi liakhovetski | guennadi liakhovetski | 140 | 9.11% | 2 | 5.13% |
gerd knorr | gerd knorr | 47 | 3.06% | 1 | 2.56% |
sakari ailus | sakari ailus | 43 | 2.80% | 1 | 2.56% |
maciej matraszek | maciej matraszek | 21 | 1.37% | 1 | 2.56% |
mauro carvalho chehab | mauro carvalho chehab | 14 | 0.91% | 3 | 7.69% |
laurent pinchart | laurent pinchart | 10 | 0.65% | 1 | 2.56% |
lars-peter clausen | lars-peter clausen | 10 | 0.65% | 1 | 2.56% |
eduardo valentin | eduardo valentin | 4 | 0.26% | 1 | 2.56% |
alan cox | alan cox | 4 | 0.26% | 2 | 5.13% |
michael krufky | michael krufky | 3 | 0.20% | 1 | 2.56% |
jean delvare | jean delvare | 2 | 0.13% | 1 | 2.56% |
peter senna tschudin | peter senna tschudin | 2 | 0.13% | 1 | 2.56% |
michael jones | michael jones | 1 | 0.07% | 1 | 2.56% |
jan engelhardt | jan engelhardt | 1 | 0.07% | 1 | 2.56% |
| Total | 1537 | 100.00% | 39 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.