Skip to content

Commit edb715d

Browse files
pinchartltomba
authored andcommitted
drm/omap: dss: dsi: Move initialization code from bind to probe
There's no reason to delay initialization of most of the driver (such as mapping memory I/O or enabling runtime PM) to the component bind handler. Perform as much of the initialization as possible at probe time, initializing at bind time only the parts that depends on the DSS. The cleanup code is moved from unbind to remove in a similar way. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
1 parent 66aacfe commit edb715d

File tree

1 file changed

+161
-140
lines changed
  • drivers/gpu/drm/omapdrm/dss

1 file changed

+161
-140
lines changed

drivers/gpu/drm/omapdrm/dss/dsi.c

Lines changed: 161 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -4981,85 +4981,9 @@ static const struct omap_dss_device_ops dsi_ops = {
49814981
},
49824982
};
49834983

4984-
static void dsi_init_output(struct dsi_data *dsi)
4985-
{
4986-
struct omap_dss_device *out = &dsi->output;
4987-
4988-
out->dev = dsi->dev;
4989-
out->id = dsi->module_id == 0 ?
4990-
OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
4991-
4992-
out->output_type = OMAP_DISPLAY_TYPE_DSI;
4993-
out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
4994-
out->dispc_channel = dsi_get_channel(dsi);
4995-
out->ops = &dsi_ops;
4996-
out->owner = THIS_MODULE;
4997-
out->of_ports = BIT(0);
4998-
4999-
omapdss_device_register(out);
5000-
}
5001-
5002-
static void dsi_uninit_output(struct dsi_data *dsi)
5003-
{
5004-
struct omap_dss_device *out = &dsi->output;
5005-
5006-
omapdss_device_unregister(out);
5007-
}
5008-
5009-
static int dsi_probe_of(struct dsi_data *dsi)
5010-
{
5011-
struct device_node *node = dsi->dev->of_node;
5012-
struct property *prop;
5013-
u32 lane_arr[10];
5014-
int len, num_pins;
5015-
int r, i;
5016-
struct device_node *ep;
5017-
struct omap_dsi_pin_config pin_cfg;
5018-
5019-
ep = of_graph_get_endpoint_by_regs(node, 0, 0);
5020-
if (!ep)
5021-
return 0;
5022-
5023-
prop = of_find_property(ep, "lanes", &len);
5024-
if (prop == NULL) {
5025-
dev_err(dsi->dev, "failed to find lane data\n");
5026-
r = -EINVAL;
5027-
goto err;
5028-
}
5029-
5030-
num_pins = len / sizeof(u32);
5031-
5032-
if (num_pins < 4 || num_pins % 2 != 0 ||
5033-
num_pins > dsi->num_lanes_supported * 2) {
5034-
dev_err(dsi->dev, "bad number of lanes\n");
5035-
r = -EINVAL;
5036-
goto err;
5037-
}
5038-
5039-
r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins);
5040-
if (r) {
5041-
dev_err(dsi->dev, "failed to read lane data\n");
5042-
goto err;
5043-
}
5044-
5045-
pin_cfg.num_pins = num_pins;
5046-
for (i = 0; i < num_pins; ++i)
5047-
pin_cfg.pins[i] = (int)lane_arr[i];
5048-
5049-
r = dsi_configure_pins(&dsi->output, &pin_cfg);
5050-
if (r) {
5051-
dev_err(dsi->dev, "failed to configure pins");
5052-
goto err;
5053-
}
5054-
5055-
of_node_put(ep);
5056-
5057-
return 0;
5058-
5059-
err:
5060-
of_node_put(ep);
5061-
return r;
5062-
}
4984+
/* -----------------------------------------------------------------------------
4985+
* PLL
4986+
*/
50634987

50644988
static const struct dss_pll_ops dsi_pll_ops = {
50654989
.enable = dsi_pll_enable,
@@ -5174,7 +5098,153 @@ static int dsi_init_pll_data(struct dss_device *dss, struct dsi_data *dsi)
51745098
return 0;
51755099
}
51765100

5177-
/* DSI1 HW IP initialisation */
5101+
/* -----------------------------------------------------------------------------
5102+
* Component Bind & Unbind
5103+
*/
5104+
5105+
static int dsi_bind(struct device *dev, struct device *master, void *data)
5106+
{
5107+
struct dss_device *dss = dss_get_device(master);
5108+
struct dsi_data *dsi = dev_get_drvdata(dev);
5109+
char name[10];
5110+
u32 rev;
5111+
int r;
5112+
5113+
dsi->dss = dss;
5114+
5115+
dsi_init_pll_data(dss, dsi);
5116+
5117+
r = dsi_runtime_get(dsi);
5118+
if (r)
5119+
return r;
5120+
5121+
rev = dsi_read_reg(dsi, DSI_REVISION);
5122+
dev_dbg(dev, "OMAP DSI rev %d.%d\n",
5123+
FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5124+
5125+
dsi->line_buffer_size = dsi_get_line_buf_size(dsi);
5126+
5127+
dsi_runtime_put(dsi);
5128+
5129+
snprintf(name, sizeof(name), "dsi%u_regs", dsi->module_id + 1);
5130+
dsi->debugfs.regs = dss_debugfs_create_file(dss, name,
5131+
dsi_dump_dsi_regs, &dsi);
5132+
#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
5133+
snprintf(name, sizeof(name), "dsi%u_irqs", dsi->module_id + 1);
5134+
dsi->debugfs.irqs = dss_debugfs_create_file(dss, name,
5135+
dsi_dump_dsi_irqs, &dsi);
5136+
#endif
5137+
snprintf(name, sizeof(name), "dsi%u_clks", dsi->module_id + 1);
5138+
dsi->debugfs.clks = dss_debugfs_create_file(dss, name,
5139+
dsi_dump_dsi_clocks, &dsi);
5140+
5141+
return 0;
5142+
}
5143+
5144+
static void dsi_unbind(struct device *dev, struct device *master, void *data)
5145+
{
5146+
struct dsi_data *dsi = dev_get_drvdata(dev);
5147+
5148+
dss_debugfs_remove_file(dsi->debugfs.clks);
5149+
dss_debugfs_remove_file(dsi->debugfs.irqs);
5150+
dss_debugfs_remove_file(dsi->debugfs.regs);
5151+
5152+
of_platform_depopulate(dev);
5153+
5154+
WARN_ON(dsi->scp_clk_refcount > 0);
5155+
5156+
dss_pll_unregister(&dsi->pll);
5157+
}
5158+
5159+
static const struct component_ops dsi_component_ops = {
5160+
.bind = dsi_bind,
5161+
.unbind = dsi_unbind,
5162+
};
5163+
5164+
/* -----------------------------------------------------------------------------
5165+
* Probe & Remove, Suspend & Resume
5166+
*/
5167+
5168+
static void dsi_init_output(struct dsi_data *dsi)
5169+
{
5170+
struct omap_dss_device *out = &dsi->output;
5171+
5172+
out->dev = dsi->dev;
5173+
out->id = dsi->module_id == 0 ?
5174+
OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
5175+
5176+
out->output_type = OMAP_DISPLAY_TYPE_DSI;
5177+
out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
5178+
out->dispc_channel = dsi_get_channel(dsi);
5179+
out->ops = &dsi_ops;
5180+
out->owner = THIS_MODULE;
5181+
out->of_ports = BIT(0);
5182+
5183+
omapdss_device_register(out);
5184+
}
5185+
5186+
static void dsi_uninit_output(struct dsi_data *dsi)
5187+
{
5188+
struct omap_dss_device *out = &dsi->output;
5189+
5190+
omapdss_device_unregister(out);
5191+
}
5192+
5193+
static int dsi_probe_of(struct dsi_data *dsi)
5194+
{
5195+
struct device_node *node = dsi->dev->of_node;
5196+
struct property *prop;
5197+
u32 lane_arr[10];
5198+
int len, num_pins;
5199+
int r, i;
5200+
struct device_node *ep;
5201+
struct omap_dsi_pin_config pin_cfg;
5202+
5203+
ep = of_graph_get_endpoint_by_regs(node, 0, 0);
5204+
if (!ep)
5205+
return 0;
5206+
5207+
prop = of_find_property(ep, "lanes", &len);
5208+
if (prop == NULL) {
5209+
dev_err(dsi->dev, "failed to find lane data\n");
5210+
r = -EINVAL;
5211+
goto err;
5212+
}
5213+
5214+
num_pins = len / sizeof(u32);
5215+
5216+
if (num_pins < 4 || num_pins % 2 != 0 ||
5217+
num_pins > dsi->num_lanes_supported * 2) {
5218+
dev_err(dsi->dev, "bad number of lanes\n");
5219+
r = -EINVAL;
5220+
goto err;
5221+
}
5222+
5223+
r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins);
5224+
if (r) {
5225+
dev_err(dsi->dev, "failed to read lane data\n");
5226+
goto err;
5227+
}
5228+
5229+
pin_cfg.num_pins = num_pins;
5230+
for (i = 0; i < num_pins; ++i)
5231+
pin_cfg.pins[i] = (int)lane_arr[i];
5232+
5233+
r = dsi_configure_pins(&dsi->output, &pin_cfg);
5234+
if (r) {
5235+
dev_err(dsi->dev, "failed to configure pins");
5236+
goto err;
5237+
}
5238+
5239+
of_node_put(ep);
5240+
5241+
return 0;
5242+
5243+
err:
5244+
of_node_put(ep);
5245+
return r;
5246+
}
5247+
51785248
static const struct dsi_of_data dsi_of_data_omap34xx = {
51795249
.model = DSI_MODEL_OMAP3,
51805250
.pll_hw = &dss_omap3_dsi_pll_hw,
@@ -5240,24 +5310,21 @@ static const struct soc_device_attribute dsi_soc_devices[] = {
52405310
{ /* sentinel */ }
52415311
};
52425312

5243-
static int dsi_bind(struct device *dev, struct device *master, void *data)
5313+
static int dsi_probe(struct platform_device *pdev)
52445314
{
5245-
struct platform_device *pdev = to_platform_device(dev);
5246-
struct dss_device *dss = dss_get_device(master);
52475315
const struct soc_device_attribute *soc;
52485316
const struct dsi_module_id_data *d;
5249-
u32 rev;
5250-
int r, i;
5317+
struct device *dev = &pdev->dev;
52515318
struct dsi_data *dsi;
52525319
struct resource *dsi_mem;
52535320
struct resource *res;
5254-
char name[10];
5321+
unsigned int i;
5322+
int r;
52555323

52565324
dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
52575325
if (!dsi)
52585326
return -ENOMEM;
52595327

5260-
dsi->dss = dss;
52615328
dsi->dev = dev;
52625329
dev_set_drvdata(dev, dsi);
52635330

@@ -5354,18 +5421,8 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
53545421
if (r)
53555422
return r;
53565423

5357-
dsi_init_pll_data(dss, dsi);
5358-
53595424
pm_runtime_enable(dev);
53605425

5361-
r = dsi_runtime_get(dsi);
5362-
if (r)
5363-
goto err_pm_disable;
5364-
5365-
rev = dsi_read_reg(dsi, DSI_REVISION);
5366-
dev_dbg(dev, "OMAP DSI rev %d.%d\n",
5367-
FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5368-
53695426
/* DSI on OMAP3 doesn't have register DSI_GNQ, set number
53705427
* of data to 3 by default */
53715428
if (dsi->data->quirks & DSI_QUIRK_GNQ)
@@ -5374,8 +5431,6 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
53745431
else
53755432
dsi->num_lanes_supported = 3;
53765433

5377-
dsi->line_buffer_size = dsi_get_line_buf_size(dsi);
5378-
53795434
dsi_init_output(dsi);
53805435

53815436
r = dsi_probe_of(dsi);
@@ -5388,67 +5443,33 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
53885443
if (r)
53895444
DSSERR("Failed to populate DSI child devices: %d\n", r);
53905445

5391-
dsi_runtime_put(dsi);
5392-
5393-
snprintf(name, sizeof(name), "dsi%u_regs", dsi->module_id + 1);
5394-
dsi->debugfs.regs = dss_debugfs_create_file(dss, name,
5395-
dsi_dump_dsi_regs, &dsi);
5396-
#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
5397-
snprintf(name, sizeof(name), "dsi%u_irqs", dsi->module_id + 1);
5398-
dsi->debugfs.irqs = dss_debugfs_create_file(dss, name,
5399-
dsi_dump_dsi_irqs, &dsi);
5400-
#endif
5401-
snprintf(name, sizeof(name), "dsi%u_clks", dsi->module_id + 1);
5402-
dsi->debugfs.clks = dss_debugfs_create_file(dss, name,
5403-
dsi_dump_dsi_clocks, &dsi);
5446+
r = component_add(&pdev->dev, &dsi_component_ops);
5447+
if (r)
5448+
goto err_uninit_output;
54045449

54055450
return 0;
54065451

54075452
err_uninit_output:
54085453
dsi_uninit_output(dsi);
5409-
dsi_runtime_put(dsi);
5410-
err_pm_disable:
54115454
pm_runtime_disable(dev);
54125455
return r;
54135456
}
54145457

5415-
static void dsi_unbind(struct device *dev, struct device *master, void *data)
5458+
static int dsi_remove(struct platform_device *pdev)
54165459
{
5417-
struct dsi_data *dsi = dev_get_drvdata(dev);
5460+
struct dsi_data *dsi = platform_get_drvdata(pdev);
54185461

5419-
dss_debugfs_remove_file(dsi->debugfs.clks);
5420-
dss_debugfs_remove_file(dsi->debugfs.irqs);
5421-
dss_debugfs_remove_file(dsi->debugfs.regs);
5422-
5423-
of_platform_depopulate(dev);
5424-
5425-
WARN_ON(dsi->scp_clk_refcount > 0);
5426-
5427-
dss_pll_unregister(&dsi->pll);
5462+
component_del(&pdev->dev, &dsi_component_ops);
54285463

54295464
dsi_uninit_output(dsi);
54305465

5431-
pm_runtime_disable(dev);
5466+
pm_runtime_disable(&pdev->dev);
54325467

54335468
if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) {
54345469
regulator_disable(dsi->vdds_dsi_reg);
54355470
dsi->vdds_dsi_enabled = false;
54365471
}
5437-
}
54385472

5439-
static const struct component_ops dsi_component_ops = {
5440-
.bind = dsi_bind,
5441-
.unbind = dsi_unbind,
5442-
};
5443-
5444-
static int dsi_probe(struct platform_device *pdev)
5445-
{
5446-
return component_add(&pdev->dev, &dsi_component_ops);
5447-
}
5448-
5449-
static int dsi_remove(struct platform_device *pdev)
5450-
{
5451-
component_del(&pdev->dev, &dsi_component_ops);
54525473
return 0;
54535474
}
54545475

0 commit comments

Comments
 (0)