18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * IIO driver for the light sensor ISL29028. 48c2ecf20Sopenharmony_ci * ISL29028 is Concurrent Ambient Light and Proximity Sensor 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. 78c2ecf20Sopenharmony_ci * Copyright (c) 2016-2017 Brian Masney <masneyb@onstation.org> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Datasheets: 108c2ecf20Sopenharmony_ci * - http://www.intersil.com/content/dam/Intersil/documents/isl2/isl29028.pdf 118c2ecf20Sopenharmony_ci * - http://www.intersil.com/content/dam/Intersil/documents/isl2/isl29030.pdf 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <linux/i2c.h> 168c2ecf20Sopenharmony_ci#include <linux/err.h> 178c2ecf20Sopenharmony_ci#include <linux/mutex.h> 188c2ecf20Sopenharmony_ci#include <linux/delay.h> 198c2ecf20Sopenharmony_ci#include <linux/slab.h> 208c2ecf20Sopenharmony_ci#include <linux/regmap.h> 218c2ecf20Sopenharmony_ci#include <linux/iio/iio.h> 228c2ecf20Sopenharmony_ci#include <linux/iio/sysfs.h> 238c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define ISL29028_CONV_TIME_MS 100 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define ISL29028_REG_CONFIGURE 0x01 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_IR_MODE_ALS 0 308c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) 318c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_RANGE_LOW_LUX 0 348c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1) 358c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_RANGE_MASK BIT(1) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_DIS 0 388c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_EN BIT(2) 398c2ecf20Sopenharmony_ci#define ISL29028_CONF_ALS_EN_MASK BIT(2) 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define ISL29028_CONF_PROX_SLP_SH 4 428c2ecf20Sopenharmony_ci#define ISL29028_CONF_PROX_SLP_MASK (7 << ISL29028_CONF_PROX_SLP_SH) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define ISL29028_CONF_PROX_EN BIT(7) 458c2ecf20Sopenharmony_ci#define ISL29028_CONF_PROX_EN_MASK BIT(7) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define ISL29028_REG_INTERRUPT 0x02 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define ISL29028_REG_PROX_DATA 0x08 508c2ecf20Sopenharmony_ci#define ISL29028_REG_ALSIR_L 0x09 518c2ecf20Sopenharmony_ci#define ISL29028_REG_ALSIR_U 0x0A 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define ISL29028_REG_TEST1_MODE 0x0E 548c2ecf20Sopenharmony_ci#define ISL29028_REG_TEST2_MODE 0x0F 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define ISL29028_POWER_OFF_DELAY_MS 2000 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistruct isl29028_prox_data { 618c2ecf20Sopenharmony_ci int sampling_int; 628c2ecf20Sopenharmony_ci int sampling_fract; 638c2ecf20Sopenharmony_ci int sleep_time; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic const struct isl29028_prox_data isl29028_prox_data[] = { 678c2ecf20Sopenharmony_ci { 1, 250000, 800 }, 688c2ecf20Sopenharmony_ci { 2, 500000, 400 }, 698c2ecf20Sopenharmony_ci { 5, 0, 200 }, 708c2ecf20Sopenharmony_ci { 10, 0, 100 }, 718c2ecf20Sopenharmony_ci { 13, 300000, 75 }, 728c2ecf20Sopenharmony_ci { 20, 0, 50 }, 738c2ecf20Sopenharmony_ci { 80, 0, 13 }, /* 748c2ecf20Sopenharmony_ci * Note: Data sheet lists 12.5 ms sleep time. 758c2ecf20Sopenharmony_ci * Round up a half millisecond for msleep(). 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ci { 100, 0, 0 } 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cienum isl29028_als_ir_mode { 818c2ecf20Sopenharmony_ci ISL29028_MODE_NONE = 0, 828c2ecf20Sopenharmony_ci ISL29028_MODE_ALS, 838c2ecf20Sopenharmony_ci ISL29028_MODE_IR, 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistruct isl29028_chip { 878c2ecf20Sopenharmony_ci struct mutex lock; 888c2ecf20Sopenharmony_ci struct regmap *regmap; 898c2ecf20Sopenharmony_ci int prox_sampling_int; 908c2ecf20Sopenharmony_ci int prox_sampling_frac; 918c2ecf20Sopenharmony_ci bool enable_prox; 928c2ecf20Sopenharmony_ci int lux_scale; 938c2ecf20Sopenharmony_ci enum isl29028_als_ir_mode als_ir_mode; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic int isl29028_find_prox_sleep_index(int sampling_int, int sampling_fract) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci int i; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(isl29028_prox_data); ++i) { 1018c2ecf20Sopenharmony_ci if (isl29028_prox_data[i].sampling_int == sampling_int && 1028c2ecf20Sopenharmony_ci isl29028_prox_data[i].sampling_fract == sampling_fract) 1038c2ecf20Sopenharmony_ci return i; 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci return -EINVAL; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic int isl29028_set_proxim_sampling(struct isl29028_chip *chip, 1108c2ecf20Sopenharmony_ci int sampling_int, int sampling_fract) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 1138c2ecf20Sopenharmony_ci int sleep_index, ret; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci sleep_index = isl29028_find_prox_sleep_index(sampling_int, 1168c2ecf20Sopenharmony_ci sampling_fract); 1178c2ecf20Sopenharmony_ci if (sleep_index < 0) 1188c2ecf20Sopenharmony_ci return sleep_index; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 1218c2ecf20Sopenharmony_ci ISL29028_CONF_PROX_SLP_MASK, 1228c2ecf20Sopenharmony_ci sleep_index << ISL29028_CONF_PROX_SLP_SH); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci if (ret < 0) { 1258c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Error %d setting the proximity sampling\n", 1268c2ecf20Sopenharmony_ci __func__, ret); 1278c2ecf20Sopenharmony_ci return ret; 1288c2ecf20Sopenharmony_ci } 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci chip->prox_sampling_int = sampling_int; 1318c2ecf20Sopenharmony_ci chip->prox_sampling_frac = sampling_fract; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci return ret; 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic int isl29028_enable_proximity(struct isl29028_chip *chip) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci int prox_index, ret; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling_int, 1418c2ecf20Sopenharmony_ci chip->prox_sampling_frac); 1428c2ecf20Sopenharmony_ci if (ret < 0) 1438c2ecf20Sopenharmony_ci return ret; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 1468c2ecf20Sopenharmony_ci ISL29028_CONF_PROX_EN_MASK, 1478c2ecf20Sopenharmony_ci ISL29028_CONF_PROX_EN); 1488c2ecf20Sopenharmony_ci if (ret < 0) 1498c2ecf20Sopenharmony_ci return ret; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci /* Wait for conversion to be complete for first sample */ 1528c2ecf20Sopenharmony_ci prox_index = isl29028_find_prox_sleep_index(chip->prox_sampling_int, 1538c2ecf20Sopenharmony_ci chip->prox_sampling_frac); 1548c2ecf20Sopenharmony_ci if (prox_index < 0) 1558c2ecf20Sopenharmony_ci return prox_index; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci msleep(isl29028_prox_data[prox_index].sleep_time); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci return 0; 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistatic int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) 1638c2ecf20Sopenharmony_ci{ 1648c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 1658c2ecf20Sopenharmony_ci int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX : 1668c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_RANGE_LOW_LUX; 1678c2ecf20Sopenharmony_ci int ret; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 1708c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_RANGE_MASK, val); 1718c2ecf20Sopenharmony_ci if (ret < 0) { 1728c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Error %d setting the ALS scale\n", __func__, 1738c2ecf20Sopenharmony_ci ret); 1748c2ecf20Sopenharmony_ci return ret; 1758c2ecf20Sopenharmony_ci } 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci chip->lux_scale = lux_scale; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci return ret; 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistatic int isl29028_set_als_ir_mode(struct isl29028_chip *chip, 1838c2ecf20Sopenharmony_ci enum isl29028_als_ir_mode mode) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci int ret; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci if (chip->als_ir_mode == mode) 1888c2ecf20Sopenharmony_ci return 0; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci ret = isl29028_set_als_scale(chip, chip->lux_scale); 1918c2ecf20Sopenharmony_ci if (ret < 0) 1928c2ecf20Sopenharmony_ci return ret; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci switch (mode) { 1958c2ecf20Sopenharmony_ci case ISL29028_MODE_ALS: 1968c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 1978c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_IR_MODE_MASK, 1988c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_IR_MODE_ALS); 1998c2ecf20Sopenharmony_ci if (ret < 0) 2008c2ecf20Sopenharmony_ci return ret; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 2038c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_RANGE_MASK, 2048c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_RANGE_HIGH_LUX); 2058c2ecf20Sopenharmony_ci break; 2068c2ecf20Sopenharmony_ci case ISL29028_MODE_IR: 2078c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 2088c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_IR_MODE_MASK, 2098c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_IR_MODE_IR); 2108c2ecf20Sopenharmony_ci break; 2118c2ecf20Sopenharmony_ci case ISL29028_MODE_NONE: 2128c2ecf20Sopenharmony_ci return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 2138c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_EN_MASK, 2148c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_DIS); 2158c2ecf20Sopenharmony_ci } 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci if (ret < 0) 2188c2ecf20Sopenharmony_ci return ret; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci /* Enable the ALS/IR */ 2218c2ecf20Sopenharmony_ci ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 2228c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_EN_MASK, 2238c2ecf20Sopenharmony_ci ISL29028_CONF_ALS_EN); 2248c2ecf20Sopenharmony_ci if (ret < 0) 2258c2ecf20Sopenharmony_ci return ret; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci /* Need to wait for conversion time if ALS/IR mode enabled */ 2288c2ecf20Sopenharmony_ci msleep(ISL29028_CONV_TIME_MS); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci chip->als_ir_mode = mode; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci return 0; 2338c2ecf20Sopenharmony_ci} 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cistatic int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 2388c2ecf20Sopenharmony_ci unsigned int lsb; 2398c2ecf20Sopenharmony_ci unsigned int msb; 2408c2ecf20Sopenharmony_ci int ret; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); 2438c2ecf20Sopenharmony_ci if (ret < 0) { 2448c2ecf20Sopenharmony_ci dev_err(dev, 2458c2ecf20Sopenharmony_ci "%s(): Error %d reading register ALSIR_L\n", 2468c2ecf20Sopenharmony_ci __func__, ret); 2478c2ecf20Sopenharmony_ci return ret; 2488c2ecf20Sopenharmony_ci } 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); 2518c2ecf20Sopenharmony_ci if (ret < 0) { 2528c2ecf20Sopenharmony_ci dev_err(dev, 2538c2ecf20Sopenharmony_ci "%s(): Error %d reading register ALSIR_U\n", 2548c2ecf20Sopenharmony_ci __func__, ret); 2558c2ecf20Sopenharmony_ci return ret; 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci *als_ir = ((msb & 0xF) << 8) | (lsb & 0xFF); 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci return 0; 2618c2ecf20Sopenharmony_ci} 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistatic int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) 2648c2ecf20Sopenharmony_ci{ 2658c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 2668c2ecf20Sopenharmony_ci unsigned int data; 2678c2ecf20Sopenharmony_ci int ret; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci if (!chip->enable_prox) { 2708c2ecf20Sopenharmony_ci ret = isl29028_enable_proximity(chip); 2718c2ecf20Sopenharmony_ci if (ret < 0) 2728c2ecf20Sopenharmony_ci return ret; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci chip->enable_prox = true; 2758c2ecf20Sopenharmony_ci } 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); 2788c2ecf20Sopenharmony_ci if (ret < 0) { 2798c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Error %d reading register PROX_DATA\n", 2808c2ecf20Sopenharmony_ci __func__, ret); 2818c2ecf20Sopenharmony_ci return ret; 2828c2ecf20Sopenharmony_ci } 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci *prox = data; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci return 0; 2878c2ecf20Sopenharmony_ci} 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistatic int isl29028_als_get(struct isl29028_chip *chip, int *als_data) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 2928c2ecf20Sopenharmony_ci int ret; 2938c2ecf20Sopenharmony_ci int als_ir_data; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); 2968c2ecf20Sopenharmony_ci if (ret < 0) { 2978c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Error %d enabling ALS mode\n", __func__, 2988c2ecf20Sopenharmony_ci ret); 2998c2ecf20Sopenharmony_ci return ret; 3008c2ecf20Sopenharmony_ci } 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci ret = isl29028_read_als_ir(chip, &als_ir_data); 3038c2ecf20Sopenharmony_ci if (ret < 0) 3048c2ecf20Sopenharmony_ci return ret; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci /* 3078c2ecf20Sopenharmony_ci * convert als data count to lux. 3088c2ecf20Sopenharmony_ci * if lux_scale = 125, lux = count * 0.031 3098c2ecf20Sopenharmony_ci * if lux_scale = 2000, lux = count * 0.49 3108c2ecf20Sopenharmony_ci */ 3118c2ecf20Sopenharmony_ci if (chip->lux_scale == 125) 3128c2ecf20Sopenharmony_ci als_ir_data = (als_ir_data * 31) / 1000; 3138c2ecf20Sopenharmony_ci else 3148c2ecf20Sopenharmony_ci als_ir_data = (als_ir_data * 49) / 100; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci *als_data = als_ir_data; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci return 0; 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) 3228c2ecf20Sopenharmony_ci{ 3238c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 3248c2ecf20Sopenharmony_ci int ret; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); 3278c2ecf20Sopenharmony_ci if (ret < 0) { 3288c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Error %d enabling IR mode\n", __func__, 3298c2ecf20Sopenharmony_ci ret); 3308c2ecf20Sopenharmony_ci return ret; 3318c2ecf20Sopenharmony_ci } 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci return isl29028_read_als_ir(chip, ir_data); 3348c2ecf20Sopenharmony_ci} 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistatic int isl29028_set_pm_runtime_busy(struct isl29028_chip *chip, bool on) 3378c2ecf20Sopenharmony_ci{ 3388c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 3398c2ecf20Sopenharmony_ci int ret; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci if (on) { 3428c2ecf20Sopenharmony_ci ret = pm_runtime_get_sync(dev); 3438c2ecf20Sopenharmony_ci if (ret < 0) 3448c2ecf20Sopenharmony_ci pm_runtime_put_noidle(dev); 3458c2ecf20Sopenharmony_ci } else { 3468c2ecf20Sopenharmony_ci pm_runtime_mark_last_busy(dev); 3478c2ecf20Sopenharmony_ci ret = pm_runtime_put_autosuspend(dev); 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci return ret; 3518c2ecf20Sopenharmony_ci} 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci/* Channel IO */ 3548c2ecf20Sopenharmony_cistatic int isl29028_write_raw(struct iio_dev *indio_dev, 3558c2ecf20Sopenharmony_ci struct iio_chan_spec const *chan, 3568c2ecf20Sopenharmony_ci int val, int val2, long mask) 3578c2ecf20Sopenharmony_ci{ 3588c2ecf20Sopenharmony_ci struct isl29028_chip *chip = iio_priv(indio_dev); 3598c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 3608c2ecf20Sopenharmony_ci int ret; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci ret = isl29028_set_pm_runtime_busy(chip, true); 3638c2ecf20Sopenharmony_ci if (ret < 0) 3648c2ecf20Sopenharmony_ci return ret; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci mutex_lock(&chip->lock); 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci ret = -EINVAL; 3698c2ecf20Sopenharmony_ci switch (chan->type) { 3708c2ecf20Sopenharmony_ci case IIO_PROXIMITY: 3718c2ecf20Sopenharmony_ci if (mask != IIO_CHAN_INFO_SAMP_FREQ) { 3728c2ecf20Sopenharmony_ci dev_err(dev, 3738c2ecf20Sopenharmony_ci "%s(): proximity: Mask value 0x%08lx is not supported\n", 3748c2ecf20Sopenharmony_ci __func__, mask); 3758c2ecf20Sopenharmony_ci break; 3768c2ecf20Sopenharmony_ci } 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci if (val < 1 || val > 100) { 3798c2ecf20Sopenharmony_ci dev_err(dev, 3808c2ecf20Sopenharmony_ci "%s(): proximity: Sampling frequency %d is not in the range [1:100]\n", 3818c2ecf20Sopenharmony_ci __func__, val); 3828c2ecf20Sopenharmony_ci break; 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci ret = isl29028_set_proxim_sampling(chip, val, val2); 3868c2ecf20Sopenharmony_ci break; 3878c2ecf20Sopenharmony_ci case IIO_LIGHT: 3888c2ecf20Sopenharmony_ci if (mask != IIO_CHAN_INFO_SCALE) { 3898c2ecf20Sopenharmony_ci dev_err(dev, 3908c2ecf20Sopenharmony_ci "%s(): light: Mask value 0x%08lx is not supported\n", 3918c2ecf20Sopenharmony_ci __func__, mask); 3928c2ecf20Sopenharmony_ci break; 3938c2ecf20Sopenharmony_ci } 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci if (val != 125 && val != 2000) { 3968c2ecf20Sopenharmony_ci dev_err(dev, 3978c2ecf20Sopenharmony_ci "%s(): light: Lux scale %d is not in the set {125, 2000}\n", 3988c2ecf20Sopenharmony_ci __func__, val); 3998c2ecf20Sopenharmony_ci break; 4008c2ecf20Sopenharmony_ci } 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci ret = isl29028_set_als_scale(chip, val); 4038c2ecf20Sopenharmony_ci break; 4048c2ecf20Sopenharmony_ci default: 4058c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Unsupported channel type %x\n", 4068c2ecf20Sopenharmony_ci __func__, chan->type); 4078c2ecf20Sopenharmony_ci break; 4088c2ecf20Sopenharmony_ci } 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci mutex_unlock(&chip->lock); 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci if (ret < 0) 4138c2ecf20Sopenharmony_ci return ret; 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci ret = isl29028_set_pm_runtime_busy(chip, false); 4168c2ecf20Sopenharmony_ci if (ret < 0) 4178c2ecf20Sopenharmony_ci return ret; 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci return ret; 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic int isl29028_read_raw(struct iio_dev *indio_dev, 4238c2ecf20Sopenharmony_ci struct iio_chan_spec const *chan, 4248c2ecf20Sopenharmony_ci int *val, int *val2, long mask) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci struct isl29028_chip *chip = iio_priv(indio_dev); 4278c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 4288c2ecf20Sopenharmony_ci int ret, pm_ret; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci ret = isl29028_set_pm_runtime_busy(chip, true); 4318c2ecf20Sopenharmony_ci if (ret < 0) 4328c2ecf20Sopenharmony_ci return ret; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci mutex_lock(&chip->lock); 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci ret = -EINVAL; 4378c2ecf20Sopenharmony_ci switch (mask) { 4388c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_RAW: 4398c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_PROCESSED: 4408c2ecf20Sopenharmony_ci switch (chan->type) { 4418c2ecf20Sopenharmony_ci case IIO_LIGHT: 4428c2ecf20Sopenharmony_ci ret = isl29028_als_get(chip, val); 4438c2ecf20Sopenharmony_ci break; 4448c2ecf20Sopenharmony_ci case IIO_INTENSITY: 4458c2ecf20Sopenharmony_ci ret = isl29028_ir_get(chip, val); 4468c2ecf20Sopenharmony_ci break; 4478c2ecf20Sopenharmony_ci case IIO_PROXIMITY: 4488c2ecf20Sopenharmony_ci ret = isl29028_read_proxim(chip, val); 4498c2ecf20Sopenharmony_ci break; 4508c2ecf20Sopenharmony_ci default: 4518c2ecf20Sopenharmony_ci break; 4528c2ecf20Sopenharmony_ci } 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci if (ret < 0) 4558c2ecf20Sopenharmony_ci break; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci ret = IIO_VAL_INT; 4588c2ecf20Sopenharmony_ci break; 4598c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_SAMP_FREQ: 4608c2ecf20Sopenharmony_ci if (chan->type != IIO_PROXIMITY) 4618c2ecf20Sopenharmony_ci break; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci *val = chip->prox_sampling_int; 4648c2ecf20Sopenharmony_ci *val2 = chip->prox_sampling_frac; 4658c2ecf20Sopenharmony_ci ret = IIO_VAL_INT; 4668c2ecf20Sopenharmony_ci break; 4678c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_SCALE: 4688c2ecf20Sopenharmony_ci if (chan->type != IIO_LIGHT) 4698c2ecf20Sopenharmony_ci break; 4708c2ecf20Sopenharmony_ci *val = chip->lux_scale; 4718c2ecf20Sopenharmony_ci ret = IIO_VAL_INT; 4728c2ecf20Sopenharmony_ci break; 4738c2ecf20Sopenharmony_ci default: 4748c2ecf20Sopenharmony_ci dev_err(dev, "%s(): mask value 0x%08lx is not supported\n", 4758c2ecf20Sopenharmony_ci __func__, mask); 4768c2ecf20Sopenharmony_ci break; 4778c2ecf20Sopenharmony_ci } 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci mutex_unlock(&chip->lock); 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci if (ret < 0) 4828c2ecf20Sopenharmony_ci return ret; 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci /** 4858c2ecf20Sopenharmony_ci * Preserve the ret variable if the call to 4868c2ecf20Sopenharmony_ci * isl29028_set_pm_runtime_busy() is successful so the reading 4878c2ecf20Sopenharmony_ci * (if applicable) is returned to user space. 4888c2ecf20Sopenharmony_ci */ 4898c2ecf20Sopenharmony_ci pm_ret = isl29028_set_pm_runtime_busy(chip, false); 4908c2ecf20Sopenharmony_ci if (pm_ret < 0) 4918c2ecf20Sopenharmony_ci return pm_ret; 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci return ret; 4948c2ecf20Sopenharmony_ci} 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_cistatic IIO_CONST_ATTR(in_proximity_sampling_frequency_available, 4978c2ecf20Sopenharmony_ci "1.25 2.5 5 10 13.3 20 80 100"); 4988c2ecf20Sopenharmony_cistatic IIO_CONST_ATTR(in_illuminance_scale_available, "125 2000"); 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci#define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) 5018c2ecf20Sopenharmony_cistatic struct attribute *isl29028_attributes[] = { 5028c2ecf20Sopenharmony_ci ISL29028_CONST_ATTR(in_proximity_sampling_frequency_available), 5038c2ecf20Sopenharmony_ci ISL29028_CONST_ATTR(in_illuminance_scale_available), 5048c2ecf20Sopenharmony_ci NULL, 5058c2ecf20Sopenharmony_ci}; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_cistatic const struct attribute_group isl29108_group = { 5088c2ecf20Sopenharmony_ci .attrs = isl29028_attributes, 5098c2ecf20Sopenharmony_ci}; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic const struct iio_chan_spec isl29028_channels[] = { 5128c2ecf20Sopenharmony_ci { 5138c2ecf20Sopenharmony_ci .type = IIO_LIGHT, 5148c2ecf20Sopenharmony_ci .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 5158c2ecf20Sopenharmony_ci BIT(IIO_CHAN_INFO_SCALE), 5168c2ecf20Sopenharmony_ci }, { 5178c2ecf20Sopenharmony_ci .type = IIO_INTENSITY, 5188c2ecf20Sopenharmony_ci .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 5198c2ecf20Sopenharmony_ci }, { 5208c2ecf20Sopenharmony_ci .type = IIO_PROXIMITY, 5218c2ecf20Sopenharmony_ci .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 5228c2ecf20Sopenharmony_ci BIT(IIO_CHAN_INFO_SAMP_FREQ), 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci}; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_cistatic const struct iio_info isl29028_info = { 5278c2ecf20Sopenharmony_ci .attrs = &isl29108_group, 5288c2ecf20Sopenharmony_ci .read_raw = isl29028_read_raw, 5298c2ecf20Sopenharmony_ci .write_raw = isl29028_write_raw, 5308c2ecf20Sopenharmony_ci}; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistatic int isl29028_clear_configure_reg(struct isl29028_chip *chip) 5338c2ecf20Sopenharmony_ci{ 5348c2ecf20Sopenharmony_ci struct device *dev = regmap_get_device(chip->regmap); 5358c2ecf20Sopenharmony_ci int ret; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); 5388c2ecf20Sopenharmony_ci if (ret < 0) 5398c2ecf20Sopenharmony_ci dev_err(dev, "%s(): Error %d clearing the CONFIGURE register\n", 5408c2ecf20Sopenharmony_ci __func__, ret); 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci chip->als_ir_mode = ISL29028_MODE_NONE; 5438c2ecf20Sopenharmony_ci chip->enable_prox = false; 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci return ret; 5468c2ecf20Sopenharmony_ci} 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_cistatic bool isl29028_is_volatile_reg(struct device *dev, unsigned int reg) 5498c2ecf20Sopenharmony_ci{ 5508c2ecf20Sopenharmony_ci switch (reg) { 5518c2ecf20Sopenharmony_ci case ISL29028_REG_INTERRUPT: 5528c2ecf20Sopenharmony_ci case ISL29028_REG_PROX_DATA: 5538c2ecf20Sopenharmony_ci case ISL29028_REG_ALSIR_L: 5548c2ecf20Sopenharmony_ci case ISL29028_REG_ALSIR_U: 5558c2ecf20Sopenharmony_ci return true; 5568c2ecf20Sopenharmony_ci default: 5578c2ecf20Sopenharmony_ci return false; 5588c2ecf20Sopenharmony_ci } 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic const struct regmap_config isl29028_regmap_config = { 5628c2ecf20Sopenharmony_ci .reg_bits = 8, 5638c2ecf20Sopenharmony_ci .val_bits = 8, 5648c2ecf20Sopenharmony_ci .volatile_reg = isl29028_is_volatile_reg, 5658c2ecf20Sopenharmony_ci .max_register = ISL29028_NUM_REGS - 1, 5668c2ecf20Sopenharmony_ci .num_reg_defaults_raw = ISL29028_NUM_REGS, 5678c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 5688c2ecf20Sopenharmony_ci}; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_cistatic int isl29028_probe(struct i2c_client *client, 5718c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 5728c2ecf20Sopenharmony_ci{ 5738c2ecf20Sopenharmony_ci struct isl29028_chip *chip; 5748c2ecf20Sopenharmony_ci struct iio_dev *indio_dev; 5758c2ecf20Sopenharmony_ci int ret; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 5788c2ecf20Sopenharmony_ci if (!indio_dev) 5798c2ecf20Sopenharmony_ci return -ENOMEM; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci chip = iio_priv(indio_dev); 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci i2c_set_clientdata(client, indio_dev); 5848c2ecf20Sopenharmony_ci mutex_init(&chip->lock); 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); 5878c2ecf20Sopenharmony_ci if (IS_ERR(chip->regmap)) { 5888c2ecf20Sopenharmony_ci ret = PTR_ERR(chip->regmap); 5898c2ecf20Sopenharmony_ci dev_err(&client->dev, "%s: Error %d initializing regmap\n", 5908c2ecf20Sopenharmony_ci __func__, ret); 5918c2ecf20Sopenharmony_ci return ret; 5928c2ecf20Sopenharmony_ci } 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci chip->enable_prox = false; 5958c2ecf20Sopenharmony_ci chip->prox_sampling_int = 20; 5968c2ecf20Sopenharmony_ci chip->prox_sampling_frac = 0; 5978c2ecf20Sopenharmony_ci chip->lux_scale = 2000; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); 6008c2ecf20Sopenharmony_ci if (ret < 0) { 6018c2ecf20Sopenharmony_ci dev_err(&client->dev, 6028c2ecf20Sopenharmony_ci "%s(): Error %d writing to TEST1_MODE register\n", 6038c2ecf20Sopenharmony_ci __func__, ret); 6048c2ecf20Sopenharmony_ci return ret; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); 6088c2ecf20Sopenharmony_ci if (ret < 0) { 6098c2ecf20Sopenharmony_ci dev_err(&client->dev, 6108c2ecf20Sopenharmony_ci "%s(): Error %d writing to TEST2_MODE register\n", 6118c2ecf20Sopenharmony_ci __func__, ret); 6128c2ecf20Sopenharmony_ci return ret; 6138c2ecf20Sopenharmony_ci } 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci ret = isl29028_clear_configure_reg(chip); 6168c2ecf20Sopenharmony_ci if (ret < 0) 6178c2ecf20Sopenharmony_ci return ret; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci indio_dev->info = &isl29028_info; 6208c2ecf20Sopenharmony_ci indio_dev->channels = isl29028_channels; 6218c2ecf20Sopenharmony_ci indio_dev->num_channels = ARRAY_SIZE(isl29028_channels); 6228c2ecf20Sopenharmony_ci indio_dev->name = id->name; 6238c2ecf20Sopenharmony_ci indio_dev->modes = INDIO_DIRECT_MODE; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci pm_runtime_enable(&client->dev); 6268c2ecf20Sopenharmony_ci pm_runtime_set_autosuspend_delay(&client->dev, 6278c2ecf20Sopenharmony_ci ISL29028_POWER_OFF_DELAY_MS); 6288c2ecf20Sopenharmony_ci pm_runtime_use_autosuspend(&client->dev); 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci ret = iio_device_register(indio_dev); 6318c2ecf20Sopenharmony_ci if (ret < 0) { 6328c2ecf20Sopenharmony_ci dev_err(&client->dev, 6338c2ecf20Sopenharmony_ci "%s(): iio registration failed with error %d\n", 6348c2ecf20Sopenharmony_ci __func__, ret); 6358c2ecf20Sopenharmony_ci return ret; 6368c2ecf20Sopenharmony_ci } 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci return 0; 6398c2ecf20Sopenharmony_ci} 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_cistatic int isl29028_remove(struct i2c_client *client) 6428c2ecf20Sopenharmony_ci{ 6438c2ecf20Sopenharmony_ci struct iio_dev *indio_dev = i2c_get_clientdata(client); 6448c2ecf20Sopenharmony_ci struct isl29028_chip *chip = iio_priv(indio_dev); 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci iio_device_unregister(indio_dev); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci pm_runtime_disable(&client->dev); 6498c2ecf20Sopenharmony_ci pm_runtime_set_suspended(&client->dev); 6508c2ecf20Sopenharmony_ci pm_runtime_put_noidle(&client->dev); 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci return isl29028_clear_configure_reg(chip); 6538c2ecf20Sopenharmony_ci} 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_cistatic int __maybe_unused isl29028_suspend(struct device *dev) 6568c2ecf20Sopenharmony_ci{ 6578c2ecf20Sopenharmony_ci struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 6588c2ecf20Sopenharmony_ci struct isl29028_chip *chip = iio_priv(indio_dev); 6598c2ecf20Sopenharmony_ci int ret; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci mutex_lock(&chip->lock); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci ret = isl29028_clear_configure_reg(chip); 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci mutex_unlock(&chip->lock); 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci return ret; 6688c2ecf20Sopenharmony_ci} 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_cistatic int __maybe_unused isl29028_resume(struct device *dev) 6718c2ecf20Sopenharmony_ci{ 6728c2ecf20Sopenharmony_ci /** 6738c2ecf20Sopenharmony_ci * The specific component (ALS/IR or proximity) will enable itself as 6748c2ecf20Sopenharmony_ci * needed the next time that the user requests a reading. This is done 6758c2ecf20Sopenharmony_ci * above in isl29028_set_als_ir_mode() and isl29028_enable_proximity(). 6768c2ecf20Sopenharmony_ci */ 6778c2ecf20Sopenharmony_ci return 0; 6788c2ecf20Sopenharmony_ci} 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_cistatic const struct dev_pm_ops isl29028_pm_ops = { 6818c2ecf20Sopenharmony_ci SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 6828c2ecf20Sopenharmony_ci pm_runtime_force_resume) 6838c2ecf20Sopenharmony_ci SET_RUNTIME_PM_OPS(isl29028_suspend, isl29028_resume, NULL) 6848c2ecf20Sopenharmony_ci}; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_cistatic const struct i2c_device_id isl29028_id[] = { 6878c2ecf20Sopenharmony_ci {"isl29028", 0}, 6888c2ecf20Sopenharmony_ci {"isl29030", 0}, 6898c2ecf20Sopenharmony_ci {} 6908c2ecf20Sopenharmony_ci}; 6918c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, isl29028_id); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_cistatic const struct of_device_id isl29028_of_match[] = { 6948c2ecf20Sopenharmony_ci { .compatible = "isl,isl29028", }, /* for backward compat., don't use */ 6958c2ecf20Sopenharmony_ci { .compatible = "isil,isl29028", }, 6968c2ecf20Sopenharmony_ci { .compatible = "isil,isl29030", }, 6978c2ecf20Sopenharmony_ci { }, 6988c2ecf20Sopenharmony_ci}; 6998c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, isl29028_of_match); 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_cistatic struct i2c_driver isl29028_driver = { 7028c2ecf20Sopenharmony_ci .driver = { 7038c2ecf20Sopenharmony_ci .name = "isl29028", 7048c2ecf20Sopenharmony_ci .pm = &isl29028_pm_ops, 7058c2ecf20Sopenharmony_ci .of_match_table = isl29028_of_match, 7068c2ecf20Sopenharmony_ci }, 7078c2ecf20Sopenharmony_ci .probe = isl29028_probe, 7088c2ecf20Sopenharmony_ci .remove = isl29028_remove, 7098c2ecf20Sopenharmony_ci .id_table = isl29028_id, 7108c2ecf20Sopenharmony_ci}; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_cimodule_i2c_driver(isl29028_driver); 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ISL29028 Ambient Light and Proximity Sensor driver"); 7158c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 7168c2ecf20Sopenharmony_ciMODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); 717