Lines Matching +full:i2s +full:- +full:data +full:- +full:lanes
1 // SPDX-License-Identifier: GPL-2.0-or-later
9 * Boris Brezillon <boris.brezillon@free-electrons.com>
12 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. All Rights Reserved.
16 #include <linux/i2c-mux.h>
18 #include <linux/media-bus-format.h>
31 #include <sound/hdmi-codec.h>
160 (SII902X_TPI_MISC_INFOFRAME_END - SII902X_TPI_MISC_INFOFRAME_BASE)
197 union i2c_smbus_data data; in sii902x_read_unlocked() local
200 ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags, in sii902x_read_unlocked()
201 I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, &data); in sii902x_read_unlocked()
206 *val = data.byte; in sii902x_read_unlocked()
212 union i2c_smbus_data data; in sii902x_write_unlocked() local
214 data.byte = val; in sii902x_write_unlocked()
216 return __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags, in sii902x_write_unlocked()
218 &data); in sii902x_write_unlocked()
247 if (!sii902x->reset_gpio) in sii902x_reset()
250 gpiod_set_value_cansleep(sii902x->reset_gpio, 1); in sii902x_reset()
252 /* The datasheet says treset-min = 100us. Make it 150us to be sure. */ in sii902x_reset()
255 gpiod_set_value_cansleep(sii902x->reset_gpio, 0); in sii902x_reset()
262 mutex_lock(&sii902x->mutex); in sii902x_detect()
264 regmap_read(sii902x->regmap, SII902X_INT_STATUS, &status); in sii902x_detect()
266 mutex_unlock(&sii902x->mutex); in sii902x_detect()
294 mutex_lock(&sii902x->mutex); in sii902x_edid_read()
296 drm_edid = drm_edid_read_ddc(connector, sii902x->i2cmux->adapter[0]); in sii902x_edid_read()
298 mutex_unlock(&sii902x->mutex); in sii902x_edid_read()
316 sii902x->sink_is_hdmi = connector->display_info.is_hdmi; in sii902x_get_modes()
330 mutex_lock(&sii902x->mutex); in sii902x_bridge_atomic_disable()
332 regmap_update_bits(sii902x->regmap, SII902X_SYS_CTRL_DATA, in sii902x_bridge_atomic_disable()
336 mutex_unlock(&sii902x->mutex); in sii902x_bridge_atomic_disable()
344 mutex_lock(&sii902x->mutex); in sii902x_bridge_atomic_enable()
346 regmap_update_bits(sii902x->regmap, SII902X_PWR_STATE_CTRL, in sii902x_bridge_atomic_enable()
349 regmap_update_bits(sii902x->regmap, SII902X_SYS_CTRL_DATA, in sii902x_bridge_atomic_enable()
352 mutex_unlock(&sii902x->mutex); in sii902x_bridge_atomic_enable()
361 struct regmap *regmap = sii902x->regmap; in sii902x_bridge_mode_set()
364 u16 pixel_clock_10kHz = adj->clock / 10; in sii902x_bridge_mode_set()
367 if (sii902x->sink_is_hdmi) in sii902x_bridge_mode_set()
374 buf[4] = adj->hdisplay; in sii902x_bridge_mode_set()
375 buf[5] = adj->hdisplay >> 8; in sii902x_bridge_mode_set()
376 buf[6] = adj->vdisplay; in sii902x_bridge_mode_set()
377 buf[7] = adj->vdisplay >> 8; in sii902x_bridge_mode_set()
383 mutex_lock(&sii902x->mutex); in sii902x_bridge_mode_set()
385 ret = regmap_update_bits(sii902x->regmap, SII902X_SYS_CTRL_DATA, in sii902x_bridge_mode_set()
395 &sii902x->connector, adj); in sii902x_bridge_mode_set()
409 buf + HDMI_INFOFRAME_HEADER_SIZE - 1, in sii902x_bridge_mode_set()
413 mutex_unlock(&sii902x->mutex); in sii902x_bridge_mode_set()
421 struct drm_device *drm = bridge->dev; in sii902x_bridge_attach()
425 return drm_bridge_attach(bridge->encoder, sii902x->next_bridge, in sii902x_bridge_attach()
428 drm_connector_helper_add(&sii902x->connector, in sii902x_bridge_attach()
432 dev_err(&sii902x->i2c->dev, in sii902x_bridge_attach()
434 return -ENOTSUPP; in sii902x_bridge_attach()
437 ret = drm_connector_init(drm, &sii902x->connector, in sii902x_bridge_attach()
443 if (sii902x->i2c->irq > 0) in sii902x_bridge_attach()
444 sii902x->connector.polled = DRM_CONNECTOR_POLL_HPD; in sii902x_bridge_attach()
446 sii902x->connector.polled = DRM_CONNECTOR_POLL_CONNECT; in sii902x_bridge_attach()
448 ret = drm_display_info_set_bus_formats(&sii902x->connector.display_info, in sii902x_bridge_attach()
453 drm_connector_attach_encoder(&sii902x->connector, bridge->encoder); in sii902x_bridge_attach()
499 if (crtc_state->mode.clock < SII902X_MIN_PIXEL_CLOCK_KHZ || in sii902x_bridge_atomic_check()
500 crtc_state->mode.clock > SII902X_MAX_PIXEL_CLOCK_KHZ) in sii902x_bridge_atomic_check()
501 return -EINVAL; in sii902x_bridge_atomic_check()
507 bridge_state->input_bus_cfg.flags = bridge->timings->input_bus_flags; in sii902x_bridge_atomic_check()
517 if (mode->clock < SII902X_MIN_PIXEL_CLOCK_KHZ) in sii902x_bridge_mode_valid()
520 if (mode->clock > SII902X_MAX_PIXEL_CLOCK_KHZ) in sii902x_bridge_mode_valid()
543 struct device *dev = &sii902x->i2c->dev; in sii902x_mute()
549 return regmap_update_bits(sii902x->regmap, in sii902x_mute()
565 unsigned int d = abs(div - sii902x_mclk_div_table[i]); in sii902x_select_mclk_div()
594 static int sii902x_audio_hw_params(struct device *dev, void *data, in sii902x_audio_hw_params() argument
608 if (daifmt->bit_clk_provider || daifmt->frame_clk_provider) { in sii902x_audio_hw_params()
609 dev_dbg(dev, "%s: I2S clock provider mode not supported\n", in sii902x_audio_hw_params()
611 return -EINVAL; in sii902x_audio_hw_params()
614 switch (daifmt->fmt) { in sii902x_audio_hw_params()
626 dev_dbg(dev, "%s: Unsupported i2s format %u\n", __func__, in sii902x_audio_hw_params()
627 daifmt->fmt); in sii902x_audio_hw_params()
628 return -EINVAL; in sii902x_audio_hw_params()
631 if (daifmt->bit_clk_inv) in sii902x_audio_hw_params()
636 if (daifmt->frame_clk_inv) in sii902x_audio_hw_params()
641 if (params->channels > 2) in sii902x_audio_hw_params()
646 switch (params->sample_width) { in sii902x_audio_hw_params()
659 params->sample_width); in sii902x_audio_hw_params()
660 return -EINVAL; in sii902x_audio_hw_params()
664 if (params->sample_rate == sii902x_sample_freq[i].freq) { in sii902x_audio_hw_params()
670 ret = clk_prepare_enable(sii902x->audio.mclk); in sii902x_audio_hw_params()
676 if (sii902x->audio.mclk) { in sii902x_audio_hw_params()
677 mclk_rate = clk_get_rate(sii902x->audio.mclk); in sii902x_audio_hw_params()
679 params->sample_rate, mclk_rate); in sii902x_audio_hw_params()
680 if (mclk_rate != ret * params->sample_rate) in sii902x_audio_hw_params()
682 mclk_rate, ret, params->sample_rate); in sii902x_audio_hw_params()
685 mutex_lock(&sii902x->mutex); in sii902x_audio_hw_params()
687 ret = regmap_write(sii902x->regmap, in sii902x_audio_hw_params()
693 ret = regmap_write(sii902x->regmap, SII902X_TPI_I2S_INPUT_CONFIG_REG, in sii902x_audio_hw_params()
698 for (i = 0; i < ARRAY_SIZE(sii902x->audio.i2s_fifo_sequence) && in sii902x_audio_hw_params()
699 sii902x->audio.i2s_fifo_sequence[i]; i++) in sii902x_audio_hw_params()
700 regmap_write(sii902x->regmap, in sii902x_audio_hw_params()
702 sii902x->audio.i2s_fifo_sequence[i]); in sii902x_audio_hw_params()
704 ret = regmap_write(sii902x->regmap, SII902X_TPI_AUDIO_CONFIG_BYTE3_REG, in sii902x_audio_hw_params()
709 ret = regmap_bulk_write(sii902x->regmap, SII902X_TPI_I2S_STRM_HDR_BASE, in sii902x_audio_hw_params()
710 params->iec.status, in sii902x_audio_hw_params()
712 sizeof(params->iec.status))); in sii902x_audio_hw_params()
716 ret = hdmi_audio_infoframe_pack(¶ms->cea, infoframe_buf, in sii902x_audio_hw_params()
724 ret = regmap_bulk_write(sii902x->regmap, in sii902x_audio_hw_params()
732 ret = regmap_write(sii902x->regmap, SII902X_IND_SET_PAGE, 0x02); in sii902x_audio_hw_params()
736 ret = regmap_write(sii902x->regmap, SII902X_IND_OFFSET, 0x24); in sii902x_audio_hw_params()
740 ret = regmap_write(sii902x->regmap, SII902X_IND_VALUE, 0x02); in sii902x_audio_hw_params()
746 mutex_unlock(&sii902x->mutex); in sii902x_audio_hw_params()
749 clk_disable_unprepare(sii902x->audio.mclk); in sii902x_audio_hw_params()
757 static void sii902x_audio_shutdown(struct device *dev, void *data) in sii902x_audio_shutdown() argument
761 mutex_lock(&sii902x->mutex); in sii902x_audio_shutdown()
763 regmap_write(sii902x->regmap, SII902X_TPI_AUDIO_CONFIG_BYTE2_REG, in sii902x_audio_shutdown()
766 mutex_unlock(&sii902x->mutex); in sii902x_audio_shutdown()
768 clk_disable_unprepare(sii902x->audio.mclk); in sii902x_audio_shutdown()
771 static int sii902x_audio_mute(struct device *dev, void *data, in sii902x_audio_mute() argument
776 mutex_lock(&sii902x->mutex); in sii902x_audio_mute()
780 mutex_unlock(&sii902x->mutex); in sii902x_audio_mute()
785 static int sii902x_audio_get_eld(struct device *dev, void *data, in sii902x_audio_get_eld() argument
790 mutex_lock(&sii902x->mutex); in sii902x_audio_get_eld()
792 memcpy(buf, sii902x->connector.eld, in sii902x_audio_get_eld()
793 min(sizeof(sii902x->connector.eld), len)); in sii902x_audio_get_eld()
795 mutex_unlock(&sii902x->mutex); in sii902x_audio_get_eld()
817 return -EINVAL; in sii902x_audio_get_dai_id()
846 .i2s = 1, /* Only i2s support for now. */ in sii902x_audio_codec_init()
850 u8 lanes[4]; in sii902x_audio_codec_init() local
853 if (!of_property_read_bool(dev->of_node, "#sound-dai-cells")) { in sii902x_audio_codec_init()
854 dev_dbg(dev, "%s: No \"#sound-dai-cells\", no audio\n", in sii902x_audio_codec_init()
859 num_lanes = of_property_read_variable_u8_array(dev->of_node, in sii902x_audio_codec_init()
860 "sil,i2s-data-lanes", in sii902x_audio_codec_init()
861 lanes, 1, in sii902x_audio_codec_init()
862 ARRAY_SIZE(lanes)); in sii902x_audio_codec_init()
864 if (num_lanes == -EINVAL) { in sii902x_audio_codec_init()
866 "%s: No \"sil,i2s-data-lanes\", use default <0>\n", in sii902x_audio_codec_init()
869 lanes[0] = 0; in sii902x_audio_codec_init()
872 "%s: Error gettin \"sil,i2s-data-lanes\": %d\n", in sii902x_audio_codec_init()
879 sii902x->audio.i2s_fifo_sequence[i] |= audio_fifo_id[i] | in sii902x_audio_codec_init()
880 i2s_lane_id[lanes[i]] | SII902X_TPI_I2S_FIFO_ENABLE; in sii902x_audio_codec_init()
882 sii902x->audio.mclk = devm_clk_get_optional(dev, "mclk"); in sii902x_audio_codec_init()
883 if (IS_ERR(sii902x->audio.mclk)) { in sii902x_audio_codec_init()
885 __func__, PTR_ERR(sii902x->audio.mclk)); in sii902x_audio_codec_init()
886 return PTR_ERR(sii902x->audio.mclk); in sii902x_audio_codec_init()
889 sii902x->audio.pdev = platform_device_register_data( in sii902x_audio_codec_init()
893 return PTR_ERR_OR_ZERO(sii902x->audio.pdev); in sii902x_audio_codec_init()
914 static irqreturn_t sii902x_interrupt(int irq, void *data) in sii902x_interrupt() argument
916 struct sii902x *sii902x = data; in sii902x_interrupt()
919 mutex_lock(&sii902x->mutex); in sii902x_interrupt()
921 regmap_read(sii902x->regmap, SII902X_INT_STATUS, &status); in sii902x_interrupt()
922 regmap_write(sii902x->regmap, SII902X_INT_STATUS, status); in sii902x_interrupt()
924 mutex_unlock(&sii902x->mutex); in sii902x_interrupt()
926 if ((status & SII902X_HOTPLUG_EVENT) && sii902x->bridge.dev) { in sii902x_interrupt()
927 drm_helper_hpd_irq_event(sii902x->bridge.dev); in sii902x_interrupt()
928 drm_bridge_hpd_notify(&sii902x->bridge, (status & SII902X_PLUGGED_STATUS) in sii902x_interrupt()
951 struct device *dev = &sii902x->i2c->dev; in sii902x_i2c_bypass_select()
956 ret = sii902x_update_bits_unlocked(sii902x->i2c, SII902X_SYS_CTRL_DATA, in sii902x_i2c_bypass_select()
965 ret = sii902x_read_unlocked(sii902x->i2c, SII902X_SYS_CTRL_DATA, in sii902x_i2c_bypass_select()
974 return -ETIMEDOUT; in sii902x_i2c_bypass_select()
977 return sii902x_write_unlocked(sii902x->i2c, SII902X_SYS_CTRL_DATA, in sii902x_i2c_bypass_select()
996 struct device *dev = &sii902x->i2c->dev; in sii902x_i2c_bypass_deselect()
1016 ret = sii902x_read_unlocked(sii902x->i2c, SII902X_SYS_CTRL_DATA, in sii902x_i2c_bypass_deselect()
1018 retries--; in sii902x_i2c_bypass_deselect()
1025 ret = sii902x_update_bits_unlocked(sii902x->i2c, SII902X_SYS_CTRL_DATA, in sii902x_i2c_bypass_deselect()
1034 ret = sii902x_read_unlocked(sii902x->i2c, SII902X_SYS_CTRL_DATA, in sii902x_i2c_bypass_deselect()
1045 return -ETIMEDOUT; in sii902x_i2c_bypass_deselect()
1059 struct device *dev = &sii902x->i2c->dev; in sii902x_init()
1066 ret = regmap_write(sii902x->regmap, SII902X_REG_TPI_RQB, 0x0); in sii902x_init()
1070 ret = regmap_bulk_read(sii902x->regmap, SII902X_REG_CHIPID(0), in sii902x_init()
1080 return -EINVAL; in sii902x_init()
1084 regmap_read(sii902x->regmap, SII902X_INT_STATUS, &status); in sii902x_init()
1085 regmap_write(sii902x->regmap, SII902X_INT_STATUS, status); in sii902x_init()
1087 if (sii902x->i2c->irq > 0) { in sii902x_init()
1088 regmap_write(sii902x->regmap, SII902X_INT_ENABLE, in sii902x_init()
1091 ret = devm_request_threaded_irq(dev, sii902x->i2c->irq, NULL, in sii902x_init()
1103 i2c_set_clientdata(sii902x->i2c, sii902x); in sii902x_init()
1105 sii902x->i2cmux = i2c_mux_alloc(sii902x->i2c->adapter, dev, in sii902x_init()
1109 if (!sii902x->i2cmux) { in sii902x_init()
1110 ret = -ENOMEM; in sii902x_init()
1114 sii902x->i2cmux->priv = sii902x; in sii902x_init()
1115 ret = i2c_mux_add_adapter(sii902x->i2cmux, 0, 0); in sii902x_init()
1119 sii902x->bridge.funcs = &sii902x_bridge_funcs; in sii902x_init()
1120 sii902x->bridge.of_node = dev->of_node; in sii902x_init()
1121 sii902x->bridge.timings = &default_sii902x_timings; in sii902x_init()
1122 sii902x->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID; in sii902x_init()
1124 if (sii902x->i2c->irq > 0) in sii902x_init()
1125 sii902x->bridge.ops |= DRM_BRIDGE_OP_HPD; in sii902x_init()
1127 drm_bridge_add(&sii902x->bridge); in sii902x_init()
1132 if (!PTR_ERR_OR_ZERO(sii902x->audio.pdev)) in sii902x_init()
1133 platform_device_unregister(sii902x->audio.pdev); in sii902x_init()
1140 struct device *dev = &client->dev; in sii902x_probe()
1146 ret = i2c_check_functionality(client->adapter, in sii902x_probe()
1150 return -EIO; in sii902x_probe()
1155 return -ENOMEM; in sii902x_probe()
1157 sii902x->i2c = client; in sii902x_probe()
1158 sii902x->regmap = devm_regmap_init_i2c(client, &sii902x_regmap_config); in sii902x_probe()
1159 if (IS_ERR(sii902x->regmap)) in sii902x_probe()
1160 return PTR_ERR(sii902x->regmap); in sii902x_probe()
1162 sii902x->reset_gpio = devm_gpiod_get_optional(dev, "reset", in sii902x_probe()
1164 if (IS_ERR(sii902x->reset_gpio)) { in sii902x_probe()
1166 PTR_ERR(sii902x->reset_gpio)); in sii902x_probe()
1167 return PTR_ERR(sii902x->reset_gpio); in sii902x_probe()
1170 endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 1, -1); in sii902x_probe()
1177 return -ENODEV; in sii902x_probe()
1183 return -ENODEV; in sii902x_probe()
1186 sii902x->next_bridge = of_drm_find_bridge(remote); in sii902x_probe()
1188 if (!sii902x->next_bridge) in sii902x_probe()
1189 return dev_err_probe(dev, -EPROBE_DEFER, in sii902x_probe()
1193 mutex_init(&sii902x->mutex); in sii902x_probe()
1206 drm_bridge_remove(&sii902x->bridge); in sii902x_remove()
1207 i2c_mux_del_adapters(sii902x->i2cmux); in sii902x_remove()
1209 if (!PTR_ERR_OR_ZERO(sii902x->audio.pdev)) in sii902x_remove()
1210 platform_device_unregister(sii902x->audio.pdev); in sii902x_remove()
1236 MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>");
1237 MODULE_DESCRIPTION("SII902x RGB -> HDMI bridges");