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