Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | * uvc_ctrl.c -- USB Video Class driver - Controls |
| 3 | * |
Laurent Pinchart | 11fc5ba | 2010-09-20 06:10:10 -0300 | [diff] [blame] | 4 | * Copyright (C) 2005-2010 |
| 5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 15 | #include <linux/list.h> |
| 16 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
| 19 | #include <linux/usb.h> |
| 20 | #include <linux/videodev2.h> |
| 21 | #include <linux/vmalloc.h> |
| 22 | #include <linux/wait.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 23 | #include <linux/atomic.h> |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 24 | #include <media/v4l2-ctrls.h> |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 25 | |
| 26 | #include "uvcvideo.h" |
| 27 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 28 | #define UVC_CTRL_DATA_CURRENT 0 |
| 29 | #define UVC_CTRL_DATA_BACKUP 1 |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 30 | #define UVC_CTRL_DATA_MIN 2 |
| 31 | #define UVC_CTRL_DATA_MAX 3 |
| 32 | #define UVC_CTRL_DATA_RES 4 |
| 33 | #define UVC_CTRL_DATA_DEF 5 |
| 34 | #define UVC_CTRL_DATA_LAST 6 |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 35 | |
| 36 | /* ------------------------------------------------------------------------ |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 37 | * Controls |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | static struct uvc_control_info uvc_ctrls[] = { |
| 41 | { |
| 42 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 43 | .selector = UVC_PU_BRIGHTNESS_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 44 | .index = 0, |
| 45 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 46 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 47 | | UVC_CTRL_FLAG_GET_RANGE |
| 48 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 49 | }, |
| 50 | { |
| 51 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 52 | .selector = UVC_PU_CONTRAST_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 53 | .index = 1, |
| 54 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 55 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 56 | | UVC_CTRL_FLAG_GET_RANGE |
| 57 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 58 | }, |
| 59 | { |
| 60 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 61 | .selector = UVC_PU_HUE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 62 | .index = 2, |
| 63 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 64 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 65 | | UVC_CTRL_FLAG_GET_RANGE |
| 66 | | UVC_CTRL_FLAG_RESTORE |
| 67 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 68 | }, |
| 69 | { |
| 70 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 71 | .selector = UVC_PU_SATURATION_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 72 | .index = 3, |
| 73 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 74 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 75 | | UVC_CTRL_FLAG_GET_RANGE |
| 76 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 77 | }, |
| 78 | { |
| 79 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 80 | .selector = UVC_PU_SHARPNESS_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 81 | .index = 4, |
| 82 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 83 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 84 | | UVC_CTRL_FLAG_GET_RANGE |
| 85 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 86 | }, |
| 87 | { |
| 88 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 89 | .selector = UVC_PU_GAMMA_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 90 | .index = 5, |
| 91 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 92 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 93 | | UVC_CTRL_FLAG_GET_RANGE |
| 94 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 95 | }, |
| 96 | { |
| 97 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 98 | .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 99 | .index = 6, |
| 100 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 101 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 102 | | UVC_CTRL_FLAG_GET_RANGE |
| 103 | | UVC_CTRL_FLAG_RESTORE |
| 104 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 105 | }, |
| 106 | { |
| 107 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 108 | .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 109 | .index = 7, |
| 110 | .size = 4, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 111 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 112 | | UVC_CTRL_FLAG_GET_RANGE |
| 113 | | UVC_CTRL_FLAG_RESTORE |
| 114 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 115 | }, |
| 116 | { |
| 117 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 118 | .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 119 | .index = 8, |
| 120 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 121 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 122 | | UVC_CTRL_FLAG_GET_RANGE |
| 123 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 124 | }, |
| 125 | { |
| 126 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 127 | .selector = UVC_PU_GAIN_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 128 | .index = 9, |
| 129 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 130 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 131 | | UVC_CTRL_FLAG_GET_RANGE |
| 132 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 133 | }, |
| 134 | { |
| 135 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 136 | .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 137 | .index = 10, |
| 138 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 139 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 140 | | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 141 | }, |
| 142 | { |
| 143 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 144 | .selector = UVC_PU_HUE_AUTO_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 145 | .index = 11, |
| 146 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 147 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 148 | | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 149 | }, |
| 150 | { |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 151 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 152 | .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 153 | .index = 12, |
| 154 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 155 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 156 | | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 157 | }, |
| 158 | { |
| 159 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 160 | .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 161 | .index = 13, |
| 162 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 163 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 164 | | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 165 | }, |
| 166 | { |
| 167 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 168 | .selector = UVC_PU_DIGITAL_MULTIPLIER_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 169 | .index = 14, |
| 170 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 171 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 172 | | UVC_CTRL_FLAG_GET_RANGE |
| 173 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 174 | }, |
| 175 | { |
| 176 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 177 | .selector = UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 178 | .index = 15, |
| 179 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 180 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 181 | | UVC_CTRL_FLAG_GET_RANGE |
| 182 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 183 | }, |
| 184 | { |
| 185 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 186 | .selector = UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 187 | .index = 16, |
| 188 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 189 | .flags = UVC_CTRL_FLAG_GET_CUR, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 190 | }, |
| 191 | { |
| 192 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 193 | .selector = UVC_PU_ANALOG_LOCK_STATUS_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 194 | .index = 17, |
| 195 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 196 | .flags = UVC_CTRL_FLAG_GET_CUR, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 197 | }, |
| 198 | { |
| 199 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 200 | .selector = UVC_CT_SCANNING_MODE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 201 | .index = 0, |
| 202 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 203 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 204 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 205 | }, |
| 206 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 207 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 208 | .selector = UVC_CT_AE_MODE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 209 | .index = 1, |
| 210 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 211 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 212 | | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_GET_RES |
| 213 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 214 | }, |
| 215 | { |
| 216 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 217 | .selector = UVC_CT_AE_PRIORITY_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 218 | .index = 2, |
| 219 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 220 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 221 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 222 | }, |
| 223 | { |
| 224 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 225 | .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 226 | .index = 3, |
| 227 | .size = 4, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 228 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 229 | | UVC_CTRL_FLAG_GET_RANGE |
| 230 | | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 231 | }, |
| 232 | { |
| 233 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 234 | .selector = UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 235 | .index = 4, |
| 236 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 237 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 238 | }, |
| 239 | { |
| 240 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 241 | .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 242 | .index = 5, |
| 243 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 244 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 245 | | UVC_CTRL_FLAG_GET_RANGE |
| 246 | | UVC_CTRL_FLAG_RESTORE |
| 247 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 248 | }, |
| 249 | { |
| 250 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 251 | .selector = UVC_CT_FOCUS_RELATIVE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 252 | .index = 6, |
| 253 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 254 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_MIN |
| 255 | | UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES |
| 256 | | UVC_CTRL_FLAG_GET_DEF |
| 257 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 258 | }, |
| 259 | { |
| 260 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 261 | .selector = UVC_CT_IRIS_ABSOLUTE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 262 | .index = 7, |
| 263 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 264 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 265 | | UVC_CTRL_FLAG_GET_RANGE |
| 266 | | UVC_CTRL_FLAG_RESTORE |
| 267 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 268 | }, |
| 269 | { |
| 270 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 271 | .selector = UVC_CT_IRIS_RELATIVE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 272 | .index = 8, |
| 273 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 274 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 275 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 276 | }, |
| 277 | { |
| 278 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 279 | .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 280 | .index = 9, |
| 281 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 282 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 283 | | UVC_CTRL_FLAG_GET_RANGE |
| 284 | | UVC_CTRL_FLAG_RESTORE |
| 285 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 286 | }, |
| 287 | { |
| 288 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 289 | .selector = UVC_CT_ZOOM_RELATIVE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 290 | .index = 10, |
| 291 | .size = 3, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 292 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_MIN |
| 293 | | UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES |
| 294 | | UVC_CTRL_FLAG_GET_DEF |
| 295 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 296 | }, |
| 297 | { |
| 298 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 299 | .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 300 | .index = 11, |
| 301 | .size = 8, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 302 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 303 | | UVC_CTRL_FLAG_GET_RANGE |
| 304 | | UVC_CTRL_FLAG_RESTORE |
| 305 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 306 | }, |
| 307 | { |
| 308 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 309 | .selector = UVC_CT_PANTILT_RELATIVE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 310 | .index = 12, |
| 311 | .size = 4, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 312 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_MIN |
| 313 | | UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES |
| 314 | | UVC_CTRL_FLAG_GET_DEF |
| 315 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 316 | }, |
| 317 | { |
| 318 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 319 | .selector = UVC_CT_ROLL_ABSOLUTE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 320 | .index = 13, |
| 321 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 322 | .flags = UVC_CTRL_FLAG_SET_CUR |
| 323 | | UVC_CTRL_FLAG_GET_RANGE |
| 324 | | UVC_CTRL_FLAG_RESTORE |
| 325 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 326 | }, |
| 327 | { |
| 328 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 329 | .selector = UVC_CT_ROLL_RELATIVE_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 330 | .index = 14, |
| 331 | .size = 2, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 332 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_MIN |
| 333 | | UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES |
| 334 | | UVC_CTRL_FLAG_GET_DEF |
| 335 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 336 | }, |
| 337 | { |
| 338 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 339 | .selector = UVC_CT_FOCUS_AUTO_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 340 | .index = 17, |
| 341 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 342 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 343 | | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_RESTORE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 344 | }, |
| 345 | { |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 346 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 347 | .selector = UVC_CT_PRIVACY_CONTROL, |
Laurent Pinchart | 5e26d50 | 2008-09-22 13:14:59 -0300 | [diff] [blame] | 348 | .index = 18, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 349 | .size = 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 350 | .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR |
| 351 | | UVC_CTRL_FLAG_RESTORE |
| 352 | | UVC_CTRL_FLAG_AUTO_UPDATE, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 353 | }, |
| 354 | }; |
| 355 | |
| 356 | static struct uvc_menu_info power_line_frequency_controls[] = { |
| 357 | { 0, "Disabled" }, |
| 358 | { 1, "50 Hz" }, |
| 359 | { 2, "60 Hz" }, |
| 360 | }; |
| 361 | |
| 362 | static struct uvc_menu_info exposure_auto_controls[] = { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 363 | { 2, "Auto Mode" }, |
Laurent Pinchart | 90ac5ea | 2008-07-26 11:42:29 -0300 | [diff] [blame] | 364 | { 1, "Manual Mode" }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 365 | { 4, "Shutter Priority Mode" }, |
| 366 | { 8, "Aperture Priority Mode" }, |
| 367 | }; |
| 368 | |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 369 | static __s32 uvc_ctrl_get_zoom(struct uvc_control_mapping *mapping, |
| 370 | __u8 query, const __u8 *data) |
| 371 | { |
| 372 | __s8 zoom = (__s8)data[0]; |
| 373 | |
| 374 | switch (query) { |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 375 | case UVC_GET_CUR: |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 376 | return (zoom == 0) ? 0 : (zoom > 0 ? data[2] : -data[2]); |
| 377 | |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 378 | case UVC_GET_MIN: |
| 379 | case UVC_GET_MAX: |
| 380 | case UVC_GET_RES: |
| 381 | case UVC_GET_DEF: |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 382 | default: |
| 383 | return data[2]; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | static void uvc_ctrl_set_zoom(struct uvc_control_mapping *mapping, |
| 388 | __s32 value, __u8 *data) |
| 389 | { |
| 390 | data[0] = value == 0 ? 0 : (value > 0) ? 1 : 0xff; |
Laurent Pinchart | 2e89613 | 2009-11-04 13:11:10 -0300 | [diff] [blame] | 391 | data[2] = min((int)abs(value), 0xff); |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 392 | } |
| 393 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 394 | static struct uvc_control_mapping uvc_ctrl_mappings[] = { |
| 395 | { |
| 396 | .id = V4L2_CID_BRIGHTNESS, |
| 397 | .name = "Brightness", |
| 398 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 399 | .selector = UVC_PU_BRIGHTNESS_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 400 | .size = 16, |
| 401 | .offset = 0, |
| 402 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 403 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, |
| 404 | }, |
| 405 | { |
| 406 | .id = V4L2_CID_CONTRAST, |
| 407 | .name = "Contrast", |
| 408 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 409 | .selector = UVC_PU_CONTRAST_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 410 | .size = 16, |
| 411 | .offset = 0, |
| 412 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 413 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 414 | }, |
| 415 | { |
| 416 | .id = V4L2_CID_HUE, |
| 417 | .name = "Hue", |
| 418 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 419 | .selector = UVC_PU_HUE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 420 | .size = 16, |
| 421 | .offset = 0, |
| 422 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 423 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 424 | .master_id = V4L2_CID_HUE_AUTO, |
| 425 | .master_manual = 0, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 426 | }, |
| 427 | { |
| 428 | .id = V4L2_CID_SATURATION, |
| 429 | .name = "Saturation", |
| 430 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 431 | .selector = UVC_PU_SATURATION_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 432 | .size = 16, |
| 433 | .offset = 0, |
| 434 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 435 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 436 | }, |
| 437 | { |
| 438 | .id = V4L2_CID_SHARPNESS, |
| 439 | .name = "Sharpness", |
| 440 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 441 | .selector = UVC_PU_SHARPNESS_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 442 | .size = 16, |
| 443 | .offset = 0, |
| 444 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 445 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 446 | }, |
| 447 | { |
| 448 | .id = V4L2_CID_GAMMA, |
| 449 | .name = "Gamma", |
| 450 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 451 | .selector = UVC_PU_GAMMA_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 452 | .size = 16, |
| 453 | .offset = 0, |
| 454 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 455 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 456 | }, |
| 457 | { |
| 458 | .id = V4L2_CID_BACKLIGHT_COMPENSATION, |
| 459 | .name = "Backlight Compensation", |
| 460 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 461 | .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 462 | .size = 16, |
| 463 | .offset = 0, |
| 464 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 465 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 466 | }, |
| 467 | { |
| 468 | .id = V4L2_CID_GAIN, |
| 469 | .name = "Gain", |
| 470 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 471 | .selector = UVC_PU_GAIN_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 472 | .size = 16, |
| 473 | .offset = 0, |
| 474 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 475 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 476 | }, |
| 477 | { |
| 478 | .id = V4L2_CID_POWER_LINE_FREQUENCY, |
| 479 | .name = "Power Line Frequency", |
| 480 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 481 | .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 482 | .size = 2, |
| 483 | .offset = 0, |
| 484 | .v4l2_type = V4L2_CTRL_TYPE_MENU, |
| 485 | .data_type = UVC_CTRL_DATA_TYPE_ENUM, |
| 486 | .menu_info = power_line_frequency_controls, |
| 487 | .menu_count = ARRAY_SIZE(power_line_frequency_controls), |
| 488 | }, |
| 489 | { |
| 490 | .id = V4L2_CID_HUE_AUTO, |
| 491 | .name = "Hue, Auto", |
| 492 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 493 | .selector = UVC_PU_HUE_AUTO_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 494 | .size = 1, |
| 495 | .offset = 0, |
| 496 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| 497 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 498 | .slave_ids = { V4L2_CID_HUE, }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 499 | }, |
| 500 | { |
| 501 | .id = V4L2_CID_EXPOSURE_AUTO, |
| 502 | .name = "Exposure, Auto", |
| 503 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 504 | .selector = UVC_CT_AE_MODE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 505 | .size = 4, |
| 506 | .offset = 0, |
| 507 | .v4l2_type = V4L2_CTRL_TYPE_MENU, |
| 508 | .data_type = UVC_CTRL_DATA_TYPE_BITMASK, |
| 509 | .menu_info = exposure_auto_controls, |
| 510 | .menu_count = ARRAY_SIZE(exposure_auto_controls), |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 511 | .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 512 | }, |
| 513 | { |
| 514 | .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY, |
| 515 | .name = "Exposure, Auto Priority", |
| 516 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 517 | .selector = UVC_CT_AE_PRIORITY_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 518 | .size = 1, |
| 519 | .offset = 0, |
| 520 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| 521 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
| 522 | }, |
| 523 | { |
| 524 | .id = V4L2_CID_EXPOSURE_ABSOLUTE, |
| 525 | .name = "Exposure (Absolute)", |
| 526 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 527 | .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 528 | .size = 32, |
| 529 | .offset = 0, |
| 530 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 531 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 532 | .master_id = V4L2_CID_EXPOSURE_AUTO, |
| 533 | .master_manual = V4L2_EXPOSURE_MANUAL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 534 | }, |
| 535 | { |
| 536 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 537 | .name = "White Balance Temperature, Auto", |
| 538 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 539 | .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 540 | .size = 1, |
| 541 | .offset = 0, |
| 542 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| 543 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 544 | .slave_ids = { V4L2_CID_WHITE_BALANCE_TEMPERATURE, }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 545 | }, |
| 546 | { |
| 547 | .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, |
| 548 | .name = "White Balance Temperature", |
| 549 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 550 | .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 551 | .size = 16, |
| 552 | .offset = 0, |
| 553 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 554 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 555 | .master_id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 556 | .master_manual = 0, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 557 | }, |
| 558 | { |
| 559 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 560 | .name = "White Balance Component, Auto", |
| 561 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 562 | .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 563 | .size = 1, |
| 564 | .offset = 0, |
| 565 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| 566 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 567 | .slave_ids = { V4L2_CID_BLUE_BALANCE, |
| 568 | V4L2_CID_RED_BALANCE }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 569 | }, |
| 570 | { |
| 571 | .id = V4L2_CID_BLUE_BALANCE, |
| 572 | .name = "White Balance Blue Component", |
| 573 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 574 | .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 575 | .size = 16, |
| 576 | .offset = 0, |
| 577 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 578 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 579 | .master_id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 580 | .master_manual = 0, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 581 | }, |
| 582 | { |
| 583 | .id = V4L2_CID_RED_BALANCE, |
| 584 | .name = "White Balance Red Component", |
| 585 | .entity = UVC_GUID_UVC_PROCESSING, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 586 | .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 587 | .size = 16, |
| 588 | .offset = 16, |
| 589 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 590 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 591 | .master_id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 592 | .master_manual = 0, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 593 | }, |
| 594 | { |
| 595 | .id = V4L2_CID_FOCUS_ABSOLUTE, |
| 596 | .name = "Focus (absolute)", |
| 597 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 598 | .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 599 | .size = 16, |
| 600 | .offset = 0, |
| 601 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 602 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 603 | .master_id = V4L2_CID_FOCUS_AUTO, |
| 604 | .master_manual = 0, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 605 | }, |
| 606 | { |
| 607 | .id = V4L2_CID_FOCUS_AUTO, |
| 608 | .name = "Focus, Auto", |
| 609 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 610 | .selector = UVC_CT_FOCUS_AUTO_CONTROL, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 611 | .size = 1, |
| 612 | .offset = 0, |
| 613 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| 614 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 615 | .slave_ids = { V4L2_CID_FOCUS_ABSOLUTE, }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 616 | }, |
Laurent Pinchart | 6df126f | 2008-12-16 06:44:11 -0300 | [diff] [blame] | 617 | { |
Laurent Pinchart | 35a00c4 | 2010-01-20 12:13:46 -0300 | [diff] [blame] | 618 | .id = V4L2_CID_IRIS_ABSOLUTE, |
| 619 | .name = "Iris, Absolute", |
| 620 | .entity = UVC_GUID_UVC_CAMERA, |
| 621 | .selector = UVC_CT_IRIS_ABSOLUTE_CONTROL, |
| 622 | .size = 16, |
| 623 | .offset = 0, |
| 624 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 625 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 626 | }, |
| 627 | { |
| 628 | .id = V4L2_CID_IRIS_RELATIVE, |
| 629 | .name = "Iris, Relative", |
| 630 | .entity = UVC_GUID_UVC_CAMERA, |
| 631 | .selector = UVC_CT_IRIS_RELATIVE_CONTROL, |
| 632 | .size = 8, |
| 633 | .offset = 0, |
| 634 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 635 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, |
| 636 | }, |
| 637 | { |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 638 | .id = V4L2_CID_ZOOM_ABSOLUTE, |
| 639 | .name = "Zoom, Absolute", |
| 640 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 641 | .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL, |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 642 | .size = 16, |
| 643 | .offset = 0, |
| 644 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 645 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 646 | }, |
| 647 | { |
| 648 | .id = V4L2_CID_ZOOM_CONTINUOUS, |
| 649 | .name = "Zoom, Continuous", |
| 650 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 651 | .selector = UVC_CT_ZOOM_RELATIVE_CONTROL, |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 652 | .size = 0, |
| 653 | .offset = 0, |
| 654 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 655 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, |
| 656 | .get = uvc_ctrl_get_zoom, |
| 657 | .set = uvc_ctrl_set_zoom, |
| 658 | }, |
| 659 | { |
Martin Rubli | e56be91 | 2010-05-19 19:51:56 -0300 | [diff] [blame] | 660 | .id = V4L2_CID_PAN_ABSOLUTE, |
| 661 | .name = "Pan (Absolute)", |
| 662 | .entity = UVC_GUID_UVC_CAMERA, |
| 663 | .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL, |
| 664 | .size = 32, |
| 665 | .offset = 0, |
| 666 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 667 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 668 | }, |
| 669 | { |
| 670 | .id = V4L2_CID_TILT_ABSOLUTE, |
| 671 | .name = "Tilt (Absolute)", |
| 672 | .entity = UVC_GUID_UVC_CAMERA, |
| 673 | .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL, |
| 674 | .size = 32, |
| 675 | .offset = 32, |
| 676 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, |
| 677 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, |
| 678 | }, |
| 679 | { |
Laurent Pinchart | 6df126f | 2008-12-16 06:44:11 -0300 | [diff] [blame] | 680 | .id = V4L2_CID_PRIVACY, |
| 681 | .name = "Privacy", |
| 682 | .entity = UVC_GUID_UVC_CAMERA, |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 683 | .selector = UVC_CT_PRIVACY_CONTROL, |
Laurent Pinchart | 6df126f | 2008-12-16 06:44:11 -0300 | [diff] [blame] | 684 | .size = 1, |
| 685 | .offset = 0, |
| 686 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, |
| 687 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, |
| 688 | }, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 689 | }; |
| 690 | |
| 691 | /* ------------------------------------------------------------------------ |
| 692 | * Utility functions |
| 693 | */ |
| 694 | |
| 695 | static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id) |
| 696 | { |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 697 | return ctrl->uvc_data + id * ctrl->info.size; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 698 | } |
| 699 | |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 700 | static inline int uvc_test_bit(const __u8 *data, int bit) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 701 | { |
| 702 | return (data[bit >> 3] >> (bit & 7)) & 1; |
| 703 | } |
| 704 | |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 705 | static inline void uvc_clear_bit(__u8 *data, int bit) |
| 706 | { |
| 707 | data[bit >> 3] &= ~(1 << (bit & 7)); |
| 708 | } |
| 709 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 710 | /* Extract the bit string specified by mapping->offset and mapping->size |
| 711 | * from the little-endian data stored at 'data' and return the result as |
| 712 | * a signed 32bit integer. Sign extension will be performed if the mapping |
| 713 | * references a signed data type. |
| 714 | */ |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 715 | static __s32 uvc_get_le_value(struct uvc_control_mapping *mapping, |
| 716 | __u8 query, const __u8 *data) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 717 | { |
| 718 | int bits = mapping->size; |
| 719 | int offset = mapping->offset; |
| 720 | __s32 value = 0; |
| 721 | __u8 mask; |
| 722 | |
| 723 | data += offset / 8; |
| 724 | offset &= 7; |
| 725 | mask = ((1LL << bits) - 1) << offset; |
| 726 | |
| 727 | for (; bits > 0; data++) { |
| 728 | __u8 byte = *data & mask; |
| 729 | value |= offset > 0 ? (byte >> offset) : (byte << (-offset)); |
| 730 | bits -= 8 - (offset > 0 ? offset : 0); |
| 731 | offset -= 8; |
| 732 | mask = (1 << bits) - 1; |
| 733 | } |
| 734 | |
Laurent Pinchart | 2c2d264 | 2009-01-03 19:12:40 -0300 | [diff] [blame] | 735 | /* Sign-extend the value if needed. */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 736 | if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED) |
| 737 | value |= -(value & (1 << (mapping->size - 1))); |
| 738 | |
| 739 | return value; |
| 740 | } |
| 741 | |
| 742 | /* Set the bit string specified by mapping->offset and mapping->size |
| 743 | * in the little-endian data stored at 'data' to the value 'value'. |
| 744 | */ |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 745 | static void uvc_set_le_value(struct uvc_control_mapping *mapping, |
| 746 | __s32 value, __u8 *data) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 747 | { |
| 748 | int bits = mapping->size; |
| 749 | int offset = mapping->offset; |
| 750 | __u8 mask; |
| 751 | |
Hans de Goede | 3653639 | 2010-05-19 20:15:00 -0300 | [diff] [blame] | 752 | /* According to the v4l2 spec, writing any value to a button control |
| 753 | * should result in the action belonging to the button control being |
| 754 | * triggered. UVC devices however want to see a 1 written -> override |
| 755 | * value. |
| 756 | */ |
| 757 | if (mapping->v4l2_type == V4L2_CTRL_TYPE_BUTTON) |
| 758 | value = -1; |
| 759 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 760 | data += offset / 8; |
| 761 | offset &= 7; |
| 762 | |
| 763 | for (; bits > 0; data++) { |
| 764 | mask = ((1LL << bits) - 1) << offset; |
| 765 | *data = (*data & ~mask) | ((value << offset) & mask); |
| 766 | value >>= offset ? offset : 8; |
| 767 | bits -= 8 - offset; |
| 768 | offset = 0; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | /* ------------------------------------------------------------------------ |
| 773 | * Terminal and unit management |
| 774 | */ |
| 775 | |
| 776 | static const __u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; |
| 777 | static const __u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; |
| 778 | static const __u8 uvc_media_transport_input_guid[16] = |
| 779 | UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; |
| 780 | |
Laurent Pinchart | f9d81df | 2010-09-17 05:24:13 -0300 | [diff] [blame] | 781 | static int uvc_entity_match_guid(const struct uvc_entity *entity, |
| 782 | const __u8 guid[16]) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 783 | { |
| 784 | switch (UVC_ENTITY_TYPE(entity)) { |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 785 | case UVC_ITT_CAMERA: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 786 | return memcmp(uvc_camera_guid, guid, 16) == 0; |
| 787 | |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 788 | case UVC_ITT_MEDIA_TRANSPORT_INPUT: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 789 | return memcmp(uvc_media_transport_input_guid, guid, 16) == 0; |
| 790 | |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 791 | case UVC_VC_PROCESSING_UNIT: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 792 | return memcmp(uvc_processing_guid, guid, 16) == 0; |
| 793 | |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 794 | case UVC_VC_EXTENSION_UNIT: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 795 | return memcmp(entity->extension.guidExtensionCode, |
| 796 | guid, 16) == 0; |
| 797 | |
| 798 | default: |
| 799 | return 0; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | /* ------------------------------------------------------------------------ |
| 804 | * UVC Controls |
| 805 | */ |
| 806 | |
| 807 | static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id, |
| 808 | struct uvc_control_mapping **mapping, struct uvc_control **control, |
| 809 | int next) |
| 810 | { |
| 811 | struct uvc_control *ctrl; |
| 812 | struct uvc_control_mapping *map; |
| 813 | unsigned int i; |
| 814 | |
| 815 | if (entity == NULL) |
| 816 | return; |
| 817 | |
| 818 | for (i = 0; i < entity->ncontrols; ++i) { |
| 819 | ctrl = &entity->controls[i]; |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 820 | if (!ctrl->initialized) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 821 | continue; |
| 822 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 823 | list_for_each_entry(map, &ctrl->info.mappings, list) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 824 | if ((map->id == v4l2_id) && !next) { |
| 825 | *control = ctrl; |
| 826 | *mapping = map; |
| 827 | return; |
| 828 | } |
| 829 | |
| 830 | if ((*mapping == NULL || (*mapping)->id > map->id) && |
| 831 | (map->id > v4l2_id) && next) { |
| 832 | *control = ctrl; |
| 833 | *mapping = map; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 839 | static struct uvc_control *uvc_find_control(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 840 | __u32 v4l2_id, struct uvc_control_mapping **mapping) |
| 841 | { |
| 842 | struct uvc_control *ctrl = NULL; |
| 843 | struct uvc_entity *entity; |
| 844 | int next = v4l2_id & V4L2_CTRL_FLAG_NEXT_CTRL; |
| 845 | |
| 846 | *mapping = NULL; |
| 847 | |
| 848 | /* Mask the query flags. */ |
| 849 | v4l2_id &= V4L2_CTRL_ID_MASK; |
| 850 | |
| 851 | /* Find the control. */ |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 852 | list_for_each_entry(entity, &chain->entities, chain) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 853 | __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next); |
| 854 | if (ctrl && !next) |
| 855 | return ctrl; |
| 856 | } |
| 857 | |
| 858 | if (ctrl == NULL && !next) |
| 859 | uvc_trace(UVC_TRACE_CONTROL, "Control 0x%08x not found.\n", |
| 860 | v4l2_id); |
| 861 | |
| 862 | return ctrl; |
| 863 | } |
| 864 | |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 865 | static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain, |
| 866 | struct uvc_control *ctrl) |
| 867 | { |
| 868 | int ret; |
| 869 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 870 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) { |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 871 | ret = uvc_query_ctrl(chain->dev, UVC_GET_DEF, ctrl->entity->id, |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 872 | chain->dev->intfnum, ctrl->info.selector, |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 873 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 874 | ctrl->info.size); |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 875 | if (ret < 0) |
| 876 | return ret; |
| 877 | } |
| 878 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 879 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) { |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 880 | ret = uvc_query_ctrl(chain->dev, UVC_GET_MIN, ctrl->entity->id, |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 881 | chain->dev->intfnum, ctrl->info.selector, |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 882 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 883 | ctrl->info.size); |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 884 | if (ret < 0) |
| 885 | return ret; |
| 886 | } |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 887 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) { |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 888 | ret = uvc_query_ctrl(chain->dev, UVC_GET_MAX, ctrl->entity->id, |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 889 | chain->dev->intfnum, ctrl->info.selector, |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 890 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 891 | ctrl->info.size); |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 892 | if (ret < 0) |
| 893 | return ret; |
| 894 | } |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 895 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) { |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 896 | ret = uvc_query_ctrl(chain->dev, UVC_GET_RES, ctrl->entity->id, |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 897 | chain->dev->intfnum, ctrl->info.selector, |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 898 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 899 | ctrl->info.size); |
Laurent Pinchart | c4d99f8 | 2010-09-30 09:04:03 -0300 | [diff] [blame] | 900 | if (ret < 0) { |
| 901 | if (UVC_ENTITY_TYPE(ctrl->entity) != |
| 902 | UVC_VC_EXTENSION_UNIT) |
| 903 | return ret; |
| 904 | |
| 905 | /* GET_RES is mandatory for XU controls, but some |
| 906 | * cameras still choke on it. Ignore errors and set the |
| 907 | * resolution value to zero. |
| 908 | */ |
| 909 | uvc_warn_once(chain->dev, UVC_WARN_XU_GET_RES, |
| 910 | "UVC non compliance - GET_RES failed on " |
| 911 | "an XU control. Enabling workaround.\n"); |
| 912 | memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES), 0, |
| 913 | ctrl->info.size); |
| 914 | } |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | ctrl->cached = 1; |
| 918 | return 0; |
| 919 | } |
| 920 | |
Hans de Goede | cb74d48 | 2012-04-08 12:59:50 -0300 | [diff] [blame] | 921 | static int __uvc_ctrl_get(struct uvc_video_chain *chain, |
| 922 | struct uvc_control *ctrl, struct uvc_control_mapping *mapping, |
| 923 | s32 *value) |
| 924 | { |
| 925 | struct uvc_menu_info *menu; |
| 926 | unsigned int i; |
| 927 | int ret; |
| 928 | |
| 929 | if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) |
Laurent Pinchart | 30ecb93 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 930 | return -EACCES; |
Hans de Goede | cb74d48 | 2012-04-08 12:59:50 -0300 | [diff] [blame] | 931 | |
| 932 | if (!ctrl->loaded) { |
| 933 | ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, |
| 934 | chain->dev->intfnum, ctrl->info.selector, |
| 935 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), |
| 936 | ctrl->info.size); |
| 937 | if (ret < 0) |
| 938 | return ret; |
| 939 | |
| 940 | ctrl->loaded = 1; |
| 941 | } |
| 942 | |
| 943 | *value = mapping->get(mapping, UVC_GET_CUR, |
| 944 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); |
| 945 | |
| 946 | if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { |
| 947 | menu = mapping->menu_info; |
| 948 | for (i = 0; i < mapping->menu_count; ++i, ++menu) { |
| 949 | if (menu->value == *value) { |
| 950 | *value = i; |
| 951 | break; |
| 952 | } |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 959 | static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, |
| 960 | struct uvc_control *ctrl, |
| 961 | struct uvc_control_mapping *mapping, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 962 | struct v4l2_queryctrl *v4l2_ctrl) |
| 963 | { |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 964 | struct uvc_control_mapping *master_map = NULL; |
| 965 | struct uvc_control *master_ctrl = NULL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 966 | struct uvc_menu_info *menu; |
| 967 | unsigned int i; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 968 | |
Laurent Pinchart | 54812c7 | 2008-07-17 07:37:37 -0300 | [diff] [blame] | 969 | memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 970 | v4l2_ctrl->id = mapping->id; |
| 971 | v4l2_ctrl->type = mapping->v4l2_type; |
Laurent Pinchart | d0ebf30 | 2009-01-08 14:05:11 -0300 | [diff] [blame] | 972 | strlcpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 973 | v4l2_ctrl->flags = 0; |
| 974 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 975 | if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) |
Laurent Pinchart | a90ef69 | 2010-04-25 16:23:24 -0300 | [diff] [blame] | 976 | v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 977 | if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 978 | v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
| 979 | |
Hans de Goede | 55afeb8 | 2012-04-08 12:59:52 -0300 | [diff] [blame] | 980 | if (mapping->master_id) |
| 981 | __uvc_find_control(ctrl->entity, mapping->master_id, |
| 982 | &master_map, &master_ctrl, 0); |
| 983 | if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) { |
| 984 | s32 val; |
| 985 | int ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); |
| 986 | if (ret < 0) |
| 987 | return ret; |
| 988 | |
| 989 | if (val != mapping->master_manual) |
| 990 | v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; |
| 991 | } |
| 992 | |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 993 | if (!ctrl->cached) { |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 994 | int ret = uvc_ctrl_populate_cache(chain, ctrl); |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 995 | if (ret < 0) |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 996 | return ret; |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 997 | } |
| 998 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 999 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) { |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 1000 | v4l2_ctrl->default_value = mapping->get(mapping, UVC_GET_DEF, |
| 1001 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1002 | } |
| 1003 | |
Laurent Pinchart | 54812c7 | 2008-07-17 07:37:37 -0300 | [diff] [blame] | 1004 | switch (mapping->v4l2_type) { |
| 1005 | case V4L2_CTRL_TYPE_MENU: |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1006 | v4l2_ctrl->minimum = 0; |
| 1007 | v4l2_ctrl->maximum = mapping->menu_count - 1; |
| 1008 | v4l2_ctrl->step = 1; |
| 1009 | |
| 1010 | menu = mapping->menu_info; |
| 1011 | for (i = 0; i < mapping->menu_count; ++i, ++menu) { |
| 1012 | if (menu->value == v4l2_ctrl->default_value) { |
| 1013 | v4l2_ctrl->default_value = i; |
| 1014 | break; |
| 1015 | } |
| 1016 | } |
| 1017 | |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1018 | return 0; |
Laurent Pinchart | 54812c7 | 2008-07-17 07:37:37 -0300 | [diff] [blame] | 1019 | |
| 1020 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 1021 | v4l2_ctrl->minimum = 0; |
| 1022 | v4l2_ctrl->maximum = 1; |
| 1023 | v4l2_ctrl->step = 1; |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1024 | return 0; |
Laurent Pinchart | 54812c7 | 2008-07-17 07:37:37 -0300 | [diff] [blame] | 1025 | |
Laurent Pinchart | f4eabaf | 2009-08-06 06:05:40 -0300 | [diff] [blame] | 1026 | case V4L2_CTRL_TYPE_BUTTON: |
| 1027 | v4l2_ctrl->minimum = 0; |
| 1028 | v4l2_ctrl->maximum = 0; |
| 1029 | v4l2_ctrl->step = 0; |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1030 | return 0; |
Laurent Pinchart | f4eabaf | 2009-08-06 06:05:40 -0300 | [diff] [blame] | 1031 | |
Laurent Pinchart | 54812c7 | 2008-07-17 07:37:37 -0300 | [diff] [blame] | 1032 | default: |
| 1033 | break; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1034 | } |
| 1035 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1036 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 1037 | v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, |
| 1038 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1039 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1040 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 1041 | v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, |
| 1042 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); |
| 1043 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1044 | if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) |
Laurent Pinchart | 5952908 | 2010-01-23 06:30:20 -0300 | [diff] [blame] | 1045 | v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, |
| 1046 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); |
| 1047 | |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, |
| 1052 | struct v4l2_queryctrl *v4l2_ctrl) |
| 1053 | { |
| 1054 | struct uvc_control *ctrl; |
| 1055 | struct uvc_control_mapping *mapping; |
| 1056 | int ret; |
| 1057 | |
| 1058 | ret = mutex_lock_interruptible(&chain->ctrl_mutex); |
| 1059 | if (ret < 0) |
| 1060 | return -ERESTARTSYS; |
| 1061 | |
| 1062 | ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping); |
| 1063 | if (ctrl == NULL) { |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1064 | ret = -ENOENT; |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1065 | goto done; |
| 1066 | } |
| 1067 | |
| 1068 | ret = __uvc_query_v4l2_ctrl(chain, ctrl, mapping, v4l2_ctrl); |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1069 | done: |
| 1070 | mutex_unlock(&chain->ctrl_mutex); |
| 1071 | return ret; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1072 | } |
| 1073 | |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 1074 | /* |
| 1075 | * Mapping V4L2 controls to UVC controls can be straighforward if done well. |
| 1076 | * Most of the UVC controls exist in V4L2, and can be mapped directly. Some |
| 1077 | * must be grouped (for instance the Red Balance, Blue Balance and Do White |
| 1078 | * Balance V4L2 controls use the White Balance Component UVC control) or |
| 1079 | * otherwise translated. The approach we take here is to use a translation |
| 1080 | * table for the controls that can be mapped directly, and handle the others |
| 1081 | * manually. |
| 1082 | */ |
| 1083 | int uvc_query_v4l2_menu(struct uvc_video_chain *chain, |
| 1084 | struct v4l2_querymenu *query_menu) |
| 1085 | { |
| 1086 | struct uvc_menu_info *menu_info; |
| 1087 | struct uvc_control_mapping *mapping; |
| 1088 | struct uvc_control *ctrl; |
| 1089 | u32 index = query_menu->index; |
| 1090 | u32 id = query_menu->id; |
| 1091 | int ret; |
| 1092 | |
| 1093 | memset(query_menu, 0, sizeof(*query_menu)); |
| 1094 | query_menu->id = id; |
| 1095 | query_menu->index = index; |
| 1096 | |
| 1097 | ret = mutex_lock_interruptible(&chain->ctrl_mutex); |
| 1098 | if (ret < 0) |
| 1099 | return -ERESTARTSYS; |
| 1100 | |
| 1101 | ctrl = uvc_find_control(chain, query_menu->id, &mapping); |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1102 | if (ctrl == NULL) { |
| 1103 | ret = -ENOENT; |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 1104 | goto done; |
| 1105 | } |
| 1106 | |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1107 | if (mapping->v4l2_type != V4L2_CTRL_TYPE_MENU || |
| 1108 | query_menu->index >= mapping->menu_count) { |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 1109 | ret = -EINVAL; |
| 1110 | goto done; |
| 1111 | } |
| 1112 | |
| 1113 | menu_info = &mapping->menu_info[query_menu->index]; |
Laurent Pinchart | fc2d573 | 2011-04-30 09:46:11 -0300 | [diff] [blame] | 1114 | |
Hans de Goede | 241fa6e | 2011-10-11 11:54:26 -0300 | [diff] [blame] | 1115 | if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK && |
| 1116 | (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)) { |
Laurent Pinchart | fc2d573 | 2011-04-30 09:46:11 -0300 | [diff] [blame] | 1117 | s32 bitmap; |
| 1118 | |
| 1119 | if (!ctrl->cached) { |
| 1120 | ret = uvc_ctrl_populate_cache(chain, ctrl); |
| 1121 | if (ret < 0) |
| 1122 | goto done; |
| 1123 | } |
| 1124 | |
| 1125 | bitmap = mapping->get(mapping, UVC_GET_RES, |
| 1126 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); |
| 1127 | if (!(bitmap & menu_info->value)) { |
| 1128 | ret = -EINVAL; |
| 1129 | goto done; |
| 1130 | } |
| 1131 | } |
| 1132 | |
Laurent Pinchart | 23d9f3e | 2010-11-21 07:58:54 -0300 | [diff] [blame] | 1133 | strlcpy(query_menu->name, menu_info->name, sizeof query_menu->name); |
| 1134 | |
| 1135 | done: |
| 1136 | mutex_unlock(&chain->ctrl_mutex); |
| 1137 | return ret; |
| 1138 | } |
| 1139 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1140 | /* -------------------------------------------------------------------------- |
| 1141 | * Ctrl event handling |
| 1142 | */ |
| 1143 | |
| 1144 | static void uvc_ctrl_fill_event(struct uvc_video_chain *chain, |
| 1145 | struct v4l2_event *ev, |
| 1146 | struct uvc_control *ctrl, |
| 1147 | struct uvc_control_mapping *mapping, |
| 1148 | s32 value, u32 changes) |
| 1149 | { |
| 1150 | struct v4l2_queryctrl v4l2_ctrl; |
| 1151 | |
| 1152 | __uvc_query_v4l2_ctrl(chain, ctrl, mapping, &v4l2_ctrl); |
| 1153 | |
| 1154 | memset(ev->reserved, 0, sizeof(ev->reserved)); |
| 1155 | ev->type = V4L2_EVENT_CTRL; |
| 1156 | ev->id = v4l2_ctrl.id; |
| 1157 | ev->u.ctrl.value = value; |
| 1158 | ev->u.ctrl.changes = changes; |
| 1159 | ev->u.ctrl.type = v4l2_ctrl.type; |
| 1160 | ev->u.ctrl.flags = v4l2_ctrl.flags; |
| 1161 | ev->u.ctrl.minimum = v4l2_ctrl.minimum; |
| 1162 | ev->u.ctrl.maximum = v4l2_ctrl.maximum; |
| 1163 | ev->u.ctrl.step = v4l2_ctrl.step; |
| 1164 | ev->u.ctrl.default_value = v4l2_ctrl.default_value; |
| 1165 | } |
| 1166 | |
| 1167 | static void uvc_ctrl_send_event(struct uvc_fh *handle, |
| 1168 | struct uvc_control *ctrl, struct uvc_control_mapping *mapping, |
| 1169 | s32 value, u32 changes) |
| 1170 | { |
| 1171 | struct v4l2_subscribed_event *sev; |
| 1172 | struct v4l2_event ev; |
| 1173 | |
| 1174 | if (list_empty(&mapping->ev_subs)) |
| 1175 | return; |
| 1176 | |
| 1177 | uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, value, changes); |
| 1178 | |
| 1179 | list_for_each_entry(sev, &mapping->ev_subs, node) { |
| 1180 | if (sev->fh && (sev->fh != &handle->vfh || |
Hans de Goede | 805e9b4 | 2012-04-08 12:59:53 -0300 | [diff] [blame] | 1181 | (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK) || |
| 1182 | (changes & V4L2_EVENT_CTRL_CH_FLAGS))) |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1183 | v4l2_event_queue_fh(sev->fh, &ev); |
| 1184 | } |
| 1185 | } |
| 1186 | |
Hans de Goede | 805e9b4 | 2012-04-08 12:59:53 -0300 | [diff] [blame] | 1187 | static void uvc_ctrl_send_slave_event(struct uvc_fh *handle, |
| 1188 | struct uvc_control *master, u32 slave_id, |
| 1189 | const struct v4l2_ext_control *xctrls, unsigned int xctrls_count) |
| 1190 | { |
| 1191 | struct uvc_control_mapping *mapping = NULL; |
| 1192 | struct uvc_control *ctrl = NULL; |
| 1193 | u32 changes = V4L2_EVENT_CTRL_CH_FLAGS; |
| 1194 | unsigned int i; |
| 1195 | s32 val = 0; |
| 1196 | |
| 1197 | /* |
| 1198 | * We can skip sending an event for the slave if the slave |
| 1199 | * is being modified in the same transaction. |
| 1200 | */ |
| 1201 | for (i = 0; i < xctrls_count; i++) { |
| 1202 | if (xctrls[i].id == slave_id) |
| 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | __uvc_find_control(master->entity, slave_id, &mapping, &ctrl, 0); |
| 1207 | if (ctrl == NULL) |
| 1208 | return; |
| 1209 | |
| 1210 | if (__uvc_ctrl_get(handle->chain, ctrl, mapping, &val) == 0) |
| 1211 | changes |= V4L2_EVENT_CTRL_CH_VALUE; |
| 1212 | |
| 1213 | uvc_ctrl_send_event(handle, ctrl, mapping, val, changes); |
| 1214 | } |
| 1215 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1216 | static void uvc_ctrl_send_events(struct uvc_fh *handle, |
| 1217 | const struct v4l2_ext_control *xctrls, unsigned int xctrls_count) |
| 1218 | { |
| 1219 | struct uvc_control_mapping *mapping; |
| 1220 | struct uvc_control *ctrl; |
Hans de Goede | 805e9b4 | 2012-04-08 12:59:53 -0300 | [diff] [blame] | 1221 | u32 changes = V4L2_EVENT_CTRL_CH_VALUE; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1222 | unsigned int i; |
Hans de Goede | 805e9b4 | 2012-04-08 12:59:53 -0300 | [diff] [blame] | 1223 | unsigned int j; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1224 | |
| 1225 | for (i = 0; i < xctrls_count; ++i) { |
| 1226 | ctrl = uvc_find_control(handle->chain, xctrls[i].id, &mapping); |
Hans de Goede | 805e9b4 | 2012-04-08 12:59:53 -0300 | [diff] [blame] | 1227 | |
| 1228 | for (j = 0; j < ARRAY_SIZE(mapping->slave_ids); ++j) { |
| 1229 | if (!mapping->slave_ids[j]) |
| 1230 | break; |
| 1231 | uvc_ctrl_send_slave_event(handle, ctrl, |
| 1232 | mapping->slave_ids[j], |
| 1233 | xctrls, xctrls_count); |
| 1234 | } |
| 1235 | |
| 1236 | /* |
| 1237 | * If the master is being modified in the same transaction |
| 1238 | * flags may change too. |
| 1239 | */ |
| 1240 | if (mapping->master_id) { |
| 1241 | for (j = 0; j < xctrls_count; j++) { |
| 1242 | if (xctrls[j].id == mapping->master_id) { |
| 1243 | changes |= V4L2_EVENT_CTRL_CH_FLAGS; |
| 1244 | break; |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1249 | uvc_ctrl_send_event(handle, ctrl, mapping, xctrls[i].value, |
Hans de Goede | 805e9b4 | 2012-04-08 12:59:53 -0300 | [diff] [blame] | 1250 | changes); |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
Hans Verkuil | 6e6d76c | 2012-05-07 16:53:20 -0300 | [diff] [blame] | 1254 | static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems) |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1255 | { |
| 1256 | struct uvc_fh *handle = container_of(sev->fh, struct uvc_fh, vfh); |
| 1257 | struct uvc_control_mapping *mapping; |
| 1258 | struct uvc_control *ctrl; |
| 1259 | int ret; |
| 1260 | |
| 1261 | ret = mutex_lock_interruptible(&handle->chain->ctrl_mutex); |
| 1262 | if (ret < 0) |
| 1263 | return -ERESTARTSYS; |
| 1264 | |
| 1265 | ctrl = uvc_find_control(handle->chain, sev->id, &mapping); |
| 1266 | if (ctrl == NULL) { |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1267 | ret = -ENOENT; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1268 | goto done; |
| 1269 | } |
| 1270 | |
| 1271 | list_add_tail(&sev->node, &mapping->ev_subs); |
| 1272 | if (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL) { |
| 1273 | struct v4l2_event ev; |
| 1274 | u32 changes = V4L2_EVENT_CTRL_CH_FLAGS; |
| 1275 | s32 val = 0; |
| 1276 | |
| 1277 | if (__uvc_ctrl_get(handle->chain, ctrl, mapping, &val) == 0) |
| 1278 | changes |= V4L2_EVENT_CTRL_CH_VALUE; |
| 1279 | |
| 1280 | uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, val, |
| 1281 | changes); |
Hans Verkuil | 6e6d76c | 2012-05-07 16:53:20 -0300 | [diff] [blame] | 1282 | /* Mark the queue as active, allowing this initial |
| 1283 | event to be accepted. */ |
| 1284 | sev->elems = elems; |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1285 | v4l2_event_queue_fh(sev->fh, &ev); |
| 1286 | } |
| 1287 | |
| 1288 | done: |
| 1289 | mutex_unlock(&handle->chain->ctrl_mutex); |
| 1290 | return ret; |
| 1291 | } |
| 1292 | |
| 1293 | static void uvc_ctrl_del_event(struct v4l2_subscribed_event *sev) |
| 1294 | { |
| 1295 | struct uvc_fh *handle = container_of(sev->fh, struct uvc_fh, vfh); |
| 1296 | |
| 1297 | mutex_lock(&handle->chain->ctrl_mutex); |
| 1298 | list_del(&sev->node); |
| 1299 | mutex_unlock(&handle->chain->ctrl_mutex); |
| 1300 | } |
| 1301 | |
| 1302 | const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops = { |
| 1303 | .add = uvc_ctrl_add_event, |
| 1304 | .del = uvc_ctrl_del_event, |
| 1305 | .replace = v4l2_ctrl_replace, |
| 1306 | .merge = v4l2_ctrl_merge, |
| 1307 | }; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1308 | |
| 1309 | /* -------------------------------------------------------------------------- |
| 1310 | * Control transactions |
| 1311 | * |
| 1312 | * To make extended set operations as atomic as the hardware allows, controls |
| 1313 | * are handled using begin/commit/rollback operations. |
| 1314 | * |
| 1315 | * At the beginning of a set request, uvc_ctrl_begin should be called to |
| 1316 | * initialize the request. This function acquires the control lock. |
| 1317 | * |
| 1318 | * When setting a control, the new value is stored in the control data field |
| 1319 | * at position UVC_CTRL_DATA_CURRENT. The control is then marked as dirty for |
| 1320 | * later processing. If the UVC and V4L2 control sizes differ, the current |
| 1321 | * value is loaded from the hardware before storing the new value in the data |
| 1322 | * field. |
| 1323 | * |
| 1324 | * After processing all controls in the transaction, uvc_ctrl_commit or |
| 1325 | * uvc_ctrl_rollback must be called to apply the pending changes to the |
| 1326 | * hardware or revert them. When applying changes, all controls marked as |
| 1327 | * dirty will be modified in the UVC device, and the dirty flag will be |
| 1328 | * cleared. When reverting controls, the control data field |
| 1329 | * UVC_CTRL_DATA_CURRENT is reverted to its previous value |
| 1330 | * (UVC_CTRL_DATA_BACKUP) for all dirty controls. Both functions release the |
| 1331 | * control lock. |
| 1332 | */ |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1333 | int uvc_ctrl_begin(struct uvc_video_chain *chain) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1334 | { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1335 | return mutex_lock_interruptible(&chain->ctrl_mutex) ? -ERESTARTSYS : 0; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static int uvc_ctrl_commit_entity(struct uvc_device *dev, |
| 1339 | struct uvc_entity *entity, int rollback) |
| 1340 | { |
| 1341 | struct uvc_control *ctrl; |
| 1342 | unsigned int i; |
| 1343 | int ret; |
| 1344 | |
| 1345 | if (entity == NULL) |
| 1346 | return 0; |
| 1347 | |
| 1348 | for (i = 0; i < entity->ncontrols; ++i) { |
| 1349 | ctrl = &entity->controls[i]; |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1350 | if (!ctrl->initialized) |
Laurent Pinchart | b1accfa | 2008-09-27 20:54:02 -0300 | [diff] [blame] | 1351 | continue; |
| 1352 | |
| 1353 | /* Reset the loaded flag for auto-update controls that were |
| 1354 | * marked as loaded in uvc_ctrl_get/uvc_ctrl_set to prevent |
Laurent Pinchart | 6b363f9 | 2012-05-11 09:55:59 -0300 | [diff] [blame] | 1355 | * uvc_ctrl_get from using the cached value, and for write-only |
| 1356 | * controls to prevent uvc_ctrl_set from setting bits not |
| 1357 | * explicitly set by the user. |
Laurent Pinchart | b1accfa | 2008-09-27 20:54:02 -0300 | [diff] [blame] | 1358 | */ |
Laurent Pinchart | 6b363f9 | 2012-05-11 09:55:59 -0300 | [diff] [blame] | 1359 | if (ctrl->info.flags & UVC_CTRL_FLAG_AUTO_UPDATE || |
| 1360 | !(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) |
Laurent Pinchart | b1accfa | 2008-09-27 20:54:02 -0300 | [diff] [blame] | 1361 | ctrl->loaded = 0; |
| 1362 | |
| 1363 | if (!ctrl->dirty) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1364 | continue; |
| 1365 | |
| 1366 | if (!rollback) |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 1367 | ret = uvc_query_ctrl(dev, UVC_SET_CUR, ctrl->entity->id, |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1368 | dev->intfnum, ctrl->info.selector, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1369 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1370 | ctrl->info.size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1371 | else |
| 1372 | ret = 0; |
| 1373 | |
| 1374 | if (rollback || ret < 0) |
| 1375 | memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), |
| 1376 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1377 | ctrl->info.size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1378 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1379 | ctrl->dirty = 0; |
| 1380 | |
| 1381 | if (ret < 0) |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1388 | int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, |
| 1389 | const struct v4l2_ext_control *xctrls, |
| 1390 | unsigned int xctrls_count) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1391 | { |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1392 | struct uvc_video_chain *chain = handle->chain; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1393 | struct uvc_entity *entity; |
| 1394 | int ret = 0; |
| 1395 | |
| 1396 | /* Find the control. */ |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 1397 | list_for_each_entry(entity, &chain->entities, chain) { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1398 | ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1399 | if (ret < 0) |
| 1400 | goto done; |
| 1401 | } |
| 1402 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1403 | if (!rollback) |
| 1404 | uvc_ctrl_send_events(handle, xctrls, xctrls_count); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1405 | done: |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1406 | mutex_unlock(&chain->ctrl_mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1407 | return ret; |
| 1408 | } |
| 1409 | |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1410 | int uvc_ctrl_get(struct uvc_video_chain *chain, |
| 1411 | struct v4l2_ext_control *xctrl) |
| 1412 | { |
| 1413 | struct uvc_control *ctrl; |
| 1414 | struct uvc_control_mapping *mapping; |
| 1415 | |
| 1416 | ctrl = uvc_find_control(chain, xctrl->id, &mapping); |
| 1417 | if (ctrl == NULL) |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1418 | return -ENOENT; |
Hans de Goede | 35f1674 | 2012-04-08 12:59:49 -0300 | [diff] [blame] | 1419 | |
| 1420 | return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); |
| 1421 | } |
| 1422 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1423 | int uvc_ctrl_set(struct uvc_video_chain *chain, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1424 | struct v4l2_ext_control *xctrl) |
| 1425 | { |
| 1426 | struct uvc_control *ctrl; |
| 1427 | struct uvc_control_mapping *mapping; |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1428 | s32 value; |
| 1429 | u32 step; |
| 1430 | s32 min; |
| 1431 | s32 max; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1432 | int ret; |
| 1433 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1434 | ctrl = uvc_find_control(chain, xctrl->id, &mapping); |
Laurent Pinchart | f0ed2ce | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1435 | if (ctrl == NULL) |
| 1436 | return -ENOENT; |
| 1437 | if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) |
Laurent Pinchart | 30ecb93 | 2012-08-28 18:38:58 -0300 | [diff] [blame] | 1438 | return -EACCES; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1439 | |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1440 | /* Clamp out of range values. */ |
| 1441 | switch (mapping->v4l2_type) { |
| 1442 | case V4L2_CTRL_TYPE_INTEGER: |
| 1443 | if (!ctrl->cached) { |
| 1444 | ret = uvc_ctrl_populate_cache(chain, ctrl); |
| 1445 | if (ret < 0) |
| 1446 | return ret; |
| 1447 | } |
| 1448 | |
| 1449 | min = mapping->get(mapping, UVC_GET_MIN, |
| 1450 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); |
| 1451 | max = mapping->get(mapping, UVC_GET_MAX, |
| 1452 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); |
| 1453 | step = mapping->get(mapping, UVC_GET_RES, |
| 1454 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); |
Laurent Pinchart | cf7a50e | 2010-04-25 16:27:14 -0300 | [diff] [blame] | 1455 | if (step == 0) |
| 1456 | step = 1; |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1457 | |
Laurent Pinchart | 64ae995 | 2012-09-26 08:15:24 -0300 | [diff] [blame] | 1458 | xctrl->value = min + ((u32)(xctrl->value - min) + step / 2) |
| 1459 | / step * step; |
| 1460 | if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED) |
| 1461 | xctrl->value = clamp(xctrl->value, min, max); |
| 1462 | else |
| 1463 | xctrl->value = clamp_t(u32, xctrl->value, min, max); |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1464 | value = xctrl->value; |
| 1465 | break; |
| 1466 | |
| 1467 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 1468 | xctrl->value = clamp(xctrl->value, 0, 1); |
| 1469 | value = xctrl->value; |
| 1470 | break; |
| 1471 | |
| 1472 | case V4L2_CTRL_TYPE_MENU: |
| 1473 | if (xctrl->value < 0 || xctrl->value >= mapping->menu_count) |
Laurent Pinchart | 8a4e76c | 2010-01-21 16:53:11 -0300 | [diff] [blame] | 1474 | return -ERANGE; |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1475 | value = mapping->menu_info[xctrl->value].value; |
Laurent Pinchart | f411f10 | 2011-04-30 09:46:11 -0300 | [diff] [blame] | 1476 | |
| 1477 | /* Valid menu indices are reported by the GET_RES request for |
| 1478 | * UVC controls that support it. |
| 1479 | */ |
Hans de Goede | 241fa6e | 2011-10-11 11:54:26 -0300 | [diff] [blame] | 1480 | if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK && |
| 1481 | (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)) { |
Laurent Pinchart | f411f10 | 2011-04-30 09:46:11 -0300 | [diff] [blame] | 1482 | if (!ctrl->cached) { |
| 1483 | ret = uvc_ctrl_populate_cache(chain, ctrl); |
| 1484 | if (ret < 0) |
| 1485 | return ret; |
| 1486 | } |
| 1487 | |
| 1488 | step = mapping->get(mapping, UVC_GET_RES, |
| 1489 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); |
| 1490 | if (!(step & value)) |
| 1491 | return -ERANGE; |
| 1492 | } |
| 1493 | |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1494 | break; |
| 1495 | |
| 1496 | default: |
| 1497 | value = xctrl->value; |
| 1498 | break; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1499 | } |
| 1500 | |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1501 | /* If the mapping doesn't span the whole UVC control, the current value |
| 1502 | * needs to be loaded from the device to perform the read-modify-write |
| 1503 | * operation. |
| 1504 | */ |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1505 | if (!ctrl->loaded && (ctrl->info.size * 8) != mapping->size) { |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1506 | if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1507 | memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1508 | 0, ctrl->info.size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1509 | } else { |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1510 | ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, |
| 1511 | ctrl->entity->id, chain->dev->intfnum, |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1512 | ctrl->info.selector, |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1513 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1514 | ctrl->info.size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1515 | if (ret < 0) |
| 1516 | return ret; |
| 1517 | } |
| 1518 | |
Laurent Pinchart | b1accfa | 2008-09-27 20:54:02 -0300 | [diff] [blame] | 1519 | ctrl->loaded = 1; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1520 | } |
| 1521 | |
Laurent Pinchart | e54532e | 2010-01-23 07:07:53 -0300 | [diff] [blame] | 1522 | /* Backup the current value in case we need to rollback later. */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1523 | if (!ctrl->dirty) { |
| 1524 | memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), |
| 1525 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1526 | ctrl->info.size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1527 | } |
| 1528 | |
Laurent Pinchart | 9768352 | 2008-12-16 06:46:32 -0300 | [diff] [blame] | 1529 | mapping->set(mapping, value, |
| 1530 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1531 | |
| 1532 | ctrl->dirty = 1; |
| 1533 | ctrl->modified = 1; |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | /* -------------------------------------------------------------------------- |
| 1538 | * Dynamic controls |
| 1539 | */ |
| 1540 | |
Laurent Pinchart | b5977a5 | 2010-10-01 15:39:49 -0300 | [diff] [blame] | 1541 | static void uvc_ctrl_fixup_xu_info(struct uvc_device *dev, |
| 1542 | const struct uvc_control *ctrl, struct uvc_control_info *info) |
| 1543 | { |
| 1544 | struct uvc_ctrl_fixup { |
| 1545 | struct usb_device_id id; |
| 1546 | u8 entity; |
| 1547 | u8 selector; |
| 1548 | u8 flags; |
| 1549 | }; |
| 1550 | |
| 1551 | static const struct uvc_ctrl_fixup fixups[] = { |
| 1552 | { { USB_DEVICE(0x046d, 0x08c2) }, 9, 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1553 | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX | |
| 1554 | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_SET_CUR | |
| 1555 | UVC_CTRL_FLAG_AUTO_UPDATE }, |
Laurent Pinchart | b5977a5 | 2010-10-01 15:39:49 -0300 | [diff] [blame] | 1556 | { { USB_DEVICE(0x046d, 0x08cc) }, 9, 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1557 | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX | |
| 1558 | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_SET_CUR | |
| 1559 | UVC_CTRL_FLAG_AUTO_UPDATE }, |
Laurent Pinchart | b5977a5 | 2010-10-01 15:39:49 -0300 | [diff] [blame] | 1560 | { { USB_DEVICE(0x046d, 0x0994) }, 9, 1, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1561 | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX | |
| 1562 | UVC_CTRL_FLAG_GET_DEF | UVC_CTRL_FLAG_SET_CUR | |
| 1563 | UVC_CTRL_FLAG_AUTO_UPDATE }, |
Laurent Pinchart | b5977a5 | 2010-10-01 15:39:49 -0300 | [diff] [blame] | 1564 | }; |
| 1565 | |
| 1566 | unsigned int i; |
| 1567 | |
| 1568 | for (i = 0; i < ARRAY_SIZE(fixups); ++i) { |
| 1569 | if (!usb_match_one_id(dev->intf, &fixups[i].id)) |
| 1570 | continue; |
| 1571 | |
| 1572 | if (fixups[i].entity == ctrl->entity->id && |
| 1573 | fixups[i].selector == info->selector) { |
| 1574 | info->flags = fixups[i].flags; |
| 1575 | return; |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1580 | /* |
| 1581 | * Query control information (size and flags) for XU controls. |
| 1582 | */ |
| 1583 | static int uvc_ctrl_fill_xu_info(struct uvc_device *dev, |
| 1584 | const struct uvc_control *ctrl, struct uvc_control_info *info) |
| 1585 | { |
| 1586 | u8 *data; |
| 1587 | int ret; |
| 1588 | |
| 1589 | data = kmalloc(2, GFP_KERNEL); |
| 1590 | if (data == NULL) |
| 1591 | return -ENOMEM; |
| 1592 | |
| 1593 | memcpy(info->entity, ctrl->entity->extension.guidExtensionCode, |
| 1594 | sizeof(info->entity)); |
| 1595 | info->index = ctrl->index; |
| 1596 | info->selector = ctrl->index + 1; |
| 1597 | |
| 1598 | /* Query and verify the control length (GET_LEN) */ |
| 1599 | ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id, dev->intfnum, |
| 1600 | info->selector, data, 2); |
| 1601 | if (ret < 0) { |
| 1602 | uvc_trace(UVC_TRACE_CONTROL, |
| 1603 | "GET_LEN failed on control %pUl/%u (%d).\n", |
| 1604 | info->entity, info->selector, ret); |
| 1605 | goto done; |
| 1606 | } |
| 1607 | |
| 1608 | info->size = le16_to_cpup((__le16 *)data); |
| 1609 | |
| 1610 | /* Query the control information (GET_INFO) */ |
| 1611 | ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, |
| 1612 | info->selector, data, 1); |
| 1613 | if (ret < 0) { |
| 1614 | uvc_trace(UVC_TRACE_CONTROL, |
| 1615 | "GET_INFO failed on control %pUl/%u (%d).\n", |
| 1616 | info->entity, info->selector, ret); |
| 1617 | goto done; |
| 1618 | } |
| 1619 | |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1620 | info->flags = UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX |
| 1621 | | UVC_CTRL_FLAG_GET_RES | UVC_CTRL_FLAG_GET_DEF |
| 1622 | | (data[0] & UVC_CONTROL_CAP_GET ? |
| 1623 | UVC_CTRL_FLAG_GET_CUR : 0) |
| 1624 | | (data[0] & UVC_CONTROL_CAP_SET ? |
| 1625 | UVC_CTRL_FLAG_SET_CUR : 0) |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1626 | | (data[0] & UVC_CONTROL_CAP_AUTOUPDATE ? |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1627 | UVC_CTRL_FLAG_AUTO_UPDATE : 0); |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1628 | |
Laurent Pinchart | b5977a5 | 2010-10-01 15:39:49 -0300 | [diff] [blame] | 1629 | uvc_ctrl_fixup_xu_info(dev, ctrl, info); |
| 1630 | |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1631 | uvc_trace(UVC_TRACE_CONTROL, "XU control %pUl/%u queried: len %u, " |
| 1632 | "flags { get %u set %u auto %u }.\n", |
| 1633 | info->entity, info->selector, info->size, |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1634 | (info->flags & UVC_CTRL_FLAG_GET_CUR) ? 1 : 0, |
| 1635 | (info->flags & UVC_CTRL_FLAG_SET_CUR) ? 1 : 0, |
| 1636 | (info->flags & UVC_CTRL_FLAG_AUTO_UPDATE) ? 1 : 0); |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1637 | |
| 1638 | done: |
| 1639 | kfree(data); |
| 1640 | return ret; |
| 1641 | } |
| 1642 | |
| 1643 | static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, |
| 1644 | const struct uvc_control_info *info); |
| 1645 | |
| 1646 | static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev, |
| 1647 | struct uvc_control *ctrl) |
| 1648 | { |
| 1649 | struct uvc_control_info info; |
| 1650 | int ret; |
| 1651 | |
| 1652 | if (ctrl->initialized) |
| 1653 | return 0; |
| 1654 | |
| 1655 | ret = uvc_ctrl_fill_xu_info(dev, ctrl, &info); |
| 1656 | if (ret < 0) |
| 1657 | return ret; |
| 1658 | |
| 1659 | ret = uvc_ctrl_add_info(dev, ctrl, &info); |
| 1660 | if (ret < 0) |
| 1661 | uvc_trace(UVC_TRACE_CONTROL, "Failed to initialize control " |
| 1662 | "%pUl/%u on device %s entity %u\n", info.entity, |
| 1663 | info.selector, dev->udev->devpath, ctrl->entity->id); |
| 1664 | |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1668 | int uvc_xu_ctrl_query(struct uvc_video_chain *chain, |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1669 | struct uvc_xu_control_query *xqry) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1670 | { |
| 1671 | struct uvc_entity *entity; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1672 | struct uvc_control *ctrl; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1673 | unsigned int i, found = 0; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1674 | __u32 reqflags; |
| 1675 | __u16 size; |
| 1676 | __u8 *data = NULL; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1677 | int ret; |
| 1678 | |
| 1679 | /* Find the extension unit. */ |
Laurent Pinchart | 6241d8c | 2009-11-25 12:00:22 -0300 | [diff] [blame] | 1680 | list_for_each_entry(entity, &chain->entities, chain) { |
| 1681 | if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT && |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1682 | entity->id == xqry->unit) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1683 | break; |
| 1684 | } |
| 1685 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1686 | if (entity->id != xqry->unit) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1687 | uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n", |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1688 | xqry->unit); |
| 1689 | return -ENOENT; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1690 | } |
| 1691 | |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1692 | /* Find the control and perform delayed initialization if needed. */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1693 | for (i = 0; i < entity->ncontrols; ++i) { |
| 1694 | ctrl = &entity->controls[i]; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1695 | if (ctrl->index == xqry->selector - 1) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1696 | found = 1; |
| 1697 | break; |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | if (!found) { |
Laurent Pinchart | 36bd883 | 2010-01-19 09:06:22 -0300 | [diff] [blame] | 1702 | uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u not found.\n", |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1703 | entity->extension.guidExtensionCode, xqry->selector); |
| 1704 | return -ENOENT; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1705 | } |
| 1706 | |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1707 | if (mutex_lock_interruptible(&chain->ctrl_mutex)) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1708 | return -ERESTARTSYS; |
| 1709 | |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1710 | ret = uvc_ctrl_init_xu_ctrl(chain->dev, ctrl); |
| 1711 | if (ret < 0) { |
| 1712 | ret = -ENOENT; |
| 1713 | goto done; |
| 1714 | } |
| 1715 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1716 | /* Validate the required buffer size and flags for the request */ |
| 1717 | reqflags = 0; |
| 1718 | size = ctrl->info.size; |
| 1719 | |
| 1720 | switch (xqry->query) { |
| 1721 | case UVC_GET_CUR: |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1722 | reqflags = UVC_CTRL_FLAG_GET_CUR; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1723 | break; |
| 1724 | case UVC_GET_MIN: |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1725 | reqflags = UVC_CTRL_FLAG_GET_MIN; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1726 | break; |
| 1727 | case UVC_GET_MAX: |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1728 | reqflags = UVC_CTRL_FLAG_GET_MAX; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1729 | break; |
| 1730 | case UVC_GET_DEF: |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1731 | reqflags = UVC_CTRL_FLAG_GET_DEF; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1732 | break; |
| 1733 | case UVC_GET_RES: |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1734 | reqflags = UVC_CTRL_FLAG_GET_RES; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1735 | break; |
| 1736 | case UVC_SET_CUR: |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1737 | reqflags = UVC_CTRL_FLAG_SET_CUR; |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1738 | break; |
| 1739 | case UVC_GET_LEN: |
| 1740 | size = 2; |
| 1741 | break; |
| 1742 | case UVC_GET_INFO: |
| 1743 | size = 1; |
| 1744 | break; |
| 1745 | default: |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1746 | ret = -EINVAL; |
| 1747 | goto done; |
| 1748 | } |
| 1749 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1750 | if (size != xqry->size) { |
| 1751 | ret = -ENOBUFS; |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1752 | goto done; |
| 1753 | } |
| 1754 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1755 | if (reqflags && !(ctrl->info.flags & reqflags)) { |
| 1756 | ret = -EBADRQC; |
| 1757 | goto done; |
| 1758 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1759 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1760 | data = kmalloc(size, GFP_KERNEL); |
| 1761 | if (data == NULL) { |
| 1762 | ret = -ENOMEM; |
| 1763 | goto done; |
| 1764 | } |
| 1765 | |
| 1766 | if (xqry->query == UVC_SET_CUR && |
| 1767 | copy_from_user(data, xqry->data, size)) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1768 | ret = -EFAULT; |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1769 | goto done; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1770 | } |
| 1771 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1772 | ret = uvc_query_ctrl(chain->dev, xqry->query, xqry->unit, |
| 1773 | chain->dev->intfnum, xqry->selector, data, size); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1774 | if (ret < 0) |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1775 | goto done; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1776 | |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1777 | if (xqry->query != UVC_SET_CUR && |
| 1778 | copy_to_user(xqry->data, data, size)) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1779 | ret = -EFAULT; |
Laurent Pinchart | 27a61c1 | 2010-10-02 09:04:53 -0300 | [diff] [blame] | 1780 | done: |
Martin Rubli | fe78d18 | 2010-10-02 19:10:16 -0300 | [diff] [blame] | 1781 | kfree(data); |
Laurent Pinchart | 8e11359 | 2009-07-01 20:24:47 -0300 | [diff] [blame] | 1782 | mutex_unlock(&chain->ctrl_mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1783 | return ret; |
| 1784 | } |
| 1785 | |
| 1786 | /* -------------------------------------------------------------------------- |
| 1787 | * Suspend/resume |
| 1788 | */ |
| 1789 | |
| 1790 | /* |
| 1791 | * Restore control values after resume, skipping controls that haven't been |
| 1792 | * changed. |
| 1793 | * |
| 1794 | * TODO |
| 1795 | * - Don't restore modified controls that are back to their default value. |
| 1796 | * - Handle restore order (Auto-Exposure Mode should be restored before |
| 1797 | * Exposure Time). |
| 1798 | */ |
| 1799 | int uvc_ctrl_resume_device(struct uvc_device *dev) |
| 1800 | { |
| 1801 | struct uvc_control *ctrl; |
| 1802 | struct uvc_entity *entity; |
| 1803 | unsigned int i; |
| 1804 | int ret; |
| 1805 | |
| 1806 | /* Walk the entities list and restore controls when possible. */ |
| 1807 | list_for_each_entry(entity, &dev->entities, list) { |
| 1808 | |
| 1809 | for (i = 0; i < entity->ncontrols; ++i) { |
| 1810 | ctrl = &entity->controls[i]; |
| 1811 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1812 | if (!ctrl->initialized || !ctrl->modified || |
Laurent Pinchart | 9eb30d2 | 2010-11-21 17:08:16 -0300 | [diff] [blame] | 1813 | (ctrl->info.flags & UVC_CTRL_FLAG_RESTORE) == 0) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1814 | continue; |
| 1815 | |
Laurent Pinchart | 36bd883 | 2010-01-19 09:06:22 -0300 | [diff] [blame] | 1816 | printk(KERN_INFO "restoring control %pUl/%u/%u\n", |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1817 | ctrl->info.entity, ctrl->info.index, |
| 1818 | ctrl->info.selector); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1819 | ctrl->dirty = 1; |
| 1820 | } |
| 1821 | |
| 1822 | ret = uvc_ctrl_commit_entity(dev, entity, 0); |
| 1823 | if (ret < 0) |
| 1824 | return ret; |
| 1825 | } |
| 1826 | |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | /* -------------------------------------------------------------------------- |
| 1831 | * Control and mapping handling |
| 1832 | */ |
| 1833 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1834 | /* |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1835 | * Add control information to a given control. |
| 1836 | */ |
| 1837 | static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, |
| 1838 | const struct uvc_control_info *info) |
| 1839 | { |
| 1840 | int ret = 0; |
| 1841 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1842 | memcpy(&ctrl->info, info, sizeof(*info)); |
| 1843 | INIT_LIST_HEAD(&ctrl->info.mappings); |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1844 | |
| 1845 | /* Allocate an array to save control values (cur, def, max, etc.) */ |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1846 | ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1, |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1847 | GFP_KERNEL); |
| 1848 | if (ctrl->uvc_data == NULL) { |
| 1849 | ret = -ENOMEM; |
| 1850 | goto done; |
| 1851 | } |
| 1852 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1853 | ctrl->initialized = 1; |
| 1854 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1855 | uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s " |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1856 | "entity %u\n", ctrl->info.entity, ctrl->info.selector, |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1857 | dev->udev->devpath, ctrl->entity->id); |
| 1858 | |
| 1859 | done: |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1860 | if (ret < 0) |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1861 | kfree(ctrl->uvc_data); |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1862 | return ret; |
| 1863 | } |
| 1864 | |
| 1865 | /* |
| 1866 | * Add a control mapping to a given control. |
| 1867 | */ |
| 1868 | static int __uvc_ctrl_add_mapping(struct uvc_device *dev, |
| 1869 | struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) |
| 1870 | { |
| 1871 | struct uvc_control_mapping *map; |
| 1872 | unsigned int size; |
| 1873 | |
| 1874 | /* Most mappings come from static kernel data and need to be duplicated. |
| 1875 | * Mappings that come from userspace will be unnecessarily duplicated, |
| 1876 | * this could be optimized. |
| 1877 | */ |
| 1878 | map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL); |
| 1879 | if (map == NULL) |
| 1880 | return -ENOMEM; |
| 1881 | |
Hans de Goede | b401200 | 2012-04-08 12:59:51 -0300 | [diff] [blame] | 1882 | INIT_LIST_HEAD(&map->ev_subs); |
| 1883 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1884 | size = sizeof(*mapping->menu_info) * mapping->menu_count; |
| 1885 | map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); |
| 1886 | if (map->menu_info == NULL) { |
| 1887 | kfree(map); |
| 1888 | return -ENOMEM; |
| 1889 | } |
| 1890 | |
| 1891 | if (map->get == NULL) |
| 1892 | map->get = uvc_get_le_value; |
| 1893 | if (map->set == NULL) |
| 1894 | map->set = uvc_set_le_value; |
| 1895 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1896 | list_add_tail(&map->list, &ctrl->info.mappings); |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1897 | uvc_trace(UVC_TRACE_CONTROL, |
| 1898 | "Adding mapping '%s' to control %pUl/%u.\n", |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1899 | map->name, ctrl->info.entity, ctrl->info.selector); |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1900 | |
| 1901 | return 0; |
| 1902 | } |
| 1903 | |
| 1904 | int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, |
| 1905 | const struct uvc_control_mapping *mapping) |
| 1906 | { |
| 1907 | struct uvc_device *dev = chain->dev; |
| 1908 | struct uvc_control_mapping *map; |
| 1909 | struct uvc_entity *entity; |
| 1910 | struct uvc_control *ctrl; |
| 1911 | int found = 0; |
Martin Rubli | 8fb91b3 | 2010-09-08 04:15:23 -0300 | [diff] [blame] | 1912 | int ret; |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1913 | |
| 1914 | if (mapping->id & ~V4L2_CTRL_ID_MASK) { |
| 1915 | uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', control " |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1916 | "id 0x%08x is invalid.\n", mapping->name, |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1917 | mapping->id); |
| 1918 | return -EINVAL; |
| 1919 | } |
| 1920 | |
Stephan Lachowsky | c0c5e71 | 2011-05-31 19:24:21 -0300 | [diff] [blame] | 1921 | /* Search for the matching (GUID/CS) control on the current chain */ |
| 1922 | list_for_each_entry(entity, &chain->entities, chain) { |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1923 | unsigned int i; |
| 1924 | |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1925 | if (UVC_ENTITY_TYPE(entity) != UVC_VC_EXTENSION_UNIT || |
| 1926 | !uvc_entity_match_guid(entity, mapping->entity)) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1927 | continue; |
| 1928 | |
| 1929 | for (i = 0; i < entity->ncontrols; ++i) { |
| 1930 | ctrl = &entity->controls[i]; |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1931 | if (ctrl->index == mapping->selector - 1) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1932 | found = 1; |
| 1933 | break; |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | if (found) |
| 1938 | break; |
| 1939 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1940 | if (!found) |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1941 | return -ENOENT; |
Laurent Pinchart | b30ece5 | 2010-06-18 11:31:24 -0300 | [diff] [blame] | 1942 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1943 | if (mutex_lock_interruptible(&chain->ctrl_mutex)) |
| 1944 | return -ERESTARTSYS; |
Laurent Pinchart | b30ece5 | 2010-06-18 11:31:24 -0300 | [diff] [blame] | 1945 | |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 1946 | /* Perform delayed initialization of XU controls */ |
| 1947 | ret = uvc_ctrl_init_xu_ctrl(dev, ctrl); |
| 1948 | if (ret < 0) { |
| 1949 | ret = -ENOENT; |
| 1950 | goto done; |
| 1951 | } |
| 1952 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 1953 | list_for_each_entry(map, &ctrl->info.mappings, list) { |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1954 | if (mapping->id == map->id) { |
| 1955 | uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', " |
| 1956 | "control id 0x%08x already exists.\n", |
| 1957 | mapping->name, mapping->id); |
| 1958 | ret = -EEXIST; |
Laurent Pinchart | b30ece5 | 2010-06-18 11:31:24 -0300 | [diff] [blame] | 1959 | goto done; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
Martin Rubli | 8fb91b3 | 2010-09-08 04:15:23 -0300 | [diff] [blame] | 1963 | /* Prevent excess memory consumption */ |
| 1964 | if (atomic_inc_return(&dev->nmappings) > UVC_MAX_CONTROL_MAPPINGS) { |
| 1965 | atomic_dec(&dev->nmappings); |
| 1966 | uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', maximum " |
| 1967 | "mappings count (%u) exceeded.\n", mapping->name, |
| 1968 | UVC_MAX_CONTROL_MAPPINGS); |
| 1969 | ret = -ENOMEM; |
| 1970 | goto done; |
| 1971 | } |
| 1972 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1973 | ret = __uvc_ctrl_add_mapping(dev, ctrl, mapping); |
Martin Rubli | 8fb91b3 | 2010-09-08 04:15:23 -0300 | [diff] [blame] | 1974 | if (ret < 0) |
| 1975 | atomic_dec(&dev->nmappings); |
| 1976 | |
Laurent Pinchart | b30ece5 | 2010-06-18 11:31:24 -0300 | [diff] [blame] | 1977 | done: |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1978 | mutex_unlock(&chain->ctrl_mutex); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 1979 | return ret; |
| 1980 | } |
| 1981 | |
| 1982 | /* |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 1983 | * Prune an entity of its bogus controls using a blacklist. Bogus controls |
| 1984 | * are currently the ones that crash the camera or unconditionally return an |
| 1985 | * error when queried. |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 1986 | */ |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 1987 | static void uvc_ctrl_prune_entity(struct uvc_device *dev, |
| 1988 | struct uvc_entity *entity) |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 1989 | { |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 1990 | struct uvc_ctrl_blacklist { |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 1991 | struct usb_device_id id; |
| 1992 | u8 index; |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 1993 | }; |
| 1994 | |
| 1995 | static const struct uvc_ctrl_blacklist processing_blacklist[] = { |
Laurent Pinchart | 9405e3c | 2010-02-03 06:49:35 -0300 | [diff] [blame] | 1996 | { { USB_DEVICE(0x13d3, 0x509b) }, 9 }, /* Gain */ |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 1997 | { { USB_DEVICE(0x1c4f, 0x3000) }, 6 }, /* WB Temperature */ |
| 1998 | { { USB_DEVICE(0x5986, 0x0241) }, 2 }, /* Hue */ |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 1999 | }; |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2000 | static const struct uvc_ctrl_blacklist camera_blacklist[] = { |
| 2001 | { { USB_DEVICE(0x06f8, 0x3005) }, 9 }, /* Zoom, Absolute */ |
| 2002 | }; |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2003 | |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2004 | const struct uvc_ctrl_blacklist *blacklist; |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2005 | unsigned int size; |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2006 | unsigned int count; |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2007 | unsigned int i; |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2008 | u8 *controls; |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2009 | |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2010 | switch (UVC_ENTITY_TYPE(entity)) { |
| 2011 | case UVC_VC_PROCESSING_UNIT: |
| 2012 | blacklist = processing_blacklist; |
| 2013 | count = ARRAY_SIZE(processing_blacklist); |
| 2014 | controls = entity->processing.bmControls; |
| 2015 | size = entity->processing.bControlSize; |
| 2016 | break; |
| 2017 | |
| 2018 | case UVC_ITT_CAMERA: |
| 2019 | blacklist = camera_blacklist; |
| 2020 | count = ARRAY_SIZE(camera_blacklist); |
| 2021 | controls = entity->camera.bmControls; |
| 2022 | size = entity->camera.bControlSize; |
| 2023 | break; |
| 2024 | |
| 2025 | default: |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2026 | return; |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2027 | } |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2028 | |
Laurent Pinchart | fa34168 | 2010-07-23 10:06:08 -0300 | [diff] [blame] | 2029 | for (i = 0; i < count; ++i) { |
Laurent Pinchart | 385097e | 2009-12-09 22:31:21 -0300 | [diff] [blame] | 2030 | if (!usb_match_one_id(dev->intf, &blacklist[i].id)) |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2031 | continue; |
| 2032 | |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 2033 | if (blacklist[i].index >= 8 * size || |
| 2034 | !uvc_test_bit(controls, blacklist[i].index)) |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2035 | continue; |
| 2036 | |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 2037 | uvc_trace(UVC_TRACE_CONTROL, "%u/%u control is black listed, " |
| 2038 | "removing it.\n", entity->id, blacklist[i].index); |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2039 | |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 2040 | uvc_clear_bit(controls, blacklist[i].index); |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | /* |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2045 | * Add control information and hardcoded stock control mappings to the given |
| 2046 | * device. |
| 2047 | */ |
| 2048 | static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) |
| 2049 | { |
| 2050 | const struct uvc_control_info *info = uvc_ctrls; |
| 2051 | const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); |
| 2052 | const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; |
| 2053 | const struct uvc_control_mapping *mend = |
| 2054 | mapping + ARRAY_SIZE(uvc_ctrl_mappings); |
| 2055 | |
Laurent Pinchart | 52c58ad | 2010-09-29 16:03:03 -0300 | [diff] [blame] | 2056 | /* XU controls initialization requires querying the device for control |
| 2057 | * information. As some buggy UVC devices will crash when queried |
| 2058 | * repeatedly in a tight loop, delay XU controls initialization until |
| 2059 | * first use. |
| 2060 | */ |
| 2061 | if (UVC_ENTITY_TYPE(ctrl->entity) == UVC_VC_EXTENSION_UNIT) |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2062 | return; |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2063 | |
| 2064 | for (; info < iend; ++info) { |
| 2065 | if (uvc_entity_match_guid(ctrl->entity, info->entity) && |
| 2066 | ctrl->index == info->index) { |
| 2067 | uvc_ctrl_add_info(dev, ctrl, info); |
| 2068 | break; |
| 2069 | } |
| 2070 | } |
| 2071 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 2072 | if (!ctrl->initialized) |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2073 | return; |
| 2074 | |
| 2075 | for (; mapping < mend; ++mapping) { |
| 2076 | if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 2077 | ctrl->info.selector == mapping->selector) |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2078 | __uvc_ctrl_add_mapping(dev, ctrl, mapping); |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | /* |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2083 | * Initialize device controls. |
| 2084 | */ |
| 2085 | int uvc_ctrl_init_device(struct uvc_device *dev) |
| 2086 | { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2087 | struct uvc_entity *entity; |
| 2088 | unsigned int i; |
| 2089 | |
| 2090 | /* Walk the entities list and instantiate controls */ |
| 2091 | list_for_each_entry(entity, &dev->entities, list) { |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2092 | struct uvc_control *ctrl; |
Akinobu Mita | 9a60139 | 2012-07-30 14:41:02 -0700 | [diff] [blame] | 2093 | unsigned int bControlSize = 0, ncontrols; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2094 | __u8 *bmControls = NULL; |
| 2095 | |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 2096 | if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2097 | bmControls = entity->extension.bmControls; |
| 2098 | bControlSize = entity->extension.bControlSize; |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 2099 | } else if (UVC_ENTITY_TYPE(entity) == UVC_VC_PROCESSING_UNIT) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2100 | bmControls = entity->processing.bmControls; |
| 2101 | bControlSize = entity->processing.bControlSize; |
Laurent Pinchart | b482d92 | 2009-06-26 11:39:42 -0300 | [diff] [blame] | 2102 | } else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) { |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2103 | bmControls = entity->camera.bmControls; |
| 2104 | bControlSize = entity->camera.bControlSize; |
| 2105 | } |
| 2106 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2107 | /* Remove bogus/blacklisted controls */ |
Laurent Pinchart | d732c44 | 2009-05-31 17:05:55 -0300 | [diff] [blame] | 2108 | uvc_ctrl_prune_entity(dev, entity); |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2109 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2110 | /* Count supported controls and allocate the controls array */ |
Akinobu Mita | 9a60139 | 2012-07-30 14:41:02 -0700 | [diff] [blame] | 2111 | ncontrols = memweight(bmControls, bControlSize); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2112 | if (ncontrols == 0) |
| 2113 | continue; |
| 2114 | |
Thomas Meyer | d0d9748 | 2011-11-29 17:08:00 -0300 | [diff] [blame] | 2115 | entity->controls = kcalloc(ncontrols, sizeof(*ctrl), |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2116 | GFP_KERNEL); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2117 | if (entity->controls == NULL) |
| 2118 | return -ENOMEM; |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2119 | entity->ncontrols = ncontrols; |
| 2120 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2121 | /* Initialize all supported controls */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2122 | ctrl = entity->controls; |
| 2123 | for (i = 0; i < bControlSize * 8; ++i) { |
Laurent Pinchart | 2bdd29c | 2008-12-06 17:43:40 -0300 | [diff] [blame] | 2124 | if (uvc_test_bit(bmControls, i) == 0) |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2125 | continue; |
| 2126 | |
| 2127 | ctrl->entity = entity; |
| 2128 | ctrl->index = i; |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2129 | |
| 2130 | uvc_ctrl_init_ctrl(dev, ctrl); |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2131 | ctrl++; |
| 2132 | } |
| 2133 | } |
| 2134 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2135 | return 0; |
| 2136 | } |
| 2137 | |
| 2138 | /* |
| 2139 | * Cleanup device controls. |
| 2140 | */ |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2141 | static void uvc_ctrl_cleanup_mappings(struct uvc_device *dev, |
| 2142 | struct uvc_control *ctrl) |
| 2143 | { |
| 2144 | struct uvc_control_mapping *mapping, *nm; |
| 2145 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 2146 | list_for_each_entry_safe(mapping, nm, &ctrl->info.mappings, list) { |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2147 | list_del(&mapping->list); |
| 2148 | kfree(mapping->menu_info); |
| 2149 | kfree(mapping); |
| 2150 | } |
| 2151 | } |
| 2152 | |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2153 | void uvc_ctrl_cleanup_device(struct uvc_device *dev) |
| 2154 | { |
| 2155 | struct uvc_entity *entity; |
| 2156 | unsigned int i; |
| 2157 | |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2158 | /* Free controls and control mappings for all entities. */ |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2159 | list_for_each_entry(entity, &dev->entities, list) { |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2160 | for (i = 0; i < entity->ncontrols; ++i) { |
| 2161 | struct uvc_control *ctrl = &entity->controls[i]; |
| 2162 | |
Laurent Pinchart | 071c8bb | 2010-09-29 16:00:08 -0300 | [diff] [blame] | 2163 | if (!ctrl->initialized) |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2164 | continue; |
| 2165 | |
| 2166 | uvc_ctrl_cleanup_mappings(dev, ctrl); |
| 2167 | kfree(ctrl->uvc_data); |
Laurent Pinchart | ba2fa99 | 2010-09-20 05:53:21 -0300 | [diff] [blame] | 2168 | } |
Laurent Pinchart | c0efd23 | 2008-06-30 15:04:50 -0300 | [diff] [blame] | 2169 | |
| 2170 | kfree(entity->controls); |
| 2171 | } |
| 2172 | } |