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

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Apr 30 21:45:31 EST 2013


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 at gmail.com>
> > 
> > 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



More information about the devicetree-discuss mailing list