Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * kxsd9.c simple support for the Kionix KXSD9 3D |
| 3 | * accelerometer. |
| 4 | * |
Jonathan Cameron | 0f8c962 | 2012-09-02 21:34:59 +0100 | [diff] [blame] | 5 | * Copyright (c) 2008-2009 Jonathan Cameron <jic23@kernel.org> |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * The i2c interface is very similar, so shouldn't be a problem once |
| 12 | * I have a suitable wire made up. |
| 13 | * |
| 14 | * TODO: Support the motion detector |
| 15 | * Uses register address incrementing so could have a |
| 16 | * heavily optimized ring buffer access function. |
| 17 | */ |
| 18 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 19 | #include <linux/device.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/spi/spi.h> |
| 22 | #include <linux/sysfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 25 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 26 | #include <linux/iio/iio.h> |
| 27 | #include <linux/iio/sysfs.h> |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 28 | |
| 29 | #define KXSD9_REG_X 0x00 |
| 30 | #define KXSD9_REG_Y 0x02 |
| 31 | #define KXSD9_REG_Z 0x04 |
| 32 | #define KXSD9_REG_AUX 0x06 |
| 33 | #define KXSD9_REG_RESET 0x0a |
| 34 | #define KXSD9_REG_CTRL_C 0x0c |
| 35 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 36 | #define KXSD9_FS_MASK 0x03 |
| 37 | |
| 38 | #define KXSD9_REG_CTRL_B 0x0d |
| 39 | #define KXSD9_REG_CTRL_A 0x0e |
| 40 | |
| 41 | #define KXSD9_READ(a) (0x80 | (a)) |
| 42 | #define KXSD9_WRITE(a) (a) |
| 43 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 44 | #define KXSD9_STATE_RX_SIZE 2 |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 45 | #define KXSD9_STATE_TX_SIZE 2 |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 46 | |
| 47 | struct kxsd9_transport; |
| 48 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 49 | /** |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 50 | * struct kxsd9_transport - transport adapter for SPI or I2C |
| 51 | * @trdev: transport device such as SPI or I2C |
| 52 | * @write1(): function to write a byte to the device |
| 53 | * @write2(): function to write two consecutive bytes to the device |
| 54 | * @readval(): function to read a 16bit value from the device |
| 55 | * @rx: cache aligned read buffer |
| 56 | * @tx: cache aligned write buffer |
| 57 | */ |
| 58 | struct kxsd9_transport { |
| 59 | void *trdev; |
| 60 | int (*write1) (struct kxsd9_transport *tr, u8 byte); |
| 61 | int (*write2) (struct kxsd9_transport *tr, u8 b1, u8 b2); |
| 62 | int (*readval) (struct kxsd9_transport *tr, u8 address); |
Jonathan Cameron | ed0c012 | 2011-06-27 13:17:56 +0100 | [diff] [blame] | 63 | u8 rx[KXSD9_STATE_RX_SIZE] ____cacheline_aligned; |
| 64 | u8 tx[KXSD9_STATE_TX_SIZE]; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 67 | /** |
| 68 | * struct kxsd9_state - device related storage |
| 69 | * @transport: transport for the KXSD9 |
| 70 | * @buf_lock: protect the rx and tx buffers. |
| 71 | * @us: spi device |
| 72 | **/ |
| 73 | struct kxsd9_state { |
| 74 | struct kxsd9_transport *transport; |
| 75 | struct mutex buf_lock; |
| 76 | }; |
| 77 | |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 78 | #define KXSD9_SCALE_2G "0.011978" |
| 79 | #define KXSD9_SCALE_4G "0.023927" |
| 80 | #define KXSD9_SCALE_6G "0.035934" |
| 81 | #define KXSD9_SCALE_8G "0.047853" |
| 82 | |
| 83 | /* reverse order */ |
| 84 | static const int kxsd9_micro_scales[4] = { 47853, 35934, 23927, 11978 }; |
| 85 | |
| 86 | static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 87 | { |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 88 | int ret, i; |
Jonathan Cameron | ed0c012 | 2011-06-27 13:17:56 +0100 | [diff] [blame] | 89 | struct kxsd9_state *st = iio_priv(indio_dev); |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 90 | bool foundit = false; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 91 | |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 92 | for (i = 0; i < 4; i++) |
| 93 | if (micro == kxsd9_micro_scales[i]) { |
| 94 | foundit = true; |
| 95 | break; |
| 96 | } |
| 97 | if (!foundit) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 98 | return -EINVAL; |
Jonathan Cameron | f3fb001 | 2010-05-04 14:42:58 +0100 | [diff] [blame] | 99 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 100 | mutex_lock(&st->buf_lock); |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 101 | ret = st->transport->write1(st->transport, KXSD9_READ(KXSD9_REG_CTRL_C)); |
| 102 | if (ret) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 103 | goto error_ret; |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 104 | ret = st->transport->write2(st->transport, |
| 105 | KXSD9_WRITE(KXSD9_REG_CTRL_C), |
| 106 | (ret & ~KXSD9_FS_MASK) | i); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 107 | error_ret: |
| 108 | mutex_unlock(&st->buf_lock); |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 109 | return ret; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 110 | } |
Jonathan Cameron | f3fb001 | 2010-05-04 14:42:58 +0100 | [diff] [blame] | 111 | |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 112 | static int kxsd9_read(struct iio_dev *indio_dev, u8 address) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 113 | { |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 114 | int ret; |
Jonathan Cameron | ed0c012 | 2011-06-27 13:17:56 +0100 | [diff] [blame] | 115 | struct kxsd9_state *st = iio_priv(indio_dev); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 116 | |
| 117 | mutex_lock(&st->buf_lock); |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 118 | ret = st->transport->readval(st->transport, KXSD9_READ(address)); |
Frank Zago | 0ee005c | 2013-11-13 22:53:00 +0000 | [diff] [blame] | 119 | mutex_unlock(&st->buf_lock); |
| 120 | return ret; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Jonathan Cameron | f3fb001 | 2010-05-04 14:42:58 +0100 | [diff] [blame] | 123 | static IIO_CONST_ATTR(accel_scale_available, |
| 124 | KXSD9_SCALE_2G " " |
| 125 | KXSD9_SCALE_4G " " |
| 126 | KXSD9_SCALE_6G " " |
| 127 | KXSD9_SCALE_8G); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 128 | |
| 129 | static struct attribute *kxsd9_attributes[] = { |
Jonathan Cameron | f3fb001 | 2010-05-04 14:42:58 +0100 | [diff] [blame] | 130 | &iio_const_attr_accel_scale_available.dev_attr.attr, |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 131 | NULL, |
| 132 | }; |
| 133 | |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 134 | static int kxsd9_write_raw(struct iio_dev *indio_dev, |
| 135 | struct iio_chan_spec const *chan, |
| 136 | int val, |
| 137 | int val2, |
| 138 | long mask) |
| 139 | { |
| 140 | int ret = -EINVAL; |
| 141 | |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 142 | if (mask == IIO_CHAN_INFO_SCALE) { |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 143 | /* Check no integer component */ |
| 144 | if (val) |
| 145 | return -EINVAL; |
| 146 | ret = kxsd9_write_scale(indio_dev, val2); |
| 147 | } |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | static int kxsd9_read_raw(struct iio_dev *indio_dev, |
| 153 | struct iio_chan_spec const *chan, |
| 154 | int *val, int *val2, long mask) |
| 155 | { |
| 156 | int ret = -EINVAL; |
| 157 | struct kxsd9_state *st = iio_priv(indio_dev); |
| 158 | |
| 159 | switch (mask) { |
Jonathan Cameron | 31313fc | 2012-04-15 17:41:17 +0100 | [diff] [blame] | 160 | case IIO_CHAN_INFO_RAW: |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 161 | ret = kxsd9_read(indio_dev, chan->address); |
| 162 | if (ret < 0) |
| 163 | goto error_ret; |
| 164 | *val = ret; |
Linus Walleij | 7ac61a0 | 2016-08-16 15:33:28 +0200 | [diff] [blame] | 165 | ret = IIO_VAL_INT; |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 166 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 167 | case IIO_CHAN_INFO_SCALE: |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 168 | ret = st->transport->write1(st->transport, KXSD9_READ(KXSD9_REG_CTRL_C)); |
| 169 | if (ret) |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 170 | goto error_ret; |
Linus Walleij | 307fe9d | 2016-09-01 11:44:35 +0200 | [diff] [blame] | 171 | *val = 0; |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 172 | *val2 = kxsd9_micro_scales[ret & KXSD9_FS_MASK]; |
| 173 | ret = IIO_VAL_INT_PLUS_MICRO; |
| 174 | break; |
Peter Senna Tschudin | 73327b4 | 2012-09-28 10:57:00 +0100 | [diff] [blame] | 175 | } |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 176 | |
| 177 | error_ret: |
| 178 | return ret; |
| 179 | }; |
| 180 | #define KXSD9_ACCEL_CHAN(axis) \ |
| 181 | { \ |
| 182 | .type = IIO_ACCEL, \ |
| 183 | .modified = 1, \ |
| 184 | .channel2 = IIO_MOD_##axis, \ |
Jonathan Cameron | 2f6bb53 | 2013-02-27 19:03:36 +0000 | [diff] [blame] | 185 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 186 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 187 | .address = KXSD9_REG_##axis, \ |
| 188 | } |
| 189 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 190 | static const struct iio_chan_spec kxsd9_channels[] = { |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 191 | KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z), |
| 192 | { |
Jonathan Cameron | 6835cb6 | 2011-09-27 09:56:41 +0100 | [diff] [blame] | 193 | .type = IIO_VOLTAGE, |
Jonathan Cameron | 2f6bb53 | 2013-02-27 19:03:36 +0000 | [diff] [blame] | 194 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 195 | .indexed = 1, |
| 196 | .address = KXSD9_REG_AUX, |
| 197 | } |
| 198 | }; |
| 199 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 200 | static const struct attribute_group kxsd9_attribute_group = { |
| 201 | .attrs = kxsd9_attributes, |
| 202 | }; |
| 203 | |
Bill Pemberton | 4ae1c61 | 2012-11-19 13:21:57 -0500 | [diff] [blame] | 204 | static int kxsd9_power_up(struct kxsd9_state *st) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 205 | { |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 206 | int ret; |
| 207 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 208 | ret = st->transport->write2(st->transport, 0x0d, 0x40); |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 209 | if (ret) |
| 210 | return ret; |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 211 | return st->transport->write2(st->transport, 0x0c, 0x9b); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 212 | }; |
| 213 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 214 | static const struct iio_info kxsd9_info = { |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 215 | .read_raw = &kxsd9_read_raw, |
| 216 | .write_raw = &kxsd9_write_raw, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 217 | .attrs = &kxsd9_attribute_group, |
| 218 | .driver_module = THIS_MODULE, |
| 219 | }; |
| 220 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 221 | static int kxsd9_common_probe(struct device *parent, |
| 222 | struct kxsd9_transport *transport, |
Linus Walleij | 154021a | 2016-09-01 11:44:37 +0200 | [diff] [blame^] | 223 | const char *name) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 224 | { |
Jonathan Cameron | ed0c012 | 2011-06-27 13:17:56 +0100 | [diff] [blame] | 225 | struct iio_dev *indio_dev; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 226 | struct kxsd9_state *st; |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 227 | int ret; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 228 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 229 | indio_dev = devm_iio_device_alloc(parent, sizeof(*st)); |
Sachin Kamat | 4ee3093 | 2013-07-23 07:47:00 +0100 | [diff] [blame] | 230 | if (!indio_dev) |
| 231 | return -ENOMEM; |
| 232 | |
Jonathan Cameron | ed0c012 | 2011-06-27 13:17:56 +0100 | [diff] [blame] | 233 | st = iio_priv(indio_dev); |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 234 | st->transport = transport; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 235 | |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 236 | mutex_init(&st->buf_lock); |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 237 | indio_dev->channels = kxsd9_channels; |
| 238 | indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels); |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 239 | indio_dev->name = name; |
| 240 | indio_dev->dev.parent = parent; |
Jonathan Cameron | ed0c012 | 2011-06-27 13:17:56 +0100 | [diff] [blame] | 241 | indio_dev->info = &kxsd9_info; |
| 242 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 243 | |
anish kumar | 3fd47d4 | 2011-06-27 13:08:00 +0100 | [diff] [blame] | 244 | kxsd9_power_up(st); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 245 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 246 | ret = iio_device_register(indio_dev); |
| 247 | if (ret) |
| 248 | return ret; |
| 249 | |
Linus Walleij | 154021a | 2016-09-01 11:44:37 +0200 | [diff] [blame^] | 250 | dev_set_drvdata(parent, indio_dev); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int kxsd9_common_remove(struct device *parent) |
| 256 | { |
| 257 | struct iio_dev *indio_dev = dev_get_drvdata(parent); |
| 258 | |
| 259 | iio_device_unregister(indio_dev); |
| 260 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 261 | return 0; |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 264 | static int kxsd9_spi_write1(struct kxsd9_transport *tr, u8 byte) |
| 265 | { |
| 266 | struct spi_device *spi = tr->trdev; |
| 267 | |
| 268 | return spi_w8r8(spi, byte); |
| 269 | } |
| 270 | |
| 271 | static int kxsd9_spi_write2(struct kxsd9_transport *tr, u8 b1, u8 b2) |
| 272 | { |
| 273 | struct spi_device *spi = tr->trdev; |
| 274 | |
| 275 | tr->tx[0] = b1; |
| 276 | tr->tx[1] = b2; |
| 277 | return spi_write(spi, tr->tx, 2); |
| 278 | } |
| 279 | |
| 280 | static int kxsd9_spi_readval(struct kxsd9_transport *tr, u8 address) |
| 281 | { |
| 282 | struct spi_device *spi = tr->trdev; |
| 283 | struct spi_transfer xfers[] = { |
| 284 | { |
| 285 | .bits_per_word = 8, |
| 286 | .len = 1, |
| 287 | .delay_usecs = 200, |
| 288 | .tx_buf = tr->tx, |
| 289 | }, { |
| 290 | .bits_per_word = 8, |
| 291 | .len = 2, |
| 292 | .rx_buf = tr->rx, |
| 293 | }, |
| 294 | }; |
| 295 | int ret; |
| 296 | |
| 297 | tr->tx[0] = address; |
| 298 | ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers)); |
| 299 | if (!ret) |
| 300 | ret = (((u16)(tr->rx[0])) << 8) | (tr->rx[1] & 0xF0); |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | static int kxsd9_spi_probe(struct spi_device *spi) |
| 305 | { |
| 306 | struct kxsd9_transport *transport; |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 307 | int ret; |
| 308 | |
| 309 | transport = devm_kzalloc(&spi->dev, sizeof(*transport), GFP_KERNEL); |
| 310 | if (!transport) |
| 311 | return -ENOMEM; |
| 312 | |
| 313 | transport->trdev = spi; |
| 314 | transport->write1 = kxsd9_spi_write1; |
| 315 | transport->write2 = kxsd9_spi_write2; |
| 316 | transport->readval = kxsd9_spi_readval; |
| 317 | spi->mode = SPI_MODE_0; |
| 318 | spi_setup(spi); |
| 319 | |
| 320 | ret = kxsd9_common_probe(&spi->dev, |
| 321 | transport, |
Linus Walleij | 154021a | 2016-09-01 11:44:37 +0200 | [diff] [blame^] | 322 | spi_get_device_id(spi)->name); |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 323 | if (ret) |
| 324 | return ret; |
| 325 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int kxsd9_spi_remove(struct spi_device *spi) |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 330 | { |
Linus Walleij | 154021a | 2016-09-01 11:44:37 +0200 | [diff] [blame^] | 331 | return kxsd9_common_remove(&spi->dev); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 334 | static const struct spi_device_id kxsd9_spi_id[] = { |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 335 | {"kxsd9", 0}, |
| 336 | { }, |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 337 | }; |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 338 | MODULE_DEVICE_TABLE(spi, kxsd9_spi_id); |
Jonathan Cameron | d34dbee | 2011-08-12 17:47:52 +0100 | [diff] [blame] | 339 | |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 340 | static struct spi_driver kxsd9_spi_driver = { |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 341 | .driver = { |
| 342 | .name = "kxsd9", |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 343 | }, |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 344 | .probe = kxsd9_spi_probe, |
| 345 | .remove = kxsd9_spi_remove, |
| 346 | .id_table = kxsd9_spi_id, |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 347 | }; |
Linus Walleij | 9f90797 | 2016-09-01 11:44:36 +0200 | [diff] [blame] | 348 | module_spi_driver(kxsd9_spi_driver); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 349 | |
Jonathan Cameron | 0f8c962 | 2012-09-02 21:34:59 +0100 | [diff] [blame] | 350 | MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); |
Jonathan Cameron | e435bc1 | 2009-08-18 18:06:23 +0100 | [diff] [blame] | 351 | MODULE_DESCRIPTION("Kionix KXSD9 SPI driver"); |
| 352 | MODULE_LICENSE("GPL v2"); |