Lines Matching refs:state

59 static int adv748x_configure_regmap(struct adv748x_state *state, int region)  in adv748x_configure_regmap()  argument
63 if (!state->i2c_clients[region]) in adv748x_configure_regmap()
66 state->regmap[region] = in adv748x_configure_regmap()
67 devm_regmap_init_i2c(state->i2c_clients[region], in adv748x_configure_regmap()
70 if (IS_ERR(state->regmap[region])) { in adv748x_configure_regmap()
71 err = PTR_ERR(state->regmap[region]); in adv748x_configure_regmap()
72 adv_err(state, in adv748x_configure_regmap()
100 static int adv748x_read_check(struct adv748x_state *state, in adv748x_read_check() argument
103 struct i2c_client *client = state->i2c_clients[client_page]; in adv748x_read_check()
107 err = regmap_read(state->regmap[client_page], reg, &val); in adv748x_read_check()
110 adv_err(state, "error reading %02x, %02x\n", in adv748x_read_check()
118 int adv748x_read(struct adv748x_state *state, u8 page, u8 reg) in adv748x_read() argument
120 return adv748x_read_check(state, page, reg); in adv748x_read()
123 int adv748x_write(struct adv748x_state *state, u8 page, u8 reg, u8 value) in adv748x_write() argument
125 return regmap_write(state->regmap[page], reg, value); in adv748x_write()
128 static int adv748x_write_check(struct adv748x_state *state, u8 page, u8 reg, in adv748x_write_check() argument
134 *error = adv748x_write(state, page, reg, value); in adv748x_write_check()
144 int adv748x_write_block(struct adv748x_state *state, int client_page, in adv748x_write_block() argument
148 struct regmap *regmap = state->regmap[client_page]; in adv748x_write_block()
156 static int adv748x_set_slave_addresses(struct adv748x_state *state) in adv748x_set_slave_addresses() argument
164 client = state->i2c_clients[i]; in adv748x_set_slave_addresses()
166 io_write(state, io_reg, client->addr << 1); in adv748x_set_slave_addresses()
172 static void adv748x_unregister_clients(struct adv748x_state *state) in adv748x_unregister_clients() argument
176 for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) in adv748x_unregister_clients()
177 i2c_unregister_device(state->i2c_clients[i]); in adv748x_unregister_clients()
180 static int adv748x_initialise_clients(struct adv748x_state *state) in adv748x_initialise_clients() argument
186 state->i2c_clients[i] = i2c_new_ancillary_device( in adv748x_initialise_clients()
187 state->client, in adv748x_initialise_clients()
191 if (IS_ERR(state->i2c_clients[i])) { in adv748x_initialise_clients()
192 adv_err(state, "failed to create i2c client %u\n", i); in adv748x_initialise_clients()
193 return PTR_ERR(state->i2c_clients[i]); in adv748x_initialise_clients()
196 ret = adv748x_configure_regmap(state, i); in adv748x_initialise_clients()
216 static int adv748x_write_regs(struct adv748x_state *state, in adv748x_write_regs() argument
222 ret = adv748x_write(state, regs->page, regs->reg, regs->value); in adv748x_write_regs()
224 adv_err(state, "Error regs page: 0x%02x reg: 0x%02x\n", in adv748x_write_regs()
239 struct adv748x_state *state = tx->state; in adv748x_power_up_tx() local
244 adv748x_write_check(state, page, 0x00, 0x80 | tx->active_lanes, &ret); in adv748x_power_up_tx()
247 adv748x_write_check(state, page, 0x00, 0xa0 | tx->active_lanes, &ret); in adv748x_power_up_tx()
250 if (tx->src == &state->hdmi.sd) { in adv748x_power_up_tx()
251 adv748x_write_check(state, page, 0xdb, 0x10, &ret); in adv748x_power_up_tx()
252 adv748x_write_check(state, page, 0xd6, 0x07, &ret); in adv748x_power_up_tx()
254 adv748x_write_check(state, page, 0xd2, 0x40, &ret); in adv748x_power_up_tx()
257 adv748x_write_check(state, page, 0xc4, 0x0a, &ret); in adv748x_power_up_tx()
258 adv748x_write_check(state, page, 0x71, 0x33, &ret); in adv748x_power_up_tx()
259 adv748x_write_check(state, page, 0x72, 0x11, &ret); in adv748x_power_up_tx()
262 adv748x_write_check(state, page, 0xf0, 0x00, &ret); in adv748x_power_up_tx()
265 adv748x_write_check(state, page, 0x31, 0x82, &ret); in adv748x_power_up_tx()
266 adv748x_write_check(state, page, 0x1e, 0x40, &ret); in adv748x_power_up_tx()
269 adv748x_write_check(state, page, 0xda, 0x01, &ret); in adv748x_power_up_tx()
273 adv748x_write_check(state, page, 0x00, 0x20 | tx->active_lanes, &ret); in adv748x_power_up_tx()
277 adv748x_write_check(state, page, 0xc1, 0x2b, &ret); in adv748x_power_up_tx()
279 adv748x_write_check(state, page, 0x31, 0x80, &ret); in adv748x_power_up_tx()
286 struct adv748x_state *state = tx->state; in adv748x_power_down_tx() local
291 adv748x_write_check(state, page, 0x31, 0x82, &ret); in adv748x_power_down_tx()
292 adv748x_write_check(state, page, 0x1e, 0x00, &ret); in adv748x_power_down_tx()
295 adv748x_write_check(state, page, 0x00, 0x80 | tx->active_lanes, &ret); in adv748x_power_down_tx()
298 adv748x_write_check(state, page, 0xda, 0x01, &ret); in adv748x_power_down_tx()
301 adv748x_write_check(state, page, 0xc1, 0x3b, &ret); in adv748x_power_down_tx()
337 struct adv748x_state *state = v4l2_get_subdevdata(sd); in adv748x_link_setup() local
350 if (rsd == &state->afe.sd) in adv748x_link_setup()
351 state->afe.tx = enable ? tx : NULL; in adv748x_link_setup()
353 state->hdmi.tx = enable ? tx : NULL; in adv748x_link_setup()
357 if (state->afe.tx) { in adv748x_link_setup()
375 if (state->hdmi.tx) { in adv748x_link_setup()
384 return io_clrset(state, ADV748X_IO_10, io10_mask, io10); in adv748x_link_setup()
476 static int adv748x_sw_reset(struct adv748x_state *state) in adv748x_sw_reset() argument
480 ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET); in adv748x_sw_reset()
487 ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK, in adv748x_sw_reset()
493 return io_write(state, ADV748X_IO_REG_F2, in adv748x_sw_reset()
497 static int adv748x_reset(struct adv748x_state *state) in adv748x_reset() argument
502 ret = adv748x_sw_reset(state); in adv748x_reset()
506 ret = adv748x_set_slave_addresses(state); in adv748x_reset()
511 ret = adv748x_write_regs(state, adv748x_init_hdmi); in adv748x_reset()
515 ret = adv748x_write_regs(state, adv748x_init_afe); in adv748x_reset()
519 adv748x_afe_s_input(&state->afe, state->afe.input); in adv748x_reset()
521 adv_dbg(state, "AFE Default input set to %d\n", state->afe.input); in adv748x_reset()
524 adv748x_tx_power(&state->txa, 1); in adv748x_reset()
525 adv748x_tx_power(&state->txa, 0); in adv748x_reset()
526 adv748x_tx_power(&state->txb, 1); in adv748x_reset()
527 adv748x_tx_power(&state->txb, 0); in adv748x_reset()
530 io_write(state, ADV748X_IO_PD, ADV748X_IO_PD_RX_EN); in adv748x_reset()
533 if (is_tx_enabled(&state->txa)) { in adv748x_reset()
535 adv748x_csi2_set_virtual_channel(&state->txa, 0); in adv748x_reset()
537 if (is_tx_enabled(&state->txb)) { in adv748x_reset()
539 adv748x_csi2_set_virtual_channel(&state->txb, 0); in adv748x_reset()
541 io_write(state, ADV748X_IO_10, regval); in adv748x_reset()
544 cp_clrset(state, ADV748X_CP_CLMP_POS, ADV748X_CP_CLMP_POS_DIS_AUTO, in adv748x_reset()
550 static int adv748x_identify_chip(struct adv748x_state *state) in adv748x_identify_chip() argument
554 lsb = io_read(state, ADV748X_IO_CHIP_REV_ID_1); in adv748x_identify_chip()
555 msb = io_read(state, ADV748X_IO_CHIP_REV_ID_2); in adv748x_identify_chip()
558 adv_err(state, "Failed to read chip revision\n"); in adv748x_identify_chip()
562 adv_info(state, "chip found @ 0x%02x revision %02x%02x\n", in adv748x_identify_chip()
563 state->client->addr << 1, lsb, msb); in adv748x_identify_chip()
575 struct adv748x_state *state = i2c_get_clientdata(client); in adv748x_resume_early() local
577 return adv748x_reset(state); in adv748x_resume_early()
584 void adv748x_subdev_init(struct v4l2_subdev *sd, struct adv748x_state *state, in adv748x_subdev_init() argument
592 sd->owner = state->dev->driver->owner; in adv748x_subdev_init()
593 sd->dev = state->dev; in adv748x_subdev_init()
595 v4l2_set_subdevdata(sd, state); in adv748x_subdev_init()
599 state->dev->driver->name, in adv748x_subdev_init()
600 i2c_adapter_id(state->client->adapter), in adv748x_subdev_init()
601 state->client->addr, ident); in adv748x_subdev_init()
608 static int adv748x_parse_csi2_lanes(struct adv748x_state *state, in adv748x_parse_csi2_lanes() argument
627 adv_err(state, "TXA: Invalid number (%u) of lanes\n", in adv748x_parse_csi2_lanes()
632 state->txa.num_lanes = num_lanes; in adv748x_parse_csi2_lanes()
633 state->txa.active_lanes = num_lanes; in adv748x_parse_csi2_lanes()
634 adv_dbg(state, "TXA: using %u lanes\n", state->txa.num_lanes); in adv748x_parse_csi2_lanes()
639 adv_err(state, "TXB: Invalid number (%u) of lanes\n", in adv748x_parse_csi2_lanes()
644 state->txb.num_lanes = num_lanes; in adv748x_parse_csi2_lanes()
645 state->txb.active_lanes = num_lanes; in adv748x_parse_csi2_lanes()
646 adv_dbg(state, "TXB: using %u lanes\n", state->txb.num_lanes); in adv748x_parse_csi2_lanes()
652 static int adv748x_parse_dt(struct adv748x_state *state) in adv748x_parse_dt() argument
660 for_each_endpoint_of_node(state->dev->of_node, ep_np) { in adv748x_parse_dt()
662 adv_info(state, "Endpoint %pOF on port %d", ep.local_node, in adv748x_parse_dt()
666 adv_err(state, "Invalid endpoint %pOF on port %d", in adv748x_parse_dt()
672 if (state->endpoints[ep.port]) { in adv748x_parse_dt()
673 adv_err(state, in adv748x_parse_dt()
679 state->endpoints[ep.port] = ep_np; in adv748x_parse_dt()
691 ret = adv748x_parse_csi2_lanes(state, ep.port, ep_np); in adv748x_parse_dt()
699 static void adv748x_dt_cleanup(struct adv748x_state *state) in adv748x_dt_cleanup() argument
704 of_node_put(state->endpoints[i]); in adv748x_dt_cleanup()
709 struct adv748x_state *state; in adv748x_probe() local
716 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); in adv748x_probe()
717 if (!state) in adv748x_probe()
720 mutex_init(&state->mutex); in adv748x_probe()
722 state->dev = &client->dev; in adv748x_probe()
723 state->client = client; in adv748x_probe()
724 state->i2c_clients[ADV748X_PAGE_IO] = client; in adv748x_probe()
725 i2c_set_clientdata(client, state); in adv748x_probe()
732 state->txa.state = state->txb.state = state; in adv748x_probe()
733 state->txa.page = ADV748X_PAGE_TXA; in adv748x_probe()
734 state->txb.page = ADV748X_PAGE_TXB; in adv748x_probe()
735 state->txa.port = ADV748X_PORT_TXA; in adv748x_probe()
736 state->txb.port = ADV748X_PORT_TXB; in adv748x_probe()
739 ret = adv748x_parse_dt(state); in adv748x_probe()
741 adv_err(state, "Failed to parse device tree"); in adv748x_probe()
746 ret = adv748x_configure_regmap(state, ADV748X_PAGE_IO); in adv748x_probe()
748 adv_err(state, "Error configuring IO regmap region"); in adv748x_probe()
752 ret = adv748x_identify_chip(state); in adv748x_probe()
754 adv_err(state, "Failed to identify chip"); in adv748x_probe()
759 ret = adv748x_initialise_clients(state); in adv748x_probe()
761 adv_err(state, "Failed to setup client regmap pages"); in adv748x_probe()
766 ret = adv748x_reset(state); in adv748x_probe()
768 adv_err(state, "Failed to reset hardware"); in adv748x_probe()
773 ret = adv748x_hdmi_init(&state->hdmi); in adv748x_probe()
775 adv_err(state, "Failed to probe HDMI"); in adv748x_probe()
780 ret = adv748x_afe_init(&state->afe); in adv748x_probe()
782 adv_err(state, "Failed to probe AFE"); in adv748x_probe()
787 ret = adv748x_csi2_init(state, &state->txa); in adv748x_probe()
789 adv_err(state, "Failed to probe TXA"); in adv748x_probe()
794 ret = adv748x_csi2_init(state, &state->txb); in adv748x_probe()
796 adv_err(state, "Failed to probe TXB"); in adv748x_probe()
803 adv748x_csi2_cleanup(&state->txa); in adv748x_probe()
805 adv748x_afe_cleanup(&state->afe); in adv748x_probe()
807 adv748x_hdmi_cleanup(&state->hdmi); in adv748x_probe()
809 adv748x_unregister_clients(state); in adv748x_probe()
811 adv748x_dt_cleanup(state); in adv748x_probe()
813 mutex_destroy(&state->mutex); in adv748x_probe()
820 struct adv748x_state *state = i2c_get_clientdata(client); in adv748x_remove() local
822 adv748x_afe_cleanup(&state->afe); in adv748x_remove()
823 adv748x_hdmi_cleanup(&state->hdmi); in adv748x_remove()
825 adv748x_csi2_cleanup(&state->txa); in adv748x_remove()
826 adv748x_csi2_cleanup(&state->txb); in adv748x_remove()
828 adv748x_unregister_clients(state); in adv748x_remove()
829 adv748x_dt_cleanup(state); in adv748x_remove()
830 mutex_destroy(&state->mutex); in adv748x_remove()