Re: [PATCH RFC] media: i2c: mt9p031: add OF support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Sascha,

On Tuesday 30 April 2013 08:16:25 Sascha Hauer wrote:
> On Mon, Apr 29, 2013 at 01:30:01PM +0530, Prabhakar Lad wrote:
> > From: Lad, Prabhakar <prabhakar.csengg@xxxxxxxxx>
> > 
> > add OF support for the mt9p031 sensor driver.
> > 
> > +static struct mt9p031_platform_data
> > +	*mt9p031_get_pdata(struct i2c_client *client)
> > +
> > +{
> > +	if (!client->dev.platform_data && client->dev.of_node) {
> > +		struct device_node *np;
> > +		struct mt9p031_platform_data *pdata;
> > +		int ret;
> > +
> > +		np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL);
> > +		if (!np)
> > +			return NULL;
> > +
> > +		pdata = devm_kzalloc(&client->dev,
> > +				     sizeof(struct mt9p031_platform_data),
> > +				     GFP_KERNEL);
> > +		if (!pdata) {
> > +			pr_warn("mt9p031 failed allocate memeory\n");
> > +			return NULL;
> > +		}
> > +		ret = of_property_read_u32(np, "reset", &pdata->reset);
> > +		if (ret == -EINVAL)
> > +			pdata->reset = -1;
> > +		else if (ret == -ENODATA)
> > +			return NULL;
> > +
> > +		if (of_property_read_u32(np, "ext_freq", &pdata->ext_freq))
> > +			return NULL;
> > +
> > +		if (of_property_read_u32(np, "target_freq",
> > +					 &pdata->target_freq))
> > +			return NULL;
> > +
> > +		return pdata;
> > +	}
> 
> I don't know how the others see this, but IMO it would be cleaner to
> first add a duplicate of the members of pdata in struct mt9p031 and then
> initialize them either from pdata or from devicetree data. The
> (artificial) creation of platform_data for the devicetree case adds a
> new level of indirection. This may not be a problem here, but there are
> cases where there is no 1:1 transcription between pdata and devicetree
> possible.

I have no strong opinion on this. In the mt9p031 case it won't matter much, 
but it's probably a good idea in general.

-- 
Regards,

Laurent Pinchart

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux