First round of IIO new stuff and cleanups for 3.9

Here we have:
 * RTC driver for the hid-sensor hubs.  This is routed through here with
   agreement of Jiri Kosina and Andrew Morton.
 * Some small patches doing dead code removal and fixing some comments.
 * max1363 - move to the triggered_buffer helpers (basically duplicate code
   removal).
 * lp8788 - parent device change from the i2c device to the intermediate mfd.
 
 So the bulk of what we have is actually outside the IIO tree but the RTC
 driver in question is dependent on some patches that directly effect IIO so
 I am routing it through IIO with the agreement of the relevant maintainers
 (Andrew is acting as maintainer of RTC at the moment).  The majority of
 HID-sensor related code is in IIO and it now crosses 3 subsystems so it
 was going to be a bit awkward whatever route it took.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.19 (GNU/Linux)
 
 iQIcBAABAgAGBQJQ6adzAAoJEFSFNJnE9BaIdXUP/3evWP7pfIME87JWjG7/jE4G
 OD1Wv5S0Iq7qJUYrd1GD4jeGleXQbsWfb956mXG3CyVMWzZhn5Yfn6rLYCBwET+7
 NYDh/4e5qLzcdENtqMrXYlb+PNMnv07lCsOhxTHEm8EaqkaQBd+AYZTm8qWaADt8
 Cd26ItGPLAgWlyaskF1dfu0sZAR2C7s4dBqqGdD7Yt/pk8jF7AllCcPKgZ48vhBI
 oVP2Gmxs5Tt2CtmOhJMrtx+u5SqMyOyIgf6BFxVSjTBBDyD3uBBZ/VqlKVkBOCE6
 DeCoBjkEuu0nnI6akygcQLHPa3MbLYum42WaSLX12VG4ZMcxYwRoimzSPwDDeSyP
 oJd8V9RhvlqOHbvKo2aF6gDYRkVd2RXo32B8xrpB8WvAuI/EEYn/1BpeV8WkPph3
 hngFV20r7pevm5mtjdRK+1tx8Vp8NjpWp0Y/dwfsbr6F4LJMa2cKfpKQWHoD51ZK
 LNy4lRLTEP0iJWpUE752Zt0FBFpTJO65nsHQ6QkWELRBxJ0WjM9yy3ArWxBz1EPv
 gzbWJpT4B3XnKn5qx0TZ0tCPqTAeqVlHAUwp4VxhQMaa+qxWKDjvhKO58GaEifep
 9yv7sVhUo4sULNIMW0dT6stu/dAA5ygGu1Y387t+ZTQEv8gdGNljAua7bVNbQYxJ
 qqTTsjwx/rX+8NxQbPJh
 =vBZ+
 -----END PGP SIGNATURE-----

Merge tag 'iio-for-3.9a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan says:

	First round of IIO new stuff and cleanups for 3.9

	Here we have:
	* RTC driver for the hid-sensor hubs.  This is routed through here with
	  agreement of Jiri Kosina and Andrew Morton.
	* Some small patches doing dead code removal and fixing some comments.
	* max1363 - move to the triggered_buffer helpers (basically duplicate code
	  removal).
	* lp8788 - parent device change from the i2c device to the intermediate mfd.

	So the bulk of what we have is actually outside the IIO tree but the RTC
	driver in question is dependent on some patches that directly effect IIO so
	I am routing it through IIO with the agreement of the relevant maintainers
	(Andrew is acting as maintainer of RTC at the moment).  The majority of
	HID-sensor related code is in IIO and it now crosses 3 subsystems so it
	was going to be a bit awkward whatever route it took.
This commit is contained in:
Greg Kroah-Hartman 2013-01-07 09:53:39 -08:00
commit ecc3599396
18 changed files with 385 additions and 150 deletions

View File

@ -28,7 +28,6 @@
#include <linux/iio/buffer.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "../common/hid-sensors/hid-sensor-attributes.h"
#include "../common/hid-sensors/hid-sensor-trigger.h"
/*Format: HID-SENSOR-usage_id_in_hex*/
@ -44,7 +43,7 @@ enum accel_3d_channel {
struct accel_3d_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_iio_common common_attributes;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
u32 accel_val[ACCEL_3D_CHANNEL_MAX];
};

View File

@ -179,7 +179,7 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
ret = iio_map_array_register(indio_dev, map);
if (ret) {
dev_err(adc->lp->dev, "iio map err: %d\n", ret);
dev_err(&indio_dev->dev, "iio map err: %d\n", ret);
return ret;
}
@ -214,7 +214,7 @@ static int __devinit lp8788_adc_probe(struct platform_device *pdev)
mutex_init(&adc->lock);
indio_dev->dev.parent = lp->dev;
indio_dev->dev.parent = &pdev->dev;
indio_dev->name = pdev->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &lp8788_adc_info;
@ -223,7 +223,7 @@ static int __devinit lp8788_adc_probe(struct platform_device *pdev)
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(lp->dev, "iio dev register err: %d\n", ret);
dev_err(&pdev->dev, "iio dev register err: %d\n", ret);
goto err_iio_device;
}

View File

@ -39,6 +39,7 @@
#include <linux/iio/driver.h>
#include <linux/iio/kfifo_buf.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#define MAX1363_SETUP_BYTE(a) ((a) | 0x80)
@ -55,7 +56,7 @@
#define MAX1363_SETUP_POWER_UP_INT_REF 0x10
#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00
/* think about includeing max11600 etc - more settings */
/* think about including max11600 etc - more settings */
#define MAX1363_SETUP_EXT_CLOCK 0x08
#define MAX1363_SETUP_INT_CLOCK 0x00
#define MAX1363_SETUP_UNIPOLAR 0x00
@ -86,7 +87,7 @@
/* max123{6-9} only */
#define MAX1236_SCAN_MID_TO_CHANNEL 0x40
/* max1363 only - merely part of channel selects or don't care for others*/
/* max1363 only - merely part of channel selects or don't care for others */
#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18
#define MAX1363_CHANNEL_SEL(a) ((a) << 1)
@ -133,7 +134,7 @@ enum max1363_modes {
* @mode_list: array of available scan modes
* @default_mode: the scan mode in which the chip starts up
* @int_vref_mv: the internal reference voltage
* @num_channels: number of channels
* @num_modes: number of modes
* @bits: accuracy of the adc in bits
*/
struct max1363_chip_info {
@ -152,7 +153,7 @@ struct max1363_chip_info {
* @client: i2c_client
* @setupbyte: cache of current device setup byte
* @configbyte: cache of current device config byte
* @chip_info: chip model specific constants, available modes etc
* @chip_info: chip model specific constants, available modes, etc.
* @current_mode: the scan mode of this chip
* @requestedmask: a valid requested set of channels
* @reg: supply regulator
@ -293,7 +294,7 @@ static const struct max1363_mode max1363_mode_table[] = {
static const struct max1363_mode
*max1363_match_mode(const unsigned long *mask,
const struct max1363_chip_info *ci)
const struct max1363_chip_info *ci)
{
int i;
if (mask)
@ -1394,7 +1395,7 @@ static int max1363_initial_setup(struct max1363_state *st)
| MAX1363_SETUP_UNIPOLAR
| MAX1363_SETUP_NORESET;
/* Set scan mode writes the config anyway so wait until then*/
/* Set scan mode writes the config anyway so wait until then */
st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte);
st->current_mode = &max1363_mode_table[st->chip_info->default_mode];
st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte);
@ -1423,7 +1424,6 @@ static int __devinit max1363_alloc_scan_masks(struct iio_dev *indio_dev)
return 0;
}
static irqreturn_t max1363_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
@ -1483,48 +1483,6 @@ static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = {
.predisable = &iio_triggered_buffer_predisable,
};
static int max1363_register_buffered_funcs_and_init(struct iio_dev *indio_dev)
{
struct max1363_state *st = iio_priv(indio_dev);
int ret = 0;
indio_dev->buffer = iio_kfifo_allocate(indio_dev);
if (!indio_dev->buffer) {
ret = -ENOMEM;
goto error_ret;
}
indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
&max1363_trigger_handler,
IRQF_ONESHOT,
indio_dev,
"%s_consumer%d",
st->client->name,
indio_dev->id);
if (indio_dev->pollfunc == NULL) {
ret = -ENOMEM;
goto error_deallocate_sw_rb;
}
/* Buffer functions - here trigger setup related */
indio_dev->setup_ops = &max1363_buffered_setup_ops;
/* Flag that polled buffering is possible */
indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
return 0;
error_deallocate_sw_rb:
iio_kfifo_free(indio_dev->buffer);
error_ret:
return ret;
}
static void max1363_buffer_cleanup(struct iio_dev *indio_dev)
{
/* ensure that the trigger has been detached */
iio_dealloc_pollfunc(indio_dev->pollfunc);
iio_kfifo_free(indio_dev->buffer);
}
static int __devinit max1363_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@ -1564,7 +1522,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
if (ret)
goto error_disable_reg;
/* Estabilish that the iio_dev is a child of the i2c device */
/* Establish that the iio_dev is a child of the i2c device */
indio_dev->dev.parent = &client->dev;
indio_dev->name = id->name;
indio_dev->channels = st->chip_info->channels;
@ -1577,16 +1535,11 @@ static int __devinit max1363_probe(struct i2c_client *client,
if (ret < 0)
goto error_free_available_scan_masks;
ret = max1363_register_buffered_funcs_and_init(indio_dev);
ret = iio_triggered_buffer_setup(indio_dev, NULL,
&max1363_trigger_handler, &max1363_buffered_setup_ops);
if (ret)
goto error_free_available_scan_masks;
ret = iio_buffer_register(indio_dev,
st->chip_info->channels,
st->chip_info->num_channels);
if (ret)
goto error_cleanup_buffer;
if (client->irq) {
ret = request_threaded_irq(st->client->irq,
NULL,
@ -1607,9 +1560,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
error_free_irq:
free_irq(st->client->irq, indio_dev);
error_uninit_buffer:
iio_buffer_unregister(indio_dev);
error_cleanup_buffer:
max1363_buffer_cleanup(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
error_free_available_scan_masks:
kfree(indio_dev->available_scan_masks);
error_unregister_map:
@ -1632,8 +1583,7 @@ static int __devexit max1363_remove(struct i2c_client *client)
iio_device_unregister(indio_dev);
if (client->irq)
free_irq(st->client->irq, indio_dev);
iio_buffer_unregister(indio_dev);
max1363_buffer_cleanup(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
kfree(indio_dev->available_scan_masks);
if (!IS_ERR(st->reg)) {
regulator_disable(st->reg);

View File

@ -25,7 +25,6 @@
#include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include "hid-sensor-attributes.h"
static int pow_10(unsigned power)
{
@ -114,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
return value;
}
int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
int *val1, int *val2)
{
s32 value;
@ -141,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
}
EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
int val1, int val2)
{
s32 value;
@ -169,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
}
EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
int *val1, int *val2)
{
s32 value;
@ -191,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
}
EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
int val1, int val2)
{
s32 value;
@ -212,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
u32 usage_id,
struct hid_sensor_iio_common *st)
struct hid_sensor_common *st)
{
sensor_hub_input_get_attribute_info(hsdev,

View File

@ -1,57 +0,0 @@
/*
* HID Sensors Driver
* Copyright (c) 2012, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#ifndef _HID_SENSORS_ATTRIBUTES_H
#define _HID_SENSORS_ATTRIBUTES_H
/* Common hid sensor iio structure */
struct hid_sensor_iio_common {
struct hid_sensor_hub_device *hsdev;
struct platform_device *pdev;
unsigned usage_id;
bool data_ready;
struct hid_sensor_hub_attribute_info poll;
struct hid_sensor_hub_attribute_info report_state;
struct hid_sensor_hub_attribute_info power_state;
struct hid_sensor_hub_attribute_info sensitivity;
};
/*Convert from hid unit expo to regular exponent*/
static inline int hid_sensor_convert_exponent(int unit_expo)
{
if (unit_expo < 0x08)
return unit_expo;
else if (unit_expo <= 0x0f)
return -(0x0f-unit_expo+1);
else
return 0;
}
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
u32 usage_id,
struct hid_sensor_iio_common *st);
int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
int val1, int val2);
int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
int *val1, int *val2);
int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
int val1, int val2);
int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
int *val1, int *val2);
#endif

View File

@ -26,13 +26,12 @@
#include <linux/iio/iio.h>
#include <linux/iio/trigger.h>
#include <linux/iio/sysfs.h>
#include "hid-sensor-attributes.h"
#include "hid-sensor-trigger.h"
static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
bool state)
{
struct hid_sensor_iio_common *st = trig->private_data;
struct hid_sensor_common *st = trig->private_data;
int state_val;
state_val = state ? 1 : 0;
@ -64,7 +63,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
};
int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
struct hid_sensor_iio_common *attrb)
struct hid_sensor_common *attrb)
{
int ret;
struct iio_trigger *trig;

View File

@ -20,7 +20,7 @@
#define _HID_SENSOR_TRIGGER_H
int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
struct hid_sensor_iio_common *attrb);
struct hid_sensor_common *attrb);
void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
#endif

View File

@ -28,7 +28,6 @@
#include <linux/iio/buffer.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "../common/hid-sensors/hid-sensor-attributes.h"
#include "../common/hid-sensors/hid-sensor-trigger.h"
/*Format: HID-SENSOR-usage_id_in_hex*/
@ -44,7 +43,7 @@ enum gyro_3d_channel {
struct gyro_3d_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_iio_common common_attributes;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
u32 gyro_val[GYRO_3D_CHANNEL_MAX];
};

View File

@ -28,7 +28,6 @@
#include <linux/iio/buffer.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "../common/hid-sensors/hid-sensor-attributes.h"
#include "../common/hid-sensors/hid-sensor-trigger.h"
/*Format: HID-SENSOR-usage_id_in_hex*/
@ -39,7 +38,7 @@
struct als_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_iio_common common_attributes;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info als_illum;
u32 illum;
};

View File

@ -28,7 +28,6 @@
#include <linux/iio/buffer.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "../common/hid-sensors/hid-sensor-attributes.h"
#include "../common/hid-sensors/hid-sensor-trigger.h"
/*Format: HID-SENSOR-usage_id_in_hex*/
@ -44,7 +43,7 @@ enum magn_3d_channel {
struct magn_3d_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_iio_common common_attributes;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
u32 magn_val[MAGN_3D_CHANNEL_MAX];
};

View File

@ -1165,4 +1165,20 @@ config RTC_DRV_SNVS
This driver can also be built as a module, if so, the module
will be called "rtc-snvs".
comment "HID Sensor RTC drivers"
config RTC_DRV_HID_SENSOR_TIME
tristate "HID Sensor Time"
depends on USB_HID
select IIO
select HID_SENSOR_HUB
select HID_SENSOR_IIO_COMMON
help
Say yes here to build support for the HID Sensors of type Time.
This drivers makes such sensors available as RTCs.
If this driver is compiled as a module, it will be named
rtc-hid-sensor-time.
endif # RTC_CLASS

View File

@ -52,6 +52,7 @@ obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o
obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o
obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o

View File

@ -0,0 +1,291 @@
/*
* HID Sensor Time Driver
* Copyright (c) 2012, Alexander Holler.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h>
#include <linux/rtc.h>
/* Format: HID-SENSOR-usage_id_in_hex */
/* Usage ID from spec for Time: 0x2000A0 */
#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
enum hid_time_channel {
CHANNEL_SCAN_INDEX_YEAR,
CHANNEL_SCAN_INDEX_MONTH,
CHANNEL_SCAN_INDEX_DAY,
CHANNEL_SCAN_INDEX_HOUR,
CHANNEL_SCAN_INDEX_MINUTE,
CHANNEL_SCAN_INDEX_SECOND,
TIME_RTC_CHANNEL_MAX,
};
struct hid_time_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
struct rtc_time last_time;
spinlock_t lock_last_time;
struct completion comp_last_time;
struct rtc_time time_buf;
struct rtc_device *rtc;
};
static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
HID_USAGE_SENSOR_TIME_YEAR,
HID_USAGE_SENSOR_TIME_MONTH,
HID_USAGE_SENSOR_TIME_DAY,
HID_USAGE_SENSOR_TIME_HOUR,
HID_USAGE_SENSOR_TIME_MINUTE,
HID_USAGE_SENSOR_TIME_SECOND,
};
/* Channel names for verbose error messages */
static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
"year", "month", "day", "hour", "minute", "second",
};
/* Callback handler to send event after all samples are received and captured */
static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
unsigned usage_id, void *priv)
{
unsigned long flags;
struct hid_time_state *time_state = platform_get_drvdata(priv);
spin_lock_irqsave(&time_state->lock_last_time, flags);
time_state->last_time = time_state->time_buf;
spin_unlock_irqrestore(&time_state->lock_last_time, flags);
complete(&time_state->comp_last_time);
return 0;
}
static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
unsigned usage_id, size_t raw_len,
char *raw_data, void *priv)
{
struct hid_time_state *time_state = platform_get_drvdata(priv);
struct rtc_time *time_buf = &time_state->time_buf;
switch (usage_id) {
case HID_USAGE_SENSOR_TIME_YEAR:
time_buf->tm_year = *(u8 *)raw_data;
if (time_buf->tm_year < 70)
/* assume we are in 1970...2069 */
time_buf->tm_year += 100;
break;
case HID_USAGE_SENSOR_TIME_MONTH:
/* sensor sending the month as 1-12, we need 0-11 */
time_buf->tm_mon = *(u8 *)raw_data-1;
break;
case HID_USAGE_SENSOR_TIME_DAY:
time_buf->tm_mday = *(u8 *)raw_data;
break;
case HID_USAGE_SENSOR_TIME_HOUR:
time_buf->tm_hour = *(u8 *)raw_data;
break;
case HID_USAGE_SENSOR_TIME_MINUTE:
time_buf->tm_min = *(u8 *)raw_data;
break;
case HID_USAGE_SENSOR_TIME_SECOND:
time_buf->tm_sec = *(u8 *)raw_data;
break;
default:
return -EINVAL;
}
return 0;
}
/* small helper, haven't found any other way */
static const char *hid_time_attrib_name(u32 attrib_id)
{
static const char unknown[] = "unknown";
unsigned i;
for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
if (hid_time_addresses[i] == attrib_id)
return hid_time_channel_names[i];
}
return unknown; /* should never happen */
}
static int hid_time_parse_report(struct platform_device *pdev,
struct hid_sensor_hub_device *hsdev,
unsigned usage_id,
struct hid_time_state *time_state)
{
int report_id, i;
for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
if (sensor_hub_input_get_attribute_info(hsdev,
HID_INPUT_REPORT, usage_id,
hid_time_addresses[i],
&time_state->info[i]) < 0)
return -EINVAL;
/* Check the (needed) attributes for sanity */
report_id = time_state->info[0].report_id;
if (report_id < 0) {
dev_err(&pdev->dev, "bad report ID!\n");
return -EINVAL;
}
for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
if (time_state->info[i].report_id != report_id) {
dev_err(&pdev->dev,
"not all needed attributes inside the same report!\n");
return -EINVAL;
}
if (time_state->info[i].size != 1) {
dev_err(&pdev->dev,
"attribute '%s' not 8 bits wide!\n",
hid_time_attrib_name(
time_state->info[i].attrib_id));
return -EINVAL;
}
if (time_state->info[i].units !=
HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
/* allow attribute seconds with unit seconds */
!(time_state->info[i].attrib_id ==
HID_USAGE_SENSOR_TIME_SECOND &&
time_state->info[i].units ==
HID_USAGE_SENSOR_UNITS_SECOND)) {
dev_err(&pdev->dev,
"attribute '%s' hasn't a unit of type 'none'!\n",
hid_time_attrib_name(
time_state->info[i].attrib_id));
return -EINVAL;
}
if (time_state->info[i].unit_expo) {
dev_err(&pdev->dev,
"attribute '%s' hasn't a unit exponent of 1!\n",
hid_time_attrib_name(
time_state->info[i].attrib_id));
return -EINVAL;
}
}
return 0;
}
static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
unsigned long flags;
struct hid_time_state *time_state =
platform_get_drvdata(to_platform_device(dev));
int ret;
INIT_COMPLETION(time_state->comp_last_time);
/* get a report with all values through requesting one value */
sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
time_state->info[0].report_id);
/* wait for all values (event) */
ret = wait_for_completion_killable_timeout(
&time_state->comp_last_time, HZ*6);
if (ret > 0) {
/* no error */
spin_lock_irqsave(&time_state->lock_last_time, flags);
*tm = time_state->last_time;
spin_unlock_irqrestore(&time_state->lock_last_time, flags);
return 0;
}
if (!ret)
return -EIO; /* timeouted */
return ret; /* killed (-ERESTARTSYS) */
}
static const struct rtc_class_ops hid_time_rtc_ops = {
.read_time = hid_rtc_read_time,
};
static int hid_time_probe(struct platform_device *pdev)
{
int ret = 0;
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
sizeof(struct hid_time_state), GFP_KERNEL);
if (time_state == NULL)
return -ENOMEM;
platform_set_drvdata(pdev, time_state);
init_completion(&time_state->comp_last_time);
time_state->common_attributes.hsdev = hsdev;
time_state->common_attributes.pdev = pdev;
ret = hid_sensor_parse_common_attributes(hsdev,
HID_USAGE_SENSOR_TIME,
&time_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes!\n");
return ret;
}
ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
time_state);
if (ret) {
dev_err(&pdev->dev, "failed to setup attributes!\n");
return ret;
}
time_state->callbacks.send_event = hid_time_proc_event;
time_state->callbacks.capture_sample = hid_time_capture_sample;
time_state->callbacks.pdev = pdev;
ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
&time_state->callbacks);
if (ret < 0) {
dev_err(&pdev->dev, "register callback failed!\n");
return ret;
}
time_state->rtc = rtc_device_register("hid-sensor-time",
&pdev->dev, &hid_time_rtc_ops, THIS_MODULE);
if (IS_ERR(time_state->rtc)) {
dev_err(&pdev->dev, "rtc device register failed!\n");
return PTR_ERR(time_state->rtc);
}
return ret;
}
static int hid_time_remove(struct platform_device *pdev)
{
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct hid_time_state *time_state = platform_get_drvdata(pdev);
rtc_device_unregister(time_state->rtc);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
return 0;
}
static struct platform_driver hid_time_platform_driver = {
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
},
.probe = hid_time_probe,
.remove = hid_time_remove,
};
module_platform_driver(hid_time_platform_driver);
MODULE_DESCRIPTION("HID Sensor Time");
MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
MODULE_LICENSE("GPL");

View File

@ -75,11 +75,6 @@ static const char * const mxs_lradc_irq_name[] = {
"mxs-lradc-button1",
};
struct mxs_lradc_chan {
uint8_t slot;
uint8_t flags;
};
struct mxs_lradc {
struct device *dev;
void __iomem *base;
@ -90,8 +85,6 @@ struct mxs_lradc {
struct mutex lock;
uint8_t enable;
struct completion completion;
};

View File

@ -54,7 +54,7 @@ struct iio_dummy_accel_calibscale {
static const struct iio_dummy_accel_calibscale dummy_scales[] = {
{ 0, 100, 0x8 }, /* 0.000100 */
{ 0, 133, 0x7 }, /* 0.000133 */
{ 733, 13, 0x9 }, /* 733.00013 */
{ 733, 13, 0x9 }, /* 733.000013 */
};
/*
@ -284,7 +284,7 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
/**
* iio_dummy_write_raw() - data write function.
* @indio_dev: the struct iio_dev associated with this device instance
* @chan: the channel whose data is to be read
* @chan: the channel whose data is to be written
* @val: first element of value to set (typically INT)
* @val2: second element of value to set (typically MICRO)
* @mask: what we actually want to write. 0 is the channel, everything else

View File

@ -155,7 +155,7 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev,
* occurs, this function is run. Typically this grabs data
* from the device.
*
* NULL for the top half. This is normally implemented only if we
* NULL for the bottom half. This is normally implemented only if we
* either want to ping a capture now pin (no sleeping) or grab
* a timestamp as close as possible to a data ready trigger firing.
*

View File

@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
*/
int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
u32 field_index, s32 *value);
/* hid-sensor-attributes */
/* Common hid sensor iio structure */
struct hid_sensor_common {
struct hid_sensor_hub_device *hsdev;
struct platform_device *pdev;
unsigned usage_id;
bool data_ready;
struct hid_sensor_hub_attribute_info poll;
struct hid_sensor_hub_attribute_info report_state;
struct hid_sensor_hub_attribute_info power_state;
struct hid_sensor_hub_attribute_info sensitivity;
};
/*Convert from hid unit expo to regular exponent*/
static inline int hid_sensor_convert_exponent(int unit_expo)
{
if (unit_expo < 0x08)
return unit_expo;
else if (unit_expo <= 0x0f)
return -(0x0f-unit_expo+1);
else
return 0;
}
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
u32 usage_id,
struct hid_sensor_common *st);
int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
int val1, int val2);
int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
int *val1, int *val2);
int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
int val1, int val2);
int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
int *val1, int *val2);
#endif

View File

@ -66,6 +66,15 @@
#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS 0x200486
#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS 0x200487
/* Time (2000a0) */
#define HID_USAGE_SENSOR_TIME 0x2000a0
#define HID_USAGE_SENSOR_TIME_YEAR 0x200521
#define HID_USAGE_SENSOR_TIME_MONTH 0x200522
#define HID_USAGE_SENSOR_TIME_DAY 0x200523
#define HID_USAGE_SENSOR_TIME_HOUR 0x200525
#define HID_USAGE_SENSOR_TIME_MINUTE 0x200526
#define HID_USAGE_SENSOR_TIME_SECOND 0x200527
/* Units */
#define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED 0x00
#define HID_USAGE_SENSOR_UNITS_LUX 0x01