Skip to content

Commit 4b8a531

Browse files
prabhakarladmchehab
authored andcommitted
[media] media: davinci: vpif: display: add V4L2-async support
Add support for asynchronous subdevice probing, using the v4l2-async API. The legacy synchronous mode is still supported too, which allows to gradually update drivers and platforms. Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Cc: Hans Verkuil <hans.verkuil@cisco.com> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Sakari Ailus <sakari.ailus@iki.fi> Cc: Mauro Carvalho Chehab <mchehab@redhat.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
1 parent 873229e commit 4b8a531

3 files changed

Lines changed: 132 additions & 83 deletions

File tree

‎drivers/media/platform/davinci/vpif_display.c‎

Lines changed: 128 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,18 +1618,112 @@ static int initialize_vpif(void)
16181618
return err;
16191619
}
16201620

1621+
static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1622+
struct v4l2_subdev *subdev,
1623+
struct v4l2_async_subdev *asd)
1624+
{
1625+
int i;
1626+
1627+
for (i = 0; i < vpif_obj.config->subdev_count; i++)
1628+
if (!strcmp(vpif_obj.config->subdevinfo[i].name,
1629+
subdev->name)) {
1630+
vpif_obj.sd[i] = subdev;
1631+
vpif_obj.sd[i]->grp_id = 1 << i;
1632+
return 0;
1633+
}
1634+
1635+
return -EINVAL;
1636+
}
1637+
1638+
static int vpif_probe_complete(void)
1639+
{
1640+
struct common_obj *common;
1641+
struct channel_obj *ch;
1642+
int j, err, k;
1643+
1644+
for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
1645+
ch = vpif_obj.dev[j];
1646+
/* Initialize field of the channel objects */
1647+
atomic_set(&ch->usrs, 0);
1648+
for (k = 0; k < VPIF_NUMOBJECTS; k++) {
1649+
ch->common[k].numbuffers = 0;
1650+
common = &ch->common[k];
1651+
common->io_usrs = 0;
1652+
common->started = 0;
1653+
spin_lock_init(&common->irqlock);
1654+
mutex_init(&common->lock);
1655+
common->numbuffers = 0;
1656+
common->set_addr = NULL;
1657+
common->ytop_off = 0;
1658+
common->ybtm_off = 0;
1659+
common->ctop_off = 0;
1660+
common->cbtm_off = 0;
1661+
common->cur_frm = NULL;
1662+
common->next_frm = NULL;
1663+
memset(&common->fmt, 0, sizeof(common->fmt));
1664+
common->numbuffers = config_params.numbuffers[k];
1665+
}
1666+
ch->initialized = 0;
1667+
if (vpif_obj.config->subdev_count)
1668+
ch->sd = vpif_obj.sd[0];
1669+
ch->channel_id = j;
1670+
if (j < 2)
1671+
ch->common[VPIF_VIDEO_INDEX].numbuffers =
1672+
config_params.numbuffers[ch->channel_id];
1673+
else
1674+
ch->common[VPIF_VIDEO_INDEX].numbuffers = 0;
1675+
1676+
memset(&ch->vpifparams, 0, sizeof(ch->vpifparams));
1677+
1678+
/* Initialize prio member of channel object */
1679+
v4l2_prio_init(&ch->prio);
1680+
ch->common[VPIF_VIDEO_INDEX].fmt.type =
1681+
V4L2_BUF_TYPE_VIDEO_OUTPUT;
1682+
ch->video_dev->lock = &common->lock;
1683+
video_set_drvdata(ch->video_dev, ch);
1684+
1685+
/* select output 0 */
1686+
err = vpif_set_output(vpif_obj.config, ch, 0);
1687+
if (err)
1688+
goto probe_out;
1689+
1690+
/* register video device */
1691+
vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n",
1692+
(int)ch, (int)&ch->video_dev);
1693+
1694+
err = video_register_device(ch->video_dev,
1695+
VFL_TYPE_GRABBER, (j ? 3 : 2));
1696+
if (err < 0)
1697+
goto probe_out;
1698+
}
1699+
1700+
return 0;
1701+
1702+
probe_out:
1703+
for (k = 0; k < j; k++) {
1704+
ch = vpif_obj.dev[k];
1705+
video_unregister_device(ch->video_dev);
1706+
video_device_release(ch->video_dev);
1707+
ch->video_dev = NULL;
1708+
}
1709+
return err;
1710+
}
1711+
1712+
static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1713+
{
1714+
return vpif_probe_complete();
1715+
}
1716+
16211717
/*
16221718
* vpif_probe: This function creates device entries by register itself to the
16231719
* V4L2 driver and initializes fields of each channel objects
16241720
*/
16251721
static __init int vpif_probe(struct platform_device *pdev)
16261722
{
16271723
struct vpif_subdev_info *subdevdata;
1628-
struct vpif_display_config *config;
1629-
int i, j = 0, k, err = 0;
1724+
int i, j = 0, err = 0;
16301725
int res_idx = 0;
16311726
struct i2c_adapter *i2c_adap;
1632-
struct common_obj *common;
16331727
struct channel_obj *ch;
16341728
struct video_device *vfd;
16351729
struct resource *res;
@@ -1708,11 +1802,9 @@ static __init int vpif_probe(struct platform_device *pdev)
17081802
size/2;
17091803
}
17101804
}
1711-
1712-
i2c_adap = i2c_get_adapter(1);
1713-
config = pdev->dev.platform_data;
1714-
subdev_count = config->subdev_count;
1715-
subdevdata = config->subdevinfo;
1805+
vpif_obj.config = pdev->dev.platform_data;
1806+
subdev_count = vpif_obj.config->subdev_count;
1807+
subdevdata = vpif_obj.config->subdevinfo;
17161808
vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
17171809
GFP_KERNEL);
17181810
if (vpif_obj.sd == NULL) {
@@ -1721,86 +1813,40 @@ static __init int vpif_probe(struct platform_device *pdev)
17211813
goto vpif_sd_error;
17221814
}
17231815

1724-
for (i = 0; i < subdev_count; i++) {
1725-
vpif_obj.sd[i] = v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1726-
i2c_adap,
1727-
&subdevdata[i].board_info,
1728-
NULL);
1729-
if (!vpif_obj.sd[i]) {
1730-
vpif_err("Error registering v4l2 subdevice\n");
1731-
err = -ENODEV;
1732-
goto probe_subdev_out;
1733-
}
1734-
1735-
if (vpif_obj.sd[i])
1736-
vpif_obj.sd[i]->grp_id = 1 << i;
1737-
}
1738-
1739-
for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
1740-
ch = vpif_obj.dev[j];
1741-
/* Initialize field of the channel objects */
1742-
atomic_set(&ch->usrs, 0);
1743-
for (k = 0; k < VPIF_NUMOBJECTS; k++) {
1744-
ch->common[k].numbuffers = 0;
1745-
common = &ch->common[k];
1746-
common->io_usrs = 0;
1747-
common->started = 0;
1748-
spin_lock_init(&common->irqlock);
1749-
mutex_init(&common->lock);
1750-
common->numbuffers = 0;
1751-
common->set_addr = NULL;
1752-
common->ytop_off = common->ybtm_off = 0;
1753-
common->ctop_off = common->cbtm_off = 0;
1754-
common->cur_frm = common->next_frm = NULL;
1755-
memset(&common->fmt, 0, sizeof(common->fmt));
1756-
common->numbuffers = config_params.numbuffers[k];
1816+
if (!vpif_obj.config->asd_sizes) {
1817+
i2c_adap = i2c_get_adapter(1);
1818+
for (i = 0; i < subdev_count; i++) {
1819+
vpif_obj.sd[i] =
1820+
v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1821+
i2c_adap,
1822+
&subdevdata[i].
1823+
board_info,
1824+
NULL);
1825+
if (!vpif_obj.sd[i]) {
1826+
vpif_err("Error registering v4l2 subdevice\n");
1827+
goto probe_subdev_out;
1828+
}
17571829

1830+
if (vpif_obj.sd[i])
1831+
vpif_obj.sd[i]->grp_id = 1 << i;
1832+
}
1833+
vpif_probe_complete();
1834+
} else {
1835+
vpif_obj.notifier.subdev = vpif_obj.config->asd;
1836+
vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1837+
vpif_obj.notifier.bound = vpif_async_bound;
1838+
vpif_obj.notifier.complete = vpif_async_complete;
1839+
err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1840+
&vpif_obj.notifier);
1841+
if (err) {
1842+
vpif_err("Error registering async notifier\n");
1843+
err = -EINVAL;
1844+
goto probe_subdev_out;
17581845
}
1759-
ch->initialized = 0;
1760-
if (subdev_count)
1761-
ch->sd = vpif_obj.sd[0];
1762-
ch->channel_id = j;
1763-
if (j < 2)
1764-
ch->common[VPIF_VIDEO_INDEX].numbuffers =
1765-
config_params.numbuffers[ch->channel_id];
1766-
else
1767-
ch->common[VPIF_VIDEO_INDEX].numbuffers = 0;
1768-
1769-
memset(&ch->vpifparams, 0, sizeof(ch->vpifparams));
1770-
1771-
/* Initialize prio member of channel object */
1772-
v4l2_prio_init(&ch->prio);
1773-
ch->common[VPIF_VIDEO_INDEX].fmt.type =
1774-
V4L2_BUF_TYPE_VIDEO_OUTPUT;
1775-
ch->video_dev->lock = &common->lock;
1776-
video_set_drvdata(ch->video_dev, ch);
1777-
1778-
/* select output 0 */
1779-
err = vpif_set_output(config, ch, 0);
1780-
if (err)
1781-
goto probe_out;
1782-
1783-
/* register video device */
1784-
vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n",
1785-
(int)ch, (int)&ch->video_dev);
1786-
1787-
err = video_register_device(ch->video_dev,
1788-
VFL_TYPE_GRABBER, (j ? 3 : 2));
1789-
if (err < 0)
1790-
goto probe_out;
17911846
}
17921847

1793-
v4l2_info(&vpif_obj.v4l2_dev,
1794-
" VPIF display driver initialized\n");
17951848
return 0;
17961849

1797-
probe_out:
1798-
for (k = 0; k < j; k++) {
1799-
ch = vpif_obj.dev[k];
1800-
video_unregister_device(ch->video_dev);
1801-
video_device_release(ch->video_dev);
1802-
ch->video_dev = NULL;
1803-
}
18041850
probe_subdev_out:
18051851
kfree(vpif_obj.sd);
18061852
vpif_sd_error:

‎drivers/media/platform/davinci/vpif_display.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ struct vpif_device {
148148
struct v4l2_device v4l2_dev;
149149
struct channel_obj *dev[VPIF_DISPLAY_NUM_CHANNELS];
150150
struct v4l2_subdev **sd;
151-
151+
struct v4l2_async_notifier notifier;
152+
struct vpif_display_config *config;
152153
};
153154

154155
struct vpif_config_params {

‎include/media/davinci/vpif_types.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct vpif_display_config {
5959
int subdev_count;
6060
struct vpif_display_chan_config chan_config[VPIF_DISPLAY_MAX_CHANNELS];
6161
const char *card_name;
62+
struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */
63+
int *asd_sizes; /* 0-terminated array of asd group sizes */
6264
};
6365

6466
struct vpif_input {

0 commit comments

Comments
 (0)