From: Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
To: Alan Cox <alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/4] hmc6352: Add driver for the HMC6352 compass
Date: Wed, 14 Apr 2010 17:39:32 +0100 [thread overview]
Message-ID: <4BC5EFC4.5030802@cam.ac.uk> (raw)
In-Reply-To: <20100414161904.713eef78-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
Looks good to me,
Acked-by: Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
On 04/14/10 16:19, Alan Cox wrote:
> Ripping it out of hwmon and applying the hedge trimmers to everything not
> needed and we get this for drivers/misc. I've also swapped the command
> codes to characters as the datasheet specifies them in ascii.
>
> --------------------------------8<------------------------------
>
> hmc6352: Add driver for the HMC6352 compass
>
> From: Kalhan Trisal <kalhan.trisal-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> This driver will report the heading values in degrees to the sysfs interface.
> The values returned are headings . e.g. 245.6
>
> (Some cleanups from Alan Cox)
>
> Signed-off-by: Kalhan Trisal <kalhan.trisal-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Alan Cox <alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
>
> drivers/misc/Kconfig | 7 ++
> drivers/misc/Makefile | 1
> drivers/misc/hmc6352.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 207 insertions(+), 0 deletions(-)
> create mode 100644 drivers/misc/hmc6352.c
>
>
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 2191c8d..e626bac 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -278,6 +278,13 @@ config SENSORS_TSL2550
> This driver can also be built as a module. If so, the module
> will be called tsl2550.
>
> +config HMC6352
> + tristate "Honeywell HMC6352 compass"
> + depends on I2C
> + help
> + This driver provides support for the Honeywell HMC6352 compass,
> + providing configuration and heading data via sysfs.
> +
> config EP93XX_PWM
> tristate "EP93xx PWM support"
> depends on ARCH_EP93XX
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 208ae30..620cf0b 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -26,5 +26,6 @@ obj-$(CONFIG_DS1682) += ds1682.o
> obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o
> obj-$(CONFIG_C2PORT) += c2port/
> obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/
> +obj-$(CONFIG_HMC6352) += hmc6352.o
> obj-y += eeprom/
> obj-y += cb710/
> diff --git a/drivers/misc/hmc6352.c b/drivers/misc/hmc6352.c
> new file mode 100644
> index 0000000..f4162ea
> --- /dev/null
> +++ b/drivers/misc/hmc6352.c
> @@ -0,0 +1,199 @@
> +/*
> + * hmc6352.c - Honeywell Compass Driver
> + *
> + * Copyright (C) 2009 Intel Corp
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + *
> + * This program is distributed in the hope that 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.,
> + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/i2c.h>
> +#include <linux/err.h>
> +#include <linux/delay.h>
> +#include <linux/sysfs.h>
> +
> +static ssize_t compass_calibration_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + int ret;
> + unsigned long val;
> + char cmd = 'C'; /* Calibrate */
> + char cmd1 = 'E'; /* Exit calibration mode */
> + struct i2c_msg msg[] = {
> + { client->addr, 0, 1, &cmd },
> + };
> + struct i2c_msg msg1[] = {
> + { client->addr, 0, 1, &cmd1 },
> + };
> +
> + if (strict_strtoul(buf, 10, &val))
> + return -EINVAL;
> + if (val == 1) {
> + ret = i2c_transfer(client->adapter, msg, 1);
> + if (ret != 1) {
> + dev_warn(dev, "hmc6352_comp: i2c calib start cmd failed\n");
> + return ret;
> + }
> + } else if (val == 2) {
> + ret = i2c_transfer(client->adapter, msg1, 1);
> + if (ret != 1) {
> + dev_warn(dev, "hmc6352_comp: i2c calib stop cmd failed\n");
> + return ret;
> + }
> + } else
> + return -EINVAL;
> +
> + return count;
> +}
> +
> +static ssize_t compass_heading_data_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> +
> + struct i2c_client *client = to_i2c_client(dev);
> + static char cmd = 'A'; /* Get Data */
> + unsigned char i2c_data[2];
> + unsigned int ret, ret_val;
> + struct i2c_msg msg[] = {
> + { client->addr, 0, 1, &cmd },
> + };
> + struct i2c_msg msg1[] = {
> + { client->addr, I2C_M_RD, 2, i2c_data },
> + };
> +
> + ret = i2c_transfer(client->adapter, msg, 1);
> + if (ret != 1) {
> + dev_warn(dev, "hmc6352: i2c cmd 0x41 failed\n");
> + return ret;
> + }
> + msleep(10); /* sending 0x41 cmd we need to wait for 7-10 milli second*/
> + ret = i2c_transfer(client->adapter, msg1, 1);
> + if (ret != 1) {
> + dev_warn(dev, "hmc6352: i2c read data cmd failed\n");
> + return ret;
> + }
> + ret_val = i2c_data[0];
> + ret_val = ((ret_val << 8) | i2c_data[1]);
> + return sprintf(buf, "%d.%d\n", ret_val/10, ret_val%10);
> +}
> +
> +static ssize_t compass_power_mode_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> +
> + struct i2c_client *client = to_i2c_client(dev);
> + unsigned long val;
> + unsigned int ret;
> + static char cmd = 'S'; /* Sleep mode */
> + static char cmd1 = 'W'; /* Wake up */
> + struct i2c_msg msg[] = {
> + { client->addr, 0, 1, &cmd },
> + };
> + struct i2c_msg msg1[] = {
> + { client->addr, 0, 1, &cmd1 },
> + };
> +
> + if (strict_strtoul(buf, 10, &val))
> + return -EINVAL;
> +
> + if (val == 0) {
> + ret = i2c_transfer(client->adapter, msg, 1);
> + if (ret != 1)
> + dev_warn(dev, "hmc6352: i2c cmd sleep mode failed\n");
> + } else if (val == 1) {
> + ret = i2c_transfer(client->adapter, msg1, 1);
> + if (ret != 1)
> + dev_warn(dev, "hmc6352: i2c cmd active mode failed\n");
> + } else
> + return -EINVAL;
> +
> + return count;
> +}
> +
> +static DEVICE_ATTR(heading, S_IRUGO, compass_heading_data_show, NULL);
> +static DEVICE_ATTR(calibration, S_IWUSR, NULL, compass_calibration_store);
> +static DEVICE_ATTR(power_state, S_IWUSR, NULL, compass_power_mode_store);
> +
> +static struct attribute *mid_att_compass[] = {
> + &dev_attr_heading.attr,
> + &dev_attr_calibration.attr,
> + &dev_attr_power_state.attr,
> + NULL
> +};
> +
> +static struct attribute_group m_compass_gr = {
> + .name = "hmc6352",
> + .attrs = mid_att_compass
> +};
> +
> +static int hmc6352_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + int res;
> +
> + res = sysfs_create_group(&client->dev.kobj, &m_compass_gr);
> + if (res) {
> + dev_err(&client->dev, "hmc6352: device_create_file failed\n");
> + return res;
> + }
> + dev_info(&client->dev, "%s HMC6352 compass chip found\n",
> + client->name);
> + return 0;
> +}
> +
> +static int hmc6352_remove(struct i2c_client *client)
> +{
> + sysfs_remove_group(&client->dev.kobj, &m_compass_gr);
> + return 0;
> +}
> +
> +static struct i2c_device_id hmc6352_id[] = {
> + { "hmc6352", 0 },
> + { }
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, hmc6352_id);
> +
> +static struct i2c_driver hmc6352_driver = {
> + .driver = {
> + .name = "hmc6352",
> + },
> + .probe = hmc6352_probe,
> + .remove = hmc6352_remove,
> + .id_table = hmc6352_id,
> +};
> +
> +static int __init sensor_hmc6352_init(void)
> +{
> + return i2c_add_driver(&hmc6352_driver);
> +}
> +
> +static void __exit sensor_hmc6352_exit(void)
> +{
> + i2c_del_driver(&hmc6352_driver);
> +}
> +
> +module_init(sensor_hmc6352_init);
> +module_exit(sensor_hmc6352_exit);
> +
> +MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org");
> +MODULE_DESCRIPTION("hmc6352 Compass Driver");
> +MODULE_LICENSE("GPL v2");
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2010-04-14 16:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-14 12:51 [PATCH 0/4] Various intel small device drivers Alan Cox
2010-04-14 12:51 ` [PATCH 1/4] hmc6352: Add driver for the HMC6352 compass Alan Cox
[not found] ` <20100414125136.23181.16788.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-04-14 13:48 ` Jonathan Cameron
[not found] ` <4BC5C7A8.1040807-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2010-04-14 14:32 ` Alan Cox
[not found] ` <20100414153234.22765666-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-04-14 14:51 ` Jonathan Cameron
2010-04-14 15:19 ` Alan Cox
[not found] ` <20100414161904.713eef78-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-04-14 16:39 ` Jonathan Cameron [this message]
2010-04-14 21:36 ` Joe Perches
[not found] ` <1271280993.1833.36.camel-AkRN8/LKpobuYGix6ZUp1Q@public.gmane.org>
2010-04-15 12:11 ` Alan Cox
[not found] ` <20100415131153.0e383ef3-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-04-15 15:57 ` Joe Perches
[not found] ` <4BC5D681.20707-tko9wxEg+fIOOJlXag/Snyp2UmYkHbXO@public.gmane.org>
2010-04-14 16:56 ` isl29020: ALS driver as misc device Alan Cox
[not found] ` <20100414175602.44580f3c-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-04-14 17:01 ` Greg KH
[not found] ` <20100414170153.GA7494-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2010-04-15 10:09 ` Jonathan Cameron
[not found] ` <4BC6E5CF.9070302-tko9wxEg+fIOOJlXag/Snyp2UmYkHbXO@public.gmane.org>
2010-04-15 11:17 ` Alan Cox
[not found] ` <20100415121726.1b2a5a87-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-04-26 10:59 ` Jonathan Cameron
2010-04-14 12:51 ` [PATCH 2/4] isl29020: ambient light sensor Alan Cox
[not found] ` <20100414125147.23181.5817.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-04-14 22:45 ` Daniel Mack
[not found] ` <20100414224542.GX30807-ahpEBR4enfnCULTFXS99ULNAH6kLmebB@public.gmane.org>
2010-04-14 22:35 ` Alan Cox
[not found] ` <20100414233554.3f020155-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2010-04-15 6:20 ` Daniel Mack
2010-04-15 10:15 ` Jonathan Cameron
[not found] ` <20100414124913.23181.75903.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-04-14 12:52 ` [PATCH 3/4] liss331d1: accelerometer driver Alan Cox
2010-04-14 22:12 ` Éric Piel
[not found] ` <4BC63DC5.8040501-hGVxb2UgFK3z+pZb47iToQ@public.gmane.org>
2010-04-14 22:34 ` Daniel Mack
[not found] ` <20100414223429.GW30807-ahpEBR4enfnCULTFXS99ULNAH6kLmebB@public.gmane.org>
2010-04-14 23:05 ` Neil Brown
2010-04-15 9:47 ` Éric Piel
2010-04-14 22:37 ` Alan Cox
2010-04-15 10:28 ` Jonathan Cameron
[not found] ` <4BC6EA64.4070308-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2010-04-15 10:02 ` Alan Cox
[not found] ` <20100414125155.23181.56610.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-04-15 19:12 ` Pavel Machek
2010-04-14 13:30 ` [PATCH 0/4] Various intel small device drivers Jean Delvare
[not found] ` <20100414153052.4e07f0cc-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-04-14 13:49 ` Alan Cox
[not found] ` <20100414144912.12c83f51-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-04-14 13:55 ` Jonathan Cameron
[not found] ` <4BC5C96B.7050901-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2010-04-14 14:19 ` Alan Cox
2010-04-14 12:52 ` [PATCH 4/4] emc1403: thermal sensor support Alan Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BC5EFC4.5030802@cam.ac.uk \
--to=jic23-kwpb1pkirijaa/9udqfwiw@public.gmane.org \
--cc=alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).