Lines Matching +full:aux +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0
134 * struct ti_sn65dsi86 - Platform data for ti-sn65dsi86 driver.
135 * @bridge_aux: AUX-bus sub device for MIPI-to-eDP bridge functionality.
136 * @gpio_aux: AUX-bus sub device for GPIO controller functionality.
137 * @aux_aux: AUX-bus sub device for eDP AUX channel functionality.
138 * @pwm_aux: AUX-bus sub device for PWM controller functionality.
142 * @aux: Our aux channel.
153 * @ln_polrs: Value for the 4-bit LN_POLRS field of SN_ENH_FRAME_REG.
154 * @comms_enabled: If true then communication over the aux channel is enabled.
159 * serves double-duty of keeping track of the direction and
165 * each other's read-modify-write.
180 struct drm_dp_aux aux; member
230 ret = regmap_bulk_read(pdata->regmap, reg, buf, ARRAY_SIZE(buf)); in ti_sn65dsi86_read_u16()
244 regmap_bulk_write(pdata->regmap, reg, buf, ARRAY_SIZE(buf)); in ti_sn65dsi86_write_u16()
251 &pdata->bridge.encoder->crtc->state->adjusted_mode; in ti_sn_bridge_get_dsi_freq()
253 bit_rate_khz = mode->clock * in ti_sn_bridge_get_dsi_freq()
254 mipi_dsi_pixel_format_to_bpp(pdata->dsi->format); in ti_sn_bridge_get_dsi_freq()
255 clk_freq_khz = bit_rate_khz / (pdata->dsi->lanes * 2); in ti_sn_bridge_get_dsi_freq()
285 if (pdata->refclk) { in ti_sn_bridge_set_refclk_freq()
286 refclk_rate = clk_get_rate(pdata->refclk); in ti_sn_bridge_set_refclk_freq()
289 clk_prepare_enable(pdata->refclk); in ti_sn_bridge_set_refclk_freq()
301 regmap_update_bits(pdata->regmap, SN_DPPLL_SRC_REG, REFCLK_FREQ_MASK, in ti_sn_bridge_set_refclk_freq()
308 pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; in ti_sn_bridge_set_refclk_freq()
313 mutex_lock(&pdata->comms_mutex); in ti_sn65dsi86_enable_comms()
323 * voltage, and temperate--I measured it at about 200 ms). One in ti_sn65dsi86_enable_comms()
334 regmap_update_bits(pdata->regmap, SN_HPD_DISABLE_REG, HPD_DISABLE, in ti_sn65dsi86_enable_comms()
337 pdata->comms_enabled = true; in ti_sn65dsi86_enable_comms()
339 mutex_unlock(&pdata->comms_mutex); in ti_sn65dsi86_enable_comms()
344 mutex_lock(&pdata->comms_mutex); in ti_sn65dsi86_disable_comms()
346 pdata->comms_enabled = false; in ti_sn65dsi86_disable_comms()
347 clk_disable_unprepare(pdata->refclk); in ti_sn65dsi86_disable_comms()
349 mutex_unlock(&pdata->comms_mutex); in ti_sn65dsi86_disable_comms()
357 ret = regulator_bulk_enable(SN_REGULATOR_SUPPLY_NUM, pdata->supplies); in ti_sn65dsi86_resume()
366 gpiod_set_value(pdata->enable_gpio, 1); in ti_sn65dsi86_resume()
370 * panel (including the aux channel) w/out any need for an input clock in ti_sn65dsi86_resume()
375 if (pdata->refclk) in ti_sn65dsi86_resume()
386 if (pdata->refclk) in ti_sn65dsi86_suspend()
389 gpiod_set_value(pdata->enable_gpio, 0); in ti_sn65dsi86_suspend()
391 ret = regulator_bulk_disable(SN_REGULATOR_SUPPLY_NUM, pdata->supplies); in ti_sn65dsi86_suspend()
406 struct ti_sn65dsi86 *pdata = s->private; in status_show()
411 pm_runtime_get_sync(pdata->dev); in status_show()
415 regmap_read(pdata->regmap, reg, &val); in status_show()
419 pm_runtime_put_autosuspend(pdata->dev); in status_show()
433 struct device *dev = pdata->dev; in ti_sn65dsi86_debugfs_init()
453 /* -----------------------------------------------------------------------------
454 * Auxiliary Devices (*not* AUX)
468 * AUX bus docs say that a non-NULL release is mandatory, but it makes no
469 * sense for the model used here where all of the aux devices are allocated
475 struct auxiliary_device *aux, in ti_sn65dsi86_add_aux_device() argument
478 struct device *dev = pdata->dev; in ti_sn65dsi86_add_aux_device()
481 aux->name = name; in ti_sn65dsi86_add_aux_device()
482 aux->dev.parent = dev; in ti_sn65dsi86_add_aux_device()
483 aux->dev.release = ti_sn65dsi86_noop; in ti_sn65dsi86_add_aux_device()
484 device_set_of_node_from_dev(&aux->dev, dev); in ti_sn65dsi86_add_aux_device()
485 ret = auxiliary_device_init(aux); in ti_sn65dsi86_add_aux_device()
488 ret = devm_add_action_or_reset(dev, ti_sn65dsi86_uninit_aux, aux); in ti_sn65dsi86_add_aux_device()
492 ret = auxiliary_device_add(aux); in ti_sn65dsi86_add_aux_device()
495 ret = devm_add_action_or_reset(dev, ti_sn65dsi86_delete_aux, aux); in ti_sn65dsi86_add_aux_device()
500 /* -----------------------------------------------------------------------------
501 * AUX Adapter
504 static struct ti_sn65dsi86 *aux_to_ti_sn65dsi86(struct drm_dp_aux *aux) in aux_to_ti_sn65dsi86() argument
506 return container_of(aux, struct ti_sn65dsi86, aux); in aux_to_ti_sn65dsi86()
509 static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, in ti_sn_aux_transfer() argument
512 struct ti_sn65dsi86 *pdata = aux_to_ti_sn65dsi86(aux); in ti_sn_aux_transfer()
513 u32 request = msg->request & ~(DP_AUX_I2C_MOT | DP_AUX_I2C_WRITE_STATUS_UPDATE); in ti_sn_aux_transfer()
514 u32 request_val = AUX_CMD_REQ(msg->request); in ti_sn_aux_transfer()
515 u8 *buf = msg->buffer; in ti_sn_aux_transfer()
516 unsigned int len = msg->size; in ti_sn_aux_transfer()
519 u8 addr_len[SN_AUX_LENGTH_REG + 1 - SN_AUX_ADDR_19_16_REG]; in ti_sn_aux_transfer()
522 return -EINVAL; in ti_sn_aux_transfer()
524 pm_runtime_get_sync(pdata->dev); in ti_sn_aux_transfer()
525 mutex_lock(&pdata->comms_mutex); in ti_sn_aux_transfer()
528 * If someone tries to do a DDC over AUX transaction before pre_enable() in ti_sn_aux_transfer()
530 * do it. Fail right away. This prevents non-refclk users from reading in ti_sn_aux_transfer()
533 if (!pdata->comms_enabled) { in ti_sn_aux_transfer()
534 ret = -EIO; in ti_sn_aux_transfer()
543 regmap_write(pdata->regmap, SN_AUX_CMD_REG, request_val); in ti_sn_aux_transfer()
545 msg->reply = 0; in ti_sn_aux_transfer()
548 ret = -EINVAL; in ti_sn_aux_transfer()
553 put_unaligned_be32((msg->address & SN_AUX_ADDR_MASK) << 8 | len, in ti_sn_aux_transfer()
555 regmap_bulk_write(pdata->regmap, SN_AUX_ADDR_19_16_REG, addr_len, in ti_sn_aux_transfer()
559 regmap_bulk_write(pdata->regmap, SN_AUX_WDATA_REG(0), buf, len); in ti_sn_aux_transfer()
562 regmap_write(pdata->regmap, SN_AUX_CMD_STATUS_REG, in ti_sn_aux_transfer()
567 regmap_write(pdata->regmap, SN_AUX_CMD_REG, request_val | AUX_CMD_SEND); in ti_sn_aux_transfer()
570 ret = regmap_read_poll_timeout(pdata->regmap, SN_AUX_CMD_REG, val, in ti_sn_aux_transfer()
575 ret = regmap_read(pdata->regmap, SN_AUX_CMD_STATUS_REG, &val); in ti_sn_aux_transfer()
585 ret = -ETIMEDOUT; in ti_sn_aux_transfer()
590 ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &len); in ti_sn_aux_transfer()
597 msg->reply |= DP_AUX_I2C_REPLY_NACK; in ti_sn_aux_transfer()
601 msg->reply |= DP_AUX_NATIVE_REPLY_NACK; in ti_sn_aux_transfer()
609 ret = regmap_bulk_read(pdata->regmap, SN_AUX_RDATA_REG(0), buf, len); in ti_sn_aux_transfer()
612 mutex_unlock(&pdata->comms_mutex); in ti_sn_aux_transfer()
613 pm_runtime_mark_last_busy(pdata->dev); in ti_sn_aux_transfer()
614 pm_runtime_put_autosuspend(pdata->dev); in ti_sn_aux_transfer()
624 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_aux_probe()
627 pdata->aux.name = "ti-sn65dsi86-aux"; in ti_sn_aux_probe()
628 pdata->aux.dev = &adev->dev; in ti_sn_aux_probe()
629 pdata->aux.transfer = ti_sn_aux_transfer; in ti_sn_aux_probe()
630 drm_dp_aux_init(&pdata->aux); in ti_sn_aux_probe()
632 ret = devm_of_dp_aux_populate_ep_devices(&pdata->aux); in ti_sn_aux_probe()
637 * The eDP to MIPI bridge parts don't work until the AUX channel is in ti_sn_aux_probe()
640 return ti_sn65dsi86_add_aux_device(pdata, &pdata->bridge_aux, "bridge"); in ti_sn_aux_probe()
644 { .name = "ti_sn65dsi86.aux", },
649 .name = "aux",
654 /*------------------------------------------------------------------------------
668 struct device *dev = pdata->dev; in ti_sn_attach_host()
674 host = of_find_mipi_dsi_host_by_node(pdata->host_node); in ti_sn_attach_host()
676 return -EPROBE_DEFER; in ti_sn_attach_host()
683 dsi->lanes = 4; in ti_sn_attach_host()
684 dsi->format = MIPI_DSI_FMT_RGB888; in ti_sn_attach_host()
685 dsi->mode_flags = MIPI_DSI_MODE_VIDEO; in ti_sn_attach_host()
689 regmap_read(pdata->regmap, SN_DPPLL_SRC_REG, &val); in ti_sn_attach_host()
692 dsi->mode_flags |= MIPI_DSI_CLOCK_NON_CONTINUOUS; in ti_sn_attach_host()
694 pdata->dsi = dsi; in ti_sn_attach_host()
705 pdata->aux.drm_dev = bridge->dev; in ti_sn_bridge_attach()
706 ret = drm_dp_aux_register(&pdata->aux); in ti_sn_bridge_attach()
708 drm_err(bridge->dev, "Failed to register DP AUX channel: %d\n", ret); in ti_sn_bridge_attach()
716 ret = drm_bridge_attach(bridge->encoder, pdata->next_bridge, in ti_sn_bridge_attach()
717 &pdata->bridge, flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR); in ti_sn_bridge_attach()
724 pdata->connector = drm_bridge_connector_init(pdata->bridge.dev, in ti_sn_bridge_attach()
725 pdata->bridge.encoder); in ti_sn_bridge_attach()
726 if (IS_ERR(pdata->connector)) { in ti_sn_bridge_attach()
727 ret = PTR_ERR(pdata->connector); in ti_sn_bridge_attach()
731 drm_connector_attach_encoder(pdata->connector, pdata->bridge.encoder); in ti_sn_bridge_attach()
736 drm_dp_aux_unregister(&pdata->aux); in ti_sn_bridge_attach()
742 drm_dp_aux_unregister(&bridge_to_ti_sn65dsi86(bridge)->aux); in ti_sn_bridge_detach()
751 if (mode->clock > 594000) in ti_sn_bridge_mode_valid()
759 if ((mode->hsync_start - mode->hdisplay) > 0xff) in ti_sn_bridge_mode_valid()
762 if ((mode->vsync_start - mode->vdisplay) > 0xff) in ti_sn_bridge_mode_valid()
765 if ((mode->hsync_end - mode->hsync_start) > 0x7fff) in ti_sn_bridge_mode_valid()
768 if ((mode->vsync_end - mode->vsync_start) > 0x7fff) in ti_sn_bridge_mode_valid()
771 if ((mode->htotal - mode->hsync_end) > 0xff) in ti_sn_bridge_mode_valid()
774 if ((mode->vtotal - mode->vsync_end) > 0xff) in ti_sn_bridge_mode_valid()
786 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, 0); in ti_sn_bridge_atomic_disable()
794 &pdata->bridge.encoder->crtc->state->adjusted_mode; in ti_sn_bridge_set_dsi_rate()
797 bit_rate_mhz = (mode->clock / 1000) * in ti_sn_bridge_set_dsi_rate()
798 mipi_dsi_pixel_format_to_bpp(pdata->dsi->format); in ti_sn_bridge_set_dsi_rate()
799 clk_freq_mhz = bit_rate_mhz / (pdata->dsi->lanes * 2); in ti_sn_bridge_set_dsi_rate()
803 (((clk_freq_mhz - MIN_DSI_CLK_FREQ_MHZ) / 5) & 0xFF); in ti_sn_bridge_set_dsi_rate()
804 regmap_write(pdata->regmap, SN_DSIA_CLK_FREQ_REG, val); in ti_sn_bridge_set_dsi_rate()
809 if (connector->display_info.bpc <= 6) in ti_sn_bridge_get_bpp()
829 &pdata->bridge.encoder->crtc->state->adjusted_mode; in ti_sn_bridge_calc_min_dp_rate_idx()
832 bit_rate_khz = mode->clock * bpp; in ti_sn_bridge_calc_min_dp_rate_idx()
836 1000 * pdata->dp_lanes * DP_CLK_FUDGE_DEN); in ti_sn_bridge_calc_min_dp_rate_idx()
838 for (i = 1; i < ARRAY_SIZE(ti_sn_bridge_dp_rate_lut) - 1; i++) in ti_sn_bridge_calc_min_dp_rate_idx()
854 ret = drm_dp_dpcd_readb(&pdata->aux, DP_EDP_DPCD_REV, &dpcd_val); in ti_sn_bridge_read_valid_rates()
856 DRM_DEV_ERROR(pdata->dev, in ti_sn_bridge_read_valid_rates()
865 ret = drm_dp_dpcd_read(&pdata->aux, DP_SUPPORTED_LINK_RATES, in ti_sn_bridge_read_valid_rates()
869 DRM_DEV_ERROR(pdata->dev, in ti_sn_bridge_read_valid_rates()
895 DRM_DEV_ERROR(pdata->dev, in ti_sn_bridge_read_valid_rates()
900 ret = drm_dp_dpcd_readb(&pdata->aux, DP_MAX_LINK_RATE, &dpcd_val); in ti_sn_bridge_read_valid_rates()
902 DRM_DEV_ERROR(pdata->dev, in ti_sn_bridge_read_valid_rates()
910 DRM_DEV_ERROR(pdata->dev, in ti_sn_bridge_read_valid_rates()
931 &pdata->bridge.encoder->crtc->state->adjusted_mode; in ti_sn_bridge_set_video_timings()
934 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in ti_sn_bridge_set_video_timings()
936 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in ti_sn_bridge_set_video_timings()
940 mode->hdisplay); in ti_sn_bridge_set_video_timings()
942 mode->vdisplay); in ti_sn_bridge_set_video_timings()
943 regmap_write(pdata->regmap, SN_CHA_HSYNC_PULSE_WIDTH_LOW_REG, in ti_sn_bridge_set_video_timings()
944 (mode->hsync_end - mode->hsync_start) & 0xFF); in ti_sn_bridge_set_video_timings()
945 regmap_write(pdata->regmap, SN_CHA_HSYNC_PULSE_WIDTH_HIGH_REG, in ti_sn_bridge_set_video_timings()
946 (((mode->hsync_end - mode->hsync_start) >> 8) & 0x7F) | in ti_sn_bridge_set_video_timings()
948 regmap_write(pdata->regmap, SN_CHA_VSYNC_PULSE_WIDTH_LOW_REG, in ti_sn_bridge_set_video_timings()
949 (mode->vsync_end - mode->vsync_start) & 0xFF); in ti_sn_bridge_set_video_timings()
950 regmap_write(pdata->regmap, SN_CHA_VSYNC_PULSE_WIDTH_HIGH_REG, in ti_sn_bridge_set_video_timings()
951 (((mode->vsync_end - mode->vsync_start) >> 8) & 0x7F) | in ti_sn_bridge_set_video_timings()
954 regmap_write(pdata->regmap, SN_CHA_HORIZONTAL_BACK_PORCH_REG, in ti_sn_bridge_set_video_timings()
955 (mode->htotal - mode->hsync_end) & 0xFF); in ti_sn_bridge_set_video_timings()
956 regmap_write(pdata->regmap, SN_CHA_VERTICAL_BACK_PORCH_REG, in ti_sn_bridge_set_video_timings()
957 (mode->vtotal - mode->vsync_end) & 0xFF); in ti_sn_bridge_set_video_timings()
959 regmap_write(pdata->regmap, SN_CHA_HORIZONTAL_FRONT_PORCH_REG, in ti_sn_bridge_set_video_timings()
960 (mode->hsync_start - mode->hdisplay) & 0xFF); in ti_sn_bridge_set_video_timings()
961 regmap_write(pdata->regmap, SN_CHA_VERTICAL_FRONT_PORCH_REG, in ti_sn_bridge_set_video_timings()
962 (mode->vsync_start - mode->vdisplay) & 0xFF); in ti_sn_bridge_set_video_timings()
972 ret = drm_dp_dpcd_readb(&pdata->aux, DP_MAX_LANE_COUNT, &data); in ti_sn_get_max_lanes()
974 DRM_DEV_ERROR(pdata->dev, in ti_sn_get_max_lanes()
990 regmap_update_bits(pdata->regmap, SN_DATARATE_CONFIG_REG, in ti_sn_link_training()
994 regmap_write(pdata->regmap, SN_PLL_ENABLE_REG, 1); in ti_sn_link_training()
996 ret = regmap_read_poll_timeout(pdata->regmap, SN_DPPLL_SRC_REG, val, in ti_sn_link_training()
1012 regmap_write(pdata->regmap, SN_ML_TX_MODE_REG, 0x0A); in ti_sn_link_training()
1013 ret = regmap_read_poll_timeout(pdata->regmap, SN_ML_TX_MODE_REG, val, in ti_sn_link_training()
1021 ret = -EIO; in ti_sn_link_training()
1030 DRM_DEV_INFO(pdata->dev, "Link training needed %d retries\n", i); in ti_sn_link_training()
1035 regmap_write(pdata->regmap, SN_PLL_ENABLE_REG, 0); in ti_sn_link_training()
1049 int ret = -EINVAL; in ti_sn_bridge_atomic_enable()
1053 connector = drm_atomic_get_new_connector_for_encoder(old_bridge_state->base.state, in ti_sn_bridge_atomic_enable()
1054 bridge->encoder); in ti_sn_bridge_atomic_enable()
1056 dev_err_ratelimited(pdata->dev, "Could not get the connector\n"); in ti_sn_bridge_atomic_enable()
1061 pdata->dp_lanes = min(pdata->dp_lanes, max_dp_lanes); in ti_sn_bridge_atomic_enable()
1064 val = CHA_DSI_LANES(SN_MAX_DP_LANES - pdata->dsi->lanes); in ti_sn_bridge_atomic_enable()
1065 regmap_update_bits(pdata->regmap, SN_DSI_LANES_REG, in ti_sn_bridge_atomic_enable()
1068 regmap_write(pdata->regmap, SN_LN_ASSIGN_REG, pdata->ln_assign); in ti_sn_bridge_atomic_enable()
1069 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, LN_POLRS_MASK, in ti_sn_bridge_atomic_enable()
1070 pdata->ln_polrs << LN_POLRS_OFFSET); in ti_sn_bridge_atomic_enable()
1084 if (pdata->bridge.type == DRM_MODE_CONNECTOR_eDP) { in ti_sn_bridge_atomic_enable()
1085 drm_dp_dpcd_writeb(&pdata->aux, DP_EDP_CONFIGURATION_SET, in ti_sn_bridge_atomic_enable()
1088 regmap_update_bits(pdata->regmap, SN_TRAINING_SETTING_REG, in ti_sn_bridge_atomic_enable()
1091 regmap_update_bits(pdata->regmap, SN_TRAINING_SETTING_REG, in ti_sn_bridge_atomic_enable()
1098 regmap_update_bits(pdata->regmap, SN_DATA_FORMAT_REG, BPP_18_RGB, val); in ti_sn_bridge_atomic_enable()
1101 val = DP_NUM_LANES(min(pdata->dp_lanes, 3)); in ti_sn_bridge_atomic_enable()
1102 regmap_update_bits(pdata->regmap, SN_SSC_CONFIG_REG, DP_NUM_LANES_MASK, in ti_sn_bridge_atomic_enable()
1119 DRM_DEV_ERROR(pdata->dev, "%s (%d)\n", last_err_str, ret); in ti_sn_bridge_atomic_enable()
1127 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, in ti_sn_bridge_atomic_enable()
1136 pm_runtime_get_sync(pdata->dev); in ti_sn_bridge_atomic_pre_enable()
1138 if (!pdata->refclk) in ti_sn_bridge_atomic_pre_enable()
1151 regmap_write(pdata->regmap, SN_ML_TX_MODE_REG, 0); in ti_sn_bridge_atomic_post_disable()
1153 regmap_update_bits(pdata->regmap, SN_SSC_CONFIG_REG, DP_NUM_LANES_MASK, 0); in ti_sn_bridge_atomic_post_disable()
1155 regmap_write(pdata->regmap, SN_PLL_ENABLE_REG, 0); in ti_sn_bridge_atomic_post_disable()
1157 if (!pdata->refclk) in ti_sn_bridge_atomic_post_disable()
1160 pm_runtime_put_sync(pdata->dev); in ti_sn_bridge_atomic_post_disable()
1168 pm_runtime_get_sync(pdata->dev); in ti_sn_bridge_detect()
1169 regmap_read(pdata->regmap, SN_HPD_DISABLE_REG, &val); in ti_sn_bridge_detect()
1170 pm_runtime_put_autosuspend(pdata->dev); in ti_sn_bridge_detect()
1181 return drm_get_edid(connector, &pdata->aux.ddc); in ti_sn_bridge_get_edid()
1214 * data-lanes but not lane-polarities but not vice versa. in ti_sn_bridge_parse_lanes()
1220 endpoint = of_graph_get_endpoint_by_regs(np, 1, -1); in ti_sn_bridge_parse_lanes()
1223 of_property_read_u32_array(endpoint, "data-lanes", in ti_sn_bridge_parse_lanes()
1225 of_property_read_u32_array(endpoint, "lane-polarities", in ti_sn_bridge_parse_lanes()
1234 * data-lanes had fewer elements so that we nicely initialize in ti_sn_bridge_parse_lanes()
1237 for (i = SN_MAX_DP_LANES - 1; i >= 0; i--) { in ti_sn_bridge_parse_lanes()
1243 pdata->dp_lanes = dp_lanes; in ti_sn_bridge_parse_lanes()
1244 pdata->ln_assign = ln_assign; in ti_sn_bridge_parse_lanes()
1245 pdata->ln_polrs = ln_polrs; in ti_sn_bridge_parse_lanes()
1250 struct device_node *np = pdata->dev->of_node; in ti_sn_bridge_parse_dsi_host()
1252 pdata->host_node = of_graph_get_remote_node(np, 0, 0); in ti_sn_bridge_parse_dsi_host()
1254 if (!pdata->host_node) { in ti_sn_bridge_parse_dsi_host()
1256 return -ENODEV; in ti_sn_bridge_parse_dsi_host()
1265 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_bridge_probe()
1266 struct device_node *np = pdata->dev->of_node; in ti_sn_bridge_probe()
1269 pdata->next_bridge = devm_drm_of_get_bridge(pdata->dev, np, 1, 0); in ti_sn_bridge_probe()
1270 if (IS_ERR(pdata->next_bridge)) in ti_sn_bridge_probe()
1271 return dev_err_probe(pdata->dev, PTR_ERR(pdata->next_bridge), in ti_sn_bridge_probe()
1280 pdata->bridge.funcs = &ti_sn_bridge_funcs; in ti_sn_bridge_probe()
1281 pdata->bridge.of_node = np; in ti_sn_bridge_probe()
1282 pdata->bridge.type = pdata->next_bridge->type == DRM_MODE_CONNECTOR_DisplayPort in ti_sn_bridge_probe()
1285 if (pdata->bridge.type == DRM_MODE_CONNECTOR_DisplayPort) in ti_sn_bridge_probe()
1286 pdata->bridge.ops = DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_DETECT; in ti_sn_bridge_probe()
1288 drm_bridge_add(&pdata->bridge); in ti_sn_bridge_probe()
1292 dev_err_probe(pdata->dev, ret, "failed to attach dsi host\n"); in ti_sn_bridge_probe()
1299 drm_bridge_remove(&pdata->bridge); in ti_sn_bridge_probe()
1305 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_bridge_remove()
1310 drm_bridge_remove(&pdata->bridge); in ti_sn_bridge_remove()
1312 of_node_put(pdata->host_node); in ti_sn_bridge_remove()
1327 /* -----------------------------------------------------------------------------
1333 return atomic_xchg(&pdata->pwm_pin_busy, 1) ? -EBUSY : 0; in ti_sn_pwm_pin_request()
1338 atomic_set(&pdata->pwm_pin_busy, 0); in ti_sn_pwm_pin_release()
1362 * - The PWM signal is not driven when the chip is powered down, or in its
1364 * described in the documentation. In order to save power, state->enabled is
1367 * - Changing both period and duty_cycle is not done atomically, neither is the
1368 * multi-byte register updates, so the output might briefly be undefined
1383 if (!pdata->pwm_enabled) { in ti_sn_pwm_apply()
1384 ret = pm_runtime_get_sync(pdata->dev); in ti_sn_pwm_apply()
1386 pm_runtime_put_sync(pdata->dev); in ti_sn_pwm_apply()
1391 if (state->enabled) { in ti_sn_pwm_apply()
1392 if (!pdata->pwm_enabled) { in ti_sn_pwm_apply()
1398 ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG, in ti_sn_pwm_apply()
1402 dev_err(pdata->dev, "failed to mux in PWM function\n"); in ti_sn_pwm_apply()
1411 * PWM_FREQ = ----------------------------------- in ti_sn_pwm_apply()
1426 * PWM_PRE_DIV >= ------------------------- in ti_sn_pwm_apply()
1435 * BACKLIGHT_SCALE = ---------------------- - 1 in ti_sn_pwm_apply()
1443 if (state->period <= NSEC_PER_SEC / pdata->pwm_refclk_freq) { in ti_sn_pwm_apply()
1444 ret = -EINVAL; in ti_sn_pwm_apply()
1453 pdata->pwm_refclk_freq); in ti_sn_pwm_apply()
1454 period = min(state->period, period_max); in ti_sn_pwm_apply()
1456 pre_div = DIV64_U64_ROUND_UP(period * pdata->pwm_refclk_freq, in ti_sn_pwm_apply()
1458 scale = div64_u64(period * pdata->pwm_refclk_freq, (u64)NSEC_PER_SEC * pre_div) - 1; in ti_sn_pwm_apply()
1464 * ------- = --------------------- in ti_sn_pwm_apply()
1471 backlight = div64_u64(state->duty_cycle * pdata->pwm_refclk_freq, in ti_sn_pwm_apply()
1476 ret = regmap_write(pdata->regmap, SN_PWM_PRE_DIV_REG, pre_div); in ti_sn_pwm_apply()
1478 dev_err(pdata->dev, "failed to update PWM_PRE_DIV\n"); in ti_sn_pwm_apply()
1486 pwm_en_inv = FIELD_PREP(SN_PWM_EN_MASK, state->enabled) | in ti_sn_pwm_apply()
1487 FIELD_PREP(SN_PWM_INV_MASK, state->polarity == PWM_POLARITY_INVERSED); in ti_sn_pwm_apply()
1488 ret = regmap_write(pdata->regmap, SN_PWM_EN_INV_REG, pwm_en_inv); in ti_sn_pwm_apply()
1490 dev_err(pdata->dev, "failed to update PWM_EN/PWM_INV\n"); in ti_sn_pwm_apply()
1494 pdata->pwm_enabled = state->enabled; in ti_sn_pwm_apply()
1497 if (!pdata->pwm_enabled) in ti_sn_pwm_apply()
1498 pm_runtime_put_sync(pdata->dev); in ti_sn_pwm_apply()
1513 ret = regmap_read(pdata->regmap, SN_PWM_EN_INV_REG, &pwm_en_inv); in ti_sn_pwm_get_state()
1525 ret = regmap_read(pdata->regmap, SN_PWM_PRE_DIV_REG, &pre_div); in ti_sn_pwm_get_state()
1529 state->enabled = FIELD_GET(SN_PWM_EN_MASK, pwm_en_inv); in ti_sn_pwm_get_state()
1531 state->polarity = PWM_POLARITY_INVERSED; in ti_sn_pwm_get_state()
1533 state->polarity = PWM_POLARITY_NORMAL; in ti_sn_pwm_get_state()
1535 state->period = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * pre_div * (scale + 1), in ti_sn_pwm_get_state()
1536 pdata->pwm_refclk_freq); in ti_sn_pwm_get_state()
1537 state->duty_cycle = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * pre_div * backlight, in ti_sn_pwm_get_state()
1538 pdata->pwm_refclk_freq); in ti_sn_pwm_get_state()
1540 if (state->duty_cycle > state->period) in ti_sn_pwm_get_state()
1541 state->duty_cycle = state->period; in ti_sn_pwm_get_state()
1555 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_pwm_probe()
1557 pdata->pchip.dev = pdata->dev; in ti_sn_pwm_probe()
1558 pdata->pchip.ops = &ti_sn_pwm_ops; in ti_sn_pwm_probe()
1559 pdata->pchip.npwm = 1; in ti_sn_pwm_probe()
1560 pdata->pchip.of_xlate = of_pwm_single_xlate; in ti_sn_pwm_probe()
1561 pdata->pchip.of_pwm_n_cells = 1; in ti_sn_pwm_probe()
1563 return pwmchip_add(&pdata->pchip); in ti_sn_pwm_probe()
1568 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_pwm_remove()
1570 pwmchip_remove(&pdata->pchip); in ti_sn_pwm_remove()
1572 if (pdata->pwm_enabled) in ti_sn_pwm_remove()
1573 pm_runtime_put_sync(pdata->dev); in ti_sn_pwm_remove()
1606 /* -----------------------------------------------------------------------------
1615 if (WARN_ON(gpiospec->args_count < chip->of_gpio_n_cells)) in tn_sn_bridge_of_xlate()
1616 return -EINVAL; in tn_sn_bridge_of_xlate()
1618 if (gpiospec->args[0] > chip->ngpio || gpiospec->args[0] < 1) in tn_sn_bridge_of_xlate()
1619 return -EINVAL; in tn_sn_bridge_of_xlate()
1622 *flags = gpiospec->args[1]; in tn_sn_bridge_of_xlate()
1624 return gpiospec->args[0] - SN_GPIO_PHYSICAL_OFFSET; in tn_sn_bridge_of_xlate()
1638 return test_bit(offset, pdata->gchip_output) ? in ti_sn_bridge_gpio_get_direction()
1650 * powered--we just power it on to read the pin. NOTE: part of in ti_sn_bridge_gpio_get()
1656 pm_runtime_get_sync(pdata->dev); in ti_sn_bridge_gpio_get()
1657 ret = regmap_read(pdata->regmap, SN_GPIO_IO_REG, &val); in ti_sn_bridge_gpio_get()
1658 pm_runtime_put_autosuspend(pdata->dev); in ti_sn_bridge_gpio_get()
1672 if (!test_bit(offset, pdata->gchip_output)) { in ti_sn_bridge_gpio_set()
1673 dev_err(pdata->dev, "Ignoring GPIO set while input\n"); in ti_sn_bridge_gpio_set()
1678 ret = regmap_update_bits(pdata->regmap, SN_GPIO_IO_REG, in ti_sn_bridge_gpio_set()
1682 dev_warn(pdata->dev, in ti_sn_bridge_gpio_set()
1693 if (!test_and_clear_bit(offset, pdata->gchip_output)) in ti_sn_bridge_gpio_direction_input()
1696 ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG, in ti_sn_bridge_gpio_direction_input()
1700 set_bit(offset, pdata->gchip_output); in ti_sn_bridge_gpio_direction_input()
1709 pm_runtime_put_autosuspend(pdata->dev); in ti_sn_bridge_gpio_direction_input()
1721 if (test_and_set_bit(offset, pdata->gchip_output)) in ti_sn_bridge_gpio_direction_output()
1724 pm_runtime_get_sync(pdata->dev); in ti_sn_bridge_gpio_direction_output()
1730 ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG, in ti_sn_bridge_gpio_direction_output()
1734 clear_bit(offset, pdata->gchip_output); in ti_sn_bridge_gpio_direction_output()
1735 pm_runtime_put_autosuspend(pdata->dev); in ti_sn_bridge_gpio_direction_output()
1769 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_gpio_probe()
1773 if (!of_property_read_bool(pdata->dev->of_node, "gpio-controller")) in ti_sn_gpio_probe()
1776 pdata->gchip.label = dev_name(pdata->dev); in ti_sn_gpio_probe()
1777 pdata->gchip.parent = pdata->dev; in ti_sn_gpio_probe()
1778 pdata->gchip.owner = THIS_MODULE; in ti_sn_gpio_probe()
1779 pdata->gchip.of_xlate = tn_sn_bridge_of_xlate; in ti_sn_gpio_probe()
1780 pdata->gchip.of_gpio_n_cells = 2; in ti_sn_gpio_probe()
1781 pdata->gchip.request = ti_sn_bridge_gpio_request; in ti_sn_gpio_probe()
1782 pdata->gchip.free = ti_sn_bridge_gpio_free; in ti_sn_gpio_probe()
1783 pdata->gchip.get_direction = ti_sn_bridge_gpio_get_direction; in ti_sn_gpio_probe()
1784 pdata->gchip.direction_input = ti_sn_bridge_gpio_direction_input; in ti_sn_gpio_probe()
1785 pdata->gchip.direction_output = ti_sn_bridge_gpio_direction_output; in ti_sn_gpio_probe()
1786 pdata->gchip.get = ti_sn_bridge_gpio_get; in ti_sn_gpio_probe()
1787 pdata->gchip.set = ti_sn_bridge_gpio_set; in ti_sn_gpio_probe()
1788 pdata->gchip.can_sleep = true; in ti_sn_gpio_probe()
1789 pdata->gchip.names = ti_sn_bridge_gpio_names; in ti_sn_gpio_probe()
1790 pdata->gchip.ngpio = SN_NUM_GPIOS; in ti_sn_gpio_probe()
1791 pdata->gchip.base = -1; in ti_sn_gpio_probe()
1792 ret = devm_gpiochip_add_data(&adev->dev, &pdata->gchip, pdata); in ti_sn_gpio_probe()
1794 dev_err(pdata->dev, "can't add gpio chip\n"); in ti_sn_gpio_probe()
1829 /* -----------------------------------------------------------------------------
1847 pdata->supplies[i].supply = ti_sn_bridge_supply_names[i]; in ti_sn65dsi86_parse_regulators()
1849 return devm_regulator_bulk_get(pdata->dev, SN_REGULATOR_SUPPLY_NUM, in ti_sn65dsi86_parse_regulators()
1850 pdata->supplies); in ti_sn65dsi86_parse_regulators()
1856 struct device *dev = &client->dev; in ti_sn65dsi86_probe()
1860 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in ti_sn65dsi86_probe()
1862 return -ENODEV; in ti_sn65dsi86_probe()
1867 return -ENOMEM; in ti_sn65dsi86_probe()
1869 pdata->dev = dev; in ti_sn65dsi86_probe()
1871 mutex_init(&pdata->comms_mutex); in ti_sn65dsi86_probe()
1873 pdata->regmap = devm_regmap_init_i2c(client, in ti_sn65dsi86_probe()
1875 if (IS_ERR(pdata->regmap)) in ti_sn65dsi86_probe()
1876 return dev_err_probe(dev, PTR_ERR(pdata->regmap), in ti_sn65dsi86_probe()
1879 pdata->enable_gpio = devm_gpiod_get_optional(dev, "enable", in ti_sn65dsi86_probe()
1881 if (IS_ERR(pdata->enable_gpio)) in ti_sn65dsi86_probe()
1882 return dev_err_probe(dev, PTR_ERR(pdata->enable_gpio), in ti_sn65dsi86_probe()
1889 pdata->refclk = devm_clk_get_optional(dev, "refclk"); in ti_sn65dsi86_probe()
1890 if (IS_ERR(pdata->refclk)) in ti_sn65dsi86_probe()
1891 return dev_err_probe(dev, PTR_ERR(pdata->refclk), in ti_sn65dsi86_probe()
1895 pm_runtime_set_autosuspend_delay(pdata->dev, 500); in ti_sn65dsi86_probe()
1896 pm_runtime_use_autosuspend(pdata->dev); in ti_sn65dsi86_probe()
1904 * Break ourselves up into a collection of aux devices. The only real in ti_sn65dsi86_probe()
1905 * motiviation here is to solve the chicken-and-egg problem of probe in ti_sn65dsi86_probe()
1909 * bus or the pwm_chip. Having sub-devices allows the some sub devices in ti_sn65dsi86_probe()
1910 * to finish probing even if others return -EPROBE_DEFER and gets us in ti_sn65dsi86_probe()
1915 ret = ti_sn65dsi86_add_aux_device(pdata, &pdata->gpio_aux, "gpio"); in ti_sn65dsi86_probe()
1921 ret = ti_sn65dsi86_add_aux_device(pdata, &pdata->pwm_aux, "pwm"); in ti_sn65dsi86_probe()
1927 * NOTE: At the end of the AUX channel probe we'll add the aux device in ti_sn65dsi86_probe()
1929 * AUX channel is there and this is a very simple solution to the in ti_sn65dsi86_probe()
1932 return ti_sn65dsi86_add_aux_device(pdata, &pdata->aux_aux, "aux"); in ti_sn65dsi86_probe()