1 // SPDX-License-Identifier: GPL-2.0
3 * Support for GalaxyCore GC2235 2M camera sensor.
5 * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
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.
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/errno.h>
24 #include <linux/init.h>
25 #include <linux/kmod.h>
26 #include <linux/device.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/i2c.h>
30 #include <linux/moduleparam.h>
31 #include <media/v4l2-device.h>
32 #include "../include/linux/atomisp_gmin_platform.h"
33 #include <linux/acpi.h>
38 /* i2c read/write stuff */
39 static int gc2235_read_reg(struct i2c_client *client,
40 u16 data_length, u16 reg, u16 *val)
43 struct i2c_msg msg[2];
44 unsigned char data[6];
46 if (!client->adapter) {
47 dev_err(&client->dev, "%s error, no client->adapter\n",
52 if (data_length != GC2235_8BIT) {
53 dev_err(&client->dev, "%s error, invalid data length\n",
58 memset(msg, 0, sizeof(msg));
60 msg[0].addr = client->addr;
65 /* high byte goes out first */
66 data[0] = (u8)(reg & 0xff);
68 msg[1].addr = client->addr;
69 msg[1].len = data_length;
70 msg[1].flags = I2C_M_RD;
73 err = i2c_transfer(client->adapter, msg, 2);
78 "read from offset 0x%x error %d", reg, err);
83 /* high byte comes first */
84 if (data_length == GC2235_8BIT)
90 static int gc2235_i2c_write(struct i2c_client *client, u16 len, u8 *data)
93 const int num_msg = 1;
96 msg.addr = client->addr;
100 ret = i2c_transfer(client->adapter, &msg, 1);
102 return ret == num_msg ? 0 : -EIO;
105 static int gc2235_write_reg(struct i2c_client *client, u16 data_length,
109 unsigned char data[4] = {0};
110 const u16 len = data_length + sizeof(u8); /* 16-bit address + data */
112 if (data_length != GC2235_8BIT) {
113 dev_err(&client->dev,
114 "%s error, invalid data_length\n", __func__);
118 /* high byte goes out first */
122 ret = gc2235_i2c_write(client, len, data);
124 dev_err(&client->dev,
125 "write error: wrote 0x%x to offset 0x%x error %d",
131 static int __gc2235_flush_reg_array(struct i2c_client *client,
132 struct gc2235_write_ctrl *ctrl)
136 if (ctrl->index == 0)
139 size = sizeof(u8) + ctrl->index; /* 8-bit address + data */
142 return gc2235_i2c_write(client, size, (u8 *)&ctrl->buffer);
145 static int __gc2235_buf_reg_array(struct i2c_client *client,
146 struct gc2235_write_ctrl *ctrl,
147 const struct gc2235_reg *next)
151 if (next->type != GC2235_8BIT)
155 ctrl->buffer.data[ctrl->index] = (u8)next->val;
157 /* When first item is added, we need to store its starting address */
158 if (ctrl->index == 0)
159 ctrl->buffer.addr = next->reg;
164 * Buffer cannot guarantee free space for u32? Better flush it to avoid
165 * possible lack of memory for next item.
167 if (ctrl->index + sizeof(u8) >= GC2235_MAX_WRITE_BUF_SIZE)
168 return __gc2235_flush_reg_array(client, ctrl);
173 static int __gc2235_write_reg_is_consecutive(struct i2c_client *client,
174 struct gc2235_write_ctrl *ctrl,
175 const struct gc2235_reg *next)
177 if (ctrl->index == 0)
180 return ctrl->buffer.addr + ctrl->index == next->reg;
183 static int gc2235_write_reg_array(struct i2c_client *client,
184 const struct gc2235_reg *reglist)
186 const struct gc2235_reg *next = reglist;
187 struct gc2235_write_ctrl ctrl;
191 for (; next->type != GC2235_TOK_TERM; next++) {
192 switch (next->type & GC2235_TOK_MASK) {
193 case GC2235_TOK_DELAY:
194 err = __gc2235_flush_reg_array(client, &ctrl);
201 * If next address is not consecutive, data needs to be
202 * flushed before proceed.
204 if (!__gc2235_write_reg_is_consecutive(client, &ctrl,
206 err = __gc2235_flush_reg_array(client, &ctrl);
210 err = __gc2235_buf_reg_array(client, &ctrl, next);
212 dev_err(&client->dev, "%s: write error, aborted\n",
220 return __gc2235_flush_reg_array(client, &ctrl);
223 static int gc2235_g_focal(struct v4l2_subdev *sd, s32 *val)
225 *val = (GC2235_FOCAL_LENGTH_NUM << 16) | GC2235_FOCAL_LENGTH_DEM;
229 static int gc2235_g_fnumber(struct v4l2_subdev *sd, s32 *val)
231 /* const f number for imx */
232 *val = (GC2235_F_NUMBER_DEFAULT_NUM << 16) | GC2235_F_NUMBER_DEM;
236 static int gc2235_g_fnumber_range(struct v4l2_subdev *sd, s32 *val)
238 *val = (GC2235_F_NUMBER_DEFAULT_NUM << 24) |
239 (GC2235_F_NUMBER_DEM << 16) |
240 (GC2235_F_NUMBER_DEFAULT_NUM << 8) | GC2235_F_NUMBER_DEM;
244 static int gc2235_get_intg_factor(struct i2c_client *client,
245 struct camera_mipi_info *info,
246 const struct gc2235_resolution *res)
248 struct v4l2_subdev *sd = i2c_get_clientdata(client);
249 struct gc2235_device *dev = to_gc2235_sensor(sd);
250 struct atomisp_sensor_mode_data *buf = &info->data;
251 u16 reg_val, reg_val_h;
257 /* pixel clock calculattion */
258 buf->vt_pix_clk_freq_mhz = dev->vt_pix_clk_freq_mhz = 30000000;
260 /* get integration time */
261 buf->coarse_integration_time_min = GC2235_COARSE_INTG_TIME_MIN;
262 buf->coarse_integration_time_max_margin =
263 GC2235_COARSE_INTG_TIME_MAX_MARGIN;
265 buf->fine_integration_time_min = GC2235_FINE_INTG_TIME_MIN;
266 buf->fine_integration_time_max_margin =
267 GC2235_FINE_INTG_TIME_MAX_MARGIN;
269 buf->fine_integration_time_def = GC2235_FINE_INTG_TIME_MIN;
270 buf->frame_length_lines = res->lines_per_frame;
271 buf->line_length_pck = res->pixels_per_line;
272 buf->read_mode = res->bin_mode;
274 /* get the cropping and output resolution to ISP for this mode. */
275 ret = gc2235_read_reg(client, GC2235_8BIT,
276 GC2235_H_CROP_START_H, ®_val_h);
277 ret = gc2235_read_reg(client, GC2235_8BIT,
278 GC2235_H_CROP_START_L, ®_val);
282 buf->crop_horizontal_start = (reg_val_h << 8) | reg_val;
284 ret = gc2235_read_reg(client, GC2235_8BIT,
285 GC2235_V_CROP_START_H, ®_val_h);
286 ret = gc2235_read_reg(client, GC2235_8BIT,
287 GC2235_V_CROP_START_L, ®_val);
291 buf->crop_vertical_start = (reg_val_h << 8) | reg_val;
293 ret = gc2235_read_reg(client, GC2235_8BIT,
294 GC2235_H_OUTSIZE_H, ®_val_h);
295 ret = gc2235_read_reg(client, GC2235_8BIT,
296 GC2235_H_OUTSIZE_L, ®_val);
299 buf->output_width = (reg_val_h << 8) | reg_val;
301 ret = gc2235_read_reg(client, GC2235_8BIT,
302 GC2235_V_OUTSIZE_H, ®_val_h);
303 ret = gc2235_read_reg(client, GC2235_8BIT,
304 GC2235_V_OUTSIZE_L, ®_val);
307 buf->output_height = (reg_val_h << 8) | reg_val;
309 buf->crop_horizontal_end = buf->crop_horizontal_start +
310 buf->output_width - 1;
311 buf->crop_vertical_end = buf->crop_vertical_start +
312 buf->output_height - 1;
314 ret = gc2235_read_reg(client, GC2235_8BIT,
315 GC2235_HB_H, ®_val_h);
316 ret = gc2235_read_reg(client, GC2235_8BIT,
317 GC2235_HB_L, ®_val);
322 u16 dummy = (reg_val_h << 8) | reg_val;
325 ret = gc2235_read_reg(client, GC2235_8BIT,
326 GC2235_SH_DELAY_H, ®_val_h);
327 ret = gc2235_read_reg(client, GC2235_8BIT,
328 GC2235_SH_DELAY_L, ®_val);
331 buf->line_length_pck = buf->output_width + 16 + dummy +
332 (((u16)reg_val_h << 8) | (u16)reg_val) + 4;
334 ret = gc2235_read_reg(client, GC2235_8BIT,
335 GC2235_VB_H, ®_val_h);
336 ret = gc2235_read_reg(client, GC2235_8BIT,
337 GC2235_VB_L, ®_val);
342 buf->frame_length_lines = buf->output_height + 32 +
343 (((u16)reg_val_h << 8) | (u16)reg_val);
345 buf->binning_factor_x = res->bin_factor_x ?
346 res->bin_factor_x : 1;
347 buf->binning_factor_y = res->bin_factor_y ?
348 res->bin_factor_y : 1;
352 static long __gc2235_set_exposure(struct v4l2_subdev *sd, int coarse_itg,
353 int gain, int digitgain)
356 struct i2c_client *client = v4l2_get_subdevdata(sd);
357 u16 coarse_integration = (u16)coarse_itg;
359 u16 expo_coarse_h, expo_coarse_l, gain_val = 0xF0, gain_val2 = 0xF0;
361 expo_coarse_h = coarse_integration >> 8;
362 expo_coarse_l = coarse_integration & 0xff;
364 ret = gc2235_write_reg(client, GC2235_8BIT,
365 GC2235_EXPOSURE_H, expo_coarse_h);
366 ret = gc2235_write_reg(client, GC2235_8BIT,
367 GC2235_EXPOSURE_L, expo_coarse_l);
372 } else if (gain < 256) {
376 gain_val2 = 64 * gain / 256;
380 ret = gc2235_write_reg(client, GC2235_8BIT,
381 GC2235_GLOBAL_GAIN, (u8)gain_val);
382 ret = gc2235_write_reg(client, GC2235_8BIT,
383 GC2235_PRE_GAIN, (u8)gain_val2);
388 static int gc2235_set_exposure(struct v4l2_subdev *sd, int exposure,
389 int gain, int digitgain)
391 struct gc2235_device *dev = to_gc2235_sensor(sd);
394 mutex_lock(&dev->input_lock);
395 ret = __gc2235_set_exposure(sd, exposure, gain, digitgain);
396 mutex_unlock(&dev->input_lock);
401 static long gc2235_s_exposure(struct v4l2_subdev *sd,
402 struct atomisp_exposure *exposure)
404 int exp = exposure->integration_time[0];
405 int gain = exposure->gain[0];
406 int digitgain = exposure->gain[1];
408 /* we should not accept the invalid value below. */
410 struct i2c_client *client = v4l2_get_subdevdata(sd);
412 v4l2_err(client, "%s: invalid value\n", __func__);
416 return gc2235_set_exposure(sd, exp, gain, digitgain);
419 static long gc2235_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
422 case ATOMISP_IOC_S_EXPOSURE:
423 return gc2235_s_exposure(sd, arg);
431 * This returns the exposure time being used. This should only be used
432 * for filling in EXIF data, not for actual image processing.
434 static int gc2235_q_exposure(struct v4l2_subdev *sd, s32 *value)
436 struct i2c_client *client = v4l2_get_subdevdata(sd);
441 ret = gc2235_read_reg(client, GC2235_8BIT,
447 ret = gc2235_read_reg(client, GC2235_8BIT,
453 reg_v += reg_v2 << 8;
460 static int gc2235_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
462 struct gc2235_device *dev =
463 container_of(ctrl->handler, struct gc2235_device, ctrl_handler);
467 case V4L2_CID_EXPOSURE_ABSOLUTE:
468 ret = gc2235_q_exposure(&dev->sd, &ctrl->val);
470 case V4L2_CID_FOCAL_ABSOLUTE:
471 ret = gc2235_g_focal(&dev->sd, &ctrl->val);
473 case V4L2_CID_FNUMBER_ABSOLUTE:
474 ret = gc2235_g_fnumber(&dev->sd, &ctrl->val);
476 case V4L2_CID_FNUMBER_RANGE:
477 ret = gc2235_g_fnumber_range(&dev->sd, &ctrl->val);
486 static const struct v4l2_ctrl_ops ctrl_ops = {
487 .g_volatile_ctrl = gc2235_g_volatile_ctrl
490 static struct v4l2_ctrl_config gc2235_controls[] = {
493 .id = V4L2_CID_EXPOSURE_ABSOLUTE,
494 .type = V4L2_CTRL_TYPE_INTEGER,
504 .id = V4L2_CID_FOCAL_ABSOLUTE,
505 .type = V4L2_CTRL_TYPE_INTEGER,
506 .name = "focal length",
507 .min = GC2235_FOCAL_LENGTH_DEFAULT,
508 .max = GC2235_FOCAL_LENGTH_DEFAULT,
510 .def = GC2235_FOCAL_LENGTH_DEFAULT,
515 .id = V4L2_CID_FNUMBER_ABSOLUTE,
516 .type = V4L2_CTRL_TYPE_INTEGER,
518 .min = GC2235_F_NUMBER_DEFAULT,
519 .max = GC2235_F_NUMBER_DEFAULT,
521 .def = GC2235_F_NUMBER_DEFAULT,
526 .id = V4L2_CID_FNUMBER_RANGE,
527 .type = V4L2_CTRL_TYPE_INTEGER,
528 .name = "f-number range",
529 .min = GC2235_F_NUMBER_RANGE,
530 .max = GC2235_F_NUMBER_RANGE,
532 .def = GC2235_F_NUMBER_RANGE,
537 static int __gc2235_init(struct v4l2_subdev *sd)
539 struct i2c_client *client = v4l2_get_subdevdata(sd);
541 /* restore settings */
542 gc2235_res = gc2235_res_preview;
543 N_RES = N_RES_PREVIEW;
545 return gc2235_write_reg_array(client, gc2235_init_settings);
550 static int power_ctrl(struct v4l2_subdev *sd, bool flag)
553 struct gc2235_device *dev = to_gc2235_sensor(sd);
555 if (!dev || !dev->platform_data)
559 ret = dev->platform_data->v1p8_ctrl(sd, 1);
560 usleep_range(60, 90);
562 ret |= dev->platform_data->v2p8_ctrl(sd, 1);
564 ret = dev->platform_data->v1p8_ctrl(sd, 0);
565 ret |= dev->platform_data->v2p8_ctrl(sd, 0);
570 static int gpio_ctrl(struct v4l2_subdev *sd, bool flag)
572 struct gc2235_device *dev = to_gc2235_sensor(sd);
575 if (!dev || !dev->platform_data)
578 ret = dev->platform_data->gpio1_ctrl(sd, !flag);
579 usleep_range(60, 90);
580 ret |= dev->platform_data->gpio0_ctrl(sd, flag);
585 static int power_up(struct v4l2_subdev *sd)
587 struct gc2235_device *dev = to_gc2235_sensor(sd);
588 struct i2c_client *client = v4l2_get_subdevdata(sd);
591 if (!dev->platform_data) {
592 dev_err(&client->dev,
593 "no camera_sensor_platform_data");
597 ret = power_ctrl(sd, 1);
601 /* according to DS, at least 5ms is needed between DOVDD and PWDN */
602 usleep_range(5000, 6000);
604 ret = dev->platform_data->flisclk_ctrl(sd, 1);
607 usleep_range(5000, 6000);
610 ret = gpio_ctrl(sd, 1);
612 ret = gpio_ctrl(sd, 1);
624 dev_err(&client->dev, "sensor power-up failed\n");
629 static int power_down(struct v4l2_subdev *sd)
631 struct gc2235_device *dev = to_gc2235_sensor(sd);
632 struct i2c_client *client = v4l2_get_subdevdata(sd);
635 if (!dev->platform_data) {
636 dev_err(&client->dev,
637 "no camera_sensor_platform_data");
641 ret = gpio_ctrl(sd, 0);
643 ret = gpio_ctrl(sd, 0);
645 dev_err(&client->dev, "gpio failed 2\n");
648 ret = dev->platform_data->flisclk_ctrl(sd, 0);
650 dev_err(&client->dev, "flisclk failed\n");
653 ret = power_ctrl(sd, 0);
655 dev_err(&client->dev, "vprog failed.\n");
660 static int gc2235_s_power(struct v4l2_subdev *sd, int on)
665 ret = power_down(sd);
669 ret = __gc2235_init(sd);
675 static int startup(struct v4l2_subdev *sd)
677 struct gc2235_device *dev = to_gc2235_sensor(sd);
678 struct i2c_client *client = v4l2_get_subdevdata(sd);
683 * force gc2235 to do a reset in res change, otherwise it
684 * can not output normal after switching res. and it is not
685 * necessary for first time run up after power on, for the sack
690 gc2235_write_reg_array(client, gc2235_init_settings);
693 ret = gc2235_write_reg_array(client, dev->res->regs);
695 dev_err(&client->dev, "gc2235 write register err.\n");
703 static int gc2235_set_fmt(struct v4l2_subdev *sd,
704 struct v4l2_subdev_state *sd_state,
705 struct v4l2_subdev_format *format)
707 struct v4l2_mbus_framefmt *fmt = &format->format;
708 struct gc2235_device *dev = to_gc2235_sensor(sd);
709 struct i2c_client *client = v4l2_get_subdevdata(sd);
710 struct camera_mipi_info *gc2235_info = NULL;
711 struct gc2235_resolution *res;
714 gc2235_info = v4l2_get_subdev_hostdata(sd);
722 mutex_lock(&dev->input_lock);
723 res = v4l2_find_nearest_size(gc2235_res_preview,
724 ARRAY_SIZE(gc2235_res_preview), width,
725 height, fmt->width, fmt->height);
727 res = &gc2235_res_preview[N_RES - 1];
729 fmt->width = res->width;
730 fmt->height = res->height;
733 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
734 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
735 sd_state->pads->try_fmt = *fmt;
736 mutex_unlock(&dev->input_lock);
742 dev_err(&client->dev, "gc2235 startup err\n");
746 ret = gc2235_get_intg_factor(client, gc2235_info,
749 dev_err(&client->dev, "failed to get integration_factor\n");
752 mutex_unlock(&dev->input_lock);
756 static int gc2235_get_fmt(struct v4l2_subdev *sd,
757 struct v4l2_subdev_state *sd_state,
758 struct v4l2_subdev_format *format)
760 struct v4l2_mbus_framefmt *fmt = &format->format;
761 struct gc2235_device *dev = to_gc2235_sensor(sd);
769 fmt->width = dev->res->width;
770 fmt->height = dev->res->height;
771 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
776 static int gc2235_detect(struct i2c_client *client)
778 struct i2c_adapter *adapter = client->adapter;
779 u16 high = 0, low = 0;
782 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
785 gc2235_read_reg(client, GC2235_8BIT, GC2235_SENSOR_ID_H, &high);
786 gc2235_read_reg(client, GC2235_8BIT, GC2235_SENSOR_ID_L, &low);
787 id = ((high << 8) | low);
789 if (id != GC2235_ID) {
790 dev_err(&client->dev, "sensor ID error, 0x%x\n", id);
794 dev_info(&client->dev, "detect gc2235 success\n");
798 static int gc2235_s_stream(struct v4l2_subdev *sd, int enable)
800 struct gc2235_device *dev = to_gc2235_sensor(sd);
801 struct i2c_client *client = v4l2_get_subdevdata(sd);
804 mutex_lock(&dev->input_lock);
807 ret = gc2235_write_reg_array(client, gc2235_stream_on);
809 ret = gc2235_write_reg_array(client, gc2235_stream_off);
811 mutex_unlock(&dev->input_lock);
815 static int gc2235_s_config(struct v4l2_subdev *sd,
816 int irq, void *platform_data)
818 struct gc2235_device *dev = to_gc2235_sensor(sd);
819 struct i2c_client *client = v4l2_get_subdevdata(sd);
826 (struct camera_sensor_platform_data *)platform_data;
828 mutex_lock(&dev->input_lock);
830 * power off the module, then power on it in future
831 * as first power on by board may not fulfill the
832 * power on sequqence needed by the module
834 ret = power_down(sd);
836 dev_err(&client->dev, "gc2235 power-off err.\n");
842 dev_err(&client->dev, "gc2235 power-up err.\n");
846 ret = dev->platform_data->csi_cfg(sd, 1);
850 /* config & detect sensor */
851 ret = gc2235_detect(client);
853 dev_err(&client->dev, "gc2235_detect err s_config.\n");
857 /* turn off sensor, after probed */
858 ret = power_down(sd);
860 dev_err(&client->dev, "gc2235 power-off err.\n");
863 mutex_unlock(&dev->input_lock);
868 dev->platform_data->csi_cfg(sd, 0);
871 dev_err(&client->dev, "sensor power-gating failed\n");
873 mutex_unlock(&dev->input_lock);
877 static int gc2235_g_frame_interval(struct v4l2_subdev *sd,
878 struct v4l2_subdev_frame_interval *interval)
880 struct gc2235_device *dev = to_gc2235_sensor(sd);
882 interval->interval.numerator = 1;
883 interval->interval.denominator = dev->res->fps;
888 static int gc2235_enum_mbus_code(struct v4l2_subdev *sd,
889 struct v4l2_subdev_state *sd_state,
890 struct v4l2_subdev_mbus_code_enum *code)
892 if (code->index >= MAX_FMTS)
895 code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
899 static int gc2235_enum_frame_size(struct v4l2_subdev *sd,
900 struct v4l2_subdev_state *sd_state,
901 struct v4l2_subdev_frame_size_enum *fse)
903 int index = fse->index;
908 fse->min_width = gc2235_res[index].width;
909 fse->min_height = gc2235_res[index].height;
910 fse->max_width = gc2235_res[index].width;
911 fse->max_height = gc2235_res[index].height;
916 static int gc2235_g_skip_frames(struct v4l2_subdev *sd, u32 *frames)
918 struct gc2235_device *dev = to_gc2235_sensor(sd);
920 mutex_lock(&dev->input_lock);
921 *frames = dev->res->skip_frames;
922 mutex_unlock(&dev->input_lock);
927 static const struct v4l2_subdev_sensor_ops gc2235_sensor_ops = {
928 .g_skip_frames = gc2235_g_skip_frames,
931 static const struct v4l2_subdev_video_ops gc2235_video_ops = {
932 .s_stream = gc2235_s_stream,
933 .g_frame_interval = gc2235_g_frame_interval,
936 static const struct v4l2_subdev_core_ops gc2235_core_ops = {
937 .s_power = gc2235_s_power,
938 .ioctl = gc2235_ioctl,
941 static const struct v4l2_subdev_pad_ops gc2235_pad_ops = {
942 .enum_mbus_code = gc2235_enum_mbus_code,
943 .enum_frame_size = gc2235_enum_frame_size,
944 .get_fmt = gc2235_get_fmt,
945 .set_fmt = gc2235_set_fmt,
948 static const struct v4l2_subdev_ops gc2235_ops = {
949 .core = &gc2235_core_ops,
950 .video = &gc2235_video_ops,
951 .pad = &gc2235_pad_ops,
952 .sensor = &gc2235_sensor_ops,
955 static int gc2235_remove(struct i2c_client *client)
957 struct v4l2_subdev *sd = i2c_get_clientdata(client);
958 struct gc2235_device *dev = to_gc2235_sensor(sd);
960 dev_dbg(&client->dev, "gc2235_remove...\n");
962 dev->platform_data->csi_cfg(sd, 0);
964 v4l2_device_unregister_subdev(sd);
965 media_entity_cleanup(&dev->sd.entity);
966 v4l2_ctrl_handler_free(&dev->ctrl_handler);
972 static int gc2235_probe(struct i2c_client *client)
974 struct gc2235_device *dev;
979 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
983 mutex_init(&dev->input_lock);
985 dev->res = &gc2235_res_preview[0];
986 v4l2_i2c_subdev_init(&dev->sd, client, &gc2235_ops);
988 gcpdev = gmin_camera_platform_data(&dev->sd,
989 ATOMISP_INPUT_FORMAT_RAW_10,
990 atomisp_bayer_order_grbg);
992 ret = gc2235_s_config(&dev->sd, client->irq, gcpdev);
996 dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
997 dev->pad.flags = MEDIA_PAD_FL_SOURCE;
998 dev->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
999 dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1001 v4l2_ctrl_handler_init(&dev->ctrl_handler,
1002 ARRAY_SIZE(gc2235_controls));
1004 gc2235_remove(client);
1008 for (i = 0; i < ARRAY_SIZE(gc2235_controls); i++)
1009 v4l2_ctrl_new_custom(&dev->ctrl_handler, &gc2235_controls[i],
1012 if (dev->ctrl_handler.error) {
1013 gc2235_remove(client);
1014 return dev->ctrl_handler.error;
1017 /* Use same lock for controls as for everything else. */
1018 dev->ctrl_handler.lock = &dev->input_lock;
1019 dev->sd.ctrl_handler = &dev->ctrl_handler;
1021 ret = media_entity_pads_init(&dev->sd.entity, 1, &dev->pad);
1023 gc2235_remove(client);
1025 return atomisp_register_i2c_module(&dev->sd, gcpdev, RAW_CAMERA);
1028 v4l2_device_unregister_subdev(&dev->sd);
1034 static const struct acpi_device_id gc2235_acpi_match[] = {
1038 MODULE_DEVICE_TABLE(acpi, gc2235_acpi_match);
1040 static struct i2c_driver gc2235_driver = {
1043 .acpi_match_table = gc2235_acpi_match,
1045 .probe_new = gc2235_probe,
1046 .remove = gc2235_remove,
1048 module_i2c_driver(gc2235_driver);
1050 MODULE_AUTHOR("Shuguang Gong <Shuguang.Gong@intel.com>");
1051 MODULE_DESCRIPTION("A low-level driver for GC2235 sensors");
1052 MODULE_LICENSE("GPL");