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...) \ 38f9d32f25SLars-Peter Clausen v4l_printk(level, (client)->dev.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 58a41231d5SMauro Carvalho Chehab /* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */ 59a41231d5SMauro Carvalho Chehab #define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...) \ 60a41231d5SMauro Carvalho Chehab do { \ 61a41231d5SMauro Carvalho Chehab if (__debug >= (__level)) \ 62a41231d5SMauro Carvalho Chehab dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg); \ 63a41231d5SMauro Carvalho Chehab } while (0) 64a41231d5SMauro Carvalho Chehab 657e8b09eaSHans Verkuil /* ------------------------------------------------------------------------- */ 667e8b09eaSHans Verkuil 67dd99120cSHans Verkuil /* These printk constructs can be used with v4l2_device and v4l2_subdev */ 68dd99120cSHans Verkuil #define v4l2_printk(level, dev, fmt, arg...) \ 69dd99120cSHans Verkuil printk(level "%s: " fmt, (dev)->name , ## arg) 70dd99120cSHans Verkuil 71dd99120cSHans Verkuil #define v4l2_err(dev, fmt, arg...) \ 72dd99120cSHans Verkuil v4l2_printk(KERN_ERR, dev, fmt , ## arg) 73dd99120cSHans Verkuil 74dd99120cSHans Verkuil #define v4l2_warn(dev, fmt, arg...) \ 75dd99120cSHans Verkuil v4l2_printk(KERN_WARNING, dev, fmt , ## arg) 76dd99120cSHans Verkuil 77dd99120cSHans Verkuil #define v4l2_info(dev, fmt, arg...) \ 78dd99120cSHans Verkuil v4l2_printk(KERN_INFO, dev, fmt , ## arg) 79dd99120cSHans Verkuil 80dd99120cSHans Verkuil /* These three macros assume that the debug level is set with a module 81dd99120cSHans Verkuil parameter called 'debug'. */ 82dd99120cSHans Verkuil #define v4l2_dbg(level, debug, dev, fmt, arg...) \ 83dd99120cSHans Verkuil do { \ 84dd99120cSHans Verkuil if (debug >= (level)) \ 85dd99120cSHans Verkuil v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \ 86dd99120cSHans Verkuil } while (0) 87dd99120cSHans Verkuil 88b8719158SMauro Carvalho Chehab /** 89b8719158SMauro Carvalho Chehab * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl 90b8719158SMauro Carvalho Chehab * 91b8719158SMauro Carvalho Chehab * @qctrl: pointer to the &struct v4l2_queryctrl to be filled 92b8719158SMauro Carvalho Chehab * @min: minimum value for the control 93b8719158SMauro Carvalho Chehab * @max: maximum value for the control 94b8719158SMauro Carvalho Chehab * @step: control step 95b8719158SMauro Carvalho Chehab * @def: default value for the control 96b8719158SMauro Carvalho Chehab * 97b8719158SMauro Carvalho Chehab * Fills the &struct v4l2_queryctrl fields for the query control. 98b8719158SMauro Carvalho Chehab * 99b8719158SMauro Carvalho Chehab * .. note:: 100b8719158SMauro Carvalho Chehab * 101b8719158SMauro Carvalho Chehab * This function assumes that the @qctrl->id field is filled. 102b8719158SMauro Carvalho Chehab * 103b8719158SMauro Carvalho Chehab * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success. 104b8719158SMauro Carvalho Chehab */ 105dd99120cSHans Verkuil 106b8719158SMauro Carvalho Chehab int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, 107b8719158SMauro Carvalho Chehab s32 min, s32 max, s32 step, s32 def); 1089cb2318bSHans Verkuil 1099cb2318bSHans Verkuil /* ------------------------------------------------------------------------- */ 1109cb2318bSHans Verkuil 11178a3b4dbSHans Verkuil /* I2C Helper functions */ 1128ffbc655SHans Verkuil 1138ffbc655SHans Verkuil struct i2c_driver; 1148ffbc655SHans Verkuil struct i2c_adapter; 1158ffbc655SHans Verkuil struct i2c_client; 116d2653e92SJean Delvare struct i2c_device_id; 117dd99120cSHans Verkuil struct v4l2_device; 118dd99120cSHans Verkuil struct v4l2_subdev; 119dd99120cSHans Verkuil struct v4l2_subdev_ops; 1208ffbc655SHans Verkuil 121a39c57f8SMauro Carvalho Chehab /** 122a39c57f8SMauro Carvalho Chehab * v4l2_i2c_new_subdev - Load an i2c module and return an initialized 123a39c57f8SMauro Carvalho Chehab * &struct v4l2_subdev. 124a39c57f8SMauro Carvalho Chehab * 125a39c57f8SMauro Carvalho Chehab * @v4l2_dev: pointer to &struct v4l2_device 126a39c57f8SMauro Carvalho Chehab * @adapter: pointer to struct i2c_adapter 127a39c57f8SMauro Carvalho Chehab * @client_type: name of the chip that's on the adapter. 128a39c57f8SMauro Carvalho Chehab * @addr: I2C address. If zero, it will use @probe_addrs 129a39c57f8SMauro Carvalho Chehab * @probe_addrs: array with a list of address. The last entry at such 130a39c57f8SMauro Carvalho Chehab * array should be %I2C_CLIENT_END. 131a39c57f8SMauro Carvalho Chehab * 132a39c57f8SMauro Carvalho Chehab * returns a &struct v4l2_subdev pointer. 133a39c57f8SMauro Carvalho Chehab */ 1343c7c9370SHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, 1359a1f8b34SLaurent Pinchart struct i2c_adapter *adapter, const char *client_type, 136f0222c7dSHans Verkuil u8 addr, const unsigned short *probe_addrs); 137f0222c7dSHans Verkuil 138f0222c7dSHans Verkuil struct i2c_board_info; 139f0222c7dSHans Verkuil 140a39c57f8SMauro Carvalho Chehab /** 141a39c57f8SMauro Carvalho Chehab * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized 142a39c57f8SMauro Carvalho Chehab * &struct v4l2_subdev. 143a39c57f8SMauro Carvalho Chehab * 144a39c57f8SMauro Carvalho Chehab * @v4l2_dev: pointer to &struct v4l2_device 145a39c57f8SMauro Carvalho Chehab * @adapter: pointer to struct i2c_adapter 146a39c57f8SMauro Carvalho Chehab * @info: pointer to struct i2c_board_info used to replace the irq, 147a39c57f8SMauro Carvalho Chehab * platform_data and addr arguments. 148a39c57f8SMauro Carvalho Chehab * @probe_addrs: array with a list of address. The last entry at such 149a39c57f8SMauro Carvalho Chehab * array should be %I2C_CLIENT_END. 150a39c57f8SMauro Carvalho Chehab * 151a39c57f8SMauro Carvalho Chehab * returns a &struct v4l2_subdev pointer. 152a39c57f8SMauro Carvalho Chehab */ 153f0222c7dSHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, 1549a1f8b34SLaurent Pinchart struct i2c_adapter *adapter, struct i2c_board_info *info, 1559a1f8b34SLaurent Pinchart const unsigned short *probe_addrs); 156f0222c7dSHans Verkuil 157a39c57f8SMauro Carvalho Chehab /** 158a39c57f8SMauro Carvalho Chehab * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from 159a39c57f8SMauro Carvalho Chehab * an i2c_client struct. 160a39c57f8SMauro Carvalho Chehab * 161a39c57f8SMauro Carvalho Chehab * @sd: pointer to &struct v4l2_subdev 162a39c57f8SMauro Carvalho Chehab * @client: pointer to struct i2c_client 163a39c57f8SMauro Carvalho Chehab * @ops: pointer to &struct v4l2_subdev_ops 164a39c57f8SMauro Carvalho Chehab */ 165dd99120cSHans Verkuil void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, 166dd99120cSHans Verkuil const struct v4l2_subdev_ops *ops); 167a39c57f8SMauro Carvalho Chehab 168a39c57f8SMauro Carvalho Chehab /** 169a39c57f8SMauro Carvalho Chehab * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev. 170a39c57f8SMauro Carvalho Chehab * 171a39c57f8SMauro Carvalho Chehab * @sd: pointer to &struct v4l2_subdev 172a39c57f8SMauro Carvalho Chehab * 173a39c57f8SMauro Carvalho Chehab * Returns the address of an I2C sub-device 174a39c57f8SMauro Carvalho Chehab */ 175ab373190SHans Verkuil unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd); 176dd99120cSHans Verkuil 177c7d29e2fSHans Verkuil enum v4l2_i2c_tuner_type { 178c7d29e2fSHans Verkuil ADDRS_RADIO, /* Radio tuner addresses */ 179c7d29e2fSHans Verkuil ADDRS_DEMOD, /* Demod tuner addresses */ 180c7d29e2fSHans Verkuil ADDRS_TV, /* TV tuner addresses */ 181c7d29e2fSHans Verkuil /* TV tuner addresses if demod is present, this excludes 182c7d29e2fSHans Verkuil addresses used by the demodulator from the list of 183c7d29e2fSHans Verkuil candidates. */ 184c7d29e2fSHans Verkuil ADDRS_TV_WITH_DEMOD, 185c7d29e2fSHans Verkuil }; 186c7d29e2fSHans Verkuil /* Return a list of I2C tuner addresses to probe. Use only if the tuner 187c7d29e2fSHans Verkuil addresses are unknown. */ 188c7d29e2fSHans Verkuil const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); 189c7d29e2fSHans Verkuil 1908ffbc655SHans Verkuil /* ------------------------------------------------------------------------- */ 1918ffbc655SHans Verkuil 19285e09219SDmitri Belimov /* SPI Helper functions */ 19385e09219SDmitri Belimov #if defined(CONFIG_SPI) 19485e09219SDmitri Belimov 19585e09219SDmitri Belimov #include <linux/spi/spi.h> 19685e09219SDmitri Belimov 19785e09219SDmitri Belimov struct spi_device; 19885e09219SDmitri Belimov 199b8719158SMauro Carvalho Chehab /** 200b8719158SMauro Carvalho Chehab * v4l2_spi_new_subdev - Load an spi module and return an initialized 201b8719158SMauro Carvalho Chehab * &struct v4l2_subdev. 202b8719158SMauro Carvalho Chehab * 203b8719158SMauro Carvalho Chehab * 204b8719158SMauro Carvalho Chehab * @v4l2_dev: pointer to &struct v4l2_device. 205b8719158SMauro Carvalho Chehab * @master: pointer to struct spi_master. 206b8719158SMauro Carvalho Chehab * @info: pointer to struct spi_board_info. 207b8719158SMauro Carvalho Chehab * 208b8719158SMauro Carvalho Chehab * returns a &struct v4l2_subdev pointer. 209b8719158SMauro Carvalho Chehab */ 21085e09219SDmitri Belimov struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, 21185e09219SDmitri Belimov struct spi_master *master, struct spi_board_info *info); 21285e09219SDmitri Belimov 213b8719158SMauro Carvalho Chehab /** 214b8719158SMauro Carvalho Chehab * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an 215b8719158SMauro Carvalho Chehab * spi_device struct. 216b8719158SMauro Carvalho Chehab * 217b8719158SMauro Carvalho Chehab * @sd: pointer to &struct v4l2_subdev 218b8719158SMauro Carvalho Chehab * @spi: pointer to struct spi_device. 219b8719158SMauro Carvalho Chehab * @ops: pointer to &struct v4l2_subdev_ops 220b8719158SMauro Carvalho Chehab */ 22185e09219SDmitri Belimov void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 22285e09219SDmitri Belimov const struct v4l2_subdev_ops *ops); 22385e09219SDmitri Belimov #endif 22485e09219SDmitri Belimov 22585e09219SDmitri Belimov /* ------------------------------------------------------------------------- */ 22685e09219SDmitri Belimov 227*01154ef5SMauro Carvalho Chehab /* 228*01154ef5SMauro Carvalho Chehab * FIXME: these remaining ioctls/structs should be removed as well, but they 229*01154ef5SMauro Carvalho Chehab * are still used in tuner-simple.c (TUNER_SET_CONFIG) and cx18/ivtv (RESET). 230*01154ef5SMauro Carvalho Chehab * To remove these ioctls some more cleanup is needed in those modules. 231*01154ef5SMauro Carvalho Chehab */ 2327e8b09eaSHans Verkuil 23378a3b4dbSHans Verkuil /* s_config */ 2347f171123SMauro Carvalho Chehab struct v4l2_priv_tun_config { 2357f171123SMauro Carvalho Chehab int tuner; 2367f171123SMauro Carvalho Chehab void *priv; 2377f171123SMauro Carvalho Chehab }; 2387f171123SMauro Carvalho Chehab #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config) 2395e453dc7SMichael Krufky 2406c31e598SHans Verkuil #define VIDIOC_INT_RESET _IOW ('d', 102, u32) 2416c31e598SHans Verkuil 242b0d3159bSTrent Piepho /* ------------------------------------------------------------------------- */ 243b0d3159bSTrent Piepho 244b0d3159bSTrent Piepho /* Miscellaneous helper functions */ 245b0d3159bSTrent Piepho 246b0d3159bSTrent Piepho void v4l_bound_align_image(unsigned int *w, unsigned int wmin, 247b0d3159bSTrent Piepho unsigned int wmax, unsigned int walign, 248b0d3159bSTrent Piepho unsigned int *h, unsigned int hmin, 249b0d3159bSTrent Piepho unsigned int hmax, unsigned int halign, 250b0d3159bSTrent Piepho unsigned int salign); 2513fd8e647SHans Verkuil 2523fd8e647SHans Verkuil struct v4l2_discrete_probe { 2533fd8e647SHans Verkuil const struct v4l2_frmsize_discrete *sizes; 2543fd8e647SHans Verkuil int num_sizes; 2553fd8e647SHans Verkuil }; 2563fd8e647SHans Verkuil 2573fd8e647SHans Verkuil const struct v4l2_frmsize_discrete *v4l2_find_nearest_format( 2583fd8e647SHans Verkuil const struct v4l2_discrete_probe *probe, 2593fd8e647SHans Verkuil s32 width, s32 height); 2603fd8e647SHans Verkuil 261abd23295SSakari Ailus void v4l2_get_timestamp(struct timeval *tv); 262abd23295SSakari Ailus 263b2f0648fSHans Verkuil #endif /* V4L2_COMMON_H_ */ 264