Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
0ba2aeb6 7d6bc608

+94 -66
+1 -1
drivers/media/i2c/mt9v032.c
··· 931 931 932 932 mt9v032->pixel_rate = 933 933 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); 935 935 936 936 if (pdata && pdata->link_freqs) { 937 937 unsigned int def = 0;
+2 -2
drivers/media/i2c/smiapp/smiapp-core.c
··· 533 533 534 534 sensor->pixel_rate_parray = v4l2_ctrl_new_std( 535 535 &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); 537 537 538 538 if (sensor->pixel_array->ctrl_handler.error) { 539 539 dev_err(&client->dev, ··· 562 562 563 563 sensor->pixel_rate_csi = v4l2_ctrl_new_std( 564 564 &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); 566 566 567 567 if (sensor->src->ctrl_handler.error) { 568 568 dev_err(&client->dev,
+4 -1
drivers/media/platform/vivi.c
··· 1236 1236 .id = VIVI_CID_CUSTOM_BASE + 2, 1237 1237 .name = "Integer 32 Bits", 1238 1238 .type = V4L2_CTRL_TYPE_INTEGER, 1239 - .min = 0x80000000, 1239 + .min = -0x80000000LL, 1240 1240 .max = 0x7fffffff, 1241 1241 .step = 1, 1242 1242 }; ··· 1246 1246 .id = VIVI_CID_CUSTOM_BASE + 3, 1247 1247 .name = "Integer 64 Bits", 1248 1248 .type = V4L2_CTRL_TYPE_INTEGER64, 1249 + .min = LLONG_MIN, 1250 + .max = LLONG_MAX, 1251 + .step = 1, 1249 1252 }; 1250 1253 1251 1254 static const char * const vivi_ctrl_menu_strings[] = {
+5 -1
drivers/media/v4l2-core/v4l2-common.c
··· 111 111 EXPORT_SYMBOL(v4l2_ctrl_check); 112 112 113 113 /* 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) 115 115 { 116 116 const char *name; 117 + s64 min = _min; 118 + s64 max = _max; 119 + u64 step = _step; 120 + s64 def = _def; 117 121 118 122 v4l2_ctrl_fill(qctrl->id, &name, &qctrl->type, 119 123 &min, &max, &step, &def, &qctrl->flags);
+57 -36
drivers/media/v4l2-core/v4l2-ctrls.c
··· 877 877 EXPORT_SYMBOL(v4l2_ctrl_get_name); 878 878 879 879 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) 881 881 { 882 882 *name = v4l2_ctrl_get_name(id); 883 883 *flags = 0; ··· 1041 1041 *type = V4L2_CTRL_TYPE_INTEGER; 1042 1042 *flags |= V4L2_CTRL_FLAG_READ_ONLY; 1043 1043 break; 1044 - case V4L2_CID_MPEG_VIDEO_DEC_FRAME: 1045 1044 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; 1048 1058 case V4L2_CID_PIXEL_RATE: 1049 1059 *type = V4L2_CTRL_TYPE_INTEGER64; 1050 1060 *flags |= V4L2_CTRL_FLAG_READ_ONLY; 1051 - *min = *max = *step = *def = 0; 1052 1061 break; 1053 1062 default: 1054 1063 *type = V4L2_CTRL_TYPE_INTEGER; ··· 1361 1352 1362 1353 /* Control range checking */ 1363 1354 static int check_range(enum v4l2_ctrl_type type, 1364 - s32 min, s32 max, u32 step, s32 def) 1355 + s64 min, s64 max, u64 step, s64 def) 1365 1356 { 1366 1357 switch (type) { 1367 1358 case V4L2_CTRL_TYPE_BOOLEAN: ··· 1369 1360 return -ERANGE; 1370 1361 /* fall through */ 1371 1362 case V4L2_CTRL_TYPE_INTEGER: 1372 - if (step <= 0 || min > max || def < min || def > max) 1363 + case V4L2_CTRL_TYPE_INTEGER64: 1364 + if (step == 0 || min > max || def < min || def > max) 1373 1365 return -ERANGE; 1374 1366 return 0; 1375 1367 case V4L2_CTRL_TYPE_BITMASK: ··· 1395 1385 } 1396 1386 } 1397 1387 1388 + /* Round towards the closest legal value */ 1389 + #define ROUND_TO_RANGE(val, offset_type, ctrl) \ 1390 + ({ \ 1391 + offset_type offset; \ 1392 + val += (ctrl)->step / 2; \ 1393 + val = clamp_t(typeof(val), val, \ 1394 + (ctrl)->minimum, (ctrl)->maximum); \ 1395 + offset = (val) - (ctrl)->minimum; \ 1396 + offset = (ctrl)->step * (offset / (ctrl)->step); \ 1397 + val = (ctrl)->minimum + offset; \ 1398 + 0; \ 1399 + }) 1400 + 1398 1401 /* Validate a new control */ 1399 1402 static int validate_new(const struct v4l2_ctrl *ctrl, 1400 1403 struct v4l2_ext_control *c) 1401 1404 { 1402 1405 size_t len; 1403 - u32 offset; 1404 - s32 val; 1405 1406 1406 1407 switch (ctrl->type) { 1407 1408 case V4L2_CTRL_TYPE_INTEGER: 1408 - /* Round towards the closest legal value */ 1409 - val = c->value + ctrl->step / 2; 1410 - val = clamp(val, ctrl->minimum, ctrl->maximum); 1411 - offset = val - ctrl->minimum; 1412 - offset = ctrl->step * (offset / ctrl->step); 1413 - c->value = ctrl->minimum + offset; 1414 - return 0; 1409 + return ROUND_TO_RANGE(*(s32 *)&c->value, u32, ctrl); 1410 + case V4L2_CTRL_TYPE_INTEGER64: 1411 + return ROUND_TO_RANGE(*(s64 *)&c->value64, u64, ctrl); 1415 1412 1416 1413 case V4L2_CTRL_TYPE_BOOLEAN: 1417 1414 c->value = !!c->value; ··· 1442 1425 case V4L2_CTRL_TYPE_BUTTON: 1443 1426 case V4L2_CTRL_TYPE_CTRL_CLASS: 1444 1427 c->value = 0; 1445 - return 0; 1446 - 1447 - case V4L2_CTRL_TYPE_INTEGER64: 1448 1428 return 0; 1449 1429 1450 1430 case V4L2_CTRL_TYPE_STRING: ··· 1667 1653 static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, 1668 1654 const struct v4l2_ctrl_ops *ops, 1669 1655 u32 id, const char *name, enum v4l2_ctrl_type type, 1670 - s32 min, s32 max, u32 step, s32 def, 1656 + s64 min, s64 max, u64 step, s64 def, 1671 1657 u32 flags, const char * const *qmenu, 1672 1658 const s64 *qmenu_int, void *priv) 1673 1659 { ··· 1752 1738 const s64 *qmenu_int = cfg->qmenu_int; 1753 1739 enum v4l2_ctrl_type type = cfg->type; 1754 1740 u32 flags = cfg->flags; 1755 - s32 min = cfg->min; 1756 - s32 max = cfg->max; 1757 - u32 step = cfg->step; 1758 - s32 def = cfg->def; 1741 + s64 min = cfg->min; 1742 + s64 max = cfg->max; 1743 + u64 step = cfg->step; 1744 + s64 def = cfg->def; 1759 1745 1760 1746 if (name == NULL) 1761 1747 v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step, ··· 1788 1774 /* Helper function for standard non-menu controls */ 1789 1775 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, 1790 1776 const struct v4l2_ctrl_ops *ops, 1791 - u32 id, s32 min, s32 max, u32 step, s32 def) 1777 + u32 id, s64 min, s64 max, u64 step, s64 def) 1792 1778 { 1793 1779 const char *name; 1794 1780 enum v4l2_ctrl_type type; ··· 1808 1794 /* Helper function for standard menu controls */ 1809 1795 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, 1810 1796 const struct v4l2_ctrl_ops *ops, 1811 - u32 id, s32 max, s32 mask, s32 def) 1797 + u32 id, u8 _max, u64 mask, u8 _def) 1812 1798 { 1813 1799 const char * const *qmenu = NULL; 1814 1800 const s64 *qmenu_int = NULL; 1815 1801 unsigned int qmenu_int_len = 0; 1816 1802 const char *name; 1817 1803 enum v4l2_ctrl_type type; 1818 - s32 min; 1819 - s32 step; 1804 + s64 min; 1805 + s64 max = _max; 1806 + s64 def = _def; 1807 + u64 step; 1820 1808 u32 flags; 1821 1809 1822 1810 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); ··· 1839 1823 1840 1824 /* Helper function for standard menu controls with driver defined menu */ 1841 1825 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, 1842 - const struct v4l2_ctrl_ops *ops, u32 id, s32 max, 1843 - s32 mask, s32 def, const char * const *qmenu) 1826 + const struct v4l2_ctrl_ops *ops, u32 id, u8 _max, 1827 + u64 mask, u8 _def, const char * const *qmenu) 1844 1828 { 1845 1829 enum v4l2_ctrl_type type; 1846 1830 const char *name; 1847 1831 u32 flags; 1848 - s32 step; 1849 - s32 min; 1832 + u64 step; 1833 + s64 min; 1834 + s64 max = _max; 1835 + s64 def = _def; 1850 1836 1851 1837 /* v4l2_ctrl_new_std_menu_items() should only be called for 1852 1838 * standard controls without a standard menu. ··· 1872 1854 /* Helper function for standard integer menu controls */ 1873 1855 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, 1874 1856 const struct v4l2_ctrl_ops *ops, 1875 - u32 id, s32 max, s32 def, const s64 *qmenu_int) 1857 + u32 id, u8 _max, u8 _def, const s64 *qmenu_int) 1876 1858 { 1877 1859 const char *name; 1878 1860 enum v4l2_ctrl_type type; 1879 - s32 min; 1880 - s32 step; 1861 + s64 min; 1862 + u64 step; 1863 + s64 max = _max; 1864 + s64 def = _def; 1881 1865 u32 flags; 1882 1866 1883 1867 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); ··· 2907 2887 EXPORT_SYMBOL(v4l2_ctrl_notify); 2908 2888 2909 2889 int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 2910 - s32 min, s32 max, u32 step, s32 def) 2890 + s64 min, s64 max, u64 step, s64 def) 2911 2891 { 2912 2892 int ret = check_range(ctrl->type, min, max, step, def); 2913 2893 struct v4l2_ext_control c; 2914 2894 2915 2895 switch (ctrl->type) { 2916 2896 case V4L2_CTRL_TYPE_INTEGER: 2897 + case V4L2_CTRL_TYPE_INTEGER64: 2917 2898 case V4L2_CTRL_TYPE_BOOLEAN: 2918 2899 case V4L2_CTRL_TYPE_MENU: 2919 2900 case V4L2_CTRL_TYPE_INTEGER_MENU:
+1 -1
drivers/staging/media/msi3101/msi001.c
··· 381 381 382 382 int ret; 383 383 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", 385 385 __func__, ctrl->id, ctrl->name, ctrl->val, 386 386 ctrl->minimum, ctrl->maximum, ctrl->step); 387 387
+3 -3
drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
··· 1337 1337 int ret; 1338 1338 1339 1339 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", 1341 1341 __func__, ctrl->id, ctrl->name, ctrl->val, 1342 1342 ctrl->minimum, ctrl->maximum, ctrl->step); 1343 1343 ··· 1350 1350 s32 val = s->f_adc + s->bandwidth->step / 2; 1351 1351 u32 offset; 1352 1352 1353 - val = clamp(val, s->bandwidth->minimum, 1354 - s->bandwidth->maximum); 1353 + val = clamp_t(s32, val, s->bandwidth->minimum, 1354 + s->bandwidth->maximum); 1355 1355 offset = val - s->bandwidth->minimum; 1356 1356 offset = s->bandwidth->step * 1357 1357 (offset / s->bandwidth->step);
+21 -21
include/media/v4l2-ctrls.h
··· 131 131 u32 id; 132 132 const char *name; 133 133 enum v4l2_ctrl_type type; 134 - s32 minimum, maximum, default_value; 134 + s64 minimum, maximum, default_value; 135 135 union { 136 - u32 step; 137 - u32 menu_skip_mask; 136 + u64 step; 137 + u64 menu_skip_mask; 138 138 }; 139 139 union { 140 140 const char * const *qmenu; ··· 216 216 * @menu_skip_mask: The control's skip mask for menu controls. This makes it 217 217 * easy to skip menu items that are not valid. If bit X is set, 218 218 * then menu item X is skipped. Of course, this only works for 219 - * menus with <= 32 menu items. There are no menus that come 219 + * menus with <= 64 menu items. There are no menus that come 220 220 * close to that number, so this is OK. Should we ever need more, 221 - * then this will have to be extended to a u64 or a bit array. 221 + * then this will have to be extended to a bit array. 222 222 * @qmenu: A const char * array for all menu items. Array entries that are 223 223 * empty strings ("") correspond to non-existing menu items (this 224 224 * is in addition to the menu_skip_mask above). The last entry ··· 231 231 u32 id; 232 232 const char *name; 233 233 enum v4l2_ctrl_type type; 234 - s32 min; 235 - s32 max; 236 - u32 step; 237 - s32 def; 234 + s64 min; 235 + s64 max; 236 + u64 step; 237 + s64 def; 238 238 u32 flags; 239 - u32 menu_skip_mask; 239 + u64 menu_skip_mask; 240 240 const char * const *qmenu; 241 241 const s64 *qmenu_int; 242 242 unsigned int is_private:1; ··· 257 257 * control framework this function will no longer be exported. 258 258 */ 259 259 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 260 - s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags); 260 + s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags); 261 261 262 262 263 263 /** v4l2_ctrl_handler_init_class() - Initialize the control handler. ··· 362 362 */ 363 363 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, 364 364 const struct v4l2_ctrl_ops *ops, 365 - u32 id, s32 min, s32 max, u32 step, s32 def); 365 + u32 id, s64 min, s64 max, u64 step, s64 def); 366 366 367 367 /** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control. 368 368 * @hdl: The control handler. ··· 372 372 * @mask: The control's skip mask for menu controls. This makes it 373 373 * easy to skip menu items that are not valid. If bit X is set, 374 374 * then menu item X is skipped. Of course, this only works for 375 - * menus with <= 32 menu items. There are no menus that come 375 + * menus with <= 64 menu items. There are no menus that come 376 376 * close to that number, so this is OK. Should we ever need more, 377 - * then this will have to be extended to a u64 or a bit array. 377 + * then this will have to be extended to a bit array. 378 378 * @def: The control's default value. 379 379 * 380 380 * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value ··· 384 384 */ 385 385 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, 386 386 const struct v4l2_ctrl_ops *ops, 387 - u32 id, s32 max, s32 mask, s32 def); 387 + u32 id, u8 max, u64 mask, u8 def); 388 388 389 389 /** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control 390 390 * with driver specific menu. ··· 395 395 * @mask: The control's skip mask for menu controls. This makes it 396 396 * easy to skip menu items that are not valid. If bit X is set, 397 397 * then menu item X is skipped. Of course, this only works for 398 - * menus with <= 32 menu items. There are no menus that come 398 + * menus with <= 64 menu items. There are no menus that come 399 399 * close to that number, so this is OK. Should we ever need more, 400 - * then this will have to be extended to a u64 or a bit array. 400 + * then this will have to be extended to a bit array. 401 401 * @def: The control's default value. 402 402 * @qmenu: The new menu. 403 403 * ··· 406 406 * 407 407 */ 408 408 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, 409 - const struct v4l2_ctrl_ops *ops, u32 id, s32 max, 410 - s32 mask, s32 def, const char * const *qmenu); 409 + const struct v4l2_ctrl_ops *ops, u32 id, u8 max, 410 + u64 mask, u8 def, const char * const *qmenu); 411 411 412 412 /** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 413 413 * @hdl: The control handler. ··· 424 424 */ 425 425 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, 426 426 const struct v4l2_ctrl_ops *ops, 427 - u32 id, s32 max, s32 def, const s64 *qmenu_int); 427 + u32 id, u8 max, u8 def, const s64 *qmenu_int); 428 428 429 429 /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. 430 430 * @hdl: The control handler. ··· 560 560 * take the lock itself. 561 561 */ 562 562 int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 563 - s32 min, s32 max, u32 step, s32 def); 563 + s64 min, s64 max, u64 step, s64 def); 564 564 565 565 /** v4l2_ctrl_lock() - Helper function to lock the handler 566 566 * associated with the control.