Skip to content

Commit c98ba24

Browse files
Jacopo Mondipopcornmix
authored andcommitted
media: pxa_camera: Use the new set_mbus_config op
Upstream https://patchwork.linuxtv.org/patch/64671/ Move the PXA camera driver to use the new set_mbus_config pad operation. For this platform the change is not only cosmetic, as the pxa driver is currently the only driver in mainline to make use of the g_mbus_config and s_mbus_config video operations. The existing driver semantic is the following: - Collect all supported mbus config flags from the remote end - Match them with the supported PXA mbus configuration flags - If the remote subdevice allows multiple options for for VSYNC, HSYNC and PCLK polarity, use platform data requested settings The semantic of the new get_mbus_config and set_mbus_config differs from the corresponding video ops, particularly in the fact get_mbus_config reports the current mbus configuration and not the set of supported configuration options, with set_mbus_config always reporting the actual mbus configuration applied to the remote subdevice. Adapt the driver to perform the following - Set the remote subdevice mbus configuration according to the PXA platform data preferences. - If the applied configuration differs from the requested one (i.e. the remote subdevice does not allow changing one setting) make sure that - The remote end does not claim for DATA_ACTIVE_LOW, which seems not supported by the platform - The bus mastering roles match While at there remove a few checks performed on the media bus configuration at get_format() time as they do not belong there. Compile-tested only. Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
1 parent 77755e0 commit c98ba24

1 file changed

Lines changed: 51 additions & 138 deletions

File tree

‎drivers/media/platform/pxa_camera.c‎

Lines changed: 51 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -605,42 +605,6 @@ static const struct pxa_mbus_pixelfmt *pxa_mbus_get_fmtdesc(
605605
return pxa_mbus_find_fmtdesc(code, mbus_fmt, ARRAY_SIZE(mbus_fmt));
606606
}
607607

608-
static unsigned int pxa_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
609-
unsigned int flags)
610-
{
611-
unsigned long common_flags;
612-
bool hsync = true, vsync = true, pclk, data, mode;
613-
bool mipi_lanes, mipi_clock;
614-
615-
common_flags = cfg->flags & flags;
616-
617-
switch (cfg->type) {
618-
case V4L2_MBUS_PARALLEL:
619-
hsync = common_flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
620-
V4L2_MBUS_HSYNC_ACTIVE_LOW);
621-
vsync = common_flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH |
622-
V4L2_MBUS_VSYNC_ACTIVE_LOW);
623-
/* fall through */
624-
case V4L2_MBUS_BT656:
625-
pclk = common_flags & (V4L2_MBUS_PCLK_SAMPLE_RISING |
626-
V4L2_MBUS_PCLK_SAMPLE_FALLING);
627-
data = common_flags & (V4L2_MBUS_DATA_ACTIVE_HIGH |
628-
V4L2_MBUS_DATA_ACTIVE_LOW);
629-
mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
630-
return (!hsync || !vsync || !pclk || !data || !mode) ?
631-
0 : common_flags;
632-
case V4L2_MBUS_CSI2_DPHY:
633-
mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
634-
mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
635-
V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
636-
return (!mipi_lanes || !mipi_clock) ? 0 : common_flags;
637-
default:
638-
WARN_ON(1);
639-
return -EINVAL;
640-
}
641-
return 0;
642-
}
643-
644608
/**
645609
* struct pxa_camera_format_xlate - match between host and sensor formats
646610
* @code: code of a sensor provided format
@@ -1231,31 +1195,6 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
12311195
return IRQ_HANDLED;
12321196
}
12331197

1234-
static int test_platform_param(struct pxa_camera_dev *pcdev,
1235-
unsigned char buswidth, unsigned long *flags)
1236-
{
1237-
/*
1238-
* Platform specified synchronization and pixel clock polarities are
1239-
* only a recommendation and are only used during probing. The PXA270
1240-
* quick capture interface supports both.
1241-
*/
1242-
*flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
1243-
V4L2_MBUS_MASTER : V4L2_MBUS_SLAVE) |
1244-
V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1245-
V4L2_MBUS_HSYNC_ACTIVE_LOW |
1246-
V4L2_MBUS_VSYNC_ACTIVE_HIGH |
1247-
V4L2_MBUS_VSYNC_ACTIVE_LOW |
1248-
V4L2_MBUS_DATA_ACTIVE_HIGH |
1249-
V4L2_MBUS_PCLK_SAMPLE_RISING |
1250-
V4L2_MBUS_PCLK_SAMPLE_FALLING;
1251-
1252-
/* If requested data width is supported by the platform, use it */
1253-
if ((1 << (buswidth - 1)) & pcdev->width_flags)
1254-
return 0;
1255-
1256-
return -EINVAL;
1257-
}
1258-
12591198
static void pxa_camera_setup_cicr(struct pxa_camera_dev *pcdev,
12601199
unsigned long flags, __u32 pixfmt)
12611200
{
@@ -1598,99 +1537,78 @@ static int pxa_camera_init_videobuf2(struct pxa_camera_dev *pcdev)
15981537
*/
15991538
static int pxa_camera_set_bus_param(struct pxa_camera_dev *pcdev)
16001539
{
1540+
unsigned int bus_width = pcdev->current_fmt->host_fmt->bits_per_sample;
16011541
struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
16021542
u32 pixfmt = pcdev->current_fmt->host_fmt->fourcc;
1603-
unsigned long bus_flags, common_flags;
1543+
int mbus_config;
16041544
int ret;
16051545

1606-
ret = test_platform_param(pcdev,
1607-
pcdev->current_fmt->host_fmt->bits_per_sample,
1608-
&bus_flags);
1609-
if (ret < 0)
1610-
return ret;
1611-
1612-
ret = sensor_call(pcdev, video, g_mbus_config, &cfg);
1613-
if (!ret) {
1614-
common_flags = pxa_mbus_config_compatible(&cfg,
1615-
bus_flags);
1616-
if (!common_flags) {
1617-
dev_warn(pcdev_to_dev(pcdev),
1618-
"Flags incompatible: camera 0x%x, host 0x%lx\n",
1619-
cfg.flags, bus_flags);
1620-
return -EINVAL;
1621-
}
1622-
} else if (ret != -ENOIOCTLCMD) {
1623-
return ret;
1624-
} else {
1625-
common_flags = bus_flags;
1546+
if (!((1 << (bus_width - 1)) & pcdev->width_flags)) {
1547+
dev_err(pcdev_to_dev(pcdev), "Unsupported bus width %u",
1548+
bus_width);
1549+
return -EINVAL;
16261550
}
16271551

16281552
pcdev->channels = 1;
16291553

16301554
/* Make choices, based on platform preferences */
1631-
if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
1632-
(common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
1633-
if (pcdev->platform_flags & PXA_CAMERA_HSP)
1634-
common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
1635-
else
1636-
common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
1637-
}
1555+
mbus_config = 0;
1556+
if (pcdev->platform_flags & PXA_CAMERA_MASTER)
1557+
mbus_config |= V4L2_MBUS_MASTER;
1558+
else
1559+
mbus_config |= V4L2_MBUS_SLAVE;
16381560

1639-
if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
1640-
(common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
1641-
if (pcdev->platform_flags & PXA_CAMERA_VSP)
1642-
common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1643-
else
1644-
common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
1645-
}
1561+
if (pcdev->platform_flags & PXA_CAMERA_HSP)
1562+
mbus_config |= V4L2_MBUS_HSYNC_ACTIVE_HIGH;
1563+
else
1564+
mbus_config |= V4L2_MBUS_HSYNC_ACTIVE_LOW;
16461565

1647-
if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1648-
(common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
1649-
if (pcdev->platform_flags & PXA_CAMERA_PCP)
1650-
common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
1651-
else
1652-
common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
1653-
}
1566+
if (pcdev->platform_flags & PXA_CAMERA_VSP)
1567+
mbus_config |= V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1568+
else
1569+
mbus_config |= V4L2_MBUS_VSYNC_ACTIVE_LOW;
16541570

1655-
cfg.flags = common_flags;
1656-
ret = sensor_call(pcdev, video, s_mbus_config, &cfg);
1571+
if (pcdev->platform_flags & PXA_CAMERA_PCP)
1572+
mbus_config |= V4L2_MBUS_PCLK_SAMPLE_RISING;
1573+
else
1574+
mbus_config |= V4L2_MBUS_PCLK_SAMPLE_FALLING;
1575+
mbus_config |= V4L2_MBUS_DATA_ACTIVE_HIGH;
1576+
1577+
cfg.flags = mbus_config;
1578+
ret = sensor_call(pcdev, pad, set_mbus_config, 0, &cfg);
16571579
if (ret < 0 && ret != -ENOIOCTLCMD) {
1658-
dev_dbg(pcdev_to_dev(pcdev),
1659-
"camera s_mbus_config(0x%lx) returned %d\n",
1660-
common_flags, ret);
1580+
dev_err(pcdev_to_dev(pcdev),
1581+
"Failed to call set_mbus_config: %d\n", ret);
16611582
return ret;
16621583
}
16631584

1664-
pxa_camera_setup_cicr(pcdev, common_flags, pixfmt);
1665-
1666-
return 0;
1667-
}
1668-
1669-
static int pxa_camera_try_bus_param(struct pxa_camera_dev *pcdev,
1670-
unsigned char buswidth)
1671-
{
1672-
struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1673-
unsigned long bus_flags, common_flags;
1674-
int ret = test_platform_param(pcdev, buswidth, &bus_flags);
1675-
1676-
if (ret < 0)
1677-
return ret;
1585+
/*
1586+
* If the requested media bus configuration has not been fully applied
1587+
* make sure it is supported by the platform.
1588+
*
1589+
* PXA does not support V4L2_MBUS_DATA_ACTIVE_LOW and the bus mastering
1590+
* roles should match.
1591+
*/
1592+
if (cfg.flags != mbus_config) {
1593+
unsigned int pxa_mbus_role = mbus_config & (V4L2_MBUS_MASTER |
1594+
V4L2_MBUS_SLAVE);
1595+
if (pxa_mbus_role != (cfg.flags & (V4L2_MBUS_MASTER |
1596+
V4L2_MBUS_SLAVE))) {
1597+
dev_err(pcdev_to_dev(pcdev),
1598+
"Unsupported mbus configuration: bus mastering\n");
1599+
return -EINVAL;
1600+
}
16781601

1679-
ret = sensor_call(pcdev, video, g_mbus_config, &cfg);
1680-
if (!ret) {
1681-
common_flags = pxa_mbus_config_compatible(&cfg,
1682-
bus_flags);
1683-
if (!common_flags) {
1684-
dev_warn(pcdev_to_dev(pcdev),
1685-
"Flags incompatible: camera 0x%x, host 0x%lx\n",
1686-
cfg.flags, bus_flags);
1602+
if (cfg.flags & V4L2_MBUS_DATA_ACTIVE_LOW) {
1603+
dev_err(pcdev_to_dev(pcdev),
1604+
"Unsupported mbus configuration: DATA_ACTIVE_LOW\n");
16871605
return -EINVAL;
16881606
}
1689-
} else if (ret == -ENOIOCTLCMD) {
1690-
ret = 0;
16911607
}
16921608

1693-
return ret;
1609+
pxa_camera_setup_cicr(pcdev, cfg.flags, pixfmt);
1610+
1611+
return 0;
16941612
}
16951613

16961614
static const struct pxa_mbus_pixelfmt pxa_camera_formats[] = {
@@ -1738,11 +1656,6 @@ static int pxa_camera_get_formats(struct v4l2_device *v4l2_dev,
17381656
return 0;
17391657
}
17401658

1741-
/* This also checks support for the requested bits-per-sample */
1742-
ret = pxa_camera_try_bus_param(pcdev, fmt->bits_per_sample);
1743-
if (ret < 0)
1744-
return 0;
1745-
17461659
switch (code.code) {
17471660
case MEDIA_BUS_FMT_UYVY8_2X8:
17481661
formats++;

0 commit comments

Comments
 (0)