Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1 | /* |
| 2 | * adv7180.c Analog Devices ADV7180 video decoder driver |
| 3 | * Copyright (c) 2009 Intel Corporation |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 4 | * Copyright (C) 2013 Cogent Embedded, Inc. |
| 5 | * Copyright (C) 2013 Renesas Solutions Corp. |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -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 version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 28 | #include <media/v4l2-ioctl.h> |
| 29 | #include <linux/videodev2.h> |
| 30 | #include <media/v4l2-device.h> |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 31 | #include <media/v4l2-ctrls.h> |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 33 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 34 | #define ADV7180_INPUT_CONTROL_REG 0x00 |
| 35 | #define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM 0x00 |
| 36 | #define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM_PED 0x10 |
| 37 | #define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_J_SECAM 0x20 |
| 38 | #define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_M_SECAM 0x30 |
| 39 | #define ADV7180_INPUT_CONTROL_NTSC_J 0x40 |
| 40 | #define ADV7180_INPUT_CONTROL_NTSC_M 0x50 |
| 41 | #define ADV7180_INPUT_CONTROL_PAL60 0x60 |
| 42 | #define ADV7180_INPUT_CONTROL_NTSC_443 0x70 |
| 43 | #define ADV7180_INPUT_CONTROL_PAL_BG 0x80 |
| 44 | #define ADV7180_INPUT_CONTROL_PAL_N 0x90 |
| 45 | #define ADV7180_INPUT_CONTROL_PAL_M 0xa0 |
| 46 | #define ADV7180_INPUT_CONTROL_PAL_M_PED 0xb0 |
| 47 | #define ADV7180_INPUT_CONTROL_PAL_COMB_N 0xc0 |
| 48 | #define ADV7180_INPUT_CONTROL_PAL_COMB_N_PED 0xd0 |
| 49 | #define ADV7180_INPUT_CONTROL_PAL_SECAM 0xe0 |
| 50 | #define ADV7180_INPUT_CONTROL_PAL_SECAM_PED 0xf0 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 51 | #define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 52 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 53 | #define ADV7180_EXTENDED_OUTPUT_CONTROL_REG 0x04 |
| 54 | #define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 55 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 56 | #define ADV7180_AUTODETECT_ENABLE_REG 0x07 |
| 57 | #define ADV7180_AUTODETECT_DEFAULT 0x7f |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 58 | /* Contrast */ |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 59 | #define ADV7180_CON_REG 0x08 /*Unsigned */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 60 | #define ADV7180_CON_MIN 0 |
| 61 | #define ADV7180_CON_DEF 128 |
| 62 | #define ADV7180_CON_MAX 255 |
| 63 | /* Brightness*/ |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 64 | #define ADV7180_BRI_REG 0x0a /*Signed */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 65 | #define ADV7180_BRI_MIN -128 |
| 66 | #define ADV7180_BRI_DEF 0 |
| 67 | #define ADV7180_BRI_MAX 127 |
| 68 | /* Hue */ |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 69 | #define ADV7180_HUE_REG 0x0b /*Signed, inverted */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 70 | #define ADV7180_HUE_MIN -127 |
| 71 | #define ADV7180_HUE_DEF 0 |
| 72 | #define ADV7180_HUE_MAX 128 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 73 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 74 | #define ADV7180_ADI_CTRL_REG 0x0e |
| 75 | #define ADV7180_ADI_CTRL_IRQ_SPACE 0x20 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 76 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 77 | #define ADV7180_PWR_MAN_REG 0x0f |
| 78 | #define ADV7180_PWR_MAN_ON 0x04 |
| 79 | #define ADV7180_PWR_MAN_OFF 0x24 |
| 80 | #define ADV7180_PWR_MAN_RES 0x80 |
| 81 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 82 | #define ADV7180_STATUS1_REG 0x10 |
| 83 | #define ADV7180_STATUS1_IN_LOCK 0x01 |
| 84 | #define ADV7180_STATUS1_AUTOD_MASK 0x70 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 85 | #define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00 |
| 86 | #define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10 |
| 87 | #define ADV7180_STATUS1_AUTOD_PAL_M 0x20 |
| 88 | #define ADV7180_STATUS1_AUTOD_PAL_60 0x30 |
| 89 | #define ADV7180_STATUS1_AUTOD_PAL_B_G 0x40 |
| 90 | #define ADV7180_STATUS1_AUTOD_SECAM 0x50 |
| 91 | #define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60 |
| 92 | #define ADV7180_STATUS1_AUTOD_SECAM_525 0x70 |
| 93 | |
| 94 | #define ADV7180_IDENT_REG 0x11 |
| 95 | #define ADV7180_ID_7180 0x18 |
| 96 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 97 | #define ADV7180_ICONF1_ADI 0x40 |
| 98 | #define ADV7180_ICONF1_ACTIVE_LOW 0x01 |
| 99 | #define ADV7180_ICONF1_PSYNC_ONLY 0x10 |
| 100 | #define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0 |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 101 | /* Saturation */ |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 102 | #define ADV7180_SD_SAT_CB_REG 0xe3 /*Unsigned */ |
| 103 | #define ADV7180_SD_SAT_CR_REG 0xe4 /*Unsigned */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 104 | #define ADV7180_SAT_MIN 0 |
| 105 | #define ADV7180_SAT_DEF 128 |
| 106 | #define ADV7180_SAT_MAX 255 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 107 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 108 | #define ADV7180_IRQ1_LOCK 0x01 |
| 109 | #define ADV7180_IRQ1_UNLOCK 0x02 |
| 110 | #define ADV7180_ISR1_ADI 0x42 |
| 111 | #define ADV7180_ICR1_ADI 0x43 |
| 112 | #define ADV7180_IMR1_ADI 0x44 |
| 113 | #define ADV7180_IMR2_ADI 0x48 |
| 114 | #define ADV7180_IRQ3_AD_CHANGE 0x08 |
| 115 | #define ADV7180_ISR3_ADI 0x4A |
| 116 | #define ADV7180_ICR3_ADI 0x4B |
| 117 | #define ADV7180_IMR3_ADI 0x4C |
| 118 | #define ADV7180_IMR4_ADI 0x50 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 119 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 120 | #define ADV7180_NTSC_V_BIT_END_REG 0xE6 |
| 121 | #define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F |
| 122 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 123 | struct adv7180_state { |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 124 | struct v4l2_ctrl_handler ctrl_hdl; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 125 | struct v4l2_subdev sd; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 126 | struct mutex mutex; /* mutual excl. when accessing chip */ |
| 127 | int irq; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 128 | v4l2_std_id curr_norm; |
| 129 | bool autodetect; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 130 | u8 input; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 131 | }; |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 132 | #define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \ |
| 133 | struct adv7180_state, \ |
| 134 | ctrl_hdl)->sd) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 135 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 136 | static v4l2_std_id adv7180_std_to_v4l2(u8 status1) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 137 | { |
Vladimir Barinov | b294a19 | 2013-04-11 18:06:46 -0300 | [diff] [blame] | 138 | /* in case V4L2_IN_ST_NO_SIGNAL */ |
| 139 | if (!(status1 & ADV7180_STATUS1_IN_LOCK)) |
| 140 | return V4L2_STD_UNKNOWN; |
| 141 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 142 | switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { |
| 143 | case ADV7180_STATUS1_AUTOD_NTSM_M_J: |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 144 | return V4L2_STD_NTSC; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 145 | case ADV7180_STATUS1_AUTOD_NTSC_4_43: |
| 146 | return V4L2_STD_NTSC_443; |
| 147 | case ADV7180_STATUS1_AUTOD_PAL_M: |
| 148 | return V4L2_STD_PAL_M; |
| 149 | case ADV7180_STATUS1_AUTOD_PAL_60: |
| 150 | return V4L2_STD_PAL_60; |
| 151 | case ADV7180_STATUS1_AUTOD_PAL_B_G: |
| 152 | return V4L2_STD_PAL; |
| 153 | case ADV7180_STATUS1_AUTOD_SECAM: |
| 154 | return V4L2_STD_SECAM; |
| 155 | case ADV7180_STATUS1_AUTOD_PAL_COMB: |
| 156 | return V4L2_STD_PAL_Nc | V4L2_STD_PAL_N; |
| 157 | case ADV7180_STATUS1_AUTOD_SECAM_525: |
| 158 | return V4L2_STD_SECAM; |
| 159 | default: |
| 160 | return V4L2_STD_UNKNOWN; |
| 161 | } |
| 162 | } |
| 163 | |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 164 | static int v4l2_std_to_adv7180(v4l2_std_id std) |
| 165 | { |
| 166 | if (std == V4L2_STD_PAL_60) |
| 167 | return ADV7180_INPUT_CONTROL_PAL60; |
| 168 | if (std == V4L2_STD_NTSC_443) |
| 169 | return ADV7180_INPUT_CONTROL_NTSC_443; |
| 170 | if (std == V4L2_STD_PAL_N) |
| 171 | return ADV7180_INPUT_CONTROL_PAL_N; |
| 172 | if (std == V4L2_STD_PAL_M) |
| 173 | return ADV7180_INPUT_CONTROL_PAL_M; |
| 174 | if (std == V4L2_STD_PAL_Nc) |
| 175 | return ADV7180_INPUT_CONTROL_PAL_COMB_N; |
| 176 | |
| 177 | if (std & V4L2_STD_PAL) |
| 178 | return ADV7180_INPUT_CONTROL_PAL_BG; |
| 179 | if (std & V4L2_STD_NTSC) |
| 180 | return ADV7180_INPUT_CONTROL_NTSC_M; |
| 181 | if (std & V4L2_STD_SECAM) |
| 182 | return ADV7180_INPUT_CONTROL_PAL_SECAM; |
| 183 | |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 187 | static u32 adv7180_status_to_v4l2(u8 status1) |
| 188 | { |
| 189 | if (!(status1 & ADV7180_STATUS1_IN_LOCK)) |
| 190 | return V4L2_IN_ST_NO_SIGNAL; |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int __adv7180_status(struct i2c_client *client, u32 *status, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 196 | v4l2_std_id *std) |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 197 | { |
| 198 | int status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG); |
| 199 | |
| 200 | if (status1 < 0) |
| 201 | return status1; |
| 202 | |
| 203 | if (status) |
| 204 | *status = adv7180_status_to_v4l2(status1); |
| 205 | if (std) |
| 206 | *std = adv7180_std_to_v4l2(status1); |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 211 | static inline struct adv7180_state *to_state(struct v4l2_subdev *sd) |
| 212 | { |
| 213 | return container_of(sd, struct adv7180_state, sd); |
| 214 | } |
| 215 | |
| 216 | static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) |
| 217 | { |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 218 | struct adv7180_state *state = to_state(sd); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 219 | int err = mutex_lock_interruptible(&state->mutex); |
| 220 | if (err) |
| 221 | return err; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 222 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 223 | /* when we are interrupt driven we know the state */ |
| 224 | if (!state->autodetect || state->irq > 0) |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 225 | *std = state->curr_norm; |
| 226 | else |
| 227 | err = __adv7180_status(v4l2_get_subdevdata(sd), NULL, std); |
| 228 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 229 | mutex_unlock(&state->mutex); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 230 | return err; |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 231 | } |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 232 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 233 | static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input, |
| 234 | u32 output, u32 config) |
| 235 | { |
| 236 | struct adv7180_state *state = to_state(sd); |
| 237 | int ret = mutex_lock_interruptible(&state->mutex); |
| 238 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 239 | |
| 240 | if (ret) |
| 241 | return ret; |
| 242 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 243 | /* We cannot discriminate between LQFP and 40-pin LFCSP, so accept |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 244 | * all inputs and let the card driver take care of validation |
| 245 | */ |
| 246 | if ((input & ADV7180_INPUT_CONTROL_INSEL_MASK) != input) |
| 247 | goto out; |
| 248 | |
| 249 | ret = i2c_smbus_read_byte_data(client, ADV7180_INPUT_CONTROL_REG); |
| 250 | |
| 251 | if (ret < 0) |
| 252 | goto out; |
| 253 | |
| 254 | ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK; |
| 255 | ret = i2c_smbus_write_byte_data(client, |
| 256 | ADV7180_INPUT_CONTROL_REG, ret | input); |
| 257 | state->input = input; |
| 258 | out: |
| 259 | mutex_unlock(&state->mutex); |
| 260 | return ret; |
| 261 | } |
| 262 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 263 | static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status) |
| 264 | { |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 265 | struct adv7180_state *state = to_state(sd); |
| 266 | int ret = mutex_lock_interruptible(&state->mutex); |
| 267 | if (ret) |
| 268 | return ret; |
| 269 | |
| 270 | ret = __adv7180_status(v4l2_get_subdevdata(sd), status, NULL); |
| 271 | mutex_unlock(&state->mutex); |
| 272 | return ret; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 273 | } |
| 274 | |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 275 | static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) |
| 276 | { |
| 277 | struct adv7180_state *state = to_state(sd); |
| 278 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 279 | int ret = mutex_lock_interruptible(&state->mutex); |
| 280 | if (ret) |
| 281 | return ret; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 282 | |
| 283 | /* all standards -> autodetect */ |
| 284 | if (std == V4L2_STD_ALL) { |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 285 | ret = |
| 286 | i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, |
| 287 | ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM |
| 288 | | state->input); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 289 | if (ret < 0) |
| 290 | goto out; |
| 291 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 292 | __adv7180_status(client, NULL, &state->curr_norm); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 293 | state->autodetect = true; |
| 294 | } else { |
| 295 | ret = v4l2_std_to_adv7180(std); |
| 296 | if (ret < 0) |
| 297 | goto out; |
| 298 | |
| 299 | ret = i2c_smbus_write_byte_data(client, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 300 | ADV7180_INPUT_CONTROL_REG, |
| 301 | ret | state->input); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 302 | if (ret < 0) |
| 303 | goto out; |
| 304 | |
| 305 | state->curr_norm = std; |
| 306 | state->autodetect = false; |
| 307 | } |
| 308 | ret = 0; |
| 309 | out: |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 310 | mutex_unlock(&state->mutex); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 311 | return ret; |
| 312 | } |
| 313 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 314 | static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 315 | { |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 316 | struct v4l2_subdev *sd = to_adv7180_sd(ctrl); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 317 | struct adv7180_state *state = to_state(sd); |
| 318 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 319 | int ret = mutex_lock_interruptible(&state->mutex); |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 320 | int val; |
| 321 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 322 | if (ret) |
| 323 | return ret; |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 324 | val = ctrl->val; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 325 | switch (ctrl->id) { |
| 326 | case V4L2_CID_BRIGHTNESS: |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 327 | ret = i2c_smbus_write_byte_data(client, ADV7180_BRI_REG, val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 328 | break; |
| 329 | case V4L2_CID_HUE: |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 330 | /*Hue is inverted according to HSL chart */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 331 | ret = i2c_smbus_write_byte_data(client, ADV7180_HUE_REG, -val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 332 | break; |
| 333 | case V4L2_CID_CONTRAST: |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 334 | ret = i2c_smbus_write_byte_data(client, ADV7180_CON_REG, val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 335 | break; |
| 336 | case V4L2_CID_SATURATION: |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 337 | /* |
| 338 | *This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE |
| 339 | *Let's not confuse the user, everybody understands saturation |
| 340 | */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 341 | ret = i2c_smbus_write_byte_data(client, ADV7180_SD_SAT_CB_REG, |
| 342 | val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 343 | if (ret < 0) |
| 344 | break; |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 345 | ret = i2c_smbus_write_byte_data(client, ADV7180_SD_SAT_CR_REG, |
| 346 | val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 347 | break; |
| 348 | default: |
| 349 | ret = -EINVAL; |
| 350 | } |
| 351 | |
| 352 | mutex_unlock(&state->mutex); |
| 353 | return ret; |
| 354 | } |
| 355 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 356 | static const struct v4l2_ctrl_ops adv7180_ctrl_ops = { |
| 357 | .s_ctrl = adv7180_s_ctrl, |
| 358 | }; |
| 359 | |
| 360 | static int adv7180_init_controls(struct adv7180_state *state) |
| 361 | { |
| 362 | v4l2_ctrl_handler_init(&state->ctrl_hdl, 4); |
| 363 | |
| 364 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 365 | V4L2_CID_BRIGHTNESS, ADV7180_BRI_MIN, |
| 366 | ADV7180_BRI_MAX, 1, ADV7180_BRI_DEF); |
| 367 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 368 | V4L2_CID_CONTRAST, ADV7180_CON_MIN, |
| 369 | ADV7180_CON_MAX, 1, ADV7180_CON_DEF); |
| 370 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 371 | V4L2_CID_SATURATION, ADV7180_SAT_MIN, |
| 372 | ADV7180_SAT_MAX, 1, ADV7180_SAT_DEF); |
| 373 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 374 | V4L2_CID_HUE, ADV7180_HUE_MIN, |
| 375 | ADV7180_HUE_MAX, 1, ADV7180_HUE_DEF); |
| 376 | state->sd.ctrl_handler = &state->ctrl_hdl; |
| 377 | if (state->ctrl_hdl.error) { |
| 378 | int err = state->ctrl_hdl.error; |
| 379 | |
| 380 | v4l2_ctrl_handler_free(&state->ctrl_hdl); |
| 381 | return err; |
| 382 | } |
| 383 | v4l2_ctrl_handler_setup(&state->ctrl_hdl); |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | static void adv7180_exit_controls(struct adv7180_state *state) |
| 388 | { |
| 389 | v4l2_ctrl_handler_free(&state->ctrl_hdl); |
| 390 | } |
| 391 | |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 392 | static int adv7180_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index, |
| 393 | enum v4l2_mbus_pixelcode *code) |
| 394 | { |
| 395 | if (index > 0) |
| 396 | return -EINVAL; |
| 397 | |
| 398 | *code = V4L2_MBUS_FMT_YUYV8_2X8; |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static int adv7180_mbus_fmt(struct v4l2_subdev *sd, |
| 404 | struct v4l2_mbus_framefmt *fmt) |
| 405 | { |
| 406 | struct adv7180_state *state = to_state(sd); |
| 407 | |
| 408 | fmt->code = V4L2_MBUS_FMT_YUYV8_2X8; |
| 409 | fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 410 | fmt->field = V4L2_FIELD_INTERLACED; |
| 411 | fmt->width = 720; |
| 412 | fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576; |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static int adv7180_g_mbus_config(struct v4l2_subdev *sd, |
| 418 | struct v4l2_mbus_config *cfg) |
| 419 | { |
| 420 | /* |
| 421 | * The ADV7180 sensor supports BT.601/656 output modes. |
| 422 | * The BT.656 is default and not yet configurable by s/w. |
| 423 | */ |
| 424 | cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | |
| 425 | V4L2_MBUS_DATA_ACTIVE_HIGH; |
| 426 | cfg->type = V4L2_MBUS_BT656; |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 431 | static const struct v4l2_subdev_video_ops adv7180_video_ops = { |
| 432 | .querystd = adv7180_querystd, |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 433 | .g_input_status = adv7180_g_input_status, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 434 | .s_routing = adv7180_s_routing, |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 435 | .enum_mbus_fmt = adv7180_enum_mbus_fmt, |
| 436 | .try_mbus_fmt = adv7180_mbus_fmt, |
| 437 | .g_mbus_fmt = adv7180_mbus_fmt, |
| 438 | .s_mbus_fmt = adv7180_mbus_fmt, |
| 439 | .g_mbus_config = adv7180_g_mbus_config, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | static const struct v4l2_subdev_core_ops adv7180_core_ops = { |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 443 | .s_std = adv7180_s_std, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | static const struct v4l2_subdev_ops adv7180_ops = { |
| 447 | .core = &adv7180_core_ops, |
| 448 | .video = &adv7180_video_ops, |
| 449 | }; |
| 450 | |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 451 | static irqreturn_t adv7180_irq(int irq, void *devid) |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 452 | { |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 453 | struct adv7180_state *state = devid; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 454 | struct i2c_client *client = v4l2_get_subdevdata(&state->sd); |
| 455 | u8 isr3; |
| 456 | |
| 457 | mutex_lock(&state->mutex); |
| 458 | i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 459 | ADV7180_ADI_CTRL_IRQ_SPACE); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 460 | isr3 = i2c_smbus_read_byte_data(client, ADV7180_ISR3_ADI); |
| 461 | /* clear */ |
| 462 | i2c_smbus_write_byte_data(client, ADV7180_ICR3_ADI, isr3); |
| 463 | i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 0); |
| 464 | |
| 465 | if (isr3 & ADV7180_IRQ3_AD_CHANGE && state->autodetect) |
| 466 | __adv7180_status(client, NULL, &state->curr_norm); |
| 467 | mutex_unlock(&state->mutex); |
| 468 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 469 | return IRQ_HANDLED; |
| 470 | } |
| 471 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 472 | static int init_device(struct i2c_client *client, struct adv7180_state *state) |
| 473 | { |
| 474 | int ret; |
| 475 | |
| 476 | /* Initialize adv7180 */ |
| 477 | /* Enable autodetection */ |
| 478 | if (state->autodetect) { |
| 479 | ret = |
| 480 | i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, |
| 481 | ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM |
| 482 | | state->input); |
| 483 | if (ret < 0) |
| 484 | return ret; |
| 485 | |
| 486 | ret = |
| 487 | i2c_smbus_write_byte_data(client, |
| 488 | ADV7180_AUTODETECT_ENABLE_REG, |
| 489 | ADV7180_AUTODETECT_DEFAULT); |
| 490 | if (ret < 0) |
| 491 | return ret; |
| 492 | } else { |
| 493 | ret = v4l2_std_to_adv7180(state->curr_norm); |
| 494 | if (ret < 0) |
| 495 | return ret; |
| 496 | |
| 497 | ret = |
| 498 | i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, |
| 499 | ret | state->input); |
| 500 | if (ret < 0) |
| 501 | return ret; |
| 502 | |
| 503 | } |
| 504 | /* ITU-R BT.656-4 compatible */ |
| 505 | ret = i2c_smbus_write_byte_data(client, |
| 506 | ADV7180_EXTENDED_OUTPUT_CONTROL_REG, |
| 507 | ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS); |
| 508 | if (ret < 0) |
| 509 | return ret; |
| 510 | |
| 511 | /* Manually set V bit end position in NTSC mode */ |
| 512 | ret = i2c_smbus_write_byte_data(client, |
| 513 | ADV7180_NTSC_V_BIT_END_REG, |
| 514 | ADV7180_NTSC_V_BIT_END_MANUAL_NVEND); |
| 515 | if (ret < 0) |
| 516 | return ret; |
| 517 | |
| 518 | /* read current norm */ |
| 519 | __adv7180_status(client, NULL, &state->curr_norm); |
| 520 | |
| 521 | /* register for interrupts */ |
| 522 | if (state->irq > 0) { |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 523 | ret = request_threaded_irq(state->irq, NULL, adv7180_irq, |
| 524 | IRQF_ONESHOT, KBUILD_MODNAME, state); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 525 | if (ret) |
| 526 | return ret; |
| 527 | |
| 528 | ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, |
| 529 | ADV7180_ADI_CTRL_IRQ_SPACE); |
| 530 | if (ret < 0) |
| 531 | return ret; |
| 532 | |
| 533 | /* config the Interrupt pin to be active low */ |
| 534 | ret = i2c_smbus_write_byte_data(client, ADV7180_ICONF1_ADI, |
| 535 | ADV7180_ICONF1_ACTIVE_LOW | |
| 536 | ADV7180_ICONF1_PSYNC_ONLY); |
| 537 | if (ret < 0) |
| 538 | return ret; |
| 539 | |
| 540 | ret = i2c_smbus_write_byte_data(client, ADV7180_IMR1_ADI, 0); |
| 541 | if (ret < 0) |
| 542 | return ret; |
| 543 | |
| 544 | ret = i2c_smbus_write_byte_data(client, ADV7180_IMR2_ADI, 0); |
| 545 | if (ret < 0) |
| 546 | return ret; |
| 547 | |
| 548 | /* enable AD change interrupts interrupts */ |
| 549 | ret = i2c_smbus_write_byte_data(client, ADV7180_IMR3_ADI, |
| 550 | ADV7180_IRQ3_AD_CHANGE); |
| 551 | if (ret < 0) |
| 552 | return ret; |
| 553 | |
| 554 | ret = i2c_smbus_write_byte_data(client, ADV7180_IMR4_ADI, 0); |
| 555 | if (ret < 0) |
| 556 | return ret; |
| 557 | |
| 558 | ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, |
| 559 | 0); |
| 560 | if (ret < 0) |
| 561 | return ret; |
| 562 | } |
| 563 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 564 | return 0; |
| 565 | } |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 566 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 567 | static int adv7180_probe(struct i2c_client *client, |
| 568 | const struct i2c_device_id *id) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 569 | { |
| 570 | struct adv7180_state *state; |
| 571 | struct v4l2_subdev *sd; |
| 572 | int ret; |
| 573 | |
| 574 | /* Check if the adapter supports the needed features */ |
| 575 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 576 | return -EIO; |
| 577 | |
| 578 | v4l_info(client, "chip found @ 0x%02x (%s)\n", |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 579 | client->addr, client->adapter->name); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 580 | |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 581 | state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 582 | if (state == NULL) { |
| 583 | ret = -ENOMEM; |
| 584 | goto err; |
| 585 | } |
| 586 | |
| 587 | state->irq = client->irq; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 588 | mutex_init(&state->mutex); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 589 | state->autodetect = true; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 590 | state->input = 0; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 591 | sd = &state->sd; |
| 592 | v4l2_i2c_subdev_init(sd, client, &adv7180_ops); |
| 593 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 594 | ret = adv7180_init_controls(state); |
| 595 | if (ret) |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 596 | goto err_unreg_subdev; |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 597 | ret = init_device(client, state); |
| 598 | if (ret) |
| 599 | goto err_free_ctrl; |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame^] | 600 | |
| 601 | ret = v4l2_async_register_subdev(sd); |
| 602 | if (ret) |
| 603 | goto err_free_irq; |
| 604 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 605 | return 0; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 606 | |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame^] | 607 | err_free_irq: |
| 608 | if (state->irq > 0) |
| 609 | free_irq(client->irq, state); |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 610 | err_free_ctrl: |
| 611 | adv7180_exit_controls(state); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 612 | err_unreg_subdev: |
Lars-Peter Clausen | 297a0ae | 2014-03-07 13:14:27 -0300 | [diff] [blame] | 613 | mutex_destroy(&state->mutex); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 614 | err: |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 615 | return ret; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 616 | } |
| 617 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 618 | static int adv7180_remove(struct i2c_client *client) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 619 | { |
| 620 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 621 | struct adv7180_state *state = to_state(sd); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 622 | |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame^] | 623 | v4l2_async_unregister_subdev(sd); |
| 624 | |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 625 | if (state->irq > 0) |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 626 | free_irq(client->irq, state); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 627 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 628 | v4l2_device_unregister_subdev(sd); |
Lars-Peter Clausen | b13f4af | 2014-03-07 13:14:28 -0300 | [diff] [blame] | 629 | adv7180_exit_controls(state); |
Lars-Peter Clausen | 297a0ae | 2014-03-07 13:14:27 -0300 | [diff] [blame] | 630 | mutex_destroy(&state->mutex); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | static const struct i2c_device_id adv7180_id[] = { |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 635 | {KBUILD_MODNAME, 0}, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 636 | {}, |
| 637 | }; |
| 638 | |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 639 | #ifdef CONFIG_PM_SLEEP |
| 640 | static int adv7180_suspend(struct device *dev) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 641 | { |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 642 | struct i2c_client *client = to_i2c_client(dev); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 643 | int ret; |
| 644 | |
| 645 | ret = i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG, |
| 646 | ADV7180_PWR_MAN_OFF); |
| 647 | if (ret < 0) |
| 648 | return ret; |
| 649 | return 0; |
| 650 | } |
| 651 | |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 652 | static int adv7180_resume(struct device *dev) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 653 | { |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 654 | struct i2c_client *client = to_i2c_client(dev); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 655 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 656 | struct adv7180_state *state = to_state(sd); |
| 657 | int ret; |
| 658 | |
| 659 | ret = i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG, |
| 660 | ADV7180_PWR_MAN_ON); |
| 661 | if (ret < 0) |
| 662 | return ret; |
| 663 | ret = init_device(client, state); |
| 664 | if (ret < 0) |
| 665 | return ret; |
| 666 | return 0; |
| 667 | } |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 668 | |
| 669 | static SIMPLE_DEV_PM_OPS(adv7180_pm_ops, adv7180_suspend, adv7180_resume); |
| 670 | #define ADV7180_PM_OPS (&adv7180_pm_ops) |
| 671 | |
| 672 | #else |
| 673 | #define ADV7180_PM_OPS NULL |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 674 | #endif |
| 675 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 676 | MODULE_DEVICE_TABLE(i2c, adv7180_id); |
| 677 | |
| 678 | static struct i2c_driver adv7180_driver = { |
| 679 | .driver = { |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 680 | .owner = THIS_MODULE, |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 681 | .name = KBUILD_MODNAME, |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 682 | .pm = ADV7180_PM_OPS, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 683 | }, |
| 684 | .probe = adv7180_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 685 | .remove = adv7180_remove, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 686 | .id_table = adv7180_id, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 687 | }; |
| 688 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 689 | module_i2c_driver(adv7180_driver); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 690 | |
| 691 | MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver"); |
| 692 | MODULE_AUTHOR("Mocean Laboratories"); |
| 693 | MODULE_LICENSE("GPL v2"); |