mma7660.c (4391affa107d68b6c3e5222264e91bbc21793cf0) | mma7660.c (f4bed1ceb82e465d85d2f73c26b4652b81adb257) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Freescale MMA7660FC 3-Axis Accelerometer 4 * 5 * Copyright (c) 2016, Intel Corporation. 6 * 7 * IIO driver for Freescale MMA7660FC; 7-bit I2C address: 0x4c. 8 */ --- 24 unchanged lines hidden (view full) --- 33 * 34 * scale = (1.5 + 1.5) * 9.81 / (2^6 - 1) = 0.467142857 35 */ 36 37#define MMA7660_SCALE_AVAIL "0.467142857" 38 39static const int mma7660_nscale = 467142857; 40 | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Freescale MMA7660FC 3-Axis Accelerometer 4 * 5 * Copyright (c) 2016, Intel Corporation. 6 * 7 * IIO driver for Freescale MMA7660FC; 7-bit I2C address: 0x4c. 8 */ --- 24 unchanged lines hidden (view full) --- 33 * 34 * scale = (1.5 + 1.5) * 9.81 / (2^6 - 1) = 0.467142857 35 */ 36 37#define MMA7660_SCALE_AVAIL "0.467142857" 38 39static const int mma7660_nscale = 467142857; 40 |
41#define MMA7660_CHANNEL(reg, axis) { \ 42 .type = IIO_ACCEL, \ 43 .address = reg, \ 44 .modified = 1, \ 45 .channel2 = IIO_MOD_##axis, \ 46 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 47 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 48} 49 50static const struct iio_chan_spec mma7660_channels[] = { 51 MMA7660_CHANNEL(MMA7660_REG_XOUT, X), 52 MMA7660_CHANNEL(MMA7660_REG_YOUT, Y), 53 MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z), 54}; 55 | |
56enum mma7660_mode { 57 MMA7660_MODE_STANDBY, 58 MMA7660_MODE_ACTIVE 59}; 60 61struct mma7660_data { 62 struct i2c_client *client; 63 struct mutex lock; 64 enum mma7660_mode mode; | 41enum mma7660_mode { 42 MMA7660_MODE_STANDBY, 43 MMA7660_MODE_ACTIVE 44}; 45 46struct mma7660_data { 47 struct i2c_client *client; 48 struct mutex lock; 49 enum mma7660_mode mode; |
50 struct iio_mount_matrix orientation; |
|
65}; 66 | 51}; 52 |
53static const struct iio_mount_matrix * 54mma7660_get_mount_matrix(const struct iio_dev *indio_dev, 55 const struct iio_chan_spec *chan) 56{ 57 struct mma7660_data *data = iio_priv(indio_dev); 58 59 return &data->orientation; 60} 61 62static const struct iio_chan_spec_ext_info mma7660_ext_info[] = { 63 IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, mma7660_get_mount_matrix), 64 { } 65}; 66 |
|
67static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL); 68 69static struct attribute *mma7660_attributes[] = { 70 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 71 NULL, 72}; 73 74static const struct attribute_group mma7660_attribute_group = { 75 .attrs = mma7660_attributes 76}; 77 | 67static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL); 68 69static struct attribute *mma7660_attributes[] = { 70 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 71 NULL, 72}; 73 74static const struct attribute_group mma7660_attribute_group = { 75 .attrs = mma7660_attributes 76}; 77 |
78#define MMA7660_CHANNEL(reg, axis) { \ 79 .type = IIO_ACCEL, \ 80 .address = reg, \ 81 .modified = 1, \ 82 .channel2 = IIO_MOD_##axis, \ 83 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 84 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 85 .ext_info = mma7660_ext_info, \ 86} 87 88static const struct iio_chan_spec mma7660_channels[] = { 89 MMA7660_CHANNEL(MMA7660_REG_XOUT, X), 90 MMA7660_CHANNEL(MMA7660_REG_YOUT, Y), 91 MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z), 92}; 93 |
|
78static int mma7660_set_mode(struct mma7660_data *data, 79 enum mma7660_mode mode) 80{ 81 int ret; 82 struct i2c_client *client = data->client; 83 84 if (mode == data->mode) 85 return 0; --- 96 unchanged lines hidden (view full) --- 182 } 183 184 data = iio_priv(indio_dev); 185 data->client = client; 186 i2c_set_clientdata(client, indio_dev); 187 mutex_init(&data->lock); 188 data->mode = MMA7660_MODE_STANDBY; 189 | 94static int mma7660_set_mode(struct mma7660_data *data, 95 enum mma7660_mode mode) 96{ 97 int ret; 98 struct i2c_client *client = data->client; 99 100 if (mode == data->mode) 101 return 0; --- 96 unchanged lines hidden (view full) --- 198 } 199 200 data = iio_priv(indio_dev); 201 data->client = client; 202 i2c_set_clientdata(client, indio_dev); 203 mutex_init(&data->lock); 204 data->mode = MMA7660_MODE_STANDBY; 205 |
206 ret = iio_read_mount_matrix(&client->dev, &data->orientation); 207 if (ret) 208 return ret; 209 |
|
190 indio_dev->info = &mma7660_info; 191 indio_dev->name = MMA7660_DRIVER_NAME; 192 indio_dev->modes = INDIO_DIRECT_MODE; 193 indio_dev->channels = mma7660_channels; 194 indio_dev->num_channels = ARRAY_SIZE(mma7660_channels); 195 196 ret = mma7660_set_mode(data, MMA7660_MODE_ACTIVE); 197 if (ret < 0) --- 81 unchanged lines hidden --- | 210 indio_dev->info = &mma7660_info; 211 indio_dev->name = MMA7660_DRIVER_NAME; 212 indio_dev->modes = INDIO_DIRECT_MODE; 213 indio_dev->channels = mma7660_channels; 214 indio_dev->num_channels = ARRAY_SIZE(mma7660_channels); 215 216 ret = mma7660_set_mode(data, MMA7660_MODE_ACTIVE); 217 if (ret < 0) --- 81 unchanged lines hidden --- |