Skip to contentSkip to conversation

staging: ak8975: add platform data.

RFC PATCH Jonathan Cameron 4 participants 7 messages Feb 21, 2011 – Feb 23, 2011 2 messages not in the archive IIO

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 6 lines · Andrew Chew
Quoted 2 lines

As some of the platform not support irq_to_gpio, we pass gpio port by platform data.

Looks good to me.

Firstly, please cc linux-iio for patches effecting iio drivers.

Hmm.. It's a bit of a pain that i2c devices don't take platform resources or we could avoid doing this entirely. I have a vague recollection of this being suggested in the past, but never happening (might have been for spi rather than i2c though...) Jean, can you comment on this?

Dmitry isn't going to want that header in the linux/input directory.

What we've done for other drivers that need simple platform data like this is to use a pointer to an int rather than creating a specific structure for passing the data. It's clunky but politically a lot simpler than having a driver with parts in staging and parts not (which won't happen). There were quite a few cases of this that we had to clean up before the subsystem was acceptable for staging in the first place.

For more complex cases, we have cases that really need platform data and have a chunk of of their local header in the tree that is commented to be moved to linux/iio/ when that exists and people are just cutting that out as necessary for their local development trees. We could add a directory under drivers/staging/iio for these to make this even clearer.

This whole patch highlights a point I'd originally missed when reviewing this driver. The irq is never used as an actual interrupt and hence should never have been passed like that in the first place.

Andrew, would you be happy with a patch that removed the miss use of the irq field entirely in favour of Tony's platform data route (with a simple int rather than the structure)? The interrupt passing would go back in if anyone ever added interrupt handling to this driver.

Jonathan

Quoted 81 lines
Quoted 75 lines
---
 drivers/staging/iio/magnetometer/ak8975.c |    8 +++++++-
 include/linux/input/ak8975.h              |   20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)
 create mode 100644 include/linux/input/ak8975.h
drivers/staging/iio/magnetometer/ak8975.c +7 -1
index 420f206..80c0f41 100644
@@ -29,6 +29,7 @@
 #include <linux/delay.h>
 
 #include <linux/gpio.h>
+#include <linux/input/ak8975.h>
 
 #include "../iio.h"
 #include "magnet.h"
@@ -435,6 +436,7 @@ static int ak8975_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
 	struct ak8975_data *data;
+	struct ak8975_platform_data *pdata;
 	int err;
 
 	/* Allocate our device context. */
@@ -452,7 +454,11 @@ static int ak8975_probe(struct 
 i2c_client *client,
 
 	/* Grab and set up the supplied GPIO. */
 	data->eoc_irq = client->irq;
-	data->eoc_gpio = irq_to_gpio(client->irq);
+	pdata = client->dev.platform_data;
+	if (pdata)
+		data->eoc_gpio = pdata->gpio;
+	else
+		data->eoc_gpio = irq_to_gpio(client->irq);
 
 	if (!data->eoc_gpio) {
drivers/staging/iio/magnetometer/ak8975.c +0 -0
 		dev_err(&client->dev, "failed, no valid GPIO\n");
include/linux/input/ak8975.h new file +8 -0
new file mode 100644
index 0000000..25d41eb
@@ -0,0 +1,20 @@
+/*
+ * ak8975 platform support
+ *
+ * Copyright (C) 2010 Renesas Solutions Corp.
+ *
+ * Author: Tony SIM <[email protected]>
+ *
+ * This program is free software; you can redistribute it 

and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */

include/linux/input/ak8975.h new file +9 -0
+
+#ifndef _AK8975_H
+#define _AK8975_H
+
+struct ak8975_platform_data {
+	int gpio;
+};
+
+#endif
Signature · 1 line
1.7.2.3

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#3 lore raw

Hi Jonathan,

Quoted 6 lines · Jonathan Cameron
Quoted 5 lines · Andrew Chew
Quoted 2 lines

As some of the platform not support irq_to_gpio, we pass gpio port by platform data.

Looks good to me.

Quoted 7 lines
Quoted 1 line

Firstly, please cc linux-iio for patches effecting iio drivers.

Hmm.. It's a bit of a pain that i2c devices don't take platform resources or we could avoid doing this entirely. I have a vague recollection of this being suggested in the past, but never happening (might have been for spi rather than i2c though...) Jean, can you comment on this?

I fear I don't have the slightest idea of what you're talking about. "Taking platform resources"?

Quoted 1 line

Dmitry isn't going to want that header in the linux/input directory.

And he would be right. Header files containing platform data structures for i2c device drivers go to include/linux/i2c.

Signature · 1 line
Jean Delvare
#4 lore raw
Quoted 12 lines · Jean Delvare

Hi Jonathan,

Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · Andrew Chew
Quoted 2 lines

As some of the platform not support irq_to_gpio, we pass gpio port by platform data.

Looks good to me.

Firstly, please cc linux-iio for patches effecting iio drivers.

Quoted 7 lines
Quoted 4 lines

Hmm.. It's a bit of a pain that i2c devices don't take platform resources or we could avoid doing this entirely. I have a vague recollection of this being suggested in the past, but never happening (might have been for spi rather than i2c though...) Jean, can you comment on this?

I fear I don't have the slightest idea of what you're talking about. "Taking platform resources"?

Sorry, I should have written a proper description of what I meant.

Add to i2c_board_info the following
struct resource *resource;

which is defined in ioport.h

I thought this actually allowed for gpio's but right now can't figure out how to handle them. What it definitely does handle cleanly is devices with multiple irq's.

You basically get to query for resources by name so can pass lots of 'platform data' type stuff without having to define a specific structure for passing it in.

Quoted 5 lines
Quoted 2 lines

Dmitry isn't going to want that header in the linux/input directory.

And he would be right. Header files containing platform data structures for i2c device drivers go to include/linux/i2c.

Cool. I'd kind of assumed they moved out when i2c/chips went away, but never actually checked!

Quoted 1 line
#5 lore raw
Quoted 6 lines · Jonathan Cameron

I thought this actually allowed for gpio's but right now can't figure out how to handle them. What it definitely does handle cleanly is devices with multiple irq's.

You basically get to query for resources by name so can pass lots of 'platform data' type stuff without having to define a specific structure for passing it in.

There's no standard support for GPIOs as resources - this is always done using platform data these days.

#6 lore raw
Quoted 11 lines · Mark Brown
Quoted 6 lines · Jonathan Cameron

I thought this actually allowed for gpio's but right now can't figure out how to handle them. What it definitely does handle cleanly is devices with multiple irq's.

You basically get to query for resources by name so can pass lots of 'platform data' type stuff without having to define a specific structure for passing it in.

There's no standard support for GPIOs as resources - this is always done using platform data these days.

Would it make sense to add this? I have no opinion on the question, not being a big user of GPIO, just wondering.

Signature · 1 line
Jean Delvare
#7 lore raw

Guys:

Quoted 6 lines · Jean Delvare
Quoted 2 lines · Mark Brown

There's no standard support for GPIOs as resources - this is always done using platform data these days.

Would it make sense to add this? I have no opinion on the question, not being a big user of GPIO, just wondering.

I for one would welcome an IORESOURCE_GPIO.

b.g.

Signature · 2 lines
Bill Gatliff
[email protected]
#8 lore raw
In reply to Jean Delvare
Quoted 7 lines · Jean Delvare
Quoted 2 lines · Mark Brown

There's no standard support for GPIOs as resources - this is always done using platform data these days.

Would it make sense to add this? I have no opinion on the question, not being a big user of GPIO, just wondering.

Possibly, yes.