Linux Input/HID development
 help / color / mirror / Atom feed
* Re: [PATCH 3/3] IO: hid-sensor-magn-3d: Add in support for True/Magnetic North HID usages
From: Srinivas Pandruvada @ 2014-05-28 21:25 UTC (permalink / raw)
  To: Reyad Attiyat; +Cc: linux-kernel, linux-iio, jic23, linux-input, Jiri Kosina
In-Reply-To: <CA+BWVUQEsprV1jEzD9D0hidR0jvYeSRVGT=ESzstR4apa+nV1A@mail.gmail.com>

On 05/28/2014 02:15 PM, Reyad Attiyat wrote:
>> +static void sensor_hub_fill_attr_info(
>> +               struct hid_sensor_hub_attribute_info *info,
>> +               s32 index, s32 report_id, struct hid_field *field)
>> +{
>> +       info->index = index;
>> +       info->report_id = report_id;
>> +       info->units = field->unit;
>> +       info->unit_expo = field->unit_exponent;
>> +       info->size = (field->report_size * field->report_count)/8;
>> +       info->logical_minimum = field->logical_minimum;
>> +       info->logical_maximum = field->logical_maximum;
>>   }
> I copied this function from hid/hid-sensor-hub.c as it is marked
> static in that file. I use it to fill attributes as I find them.
> Should I create an another patch to make it non-static?

I didn't check your implementation. But 
sensor_hub_input_get_attribute_info()
function is not enough? We are already using to get other attributes for 
x, y and Z.

Thanks,
Srinivas


>> +       list_for_each_entry(report, &report_enum->report_list, list) {
>> +               for (i = 0; i < report->maxfield; ++i) {
>> +                       field = report->field[i];
>> +
>> +                       for (j = 0; j < field->maxusage; j++) {
>> +                               usage = &(field->usage[j]);
>> +
> This is how I mange to find all possible hid reports in the parse
> reports function. I noticed that in the other function that was used,
> sensor_hub_input_get_attribute_info(),  it only uses field->usage[0].
> Is there a reason for this and should I change my current
> implementation?
>


^ permalink raw reply

* Re: [PATCH 3/3] IO: hid-sensor-magn-3d: Add in support for True/Magnetic North HID usages
From: Reyad Attiyat @ 2014-05-28 21:15 UTC (permalink / raw)
  To: linux-kernel, linux-iio, jic23, Srinivas Pandruvada, linux-input,
	Jiri Kosina
  Cc: Reyad Attiyat
In-Reply-To: <1401311175-12784-4-git-send-email-reyad.attiyat@gmail.com>

> +static void sensor_hub_fill_attr_info(
> +               struct hid_sensor_hub_attribute_info *info,
> +               s32 index, s32 report_id, struct hid_field *field)
> +{
> +       info->index = index;
> +       info->report_id = report_id;
> +       info->units = field->unit;
> +       info->unit_expo = field->unit_exponent;
> +       info->size = (field->report_size * field->report_count)/8;
> +       info->logical_minimum = field->logical_minimum;
> +       info->logical_maximum = field->logical_maximum;
>  }

I copied this function from hid/hid-sensor-hub.c as it is marked
static in that file. I use it to fill attributes as I find them.
Should I create an another patch to make it non-static?

> +       list_for_each_entry(report, &report_enum->report_list, list) {
> +               for (i = 0; i < report->maxfield; ++i) {
> +                       field = report->field[i];
> +
> +                       for (j = 0; j < field->maxusage; j++) {
> +                               usage = &(field->usage[j]);
> +

This is how I mange to find all possible hid reports in the parse
reports function. I noticed that in the other function that was used,
sensor_hub_input_get_attribute_info(),  it only uses field->usage[0].
Is there a reason for this and should I change my current
implementation?

^ permalink raw reply

* [PATCH 3/3] IO: hid-sensor-magn-3d: Add in support for True/Magnetic North HID usages
From: Reyad Attiyat @ 2014-05-28 21:06 UTC (permalink / raw)
  To: linux-kernel, linux-iio, jic23, srinivas.pandruvada, linux-input,
	jkosina
  Cc: Reyad Attiyat
In-Reply-To: <1401311175-12784-1-git-send-email-reyad.attiyat@gmail.com>

Updated magn_3d_channel enum for all possible north channels

Added functions to setup iio_chan_spec array depending on
a hid usage report

Renamed magn_val to iio_val to differentiate the index being used

Updated magn_3d_state struct to hold pointer array (magn_val_addr[]) to
iio_val and a count of the iio channels found

Updated magn_3d_parse_report to scan for all compass usages
and create channels for each

Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 278 +++++++++++++++++---------
 1 file changed, 183 insertions(+), 95 deletions(-)

diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 6d162b7..7ffac17 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -34,63 +34,54 @@ enum magn_3d_channel {
 	CHANNEL_SCAN_INDEX_X,
 	CHANNEL_SCAN_INDEX_Y,
 	CHANNEL_SCAN_INDEX_Z,
+	CHANNEL_SCAN_INDEX_NORTH,
+	CHANNEL_SCAN_INDEX_NORTH_TRUE,
+	CHANNEL_SCAN_INDEX_NORTH_TILT_COMP,
+	CHANNEL_SCAN_INDEX_NORTH_TRUE_TILT_COMP,
 	MAGN_3D_CHANNEL_MAX,
 };
 
+#define IIO_CHANNEL_MAX MAGN_3D_CHANNEL_MAX
+
 struct magn_3d_state {
 	struct hid_sensor_hub_callbacks callbacks;
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
-	u32 magn_val[MAGN_3D_CHANNEL_MAX];
-};
+	u32 *magn_val_addr[MAGN_3D_CHANNEL_MAX];
 
-static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = {
-	HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS,
-	HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS,
-	HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS
+	u32 iio_val[IIO_CHANNEL_MAX];
+	int num_iio_channels;
 };
 
-/* Channel definitions */
-static const struct iio_chan_spec magn_3d_channels[] = {
-	{
-		.type = IIO_MAGN,
-		.modified = 1,
-		.channel2 = IIO_MOD_X,
-		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-		BIT(IIO_CHAN_INFO_SCALE) |
-		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
-		BIT(IIO_CHAN_INFO_HYSTERESIS),
-		.scan_index = CHANNEL_SCAN_INDEX_X,
-	}, {
-		.type = IIO_MAGN,
-		.modified = 1,
-		.channel2 = IIO_MOD_Y,
-		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-		BIT(IIO_CHAN_INFO_SCALE) |
-		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
-		BIT(IIO_CHAN_INFO_HYSTERESIS),
-		.scan_index = CHANNEL_SCAN_INDEX_Y,
-	}, {
-		.type = IIO_MAGN,
-		.modified = 1,
-		.channel2 = IIO_MOD_Z,
-		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
-		BIT(IIO_CHAN_INFO_SCALE) |
-		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
-		BIT(IIO_CHAN_INFO_HYSTERESIS),
-		.scan_index = CHANNEL_SCAN_INDEX_Z,
+/* Find index into magn_3d_state magn[] and magn_val_addr[] from HID Usage  */
+static int magn_3d_usage_id_to_chan_index(unsigned usage_id){
+	int offset = -1;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS:
+		offset = CHANNEL_SCAN_INDEX_X;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS:
+		offset = CHANNEL_SCAN_INDEX_Y;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS:
+		offset = CHANNEL_SCAN_INDEX_Z;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH:
+		offset = CHANNEL_SCAN_INDEX_NORTH_TILT_COMP;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_COMP_TRUE_NORTH:
+		offset = CHANNEL_SCAN_INDEX_NORTH_TRUE_TILT_COMP;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_MAGN_NORTH:
+		offset = CHANNEL_SCAN_INDEX_NORTH;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_TRUE_NORTH:
+		offset = CHANNEL_SCAN_INDEX_NORTH_TRUE;
+		break;
 	}
-};
 
-/* Adjust channel real bits based on report descriptor */
-static void magn_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
-						int channel, int size)
-{
-	channels[channel].scan_type.sign = 's';
-	/* Real storage bits will change based on the report desc. */
-	channels[channel].scan_type.realbits = size * 8;
-	/* Maximum size of a sample to capture is u32 */
-	channels[channel].scan_type.storagebits = sizeof(u32) * 8;
+	return offset;
 }
 
 /* Channel read_raw handler */
@@ -101,21 +92,31 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
 {
 	struct magn_3d_state *magn_state = iio_priv(indio_dev);
 	int report_id = -1;
-	u32 address;
+	unsigned usage_id;
+	int chan_index = -1;
 	int ret;
 	int ret_type;
 
+	dev_dbg(&indio_dev->dev, "magn_3d_read_raw\n");
+
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
 	case 0:
+		/* We store the HID usage ID of the iio channel
+		 * in its address field
+		 */
+		usage_id = chan->address;
+		chan_index = magn_3d_usage_id_to_chan_index(usage_id);
+		if(chan_index < 0)
+			return -EINVAL;
+
 		report_id =
-			magn_state->magn[chan->scan_index].report_id;
-		address = magn_3d_addresses[chan->scan_index];
+			magn_state->magn[chan_index].report_id;
 		if (report_id >= 0)
 			*val = sensor_hub_input_attr_get_raw_value(
 				magn_state->common_attributes.hsdev,
-				HID_USAGE_SENSOR_COMPASS_3D, address,
+				HID_USAGE_SENSOR_COMPASS_3D, usage_id,
 				report_id);
 		else {
 			*val = 0;
@@ -202,12 +203,13 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 				magn_state->common_attributes.data_ready);
 	if (magn_state->common_attributes.data_ready)
 		hid_sensor_push_data(indio_dev,
-				magn_state->magn_val,
-				sizeof(magn_state->magn_val));
+				&(magn_state->iio_val),
+				sizeof(magn_state->iio_val));
 
 	return 0;
 }
 
+
 /* Capture samples in local storage */
 static int magn_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
 				unsigned usage_id,
@@ -217,62 +219,147 @@ static int magn_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct magn_3d_state *magn_state = iio_priv(indio_dev);
 	int offset;
+	u32 *magn_val;
 	int ret = -EINVAL;
 
-	switch (usage_id) {
+	offset = magn_3d_usage_id_to_chan_index(usage_id);
+	if(offset < 0)
+		return ret;
+
+	magn_val = magn_state->magn_val_addr[offset];
+	if(!magn_val)
+		return ret;
+
+	*(magn_val) =  *(u32 *)raw_data;
+
+	return 0;
+}
+
+/* Setup the iio_chan_spec for HID Usage ID */
+static int magn_3d_setup_iio_chan(unsigned usage_id,
+				struct iio_chan_spec* channel,
+				u32 size,
+				struct magn_3d_state *st)
+{
+	int ret = -1;
+
+	if(channel == NULL)
+		return ret;
+
+	channel->type = IIO_MAGN;
+	channel->address = usage_id;
+	channel->modified = 1;
+
+	switch (usage_id){
+	case HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH:
+		channel->channel2 = IIO_MOD_MAGN_NORTH_TILT_COMP;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_COMP_TRUE_NORTH:
+		channel->channel2 = IIO_MOD_MAGN_NORTH_TRUE_TILT_COMP;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_MAGN_NORTH:
+		channel->channel2 = IIO_MOD_MAGN_NORTH;
+		break;
+	case HID_USAGE_SENSOR_ORIENT_TRUE_NORTH:
+		channel->channel2 = IIO_MOD_MAGN_NORTH_TRUE;
+		break;
 	case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS:
+		channel->channel2 = IIO_MOD_X;
+		break;
 	case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS:
+		channel->channel2 = IIO_MOD_Y;
+		break;
 	case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS:
-		offset = usage_id - HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS;
-		magn_state->magn_val[CHANNEL_SCAN_INDEX_X + offset] =
-						*(u32 *)raw_data;
-		ret = 0;
-	break;
-	default:
+		channel->channel2 = IIO_MOD_Z;
 		break;
+	default:
+		return ret;
 	}
 
-	return ret;
+	channel->info_mask_shared_by_type =
+		BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS);
+
+	channel->scan_type.sign = 's';
+	/* Real storage bits will change based on the report desc. */
+	channel->scan_type.realbits = size * 8;
+	/* Maximum size of a sample to capture is u32 */
+	channel->scan_type.storagebits = sizeof(u32) * 8;
+
+	return 0;
+}
+
+static void sensor_hub_fill_attr_info(
+		struct hid_sensor_hub_attribute_info *info,
+		s32 index, s32 report_id, struct hid_field *field)
+{
+	info->index = index;
+	info->report_id = report_id;
+	info->units = field->unit;
+	info->unit_expo = field->unit_exponent;
+	info->size = (field->report_size * field->report_count)/8;
+	info->logical_minimum = field->logical_minimum;
+	info->logical_maximum = field->logical_maximum;
 }
 
-/* Parse report which is specific to an usage id*/
+/* Read the HID reports and setup IIO Channels */
 static int magn_3d_parse_report(struct platform_device *pdev,
 				struct hid_sensor_hub_device *hsdev,
-				struct iio_chan_spec *channels,
+				struct iio_chan_spec *iio_chans,
 				unsigned usage_id,
 				struct magn_3d_state *st)
 {
-	int ret;
+	int ret = -1;
 	int i;
-
-	for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) {
-		ret = sensor_hub_input_get_attribute_info(hsdev,
-				HID_INPUT_REPORT,
-				usage_id,
-				HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS + i,
-				&st->magn[CHANNEL_SCAN_INDEX_X + i]);
-		if (ret < 0)
-			break;
-		magn_3d_adjust_channel_bit_mask(channels,
-				CHANNEL_SCAN_INDEX_X + i,
-				st->magn[CHANNEL_SCAN_INDEX_X + i].size);
-	}
-	dev_dbg(&pdev->dev, "magn_3d %x:%x, %x:%x, %x:%x\n",
-			st->magn[0].index,
-			st->magn[0].report_id,
-			st->magn[1].index, st->magn[1].report_id,
-			st->magn[2].index, st->magn[2].report_id);
-
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ORIENTATION,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
+	int j;
+
+	struct hid_report *report;
+	struct hid_field *field;
+	struct hid_report_enum *report_enum;
+	struct hid_device *hdev = hsdev->hdev;
+	struct hid_usage *usage = NULL;
+
+	dev_dbg(&pdev->dev, "magn_north_parse_reports Usage ID: %x\n", usage_id);
+	report_enum = &hdev->report_enum[HID_INPUT_REPORT];
+	list_for_each_entry(report, &report_enum->report_list, list) {
+		for (i = 0; i < report->maxfield; ++i) {
+			field = report->field[i];
+
+			for (j = 0; j < field->maxusage; j++) {
+				usage = &(field->usage[j]);
+
+				/* Check if collection_index is valid */
+				if(usage->collection_index >=
+					   hsdev->start_collection_index &&
+				   usage->collection_index <
+					   hsdev->end_collection_index &&
+				   usage->hid >=
+					   HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH &&
+				   usage->hid <=
+					   HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS)
+				{
+					struct hid_sensor_hub_attribute_info *usage_attr;
+					int magn_index = magn_3d_usage_id_to_chan_index(usage->hid);
+					int iio_index = st->num_iio_channels++;
+
+					if(magn_index >= 0 && magn_index < MAGN_3D_CHANNEL_MAX &&
+						iio_index >= 0 && iio_index < IIO_CHANNEL_MAX){
+						usage_attr = &(st->magn[magn_index]);
+
+						sensor_hub_fill_attr_info(usage_attr, i,
+									report->id,
+									field);
+						ret = magn_3d_setup_iio_chan(usage->hid,
+								&(iio_chans[iio_index]),
+								usage_attr->size,
+								st);
+						st->magn_val_addr[magn_index] = &(st->iio_val[iio_index]);
+					}
+				}
+			}
+		}
 	}
 
 	return ret;
@@ -307,10 +394,11 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(magn_3d_channels, sizeof(magn_3d_channels),
-			   GFP_KERNEL);
+	channels = kcalloc(MAGN_3D_CHANNEL_MAX,
+			sizeof(struct iio_chan_spec),
+			GFP_KERNEL);
 	if (!channels) {
-		dev_err(&pdev->dev, "failed to duplicate channels\n");
+		dev_err(&pdev->dev, "failed to allocate memory for iio channel\n");
 		return -ENOMEM;
 	}
 
@@ -322,7 +410,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 	}
 
 	indio_dev->channels = channels;
-	indio_dev->num_channels = ARRAY_SIZE(magn_3d_channels);
+	indio_dev->num_channels = magn_state->num_iio_channels;
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &magn_3d_info;
 	indio_dev->name = name;
-- 
1.9.3

^ permalink raw reply related

* [PATCH 2/3] IIO: Add iio_chan modifier for True/Magnetic North HID usages
From: Reyad Attiyat @ 2014-05-28 21:06 UTC (permalink / raw)
  To: linux-kernel, linux-iio, jic23, srinivas.pandruvada, linux-input,
	jkosina
  Cc: Reyad Attiyat
In-Reply-To: <1401311175-12784-1-git-send-email-reyad.attiyat@gmail.com>

Updated iio_chan_info_enum for compass north sensor usages,
including magnetic/true north and tilt compensation.

Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
---
 drivers/iio/industrialio-core.c | 4 ++++
 include/linux/iio/types.h       | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index ede16aec..41bd377 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -84,6 +84,10 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LIGHT_RED] = "red",
 	[IIO_MOD_LIGHT_GREEN] = "green",
 	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_MAGN_NORTH] = "north",
+	[IIO_MOD_MAGN_NORTH_TRUE] = "north_true",
+	[IIO_MOD_MAGN_NORTH_TILT_COMP] = "north_tilt_comp",
+	[IIO_MOD_MAGN_NORTH_TRUE_TILT_COMP] = "north_true_tilt_comp",
 };
 
 /* relies on pairs of these shared then separate */
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 084d882..f1e8be6 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -53,6 +53,10 @@ enum iio_modifier {
 	IIO_MOD_LIGHT_RED,
 	IIO_MOD_LIGHT_GREEN,
 	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_MAGN_NORTH,
+	IIO_MOD_MAGN_NORTH_TRUE,
+	IIO_MOD_MAGN_NORTH_TILT_COMP,
+	IIO_MOD_MAGN_NORTH_TRUE_TILT_COMP
 };
 
 enum iio_event_type {
-- 
1.9.3

^ permalink raw reply related

* [PATCH 1/3] IIO: Add iio magn_north ABI documentation
From: Reyad Attiyat @ 2014-05-28 21:06 UTC (permalink / raw)
  To: linux-kernel, linux-iio, jic23, srinivas.pandruvada, linux-input,
	jkosina
  Cc: Reyad Attiyat
In-Reply-To: <1401311175-12784-1-git-send-email-reyad.attiyat@gmail.com>

Update documentation for HID compass true/magnetic north sensor.

Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
---
 Documentation/ABI/testing/sysfs-bus-iio | 76 +++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 6e02c50..0341b2f 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -165,6 +165,10 @@ Description:
 What:		/sys/bus/iio/devices/iio:deviceX/in_magn_x_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_magn_y_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_magn_z_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_true_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_tilt_comp_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_true_tilt_comp_raw
 KernelVersion:	2.6.35
 Contact:	linux-iio@vger.kernel.org
 Description:
@@ -249,6 +253,10 @@ What:		/sys/bus/iio/devices/iio:deviceX/in_magn_scale
 What:		/sys/bus/iio/devices/iio:deviceX/in_magn_x_scale
 What:		/sys/bus/iio/devices/iio:deviceX/in_magn_y_scale
 What:		/sys/bus/iio/devices/iio:deviceX/in_magn_z_scale
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_scale
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_true_scale
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_tilt_comp_scale
+What:		/sys/bus/iio/devices/iio:deviceX/in_magn_north_true_tilt_comp_scale
 What:		/sys/bus/iio/devices/iio:deviceX/in_pressureY_scale
 What:		/sys/bus/iio/devices/iio:deviceX/in_pressure_scale
 KernelVersion:	2.6.35
@@ -436,6 +444,14 @@ What:		/sys/.../iio:deviceX/events/in_magn_y_thresh_rising_en
 What:		/sys/.../iio:deviceX/events/in_magn_y_thresh_falling_en
 What:		/sys/.../iio:deviceX/events/in_magn_z_thresh_rising_en
 What:		/sys/.../iio:deviceX/events/in_magn_z_thresh_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_thresh_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_thresh_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_thresh_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_thresh_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_tilt_comp_thresh_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_tilt_comp_thresh_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_tilt_comp_thresh_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_tilt_comp_thresh_falling_en
 What:		/sys/.../iio:deviceX/events/in_voltageY_supply_thresh_rising_en
 What:		/sys/.../iio:deviceX/events/in_voltageY_supply_thresh_falling_en
 What:		/sys/.../iio:deviceX/events/in_voltageY_thresh_rising_en
@@ -481,6 +497,14 @@ What:		/sys/.../iio:deviceX/events/in_magn_y_roc_rising_en
 What:		/sys/.../iio:deviceX/events/in_magn_y_roc_falling_en
 What:		/sys/.../iio:deviceX/events/in_magn_z_roc_rising_en
 What:		/sys/.../iio:deviceX/events/in_magn_z_roc_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_roc_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_roc_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_roc_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_roc_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_tilt_comp_roc_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_tilt_comp_roc_falling_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_tilt_comp_roc_rising_en
+What:		/sys/.../iio:deviceX/events/in_magn_north_true_tilt_comp_roc_falling_en
 What:		/sys/.../iio:deviceX/events/in_voltageY_supply_roc_rising_en
 What:		/sys/.../iio:deviceX/events/in_voltageY_supply_roc_falling_en
 What:		/sys/.../iio:deviceX/events/in_voltageY_roc_rising_en
@@ -527,6 +551,14 @@ What:		/sys/.../events/in_magn_y_raw_thresh_rising_value
 What:		/sys/.../events/in_magn_y_raw_thresh_falling_value
 What:		/sys/.../events/in_magn_z_raw_thresh_rising_value
 What:		/sys/.../events/in_magn_z_raw_thresh_falling_value
+What:		/sys/.../events/in_magn_north_raw_thresh_rising_value
+What:		/sys/.../events/in_magn_north_raw_thresh_falling_value
+What:		/sys/.../events/in_magn_north_true_raw_thresh_rising_value
+What:		/sys/.../events/in_magn_north_true_raw_thresh_falling_value
+What:		/sys/.../events/in_magn_north_tilt_comp_raw_thresh_rising_value
+What:		/sys/.../events/in_magn_north_tilt_comp_raw_thresh_falling_value
+What:		/sys/.../events/in_magn_north_true_tilt_comp_raw_thresh_rising_value
+What:		/sys/.../events/in_magn_north_true_tilt_comp_raw_thresh_falling_value
 What:		/sys/.../events/in_voltageY_supply_raw_thresh_rising_value
 What:		/sys/.../events/in_voltageY_supply_raw_thresh_falling_value
 What:		/sys/.../events/in_voltageY_raw_thresh_rising_value
@@ -577,6 +609,18 @@ What:		/sys/.../events/in_magn_y_thresh_either_hysteresis
 What:		/sys/.../events/in_magn_z_thresh_rising_hysteresis
 What:		/sys/.../events/in_magn_z_thresh_falling_hysteresis
 What:		/sys/.../events/in_magn_z_thresh_either_hysteresis
+What:		/sys/.../events/in_magn_north_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_north_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_north_thresh_either_hysteresis
+What:		/sys/.../events/in_magn_north_true_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_north_true_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_north_true_thresh_either_hysteresis
+What:		/sys/.../events/in_magn_north_tilt_comp_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_north_tilt_comp_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_north_tilt_comp_thresh_either_hysteresis
+What:		/sys/.../events/in_magn_north_true_tilt_comp_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_north_true_tilt_comp_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_north_true_tilt_comp_thresh_either_hysteresis
 What:		/sys/.../events/in_voltageY_thresh_rising_hysteresis
 What:		/sys/.../events/in_voltageY_thresh_falling_hysteresis
 What:		/sys/.../events/in_voltageY_thresh_either_hysteresis
@@ -624,6 +668,14 @@ What:		/sys/.../events/in_magn_y_raw_roc_rising_value
 What:		/sys/.../events/in_magn_y_raw_roc_falling_value
 What:		/sys/.../events/in_magn_z_raw_roc_rising_value
 What:		/sys/.../events/in_magn_z_raw_roc_falling_value
+What:		/sys/.../events/in_magn_north_raw_roc_rising_value
+What:		/sys/.../events/in_magn_north_raw_roc_falling_value
+What:		/sys/.../events/in_magn_north_true_raw_roc_rising_value
+What:		/sys/.../events/in_magn_north_true_raw_roc_falling_value
+What:		/sys/.../events/in_magn_north_tilt_comp_raw_roc_rising_value
+What:		/sys/.../events/in_magn_north_tilt_comp_raw_roc_falling_value
+What:		/sys/.../events/in_magn_north_true_tilt_comp_raw_roc_rising_value
+What:		/sys/.../events/in_magn_north_true_tilt_comp_raw_roc_falling_value
 What:		/sys/.../events/in_voltageY_supply_raw_roc_rising_value
 What:		/sys/.../events/in_voltageY_supply_raw_roc_falling_value
 What:		/sys/.../events/in_voltageY_raw_roc_rising_value
@@ -679,6 +731,22 @@ What:		/sys/.../events/in_magn_z_thresh_rising_period
 What:		/sys/.../events/in_magn_z_thresh_falling_period
 What:		/sys/.../events/in_magn_z_roc_rising_period
 What:		/sys/.../events/in_magn_z_roc_falling_period
+What:		/sys/.../events/in_magn_north_thresh_rising_period
+What:		/sys/.../events/in_magn_north_thresh_falling_period
+What:		/sys/.../events/in_magn_north_roc_rising_period
+What:		/sys/.../events/in_magn_north_roc_falling_period
+What:		/sys/.../events/in_magn_north_true_thresh_rising_period
+What:		/sys/.../events/in_magn_north_true_thresh_falling_period
+What:		/sys/.../events/in_magn_north_true_roc_rising_period
+What:		/sys/.../events/in_magn_north_true_roc_falling_period
+What:		/sys/.../events/in_magn_north_tilt_comp_thresh_rising_period
+What:		/sys/.../events/in_magn_north_tilt_comp_thresh_falling_period
+What:		/sys/.../events/in_magn_north_tilt_comp_roc_rising_period
+What:		/sys/.../events/in_magn_north_tilt_comp_roc_falling_period
+What:		/sys/.../events/in_magn_north_true_tilt_comp_thresh_rising_period
+What:		/sys/.../events/in_magn_north_true_tilt_comp_thresh_falling_period
+What:		/sys/.../events/in_magn_north_true_tilt_comp_roc_rising_period
+What:		/sys/.../events/in_magn_north_true_tilt_comp_roc_falling_period
 What:		/sys/.../events/in_voltageY_supply_thresh_rising_period
 What:		/sys/.../events/in_voltageY_supply_thresh_falling_period
 What:		/sys/.../events/in_voltageY_supply_roc_rising_period
@@ -776,6 +844,10 @@ What:		/sys/.../iio:deviceX/scan_elements/in_anglvel_z_en
 What:		/sys/.../iio:deviceX/scan_elements/in_magn_x_en
 What:		/sys/.../iio:deviceX/scan_elements/in_magn_y_en
 What:		/sys/.../iio:deviceX/scan_elements/in_magn_z_en
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_en
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_true_en
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_tilt_comp_en
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_true_tilt_comp_en
 What:		/sys/.../iio:deviceX/scan_elements/in_timestamp_en
 What:		/sys/.../iio:deviceX/scan_elements/in_voltageY_supply_en
 What:		/sys/.../iio:deviceX/scan_elements/in_voltageY_en
@@ -840,6 +912,10 @@ What:		/sys/.../iio:deviceX/scan_elements/in_anglvel_z_index
 What:		/sys/.../iio:deviceX/scan_elements/in_magn_x_index
 What:		/sys/.../iio:deviceX/scan_elements/in_magn_y_index
 What:		/sys/.../iio:deviceX/scan_elements/in_magn_z_index
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_index
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_true_index
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_tilt_comp_index
+What:		/sys/.../iio:deviceX/scan_elements/in_magn_north_true_tilt_comp_index
 What:		/sys/.../iio:deviceX/scan_elements/in_incli_x_index
 What:		/sys/.../iio:deviceX/scan_elements/in_incli_y_index
 What:		/sys/.../iio:deviceX/scan_elements/in_timestamp_index
-- 
1.9.3

^ permalink raw reply related

* [PATCH 0/3] IIO: hid-sensor-magn-3d: Add support for compass north usage attribute
From: Reyad Attiyat @ 2014-05-28 21:06 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-iio-u79uwXL29TY76Z2rM5mHXA, jic23-DgEjT+Ai2ygdnm+yROfE0A,
	srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA,
	linux-input-u79uwXL29TY76Z2rM5mHXA, jkosina-AlSwsSmVLrQ
  Cc: Reyad Attiyat

Update hid-sensor-magn-3d to dynamically create IIO channels
Update IIO to include modifiers for true/magnetic north and
tilt compensation compass usages

Signed-off-by: Reyad Attiyat <reyad.attiyat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>


Reyad Attiyat (3):
  IIO: Added iio magn_north ABI documentation
  IIO: Add iio_chan modifier for True/Magnetic North HID usages
  IO: hid-sensor-magn-3d: Add in support for True/Magnetic North HID
    usages

 Documentation/ABI/testing/sysfs-bus-iio       |  76 +++++++
 drivers/iio/industrialio-core.c               |   4 +
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 278 +++++++++++++++++---------
 include/linux/iio/types.h                     |   4 +
 4 files changed, 267 insertions(+), 95 deletions(-)

-- 
1.9.3

^ permalink raw reply

* [PATCH] input: ab8500-ponkey: Allocate resources using managed interfaces
From: Himangi Saraogi @ 2014-05-28 20:12 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: julia.lawall

This patch moves most data allocated in the probe function from
unmanaged interfaces to managed interfaces. The kfrees and error
handling code is done away with. Also, the unnecesary labels are
removed and the function ab8500_ponkey_remove is removed as it becomes
empty after removing the no longer required function calls. Also,
linux/device.h is added to make sure the devm_*() routine declarations
are unambiguously available.

The following Coccinelle semantic patch was used for making a part of
the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
To send to: Dmitry Torokhov <dmitry.torokhov@gmail.com>,linux-input@vger.kernel.org,linux-kernel@vger.kernel.org

 drivers/input/misc/ab8500-ponkey.c | 51 +++++++++++---------------------------
 1 file changed, 15 insertions(+), 36 deletions(-)

diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c
index f2fbdd8..89fb1c6 100644
--- a/drivers/input/misc/ab8500-ponkey.c
+++ b/drivers/input/misc/ab8500-ponkey.c
@@ -7,6 +7,7 @@
  * AB8500 Power-On Key handler
  */
 
+#include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -65,12 +66,11 @@ static int ab8500_ponkey_probe(struct platform_device *pdev)
 		return irq_dbr;
 	}
 
-	ponkey = kzalloc(sizeof(struct ab8500_ponkey), GFP_KERNEL);
-	input = input_allocate_device();
-	if (!ponkey || !input) {
-		error = -ENOMEM;
-		goto err_free_mem;
-	}
+	ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey),
+			      GFP_KERNEL);
+	input = devm_input_allocate_device(&pdev->dev);
+	if (!ponkey || !input)
+		return -ENOMEM;
 
 	ponkey->idev = input;
 	ponkey->ab8500 = ab8500;
@@ -82,52 +82,32 @@ static int ab8500_ponkey_probe(struct platform_device *pdev)
 
 	input_set_capability(input, EV_KEY, KEY_POWER);
 
-	error = request_any_context_irq(ponkey->irq_dbf, ab8500_ponkey_handler,
-					0, "ab8500-ponkey-dbf", ponkey);
+	error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf,
+					     ab8500_ponkey_handler, 0,
+					     "ab8500-ponkey-dbf", ponkey);
 	if (error < 0) {
 		dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n",
 			ponkey->irq_dbf, error);
-		goto err_free_mem;
+		return error;
 	}
 
-	error = request_any_context_irq(ponkey->irq_dbr, ab8500_ponkey_handler,
-					0, "ab8500-ponkey-dbr", ponkey);
+	error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr,
+					     ab8500_ponkey_handler, 0,
+					     "ab8500-ponkey-dbr", ponkey);
 	if (error < 0) {
 		dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n",
 			ponkey->irq_dbr, error);
-		goto err_free_dbf_irq;
+		return error;
 	}
 
 	error = input_register_device(ponkey->idev);
 	if (error) {
 		dev_err(ab8500->dev, "Can't register input device: %d\n", error);
-		goto err_free_dbr_irq;
+		return error;
 	}
 
 	platform_set_drvdata(pdev, ponkey);
 	return 0;
-
-err_free_dbr_irq:
-	free_irq(ponkey->irq_dbr, ponkey);
-err_free_dbf_irq:
-	free_irq(ponkey->irq_dbf, ponkey);
-err_free_mem:
-	input_free_device(input);
-	kfree(ponkey);
-
-	return error;
-}
-
-static int ab8500_ponkey_remove(struct platform_device *pdev)
-{
-	struct ab8500_ponkey *ponkey = platform_get_drvdata(pdev);
-
-	free_irq(ponkey->irq_dbf, ponkey);
-	free_irq(ponkey->irq_dbr, ponkey);
-	input_unregister_device(ponkey->idev);
-	kfree(ponkey);
-
-	return 0;
 }
 
 #ifdef CONFIG_OF
@@ -144,7 +124,6 @@ static struct platform_driver ab8500_ponkey_driver = {
 		.of_match_table = of_match_ptr(ab8500_ponkey_match),
 	},
 	.probe		= ab8500_ponkey_probe,
-	.remove		= ab8500_ponkey_remove,
 };
 module_platform_driver(ab8500_ponkey_driver);
 
-- 
1.9.1


^ permalink raw reply related

* [PATCH] Input: max8925_onkey :Allocate resources using managed interfaces
From: Himangi Saraogi @ 2014-05-28 20:10 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: julia.lawall

This patch moves most data allocated in the probe function from
unmanaged interfaces to managed interfaces. The kfrees and error
handling code is done away with. The unnecesary labels are removed
and the function max8925_onkey_remove is removed as it becomes empty
after removing the no longer required function calls. Also,
linux/device.h is added to make sure the devm_*() routine declarations
are unambiguously available.

The following Coccinelle semantic patch was used for making a part of
the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
To send to: Dmitry Torokhov <dmitry.torokhov@gmail.com>,linux-input@vger.kernel.org,linux-kernel@vger.kernel.org
 drivers/input/misc/max8925_onkey.c | 52 +++++++++++---------------------------
 1 file changed, 15 insertions(+), 37 deletions(-)

diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c
index eef41cf..62899e5 100644
--- a/drivers/input/misc/max8925_onkey.c
+++ b/drivers/input/misc/max8925_onkey.c
@@ -26,6 +26,7 @@
 #include <linux/interrupt.h>
 #include <linux/mfd/max8925.h>
 #include <linux/slab.h>
+#include <linux/device.h>
 
 #define SW_INPUT		(1 << 7)	/* 0/1 -- up/down */
 #define HARDRESET_EN		(1 << 7)
@@ -81,12 +82,11 @@ static int max8925_onkey_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL);
-	input = input_allocate_device();
-	if (!info || !input) {
-		error = -ENOMEM;
-		goto err_free_mem;
-	}
+	info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_onkey_info),
+			    GFP_KERNEL);
+	input = devm_input_allocate_device(&pdev->dev);
+	if (!info || !input)
+		return -ENOMEM;
 
 	info->idev = input;
 	info->i2c = chip->i2c;
@@ -100,55 +100,34 @@ static int max8925_onkey_probe(struct platform_device *pdev)
 	input->dev.parent = &pdev->dev;
 	input_set_capability(input, EV_KEY, KEY_POWER);
 
-	error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler,
-				     IRQF_ONESHOT, "onkey-down", info);
+	error = devm_request_threaded_irq(&pdev->dev, irq[0], NULL,
+					  max8925_onkey_handler, IRQF_ONESHOT,
+					  "onkey-down", info);
 	if (error < 0) {
 		dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
 			irq[0], error);
-		goto err_free_mem;
+		return error;
 	}
 
-	error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler,
-				     IRQF_ONESHOT, "onkey-up", info);
+	error = devm_request_threaded_irq(&pdev->dev, irq[1], NULL,
+					  max8925_onkey_handler, IRQF_ONESHOT,
+					  "onkey-up", info);
 	if (error < 0) {
 		dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
 			irq[1], error);
-		goto err_free_irq0;
+		return error;
 	}
 
 	error = input_register_device(info->idev);
 	if (error) {
 		dev_err(chip->dev, "Can't register input device: %d\n", error);
-		goto err_free_irq1;
+		return error;
 	}
 
 	platform_set_drvdata(pdev, info);
 	device_init_wakeup(&pdev->dev, 1);
 
 	return 0;
-
-err_free_irq1:
-	free_irq(irq[1], info);
-err_free_irq0:
-	free_irq(irq[0], info);
-err_free_mem:
-	input_free_device(input);
-	kfree(info);
-
-	return error;
-}
-
-static int max8925_onkey_remove(struct platform_device *pdev)
-{
-	struct max8925_onkey_info *info = platform_get_drvdata(pdev);
-	struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
-
-	free_irq(info->irq[0] + chip->irq_base, info);
-	free_irq(info->irq[1] + chip->irq_base, info);
-	input_unregister_device(info->idev);
-	kfree(info);
-
-	return 0;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -190,7 +169,6 @@ static struct platform_driver max8925_onkey_driver = {
 		.pm	= &max8925_onkey_pm_ops,
 	},
 	.probe		= max8925_onkey_probe,
-	.remove		= max8925_onkey_remove,
 };
 module_platform_driver(max8925_onkey_driver);
 
-- 
1.9.1

^ permalink raw reply related

* [PATCH] Input: 88pm860x-ts: Introduce the use of the managed version of kzalloc
From: Himangi Saraogi @ 2014-05-28 20:06 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: julia.lawall

This patch moves most data allocated in the probe function from
unmanaged interfaces to managed interfaces. The kfrees and error
handling code is done away with. Also, the unnecesary labels are
removed and the function pm860x_touch_remove is removed as it becomes
empty after removing the no longer required function calls. 

This changes the order of the freeing operations in the remove
function, putting the free_irq first, and that this may resolve a 
potential race condition.

The following Coccinelle semantic patch was used for making a part of
the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/input/touchscreen/88pm860x-ts.c | 36 +++++++++------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c
index 544e20c..30c8cc1 100644
--- a/drivers/input/touchscreen/88pm860x-ts.c
+++ b/drivers/input/touchscreen/88pm860x-ts.c
@@ -16,6 +16,7 @@
 #include <linux/input.h>
 #include <linux/mfd/88pm860x.h>
 #include <linux/slab.h>
+#include <linux/device.h>
 
 #define MEAS_LEN		(8)
 #define ACCURATE_BIT		(12)
@@ -234,16 +235,16 @@ static int pm860x_touch_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	touch = kzalloc(sizeof(struct pm860x_touch), GFP_KERNEL);
+	touch = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_touch),
+			     GFP_KERNEL);
 	if (touch == NULL)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, touch);
 
-	touch->idev = input_allocate_device();
+	touch->idev = devm_input_allocate_device(&pdev->dev);
 	if (touch->idev == NULL) {
 		dev_err(&pdev->dev, "Failed to allocate input device!\n");
-		ret = -ENOMEM;
-		goto out;
+		return -ENOMEM;
 	}
 
 	touch->idev->name = "88pm860x-touch";
@@ -258,10 +259,11 @@ static int pm860x_touch_probe(struct platform_device *pdev)
 	touch->res_x = res_x;
 	input_set_drvdata(touch->idev, touch);
 
-	ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
-				   IRQF_ONESHOT, "touch", touch);
+	ret = devm_request_threaded_irq(&pdev->dev, touch->irq, NULL,
+					pm860x_touch_handler, IRQF_ONESHOT,
+					"touch", touch);
 	if (ret < 0)
-		goto out_irq;
+		return ret;
 
 	__set_bit(EV_ABS, touch->idev->evbit);
 	__set_bit(ABS_X, touch->idev->absbit);
@@ -279,28 +281,11 @@ static int pm860x_touch_probe(struct platform_device *pdev)
 	ret = input_register_device(touch->idev);
 	if (ret < 0) {
 		dev_err(chip->dev, "Failed to register touch!\n");
-		goto out_rg;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, touch);
 	return 0;
-out_rg:
-	free_irq(touch->irq, touch);
-out_irq:
-	input_free_device(touch->idev);
-out:
-	kfree(touch);
-	return ret;
-}
-
-static int pm860x_touch_remove(struct platform_device *pdev)
-{
-	struct pm860x_touch *touch = platform_get_drvdata(pdev);
-
-	input_unregister_device(touch->idev);
-	free_irq(touch->irq, touch);
-	kfree(touch);
-	return 0;
 }
 
 static struct platform_driver pm860x_touch_driver = {
@@ -309,7 +294,6 @@ static struct platform_driver pm860x_touch_driver = {
 		.owner	= THIS_MODULE,
 	},
 	.probe	= pm860x_touch_probe,
-	.remove	= pm860x_touch_remove,
 };
 module_platform_driver(pm860x_touch_driver);
 
-- 
1.9.1


^ permalink raw reply related

* [PATCH] Input: 88pm860x_onkey : Introduce the use of the managed version of  kzalloc
From: Himangi Saraogi @ 2014-05-28 20:01 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: julia.lawall

This patch moves most data allocated in the probe function from
unmanaged interfaces to managed interfaces. The kfrees and error
handling code is done away with. Also, the unnecesary labels are
removed and the function pm860x_onkey_remove is removed as it becomes
empty after removing the no longer required function calls. Also,
linux/device.h include is added to make sure the devm_*() routine
declarations are unambiguously available.

The following Coccinelle semantic patch was used for making a part of
the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/input/misc/88pm860x_onkey.c | 40 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/drivers/input/misc/88pm860x_onkey.c b/drivers/input/misc/88pm860x_onkey.c
index abd8453..220ce0f 100644
--- a/drivers/input/misc/88pm860x_onkey.c
+++ b/drivers/input/misc/88pm860x_onkey.c
@@ -26,6 +26,7 @@
 #include <linux/interrupt.h>
 #include <linux/mfd/88pm860x.h>
 #include <linux/slab.h>
+#include <linux/device.h>
 
 #define PM8607_WAKEUP		0x0b
 
@@ -68,7 +69,8 @@ static int pm860x_onkey_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	info = kzalloc(sizeof(struct pm860x_onkey_info), GFP_KERNEL);
+	info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_onkey_info),
+			    GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 	info->chip = chip;
@@ -76,11 +78,10 @@ static int pm860x_onkey_probe(struct platform_device *pdev)
 	info->dev = &pdev->dev;
 	info->irq = irq;
 
-	info->idev = input_allocate_device();
+	info->idev = devm_input_allocate_device(&pdev->dev);
 	if (!info->idev) {
 		dev_err(chip->dev, "Failed to allocate input dev\n");
-		ret = -ENOMEM;
-		goto out;
+		return -ENOMEM;
 	}
 
 	info->idev->name = "88pm860x_on";
@@ -93,42 +94,22 @@ static int pm860x_onkey_probe(struct platform_device *pdev)
 	ret = input_register_device(info->idev);
 	if (ret) {
 		dev_err(chip->dev, "Can't register input device: %d\n", ret);
-		goto out_reg;
+		return ret;
 	}
 
-	ret = request_threaded_irq(info->irq, NULL, pm860x_onkey_handler,
-				   IRQF_ONESHOT, "onkey", info);
+	ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
+					pm860x_onkey_handler, IRQF_ONESHOT,
+					"onkey", info);
 	if (ret < 0) {
 		dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
 			info->irq, ret);
-		goto out_irq;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, info);
 	device_init_wakeup(&pdev->dev, 1);
 
 	return 0;
-
-out_irq:
-	input_unregister_device(info->idev);
-	kfree(info);
-	return ret;
-
-out_reg:
-	input_free_device(info->idev);
-out:
-	kfree(info);
-	return ret;
-}
-
-static int pm860x_onkey_remove(struct platform_device *pdev)
-{
-	struct pm860x_onkey_info *info = platform_get_drvdata(pdev);
-
-	free_irq(info->irq, info);
-	input_unregister_device(info->idev);
-	kfree(info);
-	return 0;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -161,7 +142,6 @@ static struct platform_driver pm860x_onkey_driver = {
 		.pm	= &pm860x_onkey_pm_ops,
 	},
 	.probe		= pm860x_onkey_probe,
-	.remove		= pm860x_onkey_remove,
 };
 module_platform_driver(pm860x_onkey_driver);
 
-- 
1.9.1

^ permalink raw reply related

* [PATCH] Input: touchscreen : Introduce the use of the managed version of kzalloc
From: Himangi Saraogi @ 2014-05-28 18:02 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: julia.lawall

This patch moves most data allocated in the probe function from
unmanaged interfaces to managed interfaces. The kfrees and error
handling code is done away with. Also, the unnecesary labels are
removed and the function mrstouch_remove is removed as it becomes
empty after removing the no longer required function calls. Also,
linux/device.h include is added to make sure the devm_*() routine
declarations are unambiguously available.

The following Coccinelle semantic patch was used for making a part of
the change:

@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
  .probe = probefn,
  .remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
  <+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
  ...
?-kfree(e);
  ...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
  <...
- kfree(e);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/input/touchscreen/intel-mid-touch.c | 39 ++++++++---------------------
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/drivers/input/touchscreen/intel-mid-touch.c b/drivers/input/touchscreen/intel-mid-touch.c
index 4f6b156..b1b1e8b 100644
--- a/drivers/input/touchscreen/intel-mid-touch.c
+++ b/drivers/input/touchscreen/intel-mid-touch.c
@@ -36,6 +36,7 @@
 #include <linux/irq.h>
 #include <linux/delay.h>
 #include <asm/intel_scu_ipc.h>
+#include <linux/device.h>
 
 /* PMIC Interrupt registers */
 #define PMIC_REG_ID1		0x00 /* PMIC ID1 register */
@@ -580,12 +581,12 @@ static int mrstouch_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL);
-	input = input_allocate_device();
+	tsdev = devm_kzalloc(&pdev->dev, sizeof(struct mrstouch_dev),
+			     GFP_KERNEL);
+	input = devm_input_allocate_device(&pdev->dev);
 	if (!tsdev || !input) {
 		dev_err(&pdev->dev, "unable to allocate memory\n");
-		err = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	tsdev->dev = &pdev->dev;
@@ -598,7 +599,7 @@ static int mrstouch_probe(struct platform_device *pdev)
 	err = mrstouch_adc_init(tsdev);
 	if (err) {
 		dev_err(&pdev->dev, "ADC initialization failed\n");
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	input->name = "mrst_touchscreen";
@@ -618,39 +619,22 @@ static int mrstouch_probe(struct platform_device *pdev)
 	input_set_abs_params(tsdev->input, ABS_PRESSURE,
 			     MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0);
 
-	err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
-				   IRQF_ONESHOT, "mrstouch", tsdev);
+	err = devm_request_threaded_irq(&pdev->dev, tsdev->irq, NULL,
+					mrstouch_pendet_irq, IRQF_ONESHOT,
+					"mrstouch", tsdev);
 	if (err) {
 		dev_err(tsdev->dev, "unable to allocate irq\n");
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	err = input_register_device(tsdev->input);
 	if (err) {
 		dev_err(tsdev->dev, "unable to register input device\n");
-		goto err_free_irq;
+		return -ENOMEM;
 	}
 
 	platform_set_drvdata(pdev, tsdev);
 	return 0;
-
-err_free_irq:
-	free_irq(tsdev->irq, tsdev);
-err_free_mem:
-	input_free_device(input);
-	kfree(tsdev);
-	return err;
-}
-
-static int mrstouch_remove(struct platform_device *pdev)
-{
-	struct mrstouch_dev *tsdev = platform_get_drvdata(pdev);
-
-	free_irq(tsdev->irq, tsdev);
-	input_unregister_device(tsdev->input);
-	kfree(tsdev);
-
-	return 0;
 }
 
 static struct platform_driver mrstouch_driver = {
@@ -659,7 +643,6 @@ static struct platform_driver mrstouch_driver = {
 		.owner	= THIS_MODULE,
 	},
 	.probe		= mrstouch_probe,
-	.remove		= mrstouch_remove,
 };
 module_platform_driver(mrstouch_driver);
 
-- 
1.9.1


^ permalink raw reply related

* Re: [RESEND PATCH v4 1/2] Input: mcs_touchkey: use devm_* functions
From: Dmitry Torokhov @ 2014-05-28 16:37 UTC (permalink / raw)
  To: Beomho Seo
  Cc: linux-input, jy0922.shim, sachin.kamat, myungjoo.ham, jh80.chung,
	cw00.choi
In-Reply-To: <1401268396-23072-2-git-send-email-beomho.seo@samsung.com>

On Wed, May 28, 2014 at 06:13:15PM +0900, Beomho Seo wrote:
> This patch use devm_* funtions in mcs_touchkey driver.
> As a result, error path and remove() funtion is simplified.
> 
> Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
> ---
> Changes in v4:
> - free_irq are back again for equivalent transformation.
> Changes in v3:
> - Some codes are back again. use fw_version, driver name and poweron.
> Changes in v2:
> - Additionally use devm_kzalloc for mcs_touchkey_data struct.
> ---
>  drivers/input/keyboard/mcs_touchkey.c |   34 ++++++++++++---------------------
>  1 file changed, 12 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
> index 1da8e0b..48a341c 100644
> --- a/drivers/input/keyboard/mcs_touchkey.c
> +++ b/drivers/input/keyboard/mcs_touchkey.c
> @@ -113,14 +113,11 @@ static int mcs_touchkey_probe(struct i2c_client *client,
>  		return -EINVAL;
>  	}
>  
> -	data = kzalloc(sizeof(struct mcs_touchkey_data) +
> -			sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
> -			GFP_KERNEL);
> -	input_dev = input_allocate_device();
> +	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
> +	input_dev = devm_input_allocate_device(&client->dev);
>  	if (!data || !input_dev) {
>  		dev_err(&client->dev, "Failed to allocate memory\n");
> -		error = -ENOMEM;
> -		goto err_free_mem;
> +		return -ENOMEM;
>  	}
>  
>  	data->client = client;
> @@ -143,7 +140,7 @@ static int mcs_touchkey_probe(struct i2c_client *client,
>  	if (fw_ver < 0) {
>  		error = fw_ver;
>  		dev_err(&client->dev, "i2c read error[%d]\n", error);
> -		goto err_free_mem;
> +		return error;
>  	}
>  	dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
>  
> @@ -176,27 +173,22 @@ static int mcs_touchkey_probe(struct i2c_client *client,
>  		data->poweron(true);
>  	}
>  
> -	error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
> -				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> -				     client->dev.driver->name, data);
> +	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
> +				mcs_touchkey_interrupt,	IRQF_TRIGGER_FALLING |
> +				IRQF_ONESHOT, client->dev.driver->name, data);
>  	if (error) {
>  		dev_err(&client->dev, "Failed to register interrupt\n");
> -		goto err_free_mem;
> +		return error;
>  	}
>  
>  	error = input_register_device(input_dev);
> -	if (error)
> -		goto err_free_irq;
> +	if (error) {
> +		dev_err(&client->dev, "Failed to register input device\n");
> +		return error;
> +	}
>  
>  	i2c_set_clientdata(client, data);
>  	return 0;
> -
> -err_free_irq:
> -	free_irq(client->irq, data);
> -err_free_mem:
> -	input_free_device(input_dev);
> -	kfree(data);
> -	return error;
>  }
>  
>  static int mcs_touchkey_remove(struct i2c_client *client)
> @@ -206,8 +198,6 @@ static int mcs_touchkey_remove(struct i2c_client *client)
>  	free_irq(client->irq, data);

No, you can not use free_irq() on managed IRQ. If you want to do devm
conversion I'd rather you used devm_add_action() to schedule call to
data->poweron(false).

Thanks.

>  	if (data->poweron)
>  		data->poweron(false);
> -	input_unregister_device(data->input_dev);
> -	kfree(data);
>  
>  	return 0;
>  }
> -- 
> 1.7.9.5
> 

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH 1/1] Input: soc_button_array - Remove duplicate inclusion of input.h
From: Dmitry Torokhov @ 2014-05-28 16:34 UTC (permalink / raw)
  To: Sachin Kamat; +Cc: linux-input
In-Reply-To: <1401277459-31247-1-git-send-email-sachin.kamat@linaro.org>

On Wed, May 28, 2014 at 05:14:19PM +0530, Sachin Kamat wrote:
> input.h was included twice.
> 
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>

Applied, thank you.

> ---
>  drivers/input/misc/soc_button_array.c |    1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c
> index 20c80f543d5e..5a6334be30b8 100644
> --- a/drivers/input/misc/soc_button_array.c
> +++ b/drivers/input/misc/soc_button_array.c
> @@ -17,7 +17,6 @@
>  #include <linux/acpi.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/gpio_keys.h>
> -#include <linux/input.h>
>  #include <linux/platform_device.h>
>  #include <linux/pnp.h>
>  
> -- 
> 1.7.9.5
> 

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH] HID: hid-sensor-hub: Set report quirk for Microsoft Surface
From: Jiri Kosina @ 2014-05-28 14:29 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: Reyad Attiyat, linux-kernel, linux-input
In-Reply-To: <20140528135358.GA27859@mail.corp.redhat.com>

On Wed, 28 May 2014, Benjamin Tissoires wrote:

> I guess this should be fine:
> f3b0cbce01 has no more impact (there is no USB_DEVICE_ID_MS_*_2
> anymore)
> 
> e24d0d399b2f will properly add the HID_GROUP_SENSOR_HUB to the sensors
> if the report descriptor is properly set.
> 
> Given that the group SENSOR_HUB will be set, no other hid driver will
> pick them, so this patch just adds the HID_SENSOR_HUB_ENUM_QUIRK to the
> actual sensors in the surface 2.
> 
> So:
> 
> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply

* Re: [PATCH] HID: hid-sensor-hub: Set report quirk for Microsoft Surface
From: Benjamin Tissoires @ 2014-05-28 13:53 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Reyad Attiyat, linux-kernel, linux-input
In-Reply-To: <alpine.LNX.2.00.1405281541100.17241@pobox.suse.cz>

On May 28 2014 or thereabouts, Jiri Kosina wrote:
> On Tue, 27 May 2014, Reyad Attiyat wrote:
> 
> > Add the Microsoft Surface Pro 2 Type/Touch and default device hardware ID's
> > Set report quirk for the device in hid-sensor-hub
> > 
> > Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
> > ---
> >  drivers/hid/hid-ids.h        | 3 +++
> >  drivers/hid/hid-sensor-hub.c | 9 +++++++++
> >  2 files changed, 12 insertions(+)
> > 
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 34bb220..18e2099 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -633,6 +633,9 @@
> >  #define USB_DEVICE_ID_MS_PRESENTER_8K_USB	0x0713
> >  #define USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K	0x0730
> >  #define USB_DEVICE_ID_MS_COMFORT_MOUSE_4500	0x076c
> > +#define USB_DEVICE_ID_MS_SURFACE_PRO_2   0x0799
> > +#define USB_DEVICE_ID_MS_TOUCH_COVER_2   0x07a7
> > +#define USB_DEVICE_ID_MS_TYPE_COVER_2    0x07a9
> >  
> >  #define USB_VENDOR_ID_MOJO		0x8282
> >  #define USB_DEVICE_ID_RETRO_ADAPTER	0x3201
> > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
> > index be14b56..eefaaf6 100644
> > --- a/drivers/hid/hid-sensor-hub.c
> > +++ b/drivers/hid/hid-sensor-hub.c
> > @@ -711,6 +711,15 @@ static const struct hid_device_id sensor_hub_devices[] = {
> >  	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_TEXAS_INSTRUMENTS,
> >  			USB_DEVICE_ID_TEXAS_INSTRUMENTS_LENOVO_YOGA),
> >  			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> > +	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_MICROSOFT,
> > +			USB_DEVICE_ID_MS_SURFACE_PRO_2),
> > +			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> > +	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_MICROSOFT,
> > +			USB_DEVICE_ID_MS_TOUCH_COVER_2),
> > +			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> > +	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_MICROSOFT,
> > +			USB_DEVICE_ID_MS_TYPE_COVER_2),
> > +			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> >  	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, HID_ANY_ID,
> >  		     HID_ANY_ID) },
> >  	{ }
> 
> [ Benjamin added to CC]
> 
> How does this combine with f3b0cbce01 and e24d0d399b2f in Linus' tree?

I guess this should be fine:
f3b0cbce01 has no more impact (there is no USB_DEVICE_ID_MS_*_2
anymore)

e24d0d399b2f will properly add the HID_GROUP_SENSOR_HUB to the sensors
if the report descriptor is properly set.

Given that the group SENSOR_HUB will be set, no other hid driver will
pick them, so this patch just adds the HID_SENSOR_HUB_ENUM_QUIRK to the
actual sensors in the surface 2.

So:

Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Cheers,
Benjamin

^ permalink raw reply

* Re: [PATCHv2] HID: Debug: Add labels for HID Sensor Usages
From: Jiri Kosina @ 2014-05-28 13:45 UTC (permalink / raw)
  To: Reyad Attiyat; +Cc: linux-kernel, jic23, linux-input
In-Reply-To: <1401174659-2480-1-git-send-email-reyad.attiyat@gmail.com>

On Tue, 27 May 2014, Reyad Attiyat wrote:

> Add in debugfs report descriptor labels for HID Sensor Usages.

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply

* Re: [PATCH] HID: hid-sensor-hub: Set report quirk for Microsoft Surface
From: Jiri Kosina @ 2014-05-28 13:43 UTC (permalink / raw)
  To: Reyad Attiyat; +Cc: linux-kernel, linux-input, Benjamin Tissoires
In-Reply-To: <1401175750-3008-1-git-send-email-reyad.attiyat@gmail.com>

On Tue, 27 May 2014, Reyad Attiyat wrote:

> Add the Microsoft Surface Pro 2 Type/Touch and default device hardware ID's
> Set report quirk for the device in hid-sensor-hub
> 
> Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
> ---
>  drivers/hid/hid-ids.h        | 3 +++
>  drivers/hid/hid-sensor-hub.c | 9 +++++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> index 34bb220..18e2099 100644
> --- a/drivers/hid/hid-ids.h
> +++ b/drivers/hid/hid-ids.h
> @@ -633,6 +633,9 @@
>  #define USB_DEVICE_ID_MS_PRESENTER_8K_USB	0x0713
>  #define USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K	0x0730
>  #define USB_DEVICE_ID_MS_COMFORT_MOUSE_4500	0x076c
> +#define USB_DEVICE_ID_MS_SURFACE_PRO_2   0x0799
> +#define USB_DEVICE_ID_MS_TOUCH_COVER_2   0x07a7
> +#define USB_DEVICE_ID_MS_TYPE_COVER_2    0x07a9
>  
>  #define USB_VENDOR_ID_MOJO		0x8282
>  #define USB_DEVICE_ID_RETRO_ADAPTER	0x3201
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
> index be14b56..eefaaf6 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -711,6 +711,15 @@ static const struct hid_device_id sensor_hub_devices[] = {
>  	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_TEXAS_INSTRUMENTS,
>  			USB_DEVICE_ID_TEXAS_INSTRUMENTS_LENOVO_YOGA),
>  			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> +	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_MICROSOFT,
> +			USB_DEVICE_ID_MS_SURFACE_PRO_2),
> +			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> +	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_MICROSOFT,
> +			USB_DEVICE_ID_MS_TOUCH_COVER_2),
> +			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
> +	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_MICROSOFT,
> +			USB_DEVICE_ID_MS_TYPE_COVER_2),
> +			.driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
>  	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, HID_ANY_ID,
>  		     HID_ANY_ID) },
>  	{ }

[ Benjamin added to CC]

How does this combine with f3b0cbce01 and e24d0d399b2f in Linus' tree?

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply

* [PATCH 1/1] Input: soc_button_array - Remove duplicate inclusion of input.h
From: Sachin Kamat @ 2014-05-28 11:44 UTC (permalink / raw)
  To: linux-input; +Cc: dmitry.torokhov, sachin.kamat

input.h was included twice.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/input/misc/soc_button_array.c |    1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c
index 20c80f543d5e..5a6334be30b8 100644
--- a/drivers/input/misc/soc_button_array.c
+++ b/drivers/input/misc/soc_button_array.c
@@ -17,7 +17,6 @@
 #include <linux/acpi.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio_keys.h>
-#include <linux/input.h>
 #include <linux/platform_device.h>
 #include <linux/pnp.h>
 
-- 
1.7.9.5


^ permalink raw reply related

* [RESEND PATCH v4 2/2] Input: mcs5000_ts: use devm_* functions
From: Beomho Seo @ 2014-05-28  9:13 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo
In-Reply-To: <1401268396-23072-1-git-send-email-beomho.seo@samsung.com>

This patch use devm_* functions in mcs5000_ts driver.
As, a result, error patch and remove() function is simplified.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
---
Changes in v4:
- None.
Changes in v3:
- None.
Changes in v2:
- Additionally use devm_kzalloc for mcs_ts_data struct.
---
 drivers/input/touchscreen/mcs5000_ts.c |   42 +++++++++-----------------------
 1 file changed, 12 insertions(+), 30 deletions(-)

diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c
index 647e36f..6b57e28 100644
--- a/drivers/input/touchscreen/mcs5000_ts.c
+++ b/drivers/input/touchscreen/mcs5000_ts.c
@@ -196,12 +196,11 @@ static int mcs5000_ts_probe(struct i2c_client *client,
 	if (!dev_get_platdata(&client->dev))
 		return -EINVAL;
 
-	data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL);
-	input_dev = input_allocate_device();
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	input_dev = devm_input_allocate_device(&client->dev);
 	if (!data || !input_dev) {
 		dev_err(&client->dev, "Failed to allocate memory\n");
-		ret = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	data->client = client;
@@ -223,40 +222,24 @@ static int mcs5000_ts_probe(struct i2c_client *client,
 	if (data->platform_data->cfg_pin)
 		data->platform_data->cfg_pin();
 
-	ret = request_threaded_irq(client->irq, NULL, mcs5000_ts_interrupt,
-			IRQF_TRIGGER_LOW | IRQF_ONESHOT, "mcs5000_ts", data);
-
-	if (ret < 0) {
+	ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+			mcs5000_ts_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+			"mcs5000_ts", data);
+	if (ret) {
 		dev_err(&client->dev, "Failed to register interrupt\n");
-		goto err_free_mem;
+		return ret;
 	}
 
 	ret = input_register_device(data->input_dev);
-	if (ret < 0)
-		goto err_free_irq;
+	if (ret < 0) {
+		dev_err(&client->dev, "Failed to register input device\n");
+		return ret;
+	}
 
 	mcs5000_ts_phys_init(data);
 	i2c_set_clientdata(client, data);
 
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, data);
-err_free_mem:
-	input_free_device(input_dev);
-	kfree(data);
-	return ret;
-}
-
-static int mcs5000_ts_remove(struct i2c_client *client)
-{
-	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
-
-	free_irq(client->irq, data);
-	input_unregister_device(data->input_dev);
-	kfree(data);
-
-	return 0;
 }
 
 #ifdef CONFIG_PM
@@ -291,7 +274,6 @@ MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
 
 static struct i2c_driver mcs5000_ts_driver = {
 	.probe		= mcs5000_ts_probe,
-	.remove		= mcs5000_ts_remove,
 	.driver = {
 		.name = "mcs5000_ts",
 #ifdef CONFIG_PM
-- 
1.7.9.5


^ permalink raw reply related

* [RESEND PATCH v4 1/2] Input: mcs_touchkey: use devm_* functions
From: Beomho Seo @ 2014-05-28  9:13 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo
In-Reply-To: <1401268396-23072-1-git-send-email-beomho.seo@samsung.com>

This patch use devm_* funtions in mcs_touchkey driver.
As a result, error path and remove() funtion is simplified.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
---
Changes in v4:
- free_irq are back again for equivalent transformation.
Changes in v3:
- Some codes are back again. use fw_version, driver name and poweron.
Changes in v2:
- Additionally use devm_kzalloc for mcs_touchkey_data struct.
---
 drivers/input/keyboard/mcs_touchkey.c |   34 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 1da8e0b..48a341c 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -113,14 +113,11 @@ static int mcs_touchkey_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
-	data = kzalloc(sizeof(struct mcs_touchkey_data) +
-			sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
-			GFP_KERNEL);
-	input_dev = input_allocate_device();
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	input_dev = devm_input_allocate_device(&client->dev);
 	if (!data || !input_dev) {
 		dev_err(&client->dev, "Failed to allocate memory\n");
-		error = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	data->client = client;
@@ -143,7 +140,7 @@ static int mcs_touchkey_probe(struct i2c_client *client,
 	if (fw_ver < 0) {
 		error = fw_ver;
 		dev_err(&client->dev, "i2c read error[%d]\n", error);
-		goto err_free_mem;
+		return error;
 	}
 	dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
 
@@ -176,27 +173,22 @@ static int mcs_touchkey_probe(struct i2c_client *client,
 		data->poweron(true);
 	}
 
-	error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
-				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-				     client->dev.driver->name, data);
+	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+				mcs_touchkey_interrupt,	IRQF_TRIGGER_FALLING |
+				IRQF_ONESHOT, client->dev.driver->name, data);
 	if (error) {
 		dev_err(&client->dev, "Failed to register interrupt\n");
-		goto err_free_mem;
+		return error;
 	}
 
 	error = input_register_device(input_dev);
-	if (error)
-		goto err_free_irq;
+	if (error) {
+		dev_err(&client->dev, "Failed to register input device\n");
+		return error;
+	}
 
 	i2c_set_clientdata(client, data);
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, data);
-err_free_mem:
-	input_free_device(input_dev);
-	kfree(data);
-	return error;
 }
 
 static int mcs_touchkey_remove(struct i2c_client *client)
@@ -206,8 +198,6 @@ static int mcs_touchkey_remove(struct i2c_client *client)
 	free_irq(client->irq, data);
 	if (data->poweron)
 		data->poweron(false);
-	input_unregister_device(data->input_dev);
-	kfree(data);
 
 	return 0;
 }
-- 
1.7.9.5


^ permalink raw reply related

* [RESEND PATCH v4 0/2] Use devm_* functions for Melfas touch device
From: Beomho Seo @ 2014-05-28  9:13 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo

This patch set devm_* functions in Melfas touche device driver.
As a result, error path and remove() function is simplified.

Changes in v4:
- mcs_touchkey: add free_irq for equivalent transformation.

Changes in v3:
- mcs_touchkey: Some codes are back again.

Changes in v2:
- Additionally use devm_kzalloc mcs_[touchkey/ts]_data struct.

Beomho Seo (2):
  Input: mcs_touchkey: use devm_* functions
  Input: mcs5000_ts: use devm_* functions

 drivers/input/keyboard/mcs_touchkey.c  |   34 +++++++++-----------------
 drivers/input/touchscreen/mcs5000_ts.c |   42 +++++++++-----------------------
 2 files changed, 24 insertions(+), 52 deletions(-)

-- 
1.7.9.5


^ permalink raw reply

* Re: [PATCH v4 1/2] Input: mcs_touchkey: use devm_* functions
From: Beomho Seo @ 2014-05-28  9:08 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi
In-Reply-To: <1401266481-22065-2-git-send-email-beomho.seo@samsung.com>

On 05/28/2014 05:41 PM, Beomho Seo wrote:
> This patch use devm_* funtions in mcs_touchkey driver.
> As a result, error path and remove() funtion is simplified.
> 
> Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
> ---
> Changes in v4:
> - free_irq are back again for equivalent transformation.
> Changes in v3:
> - Some codes are back again. use fw_version, driver name and poweron.
> Changes in v2:
> - Additionally use devm_kzalloc for mcs_touchkey_data struct.
> 
> ---
>  drivers/input/keyboard/mcs_touchkey.c |   31 ++++++++++---------------------
>  1 file changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
> index 1da8e0b..d85adbf 100644
> --- a/drivers/input/keyboard/mcs_touchkey.c
> +++ b/drivers/input/keyboard/mcs_touchkey.c
> @@ -113,14 +113,11 @@ static int mcs_touchkey_probe(struct i2c_client *client,
>  		return -EINVAL;
>  	}
>  
> -	data = kzalloc(sizeof(struct mcs_touchkey_data) +
> -			sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
> -			GFP_KERNEL);
> -	input_dev = input_allocate_device();
> +	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
> +	input_dev = devm_input_allocate_device(&client->dev);
>  	if (!data || !input_dev) {
>  		dev_err(&client->dev, "Failed to allocate memory\n");
> -		error = -ENOMEM;
> -		goto err_free_mem;
> +		return -ENOMEM;
>  	}
>  
>  	data->client = client;
> @@ -143,7 +140,7 @@ static int mcs_touchkey_probe(struct i2c_client *client,
>  	if (fw_ver < 0) {
>  		error = fw_ver;
>  		dev_err(&client->dev, "i2c read error[%d]\n", error);
> -		goto err_free_mem;
> +		return error;
>  	}
>  	dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
>  
> @@ -176,27 +173,21 @@ static int mcs_touchkey_probe(struct i2c_client *client,
>  		data->poweron(true);
>  	}
>  
> -	error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
> -				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> -				     client->dev.driver->name, data);
> +	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
> +				mcs_touchkey_interrupt,	IRQF_TRIGGER_FALLING |
> +				IRQF_ONESHOT, client->dev.driver->name, data);
>  	if (error) {
>  		dev_err(&client->dev, "Failed to register interrupt\n");
> -		goto err_free_mem;
> +		return error;
>  	}
>  
>  	error = input_register_device(input_dev);
>  	if (error)
> -		goto err_free_irq;
> +		dev_err(&client->dev, "Failed to register input device\n");
> +		return error;

Unfortunately, I missed bracket. I will resend this patchset.
Sorry for the inconvenience.

>  
>  	i2c_set_clientdata(client, data);
>  	return 0;
> -
> -err_free_irq:
> -	free_irq(client->irq, data);
> -err_free_mem:
> -	input_free_device(input_dev);
> -	kfree(data);
> -	return error;
>  }
>  
>  static int mcs_touchkey_remove(struct i2c_client *client)
> @@ -206,8 +197,6 @@ static int mcs_touchkey_remove(struct i2c_client *client)
>  	free_irq(client->irq, data);
>  	if (data->poweron)
>  		data->poweron(false);
> -	input_unregister_device(data->input_dev);
> -	kfree(data);
>  
>  	return 0;
>  }
> 


^ permalink raw reply

* [PATCH v4 2/2] Input: mcs5000_ts: use devm_* functions
From: Beomho Seo @ 2014-05-28  8:41 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo
In-Reply-To: <1401266481-22065-1-git-send-email-beomho.seo@samsung.com>

This patch use devm_* functions in mcs5000_ts driver.
As, a result, error patch and remove() function is simplified.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
---
Changes in v4:
- None.
Changes in v3:
- None.
Changes in v2:
- Additionally use devm_kzalloc for mcs_ts_data struct.
---
 drivers/input/touchscreen/mcs5000_ts.c |   42 +++++++++-----------------------
 1 file changed, 12 insertions(+), 30 deletions(-)

diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c
index 647e36f..6b57e28 100644
--- a/drivers/input/touchscreen/mcs5000_ts.c
+++ b/drivers/input/touchscreen/mcs5000_ts.c
@@ -196,12 +196,11 @@ static int mcs5000_ts_probe(struct i2c_client *client,
 	if (!dev_get_platdata(&client->dev))
 		return -EINVAL;
 
-	data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL);
-	input_dev = input_allocate_device();
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	input_dev = devm_input_allocate_device(&client->dev);
 	if (!data || !input_dev) {
 		dev_err(&client->dev, "Failed to allocate memory\n");
-		ret = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	data->client = client;
@@ -223,40 +222,24 @@ static int mcs5000_ts_probe(struct i2c_client *client,
 	if (data->platform_data->cfg_pin)
 		data->platform_data->cfg_pin();
 
-	ret = request_threaded_irq(client->irq, NULL, mcs5000_ts_interrupt,
-			IRQF_TRIGGER_LOW | IRQF_ONESHOT, "mcs5000_ts", data);
-
-	if (ret < 0) {
+	ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+			mcs5000_ts_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+			"mcs5000_ts", data);
+	if (ret) {
 		dev_err(&client->dev, "Failed to register interrupt\n");
-		goto err_free_mem;
+		return ret;
 	}
 
 	ret = input_register_device(data->input_dev);
-	if (ret < 0)
-		goto err_free_irq;
+	if (ret < 0) {
+		dev_err(&client->dev, "Failed to register input device\n");
+		return ret;
+	}
 
 	mcs5000_ts_phys_init(data);
 	i2c_set_clientdata(client, data);
 
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, data);
-err_free_mem:
-	input_free_device(input_dev);
-	kfree(data);
-	return ret;
-}
-
-static int mcs5000_ts_remove(struct i2c_client *client)
-{
-	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
-
-	free_irq(client->irq, data);
-	input_unregister_device(data->input_dev);
-	kfree(data);
-
-	return 0;
 }
 
 #ifdef CONFIG_PM
@@ -291,7 +274,6 @@ MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
 
 static struct i2c_driver mcs5000_ts_driver = {
 	.probe		= mcs5000_ts_probe,
-	.remove		= mcs5000_ts_remove,
 	.driver = {
 		.name = "mcs5000_ts",
 #ifdef CONFIG_PM
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v4 1/2] Input: mcs_touchkey: use devm_* functions
From: Beomho Seo @ 2014-05-28  8:41 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo
In-Reply-To: <1401266481-22065-1-git-send-email-beomho.seo@samsung.com>

This patch use devm_* funtions in mcs_touchkey driver.
As a result, error path and remove() funtion is simplified.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
---
Changes in v4:
- free_irq are back again for equivalent transformation.
Changes in v3:
- Some codes are back again. use fw_version, driver name and poweron.
Changes in v2:
- Additionally use devm_kzalloc for mcs_touchkey_data struct.

---
 drivers/input/keyboard/mcs_touchkey.c |   31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 1da8e0b..d85adbf 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -113,14 +113,11 @@ static int mcs_touchkey_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
-	data = kzalloc(sizeof(struct mcs_touchkey_data) +
-			sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
-			GFP_KERNEL);
-	input_dev = input_allocate_device();
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	input_dev = devm_input_allocate_device(&client->dev);
 	if (!data || !input_dev) {
 		dev_err(&client->dev, "Failed to allocate memory\n");
-		error = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	data->client = client;
@@ -143,7 +140,7 @@ static int mcs_touchkey_probe(struct i2c_client *client,
 	if (fw_ver < 0) {
 		error = fw_ver;
 		dev_err(&client->dev, "i2c read error[%d]\n", error);
-		goto err_free_mem;
+		return error;
 	}
 	dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
 
@@ -176,27 +173,21 @@ static int mcs_touchkey_probe(struct i2c_client *client,
 		data->poweron(true);
 	}
 
-	error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
-				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-				     client->dev.driver->name, data);
+	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+				mcs_touchkey_interrupt,	IRQF_TRIGGER_FALLING |
+				IRQF_ONESHOT, client->dev.driver->name, data);
 	if (error) {
 		dev_err(&client->dev, "Failed to register interrupt\n");
-		goto err_free_mem;
+		return error;
 	}
 
 	error = input_register_device(input_dev);
 	if (error)
-		goto err_free_irq;
+		dev_err(&client->dev, "Failed to register input device\n");
+		return error;
 
 	i2c_set_clientdata(client, data);
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, data);
-err_free_mem:
-	input_free_device(input_dev);
-	kfree(data);
-	return error;
 }
 
 static int mcs_touchkey_remove(struct i2c_client *client)
@@ -206,8 +197,6 @@ static int mcs_touchkey_remove(struct i2c_client *client)
 	free_irq(client->irq, data);
 	if (data->poweron)
 		data->poweron(false);
-	input_unregister_device(data->input_dev);
-	kfree(data);
 
 	return 0;
 }
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v4 0/2] Use devm_* functions for Melfas touch device
From: Beomho Seo @ 2014-05-28  8:41 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov, jy0922.shim, sachin.kamat
  Cc: myungjoo.ham, jh80.chung, cw00.choi, Beomho Seo

This patch set devm_* functions in Melfas touche device driver.
As a result, error path and remove() function is simplified.

Changes in v4:
- mcs_touchkey: add free_irq for equivalent transformation.

Changes in v3:
- mcs_touchkey: Some codes are back again.

Changes in v2:
- Additionally use devm_kzalloc mcs_[touchkey/ts]_data struct.


Beomho Seo (2):
  Input: mcs_touchkey: use devm_* functions
  Input: mcs5000_ts: use devm_* functions

 drivers/input/keyboard/mcs_touchkey.c  |   31 ++++++++---------------
 drivers/input/touchscreen/mcs5000_ts.c |   42 +++++++++-----------------------
 2 files changed, 22 insertions(+), 51 deletions(-)

-- 
1.7.9.5


^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox