Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 1 | /* |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 2 | * ths7303/53- THS7303/53 Video Amplifier driver |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 5 | * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. |
| 6 | * |
| 7 | * Author: Chaithrika U S <chaithrika@ti.com> |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Hans Verkuil <hans.verkuil@cisco.com> |
| 11 | * Lad, Prabhakar <prabhakar.lad@ti.com> |
| 12 | * Martin Bugge <marbugge@cisco.com> |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation version 2. |
| 17 | * |
| 18 | * This program is distributed .as is. WITHOUT ANY WARRANTY of any |
| 19 | * kind, whether express or implied; without even the implied warranty |
| 20 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | */ |
| 23 | |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 24 | #include <linux/i2c.h> |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 25 | #include <linux/module.h> |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 26 | #include <linux/slab.h> |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 27 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 28 | #include <media/ths7303.h> |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 29 | #include <media/v4l2-device.h> |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 30 | |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 31 | #define THS7303_CHANNEL_1 1 |
| 32 | #define THS7303_CHANNEL_2 2 |
| 33 | #define THS7303_CHANNEL_3 3 |
| 34 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 35 | struct ths7303_state { |
| 36 | struct v4l2_subdev sd; |
Lad, Prabhakar | dd8c393 | 2013-05-25 13:39:36 -0300 | [diff] [blame] | 37 | const struct ths7303_platform_data *pdata; |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 38 | struct v4l2_bt_timings bt; |
| 39 | int std_id; |
| 40 | int stream_on; |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 41 | }; |
| 42 | |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 43 | enum ths7303_filter_mode { |
| 44 | THS7303_FILTER_MODE_480I_576I, |
| 45 | THS7303_FILTER_MODE_480P_576P, |
| 46 | THS7303_FILTER_MODE_720P_1080I, |
| 47 | THS7303_FILTER_MODE_1080P, |
| 48 | THS7303_FILTER_MODE_DISABLE |
| 49 | }; |
| 50 | |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 51 | MODULE_DESCRIPTION("TI THS7303 video amplifier driver"); |
| 52 | MODULE_AUTHOR("Chaithrika U S"); |
| 53 | MODULE_LICENSE("GPL"); |
| 54 | |
| 55 | static int debug; |
| 56 | module_param(debug, int, 0644); |
| 57 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
| 58 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 59 | static inline struct ths7303_state *to_state(struct v4l2_subdev *sd) |
| 60 | { |
| 61 | return container_of(sd, struct ths7303_state, sd); |
| 62 | } |
| 63 | |
| 64 | static int ths7303_read(struct v4l2_subdev *sd, u8 reg) |
| 65 | { |
| 66 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 67 | |
| 68 | return i2c_smbus_read_byte_data(client, reg); |
| 69 | } |
| 70 | |
| 71 | static int ths7303_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 72 | { |
| 73 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 74 | int ret; |
| 75 | int i; |
| 76 | |
| 77 | for (i = 0; i < 3; i++) { |
| 78 | ret = i2c_smbus_write_byte_data(client, reg, val); |
| 79 | if (ret == 0) |
| 80 | return 0; |
| 81 | } |
| 82 | return ret; |
| 83 | } |
| 84 | |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 85 | /* following function is used to set ths7303 */ |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 86 | int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode) |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 87 | { |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 88 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 89 | struct ths7303_state *state = to_state(sd); |
Lad, Prabhakar | dd8c393 | 2013-05-25 13:39:36 -0300 | [diff] [blame] | 90 | const struct ths7303_platform_data *pdata = state->pdata; |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 91 | u8 val, sel = 0; |
| 92 | int err, disable = 0; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 93 | |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 94 | if (!client) |
| 95 | return -EINVAL; |
| 96 | |
| 97 | switch (mode) { |
| 98 | case THS7303_FILTER_MODE_1080P: |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 99 | sel = 0x3; /*1080p and SXGA/UXGA */ |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 100 | break; |
| 101 | case THS7303_FILTER_MODE_720P_1080I: |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 102 | sel = 0x2; /*720p, 1080i and SVGA/XGA */ |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 103 | break; |
| 104 | case THS7303_FILTER_MODE_480P_576P: |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 105 | sel = 0x1; /* EDTV 480p/576p and VGA */ |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 106 | break; |
| 107 | case THS7303_FILTER_MODE_480I_576I: |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 108 | sel = 0x0; /* SDTV, S-Video, 480i/576i */ |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 109 | break; |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 110 | default: |
| 111 | /* disable all channels */ |
| 112 | disable = 1; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 113 | } |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 114 | |
| 115 | val = (sel << 6) | (sel << 3); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 116 | if (!disable) |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 117 | val |= (pdata->ch_1 & 0x27); |
| 118 | err = ths7303_write(sd, THS7303_CHANNEL_1, val); |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 119 | if (err) |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 120 | goto out; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 121 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 122 | val = (sel << 6) | (sel << 3); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 123 | if (!disable) |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 124 | val |= (pdata->ch_2 & 0x27); |
| 125 | err = ths7303_write(sd, THS7303_CHANNEL_2, val); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 126 | if (err) |
| 127 | goto out; |
| 128 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 129 | val = (sel << 6) | (sel << 3); |
| 130 | if (!disable) |
| 131 | val |= (pdata->ch_3 & 0x27); |
| 132 | err = ths7303_write(sd, THS7303_CHANNEL_3, val); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 133 | if (err) |
| 134 | goto out; |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 135 | |
| 136 | return 0; |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 137 | out: |
| 138 | pr_info("write byte data failed\n"); |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 139 | return err; |
| 140 | } |
| 141 | |
| 142 | static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm) |
| 143 | { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 144 | struct ths7303_state *state = to_state(sd); |
| 145 | |
| 146 | if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM)) { |
| 147 | state->std_id = 1; |
| 148 | state->bt.pixelclock = 0; |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 149 | return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I); |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE); |
| 153 | } |
| 154 | |
| 155 | static int ths7303_config(struct v4l2_subdev *sd) |
| 156 | { |
| 157 | struct ths7303_state *state = to_state(sd); |
| 158 | int res; |
| 159 | |
| 160 | if (!state->stream_on) { |
| 161 | ths7303_write(sd, THS7303_CHANNEL_1, |
| 162 | (ths7303_read(sd, THS7303_CHANNEL_1) & 0xf8) | |
| 163 | 0x00); |
| 164 | ths7303_write(sd, THS7303_CHANNEL_2, |
| 165 | (ths7303_read(sd, THS7303_CHANNEL_2) & 0xf8) | |
| 166 | 0x00); |
| 167 | ths7303_write(sd, THS7303_CHANNEL_3, |
| 168 | (ths7303_read(sd, THS7303_CHANNEL_3) & 0xf8) | |
| 169 | 0x00); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | if (state->bt.pixelclock > 120000000) |
| 174 | res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P); |
| 175 | else if (state->bt.pixelclock > 70000000) |
| 176 | res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I); |
| 177 | else if (state->bt.pixelclock > 20000000) |
| 178 | res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P); |
| 179 | else if (state->std_id) |
| 180 | res = ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 181 | else |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 182 | /* disable all channels */ |
| 183 | res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE); |
| 184 | |
| 185 | return res; |
| 186 | |
| 187 | } |
| 188 | |
| 189 | static int ths7303_s_stream(struct v4l2_subdev *sd, int enable) |
| 190 | { |
| 191 | struct ths7303_state *state = to_state(sd); |
| 192 | |
| 193 | state->stream_on = enable; |
| 194 | |
| 195 | return ths7303_config(sd); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* for setting filter for HD output */ |
| 199 | static int ths7303_s_dv_timings(struct v4l2_subdev *sd, |
| 200 | struct v4l2_dv_timings *dv_timings) |
| 201 | { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 202 | struct ths7303_state *state = to_state(sd); |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 203 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 204 | if (!dv_timings || dv_timings->type != V4L2_DV_BT_656_1120) |
| 205 | return -EINVAL; |
Manjunath Hadli | ad7dcb3 | 2012-10-01 11:46:35 -0300 | [diff] [blame] | 206 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 207 | state->bt = dv_timings->bt; |
| 208 | state->std_id = 0; |
| 209 | |
| 210 | return ths7303_config(sd); |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 211 | } |
| 212 | |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 213 | static const struct v4l2_subdev_video_ops ths7303_video_ops = { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 214 | .s_stream = ths7303_s_stream, |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 215 | .s_std_output = ths7303_s_std_output, |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 216 | .s_dv_timings = ths7303_s_dv_timings, |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 217 | }; |
| 218 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 219 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 220 | |
| 221 | static int ths7303_g_register(struct v4l2_subdev *sd, |
| 222 | struct v4l2_dbg_register *reg) |
| 223 | { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 224 | reg->size = 1; |
| 225 | reg->val = ths7303_read(sd, reg->reg); |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int ths7303_s_register(struct v4l2_subdev *sd, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 230 | const struct v4l2_dbg_register *reg) |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 231 | { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 232 | ths7303_write(sd, reg->reg, reg->val); |
| 233 | return 0; |
| 234 | } |
| 235 | #endif |
| 236 | |
| 237 | static const char * const stc_lpf_sel_txt[4] = { |
| 238 | "500-kHz Filter", |
| 239 | "2.5-MHz Filter", |
| 240 | "5-MHz Filter", |
| 241 | "5-MHz Filter", |
| 242 | }; |
| 243 | |
| 244 | static const char * const in_mux_sel_txt[2] = { |
| 245 | "Input A Select", |
| 246 | "Input B Select", |
| 247 | }; |
| 248 | |
| 249 | static const char * const lpf_freq_sel_txt[4] = { |
| 250 | "9-MHz LPF", |
| 251 | "16-MHz LPF", |
| 252 | "35-MHz LPF", |
| 253 | "Bypass LPF", |
| 254 | }; |
| 255 | |
| 256 | static const char * const in_bias_sel_dis_cont_txt[8] = { |
| 257 | "Disable Channel", |
| 258 | "Mute Function - No Output", |
| 259 | "DC Bias Select", |
| 260 | "DC Bias + 250 mV Offset Select", |
| 261 | "AC Bias Select", |
| 262 | "Sync Tip Clamp with low bias", |
| 263 | "Sync Tip Clamp with mid bias", |
| 264 | "Sync Tip Clamp with high bias", |
| 265 | }; |
| 266 | |
| 267 | static void ths7303_log_channel_status(struct v4l2_subdev *sd, u8 reg) |
| 268 | { |
| 269 | u8 val = ths7303_read(sd, reg); |
| 270 | |
| 271 | if ((val & 0x7) == 0) { |
| 272 | v4l2_info(sd, "Channel %d Off\n", reg); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | v4l2_info(sd, "Channel %d On\n", reg); |
| 277 | v4l2_info(sd, " value 0x%x\n", val); |
| 278 | v4l2_info(sd, " %s\n", stc_lpf_sel_txt[(val >> 6) & 0x3]); |
| 279 | v4l2_info(sd, " %s\n", in_mux_sel_txt[(val >> 5) & 0x1]); |
| 280 | v4l2_info(sd, " %s\n", lpf_freq_sel_txt[(val >> 3) & 0x3]); |
| 281 | v4l2_info(sd, " %s\n", in_bias_sel_dis_cont_txt[(val >> 0) & 0x7]); |
| 282 | } |
| 283 | |
| 284 | static int ths7303_log_status(struct v4l2_subdev *sd) |
| 285 | { |
| 286 | struct ths7303_state *state = to_state(sd); |
| 287 | |
| 288 | v4l2_info(sd, "stream %s\n", state->stream_on ? "On" : "Off"); |
| 289 | |
| 290 | if (state->bt.pixelclock) { |
| 291 | struct v4l2_bt_timings *bt = bt = &state->bt; |
| 292 | u32 frame_width, frame_height; |
| 293 | |
| 294 | frame_width = bt->width + bt->hfrontporch + |
| 295 | bt->hsync + bt->hbackporch; |
| 296 | frame_height = bt->height + bt->vfrontporch + |
| 297 | bt->vsync + bt->vbackporch; |
| 298 | v4l2_info(sd, |
| 299 | "timings: %dx%d%s%d (%dx%d). Pix freq. = %d Hz. Polarities = 0x%x\n", |
| 300 | bt->width, bt->height, bt->interlaced ? "i" : "p", |
| 301 | (frame_height * frame_width) > 0 ? |
| 302 | (int)bt->pixelclock / |
| 303 | (frame_height * frame_width) : 0, |
| 304 | frame_width, frame_height, |
| 305 | (int)bt->pixelclock, bt->polarities); |
| 306 | } else { |
| 307 | v4l2_info(sd, "no timings set\n"); |
| 308 | } |
| 309 | |
| 310 | ths7303_log_channel_status(sd, THS7303_CHANNEL_1); |
| 311 | ths7303_log_channel_status(sd, THS7303_CHANNEL_2); |
| 312 | ths7303_log_channel_status(sd, THS7303_CHANNEL_3); |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 317 | static const struct v4l2_subdev_core_ops ths7303_core_ops = { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 318 | .log_status = ths7303_log_status, |
| 319 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 320 | .g_register = ths7303_g_register, |
| 321 | .s_register = ths7303_s_register, |
| 322 | #endif |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | static const struct v4l2_subdev_ops ths7303_ops = { |
| 326 | .core = &ths7303_core_ops, |
| 327 | .video = &ths7303_video_ops, |
| 328 | }; |
| 329 | |
| 330 | static int ths7303_probe(struct i2c_client *client, |
| 331 | const struct i2c_device_id *id) |
| 332 | { |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 333 | struct ths7303_platform_data *pdata = client->dev.platform_data; |
| 334 | struct ths7303_state *state; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 335 | struct v4l2_subdev *sd; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 336 | |
Lad, Prabhakar | dd8c393 | 2013-05-25 13:39:36 -0300 | [diff] [blame] | 337 | if (pdata == NULL) { |
| 338 | dev_err(&client->dev, "No platform data\n"); |
| 339 | return -EINVAL; |
| 340 | } |
| 341 | |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 342 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 343 | return -ENODEV; |
| 344 | |
| 345 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 346 | client->addr << 1, client->adapter->name); |
| 347 | |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 348 | state = devm_kzalloc(&client->dev, sizeof(struct ths7303_state), |
| 349 | GFP_KERNEL); |
| 350 | if (!state) |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 351 | return -ENOMEM; |
| 352 | |
Lad, Prabhakar | dd8c393 | 2013-05-25 13:39:36 -0300 | [diff] [blame] | 353 | state->pdata = pdata; |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 354 | sd = &state->sd; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 355 | v4l2_i2c_subdev_init(sd, client, &ths7303_ops); |
| 356 | |
Lad, Prabhakar | 8524ce5 | 2013-05-25 13:39:35 -0300 | [diff] [blame] | 357 | /* set to default 480I_576I filter mode */ |
| 358 | if (ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I) < 0) { |
| 359 | v4l_err(client, "Setting to 480I_576I filter mode failed!\n"); |
| 360 | return -EINVAL; |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return 0; |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static int ths7303_remove(struct i2c_client *client) |
| 367 | { |
| 368 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 369 | |
| 370 | v4l2_device_unregister_subdev(sd); |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static const struct i2c_device_id ths7303_id[] = { |
Hans Verkuil | e127711 | 2013-05-29 06:59:51 -0300 | [diff] [blame] | 376 | {"ths7303", 0}, |
| 377 | {"ths7353", 0}, |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 378 | {}, |
| 379 | }; |
| 380 | |
| 381 | MODULE_DEVICE_TABLE(i2c, ths7303_id); |
| 382 | |
| 383 | static struct i2c_driver ths7303_driver = { |
| 384 | .driver = { |
| 385 | .owner = THIS_MODULE, |
Lad, Prabhakar | 88da018 | 2013-02-18 07:56:41 -0300 | [diff] [blame] | 386 | .name = "ths73x3", |
Chaithrika U S | 40199c5 | 2009-05-07 09:29:25 -0300 | [diff] [blame] | 387 | }, |
| 388 | .probe = ths7303_probe, |
| 389 | .remove = ths7303_remove, |
| 390 | .id_table = ths7303_id, |
| 391 | }; |
| 392 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 393 | module_i2c_driver(ths7303_driver); |