tw9900
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
tw9900_fill_fmt(tw9900->cur_mode, mbus_fmt);
mutex_unlock(&tw9900->mutex);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
if (tw9900->streaming) {
mutex_unlock(&tw9900->mutex);
tw9900_fill_fmt(tw9900->cur_mode, mbus_fmt);
mutex_unlock(&tw9900->mutex);
struct tw9900 *tw9900 = container_of(ctrl->handler, struct tw9900, hdl);
if (pm_runtime_suspended(&tw9900->client->dev))
ret = tw9900_write_reg(tw9900->client, TW9900_REG_BRIGHT_CTL,
ret = tw9900_write_reg(tw9900->client, TW9900_REG_CONTRAST_CTL,
struct tw9900 *tw9900 = to_tw9900(sd);
struct i2c_client *client = tw9900->client;
mutex_lock(&tw9900->mutex);
if (tw9900->streaming == on) {
mutex_unlock(&tw9900->mutex);
mutex_unlock(&tw9900->mutex);
mutex_lock(&tw9900->mutex);
ret = tw9900_write_array(tw9900->client,
tw9900->cur_mode->reg_list,
tw9900->cur_mode->n_regs);
tw9900->streaming = on;
mutex_unlock(&tw9900->mutex);
mutex_lock(&tw9900->mutex);
tw9900->streaming = on;
mutex_unlock(&tw9900->mutex);
mutex_unlock(&tw9900->mutex);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
tw9900->cur_mode = mode;
mutex_unlock(&tw9900->mutex);
static int tw9900_get_stream_std(struct tw9900 *tw9900,
lockdep_assert_held(&tw9900->mutex);
ret = tw9900_read_reg(tw9900->client, TW9900_REG_STD);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
*std = tw9900->cur_mode->std;
mutex_unlock(&tw9900->mutex);
static int tw9900_start_autodetect(struct tw9900 *tw9900)
lockdep_assert_held(&tw9900->mutex);
ret = tw9900_write_reg(tw9900->client, TW9900_REG_STDR,
ret = tw9900_write_reg(tw9900->client, TW9900_REG_STD,
ret = tw9900_write_reg(tw9900->client, TW9900_REG_STDR,
static int tw9900_detect_done(struct tw9900 *tw9900, bool *done)
lockdep_assert_held(&tw9900->mutex);
ret = tw9900_read_reg(tw9900->client, TW9900_REG_STD);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
if (tw9900->streaming) {
mutex_unlock(&tw9900->mutex);
mutex_unlock(&tw9900->mutex);
ret = pm_runtime_resume_and_get(&tw9900->client->dev);
mutex_lock(&tw9900->mutex);
ret = tw9900_start_autodetect(tw9900);
ret = tw9900_detect_done(tw9900, &done);
ret = tw9900_get_stream_std(tw9900, std);
mutex_unlock(&tw9900->mutex);
pm_runtime_put(&tw9900->client->dev);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
if (tw9900->streaming) {
mutex_unlock(&tw9900->mutex);
mutex_unlock(&tw9900->mutex);
ret = pm_runtime_resume_and_get(&tw9900->client->dev);
mutex_lock(&tw9900->mutex);
ret = tw9900_read_reg(tw9900->client, TW9900_REG_CHIP_STATUS);
mutex_unlock(&tw9900->mutex);
pm_runtime_put(&tw9900->client->dev);
static int tw9900_check_id(struct tw9900 *tw9900,
struct device *dev = &tw9900->client->dev;
ret = pm_runtime_resume_and_get(&tw9900->client->dev);
mutex_lock(&tw9900->mutex);
mutex_unlock(&tw9900->mutex);
pm_runtime_put(&tw9900->client->dev);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
if (tw9900->reset_gpio)
gpiod_set_value_cansleep(tw9900->reset_gpio, 1);
ret = regulator_enable(tw9900->regulator);
mutex_unlock(&tw9900->mutex);
if (tw9900->reset_gpio)
gpiod_set_value_cansleep(tw9900->reset_gpio, 0);
ret = tw9900_write_array(tw9900->client, tw9900_init_regs,
mutex_unlock(&tw9900->mutex);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_lock(&tw9900->mutex);
if (tw9900->reset_gpio)
gpiod_set_value_cansleep(tw9900->reset_gpio, 1);
regulator_disable(tw9900->regulator);
mutex_unlock(&tw9900->mutex);
struct tw9900 *tw9900;
tw9900 = devm_kzalloc(dev, sizeof(*tw9900), GFP_KERNEL);
if (!tw9900)
tw9900->client = client;
tw9900->cur_mode = &supported_modes[0];
tw9900->reset_gpio = devm_gpiod_get_optional(dev, "reset",
if (IS_ERR(tw9900->reset_gpio))
return dev_err_probe(dev, PTR_ERR(tw9900->reset_gpio),
tw9900->regulator = devm_regulator_get(&tw9900->client->dev, "vdd");
if (IS_ERR(tw9900->regulator))
return dev_err_probe(dev, PTR_ERR(tw9900->regulator),
v4l2_i2c_subdev_init(&tw9900->subdev, client, &tw9900_subdev_ops);
tw9900->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
mutex_init(&tw9900->mutex);
hdl = &tw9900->hdl;
hdl->lock = &tw9900->mutex;
tw9900->subdev.ctrl_handler = hdl;
tw9900->pad.flags = MEDIA_PAD_FL_SOURCE;
tw9900->subdev.entity.function = MEDIA_ENT_F_DV_DECODER;
ret = media_entity_pads_init(&tw9900->subdev.entity, 1, &tw9900->pad);
ret = tw9900_check_id(tw9900, client);
ret = v4l2_async_register_subdev(&tw9900->subdev);
media_entity_cleanup(&tw9900->subdev.entity);
mutex_destroy(&tw9900->mutex);
struct tw9900 *tw9900 = to_tw9900(sd);
mutex_destroy(&tw9900->mutex);
#define to_tw9900(sd) container_of(sd, struct tw9900, subdev)