Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 1 | /* Copyright (C) 2010 Texas Instruments |
| 2 | Author: Shubhrajyoti Datta <shubhrajyoti@ti.com> |
| 3 | Acknowledgement: Jonathan Cameron <jic23@cam.ac.uk> for valuable inputs. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/i2c.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/types.h> |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 25 | #include <linux/iio/iio.h> |
| 26 | #include <linux/iio/sysfs.h> |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 27 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 28 | #define HMC5843_CONFIG_REG_A 0x00 |
| 29 | #define HMC5843_CONFIG_REG_B 0x01 |
| 30 | #define HMC5843_MODE_REG 0x02 |
| 31 | #define HMC5843_DATA_OUT_X_MSB_REG 0x03 |
| 32 | #define HMC5843_DATA_OUT_X_LSB_REG 0x04 |
| 33 | #define HMC5843_DATA_OUT_Y_MSB_REG 0x05 |
| 34 | #define HMC5843_DATA_OUT_Y_LSB_REG 0x06 |
| 35 | #define HMC5843_DATA_OUT_Z_MSB_REG 0x07 |
| 36 | #define HMC5843_DATA_OUT_Z_LSB_REG 0x08 |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 37 | /* Beware: Y and Z are exchanged on HMC5883 */ |
| 38 | #define HMC5883_DATA_OUT_Z_MSB_REG 0x05 |
| 39 | #define HMC5883_DATA_OUT_Z_LSB_REG 0x06 |
| 40 | #define HMC5883_DATA_OUT_Y_MSB_REG 0x07 |
| 41 | #define HMC5883_DATA_OUT_Y_LSB_REG 0x08 |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 42 | #define HMC5843_STATUS_REG 0x09 |
| 43 | #define HMC5843_ID_REG_A 0x0A |
| 44 | #define HMC5843_ID_REG_B 0x0B |
| 45 | #define HMC5843_ID_REG_C 0x0C |
| 46 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 47 | |
| 48 | /* |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 49 | * Beware: identification of the HMC5883 is still "H43"; |
| 50 | * I2C address is also unchanged |
| 51 | */ |
| 52 | #define HMC5843_ID_REG_LENGTH 0x03 |
| 53 | #define HMC5843_ID_STRING "H43" |
| 54 | #define HMC5843_I2C_ADDRESS 0x1E |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 55 | |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 56 | /* |
| 57 | * Range gain settings in (+-)Ga |
| 58 | * Beware: HMC5843 and HMC5883 have different recommended sensor field |
| 59 | * ranges; default corresponds to +-1.0 Ga and +-1.3 Ga, respectively |
| 60 | */ |
| 61 | #define HMC5843_RANGE_GAIN_OFFSET 0x05 |
| 62 | #define HMC5843_RANGE_GAIN_DEFAULT 0x01 |
| 63 | #define HMC5843_RANGE_GAIN_MAX 0x07 |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Device status |
| 67 | */ |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 68 | #define HMC5843_DATA_READY 0x01 |
| 69 | #define HMC5843_DATA_OUTPUT_LOCK 0x02 |
| 70 | /* Does not exist on HMC5883, not used */ |
| 71 | #define HMC5843_VOLTAGE_REGULATOR_ENABLED 0x04 |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * Mode register configuration |
| 75 | */ |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 76 | #define HMC5843_MODE_CONVERSION_CONTINUOUS 0x00 |
| 77 | #define HMC5843_MODE_CONVERSION_SINGLE 0x01 |
| 78 | #define HMC5843_MODE_IDLE 0x02 |
| 79 | #define HMC5843_MODE_SLEEP 0x03 |
| 80 | #define HMC5843_MODE_MASK 0x03 |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 81 | |
| 82 | /* |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 83 | * HMC5843: Minimum data output rate |
| 84 | * HMC5883: Typical data output rate |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 85 | */ |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 86 | #define HMC5843_RATE_OFFSET 0x02 |
| 87 | #define HMC5843_RATE_BITMASK 0x1C |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 88 | #define HMC5843_RATE_NOT_USED 0x07 |
| 89 | |
| 90 | /* |
| 91 | * Device measurement configuration |
| 92 | */ |
| 93 | #define HMC5843_MEAS_CONF_NORMAL 0x00 |
| 94 | #define HMC5843_MEAS_CONF_POSITIVE_BIAS 0x01 |
| 95 | #define HMC5843_MEAS_CONF_NEGATIVE_BIAS 0x02 |
| 96 | #define HMC5843_MEAS_CONF_NOT_USED 0x03 |
| 97 | #define HMC5843_MEAS_CONF_MASK 0x03 |
| 98 | |
| 99 | /* |
| 100 | * Scaling factors: 10000000/Gain |
| 101 | */ |
| 102 | static const int hmc5843_regval_to_nanoscale[] = { |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 103 | 6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714 |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 104 | }; |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 105 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 106 | static const int regval_to_input_field_mg[] = { |
| 107 | 700, |
| 108 | 1000, |
| 109 | 1500, |
| 110 | 2000, |
| 111 | 3200, |
| 112 | 3800, |
| 113 | 4500, |
| 114 | 6500 |
| 115 | }; |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 116 | static const char * const regval_to_samp_freq[] = { |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 117 | "0.5", |
| 118 | "1", |
| 119 | "2", |
| 120 | "5", |
| 121 | "10", |
| 122 | "20", |
| 123 | "50", |
| 124 | }; |
| 125 | |
| 126 | /* Addresses to scan: 0x1E */ |
| 127 | static const unsigned short normal_i2c[] = { HMC5843_I2C_ADDRESS, |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 128 | I2C_CLIENT_END }; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 129 | |
| 130 | /* Each client has this additional data */ |
| 131 | struct hmc5843_data { |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 132 | struct mutex lock; |
| 133 | u8 rate; |
| 134 | u8 meas_conf; |
| 135 | u8 operating_mode; |
| 136 | u8 range; |
| 137 | }; |
| 138 | |
| 139 | static void hmc5843_init_client(struct i2c_client *client); |
| 140 | |
| 141 | static s32 hmc5843_configure(struct i2c_client *client, |
| 142 | u8 operating_mode) |
| 143 | { |
| 144 | /* The lower two bits contain the current conversion mode */ |
| 145 | return i2c_smbus_write_byte_data(client, |
| 146 | HMC5843_MODE_REG, |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 147 | operating_mode & HMC5843_MODE_MASK); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 148 | } |
| 149 | |
Justin P. Mattock | 4abf6f8 | 2012-02-29 22:00:38 -0800 | [diff] [blame] | 150 | /* Return the measurement value from the specified channel */ |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 151 | static int hmc5843_read_measurement(struct iio_dev *indio_dev, |
| 152 | int address, |
| 153 | int *val) |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 154 | { |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 155 | struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 156 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 157 | s32 result; |
| 158 | |
| 159 | mutex_lock(&data->lock); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 160 | result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG); |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 161 | while (!(result & HMC5843_DATA_READY)) |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 162 | result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG); |
| 163 | |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 164 | result = i2c_smbus_read_word_data(client, address); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 165 | mutex_unlock(&data->lock); |
| 166 | if (result < 0) |
| 167 | return -EINVAL; |
| 168 | |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 169 | *val = (s16)swab16((u16)result); |
| 170 | return IIO_VAL_INT; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 171 | } |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 172 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * From the datasheet |
| 176 | * 0 - Continuous-Conversion Mode: In continuous-conversion mode, the |
Justin P. Mattock | 4abf6f8 | 2012-02-29 22:00:38 -0800 | [diff] [blame] | 177 | * device continuously performs conversions and places the result in the |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 178 | * data register. |
| 179 | * |
| 180 | * 1 - Single-Conversion Mode : device performs a single measurement, |
| 181 | * sets RDY high and returned to sleep mode |
| 182 | * |
| 183 | * 2 - Idle Mode : Device is placed in idle mode. |
| 184 | * |
| 185 | * 3 - Sleep Mode. Device is placed in sleep mode. |
| 186 | * |
| 187 | */ |
| 188 | static ssize_t hmc5843_show_operating_mode(struct device *dev, |
| 189 | struct device_attribute *attr, |
| 190 | char *buf) |
| 191 | { |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 192 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 193 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 194 | return sprintf(buf, "%d\n", data->operating_mode); |
| 195 | } |
| 196 | |
| 197 | static ssize_t hmc5843_set_operating_mode(struct device *dev, |
| 198 | struct device_attribute *attr, |
| 199 | const char *buf, |
| 200 | size_t count) |
| 201 | { |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 202 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 203 | struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 204 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 205 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
| 206 | unsigned long operating_mode = 0; |
| 207 | s32 status; |
| 208 | int error; |
| 209 | mutex_lock(&data->lock); |
Peter Meerwald | d32ec55 | 2012-05-16 18:22:04 +0200 | [diff] [blame] | 210 | error = kstrtoul(buf, 10, &operating_mode); |
Julia Lawall | d1ae4da | 2010-08-04 21:54:26 +0200 | [diff] [blame] | 211 | if (error) { |
| 212 | count = error; |
| 213 | goto exit; |
| 214 | } |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 215 | dev_dbg(dev, "set Conversion mode to %lu\n", operating_mode); |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 216 | if (operating_mode > HMC5843_MODE_SLEEP) { |
Julia Lawall | d1ae4da | 2010-08-04 21:54:26 +0200 | [diff] [blame] | 217 | count = -EINVAL; |
| 218 | goto exit; |
| 219 | } |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 220 | |
| 221 | status = i2c_smbus_write_byte_data(client, this_attr->address, |
| 222 | operating_mode); |
| 223 | if (status) { |
| 224 | count = -EINVAL; |
| 225 | goto exit; |
| 226 | } |
| 227 | data->operating_mode = operating_mode; |
| 228 | |
| 229 | exit: |
| 230 | mutex_unlock(&data->lock); |
| 231 | return count; |
| 232 | } |
| 233 | static IIO_DEVICE_ATTR(operating_mode, |
| 234 | S_IWUSR | S_IRUGO, |
| 235 | hmc5843_show_operating_mode, |
| 236 | hmc5843_set_operating_mode, |
| 237 | HMC5843_MODE_REG); |
| 238 | |
| 239 | /* |
| 240 | * API for setting the measurement configuration to |
| 241 | * Normal, Positive bias and Negative bias |
| 242 | * From the datasheet |
| 243 | * |
| 244 | * Normal measurement configuration (default): In normal measurement |
| 245 | * configuration the device follows normal measurement flow. Pins BP and BN |
| 246 | * are left floating and high impedance. |
| 247 | * |
| 248 | * Positive bias configuration: In positive bias configuration, a positive |
| 249 | * current is forced across the resistive load on pins BP and BN. |
| 250 | * |
| 251 | * Negative bias configuration. In negative bias configuration, a negative |
| 252 | * current is forced across the resistive load on pins BP and BN. |
| 253 | * |
| 254 | */ |
| 255 | static s32 hmc5843_set_meas_conf(struct i2c_client *client, |
| 256 | u8 meas_conf) |
| 257 | { |
Peter Meerwald | 0462e2b | 2012-05-16 18:22:03 +0200 | [diff] [blame] | 258 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
| 259 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 260 | u8 reg_val; |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 261 | reg_val = (meas_conf & HMC5843_MEAS_CONF_MASK) | |
| 262 | (data->rate << HMC5843_RATE_OFFSET); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 263 | return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val); |
| 264 | } |
| 265 | |
| 266 | static ssize_t hmc5843_show_measurement_configuration(struct device *dev, |
| 267 | struct device_attribute *attr, |
| 268 | char *buf) |
| 269 | { |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 270 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 271 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 272 | return sprintf(buf, "%d\n", data->meas_conf); |
| 273 | } |
| 274 | |
| 275 | static ssize_t hmc5843_set_measurement_configuration(struct device *dev, |
| 276 | struct device_attribute *attr, |
| 277 | const char *buf, |
| 278 | size_t count) |
| 279 | { |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 280 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 281 | struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); |
Peter Meerwald | 0462e2b | 2012-05-16 18:22:03 +0200 | [diff] [blame] | 282 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 283 | unsigned long meas_conf = 0; |
Peter Meerwald | e278df1 | 2012-05-17 02:28:09 +0200 | [diff] [blame^] | 284 | int error; |
| 285 | |
| 286 | error = kstrtoul(buf, 10, &meas_conf); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 287 | if (error) |
| 288 | return error; |
Peter Meerwald | e278df1 | 2012-05-17 02:28:09 +0200 | [diff] [blame^] | 289 | if (meas_conf >= HMC5843_MEAS_CONF_NOT_USED) |
| 290 | return -EINVAL; |
| 291 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 292 | mutex_lock(&data->lock); |
| 293 | |
| 294 | dev_dbg(dev, "set mode to %lu\n", meas_conf); |
| 295 | if (hmc5843_set_meas_conf(client, meas_conf)) { |
| 296 | count = -EINVAL; |
| 297 | goto exit; |
| 298 | } |
| 299 | data->meas_conf = meas_conf; |
| 300 | |
| 301 | exit: |
| 302 | mutex_unlock(&data->lock); |
| 303 | return count; |
| 304 | } |
| 305 | static IIO_DEVICE_ATTR(meas_conf, |
| 306 | S_IWUSR | S_IRUGO, |
| 307 | hmc5843_show_measurement_configuration, |
| 308 | hmc5843_set_measurement_configuration, |
| 309 | 0); |
| 310 | |
| 311 | /* |
| 312 | * From Datasheet |
| 313 | * The table shows the minimum data output |
| 314 | * Value | Minimum data output rate(Hz) |
| 315 | * 0 | 0.5 |
| 316 | * 1 | 1 |
| 317 | * 2 | 2 |
| 318 | * 3 | 5 |
| 319 | * 4 | 10 (default) |
| 320 | * 5 | 20 |
| 321 | * 6 | 50 |
| 322 | * 7 | Not used |
| 323 | */ |
Manuel Stahl | 11f05c7 | 2010-08-31 14:27:33 +0200 | [diff] [blame] | 324 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.5 1 2 5 10 20 50"); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 325 | |
| 326 | static s32 hmc5843_set_rate(struct i2c_client *client, |
| 327 | u8 rate) |
| 328 | { |
Peter Meerwald | 0462e2b | 2012-05-16 18:22:03 +0200 | [diff] [blame] | 329 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
| 330 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 331 | u8 reg_val; |
| 332 | |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 333 | reg_val = (data->meas_conf) | (rate << HMC5843_RATE_OFFSET); |
| 334 | if (rate >= HMC5843_RATE_NOT_USED) { |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 335 | dev_err(&client->dev, |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 336 | "This data output rate is not supported\n"); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 337 | return -EINVAL; |
| 338 | } |
| 339 | return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val); |
| 340 | } |
| 341 | |
Peter Meerwald | 13f6eb6 | 2012-05-17 02:28:08 +0200 | [diff] [blame] | 342 | static int hmc5843_check_sampling_frequency(struct hmc5843_data *data, |
| 343 | const char *buf) |
| 344 | { |
| 345 | const char * const *samp_freq = regval_to_samp_freq; |
| 346 | int i; |
| 347 | |
| 348 | for (i = 0; i < HMC5843_RATE_NOT_USED; i++) { |
| 349 | if (strncmp(buf, samp_freq[i], |
| 350 | strlen(samp_freq[i])) == 0) |
| 351 | return i; |
| 352 | } |
| 353 | |
| 354 | return -EINVAL; |
| 355 | } |
| 356 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 357 | static ssize_t set_sampling_frequency(struct device *dev, |
| 358 | struct device_attribute *attr, |
| 359 | const char *buf, size_t count) |
| 360 | { |
| 361 | |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 362 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 363 | struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 364 | struct hmc5843_data *data = iio_priv(indio_dev); |
Peter Meerwald | 13f6eb6 | 2012-05-17 02:28:08 +0200 | [diff] [blame] | 365 | int rate; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 366 | |
Peter Meerwald | 13f6eb6 | 2012-05-17 02:28:08 +0200 | [diff] [blame] | 367 | rate = hmc5843_check_sampling_frequency(data, buf); |
| 368 | if (rate < 0) { |
| 369 | dev_err(&client->dev, |
| 370 | "sampling frequency is not supported\n"); |
| 371 | return rate; |
| 372 | } |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 373 | |
| 374 | mutex_lock(&data->lock); |
Peter Meerwald | 13f6eb6 | 2012-05-17 02:28:08 +0200 | [diff] [blame] | 375 | dev_dbg(dev, "set rate to %d\n", rate); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 376 | if (hmc5843_set_rate(client, rate)) { |
| 377 | count = -EINVAL; |
| 378 | goto exit; |
| 379 | } |
| 380 | data->rate = rate; |
| 381 | |
| 382 | exit: |
| 383 | mutex_unlock(&data->lock); |
| 384 | return count; |
| 385 | } |
| 386 | |
| 387 | static ssize_t show_sampling_frequency(struct device *dev, |
| 388 | struct device_attribute *attr, char *buf) |
| 389 | { |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 390 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 391 | struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); |
| 392 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
Dan Carpenter | 213fd22 | 2010-08-10 07:37:33 +0200 | [diff] [blame] | 393 | s32 rate; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 394 | |
| 395 | rate = i2c_smbus_read_byte_data(client, this_attr->address); |
| 396 | if (rate < 0) |
Dan Carpenter | 213fd22 | 2010-08-10 07:37:33 +0200 | [diff] [blame] | 397 | return rate; |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 398 | rate = (rate & HMC5843_RATE_BITMASK) >> HMC5843_RATE_OFFSET; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 399 | return sprintf(buf, "%s\n", regval_to_samp_freq[rate]); |
| 400 | } |
| 401 | static IIO_DEVICE_ATTR(sampling_frequency, |
| 402 | S_IWUSR | S_IRUGO, |
| 403 | show_sampling_frequency, |
| 404 | set_sampling_frequency, |
| 405 | HMC5843_CONFIG_REG_A); |
| 406 | |
| 407 | /* |
| 408 | * From Datasheet |
| 409 | * Nominal gain settings |
| 410 | * Value | Sensor Input Field Range(Ga) | Gain(counts/ milli-gauss) |
| 411 | *0 |(+-)0.7 |1620 |
| 412 | *1 |(+-)1.0 |1300 |
| 413 | *2 |(+-)1.5 |970 |
| 414 | *3 |(+-)2.0 |780 |
| 415 | *4 |(+-)3.2 |530 |
| 416 | *5 |(+-)3.8 |460 |
| 417 | *6 |(+-)4.5 |390 |
| 418 | *7 |(+-)6.5 |280 |
| 419 | */ |
| 420 | static ssize_t show_range(struct device *dev, |
| 421 | struct device_attribute *attr, |
| 422 | char *buf) |
| 423 | { |
| 424 | u8 range; |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 425 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 426 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 427 | |
| 428 | range = data->range; |
| 429 | return sprintf(buf, "%d\n", regval_to_input_field_mg[range]); |
| 430 | } |
| 431 | |
| 432 | static ssize_t set_range(struct device *dev, |
| 433 | struct device_attribute *attr, |
| 434 | const char *buf, |
| 435 | size_t count) |
| 436 | { |
Lars-Peter Clausen | 527cf71 | 2012-05-12 15:39:52 +0200 | [diff] [blame] | 437 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 438 | struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); |
| 439 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 440 | struct hmc5843_data *data = iio_priv(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 441 | unsigned long range = 0; |
| 442 | int error; |
| 443 | mutex_lock(&data->lock); |
Peter Meerwald | d32ec55 | 2012-05-16 18:22:04 +0200 | [diff] [blame] | 444 | error = kstrtoul(buf, 10, &range); |
Julia Lawall | d1ae4da | 2010-08-04 21:54:26 +0200 | [diff] [blame] | 445 | if (error) { |
| 446 | count = error; |
| 447 | goto exit; |
| 448 | } |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 449 | dev_dbg(dev, "set range to %lu\n", range); |
| 450 | |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 451 | if (range > HMC5843_RANGE_GAIN_MAX) { |
Julia Lawall | d1ae4da | 2010-08-04 21:54:26 +0200 | [diff] [blame] | 452 | count = -EINVAL; |
| 453 | goto exit; |
| 454 | } |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 455 | |
| 456 | data->range = range; |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 457 | range = range << HMC5843_RANGE_GAIN_OFFSET; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 458 | if (i2c_smbus_write_byte_data(client, this_attr->address, range)) |
| 459 | count = -EINVAL; |
| 460 | |
Julia Lawall | d1ae4da | 2010-08-04 21:54:26 +0200 | [diff] [blame] | 461 | exit: |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 462 | mutex_unlock(&data->lock); |
| 463 | return count; |
| 464 | |
| 465 | } |
Jonathan Cameron | 322c956 | 2011-09-14 13:01:23 +0100 | [diff] [blame] | 466 | static IIO_DEVICE_ATTR(in_magn_range, |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 467 | S_IWUSR | S_IRUGO, |
| 468 | show_range, |
| 469 | set_range, |
| 470 | HMC5843_CONFIG_REG_B); |
| 471 | |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 472 | static int hmc5843_read_raw(struct iio_dev *indio_dev, |
| 473 | struct iio_chan_spec const *chan, |
| 474 | int *val, int *val2, |
| 475 | long mask) |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 476 | { |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 477 | struct hmc5843_data *data = iio_priv(indio_dev); |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 478 | |
| 479 | switch (mask) { |
Jonathan Cameron | 4d9948b | 2012-04-15 17:41:23 +0100 | [diff] [blame] | 480 | case IIO_CHAN_INFO_RAW: |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 481 | return hmc5843_read_measurement(indio_dev, |
| 482 | chan->address, |
| 483 | val); |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 484 | case IIO_CHAN_INFO_SCALE: |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 485 | *val = 0; |
| 486 | *val2 = hmc5843_regval_to_nanoscale[data->range]; |
| 487 | return IIO_VAL_INT_PLUS_NANO; |
| 488 | }; |
| 489 | return -EINVAL; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 490 | } |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 491 | |
| 492 | #define HMC5843_CHANNEL(axis, add) \ |
| 493 | { \ |
| 494 | .type = IIO_MAGN, \ |
| 495 | .modified = 1, \ |
| 496 | .channel2 = IIO_MOD_##axis, \ |
Jonathan Cameron | 4d9948b | 2012-04-15 17:41:23 +0100 | [diff] [blame] | 497 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ |
| 498 | IIO_CHAN_INFO_SCALE_SHARED_BIT, \ |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 499 | .address = add \ |
| 500 | } |
| 501 | |
| 502 | static const struct iio_chan_spec hmc5843_channels[] = { |
| 503 | HMC5843_CHANNEL(X, HMC5843_DATA_OUT_X_MSB_REG), |
| 504 | HMC5843_CHANNEL(Y, HMC5843_DATA_OUT_Y_MSB_REG), |
| 505 | HMC5843_CHANNEL(Z, HMC5843_DATA_OUT_Z_MSB_REG), |
| 506 | }; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 507 | |
| 508 | static struct attribute *hmc5843_attributes[] = { |
| 509 | &iio_dev_attr_meas_conf.dev_attr.attr, |
| 510 | &iio_dev_attr_operating_mode.dev_attr.attr, |
| 511 | &iio_dev_attr_sampling_frequency.dev_attr.attr, |
Jonathan Cameron | 322c956 | 2011-09-14 13:01:23 +0100 | [diff] [blame] | 512 | &iio_dev_attr_in_magn_range.dev_attr.attr, |
Manuel Stahl | 11f05c7 | 2010-08-31 14:27:33 +0200 | [diff] [blame] | 513 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 514 | NULL |
| 515 | }; |
| 516 | |
| 517 | static const struct attribute_group hmc5843_group = { |
| 518 | .attrs = hmc5843_attributes, |
| 519 | }; |
| 520 | |
| 521 | static int hmc5843_detect(struct i2c_client *client, |
| 522 | struct i2c_board_info *info) |
| 523 | { |
| 524 | unsigned char id_str[HMC5843_ID_REG_LENGTH]; |
| 525 | |
| 526 | if (client->addr != HMC5843_I2C_ADDRESS) |
| 527 | return -ENODEV; |
| 528 | |
| 529 | if (i2c_smbus_read_i2c_block_data(client, HMC5843_ID_REG_A, |
| 530 | HMC5843_ID_REG_LENGTH, id_str) |
| 531 | != HMC5843_ID_REG_LENGTH) |
| 532 | return -ENODEV; |
| 533 | |
| 534 | if (0 != strncmp(id_str, HMC5843_ID_STRING, HMC5843_ID_REG_LENGTH)) |
| 535 | return -ENODEV; |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | /* Called when we have found a new HMC5843. */ |
| 541 | static void hmc5843_init_client(struct i2c_client *client) |
| 542 | { |
Marek Belisko | 62d2feb | 2012-04-12 21:48:03 +0200 | [diff] [blame] | 543 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
| 544 | struct hmc5843_data *data = iio_priv(indio_dev); |
| 545 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 546 | hmc5843_set_meas_conf(client, data->meas_conf); |
| 547 | hmc5843_set_rate(client, data->rate); |
| 548 | hmc5843_configure(client, data->operating_mode); |
| 549 | i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_B, data->range); |
| 550 | mutex_init(&data->lock); |
| 551 | pr_info("HMC5843 initialized\n"); |
| 552 | } |
| 553 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 554 | static const struct iio_info hmc5843_info = { |
| 555 | .attrs = &hmc5843_group, |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 556 | .read_raw = &hmc5843_read_raw, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 557 | .driver_module = THIS_MODULE, |
| 558 | }; |
| 559 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 560 | static int hmc5843_probe(struct i2c_client *client, |
| 561 | const struct i2c_device_id *id) |
| 562 | { |
| 563 | struct hmc5843_data *data; |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 564 | struct iio_dev *indio_dev; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 565 | int err = 0; |
| 566 | |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 567 | indio_dev = iio_device_alloc(sizeof(*data)); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 568 | if (indio_dev == NULL) { |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 569 | err = -ENOMEM; |
| 570 | goto exit; |
| 571 | } |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 572 | |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 573 | /* default settings at probe */ |
| 574 | data = iio_priv(indio_dev); |
| 575 | data->meas_conf = HMC5843_MEAS_CONF_NORMAL; |
| 576 | data->range = HMC5843_RANGE_GAIN_DEFAULT; |
| 577 | data->operating_mode = HMC5843_MODE_CONVERSION_CONTINUOUS; |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 578 | |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 579 | i2c_set_clientdata(client, indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 580 | |
| 581 | /* Initialize the HMC5843 chip */ |
| 582 | hmc5843_init_client(client); |
| 583 | |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 584 | indio_dev->info = &hmc5843_info; |
Jonathan Cameron | 494c6b1 | 2011-08-12 17:47:58 +0100 | [diff] [blame] | 585 | indio_dev->name = id->name; |
| 586 | indio_dev->channels = hmc5843_channels; |
| 587 | indio_dev->num_channels = ARRAY_SIZE(hmc5843_channels); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 588 | indio_dev->dev.parent = &client->dev; |
| 589 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 590 | err = iio_device_register(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 591 | if (err) |
| 592 | goto exit_free2; |
| 593 | return 0; |
| 594 | exit_free2: |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 595 | iio_device_free(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 596 | exit: |
| 597 | return err; |
| 598 | } |
| 599 | |
| 600 | static int hmc5843_remove(struct i2c_client *client) |
| 601 | { |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 602 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
Jonathan Cameron | d2fffd6 | 2011-10-14 14:46:58 +0100 | [diff] [blame] | 603 | |
| 604 | iio_device_unregister(indio_dev); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 605 | /* sleep mode to save power */ |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 606 | hmc5843_configure(client, HMC5843_MODE_SLEEP); |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 607 | iio_device_free(indio_dev); |
Jonathan Cameron | 88fa4de | 2011-06-27 13:07:56 +0100 | [diff] [blame] | 608 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
Lars-Peter Clausen | 01788c5 | 2012-02-20 19:37:05 +0100 | [diff] [blame] | 612 | #ifdef CONFIG_PM_SLEEP |
| 613 | static int hmc5843_suspend(struct device *dev) |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 614 | { |
Peter Meerwald | 16b91a4 | 2012-05-16 18:22:05 +0200 | [diff] [blame] | 615 | hmc5843_configure(to_i2c_client(dev), HMC5843_MODE_SLEEP); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 616 | return 0; |
| 617 | } |
| 618 | |
Lars-Peter Clausen | 01788c5 | 2012-02-20 19:37:05 +0100 | [diff] [blame] | 619 | static int hmc5843_resume(struct device *dev) |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 620 | { |
Peter Meerwald | 0462e2b | 2012-05-16 18:22:03 +0200 | [diff] [blame] | 621 | struct i2c_client *client = to_i2c_client(dev); |
| 622 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
| 623 | struct hmc5843_data *data = iio_priv(indio_dev); |
| 624 | |
| 625 | hmc5843_configure(client, data->operating_mode); |
| 626 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 627 | return 0; |
| 628 | } |
| 629 | |
Lars-Peter Clausen | 01788c5 | 2012-02-20 19:37:05 +0100 | [diff] [blame] | 630 | static SIMPLE_DEV_PM_OPS(hmc5843_pm_ops, hmc5843_suspend, hmc5843_resume); |
| 631 | #define HMC5843_PM_OPS (&hmc5843_pm_ops) |
| 632 | #else |
| 633 | #define HMC5843_PM_OPS NULL |
| 634 | #endif |
| 635 | |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 636 | static const struct i2c_device_id hmc5843_id[] = { |
| 637 | { "hmc5843", 0 }, |
| 638 | { } |
| 639 | }; |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 640 | MODULE_DEVICE_TABLE(i2c, hmc5843_id); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 641 | |
| 642 | static struct i2c_driver hmc5843_driver = { |
| 643 | .driver = { |
| 644 | .name = "hmc5843", |
Lars-Peter Clausen | 01788c5 | 2012-02-20 19:37:05 +0100 | [diff] [blame] | 645 | .pm = HMC5843_PM_OPS, |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 646 | }, |
| 647 | .id_table = hmc5843_id, |
| 648 | .probe = hmc5843_probe, |
| 649 | .remove = hmc5843_remove, |
| 650 | .detect = hmc5843_detect, |
| 651 | .address_list = normal_i2c, |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 652 | }; |
Lars-Peter Clausen | 6e5af18 | 2011-11-16 10:13:38 +0100 | [diff] [blame] | 653 | module_i2c_driver(hmc5843_driver); |
Shubhrajyoti D | b4e1782 | 2010-07-17 18:32:52 +0530 | [diff] [blame] | 654 | |
| 655 | MODULE_AUTHOR("Shubhrajyoti Datta <shubhrajyoti@ti.com"); |
| 656 | MODULE_DESCRIPTION("HMC5843 driver"); |
| 657 | MODULE_LICENSE("GPL"); |