Lines Matching refs:pdata

224 static int __maybe_unused ti_sn65dsi86_read_u16(struct ti_sn65dsi86 *pdata,  in ti_sn65dsi86_read_u16()  argument
230 ret = regmap_bulk_read(pdata->regmap, reg, buf, ARRAY_SIZE(buf)); in ti_sn65dsi86_read_u16()
239 static void ti_sn65dsi86_write_u16(struct ti_sn65dsi86 *pdata, in ti_sn65dsi86_write_u16() argument
244 regmap_bulk_write(pdata->regmap, reg, buf, ARRAY_SIZE(buf)); in ti_sn65dsi86_write_u16()
247 static u32 ti_sn_bridge_get_dsi_freq(struct ti_sn65dsi86 *pdata) in ti_sn_bridge_get_dsi_freq() argument
251 &pdata->bridge.encoder->crtc->state->adjusted_mode; 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()
278 static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) in ti_sn_bridge_set_refclk_freq() argument
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()
291 refclk_rate = ti_sn_bridge_get_dsi_freq(pdata) * 1000; 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()
311 static void ti_sn65dsi86_enable_comms(struct ti_sn65dsi86 *pdata) in ti_sn65dsi86_enable_comms() argument
313 mutex_lock(&pdata->comms_mutex); in ti_sn65dsi86_enable_comms()
316 ti_sn_bridge_set_refclk_freq(pdata); 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()
342 static void ti_sn65dsi86_disable_comms(struct ti_sn65dsi86 *pdata) in ti_sn65dsi86_disable_comms() argument
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()
354 struct ti_sn65dsi86 *pdata = dev_get_drvdata(dev); in ti_sn65dsi86_resume() local
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()
375 if (pdata->refclk) in ti_sn65dsi86_resume()
376 ti_sn65dsi86_enable_comms(pdata); in ti_sn65dsi86_resume()
383 struct ti_sn65dsi86 *pdata = dev_get_drvdata(dev); in ti_sn65dsi86_suspend() local
386 if (pdata->refclk) in ti_sn65dsi86_suspend()
387 ti_sn65dsi86_disable_comms(pdata); 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() local
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()
431 static void ti_sn65dsi86_debugfs_init(struct ti_sn65dsi86 *pdata) in ti_sn65dsi86_debugfs_init() argument
433 struct device *dev = pdata->dev; in ti_sn65dsi86_debugfs_init()
450 debugfs_create_file("status", 0600, debugfs, pdata, &status_fops); in ti_sn65dsi86_debugfs_init()
474 static int ti_sn65dsi86_add_aux_device(struct ti_sn65dsi86 *pdata, in ti_sn65dsi86_add_aux_device() argument
478 struct device *dev = pdata->dev; in ti_sn65dsi86_add_aux_device()
512 struct ti_sn65dsi86 *pdata = aux_to_ti_sn65dsi86(aux); in ti_sn_aux_transfer() local
524 pm_runtime_get_sync(pdata->dev); in ti_sn_aux_transfer()
525 mutex_lock(&pdata->comms_mutex); in ti_sn_aux_transfer()
533 if (!pdata->comms_enabled) { in ti_sn_aux_transfer()
543 regmap_write(pdata->regmap, SN_AUX_CMD_REG, request_val); 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()
590 ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &len); 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() local
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()
640 return ti_sn65dsi86_add_aux_device(pdata, &pdata->bridge_aux, "bridge"); in ti_sn_aux_probe()
663 static int ti_sn_attach_host(struct ti_sn65dsi86 *pdata) in ti_sn_attach_host() argument
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()
689 regmap_read(pdata->regmap, SN_DPPLL_SRC_REG, &val); in ti_sn_attach_host()
694 pdata->dsi = dsi; in ti_sn_attach_host()
702 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_attach() local
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()
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()
783 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_atomic_disable() local
786 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, 0); in ti_sn_bridge_atomic_disable()
789 static void ti_sn_bridge_set_dsi_rate(struct ti_sn65dsi86 *pdata) in ti_sn_bridge_set_dsi_rate() argument
794 &pdata->bridge.encoder->crtc->state->adjusted_mode; 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()
804 regmap_write(pdata->regmap, SN_DSIA_CLK_FREQ_REG, val); in ti_sn_bridge_set_dsi_rate()
824 static int ti_sn_bridge_calc_min_dp_rate_idx(struct ti_sn65dsi86 *pdata, unsigned int bpp) in ti_sn_bridge_calc_min_dp_rate_idx() argument
829 &pdata->bridge.encoder->crtc->state->adjusted_mode; 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()
845 static unsigned int ti_sn_bridge_read_valid_rates(struct ti_sn65dsi86 *pdata) in ti_sn_bridge_read_valid_rates() argument
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()
928 static void ti_sn_bridge_set_video_timings(struct ti_sn65dsi86 *pdata) in ti_sn_bridge_set_video_timings() argument
931 &pdata->bridge.encoder->crtc->state->adjusted_mode; in ti_sn_bridge_set_video_timings()
939 ti_sn65dsi86_write_u16(pdata, SN_CHA_ACTIVE_LINE_LENGTH_LOW_REG, in ti_sn_bridge_set_video_timings()
941 ti_sn65dsi86_write_u16(pdata, SN_CHA_VERTICAL_DISPLAY_SIZE_LOW_REG, 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()
945 regmap_write(pdata->regmap, SN_CHA_HSYNC_PULSE_WIDTH_HIGH_REG, 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()
950 regmap_write(pdata->regmap, SN_CHA_VSYNC_PULSE_WIDTH_HIGH_REG, 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()
956 regmap_write(pdata->regmap, SN_CHA_VERTICAL_BACK_PORCH_REG, 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()
961 regmap_write(pdata->regmap, SN_CHA_VERTICAL_FRONT_PORCH_REG, in ti_sn_bridge_set_video_timings()
967 static unsigned int ti_sn_get_max_lanes(struct ti_sn65dsi86 *pdata) in ti_sn_get_max_lanes() argument
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()
982 static int ti_sn_link_training(struct ti_sn65dsi86 *pdata, int dp_rate_idx, in ti_sn_link_training() argument
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()
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()
1043 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_atomic_enable() local
1056 dev_err_ratelimited(pdata->dev, "Could not get the connector\n"); in ti_sn_bridge_atomic_enable()
1060 max_dp_lanes = ti_sn_get_max_lanes(pdata); 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()
1073 ti_sn_bridge_set_dsi_rate(pdata); 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()
1105 valid_rates = ti_sn_bridge_read_valid_rates(pdata); in ti_sn_bridge_atomic_enable()
1108 for (dp_rate_idx = ti_sn_bridge_calc_min_dp_rate_idx(pdata, bpp); in ti_sn_bridge_atomic_enable()
1114 ret = ti_sn_link_training(pdata, dp_rate_idx, &last_err_str); 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()
1124 ti_sn_bridge_set_video_timings(pdata); in ti_sn_bridge_atomic_enable()
1127 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, in ti_sn_bridge_atomic_enable()
1134 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_atomic_pre_enable() local
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()
1139 ti_sn65dsi86_enable_comms(pdata); in ti_sn_bridge_atomic_pre_enable()
1148 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_atomic_post_disable() local
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()
1158 ti_sn65dsi86_disable_comms(pdata); in ti_sn_bridge_atomic_post_disable()
1160 pm_runtime_put_sync(pdata->dev); in ti_sn_bridge_atomic_post_disable()
1165 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_detect() local
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()
1179 struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge); in ti_sn_bridge_get_edid() local
1181 return drm_get_edid(connector, &pdata->aux.ddc); in ti_sn_bridge_get_edid()
1199 static void ti_sn_bridge_parse_lanes(struct ti_sn65dsi86 *pdata, in ti_sn_bridge_parse_lanes() argument
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()
1248 static int ti_sn_bridge_parse_dsi_host(struct ti_sn65dsi86 *pdata) in ti_sn_bridge_parse_dsi_host() argument
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()
1265 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_bridge_probe() local
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()
1274 ti_sn_bridge_parse_lanes(pdata, np); in ti_sn_bridge_probe()
1276 ret = ti_sn_bridge_parse_dsi_host(pdata); 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()
1290 ret = ti_sn_attach_host(pdata); 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() local
1307 if (!pdata) 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()
1331 static int ti_sn_pwm_pin_request(struct ti_sn65dsi86 *pdata) in ti_sn_pwm_pin_request() argument
1333 return atomic_xchg(&pdata->pwm_pin_busy, 1) ? -EBUSY : 0; in ti_sn_pwm_pin_request()
1336 static void ti_sn_pwm_pin_release(struct ti_sn65dsi86 *pdata) in ti_sn_pwm_pin_release() argument
1338 atomic_set(&pdata->pwm_pin_busy, 0); in ti_sn_pwm_pin_release()
1348 struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip); in ti_sn_pwm_request() local
1350 return ti_sn_pwm_pin_request(pdata); in ti_sn_pwm_request()
1355 struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip); in ti_sn_pwm_free() local
1357 ti_sn_pwm_pin_release(pdata); in ti_sn_pwm_free()
1374 struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip); in ti_sn_pwm_apply() local
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()
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()
1443 if (state->period <= NSEC_PER_SEC / pdata->pwm_refclk_freq) { in ti_sn_pwm_apply()
1453 pdata->pwm_refclk_freq); 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()
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()
1482 ti_sn65dsi86_write_u16(pdata, SN_BACKLIGHT_SCALE_REG, scale); in ti_sn_pwm_apply()
1483 ti_sn65dsi86_write_u16(pdata, SN_BACKLIGHT_REG, backlight); 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()
1506 struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip); in ti_sn_pwm_get_state() local
1513 ret = regmap_read(pdata->regmap, SN_PWM_EN_INV_REG, &pwm_en_inv); in ti_sn_pwm_get_state()
1517 ret = ti_sn65dsi86_read_u16(pdata, SN_BACKLIGHT_SCALE_REG, &scale); in ti_sn_pwm_get_state()
1521 ret = ti_sn65dsi86_read_u16(pdata, SN_BACKLIGHT_REG, &backlight); 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()
1536 pdata->pwm_refclk_freq); in ti_sn_pwm_get_state()
1538 pdata->pwm_refclk_freq); in ti_sn_pwm_get_state()
1555 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_pwm_probe() local
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() local
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()
1599 static inline int ti_sn_pwm_pin_request(struct ti_sn65dsi86 *pdata) { return 0; } in ti_sn_pwm_pin_request() argument
1600 static inline void ti_sn_pwm_pin_release(struct ti_sn65dsi86 *pdata) {} in ti_sn_pwm_pin_release() argument
1630 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_get_direction() local
1638 return test_bit(offset, pdata->gchip_output) ? in ti_sn_bridge_gpio_get_direction()
1644 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_get() local
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()
1669 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_set() local
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()
1689 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_direction_input() local
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()
1717 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_direction_output() local
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()
1743 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_request() local
1746 return ti_sn_pwm_pin_request(pdata); in ti_sn_bridge_gpio_request()
1753 struct ti_sn65dsi86 *pdata = gpiochip_get_data(chip); in ti_sn_bridge_gpio_free() local
1759 ti_sn_pwm_pin_release(pdata); in ti_sn_bridge_gpio_free()
1769 struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); in ti_sn_gpio_probe() local
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()
1839 static int ti_sn65dsi86_parse_regulators(struct ti_sn65dsi86 *pdata) in ti_sn65dsi86_parse_regulators() argument
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()
1857 struct ti_sn65dsi86 *pdata; in ti_sn65dsi86_probe() local
1865 pdata = devm_kzalloc(dev, sizeof(struct ti_sn65dsi86), GFP_KERNEL); in ti_sn65dsi86_probe()
1866 if (!pdata) in ti_sn65dsi86_probe()
1868 dev_set_drvdata(dev, pdata); 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()
1885 ret = ti_sn65dsi86_parse_regulators(pdata); 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()
1901 ti_sn65dsi86_debugfs_init(pdata); 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()
1932 return ti_sn65dsi86_add_aux_device(pdata, &pdata->aux_aux, "aux"); in ti_sn65dsi86_probe()