forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/iio/light/isl29018.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * A iio driver for the light sensor ISL 29018/29023/29035.
34 *
....@@ -5,16 +6,6 @@
56 * sensing and infrared sensing.
67 *
78 * Copyright (c) 2010, NVIDIA Corporation.
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful, but WITHOUT
15
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
- * more details.
189 */
1910
2011 #include <linux/module.h>
....@@ -23,6 +14,7 @@
2314 #include <linux/mutex.h>
2415 #include <linux/delay.h>
2516 #include <linux/regmap.h>
17
+#include <linux/regulator/consumer.h>
2618 #include <linux/slab.h>
2719 #include <linux/iio/iio.h>
2820 #include <linux/iio/sysfs.h>
....@@ -95,6 +87,7 @@
9587 struct isl29018_scale scale;
9688 int prox_scheme;
9789 bool suspended;
90
+ struct regulator *vcc_reg;
9891 };
9992
10093 static int isl29018_set_integration_time(struct isl29018_chip *chip,
....@@ -708,6 +701,16 @@
708701 return dev_name(dev);
709702 }
710703
704
+static void isl29018_disable_regulator_action(void *_data)
705
+{
706
+ struct isl29018_chip *chip = _data;
707
+ int err;
708
+
709
+ err = regulator_disable(chip->vcc_reg);
710
+ if (err)
711
+ pr_err("failed to disable isl29018's VCC regulator!\n");
712
+}
713
+
711714 static int isl29018_probe(struct i2c_client *client,
712715 const struct i2c_device_id *id)
713716 {
....@@ -742,6 +745,24 @@
742745 chip->scale = isl29018_scales[chip->int_time][0];
743746 chip->suspended = false;
744747
748
+ chip->vcc_reg = devm_regulator_get(&client->dev, "vcc");
749
+ if (IS_ERR(chip->vcc_reg))
750
+ return dev_err_probe(&client->dev, PTR_ERR(chip->vcc_reg),
751
+ "failed to get VCC regulator!\n");
752
+
753
+ err = regulator_enable(chip->vcc_reg);
754
+ if (err) {
755
+ dev_err(&client->dev, "failed to enable VCC regulator!\n");
756
+ return err;
757
+ }
758
+
759
+ err = devm_add_action_or_reset(&client->dev, isl29018_disable_regulator_action,
760
+ chip);
761
+ if (err) {
762
+ dev_err(&client->dev, "failed to setup regulator cleanup action!\n");
763
+ return err;
764
+ }
765
+
745766 chip->regmap = devm_regmap_init_i2c(client,
746767 isl29018_chip_info_tbl[dev_id].regmap_cfg);
747768 if (IS_ERR(chip->regmap)) {
....@@ -758,7 +779,6 @@
758779 indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels;
759780 indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels;
760781 indio_dev->name = name;
761
- indio_dev->dev.parent = &client->dev;
762782 indio_dev->modes = INDIO_DIRECT_MODE;
763783
764784 return devm_iio_device_register(&client->dev, indio_dev);
....@@ -768,6 +788,7 @@
768788 static int isl29018_suspend(struct device *dev)
769789 {
770790 struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
791
+ int ret;
771792
772793 mutex_lock(&chip->lock);
773794
....@@ -777,10 +798,13 @@
777798 * So we do not have much to do here.
778799 */
779800 chip->suspended = true;
801
+ ret = regulator_disable(chip->vcc_reg);
802
+ if (ret)
803
+ dev_err(dev, "failed to disable VCC regulator\n");
780804
781805 mutex_unlock(&chip->lock);
782806
783
- return 0;
807
+ return ret;
784808 }
785809
786810 static int isl29018_resume(struct device *dev)
....@@ -790,6 +814,13 @@
790814
791815 mutex_lock(&chip->lock);
792816
817
+ err = regulator_enable(chip->vcc_reg);
818
+ if (err) {
819
+ dev_err(dev, "failed to enable VCC regulator\n");
820
+ mutex_unlock(&chip->lock);
821
+ return err;
822
+ }
823
+
793824 err = isl29018_chip_init(chip);
794825 if (!err)
795826 chip->suspended = false;