Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * drivers/hwmon/lis3lv02d_i2c.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Implements I2C interface for lis3lv02d (STMicroelectronics) accelerometer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Driver is based on corresponding SPI driver written by Daniel Mack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * (lis3lv02d_spi.c (C) 2009 Daniel Mack <daniel@caiaq.de> ).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "lis3lv02d.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DRV_NAME	"lis3lv02d_i2c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const char reg_vdd[]    = "Vdd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const char reg_vdd_io[] = "Vdd_IO";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int lis3_reg_ctrl(struct lis3lv02d *lis3, bool state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (state == LIS3_REG_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		ret = regulator_bulk_disable(ARRAY_SIZE(lis3->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 					lis3->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		ret = regulator_bulk_enable(ARRAY_SIZE(lis3->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 					lis3->regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		/* Chip needs time to wakeup. Not mentioned in datasheet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		usleep_range(10000, 20000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static inline s32 lis3_i2c_write(struct lis3lv02d *lis3, int reg, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct i2c_client *c = lis3->bus_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return i2c_smbus_write_byte_data(c, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static inline s32 lis3_i2c_read(struct lis3lv02d *lis3, int reg, u8 *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct i2c_client *c = lis3->bus_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	*v = i2c_smbus_read_byte_data(c, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static inline s32 lis3_i2c_blockread(struct lis3lv02d *lis3, int reg, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				u8 *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct i2c_client *c = lis3->bus_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	reg |= (1 << 7); /* 7th bit enables address auto incrementation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return i2c_smbus_read_i2c_block_data(c, reg, len, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int lis3_i2c_init(struct lis3lv02d *lis3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	lis3_reg_ctrl(lis3, LIS3_REG_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	lis3->read(lis3, WHO_AM_I, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (reg != lis3->whoami)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		printk(KERN_ERR "lis3: power on failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* power up the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	ret = lis3->read(lis3, CTRL_REG1, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (lis3->whoami == WAI_3DLH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		reg |= CTRL1_PM0 | CTRL1_Xen | CTRL1_Yen | CTRL1_Zen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		reg |= CTRL1_PD0 | CTRL1_Xen | CTRL1_Yen | CTRL1_Zen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return lis3->write(lis3, CTRL_REG1, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /* Default axis mapping but it can be overwritten by platform data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static union axis_conversion lis3lv02d_axis_map =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	{ .as_array = { LIS3_DEV_X, LIS3_DEV_Y, LIS3_DEV_Z } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static const struct of_device_id lis3lv02d_i2c_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	{ .compatible = "st,lis3lv02d" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) MODULE_DEVICE_TABLE(of, lis3lv02d_i2c_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int lis3lv02d_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 					const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (of_match_device(lis3lv02d_i2c_dt_ids, &client->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		lis3_dev.of_node = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		ret = lis3lv02d_init_dt(&lis3_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		pdata = lis3_dev.pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if ((pdata->driver_features & LIS3_USE_BLOCK_READ) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			(i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 						I2C_FUNC_SMBUS_I2C_BLOCK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			lis3_dev.blkread  = lis3_i2c_blockread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		if (pdata->axis_x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			lis3lv02d_axis_map.x = pdata->axis_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (pdata->axis_y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			lis3lv02d_axis_map.y = pdata->axis_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (pdata->axis_z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			lis3lv02d_axis_map.z = pdata->axis_z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if (pdata->setup_resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			ret = pdata->setup_resources();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	lis3_dev.regulators[0].supply = reg_vdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	lis3_dev.regulators[1].supply = reg_vdd_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ret = regulator_bulk_get(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				 ARRAY_SIZE(lis3_dev.regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				 lis3_dev.regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	lis3_dev.pdata	  = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	lis3_dev.bus_priv = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	lis3_dev.init	  = lis3_i2c_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	lis3_dev.read	  = lis3_i2c_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	lis3_dev.write	  = lis3_i2c_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	lis3_dev.irq	  = client->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	lis3_dev.ac	  = lis3lv02d_axis_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	lis3_dev.pm_dev	  = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	i2c_set_clientdata(client, &lis3_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* Provide power over the init call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	lis3_reg_ctrl(&lis3_dev, LIS3_REG_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	ret = lis3lv02d_init_device(&lis3_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	lis3_reg_ctrl(&lis3_dev, LIS3_REG_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	regulator_bulk_free(ARRAY_SIZE(lis3_dev.regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				lis3_dev.regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (pdata && pdata->release_resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		pdata->release_resources();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int lis3lv02d_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct lis3lv02d *lis3 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (pdata && pdata->release_resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		pdata->release_resources();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	lis3lv02d_joystick_disable(lis3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	lis3lv02d_remove_fs(&lis3_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	regulator_bulk_free(ARRAY_SIZE(lis3->regulators),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			    lis3_dev.regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int lis3lv02d_i2c_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct lis3lv02d *lis3 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!lis3->pdata || !lis3->pdata->wakeup_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		lis3lv02d_poweroff(lis3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int lis3lv02d_i2c_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct lis3lv02d *lis3 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	 * pm_runtime documentation says that devices should always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 * be powered on at resume. Pm_runtime turns them off after system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 * wide resume is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (!lis3->pdata || !lis3->pdata->wakeup_flags ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		pm_runtime_suspended(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		lis3lv02d_poweron(lis3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #endif /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int lis3_i2c_runtime_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct lis3lv02d *lis3 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	lis3lv02d_poweroff(lis3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int lis3_i2c_runtime_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct lis3lv02d *lis3 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	lis3lv02d_poweron(lis3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static const struct i2c_device_id lis3lv02d_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	{"lis3lv02d", LIS3LV02D},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	{"lis331dlh", LIS331DLH},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_DEVICE_TABLE(i2c, lis3lv02d_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static const struct dev_pm_ops lis3_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	SET_SYSTEM_SLEEP_PM_OPS(lis3lv02d_i2c_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				lis3lv02d_i2c_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	SET_RUNTIME_PM_OPS(lis3_i2c_runtime_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			   lis3_i2c_runtime_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			   NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static struct i2c_driver lis3lv02d_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	.driver	 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		.name   = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		.pm     = &lis3_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		.of_match_table = of_match_ptr(lis3lv02d_i2c_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.probe	= lis3lv02d_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.remove	= lis3lv02d_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.id_table = lis3lv02d_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) module_i2c_driver(lis3lv02d_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) MODULE_AUTHOR("Nokia Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) MODULE_DESCRIPTION("lis3lv02d I2C interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) MODULE_LICENSE("GPL");