1814b4dd9SSylwester Nawrocki /* 2814b4dd9SSylwester Nawrocki * Samsung S5K6A3 image sensor driver 3814b4dd9SSylwester Nawrocki * 4814b4dd9SSylwester Nawrocki * Copyright (C) 2013 Samsung Electronics Co., Ltd. 5814b4dd9SSylwester Nawrocki * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> 6814b4dd9SSylwester Nawrocki * 7814b4dd9SSylwester Nawrocki * This program is free software; you can redistribute it and/or modify 8814b4dd9SSylwester Nawrocki * it under the terms of the GNU General Public License version 2 as 9814b4dd9SSylwester Nawrocki * published by the Free Software Foundation. 10814b4dd9SSylwester Nawrocki */ 11814b4dd9SSylwester Nawrocki 12814b4dd9SSylwester Nawrocki #include <linux/clk.h> 13814b4dd9SSylwester Nawrocki #include <linux/delay.h> 14814b4dd9SSylwester Nawrocki #include <linux/device.h> 15814b4dd9SSylwester Nawrocki #include <linux/errno.h> 16814b4dd9SSylwester Nawrocki #include <linux/gpio.h> 17814b4dd9SSylwester Nawrocki #include <linux/i2c.h> 18814b4dd9SSylwester Nawrocki #include <linux/kernel.h> 19814b4dd9SSylwester Nawrocki #include <linux/module.h> 20814b4dd9SSylwester Nawrocki #include <linux/of_gpio.h> 21814b4dd9SSylwester Nawrocki #include <linux/pm_runtime.h> 22814b4dd9SSylwester Nawrocki #include <linux/regulator/consumer.h> 23814b4dd9SSylwester Nawrocki #include <linux/slab.h> 24814b4dd9SSylwester Nawrocki #include <linux/videodev2.h> 25814b4dd9SSylwester Nawrocki #include <media/v4l2-async.h> 26814b4dd9SSylwester Nawrocki #include <media/v4l2-subdev.h> 27814b4dd9SSylwester Nawrocki 28814b4dd9SSylwester Nawrocki #define S5K6A3_SENSOR_MAX_WIDTH 1412 29814b4dd9SSylwester Nawrocki #define S5K6A3_SENSOR_MAX_HEIGHT 1412 30814b4dd9SSylwester Nawrocki #define S5K6A3_SENSOR_MIN_WIDTH 32 31814b4dd9SSylwester Nawrocki #define S5K6A3_SENSOR_MIN_HEIGHT 32 32814b4dd9SSylwester Nawrocki 33814b4dd9SSylwester Nawrocki #define S5K6A3_DEFAULT_WIDTH 1296 34814b4dd9SSylwester Nawrocki #define S5K6A3_DEFAULT_HEIGHT 732 35814b4dd9SSylwester Nawrocki 36814b4dd9SSylwester Nawrocki #define S5K6A3_DRV_NAME "S5K6A3" 37814b4dd9SSylwester Nawrocki #define S5K6A3_CLK_NAME "extclk" 38814b4dd9SSylwester Nawrocki #define S5K6A3_DEFAULT_CLK_FREQ 24000000U 39814b4dd9SSylwester Nawrocki 40814b4dd9SSylwester Nawrocki enum { 41814b4dd9SSylwester Nawrocki S5K6A3_SUPP_VDDA, 42814b4dd9SSylwester Nawrocki S5K6A3_SUPP_VDDIO, 43814b4dd9SSylwester Nawrocki S5K6A3_SUPP_AFVDD, 44814b4dd9SSylwester Nawrocki S5K6A3_NUM_SUPPLIES, 45814b4dd9SSylwester Nawrocki }; 46814b4dd9SSylwester Nawrocki 47814b4dd9SSylwester Nawrocki /** 48814b4dd9SSylwester Nawrocki * struct s5k6a3 - fimc-is sensor data structure 49814b4dd9SSylwester Nawrocki * @dev: pointer to this I2C client device structure 50814b4dd9SSylwester Nawrocki * @subdev: the image sensor's v4l2 subdev 51814b4dd9SSylwester Nawrocki * @pad: subdev media source pad 52814b4dd9SSylwester Nawrocki * @supplies: image sensor's voltage regulator supplies 53814b4dd9SSylwester Nawrocki * @gpio_reset: GPIO connected to the sensor's reset pin 54814b4dd9SSylwester Nawrocki * @lock: mutex protecting the structure's members below 55814b4dd9SSylwester Nawrocki * @format: media bus format at the sensor's source pad 56814b4dd9SSylwester Nawrocki */ 57814b4dd9SSylwester Nawrocki struct s5k6a3 { 58814b4dd9SSylwester Nawrocki struct device *dev; 59814b4dd9SSylwester Nawrocki struct v4l2_subdev subdev; 60814b4dd9SSylwester Nawrocki struct media_pad pad; 61814b4dd9SSylwester Nawrocki struct regulator_bulk_data supplies[S5K6A3_NUM_SUPPLIES]; 62814b4dd9SSylwester Nawrocki int gpio_reset; 63814b4dd9SSylwester Nawrocki struct mutex lock; 64814b4dd9SSylwester Nawrocki struct v4l2_mbus_framefmt format; 65814b4dd9SSylwester Nawrocki struct clk *clock; 66814b4dd9SSylwester Nawrocki u32 clock_frequency; 67814b4dd9SSylwester Nawrocki int power_count; 68814b4dd9SSylwester Nawrocki }; 69814b4dd9SSylwester Nawrocki 70814b4dd9SSylwester Nawrocki static const char * const s5k6a3_supply_names[] = { 71814b4dd9SSylwester Nawrocki [S5K6A3_SUPP_VDDA] = "svdda", 72814b4dd9SSylwester Nawrocki [S5K6A3_SUPP_VDDIO] = "svddio", 73814b4dd9SSylwester Nawrocki [S5K6A3_SUPP_AFVDD] = "afvdd", 74814b4dd9SSylwester Nawrocki }; 75814b4dd9SSylwester Nawrocki 76814b4dd9SSylwester Nawrocki static inline struct s5k6a3 *sd_to_s5k6a3(struct v4l2_subdev *sd) 77814b4dd9SSylwester Nawrocki { 78814b4dd9SSylwester Nawrocki return container_of(sd, struct s5k6a3, subdev); 79814b4dd9SSylwester Nawrocki } 80814b4dd9SSylwester Nawrocki 81814b4dd9SSylwester Nawrocki static const struct v4l2_mbus_framefmt s5k6a3_formats[] = { 82814b4dd9SSylwester Nawrocki { 83f5fe58fdSBoris BREZILLON .code = MEDIA_BUS_FMT_SGRBG10_1X10, 84814b4dd9SSylwester Nawrocki .colorspace = V4L2_COLORSPACE_SRGB, 85814b4dd9SSylwester Nawrocki .field = V4L2_FIELD_NONE, 86814b4dd9SSylwester Nawrocki } 87814b4dd9SSylwester Nawrocki }; 88814b4dd9SSylwester Nawrocki 89814b4dd9SSylwester Nawrocki static const struct v4l2_mbus_framefmt *find_sensor_format( 90814b4dd9SSylwester Nawrocki struct v4l2_mbus_framefmt *mf) 91814b4dd9SSylwester Nawrocki { 92814b4dd9SSylwester Nawrocki int i; 93814b4dd9SSylwester Nawrocki 94814b4dd9SSylwester Nawrocki for (i = 0; i < ARRAY_SIZE(s5k6a3_formats); i++) 95814b4dd9SSylwester Nawrocki if (mf->code == s5k6a3_formats[i].code) 96814b4dd9SSylwester Nawrocki return &s5k6a3_formats[i]; 97814b4dd9SSylwester Nawrocki 98814b4dd9SSylwester Nawrocki return &s5k6a3_formats[0]; 99814b4dd9SSylwester Nawrocki } 100814b4dd9SSylwester Nawrocki 101814b4dd9SSylwester Nawrocki static int s5k6a3_enum_mbus_code(struct v4l2_subdev *sd, 102*f7234138SHans Verkuil struct v4l2_subdev_pad_config *cfg, 103814b4dd9SSylwester Nawrocki struct v4l2_subdev_mbus_code_enum *code) 104814b4dd9SSylwester Nawrocki { 105814b4dd9SSylwester Nawrocki if (code->index >= ARRAY_SIZE(s5k6a3_formats)) 106814b4dd9SSylwester Nawrocki return -EINVAL; 107814b4dd9SSylwester Nawrocki 108814b4dd9SSylwester Nawrocki code->code = s5k6a3_formats[code->index].code; 109814b4dd9SSylwester Nawrocki return 0; 110814b4dd9SSylwester Nawrocki } 111814b4dd9SSylwester Nawrocki 112814b4dd9SSylwester Nawrocki static void s5k6a3_try_format(struct v4l2_mbus_framefmt *mf) 113814b4dd9SSylwester Nawrocki { 114814b4dd9SSylwester Nawrocki const struct v4l2_mbus_framefmt *fmt; 115814b4dd9SSylwester Nawrocki 116814b4dd9SSylwester Nawrocki fmt = find_sensor_format(mf); 117814b4dd9SSylwester Nawrocki mf->code = fmt->code; 118d53ce5acSLaurent Pinchart mf->field = V4L2_FIELD_NONE; 119814b4dd9SSylwester Nawrocki v4l_bound_align_image(&mf->width, S5K6A3_SENSOR_MIN_WIDTH, 120814b4dd9SSylwester Nawrocki S5K6A3_SENSOR_MAX_WIDTH, 0, 121814b4dd9SSylwester Nawrocki &mf->height, S5K6A3_SENSOR_MIN_HEIGHT, 122814b4dd9SSylwester Nawrocki S5K6A3_SENSOR_MAX_HEIGHT, 0, 0); 123814b4dd9SSylwester Nawrocki } 124814b4dd9SSylwester Nawrocki 125814b4dd9SSylwester Nawrocki static struct v4l2_mbus_framefmt *__s5k6a3_get_format( 126*f7234138SHans Verkuil struct s5k6a3 *sensor, struct v4l2_subdev_pad_config *cfg, 127814b4dd9SSylwester Nawrocki u32 pad, enum v4l2_subdev_format_whence which) 128814b4dd9SSylwester Nawrocki { 129814b4dd9SSylwester Nawrocki if (which == V4L2_SUBDEV_FORMAT_TRY) 130*f7234138SHans Verkuil return cfg ? v4l2_subdev_get_try_format(&sensor->subdev, cfg, pad) : NULL; 131814b4dd9SSylwester Nawrocki 132814b4dd9SSylwester Nawrocki return &sensor->format; 133814b4dd9SSylwester Nawrocki } 134814b4dd9SSylwester Nawrocki 135814b4dd9SSylwester Nawrocki static int s5k6a3_set_fmt(struct v4l2_subdev *sd, 136*f7234138SHans Verkuil struct v4l2_subdev_pad_config *cfg, 137814b4dd9SSylwester Nawrocki struct v4l2_subdev_format *fmt) 138814b4dd9SSylwester Nawrocki { 139814b4dd9SSylwester Nawrocki struct s5k6a3 *sensor = sd_to_s5k6a3(sd); 140814b4dd9SSylwester Nawrocki struct v4l2_mbus_framefmt *mf; 141814b4dd9SSylwester Nawrocki 142814b4dd9SSylwester Nawrocki s5k6a3_try_format(&fmt->format); 143814b4dd9SSylwester Nawrocki 144*f7234138SHans Verkuil mf = __s5k6a3_get_format(sensor, cfg, fmt->pad, fmt->which); 145814b4dd9SSylwester Nawrocki if (mf) { 146814b4dd9SSylwester Nawrocki mutex_lock(&sensor->lock); 147814b4dd9SSylwester Nawrocki if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) 148814b4dd9SSylwester Nawrocki *mf = fmt->format; 149814b4dd9SSylwester Nawrocki mutex_unlock(&sensor->lock); 150814b4dd9SSylwester Nawrocki } 151814b4dd9SSylwester Nawrocki return 0; 152814b4dd9SSylwester Nawrocki } 153814b4dd9SSylwester Nawrocki 154814b4dd9SSylwester Nawrocki static int s5k6a3_get_fmt(struct v4l2_subdev *sd, 155*f7234138SHans Verkuil struct v4l2_subdev_pad_config *cfg, 156814b4dd9SSylwester Nawrocki struct v4l2_subdev_format *fmt) 157814b4dd9SSylwester Nawrocki { 158814b4dd9SSylwester Nawrocki struct s5k6a3 *sensor = sd_to_s5k6a3(sd); 159814b4dd9SSylwester Nawrocki struct v4l2_mbus_framefmt *mf; 160814b4dd9SSylwester Nawrocki 161*f7234138SHans Verkuil mf = __s5k6a3_get_format(sensor, cfg, fmt->pad, fmt->which); 162814b4dd9SSylwester Nawrocki 163814b4dd9SSylwester Nawrocki mutex_lock(&sensor->lock); 164814b4dd9SSylwester Nawrocki fmt->format = *mf; 165814b4dd9SSylwester Nawrocki mutex_unlock(&sensor->lock); 166814b4dd9SSylwester Nawrocki return 0; 167814b4dd9SSylwester Nawrocki } 168814b4dd9SSylwester Nawrocki 169814b4dd9SSylwester Nawrocki static struct v4l2_subdev_pad_ops s5k6a3_pad_ops = { 170814b4dd9SSylwester Nawrocki .enum_mbus_code = s5k6a3_enum_mbus_code, 171814b4dd9SSylwester Nawrocki .get_fmt = s5k6a3_get_fmt, 172814b4dd9SSylwester Nawrocki .set_fmt = s5k6a3_set_fmt, 173814b4dd9SSylwester Nawrocki }; 174814b4dd9SSylwester Nawrocki 175814b4dd9SSylwester Nawrocki static int s5k6a3_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 176814b4dd9SSylwester Nawrocki { 177*f7234138SHans Verkuil struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(sd, fh->pad, 0); 178814b4dd9SSylwester Nawrocki 179814b4dd9SSylwester Nawrocki *format = s5k6a3_formats[0]; 180814b4dd9SSylwester Nawrocki format->width = S5K6A3_DEFAULT_WIDTH; 181814b4dd9SSylwester Nawrocki format->height = S5K6A3_DEFAULT_HEIGHT; 182814b4dd9SSylwester Nawrocki 183814b4dd9SSylwester Nawrocki return 0; 184814b4dd9SSylwester Nawrocki } 185814b4dd9SSylwester Nawrocki 186814b4dd9SSylwester Nawrocki static const struct v4l2_subdev_internal_ops s5k6a3_sd_internal_ops = { 187814b4dd9SSylwester Nawrocki .open = s5k6a3_open, 188814b4dd9SSylwester Nawrocki }; 189814b4dd9SSylwester Nawrocki 190814b4dd9SSylwester Nawrocki static int __s5k6a3_power_on(struct s5k6a3 *sensor) 191814b4dd9SSylwester Nawrocki { 192814b4dd9SSylwester Nawrocki int i = S5K6A3_SUPP_VDDA; 193814b4dd9SSylwester Nawrocki int ret; 194814b4dd9SSylwester Nawrocki 195814b4dd9SSylwester Nawrocki ret = clk_set_rate(sensor->clock, sensor->clock_frequency); 196814b4dd9SSylwester Nawrocki if (ret < 0) 197814b4dd9SSylwester Nawrocki return ret; 198814b4dd9SSylwester Nawrocki 199814b4dd9SSylwester Nawrocki ret = pm_runtime_get(sensor->dev); 200814b4dd9SSylwester Nawrocki if (ret < 0) 201814b4dd9SSylwester Nawrocki return ret; 202814b4dd9SSylwester Nawrocki 203814b4dd9SSylwester Nawrocki ret = regulator_enable(sensor->supplies[i].consumer); 204814b4dd9SSylwester Nawrocki if (ret < 0) 205814b4dd9SSylwester Nawrocki goto error_rpm_put; 206814b4dd9SSylwester Nawrocki 207814b4dd9SSylwester Nawrocki ret = clk_prepare_enable(sensor->clock); 208814b4dd9SSylwester Nawrocki if (ret < 0) 209814b4dd9SSylwester Nawrocki goto error_reg_dis; 210814b4dd9SSylwester Nawrocki 211814b4dd9SSylwester Nawrocki for (i++; i < S5K6A3_NUM_SUPPLIES; i++) { 212814b4dd9SSylwester Nawrocki ret = regulator_enable(sensor->supplies[i].consumer); 213814b4dd9SSylwester Nawrocki if (ret < 0) 214814b4dd9SSylwester Nawrocki goto error_reg_dis; 215814b4dd9SSylwester Nawrocki } 216814b4dd9SSylwester Nawrocki 217814b4dd9SSylwester Nawrocki gpio_set_value(sensor->gpio_reset, 1); 218814b4dd9SSylwester Nawrocki usleep_range(600, 800); 219814b4dd9SSylwester Nawrocki gpio_set_value(sensor->gpio_reset, 0); 220814b4dd9SSylwester Nawrocki usleep_range(600, 800); 221814b4dd9SSylwester Nawrocki gpio_set_value(sensor->gpio_reset, 1); 222814b4dd9SSylwester Nawrocki 223814b4dd9SSylwester Nawrocki /* Delay needed for the sensor initialization */ 224814b4dd9SSylwester Nawrocki msleep(20); 225814b4dd9SSylwester Nawrocki return 0; 226814b4dd9SSylwester Nawrocki 227814b4dd9SSylwester Nawrocki error_reg_dis: 228814b4dd9SSylwester Nawrocki for (--i; i >= 0; --i) 229814b4dd9SSylwester Nawrocki regulator_disable(sensor->supplies[i].consumer); 230814b4dd9SSylwester Nawrocki error_rpm_put: 231814b4dd9SSylwester Nawrocki pm_runtime_put(sensor->dev); 232814b4dd9SSylwester Nawrocki return ret; 233814b4dd9SSylwester Nawrocki } 234814b4dd9SSylwester Nawrocki 235814b4dd9SSylwester Nawrocki static int __s5k6a3_power_off(struct s5k6a3 *sensor) 236814b4dd9SSylwester Nawrocki { 237814b4dd9SSylwester Nawrocki int i; 238814b4dd9SSylwester Nawrocki 239814b4dd9SSylwester Nawrocki gpio_set_value(sensor->gpio_reset, 0); 240814b4dd9SSylwester Nawrocki 241814b4dd9SSylwester Nawrocki for (i = S5K6A3_NUM_SUPPLIES - 1; i >= 0; i--) 242814b4dd9SSylwester Nawrocki regulator_disable(sensor->supplies[i].consumer); 243814b4dd9SSylwester Nawrocki 244814b4dd9SSylwester Nawrocki clk_disable_unprepare(sensor->clock); 245814b4dd9SSylwester Nawrocki pm_runtime_put(sensor->dev); 246814b4dd9SSylwester Nawrocki return 0; 247814b4dd9SSylwester Nawrocki } 248814b4dd9SSylwester Nawrocki 249814b4dd9SSylwester Nawrocki static int s5k6a3_s_power(struct v4l2_subdev *sd, int on) 250814b4dd9SSylwester Nawrocki { 251814b4dd9SSylwester Nawrocki struct s5k6a3 *sensor = sd_to_s5k6a3(sd); 252814b4dd9SSylwester Nawrocki int ret = 0; 253814b4dd9SSylwester Nawrocki 254814b4dd9SSylwester Nawrocki mutex_lock(&sensor->lock); 255814b4dd9SSylwester Nawrocki 256814b4dd9SSylwester Nawrocki if (sensor->power_count == !on) { 257814b4dd9SSylwester Nawrocki if (on) 258814b4dd9SSylwester Nawrocki ret = __s5k6a3_power_on(sensor); 259814b4dd9SSylwester Nawrocki else 260814b4dd9SSylwester Nawrocki ret = __s5k6a3_power_off(sensor); 261814b4dd9SSylwester Nawrocki 262814b4dd9SSylwester Nawrocki if (ret == 0) 263814b4dd9SSylwester Nawrocki sensor->power_count += on ? 1 : -1; 264814b4dd9SSylwester Nawrocki } 265814b4dd9SSylwester Nawrocki 266814b4dd9SSylwester Nawrocki mutex_unlock(&sensor->lock); 267814b4dd9SSylwester Nawrocki return ret; 268814b4dd9SSylwester Nawrocki } 269814b4dd9SSylwester Nawrocki 270814b4dd9SSylwester Nawrocki static struct v4l2_subdev_core_ops s5k6a3_core_ops = { 271814b4dd9SSylwester Nawrocki .s_power = s5k6a3_s_power, 272814b4dd9SSylwester Nawrocki }; 273814b4dd9SSylwester Nawrocki 274814b4dd9SSylwester Nawrocki static struct v4l2_subdev_ops s5k6a3_subdev_ops = { 275814b4dd9SSylwester Nawrocki .core = &s5k6a3_core_ops, 276814b4dd9SSylwester Nawrocki .pad = &s5k6a3_pad_ops, 277814b4dd9SSylwester Nawrocki }; 278814b4dd9SSylwester Nawrocki 279814b4dd9SSylwester Nawrocki static int s5k6a3_probe(struct i2c_client *client, 280814b4dd9SSylwester Nawrocki const struct i2c_device_id *id) 281814b4dd9SSylwester Nawrocki { 282814b4dd9SSylwester Nawrocki struct device *dev = &client->dev; 283814b4dd9SSylwester Nawrocki struct s5k6a3 *sensor; 284814b4dd9SSylwester Nawrocki struct v4l2_subdev *sd; 285814b4dd9SSylwester Nawrocki int gpio, i, ret; 286814b4dd9SSylwester Nawrocki 287814b4dd9SSylwester Nawrocki sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); 288814b4dd9SSylwester Nawrocki if (!sensor) 289814b4dd9SSylwester Nawrocki return -ENOMEM; 290814b4dd9SSylwester Nawrocki 291814b4dd9SSylwester Nawrocki mutex_init(&sensor->lock); 292814b4dd9SSylwester Nawrocki sensor->gpio_reset = -EINVAL; 293814b4dd9SSylwester Nawrocki sensor->clock = ERR_PTR(-EINVAL); 294814b4dd9SSylwester Nawrocki sensor->dev = dev; 295814b4dd9SSylwester Nawrocki 296814b4dd9SSylwester Nawrocki sensor->clock = devm_clk_get(sensor->dev, S5K6A3_CLK_NAME); 297814b4dd9SSylwester Nawrocki if (IS_ERR(sensor->clock)) 298814b4dd9SSylwester Nawrocki return PTR_ERR(sensor->clock); 299814b4dd9SSylwester Nawrocki 300814b4dd9SSylwester Nawrocki gpio = of_get_gpio_flags(dev->of_node, 0, NULL); 301814b4dd9SSylwester Nawrocki if (!gpio_is_valid(gpio)) 302814b4dd9SSylwester Nawrocki return gpio; 303814b4dd9SSylwester Nawrocki 304814b4dd9SSylwester Nawrocki ret = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_LOW, 305814b4dd9SSylwester Nawrocki S5K6A3_DRV_NAME); 306814b4dd9SSylwester Nawrocki if (ret < 0) 307814b4dd9SSylwester Nawrocki return ret; 308814b4dd9SSylwester Nawrocki 309814b4dd9SSylwester Nawrocki sensor->gpio_reset = gpio; 310814b4dd9SSylwester Nawrocki 311814b4dd9SSylwester Nawrocki if (of_property_read_u32(dev->of_node, "clock-frequency", 312814b4dd9SSylwester Nawrocki &sensor->clock_frequency)) { 313814b4dd9SSylwester Nawrocki sensor->clock_frequency = S5K6A3_DEFAULT_CLK_FREQ; 314814b4dd9SSylwester Nawrocki dev_info(dev, "using default %u Hz clock frequency\n", 315814b4dd9SSylwester Nawrocki sensor->clock_frequency); 316814b4dd9SSylwester Nawrocki } 317814b4dd9SSylwester Nawrocki 318814b4dd9SSylwester Nawrocki for (i = 0; i < S5K6A3_NUM_SUPPLIES; i++) 319814b4dd9SSylwester Nawrocki sensor->supplies[i].supply = s5k6a3_supply_names[i]; 320814b4dd9SSylwester Nawrocki 321814b4dd9SSylwester Nawrocki ret = devm_regulator_bulk_get(&client->dev, S5K6A3_NUM_SUPPLIES, 322814b4dd9SSylwester Nawrocki sensor->supplies); 323814b4dd9SSylwester Nawrocki if (ret < 0) 324814b4dd9SSylwester Nawrocki return ret; 325814b4dd9SSylwester Nawrocki 326814b4dd9SSylwester Nawrocki sd = &sensor->subdev; 327814b4dd9SSylwester Nawrocki v4l2_i2c_subdev_init(sd, client, &s5k6a3_subdev_ops); 328814b4dd9SSylwester Nawrocki sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 329814b4dd9SSylwester Nawrocki sd->internal_ops = &s5k6a3_sd_internal_ops; 330814b4dd9SSylwester Nawrocki 331814b4dd9SSylwester Nawrocki sensor->format.code = s5k6a3_formats[0].code; 332814b4dd9SSylwester Nawrocki sensor->format.width = S5K6A3_DEFAULT_WIDTH; 333814b4dd9SSylwester Nawrocki sensor->format.height = S5K6A3_DEFAULT_HEIGHT; 334814b4dd9SSylwester Nawrocki 335814b4dd9SSylwester Nawrocki sensor->pad.flags = MEDIA_PAD_FL_SOURCE; 336814b4dd9SSylwester Nawrocki ret = media_entity_init(&sd->entity, 1, &sensor->pad, 0); 337814b4dd9SSylwester Nawrocki if (ret < 0) 338814b4dd9SSylwester Nawrocki return ret; 339814b4dd9SSylwester Nawrocki 340814b4dd9SSylwester Nawrocki pm_runtime_no_callbacks(dev); 341814b4dd9SSylwester Nawrocki pm_runtime_enable(dev); 342814b4dd9SSylwester Nawrocki 343814b4dd9SSylwester Nawrocki ret = v4l2_async_register_subdev(sd); 344814b4dd9SSylwester Nawrocki 345814b4dd9SSylwester Nawrocki if (ret < 0) { 346814b4dd9SSylwester Nawrocki pm_runtime_disable(&client->dev); 347814b4dd9SSylwester Nawrocki media_entity_cleanup(&sd->entity); 348814b4dd9SSylwester Nawrocki } 349814b4dd9SSylwester Nawrocki 350814b4dd9SSylwester Nawrocki return ret; 351814b4dd9SSylwester Nawrocki } 352814b4dd9SSylwester Nawrocki 353814b4dd9SSylwester Nawrocki static int s5k6a3_remove(struct i2c_client *client) 354814b4dd9SSylwester Nawrocki { 355814b4dd9SSylwester Nawrocki struct v4l2_subdev *sd = i2c_get_clientdata(client); 356814b4dd9SSylwester Nawrocki 357814b4dd9SSylwester Nawrocki pm_runtime_disable(&client->dev); 358814b4dd9SSylwester Nawrocki v4l2_async_unregister_subdev(sd); 359814b4dd9SSylwester Nawrocki media_entity_cleanup(&sd->entity); 360814b4dd9SSylwester Nawrocki return 0; 361814b4dd9SSylwester Nawrocki } 362814b4dd9SSylwester Nawrocki 363814b4dd9SSylwester Nawrocki static const struct i2c_device_id s5k6a3_ids[] = { 364814b4dd9SSylwester Nawrocki { } 365814b4dd9SSylwester Nawrocki }; 366814b4dd9SSylwester Nawrocki 367814b4dd9SSylwester Nawrocki #ifdef CONFIG_OF 368814b4dd9SSylwester Nawrocki static const struct of_device_id s5k6a3_of_match[] = { 369814b4dd9SSylwester Nawrocki { .compatible = "samsung,s5k6a3" }, 370814b4dd9SSylwester Nawrocki { /* sentinel */ } 371814b4dd9SSylwester Nawrocki }; 372814b4dd9SSylwester Nawrocki MODULE_DEVICE_TABLE(of, s5k6a3_of_match); 373814b4dd9SSylwester Nawrocki #endif 374814b4dd9SSylwester Nawrocki 375814b4dd9SSylwester Nawrocki static struct i2c_driver s5k6a3_driver = { 376814b4dd9SSylwester Nawrocki .driver = { 377814b4dd9SSylwester Nawrocki .of_match_table = of_match_ptr(s5k6a3_of_match), 378814b4dd9SSylwester Nawrocki .name = S5K6A3_DRV_NAME, 379814b4dd9SSylwester Nawrocki .owner = THIS_MODULE, 380814b4dd9SSylwester Nawrocki }, 381814b4dd9SSylwester Nawrocki .probe = s5k6a3_probe, 382814b4dd9SSylwester Nawrocki .remove = s5k6a3_remove, 383814b4dd9SSylwester Nawrocki .id_table = s5k6a3_ids, 384814b4dd9SSylwester Nawrocki }; 385814b4dd9SSylwester Nawrocki 386814b4dd9SSylwester Nawrocki module_i2c_driver(s5k6a3_driver); 387814b4dd9SSylwester Nawrocki 388814b4dd9SSylwester Nawrocki MODULE_DESCRIPTION("S5K6A3 image sensor subdev driver"); 389814b4dd9SSylwester Nawrocki MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); 390814b4dd9SSylwester Nawrocki MODULE_LICENSE("GPL v2"); 391