Skip to content

Commit

Permalink
Merge branch 'dss-devtree-cleanup'
Browse files Browse the repository at this point in the history
Merge OMAP DSS cleanups that restructure the omapdss driver to facilitate
implementing device tree support in the future.
  • Loading branch information
Tomi Valkeinen committed May 11, 2012
2 parents 3a028bb + af461d6 commit 38137c8
Show file tree
Hide file tree
Showing 15 changed files with 688 additions and 568 deletions.
192 changes: 161 additions & 31 deletions arch/arm/mach-omap2/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,128 @@ static int omap_dss_set_min_bus_tput(struct device *dev, unsigned long tput)
return omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, tput);
}

static struct platform_device *create_dss_pdev(const char *pdev_name,
int pdev_id, const char *oh_name, void *pdata, int pdata_len,
struct platform_device *parent)
{
struct platform_device *pdev;
struct omap_device *od;
struct omap_hwmod *ohs[1];
struct omap_hwmod *oh;
int r;

oh = omap_hwmod_lookup(oh_name);
if (!oh) {
pr_err("Could not look up %s\n", oh_name);
r = -ENODEV;
goto err;
}

pdev = platform_device_alloc(pdev_name, pdev_id);
if (!pdev) {
pr_err("Could not create pdev for %s\n", pdev_name);
r = -ENOMEM;
goto err;
}

if (parent != NULL)
pdev->dev.parent = &parent->dev;

if (pdev->id != -1)
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
else
dev_set_name(&pdev->dev, "%s", pdev->name);

ohs[0] = oh;
od = omap_device_alloc(pdev, ohs, 1, NULL, 0);
if (!od) {
pr_err("Could not alloc omap_device for %s\n", pdev_name);
r = -ENOMEM;
goto err;
}

r = platform_device_add_data(pdev, pdata, pdata_len);
if (r) {
pr_err("Could not set pdata for %s\n", pdev_name);
goto err;
}

r = omap_device_register(pdev);
if (r) {
pr_err("Could not register omap_device for %s\n", pdev_name);
goto err;
}

return pdev;

err:
return ERR_PTR(r);
}

static struct platform_device *create_simple_dss_pdev(const char *pdev_name,
int pdev_id, void *pdata, int pdata_len,
struct platform_device *parent)
{
struct platform_device *pdev;
int r;

pdev = platform_device_alloc(pdev_name, pdev_id);
if (!pdev) {
pr_err("Could not create pdev for %s\n", pdev_name);
r = -ENOMEM;
goto err;
}

if (parent != NULL)
pdev->dev.parent = &parent->dev;

if (pdev->id != -1)
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
else
dev_set_name(&pdev->dev, "%s", pdev->name);

r = platform_device_add_data(pdev, pdata, pdata_len);
if (r) {
pr_err("Could not set pdata for %s\n", pdev_name);
goto err;
}

r = omap_device_register(pdev);
if (r) {
pr_err("Could not register omap_device for %s\n", pdev_name);
goto err;
}

return pdev;

err:
return ERR_PTR(r);
}

int __init omap_display_init(struct omap_dss_board_info *board_data)
{
int r = 0;
struct omap_hwmod *oh;
struct platform_device *pdev;
int i, oh_count;
struct omap_display_platform_data pdata;
const struct omap_dss_hwmod_data *curr_dss_hwmod;
struct platform_device *dss_pdev;

/* create omapdss device */

memset(&pdata, 0, sizeof(pdata));
board_data->dsi_enable_pads = omap_dsi_enable_pads;
board_data->dsi_disable_pads = omap_dsi_disable_pads;
board_data->get_context_loss_count = omap_pm_get_dev_context_loss_count;
board_data->set_min_bus_tput = omap_dss_set_min_bus_tput;

omap_display_device.dev.platform_data = board_data;

r = platform_device_register(&omap_display_device);
if (r < 0) {
pr_err("Unable to register omapdss device\n");
return r;
}

/* create devices for dss hwmods */

if (cpu_is_omap24xx()) {
curr_dss_hwmod = omap2_dss_hwmod_data;
Expand All @@ -207,40 +319,58 @@ int __init omap_display_init(struct omap_dss_board_info *board_data)
oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
}

if (board_data->dsi_enable_pads == NULL)
board_data->dsi_enable_pads = omap_dsi_enable_pads;
if (board_data->dsi_disable_pads == NULL)
board_data->dsi_disable_pads = omap_dsi_disable_pads;

pdata.board_data = board_data;
pdata.board_data->get_context_loss_count =
omap_pm_get_dev_context_loss_count;
pdata.board_data->set_min_bus_tput = omap_dss_set_min_bus_tput;

for (i = 0; i < oh_count; i++) {
oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
if (!oh) {
pr_err("Could not look up %s\n",
curr_dss_hwmod[i].oh_name);
return -ENODEV;
/*
* First create the pdev for dss_core, which is used as a parent device
* by the other dss pdevs. Note: dss_core has to be the first item in
* the hwmod list.
*/
dss_pdev = create_dss_pdev(curr_dss_hwmod[0].dev_name,
curr_dss_hwmod[0].id,
curr_dss_hwmod[0].oh_name,
board_data, sizeof(*board_data),
NULL);

if (IS_ERR(dss_pdev)) {
pr_err("Could not build omap_device for %s\n",
curr_dss_hwmod[0].oh_name);

return PTR_ERR(dss_pdev);
}

for (i = 1; i < oh_count; i++) {
pdev = create_dss_pdev(curr_dss_hwmod[i].dev_name,
curr_dss_hwmod[i].id,
curr_dss_hwmod[i].oh_name,
board_data, sizeof(*board_data),
dss_pdev);

if (IS_ERR(pdev)) {
pr_err("Could not build omap_device for %s\n",
curr_dss_hwmod[i].oh_name);

return PTR_ERR(pdev);
}
}

pdev = omap_device_build(curr_dss_hwmod[i].dev_name,
curr_dss_hwmod[i].id, oh, &pdata,
sizeof(struct omap_display_platform_data),
NULL, 0, 0);
/* Create devices for DPI and SDI */

if (WARN((IS_ERR(pdev)), "Could not build omap_device for %s\n",
curr_dss_hwmod[i].oh_name))
return -ENODEV;
pdev = create_simple_dss_pdev("omapdss_dpi", -1,
board_data, sizeof(*board_data), dss_pdev);
if (IS_ERR(pdev)) {
pr_err("Could not build platform_device for omapdss_dpi\n");
return PTR_ERR(pdev);
}
omap_display_device.dev.platform_data = board_data;

r = platform_device_register(&omap_display_device);
if (r < 0)
printk(KERN_ERR "Unable to register OMAP-Display device\n");
if (cpu_is_omap34xx()) {
pdev = create_simple_dss_pdev("omapdss_sdi", -1,
board_data, sizeof(*board_data), dss_pdev);
if (IS_ERR(pdev)) {
pr_err("Could not build platform_device for omapdss_sdi\n");
return PTR_ERR(pdev);
}
}

return r;
return 0;
}

static void dispc_disable_outputs(void)
Expand Down
76 changes: 40 additions & 36 deletions drivers/video/omap2/displays/panel-tfp410.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ struct panel_drv_data {
struct mutex lock;

int pd_gpio;
};

static inline struct tfp410_platform_data
*get_pdata(const struct omap_dss_device *dssdev)
{
return dssdev->data;
}
struct i2c_adapter *i2c_adapter;
};

static int tfp410_power_on(struct omap_dss_device *dssdev)
{
Expand All @@ -68,7 +64,7 @@ static int tfp410_power_on(struct omap_dss_device *dssdev)
goto err0;

if (gpio_is_valid(ddata->pd_gpio))
gpio_set_value(ddata->pd_gpio, 1);
gpio_set_value_cansleep(ddata->pd_gpio, 1);

return 0;
err0:
Expand All @@ -83,18 +79,18 @@ static void tfp410_power_off(struct omap_dss_device *dssdev)
return;

if (gpio_is_valid(ddata->pd_gpio))
gpio_set_value(ddata->pd_gpio, 0);
gpio_set_value_cansleep(ddata->pd_gpio, 0);

omapdss_dpi_display_disable(dssdev);
}

static int tfp410_probe(struct omap_dss_device *dssdev)
{
struct tfp410_platform_data *pdata = get_pdata(dssdev);
struct panel_drv_data *ddata;
int r;
int i2c_bus_num;

ddata = kzalloc(sizeof(*ddata), GFP_KERNEL);
ddata = devm_kzalloc(&dssdev->dev, sizeof(*ddata), GFP_KERNEL);
if (!ddata)
return -ENOMEM;

Expand All @@ -104,24 +100,47 @@ static int tfp410_probe(struct omap_dss_device *dssdev)
ddata->dssdev = dssdev;
mutex_init(&ddata->lock);

if (pdata)
if (dssdev->data) {
struct tfp410_platform_data *pdata = dssdev->data;

ddata->pd_gpio = pdata->power_down_gpio;
else
i2c_bus_num = pdata->i2c_bus_num;
} else {
ddata->pd_gpio = -1;
i2c_bus_num = -1;
}

if (gpio_is_valid(ddata->pd_gpio)) {
r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW,
"tfp410 pd");
if (r) {
dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n",
ddata->pd_gpio);
ddata->pd_gpio = -1;
return r;
}
}

if (i2c_bus_num != -1) {
struct i2c_adapter *adapter;

adapter = i2c_get_adapter(i2c_bus_num);
if (!adapter) {
dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
i2c_bus_num);
r = -EINVAL;
goto err_i2c;
}

ddata->i2c_adapter = adapter;
}

dev_set_drvdata(&dssdev->dev, ddata);

return 0;
err_i2c:
if (gpio_is_valid(ddata->pd_gpio))
gpio_free(ddata->pd_gpio);
return r;
}

static void __exit tfp410_remove(struct omap_dss_device *dssdev)
Expand All @@ -130,14 +149,15 @@ static void __exit tfp410_remove(struct omap_dss_device *dssdev)

mutex_lock(&ddata->lock);

if (ddata->i2c_adapter)
i2c_put_adapter(ddata->i2c_adapter);

if (gpio_is_valid(ddata->pd_gpio))
gpio_free(ddata->pd_gpio);

dev_set_drvdata(&dssdev->dev, NULL);

mutex_unlock(&ddata->lock);

kfree(ddata);
}

static int tfp410_enable(struct omap_dss_device *dssdev)
Expand Down Expand Up @@ -269,27 +289,17 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev,
u8 *edid, int len)
{
struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
struct tfp410_platform_data *pdata = get_pdata(dssdev);
struct i2c_adapter *adapter;
int r, l, bytes_read;

mutex_lock(&ddata->lock);

if (pdata->i2c_bus_num == 0) {
if (!ddata->i2c_adapter) {
r = -ENODEV;
goto err;
}

adapter = i2c_get_adapter(pdata->i2c_bus_num);
if (!adapter) {
dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
pdata->i2c_bus_num);
r = -EINVAL;
goto err;
}

l = min(EDID_LENGTH, len);
r = tfp410_ddc_read(adapter, edid, l, 0);
r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0);
if (r)
goto err;

Expand All @@ -299,7 +309,7 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev,
if (len > EDID_LENGTH && edid[0x7e] > 0) {
l = min(EDID_LENGTH, len - EDID_LENGTH);

r = tfp410_ddc_read(adapter, edid + EDID_LENGTH,
r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH,
l, EDID_LENGTH);
if (r)
goto err;
Expand All @@ -319,21 +329,15 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev,
static bool tfp410_detect(struct omap_dss_device *dssdev)
{
struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
struct tfp410_platform_data *pdata = get_pdata(dssdev);
struct i2c_adapter *adapter;
unsigned char out;
int r;

mutex_lock(&ddata->lock);

if (pdata->i2c_bus_num == 0)
goto out;

adapter = i2c_get_adapter(pdata->i2c_bus_num);
if (!adapter)
if (!ddata->i2c_adapter)
goto out;

r = tfp410_ddc_read(adapter, &out, 1, 0);
r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0);

mutex_unlock(&ddata->lock);

Expand Down
Loading

0 comments on commit 38137c8

Please sign in to comment.