xref: /linux/drivers/iio/accel/stk8312.c (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 /**
2  * Sensortek STK8312 3-Axis Accelerometer
3  *
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This file is subject to the terms and conditions of version 2 of
7  * the GNU General Public License. See the file COPYING in the main
8  * directory of this archive for more details.
9  *
10  * IIO driver for STK8312; 7-bit I2C address: 0x3D.
11  */
12 
13 #include <linux/acpi.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/i2c.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/delay.h>
20 #include <linux/iio/buffer.h>
21 #include <linux/iio/iio.h>
22 #include <linux/iio/sysfs.h>
23 #include <linux/iio/trigger.h>
24 #include <linux/iio/triggered_buffer.h>
25 #include <linux/iio/trigger_consumer.h>
26 
27 #define STK8312_REG_XOUT		0x00
28 #define STK8312_REG_YOUT		0x01
29 #define STK8312_REG_ZOUT		0x02
30 #define STK8312_REG_INTSU		0x06
31 #define STK8312_REG_MODE		0x07
32 #define STK8312_REG_SR			0x08
33 #define STK8312_REG_STH			0x13
34 #define STK8312_REG_RESET		0x20
35 #define STK8312_REG_AFECTRL		0x24
36 #define STK8312_REG_OTPADDR		0x3D
37 #define STK8312_REG_OTPDATA		0x3E
38 #define STK8312_REG_OTPCTRL		0x3F
39 
40 #define STK8312_MODE_ACTIVE		BIT(0)
41 #define STK8312_MODE_STANDBY		0x00
42 #define STK8312_MODE_INT_AH_PP		0xC0	/* active-high, push-pull */
43 #define STK8312_DREADY_BIT		BIT(4)
44 #define STK8312_RNG_6G			1
45 #define STK8312_RNG_SHIFT		6
46 #define STK8312_RNG_MASK		GENMASK(7, 6)
47 #define STK8312_SR_MASK			GENMASK(2, 0)
48 #define STK8312_SR_400HZ_IDX		0
49 #define STK8312_ALL_CHANNEL_MASK	GENMASK(2, 0)
50 #define STK8312_ALL_CHANNEL_SIZE	3
51 
52 #define STK8312_DRIVER_NAME		"stk8312"
53 #define STK8312_GPIO			"stk8312_gpio"
54 #define STK8312_IRQ_NAME		"stk8312_event"
55 
56 /*
57  * The accelerometer has two measurement ranges:
58  *
59  * -6g - +6g (8-bit, signed)
60  * -16g - +16g (8-bit, signed)
61  *
62  * scale1 = (6 + 6) * 9.81 / (2^8 - 1)     = 0.4616
63  * scale2 = (16 + 16) * 9.81 / (2^8 - 1)   = 1.2311
64  */
65 #define STK8312_SCALE_AVAIL		"0.4616 1.2311"
66 
67 static const int stk8312_scale_table[][2] = {
68 	{0, 461600}, {1, 231100}
69 };
70 
71 static const struct {
72 	int val;
73 	int val2;
74 } stk8312_samp_freq_table[] = {
75 	{400, 0}, {200, 0}, {100, 0}, {50, 0}, {25, 0},
76 	{12, 500000}, {6, 250000}, {3, 125000}
77 };
78 
79 #define STK8312_ACCEL_CHANNEL(index, reg, axis) {			\
80 	.type = IIO_ACCEL,						\
81 	.address = reg,							\
82 	.modified = 1,							\
83 	.channel2 = IIO_MOD_##axis,					\
84 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
85 	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |		\
86 				    BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
87 	.scan_index = index,						\
88 	.scan_type = {							\
89 		.sign = 's',						\
90 		.realbits = 8,						\
91 		.storagebits = 8,					\
92 		.endianness = IIO_CPU,					\
93 	},								\
94 }
95 
96 static const struct iio_chan_spec stk8312_channels[] = {
97 	STK8312_ACCEL_CHANNEL(0, STK8312_REG_XOUT, X),
98 	STK8312_ACCEL_CHANNEL(1, STK8312_REG_YOUT, Y),
99 	STK8312_ACCEL_CHANNEL(2, STK8312_REG_ZOUT, Z),
100 	IIO_CHAN_SOFT_TIMESTAMP(3),
101 };
102 
103 struct stk8312_data {
104 	struct i2c_client *client;
105 	struct mutex lock;
106 	u8 range;
107 	u8 sample_rate_idx;
108 	u8 mode;
109 	struct iio_trigger *dready_trig;
110 	bool dready_trigger_on;
111 	s8 buffer[16]; /* 3x8-bit channels + 5x8 padding + 64-bit timestamp */
112 };
113 
114 static IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL);
115 
116 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("3.125 6.25 12.5 25 50 100 200 400");
117 
118 static struct attribute *stk8312_attributes[] = {
119 	&iio_const_attr_in_accel_scale_available.dev_attr.attr,
120 	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
121 	NULL,
122 };
123 
124 static const struct attribute_group stk8312_attribute_group = {
125 	.attrs = stk8312_attributes
126 };
127 
128 static int stk8312_otp_init(struct stk8312_data *data)
129 {
130 	int ret;
131 	int count = 10;
132 	struct i2c_client *client = data->client;
133 
134 	ret = i2c_smbus_write_byte_data(client, STK8312_REG_OTPADDR, 0x70);
135 	if (ret < 0)
136 		goto exit_err;
137 	ret = i2c_smbus_write_byte_data(client, STK8312_REG_OTPCTRL, 0x02);
138 	if (ret < 0)
139 		goto exit_err;
140 
141 	do {
142 		usleep_range(1000, 5000);
143 		ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPCTRL);
144 		if (ret < 0)
145 			goto exit_err;
146 		count--;
147 	} while (!(ret & BIT(7)) && count > 0);
148 
149 	if (count == 0) {
150 		ret = -ETIMEDOUT;
151 		goto exit_err;
152 	}
153 
154 	ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPDATA);
155 	if (ret == 0)
156 		ret = -EINVAL;
157 	if (ret < 0)
158 		goto exit_err;
159 
160 	ret = i2c_smbus_write_byte_data(data->client, STK8312_REG_AFECTRL, ret);
161 	if (ret < 0)
162 		goto exit_err;
163 	msleep(150);
164 
165 	return 0;
166 
167 exit_err:
168 	dev_err(&client->dev, "failed to initialize sensor\n");
169 	return ret;
170 }
171 
172 static int stk8312_set_mode(struct stk8312_data *data, u8 mode)
173 {
174 	int ret;
175 	struct i2c_client *client = data->client;
176 
177 	if (mode == data->mode)
178 		return 0;
179 
180 	ret = i2c_smbus_write_byte_data(client, STK8312_REG_MODE, mode);
181 	if (ret < 0) {
182 		dev_err(&client->dev, "failed to change sensor mode\n");
183 		return ret;
184 	}
185 
186 	data->mode = mode;
187 	if (mode & STK8312_MODE_ACTIVE) {
188 		/* Need to run OTP sequence before entering active mode */
189 		usleep_range(1000, 5000);
190 		ret = stk8312_otp_init(data);
191 	}
192 
193 	return ret;
194 }
195 
196 static int stk8312_set_interrupts(struct stk8312_data *data, u8 int_mask)
197 {
198 	int ret;
199 	u8 mode;
200 	struct i2c_client *client = data->client;
201 
202 	mode = data->mode;
203 	/* We need to go in standby mode to modify registers */
204 	ret = stk8312_set_mode(data, STK8312_MODE_STANDBY);
205 	if (ret < 0)
206 		return ret;
207 
208 	ret = i2c_smbus_write_byte_data(client, STK8312_REG_INTSU, int_mask);
209 	if (ret < 0) {
210 		dev_err(&client->dev, "failed to set interrupts\n");
211 		stk8312_set_mode(data, mode);
212 		return ret;
213 	}
214 
215 	return stk8312_set_mode(data, mode);
216 }
217 
218 static int stk8312_data_rdy_trigger_set_state(struct iio_trigger *trig,
219 					      bool state)
220 {
221 	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
222 	struct stk8312_data *data = iio_priv(indio_dev);
223 	int ret;
224 
225 	if (state)
226 		ret = stk8312_set_interrupts(data, STK8312_DREADY_BIT);
227 	else
228 		ret = stk8312_set_interrupts(data, 0x00);
229 
230 	if (ret < 0) {
231 		dev_err(&data->client->dev, "failed to set trigger state\n");
232 		return ret;
233 	}
234 
235 	data->dready_trigger_on = state;
236 
237 	return 0;
238 }
239 
240 static const struct iio_trigger_ops stk8312_trigger_ops = {
241 	.set_trigger_state = stk8312_data_rdy_trigger_set_state,
242 	.owner = THIS_MODULE,
243 };
244 
245 static int stk8312_set_sample_rate(struct stk8312_data *data, u8 rate)
246 {
247 	int ret;
248 	u8 masked_reg;
249 	u8 mode;
250 	struct i2c_client *client = data->client;
251 
252 	if (rate == data->sample_rate_idx)
253 		return 0;
254 
255 	mode = data->mode;
256 	/* We need to go in standby mode to modify registers */
257 	ret = stk8312_set_mode(data, STK8312_MODE_STANDBY);
258 	if (ret < 0)
259 		return ret;
260 
261 	ret = i2c_smbus_read_byte_data(client, STK8312_REG_SR);
262 	if (ret < 0)
263 		goto err_activate;
264 
265 	masked_reg = (ret & (~STK8312_SR_MASK)) | rate;
266 
267 	ret = i2c_smbus_write_byte_data(client, STK8312_REG_SR, masked_reg);
268 	if (ret < 0)
269 		goto err_activate;
270 
271 	data->sample_rate_idx = rate;
272 
273 	return stk8312_set_mode(data, mode);
274 
275 err_activate:
276 	dev_err(&client->dev, "failed to set sampling rate\n");
277 	stk8312_set_mode(data, mode);
278 
279 	return ret;
280 }
281 
282 static int stk8312_set_range(struct stk8312_data *data, u8 range)
283 {
284 	int ret;
285 	u8 masked_reg;
286 	u8 mode;
287 	struct i2c_client *client = data->client;
288 
289 	if (range != 1 && range != 2)
290 		return -EINVAL;
291 	else if (range == data->range)
292 		return 0;
293 
294 	mode = data->mode;
295 	/* We need to go in standby mode to modify registers */
296 	ret = stk8312_set_mode(data, STK8312_MODE_STANDBY);
297 	if (ret < 0)
298 		return ret;
299 
300 	ret = i2c_smbus_read_byte_data(client, STK8312_REG_STH);
301 	if (ret < 0)
302 		goto err_activate;
303 
304 	masked_reg = ret & (~STK8312_RNG_MASK);
305 	masked_reg |= range << STK8312_RNG_SHIFT;
306 
307 	ret = i2c_smbus_write_byte_data(client, STK8312_REG_STH, masked_reg);
308 	if (ret < 0)
309 		goto err_activate;
310 
311 	data->range = range;
312 
313 	return stk8312_set_mode(data, mode);
314 
315 err_activate:
316 	dev_err(&client->dev, "failed to change sensor range\n");
317 	stk8312_set_mode(data, mode);
318 
319 	return ret;
320 }
321 
322 static int stk8312_read_accel(struct stk8312_data *data, u8 address)
323 {
324 	int ret;
325 	struct i2c_client *client = data->client;
326 
327 	if (address > 2)
328 		return -EINVAL;
329 
330 	ret = i2c_smbus_read_byte_data(client, address);
331 	if (ret < 0)
332 		dev_err(&client->dev, "register read failed\n");
333 
334 	return ret;
335 }
336 
337 static int stk8312_read_raw(struct iio_dev *indio_dev,
338 			    struct iio_chan_spec const *chan,
339 			    int *val, int *val2, long mask)
340 {
341 	struct stk8312_data *data = iio_priv(indio_dev);
342 	int ret;
343 
344 	switch (mask) {
345 	case IIO_CHAN_INFO_RAW:
346 		if (iio_buffer_enabled(indio_dev))
347 			return -EBUSY;
348 		mutex_lock(&data->lock);
349 		ret = stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE);
350 		if (ret < 0) {
351 			mutex_unlock(&data->lock);
352 			return ret;
353 		}
354 		ret = stk8312_read_accel(data, chan->address);
355 		if (ret < 0) {
356 			stk8312_set_mode(data,
357 					 data->mode & (~STK8312_MODE_ACTIVE));
358 			mutex_unlock(&data->lock);
359 			return ret;
360 		}
361 		*val = sign_extend32(ret, 7);
362 		ret = stk8312_set_mode(data,
363 				       data->mode & (~STK8312_MODE_ACTIVE));
364 		mutex_unlock(&data->lock);
365 		if (ret < 0)
366 			return ret;
367 		return IIO_VAL_INT;
368 	case IIO_CHAN_INFO_SCALE:
369 		*val = stk8312_scale_table[data->range - 1][0];
370 		*val2 = stk8312_scale_table[data->range - 1][1];
371 		return IIO_VAL_INT_PLUS_MICRO;
372 	case IIO_CHAN_INFO_SAMP_FREQ:
373 		*val = stk8312_samp_freq_table[data->sample_rate_idx].val;
374 		*val2 = stk8312_samp_freq_table[data->sample_rate_idx].val2;
375 		return IIO_VAL_INT_PLUS_MICRO;
376 	}
377 
378 	return -EINVAL;
379 }
380 
381 static int stk8312_write_raw(struct iio_dev *indio_dev,
382 			     struct iio_chan_spec const *chan,
383 			     int val, int val2, long mask)
384 {
385 	int i;
386 	int index = -1;
387 	int ret;
388 	struct stk8312_data *data = iio_priv(indio_dev);
389 
390 	switch (mask) {
391 	case IIO_CHAN_INFO_SCALE:
392 		for (i = 0; i < ARRAY_SIZE(stk8312_scale_table); i++)
393 			if (val == stk8312_scale_table[i][0] &&
394 			    val2 == stk8312_scale_table[i][1]) {
395 				index = i + 1;
396 				break;
397 			}
398 		if (index < 0)
399 			return -EINVAL;
400 
401 		mutex_lock(&data->lock);
402 		ret = stk8312_set_range(data, index);
403 		mutex_unlock(&data->lock);
404 
405 		return ret;
406 	case IIO_CHAN_INFO_SAMP_FREQ:
407 		for (i = 0; i < ARRAY_SIZE(stk8312_samp_freq_table); i++)
408 			if (val == stk8312_samp_freq_table[i].val &&
409 			    val2 == stk8312_samp_freq_table[i].val2) {
410 				index = i;
411 				break;
412 			}
413 		if (index < 0)
414 			return -EINVAL;
415 		mutex_lock(&data->lock);
416 		ret = stk8312_set_sample_rate(data, index);
417 		mutex_unlock(&data->lock);
418 
419 		return ret;
420 	}
421 
422 	return -EINVAL;
423 }
424 
425 static const struct iio_info stk8312_info = {
426 	.driver_module		= THIS_MODULE,
427 	.read_raw		= stk8312_read_raw,
428 	.write_raw		= stk8312_write_raw,
429 	.attrs			= &stk8312_attribute_group,
430 };
431 
432 static irqreturn_t stk8312_trigger_handler(int irq, void *p)
433 {
434 	struct iio_poll_func *pf = p;
435 	struct iio_dev *indio_dev = pf->indio_dev;
436 	struct stk8312_data *data = iio_priv(indio_dev);
437 	int bit, ret, i = 0;
438 
439 	mutex_lock(&data->lock);
440 	/*
441 	 * Do a bulk read if all channels are requested,
442 	 * from 0x00 (XOUT) to 0x02 (ZOUT)
443 	 */
444 	if (*(indio_dev->active_scan_mask) == STK8312_ALL_CHANNEL_MASK) {
445 		ret = i2c_smbus_read_i2c_block_data(data->client,
446 						    STK8312_REG_XOUT,
447 						    STK8312_ALL_CHANNEL_SIZE,
448 						    data->buffer);
449 		if (ret < STK8312_ALL_CHANNEL_SIZE) {
450 			dev_err(&data->client->dev, "register read failed\n");
451 			mutex_unlock(&data->lock);
452 			goto err;
453 		}
454 	} else {
455 		for_each_set_bit(bit, indio_dev->active_scan_mask,
456 				 indio_dev->masklength) {
457 			ret = stk8312_read_accel(data, bit);
458 			if (ret < 0) {
459 				mutex_unlock(&data->lock);
460 				goto err;
461 			}
462 			data->buffer[i++] = ret;
463 		}
464 	}
465 	mutex_unlock(&data->lock);
466 
467 	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
468 					   pf->timestamp);
469 err:
470 	iio_trigger_notify_done(indio_dev->trig);
471 
472 	return IRQ_HANDLED;
473 }
474 
475 static irqreturn_t stk8312_data_rdy_trig_poll(int irq, void *private)
476 {
477 	struct iio_dev *indio_dev = private;
478 	struct stk8312_data *data = iio_priv(indio_dev);
479 
480 	if (data->dready_trigger_on)
481 		iio_trigger_poll(data->dready_trig);
482 
483 	return IRQ_HANDLED;
484 }
485 
486 static int stk8312_buffer_preenable(struct iio_dev *indio_dev)
487 {
488 	struct stk8312_data *data = iio_priv(indio_dev);
489 
490 	return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE);
491 }
492 
493 static int stk8312_buffer_postdisable(struct iio_dev *indio_dev)
494 {
495 	struct stk8312_data *data = iio_priv(indio_dev);
496 
497 	return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE));
498 }
499 
500 static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = {
501 	.preenable   = stk8312_buffer_preenable,
502 	.postenable  = iio_triggered_buffer_postenable,
503 	.predisable  = iio_triggered_buffer_predisable,
504 	.postdisable = stk8312_buffer_postdisable,
505 };
506 
507 static int stk8312_gpio_probe(struct i2c_client *client)
508 {
509 	struct device *dev;
510 	struct gpio_desc *gpio;
511 	int ret;
512 
513 	if (!client)
514 		return -EINVAL;
515 
516 	dev = &client->dev;
517 
518 	/* data ready gpio interrupt pin */
519 	gpio = devm_gpiod_get_index(dev, STK8312_GPIO, 0, GPIOD_IN);
520 	if (IS_ERR(gpio)) {
521 		dev_err(dev, "acpi gpio get index failed\n");
522 		return PTR_ERR(gpio);
523 	}
524 
525 	ret = gpiod_to_irq(gpio);
526 	dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
527 
528 	return ret;
529 }
530 
531 static int stk8312_probe(struct i2c_client *client,
532 			 const struct i2c_device_id *id)
533 {
534 	int ret;
535 	struct iio_dev *indio_dev;
536 	struct stk8312_data *data;
537 
538 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
539 	if (!indio_dev) {
540 		dev_err(&client->dev, "iio allocation failed!\n");
541 		return -ENOMEM;
542 	}
543 
544 	data = iio_priv(indio_dev);
545 	data->client = client;
546 	i2c_set_clientdata(client, indio_dev);
547 	mutex_init(&data->lock);
548 
549 	indio_dev->dev.parent = &client->dev;
550 	indio_dev->info = &stk8312_info;
551 	indio_dev->name = STK8312_DRIVER_NAME;
552 	indio_dev->modes = INDIO_DIRECT_MODE;
553 	indio_dev->channels = stk8312_channels;
554 	indio_dev->num_channels = ARRAY_SIZE(stk8312_channels);
555 
556 	/* A software reset is recommended at power-on */
557 	ret = i2c_smbus_write_byte_data(data->client, STK8312_REG_RESET, 0x00);
558 	if (ret < 0) {
559 		dev_err(&client->dev, "failed to reset sensor\n");
560 		return ret;
561 	}
562 	data->sample_rate_idx = STK8312_SR_400HZ_IDX;
563 	ret = stk8312_set_range(data, STK8312_RNG_6G);
564 	if (ret < 0)
565 		return ret;
566 
567 	ret = stk8312_set_mode(data,
568 			       STK8312_MODE_INT_AH_PP | STK8312_MODE_ACTIVE);
569 	if (ret < 0)
570 		return ret;
571 
572 	if (client->irq < 0)
573 		client->irq = stk8312_gpio_probe(client);
574 
575 	if (client->irq >= 0) {
576 		ret = devm_request_threaded_irq(&client->dev, client->irq,
577 						stk8312_data_rdy_trig_poll,
578 						NULL,
579 						IRQF_TRIGGER_RISING |
580 						IRQF_ONESHOT,
581 						STK8312_IRQ_NAME,
582 						indio_dev);
583 		if (ret < 0) {
584 			dev_err(&client->dev, "request irq %d failed\n",
585 				client->irq);
586 			goto err_power_off;
587 		}
588 
589 		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
590 							   "%s-dev%d",
591 							   indio_dev->name,
592 							   indio_dev->id);
593 		if (!data->dready_trig) {
594 			ret = -ENOMEM;
595 			goto err_power_off;
596 		}
597 
598 		data->dready_trig->dev.parent = &client->dev;
599 		data->dready_trig->ops = &stk8312_trigger_ops;
600 		iio_trigger_set_drvdata(data->dready_trig, indio_dev);
601 		ret = iio_trigger_register(data->dready_trig);
602 		if (ret) {
603 			dev_err(&client->dev, "iio trigger register failed\n");
604 			goto err_power_off;
605 		}
606 	}
607 
608 	ret = iio_triggered_buffer_setup(indio_dev,
609 					 iio_pollfunc_store_time,
610 					 stk8312_trigger_handler,
611 					 &stk8312_buffer_setup_ops);
612 	if (ret < 0) {
613 		dev_err(&client->dev, "iio triggered buffer setup failed\n");
614 		goto err_trigger_unregister;
615 	}
616 
617 	ret = iio_device_register(indio_dev);
618 	if (ret < 0) {
619 		dev_err(&client->dev, "device_register failed\n");
620 		goto err_buffer_cleanup;
621 	}
622 
623 	return 0;
624 
625 err_buffer_cleanup:
626 	iio_triggered_buffer_cleanup(indio_dev);
627 err_trigger_unregister:
628 	if (data->dready_trig)
629 		iio_trigger_unregister(data->dready_trig);
630 err_power_off:
631 	stk8312_set_mode(data, STK8312_MODE_STANDBY);
632 	return ret;
633 }
634 
635 static int stk8312_remove(struct i2c_client *client)
636 {
637 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
638 	struct stk8312_data *data = iio_priv(indio_dev);
639 
640 	iio_device_unregister(indio_dev);
641 	iio_triggered_buffer_cleanup(indio_dev);
642 
643 	if (data->dready_trig)
644 		iio_trigger_unregister(data->dready_trig);
645 
646 	return stk8312_set_mode(data, STK8312_MODE_STANDBY);
647 }
648 
649 #ifdef CONFIG_PM_SLEEP
650 static int stk8312_suspend(struct device *dev)
651 {
652 	struct stk8312_data *data;
653 
654 	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
655 
656 	return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE));
657 }
658 
659 static int stk8312_resume(struct device *dev)
660 {
661 	struct stk8312_data *data;
662 
663 	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
664 
665 	return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE);
666 }
667 
668 static SIMPLE_DEV_PM_OPS(stk8312_pm_ops, stk8312_suspend, stk8312_resume);
669 
670 #define STK8312_PM_OPS (&stk8312_pm_ops)
671 #else
672 #define STK8312_PM_OPS NULL
673 #endif
674 
675 static const struct i2c_device_id stk8312_i2c_id[] = {
676 	{"STK8312", 0},
677 	{}
678 };
679 MODULE_DEVICE_TABLE(i2c, stk8312_i2c_id);
680 
681 static const struct acpi_device_id stk8312_acpi_id[] = {
682 	{"STK8312", 0},
683 	{}
684 };
685 
686 MODULE_DEVICE_TABLE(acpi, stk8312_acpi_id);
687 
688 static struct i2c_driver stk8312_driver = {
689 	.driver = {
690 		.name = STK8312_DRIVER_NAME,
691 		.pm = STK8312_PM_OPS,
692 		.acpi_match_table = ACPI_PTR(stk8312_acpi_id),
693 	},
694 	.probe =            stk8312_probe,
695 	.remove =           stk8312_remove,
696 	.id_table =         stk8312_i2c_id,
697 };
698 
699 module_i2c_driver(stk8312_driver);
700 
701 MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
702 MODULE_DESCRIPTION("STK8312 3-Axis Accelerometer driver");
703 MODULE_LICENSE("GPL v2");
704