Skip to content

Commit 0ba2aeb

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] v4l2-ctrls: increase internal min/max/step/def to 64 bit
While VIDIOC_QUERYCTRL is limited to 32 bit min/max/step/def values for controls, the upcoming VIDIOC_QUERY_EXT_CTRL isn't. So increase the internal representation to 64 bits in preparation. Because of these changes the msi3101 driver has been modified slightly to fix a formatting issue (%d becomes %lld), vivi had to be modified as well to cope with the new 64-bit min/max values and the PIXEL_RATE control in a few sensor drivers required proper min/max/def values. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
1 parent 7d6bc60 commit 0ba2aeb

8 files changed

Lines changed: 94 additions & 66 deletions

File tree

‎drivers/media/i2c/mt9v032.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ static int mt9v032_probe(struct i2c_client *client,
931931

932932
mt9v032->pixel_rate =
933933
v4l2_ctrl_new_std(&mt9v032->ctrls, &mt9v032_ctrl_ops,
934-
V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
934+
V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1, 1);
935935

936936
if (pdata && pdata->link_freqs) {
937937
unsigned int def = 0;

‎drivers/media/i2c/smiapp/smiapp-core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static int smiapp_init_controls(struct smiapp_sensor *sensor)
533533

534534
sensor->pixel_rate_parray = v4l2_ctrl_new_std(
535535
&sensor->pixel_array->ctrl_handler, &smiapp_ctrl_ops,
536-
V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
536+
V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1, 1);
537537

538538
if (sensor->pixel_array->ctrl_handler.error) {
539539
dev_err(&client->dev,
@@ -562,7 +562,7 @@ static int smiapp_init_controls(struct smiapp_sensor *sensor)
562562

563563
sensor->pixel_rate_csi = v4l2_ctrl_new_std(
564564
&sensor->src->ctrl_handler, &smiapp_ctrl_ops,
565-
V4L2_CID_PIXEL_RATE, 0, 0, 1, 0);
565+
V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1, 1);
566566

567567
if (sensor->src->ctrl_handler.error) {
568568
dev_err(&client->dev,

‎drivers/media/platform/vivi.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ static const struct v4l2_ctrl_config vivi_ctrl_int32 = {
12361236
.id = VIVI_CID_CUSTOM_BASE + 2,
12371237
.name = "Integer 32 Bits",
12381238
.type = V4L2_CTRL_TYPE_INTEGER,
1239-
.min = 0x80000000,
1239+
.min = -0x80000000LL,
12401240
.max = 0x7fffffff,
12411241
.step = 1,
12421242
};
@@ -1246,6 +1246,9 @@ static const struct v4l2_ctrl_config vivi_ctrl_int64 = {
12461246
.id = VIVI_CID_CUSTOM_BASE + 3,
12471247
.name = "Integer 64 Bits",
12481248
.type = V4L2_CTRL_TYPE_INTEGER64,
1249+
.min = LLONG_MIN,
1250+
.max = LLONG_MAX,
1251+
.step = 1,
12491252
};
12501253

12511254
static const char * const vivi_ctrl_menu_strings[] = {

‎drivers/media/v4l2-core/v4l2-common.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
111111
EXPORT_SYMBOL(v4l2_ctrl_check);
112112

113113
/* Fill in a struct v4l2_queryctrl */
114-
int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
114+
int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 _min, s32 _max, s32 _step, s32 _def)
115115
{
116116
const char *name;
117+
s64 min = _min;
118+
s64 max = _max;
119+
u64 step = _step;
120+
s64 def = _def;
117121

118122
v4l2_ctrl_fill(qctrl->id, &name, &qctrl->type,
119123
&min, &max, &step, &def, &qctrl->flags);

‎drivers/media/v4l2-core/v4l2-ctrls.c‎

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ const char *v4l2_ctrl_get_name(u32 id)
877877
EXPORT_SYMBOL(v4l2_ctrl_get_name);
878878

879879
void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
880-
s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags)
880+
s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags)
881881
{
882882
*name = v4l2_ctrl_get_name(id);
883883
*flags = 0;
@@ -1041,14 +1041,23 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
10411041
*type = V4L2_CTRL_TYPE_INTEGER;
10421042
*flags |= V4L2_CTRL_FLAG_READ_ONLY;
10431043
break;
1044-
case V4L2_CID_MPEG_VIDEO_DEC_FRAME:
10451044
case V4L2_CID_MPEG_VIDEO_DEC_PTS:
1046-
*flags |= V4L2_CTRL_FLAG_VOLATILE;
1047-
/* Fall through */
1045+
*type = V4L2_CTRL_TYPE_INTEGER64;
1046+
*flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY;
1047+
*min = *def = 0;
1048+
*max = 0x1ffffffffLL;
1049+
*step = 1;
1050+
break;
1051+
case V4L2_CID_MPEG_VIDEO_DEC_FRAME:
1052+
*type = V4L2_CTRL_TYPE_INTEGER64;
1053+
*flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY;
1054+
*min = *def = 0;
1055+
*max = 0x7fffffffffffffffLL;
1056+
*step = 1;
1057+
break;
10481058
case V4L2_CID_PIXEL_RATE:
10491059
*type = V4L2_CTRL_TYPE_INTEGER64;
10501060
*flags |= V4L2_CTRL_FLAG_READ_ONLY;
1051-
*min = *max = *step = *def = 0;
10521061
break;
10531062
default:
10541063
*type = V4L2_CTRL_TYPE_INTEGER;
@@ -1352,15 +1361,16 @@ static int cluster_changed(struct v4l2_ctrl *master)
13521361

13531362
/* Control range checking */
13541363
static int check_range(enum v4l2_ctrl_type type,
1355-
s32 min, s32 max, u32 step, s32 def)
1364+
s64 min, s64 max, u64 step, s64 def)
13561365
{
13571366
switch (type) {
13581367
case V4L2_CTRL_TYPE_BOOLEAN:
13591368
if (step != 1 || max > 1 || min < 0)
13601369
return -ERANGE;
13611370
/* fall through */
13621371
case V4L2_CTRL_TYPE_INTEGER:
1363-
if (step <= 0 || min > max || def < min || def > max)
1372+
case V4L2_CTRL_TYPE_INTEGER64:
1373+
if (step == 0 || min > max || def < min || def > max)
13641374
return -ERANGE;
13651375
return 0;
13661376
case V4L2_CTRL_TYPE_BITMASK:
@@ -1385,23 +1395,30 @@ static int check_range(enum v4l2_ctrl_type type,
13851395
}
13861396
}
13871397

1398+
/* Round towards the closest legal value */
1399+
#define ROUND_TO_RANGE(val, offset_type, ctrl) \
1400+
({ \
1401+
offset_type offset; \
1402+
val += (ctrl)->step / 2; \
1403+
val = clamp_t(typeof(val), val, \
1404+
(ctrl)->minimum, (ctrl)->maximum); \
1405+
offset = (val) - (ctrl)->minimum; \
1406+
offset = (ctrl)->step * (offset / (ctrl)->step); \
1407+
val = (ctrl)->minimum + offset; \
1408+
0; \
1409+
})
1410+
13881411
/* Validate a new control */
13891412
static int validate_new(const struct v4l2_ctrl *ctrl,
13901413
struct v4l2_ext_control *c)
13911414
{
13921415
size_t len;
1393-
u32 offset;
1394-
s32 val;
13951416

13961417
switch (ctrl->type) {
13971418
case V4L2_CTRL_TYPE_INTEGER:
1398-
/* Round towards the closest legal value */
1399-
val = c->value + ctrl->step / 2;
1400-
val = clamp(val, ctrl->minimum, ctrl->maximum);
1401-
offset = val - ctrl->minimum;
1402-
offset = ctrl->step * (offset / ctrl->step);
1403-
c->value = ctrl->minimum + offset;
1404-
return 0;
1419+
return ROUND_TO_RANGE(*(s32 *)&c->value, u32, ctrl);
1420+
case V4L2_CTRL_TYPE_INTEGER64:
1421+
return ROUND_TO_RANGE(*(s64 *)&c->value64, u64, ctrl);
14051422

14061423
case V4L2_CTRL_TYPE_BOOLEAN:
14071424
c->value = !!c->value;
@@ -1427,9 +1444,6 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
14271444
c->value = 0;
14281445
return 0;
14291446

1430-
case V4L2_CTRL_TYPE_INTEGER64:
1431-
return 0;
1432-
14331447
case V4L2_CTRL_TYPE_STRING:
14341448
len = strlen(c->string);
14351449
if (len < ctrl->minimum)
@@ -1653,7 +1667,7 @@ static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
16531667
static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
16541668
const struct v4l2_ctrl_ops *ops,
16551669
u32 id, const char *name, enum v4l2_ctrl_type type,
1656-
s32 min, s32 max, u32 step, s32 def,
1670+
s64 min, s64 max, u64 step, s64 def,
16571671
u32 flags, const char * const *qmenu,
16581672
const s64 *qmenu_int, void *priv)
16591673
{
@@ -1738,10 +1752,10 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
17381752
const s64 *qmenu_int = cfg->qmenu_int;
17391753
enum v4l2_ctrl_type type = cfg->type;
17401754
u32 flags = cfg->flags;
1741-
s32 min = cfg->min;
1742-
s32 max = cfg->max;
1743-
u32 step = cfg->step;
1744-
s32 def = cfg->def;
1755+
s64 min = cfg->min;
1756+
s64 max = cfg->max;
1757+
u64 step = cfg->step;
1758+
s64 def = cfg->def;
17451759

17461760
if (name == NULL)
17471761
v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step,
@@ -1774,7 +1788,7 @@ EXPORT_SYMBOL(v4l2_ctrl_new_custom);
17741788
/* Helper function for standard non-menu controls */
17751789
struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
17761790
const struct v4l2_ctrl_ops *ops,
1777-
u32 id, s32 min, s32 max, u32 step, s32 def)
1791+
u32 id, s64 min, s64 max, u64 step, s64 def)
17781792
{
17791793
const char *name;
17801794
enum v4l2_ctrl_type type;
@@ -1794,15 +1808,17 @@ EXPORT_SYMBOL(v4l2_ctrl_new_std);
17941808
/* Helper function for standard menu controls */
17951809
struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
17961810
const struct v4l2_ctrl_ops *ops,
1797-
u32 id, s32 max, s32 mask, s32 def)
1811+
u32 id, u8 _max, u64 mask, u8 _def)
17981812
{
17991813
const char * const *qmenu = NULL;
18001814
const s64 *qmenu_int = NULL;
18011815
unsigned int qmenu_int_len = 0;
18021816
const char *name;
18031817
enum v4l2_ctrl_type type;
1804-
s32 min;
1805-
s32 step;
1818+
s64 min;
1819+
s64 max = _max;
1820+
s64 def = _def;
1821+
u64 step;
18061822
u32 flags;
18071823

18081824
v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
@@ -1823,14 +1839,16 @@ EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
18231839

18241840
/* Helper function for standard menu controls with driver defined menu */
18251841
struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
1826-
const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
1827-
s32 mask, s32 def, const char * const *qmenu)
1842+
const struct v4l2_ctrl_ops *ops, u32 id, u8 _max,
1843+
u64 mask, u8 _def, const char * const *qmenu)
18281844
{
18291845
enum v4l2_ctrl_type type;
18301846
const char *name;
18311847
u32 flags;
1832-
s32 step;
1833-
s32 min;
1848+
u64 step;
1849+
s64 min;
1850+
s64 max = _max;
1851+
s64 def = _def;
18341852

18351853
/* v4l2_ctrl_new_std_menu_items() should only be called for
18361854
* standard controls without a standard menu.
@@ -1854,12 +1872,14 @@ EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items);
18541872
/* Helper function for standard integer menu controls */
18551873
struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
18561874
const struct v4l2_ctrl_ops *ops,
1857-
u32 id, s32 max, s32 def, const s64 *qmenu_int)
1875+
u32 id, u8 _max, u8 _def, const s64 *qmenu_int)
18581876
{
18591877
const char *name;
18601878
enum v4l2_ctrl_type type;
1861-
s32 min;
1862-
s32 step;
1879+
s64 min;
1880+
u64 step;
1881+
s64 max = _max;
1882+
s64 def = _def;
18631883
u32 flags;
18641884

18651885
v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
@@ -2887,13 +2907,14 @@ void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void
28872907
EXPORT_SYMBOL(v4l2_ctrl_notify);
28882908

28892909
int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
2890-
s32 min, s32 max, u32 step, s32 def)
2910+
s64 min, s64 max, u64 step, s64 def)
28912911
{
28922912
int ret = check_range(ctrl->type, min, max, step, def);
28932913
struct v4l2_ext_control c;
28942914

28952915
switch (ctrl->type) {
28962916
case V4L2_CTRL_TYPE_INTEGER:
2917+
case V4L2_CTRL_TYPE_INTEGER64:
28972918
case V4L2_CTRL_TYPE_BOOLEAN:
28982919
case V4L2_CTRL_TYPE_MENU:
28992920
case V4L2_CTRL_TYPE_INTEGER_MENU:

‎drivers/staging/media/msi3101/msi001.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static int msi001_s_ctrl(struct v4l2_ctrl *ctrl)
381381

382382
int ret;
383383
dev_dbg(&s->spi->dev,
384-
"%s: id=%d name=%s val=%d min=%d max=%d step=%d\n",
384+
"%s: id=%d name=%s val=%d min=%lld max=%lld step=%lld\n",
385385
__func__, ctrl->id, ctrl->name, ctrl->val,
386386
ctrl->minimum, ctrl->maximum, ctrl->step);
387387

‎drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
13371337
int ret;
13381338

13391339
dev_dbg(&s->udev->dev,
1340-
"%s: id=%d name=%s val=%d min=%d max=%d step=%d\n",
1340+
"%s: id=%d name=%s val=%d min=%lld max=%lld step=%lld\n",
13411341
__func__, ctrl->id, ctrl->name, ctrl->val,
13421342
ctrl->minimum, ctrl->maximum, ctrl->step);
13431343

@@ -1350,8 +1350,8 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
13501350
s32 val = s->f_adc + s->bandwidth->step / 2;
13511351
u32 offset;
13521352

1353-
val = clamp(val, s->bandwidth->minimum,
1354-
s->bandwidth->maximum);
1353+
val = clamp_t(s32, val, s->bandwidth->minimum,
1354+
s->bandwidth->maximum);
13551355
offset = val - s->bandwidth->minimum;
13561356
offset = s->bandwidth->step *
13571357
(offset / s->bandwidth->step);

0 commit comments

Comments
 (0)