0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef V4L2_COMMON_H_
0015 #define V4L2_COMMON_H_
0016
0017 #include <linux/time.h>
0018 #include <media/v4l2-dev.h>
0019
0020
0021
0022
0023 #define v4l_printk(level, name, adapter, addr, fmt, arg...) \
0024 printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
0025
0026 #define v4l_client_printk(level, client, fmt, arg...) \
0027 v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \
0028 (client)->addr, fmt , ## arg)
0029
0030 #define v4l_err(client, fmt, arg...) \
0031 v4l_client_printk(KERN_ERR, client, fmt , ## arg)
0032
0033 #define v4l_warn(client, fmt, arg...) \
0034 v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
0035
0036 #define v4l_info(client, fmt, arg...) \
0037 v4l_client_printk(KERN_INFO, client, fmt , ## arg)
0038
0039
0040
0041 #define v4l_dbg(level, debug, client, fmt, arg...) \
0042 do { \
0043 if (debug >= (level)) \
0044 v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
0045 } while (0)
0046
0047
0048 #define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...) \
0049 do { \
0050 if (__debug >= (__level)) \
0051 dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg); \
0052 } while (0)
0053
0054
0055
0056
0057 #define v4l2_printk(level, dev, fmt, arg...) \
0058 printk(level "%s: " fmt, (dev)->name , ## arg)
0059
0060 #define v4l2_err(dev, fmt, arg...) \
0061 v4l2_printk(KERN_ERR, dev, fmt , ## arg)
0062
0063 #define v4l2_warn(dev, fmt, arg...) \
0064 v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
0065
0066 #define v4l2_info(dev, fmt, arg...) \
0067 v4l2_printk(KERN_INFO, dev, fmt , ## arg)
0068
0069
0070
0071 #define v4l2_dbg(level, debug, dev, fmt, arg...) \
0072 do { \
0073 if (debug >= (level)) \
0074 v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \
0075 } while (0)
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
0096 s32 min, s32 max, s32 step, s32 def);
0097
0098
0099
0100 struct v4l2_device;
0101 struct v4l2_subdev;
0102 struct v4l2_subdev_ops;
0103
0104
0105 #include <linux/i2c.h>
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 enum v4l2_i2c_tuner_type {
0131 ADDRS_RADIO,
0132 ADDRS_DEMOD,
0133 ADDRS_TV,
0134 ADDRS_TV_WITH_DEMOD,
0135 };
0136
0137 #if defined(CONFIG_VIDEO_V4L2_I2C)
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
0153 struct i2c_adapter *adapter, const char *client_type,
0154 u8 addr, const unsigned short *probe_addrs);
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
0170 struct i2c_adapter *adapter, struct i2c_board_info *info,
0171 const unsigned short *probe_addrs);
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182 void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
0183 const char *devname, const char *postfix);
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
0194 const struct v4l2_subdev_ops *ops);
0195
0196
0197
0198
0199
0200
0201
0202
0203 unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
0214
0215
0216
0217
0218
0219
0220 void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd);
0221
0222 #else
0223
0224 static inline struct v4l2_subdev *
0225 v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
0226 struct i2c_adapter *adapter, const char *client_type,
0227 u8 addr, const unsigned short *probe_addrs)
0228 {
0229 return NULL;
0230 }
0231
0232 static inline struct v4l2_subdev *
0233 v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
0234 struct i2c_adapter *adapter, struct i2c_board_info *info,
0235 const unsigned short *probe_addrs)
0236 {
0237 return NULL;
0238 }
0239
0240 static inline void
0241 v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
0242 const char *devname, const char *postfix)
0243 {}
0244
0245 static inline void
0246 v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
0247 const struct v4l2_subdev_ops *ops)
0248 {}
0249
0250 static inline unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
0251 {
0252 return I2C_CLIENT_END;
0253 }
0254
0255 static inline const unsigned short *
0256 v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
0257 {
0258 return NULL;
0259 }
0260
0261 static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)
0262 {}
0263
0264 #endif
0265
0266
0267
0268
0269
0270 #include <linux/spi/spi.h>
0271
0272 #if defined(CONFIG_SPI)
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
0286 struct spi_master *master, struct spi_board_info *info);
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296 void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
0297 const struct v4l2_subdev_ops *ops);
0298
0299
0300
0301
0302
0303
0304 void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd);
0305
0306 #else
0307
0308 static inline struct v4l2_subdev *
0309 v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
0310 struct spi_master *master, struct spi_board_info *info)
0311 {
0312 return NULL;
0313 }
0314
0315 static inline void
0316 v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
0317 const struct v4l2_subdev_ops *ops)
0318 {}
0319
0320 static inline void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd)
0321 {}
0322 #endif
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 struct v4l2_priv_tun_config {
0337 int tuner;
0338 void *priv;
0339 };
0340 #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)
0341
0342 #define VIDIOC_INT_RESET _IOW ('d', 102, u32)
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385 void v4l_bound_align_image(unsigned int *width, unsigned int wmin,
0386 unsigned int wmax, unsigned int walign,
0387 unsigned int *height, unsigned int hmin,
0388 unsigned int hmax, unsigned int halign,
0389 unsigned int salign);
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409 #define v4l2_find_nearest_size(array, array_size, width_field, height_field, \
0410 width, height) \
0411 ({ \
0412 BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \
0413 sizeof((array)->height_field) != sizeof(u32)); \
0414 (typeof(&(array)[0]))__v4l2_find_nearest_size( \
0415 (array), array_size, sizeof(*(array)), \
0416 offsetof(typeof(*(array)), width_field), \
0417 offsetof(typeof(*(array)), height_field), \
0418 width, height); \
0419 })
0420 const void *
0421 __v4l2_find_nearest_size(const void *array, size_t array_size,
0422 size_t entry_size, size_t width_offset,
0423 size_t height_offset, s32 width, s32 height);
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435 int v4l2_g_parm_cap(struct video_device *vdev,
0436 struct v4l2_subdev *sd, struct v4l2_streamparm *a);
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448 int v4l2_s_parm_cap(struct video_device *vdev,
0449 struct v4l2_subdev *sd, struct v4l2_streamparm *a);
0450
0451
0452 #define V4L2_FRACT_COMPARE(a, OP, b) \
0453 ((u64)(a).numerator * (b).denominator OP \
0454 (u64)(b).numerator * (a).denominator)
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468 enum v4l2_pixel_encoding {
0469 V4L2_PIXEL_ENC_UNKNOWN = 0,
0470 V4L2_PIXEL_ENC_YUV = 1,
0471 V4L2_PIXEL_ENC_RGB = 2,
0472 V4L2_PIXEL_ENC_BAYER = 3,
0473 };
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487 struct v4l2_format_info {
0488 u32 format;
0489 u8 pixel_enc;
0490 u8 mem_planes;
0491 u8 comp_planes;
0492 u8 bpp[4];
0493 u8 hdiv;
0494 u8 vdiv;
0495 u8 block_w[4];
0496 u8 block_h[4];
0497 };
0498
0499 static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f)
0500 {
0501 return f && f->pixel_enc == V4L2_PIXEL_ENC_RGB;
0502 }
0503
0504 static inline bool v4l2_is_format_yuv(const struct v4l2_format_info *f)
0505 {
0506 return f && f->pixel_enc == V4L2_PIXEL_ENC_YUV;
0507 }
0508
0509 static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f)
0510 {
0511 return f && f->pixel_enc == V4L2_PIXEL_ENC_BAYER;
0512 }
0513
0514 const struct v4l2_format_info *v4l2_format_info(u32 format);
0515 void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
0516 const struct v4l2_frmsize_stepwise *frmsize);
0517 int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
0518 u32 width, u32 height);
0519 int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
0520 u32 width, u32 height);
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540 s64 v4l2_get_link_freq(struct v4l2_ctrl_handler *handler, unsigned int mul,
0541 unsigned int div);
0542
0543 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
0544 {
0545
0546
0547
0548
0549
0550 return buf->timestamp.tv_sec * NSEC_PER_SEC +
0551 (u32)buf->timestamp.tv_usec * NSEC_PER_USEC;
0552 }
0553
0554 static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf,
0555 u64 timestamp)
0556 {
0557 struct timespec64 ts = ns_to_timespec64(timestamp);
0558
0559 buf->timestamp.tv_sec = ts.tv_sec;
0560 buf->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
0561 }
0562
0563 static inline bool v4l2_is_colorspace_valid(__u32 colorspace)
0564 {
0565 return colorspace > V4L2_COLORSPACE_DEFAULT &&
0566 colorspace < V4L2_COLORSPACE_LAST;
0567 }
0568
0569 static inline bool v4l2_is_xfer_func_valid(__u32 xfer_func)
0570 {
0571 return xfer_func > V4L2_XFER_FUNC_DEFAULT &&
0572 xfer_func < V4L2_XFER_FUNC_LAST;
0573 }
0574
0575 static inline bool v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc)
0576 {
0577 return ycbcr_enc > V4L2_YCBCR_ENC_DEFAULT &&
0578 ycbcr_enc < V4L2_YCBCR_ENC_LAST;
0579 }
0580
0581 static inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc)
0582 {
0583 return hsv_enc == V4L2_HSV_ENC_180 || hsv_enc == V4L2_HSV_ENC_256;
0584 }
0585
0586 static inline bool v4l2_is_quant_valid(__u8 quantization)
0587 {
0588 return quantization == V4L2_QUANTIZATION_FULL_RANGE ||
0589 quantization == V4L2_QUANTIZATION_LIM_RANGE;
0590 }
0591
0592 #endif