All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis de Oliveira <Luis.Oliveira@synopsys.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Sakari Ailus <sakari.ailus@iki.fi>
Cc: Luis Oliveira <Luis.Oliveira@synopsys.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Rob Herring <robh@kernel.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	"paulmck@linux.ibm.com" <paulmck@linux.ibm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	"Kishon Vijay Abraham I" <kishon@ti.com>,
	devicetree <devicetree@vger.kernel.org>,
	"Linux Media Mailing List" <linux-media@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Joao Pinto <Joao.Pinto@synopsys.com>
Subject: RE: [v4 2/6] media: platform: dwc: Add MIPI CSI-2 controller driver
Date: Mon, 12 Aug 2019 09:45:15 +0000	[thread overview]
Message-ID: <MN2PR12MB3710E54A1E4BA4FD3AD77B87CBD30@MN2PR12MB3710.namprd12.prod.outlook.com> (raw)
In-Reply-To: <CAHp75VeutP=W43GHtY+FKvVGjBnQrF+nKbdaq_QXy8ZCoS=k1g@mail.gmail.com>

Hi Sakari, Andy,

From: Andy Shevchenko <andy.shevchenko@gmail.com>
Date: Sat, Aug 10, 2019 at 14:09:21

> On Fri, Aug 9, 2019 at 5:38 PM Sakari Ailus <sakari.ailus@iki.fi> wrote:
> > On Tue, Jun 11, 2019 at 09:20:51PM +0200, Luis Oliveira wrote:
> > > Add the Synopsys MIPI CSI-2 controller driver. This
> > > controller driver is divided in platform functions and core functions.
> > > This way it serves as platform for future DesignWare drivers.
> 
> > > +const struct mipi_dt csi_dt[] = {
> >
> > Make this static or use a common prefix that somehow resembles the name
> > name of the driver.

I will do it.

> >
> > > +     {
> > > +             .hex = CSI_2_YUV420_8,
> > > +             .name = "YUV420_8bits",
> > > +     }, {
> > > +             .hex = CSI_2_YUV420_10,
> > > +             .name = "YUV420_10bits",
> > > +     }, {
> > > +             .hex = CSI_2_YUV420_8_LEG,
> > > +             .name = "YUV420_8bits_LEGACY",
> > > +     }, {
> > > +             .hex = CSI_2_YUV420_8_SHIFT,
> > > +             .name = "YUV420_8bits_SHIFT",
> > > +     }, {
> > > +             .hex = CSI_2_YUV420_10_SHIFT,
> > > +             .name = "YUV420_10bits_SHIFT",
> > > +     }, {
> > > +             .hex = CSI_2_YUV422_8,
> > > +             .name = "YUV442_8bits",
> > > +     }, {
> > > +             .hex = CSI_2_YUV422_10,
> > > +             .name = "YUV442_10bits",
> > > +     }, {
> > > +             .hex = CSI_2_RGB444,
> > > +             .name = "RGB444",
> > > +     }, {
> > > +             .hex = CSI_2_RGB555,
> > > +             .name = "RGB555",
> > > +     }, {
> > > +             .hex = CSI_2_RGB565,
> > > +             .name = "RGB565",
> > > +     }, {
> > > +             .hex = CSI_2_RGB666,
> > > +             .name = "RGB666",
> > > +     }, {
> > > +             .hex = CSI_2_RGB888,
> > > +             .name = "RGB888",
> > > +     }, {
> > > +             .hex = CSI_2_RAW6,
> > > +             .name = "RAW6",
> > > +     }, {
> > > +             .hex = CSI_2_RAW7,
> > > +             .name = "RAW7",
> > > +     }, {
> > > +             .hex = CSI_2_RAW8,
> > > +             .name = "RAW8",
> > > +     }, {
> > > +             .hex = CSI_2_RAW10,
> > > +             .name = "RAW10",
> > > +     }, {
> > > +             .hex = CSI_2_RAW12,
> > > +             .name = "RAW12",
> > > +     }, {
> > > +             .hex = CSI_2_RAW14,
> > > +             .name = "RAW14",
> > > +     }, {
> > > +             .hex = CSI_2_RAW16,
> > > +             .name = "RAW16",
> > > +     },
> > > +};
> 
> One may utilize __stringify() macro and do somelike
> 
> #define CSI_FMT_DESC(fmt) \
>  { .hex = CSI_2_##fmt, .name = __stringify(fmt), }
> 
> And do
> 
>  CSI_FMT_DESC(RAW16),
> 
> etc.
> 

Great, thanks! 

> > > +             return cfg ? v4l2_subdev_get_try_format(&dev->sd,
> > > +                                                     cfg,
> > > +                                                     0) : NULL;
> 
> This indentation looks ugly.
> I would rather put this on one line.
> 
> > > +     dev_dbg(dev->dev,
> > > +             "%s got v4l2_mbus_pixelcode. 0x%x\n", __func__,
> > > +             dev->format.code);
> > > +     dev_dbg(dev->dev,
> > > +             "%s got width. 0x%x\n", __func__,
> > > +             dev->format.width);
> > > +     dev_dbg(dev->dev,
> > > +             "%s got height. 0x%x\n", __func__,
> > > +             dev->format.height);
> 
> __func__ is usually redundant (if Dynamic Debug in use it can be
> switched at run-time).
> 

That's true, I don't need it.

> > I'd just omit these debug prints in a driver. But adding them to the
> > framework might make sense. We don't have a lot of debug prints dealing
> > with user parameters in there. OTOH the common test programs largely do the
> > same already.
> 
> I would rather see tracepoints instead of debug prints if we are
> talking about generic solution for entire framework.
> 

I will check that.

> >
> > > +     return &dev->format;
> > > +}
> 
> > > +     struct mipi_fmt *dev_fmt;
> 
> This is simple bad name. We have dev_fmt() macro. I would rather avoid
> potential collisions.

True, I will change the name.

> 
> > > +     struct v4l2_mbus_framefmt *mf;
> > > +
> > > +     mf = dw_mipi_csi_get_format(dev, cfg, fmt->which);
> > > +     if (!mf)
> > > +             return -EINVAL;
> 
> Can't you rather return an error pointer in this and similar cases?
> 

Yes, ofc.

> > > +     dev_vdbg(dev->dev, "%s: on=%d\n", __func__, on);
> 
> This is noise. If you would like to debug Function Tracer is a good start.
> 

Ok.

> > > +     of_id = of_match_node(dw_mipi_csi_of_match, dev->of_node);
> > > +     if (!of_id)
> > > +             return -EINVAL;
> 
> Is it possible to have this asserted?
> 

I will remove it.
 
> > > +     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> 
> > > +     if (!res)
> > > +             return -ENXIO;
> 
> Redundant. Below does the check for you.
> 

Yep, thanks.

> > > +
> > > +     csi->base_address = devm_ioremap_resource(dev, res);
> > > +     if (IS_ERR(csi->base_address)) {
> 
> > > +             dev_err(dev, "Base address not set.\n");
> 
> Redundant. Above does print an error message for you.
> 

Ok.

> > > +             return PTR_ERR(csi->base_address);
> > > +     }
> 
> Moreover, use devm_platform_ioremap_resource() instead of both.
> 

Nice, thanks.

> > > +     csi->ctrl_irq_number = platform_get_irq(pdev, 0);
> > > +     if (csi->ctrl_irq_number < 0) {
> 
> > > +             dev_err(dev, "irq number %d not set.\n", csi->ctrl_irq_number);
> 
> Redundant since this cycle (v5.4).
> 

Ok,

> > > +             ret = csi->ctrl_irq_number;
> 
> Better to do the opposite
> 
> ret = platform_get_irq();
> if (ret)
>  goto end;
> ... = ret;
> 
> > > +             goto end;
> > > +     }
> 
> > > +     ret = devm_request_irq(dev, csi->ctrl_irq_number,
> > > +                            dw_mipi_csi_irq1, IRQF_SHARED,
> > > +                            dev_name(dev), csi);
> > > +     if (ret) {
> > > +             dev_err(dev, "irq csi %s failed\n", of_id->name);
> > > +
> > > +             goto end;
> > > +     }
> 
> devm_*irq() might be a bad idea. Is it race free in your driver?
> 

I never thought about it like that. Should I use request_irq and 
free_irq? 

> > > +static const struct of_device_id dw_mipi_csi_of_match[] = {
> > > +     { .compatible = "snps,dw-csi" },
> 
> > > +     {},
> 
> Better without comma. Terminator may terminate even at compile time.
> 

Ok.
> > > +};
> 
> > > +static ssize_t core_version_show(struct device *dev,
> > > +                              struct device_attribute *attr,
> > > +                              char *buf)
> > > +{
> > > +     struct platform_device *pdev = to_platform_device(dev);
> > > +     struct v4l2_subdev *sd = platform_get_drvdata(pdev);
> > > +     struct dw_csi *csi_dev = sd_to_mipi_csi_dev(sd);
> 
> > > +
> > > +     char buffer[10];
> > > +
> > > +     snprintf(buffer, 10, "v.%d.%d*\n", csi_dev->hw_version_major,
> > > +              csi_dev->hw_version_minor);
> > > +
> > > +     return strlcpy(buf, buffer, PAGE_SIZE);
> 
> Oh, can't you simple without any temprorary useless buffers?
>  sprintf(buf, ...)?
> (Yes, note _absence_ of *n* there)

You are right.
> 
> > > +}
> 
> > > +static ssize_t n_lanes_store(struct device *dev, struct device_attribute *attr,
> > > +                          const char *buf, size_t count)
> > > +{
> > > +     int ret;
> > > +     unsigned long lanes;
> 
> > > +
> 
> More blank lines! We need them!
> 

Ok.

> > > +     struct platform_device *pdev = to_platform_device(dev);
> > > +     struct v4l2_subdev *sd = platform_get_drvdata(pdev);
> > > +     struct dw_csi *csi_dev = sd_to_mipi_csi_dev(sd);
> > > +
> > > +     ret = kstrtoul(buf, 10, &lanes);
> > > +     if (ret < 0)
> > > +             return ret;
> 
> Can it return positive number?
> 
> > > +     dev_info(dev, "Lanes %lu\n", lanes);
> 
> Noise.
> The user gets it, why to spam kernel log???
> 
Ok.

> > > +     csi_dev->hw.num_lanes = lanes;
> > > +
> > > +     return count;
> > > +}
> 
> I told once, can repeat again. Synopsys perhaps needs better reviews
> inside company. Each time I see the code, it repeats same mistakes
> over and over. Have you, guys, do something about it?

We are working on it. It will get better, sorry.
> 
> -- 
> With Best Regards,
> Andy Shevchenko

Thanks,
Luis

  reply	other threads:[~2019-08-12  9:45 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 19:20 [v4 0/6] platform: dwc: Adding DesignWare MIPI CSI-2 Host and D-PHY Luis Oliveira
2019-06-11 19:20 ` [v4 1/6] dt-bindings: media: Document bindings for DW MIPI CSI-2 Host Luis Oliveira
2019-06-28 14:13   ` Sakari Ailus
2019-07-08 15:21     ` Luis de Oliveira
2019-07-09 18:25       ` Sakari Ailus
2019-07-10 10:20         ` Luis de Oliveira
2019-07-25 20:02           ` Sakari Ailus
2019-07-26  9:50             ` Luis de Oliveira
2019-07-26 11:13               ` Eugen.Hristev
2019-07-26 11:13                 ` Eugen.Hristev
2019-07-09 14:33   ` Eugen.Hristev
2019-07-09 14:33     ` Eugen.Hristev
2019-07-09 17:08     ` Luis de Oliveira
2019-07-10  6:53       ` Eugen.Hristev
2019-07-10  6:53         ` Eugen.Hristev
2019-07-10 10:23         ` Luis de Oliveira
2019-06-11 19:20 ` [v4 2/6] media: platform: dwc: Add MIPI CSI-2 controller driver Luis Oliveira
2019-07-10  8:59   ` Eugen.Hristev
2019-07-10  8:59     ` Eugen.Hristev
2019-07-10 14:21     ` Luis de Oliveira
2019-08-09 14:10   ` Sakari Ailus
2019-08-10 13:09     ` Andy Shevchenko
2019-08-12  9:45       ` Luis de Oliveira [this message]
2019-08-12 16:50         ` Andy Shevchenko
2019-06-11 19:20 ` [v4 3/6] media: platform: dwc: Add MIPI CSI-2 platform data Luis Oliveira
2019-08-09 14:39   ` Sakari Ailus
2019-06-11 19:20 ` [v4 4/6] dt-bindings: phy: Document the Synopsys MIPI DPHY Rx bindings Luis Oliveira
2019-07-09 14:20   ` Rob Herring
2019-07-09 16:28     ` Luis de Oliveira
2019-07-10 13:50       ` Rob Herring
2019-08-09 14:42   ` Sakari Ailus
2019-08-09 14:45     ` Sakari Ailus
2019-08-09 14:47     ` Sakari Ailus
2019-06-11 19:20 ` [v4 5/6] media: platform: dwc: Add DW MIPI DPHY Rx driver Luis Oliveira
2019-06-11 19:20 ` [v4 6/6] media: platform: dwc: Add platform data support to D-Phy Luis Oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MN2PR12MB3710E54A1E4BA4FD3AD77B87CBD30@MN2PR12MB3710.namprd12.prod.outlook.com \
    --to=luis.oliveira@synopsys.com \
    --cc=Joao.Pinto@synopsys.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=paulmck@linux.ibm.com \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.