1b2f0648fSHans Verkuil /* 2b2f0648fSHans Verkuil v4l2 common internal API header 3b2f0648fSHans Verkuil 4b2f0648fSHans Verkuil This header contains internal shared ioctl definitions for use by the 5b2f0648fSHans Verkuil internal low-level v4l2 drivers. 6b2f0648fSHans Verkuil Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal 7b2f0648fSHans Verkuil define, 8b2f0648fSHans Verkuil 9b2f0648fSHans Verkuil Copyright (C) 2005 Hans Verkuil <hverkuil@xs4all.nl> 10b2f0648fSHans Verkuil 11b2f0648fSHans Verkuil This program is free software; you can redistribute it and/or modify 12b2f0648fSHans Verkuil it under the terms of the GNU General Public License as published by 13b2f0648fSHans Verkuil the Free Software Foundation; either version 2 of the License, or 14b2f0648fSHans Verkuil (at your option) any later version. 15b2f0648fSHans Verkuil 16b2f0648fSHans Verkuil This program is distributed in the hope that it will be useful, 17b2f0648fSHans Verkuil but WITHOUT ANY WARRANTY; without even the implied warranty of 18b2f0648fSHans Verkuil MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19b2f0648fSHans Verkuil GNU General Public License for more details. 20b2f0648fSHans Verkuil 21b2f0648fSHans Verkuil You should have received a copy of the GNU General Public License 22b2f0648fSHans Verkuil along with this program; if not, write to the Free Software 23b2f0648fSHans Verkuil Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24b2f0648fSHans Verkuil */ 25b2f0648fSHans Verkuil 26b2f0648fSHans Verkuil #ifndef V4L2_COMMON_H_ 27b2f0648fSHans Verkuil #define V4L2_COMMON_H_ 28b2f0648fSHans Verkuil 29401998faSMauro Carvalho Chehab #include <media/v4l2-dev.h> 30401998faSMauro Carvalho Chehab 317e8b09eaSHans Verkuil /* Common printk constucts for v4l-i2c drivers. These macros create a unique 327e8b09eaSHans Verkuil prefix consisting of the driver name, the adapter number and the i2c 337e8b09eaSHans Verkuil address. */ 347e8b09eaSHans Verkuil #define v4l_printk(level, name, adapter, addr, fmt, arg...) \ 357e8b09eaSHans Verkuil printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg) 367e8b09eaSHans Verkuil 377e8b09eaSHans Verkuil #define v4l_client_printk(level, client, fmt, arg...) \ 387e8b09eaSHans Verkuil v4l_printk(level, (client)->driver->driver.name, (client)->adapter, \ 397e8b09eaSHans Verkuil (client)->addr, fmt , ## arg) 407e8b09eaSHans Verkuil 417e8b09eaSHans Verkuil #define v4l_err(client, fmt, arg...) \ 427e8b09eaSHans Verkuil v4l_client_printk(KERN_ERR, client, fmt , ## arg) 437e8b09eaSHans Verkuil 447e8b09eaSHans Verkuil #define v4l_warn(client, fmt, arg...) \ 457e8b09eaSHans Verkuil v4l_client_printk(KERN_WARNING, client, fmt , ## arg) 467e8b09eaSHans Verkuil 477e8b09eaSHans Verkuil #define v4l_info(client, fmt, arg...) \ 487e8b09eaSHans Verkuil v4l_client_printk(KERN_INFO, client, fmt , ## arg) 497e8b09eaSHans Verkuil 507e8b09eaSHans Verkuil /* These three macros assume that the debug level is set with a module 517e8b09eaSHans Verkuil parameter called 'debug'. */ 52f167cb4eSMauro Carvalho Chehab #define v4l_dbg(level, debug, client, fmt, arg...) \ 537e8b09eaSHans Verkuil do { \ 547e8b09eaSHans Verkuil if (debug >= (level)) \ 557e8b09eaSHans Verkuil v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \ 567e8b09eaSHans Verkuil } while (0) 577e8b09eaSHans Verkuil 587e8b09eaSHans Verkuil /* ------------------------------------------------------------------------- */ 597e8b09eaSHans Verkuil 60dd99120cSHans Verkuil /* These printk constructs can be used with v4l2_device and v4l2_subdev */ 61dd99120cSHans Verkuil #define v4l2_printk(level, dev, fmt, arg...) \ 62dd99120cSHans Verkuil printk(level "%s: " fmt, (dev)->name , ## arg) 63dd99120cSHans Verkuil 64dd99120cSHans Verkuil #define v4l2_err(dev, fmt, arg...) \ 65dd99120cSHans Verkuil v4l2_printk(KERN_ERR, dev, fmt , ## arg) 66dd99120cSHans Verkuil 67dd99120cSHans Verkuil #define v4l2_warn(dev, fmt, arg...) \ 68dd99120cSHans Verkuil v4l2_printk(KERN_WARNING, dev, fmt , ## arg) 69dd99120cSHans Verkuil 70dd99120cSHans Verkuil #define v4l2_info(dev, fmt, arg...) \ 71dd99120cSHans Verkuil v4l2_printk(KERN_INFO, dev, fmt , ## arg) 72dd99120cSHans Verkuil 73dd99120cSHans Verkuil /* These three macros assume that the debug level is set with a module 74dd99120cSHans Verkuil parameter called 'debug'. */ 75dd99120cSHans Verkuil #define v4l2_dbg(level, debug, dev, fmt, arg...) \ 76dd99120cSHans Verkuil do { \ 77dd99120cSHans Verkuil if (debug >= (level)) \ 78dd99120cSHans Verkuil v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \ 79dd99120cSHans Verkuil } while (0) 80dd99120cSHans Verkuil 81dd99120cSHans Verkuil /* ------------------------------------------------------------------------- */ 82dd99120cSHans Verkuil 839cb2318bSHans Verkuil /* Control helper functions */ 849cb2318bSHans Verkuil 859cb2318bSHans Verkuil int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, 86513521eaSHans Verkuil const char * const *menu_items); 8769028d70SHans Verkuil const char *v4l2_ctrl_get_name(u32 id); 88513521eaSHans Verkuil const char * const *v4l2_ctrl_get_menu(u32 id); 899cb2318bSHans Verkuil int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def); 909cb2318bSHans Verkuil int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, 91513521eaSHans Verkuil struct v4l2_queryctrl *qctrl, const char * const *menu_items); 921e551266SHans Verkuil #define V4L2_CTRL_MENU_IDS_END (0xffffffff) 931e551266SHans Verkuil int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids); 942ba58894SHans Verkuil 952ba58894SHans Verkuil /* Note: ctrl_classes points to an array of u32 pointers. Each u32 array is a 962ba58894SHans Verkuil 0-terminated array of control IDs. Each array must be sorted low to high 972ba58894SHans Verkuil and belong to the same control class. The array of u32 pointers must also 982ba58894SHans Verkuil be sorted, from low class IDs to high class IDs. */ 999cb2318bSHans Verkuil u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id); 1009cb2318bSHans Verkuil 1019cb2318bSHans Verkuil /* ------------------------------------------------------------------------- */ 1029cb2318bSHans Verkuil 103f3d092b8SHans Verkuil /* Register/chip ident helper function */ 104f3d092b8SHans Verkuil 105f3d092b8SHans Verkuil struct i2c_client; /* forward reference */ 106aecde8b5SHans Verkuil int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match); 107aecde8b5SHans Verkuil int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_dbg_chip_ident *chip, 1083434eb7eSHans Verkuil u32 ident, u32 revision); 109aecde8b5SHans Verkuil int v4l2_chip_match_host(const struct v4l2_dbg_match *match); 110f3d092b8SHans Verkuil 111f3d092b8SHans Verkuil /* ------------------------------------------------------------------------- */ 112f3d092b8SHans Verkuil 11378a3b4dbSHans Verkuil /* I2C Helper functions */ 1148ffbc655SHans Verkuil 1158ffbc655SHans Verkuil struct i2c_driver; 1168ffbc655SHans Verkuil struct i2c_adapter; 1178ffbc655SHans Verkuil struct i2c_client; 118d2653e92SJean Delvare struct i2c_device_id; 119dd99120cSHans Verkuil struct v4l2_device; 120dd99120cSHans Verkuil struct v4l2_subdev; 121dd99120cSHans Verkuil struct v4l2_subdev_ops; 1228ffbc655SHans Verkuil 1238ffbc655SHans Verkuil 124dd99120cSHans Verkuil /* Load an i2c module and return an initialized v4l2_subdev struct. 125dd99120cSHans Verkuil The client_type argument is the name of the chip that's on the adapter. */ 1263c7c9370SHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, 1279a1f8b34SLaurent Pinchart struct i2c_adapter *adapter, const char *client_type, 128f0222c7dSHans Verkuil u8 addr, const unsigned short *probe_addrs); 129f0222c7dSHans Verkuil 130f0222c7dSHans Verkuil struct i2c_board_info; 131f0222c7dSHans Verkuil 132f0222c7dSHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, 1339a1f8b34SLaurent Pinchart struct i2c_adapter *adapter, struct i2c_board_info *info, 1349a1f8b34SLaurent Pinchart const unsigned short *probe_addrs); 135f0222c7dSHans Verkuil 1369d380adfSMichael Jones /* Initialize a v4l2_subdev with data from an i2c_client struct */ 137dd99120cSHans Verkuil void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, 138dd99120cSHans Verkuil const struct v4l2_subdev_ops *ops); 139ab373190SHans Verkuil /* Return i2c client address of v4l2_subdev. */ 140ab373190SHans Verkuil unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd); 141dd99120cSHans Verkuil 142c7d29e2fSHans Verkuil enum v4l2_i2c_tuner_type { 143c7d29e2fSHans Verkuil ADDRS_RADIO, /* Radio tuner addresses */ 144c7d29e2fSHans Verkuil ADDRS_DEMOD, /* Demod tuner addresses */ 145c7d29e2fSHans Verkuil ADDRS_TV, /* TV tuner addresses */ 146c7d29e2fSHans Verkuil /* TV tuner addresses if demod is present, this excludes 147c7d29e2fSHans Verkuil addresses used by the demodulator from the list of 148c7d29e2fSHans Verkuil candidates. */ 149c7d29e2fSHans Verkuil ADDRS_TV_WITH_DEMOD, 150c7d29e2fSHans Verkuil }; 151c7d29e2fSHans Verkuil /* Return a list of I2C tuner addresses to probe. Use only if the tuner 152c7d29e2fSHans Verkuil addresses are unknown. */ 153c7d29e2fSHans Verkuil const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); 154c7d29e2fSHans Verkuil 1558ffbc655SHans Verkuil /* ------------------------------------------------------------------------- */ 1568ffbc655SHans Verkuil 15785e09219SDmitri Belimov /* SPI Helper functions */ 15885e09219SDmitri Belimov #if defined(CONFIG_SPI) 15985e09219SDmitri Belimov 16085e09219SDmitri Belimov #include <linux/spi/spi.h> 16185e09219SDmitri Belimov 16285e09219SDmitri Belimov struct spi_device; 16385e09219SDmitri Belimov 16485e09219SDmitri Belimov /* Load an spi module and return an initialized v4l2_subdev struct. 16585e09219SDmitri Belimov The client_type argument is the name of the chip that's on the adapter. */ 16685e09219SDmitri Belimov struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, 16785e09219SDmitri Belimov struct spi_master *master, struct spi_board_info *info); 16885e09219SDmitri Belimov 1699d380adfSMichael Jones /* Initialize a v4l2_subdev with data from an spi_device struct */ 17085e09219SDmitri Belimov void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 17185e09219SDmitri Belimov const struct v4l2_subdev_ops *ops); 17285e09219SDmitri Belimov #endif 17385e09219SDmitri Belimov 17485e09219SDmitri Belimov /* ------------------------------------------------------------------------- */ 17585e09219SDmitri Belimov 1766c31e598SHans Verkuil /* Note: these remaining ioctls/structs should be removed as well, but they are 1776c31e598SHans Verkuil still used in tuner-simple.c (TUNER_SET_CONFIG), cx18/ivtv (RESET) and 1786c31e598SHans Verkuil v4l2-int-device.h (v4l2_routing). To remove these ioctls some more cleanup 1796c31e598SHans Verkuil is needed in those modules. */ 1807e8b09eaSHans Verkuil 18178a3b4dbSHans Verkuil /* s_config */ 1827f171123SMauro Carvalho Chehab struct v4l2_priv_tun_config { 1837f171123SMauro Carvalho Chehab int tuner; 1847f171123SMauro Carvalho Chehab void *priv; 1857f171123SMauro Carvalho Chehab }; 1867f171123SMauro Carvalho Chehab #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config) 1875e453dc7SMichael Krufky 1886c31e598SHans Verkuil #define VIDIOC_INT_RESET _IOW ('d', 102, u32) 1896c31e598SHans Verkuil 190757d2505SHans Verkuil struct v4l2_routing { 191757d2505SHans Verkuil u32 input; 192757d2505SHans Verkuil u32 output; 193757d2505SHans Verkuil }; 1941b6f1d96SHans Verkuil 195b0d3159bSTrent Piepho /* ------------------------------------------------------------------------- */ 196b0d3159bSTrent Piepho 197b0d3159bSTrent Piepho /* Miscellaneous helper functions */ 198b0d3159bSTrent Piepho 199b0d3159bSTrent Piepho void v4l_bound_align_image(unsigned int *w, unsigned int wmin, 200b0d3159bSTrent Piepho unsigned int wmax, unsigned int walign, 201b0d3159bSTrent Piepho unsigned int *h, unsigned int hmin, 202b0d3159bSTrent Piepho unsigned int hmax, unsigned int halign, 203b0d3159bSTrent Piepho unsigned int salign); 2042e535ed5SMuralidharan Karicheri int v4l_fill_dv_preset_info(u32 preset, struct v4l2_dv_enum_preset *info); 2053fd8e647SHans Verkuil 2063fd8e647SHans Verkuil struct v4l2_discrete_probe { 2073fd8e647SHans Verkuil const struct v4l2_frmsize_discrete *sizes; 2083fd8e647SHans Verkuil int num_sizes; 2093fd8e647SHans Verkuil }; 2103fd8e647SHans Verkuil 2113fd8e647SHans Verkuil const struct v4l2_frmsize_discrete *v4l2_find_nearest_format( 2123fd8e647SHans Verkuil const struct v4l2_discrete_probe *probe, 2133fd8e647SHans Verkuil s32 width, s32 height); 2143fd8e647SHans Verkuil 215c2a667faSHans Verkuil bool v4l_match_dv_timings(const struct v4l2_dv_timings *t1, 216c2a667faSHans Verkuil const struct v4l2_dv_timings *t2, 217c2a667faSHans Verkuil unsigned pclock_delta); 218c2a667faSHans Verkuil 219c61bd6a0SHans Verkuil bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 220c61bd6a0SHans Verkuil u32 polarities, struct v4l2_dv_timings *fmt); 221c61bd6a0SHans Verkuil 222c61bd6a0SHans Verkuil bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync, 223c61bd6a0SHans Verkuil u32 polarities, struct v4l2_fract aspect, 224c61bd6a0SHans Verkuil struct v4l2_dv_timings *fmt); 225c61bd6a0SHans Verkuil 226c61bd6a0SHans Verkuil struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait); 227c61bd6a0SHans Verkuil 228*abd23295SSakari Ailus void v4l2_get_timestamp(struct timeval *tv); 229*abd23295SSakari Ailus 230b2f0648fSHans Verkuil #endif /* V4L2_COMMON_H_ */ 231