Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: imu: inv_icm42600: add wakeup functionality for Wake-on-Motion

When Wake-on-Motion is on, enable system wakeup and keep the chip on
for waking up the system with an interrupt.

Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Link: https://patch.msgid.link/20250630-losd-3-inv-icm42600-add-wom-support-v6-3-5bb0c84800d9@tdk.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jean-Baptiste Maneyrol and committed by
Jonathan Cameron
7586eb9b 50cfaa9a

+47 -13
+2
drivers/iio/imu/inv_icm42600/inv_icm42600.h
··· 151 151 * @map: regmap pointer. 152 152 * @vdd_supply: VDD voltage regulator for the chip. 153 153 * @vddio_supply: I/O voltage regulator for the chip. 154 + * @irq: chip irq, required to enable/disable and set wakeup 154 155 * @orientation: sensor chip orientation relative to main hardware. 155 156 * @conf: chip sensors configurations. 156 157 * @suspended: suspended sensors configuration. ··· 169 168 struct regmap *map; 170 169 struct regulator *vdd_supply; 171 170 struct regulator *vddio_supply; 171 + int irq; 172 172 struct iio_mount_matrix orientation; 173 173 struct inv_icm42600_conf conf; 174 174 struct inv_icm42600_suspended suspended;
+5
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
··· 1206 1206 if (ret) 1207 1207 return ERR_PTR(ret); 1208 1208 1209 + /* accel events are wakeup capable */ 1210 + ret = devm_device_init_wakeup(&indio_dev->dev); 1211 + if (ret) 1212 + return ERR_PTR(ret); 1213 + 1209 1214 return indio_dev; 1210 1215 } 1211 1216
+40 -13
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
··· 765 765 mutex_init(&st->lock); 766 766 st->chip = chip; 767 767 st->map = regmap; 768 + st->irq = irq; 768 769 769 770 ret = iio_read_mount_matrix(dev, &st->orientation); 770 771 if (ret) { ··· 844 843 static int inv_icm42600_suspend(struct device *dev) 845 844 { 846 845 struct inv_icm42600_state *st = dev_get_drvdata(dev); 846 + struct device *accel_dev; 847 + bool wakeup; 848 + int accel_conf; 847 849 int ret; 848 850 849 851 mutex_lock(&st->lock); ··· 867 863 goto out_unlock; 868 864 } 869 865 870 - /* disable APEX features */ 871 - if (st->apex.wom.enable) { 872 - ret = inv_icm42600_disable_wom(st); 873 - if (ret) 874 - goto out_unlock; 866 + /* keep chip on and wake-up capable if APEX and wakeup on */ 867 + accel_dev = &st->indio_accel->dev; 868 + wakeup = st->apex.on && device_may_wakeup(accel_dev); 869 + if (wakeup) { 870 + /* keep accel on and setup irq for wakeup */ 871 + accel_conf = st->conf.accel.mode; 872 + enable_irq_wake(st->irq); 873 + disable_irq(st->irq); 874 + } else { 875 + /* disable APEX features and accel if wakeup disabled */ 876 + if (st->apex.wom.enable) { 877 + ret = inv_icm42600_disable_wom(st); 878 + if (ret) 879 + goto out_unlock; 880 + } 881 + accel_conf = INV_ICM42600_SENSOR_MODE_OFF; 875 882 } 876 883 877 884 ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, 878 - INV_ICM42600_SENSOR_MODE_OFF, false, 879 - NULL); 885 + accel_conf, false, NULL); 880 886 if (ret) 881 887 goto out_unlock; 882 888 883 - regulator_disable(st->vddio_supply); 889 + /* disable vddio regulator if chip is sleeping */ 890 + if (!wakeup) 891 + regulator_disable(st->vddio_supply); 884 892 885 893 out_unlock: 886 894 mutex_unlock(&st->lock); ··· 908 892 struct inv_icm42600_state *st = dev_get_drvdata(dev); 909 893 struct inv_icm42600_sensor_state *gyro_st = iio_priv(st->indio_gyro); 910 894 struct inv_icm42600_sensor_state *accel_st = iio_priv(st->indio_accel); 895 + struct device *accel_dev; 896 + bool wakeup; 911 897 int ret; 912 898 913 899 mutex_lock(&st->lock); 914 900 915 - ret = inv_icm42600_enable_regulator_vddio(st); 916 - if (ret) 917 - goto out_unlock; 901 + /* check wakeup capability */ 902 + accel_dev = &st->indio_accel->dev; 903 + wakeup = st->apex.on && device_may_wakeup(accel_dev); 904 + /* restore irq state or vddio if cut off */ 905 + if (wakeup) { 906 + enable_irq(st->irq); 907 + disable_irq_wake(st->irq); 908 + } else { 909 + ret = inv_icm42600_enable_regulator_vddio(st); 910 + if (ret) 911 + goto out_unlock; 912 + } 918 913 919 914 pm_runtime_disable(dev); 920 915 pm_runtime_set_active(dev); ··· 938 911 if (ret) 939 912 goto out_unlock; 940 913 941 - /* restore APEX features */ 942 - if (st->apex.wom.enable) { 914 + /* restore APEX features if disabled */ 915 + if (!wakeup && st->apex.wom.enable) { 943 916 ret = inv_icm42600_enable_wom(st); 944 917 if (ret) 945 918 goto out_unlock;