| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2013 Capella Microsystems Inc. |
|---|
| 3 | 4 | * Author: Kevin Tsai <ktsai@capellamicro.com> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 6 | | - * under the terms of the GNU General Public License version 2, as published |
|---|
| 7 | | - * by the Free Software Foundation. |
|---|
| 8 | 5 | */ |
|---|
| 9 | 6 | |
|---|
| 7 | +#include <linux/acpi.h> |
|---|
| 10 | 8 | #include <linux/delay.h> |
|---|
| 11 | 9 | #include <linux/err.h> |
|---|
| 12 | 10 | #include <linux/i2c.h> |
|---|
| 13 | 11 | #include <linux/mutex.h> |
|---|
| 14 | 12 | #include <linux/module.h> |
|---|
| 13 | +#include <linux/mod_devicetable.h> |
|---|
| 15 | 14 | #include <linux/interrupt.h> |
|---|
| 16 | 15 | #include <linux/regulator/consumer.h> |
|---|
| 17 | 16 | #include <linux/iio/iio.h> |
|---|
| .. | .. |
|---|
| 21 | 20 | |
|---|
| 22 | 21 | /* Registers Address */ |
|---|
| 23 | 22 | #define CM32181_REG_ADDR_CMD 0x00 |
|---|
| 23 | +#define CM32181_REG_ADDR_WH 0x01 |
|---|
| 24 | +#define CM32181_REG_ADDR_WL 0x02 |
|---|
| 25 | +#define CM32181_REG_ADDR_TEST 0x03 |
|---|
| 24 | 26 | #define CM32181_REG_ADDR_ALS 0x04 |
|---|
| 25 | 27 | #define CM32181_REG_ADDR_STATUS 0x06 |
|---|
| 26 | 28 | #define CM32181_REG_ADDR_ID 0x07 |
|---|
| 27 | 29 | |
|---|
| 28 | 30 | /* Number of Configurable Registers */ |
|---|
| 29 | | -#define CM32181_CONF_REG_NUM 0x01 |
|---|
| 31 | +#define CM32181_CONF_REG_NUM 4 |
|---|
| 30 | 32 | |
|---|
| 31 | 33 | /* CMD register */ |
|---|
| 32 | | -#define CM32181_CMD_ALS_ENABLE 0x00 |
|---|
| 33 | | -#define CM32181_CMD_ALS_DISABLE 0x01 |
|---|
| 34 | | -#define CM32181_CMD_ALS_INT_EN 0x02 |
|---|
| 34 | +#define CM32181_CMD_ALS_DISABLE BIT(0) |
|---|
| 35 | +#define CM32181_CMD_ALS_INT_EN BIT(1) |
|---|
| 36 | +#define CM32181_CMD_ALS_THRES_WINDOW BIT(2) |
|---|
| 37 | + |
|---|
| 38 | +#define CM32181_CMD_ALS_PERS_SHIFT 4 |
|---|
| 39 | +#define CM32181_CMD_ALS_PERS_MASK (0x03 << CM32181_CMD_ALS_PERS_SHIFT) |
|---|
| 40 | +#define CM32181_CMD_ALS_PERS_DEFAULT (0x01 << CM32181_CMD_ALS_PERS_SHIFT) |
|---|
| 35 | 41 | |
|---|
| 36 | 42 | #define CM32181_CMD_ALS_IT_SHIFT 6 |
|---|
| 37 | 43 | #define CM32181_CMD_ALS_IT_MASK (0x0F << CM32181_CMD_ALS_IT_SHIFT) |
|---|
| .. | .. |
|---|
| 41 | 47 | #define CM32181_CMD_ALS_SM_MASK (0x03 << CM32181_CMD_ALS_SM_SHIFT) |
|---|
| 42 | 48 | #define CM32181_CMD_ALS_SM_DEFAULT (0x01 << CM32181_CMD_ALS_SM_SHIFT) |
|---|
| 43 | 49 | |
|---|
| 44 | | -#define CM32181_MLUX_PER_BIT 5 /* ALS_SM=01 IT=800ms */ |
|---|
| 45 | | -#define CM32181_MLUX_PER_BIT_BASE_IT 800000 /* Based on IT=800ms */ |
|---|
| 46 | | -#define CM32181_CALIBSCALE_DEFAULT 1000 |
|---|
| 47 | | -#define CM32181_CALIBSCALE_RESOLUTION 1000 |
|---|
| 48 | | -#define MLUX_PER_LUX 1000 |
|---|
| 50 | +#define CM32181_LUX_PER_BIT 500 /* ALS_SM=01 IT=800ms */ |
|---|
| 51 | +#define CM32181_LUX_PER_BIT_RESOLUTION 100000 |
|---|
| 52 | +#define CM32181_LUX_PER_BIT_BASE_IT 800000 /* Based on IT=800ms */ |
|---|
| 53 | +#define CM32181_CALIBSCALE_DEFAULT 100000 |
|---|
| 54 | +#define CM32181_CALIBSCALE_RESOLUTION 100000 |
|---|
| 49 | 55 | |
|---|
| 50 | | -static const u8 cm32181_reg[CM32181_CONF_REG_NUM] = { |
|---|
| 51 | | - CM32181_REG_ADDR_CMD, |
|---|
| 56 | +#define SMBUS_ALERT_RESPONSE_ADDRESS 0x0c |
|---|
| 57 | + |
|---|
| 58 | +/* CPM0 Index 0: device-id (3218 or 32181), 1: Unknown, 2: init_regs_bitmap */ |
|---|
| 59 | +#define CPM0_REGS_BITMAP 2 |
|---|
| 60 | +#define CPM0_HEADER_SIZE 3 |
|---|
| 61 | + |
|---|
| 62 | +/* CPM1 Index 0: lux_per_bit, 1: calibscale, 2: resolution (100000) */ |
|---|
| 63 | +#define CPM1_LUX_PER_BIT 0 |
|---|
| 64 | +#define CPM1_CALIBSCALE 1 |
|---|
| 65 | +#define CPM1_SIZE 3 |
|---|
| 66 | + |
|---|
| 67 | +/* CM3218 Family */ |
|---|
| 68 | +static const int cm3218_als_it_bits[] = { 0, 1, 2, 3 }; |
|---|
| 69 | +static const int cm3218_als_it_values[] = { 100000, 200000, 400000, 800000 }; |
|---|
| 70 | + |
|---|
| 71 | +/* CM32181 Family */ |
|---|
| 72 | +static const int cm32181_als_it_bits[] = { 12, 8, 0, 1, 2, 3 }; |
|---|
| 73 | +static const int cm32181_als_it_values[] = { |
|---|
| 74 | + 25000, 50000, 100000, 200000, 400000, 800000 |
|---|
| 52 | 75 | }; |
|---|
| 53 | | - |
|---|
| 54 | | -static const int als_it_bits[] = {12, 8, 0, 1, 2, 3}; |
|---|
| 55 | | -static const int als_it_value[] = {25000, 50000, 100000, 200000, 400000, |
|---|
| 56 | | - 800000}; |
|---|
| 57 | 76 | |
|---|
| 58 | 77 | struct cm32181_chip { |
|---|
| 59 | 78 | struct i2c_client *client; |
|---|
| 79 | + struct device *dev; |
|---|
| 60 | 80 | struct mutex lock; |
|---|
| 61 | 81 | u16 conf_regs[CM32181_CONF_REG_NUM]; |
|---|
| 82 | + unsigned long init_regs_bitmap; |
|---|
| 62 | 83 | int calibscale; |
|---|
| 84 | + int lux_per_bit; |
|---|
| 85 | + int lux_per_bit_base_it; |
|---|
| 86 | + int num_als_it; |
|---|
| 87 | + const int *als_it_bits; |
|---|
| 88 | + const int *als_it_values; |
|---|
| 63 | 89 | }; |
|---|
| 90 | + |
|---|
| 91 | +static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val2); |
|---|
| 92 | + |
|---|
| 93 | +#ifdef CONFIG_ACPI |
|---|
| 94 | +/** |
|---|
| 95 | + * cm32181_acpi_get_cpm() - Get CPM object from ACPI |
|---|
| 96 | + * @dev: pointer of struct device. |
|---|
| 97 | + * @obj_name: pointer of ACPI object name. |
|---|
| 98 | + * @values: pointer of array for return elements. |
|---|
| 99 | + * @count: maximum size of return array. |
|---|
| 100 | + * |
|---|
| 101 | + * Convert ACPI CPM table to array. |
|---|
| 102 | + * |
|---|
| 103 | + * Return: -ENODEV for fail. Otherwise is number of elements. |
|---|
| 104 | + */ |
|---|
| 105 | +static int cm32181_acpi_get_cpm(struct device *dev, char *obj_name, |
|---|
| 106 | + u64 *values, int count) |
|---|
| 107 | +{ |
|---|
| 108 | + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
|---|
| 109 | + union acpi_object *cpm, *elem; |
|---|
| 110 | + acpi_handle handle; |
|---|
| 111 | + acpi_status status; |
|---|
| 112 | + int i; |
|---|
| 113 | + |
|---|
| 114 | + handle = ACPI_HANDLE(dev); |
|---|
| 115 | + if (!handle) |
|---|
| 116 | + return -ENODEV; |
|---|
| 117 | + |
|---|
| 118 | + status = acpi_evaluate_object(handle, obj_name, NULL, &buffer); |
|---|
| 119 | + if (ACPI_FAILURE(status)) { |
|---|
| 120 | + dev_err(dev, "object %s not found\n", obj_name); |
|---|
| 121 | + return -ENODEV; |
|---|
| 122 | + } |
|---|
| 123 | + |
|---|
| 124 | + cpm = buffer.pointer; |
|---|
| 125 | + if (cpm->package.count > count) |
|---|
| 126 | + dev_warn(dev, "%s table contains %u values, only using first %d values\n", |
|---|
| 127 | + obj_name, cpm->package.count, count); |
|---|
| 128 | + |
|---|
| 129 | + count = min_t(int, cpm->package.count, count); |
|---|
| 130 | + for (i = 0; i < count; i++) { |
|---|
| 131 | + elem = &(cpm->package.elements[i]); |
|---|
| 132 | + values[i] = elem->integer.value; |
|---|
| 133 | + } |
|---|
| 134 | + |
|---|
| 135 | + kfree(buffer.pointer); |
|---|
| 136 | + |
|---|
| 137 | + return count; |
|---|
| 138 | +} |
|---|
| 139 | + |
|---|
| 140 | +static void cm32181_acpi_parse_cpm_tables(struct cm32181_chip *cm32181) |
|---|
| 141 | +{ |
|---|
| 142 | + u64 vals[CPM0_HEADER_SIZE + CM32181_CONF_REG_NUM]; |
|---|
| 143 | + struct device *dev = cm32181->dev; |
|---|
| 144 | + int i, count; |
|---|
| 145 | + |
|---|
| 146 | + count = cm32181_acpi_get_cpm(dev, "CPM0", vals, ARRAY_SIZE(vals)); |
|---|
| 147 | + if (count <= CPM0_HEADER_SIZE) |
|---|
| 148 | + return; |
|---|
| 149 | + |
|---|
| 150 | + count -= CPM0_HEADER_SIZE; |
|---|
| 151 | + |
|---|
| 152 | + cm32181->init_regs_bitmap = vals[CPM0_REGS_BITMAP]; |
|---|
| 153 | + cm32181->init_regs_bitmap &= GENMASK(count - 1, 0); |
|---|
| 154 | + for_each_set_bit(i, &cm32181->init_regs_bitmap, count) |
|---|
| 155 | + cm32181->conf_regs[i] = vals[CPM0_HEADER_SIZE + i]; |
|---|
| 156 | + |
|---|
| 157 | + count = cm32181_acpi_get_cpm(dev, "CPM1", vals, ARRAY_SIZE(vals)); |
|---|
| 158 | + if (count != CPM1_SIZE) |
|---|
| 159 | + return; |
|---|
| 160 | + |
|---|
| 161 | + cm32181->lux_per_bit = vals[CPM1_LUX_PER_BIT]; |
|---|
| 162 | + |
|---|
| 163 | + /* Check for uncalibrated devices */ |
|---|
| 164 | + if (vals[CPM1_CALIBSCALE] == CM32181_CALIBSCALE_DEFAULT) |
|---|
| 165 | + return; |
|---|
| 166 | + |
|---|
| 167 | + cm32181->calibscale = vals[CPM1_CALIBSCALE]; |
|---|
| 168 | + /* CPM1 lux_per_bit is for the current it value */ |
|---|
| 169 | + cm32181_read_als_it(cm32181, &cm32181->lux_per_bit_base_it); |
|---|
| 170 | +} |
|---|
| 171 | +#else |
|---|
| 172 | +static void cm32181_acpi_parse_cpm_tables(struct cm32181_chip *cm32181) |
|---|
| 173 | +{ |
|---|
| 174 | +} |
|---|
| 175 | +#endif /* CONFIG_ACPI */ |
|---|
| 64 | 176 | |
|---|
| 65 | 177 | /** |
|---|
| 66 | 178 | * cm32181_reg_init() - Initialize CM32181 registers |
|---|
| .. | .. |
|---|
| 81 | 193 | return ret; |
|---|
| 82 | 194 | |
|---|
| 83 | 195 | /* check device ID */ |
|---|
| 84 | | - if ((ret & 0xFF) != 0x81) |
|---|
| 196 | + switch (ret & 0xFF) { |
|---|
| 197 | + case 0x18: /* CM3218 */ |
|---|
| 198 | + cm32181->num_als_it = ARRAY_SIZE(cm3218_als_it_bits); |
|---|
| 199 | + cm32181->als_it_bits = cm3218_als_it_bits; |
|---|
| 200 | + cm32181->als_it_values = cm3218_als_it_values; |
|---|
| 201 | + break; |
|---|
| 202 | + case 0x81: /* CM32181 */ |
|---|
| 203 | + case 0x82: /* CM32182, fully compat. with CM32181 */ |
|---|
| 204 | + cm32181->num_als_it = ARRAY_SIZE(cm32181_als_it_bits); |
|---|
| 205 | + cm32181->als_it_bits = cm32181_als_it_bits; |
|---|
| 206 | + cm32181->als_it_values = cm32181_als_it_values; |
|---|
| 207 | + break; |
|---|
| 208 | + default: |
|---|
| 85 | 209 | return -ENODEV; |
|---|
| 210 | + } |
|---|
| 86 | 211 | |
|---|
| 87 | 212 | /* Default Values */ |
|---|
| 88 | | - cm32181->conf_regs[CM32181_REG_ADDR_CMD] = CM32181_CMD_ALS_ENABLE | |
|---|
| 213 | + cm32181->conf_regs[CM32181_REG_ADDR_CMD] = |
|---|
| 89 | 214 | CM32181_CMD_ALS_IT_DEFAULT | CM32181_CMD_ALS_SM_DEFAULT; |
|---|
| 215 | + cm32181->init_regs_bitmap = BIT(CM32181_REG_ADDR_CMD); |
|---|
| 90 | 216 | cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT; |
|---|
| 217 | + cm32181->lux_per_bit = CM32181_LUX_PER_BIT; |
|---|
| 218 | + cm32181->lux_per_bit_base_it = CM32181_LUX_PER_BIT_BASE_IT; |
|---|
| 219 | + |
|---|
| 220 | + if (ACPI_HANDLE(cm32181->dev)) |
|---|
| 221 | + cm32181_acpi_parse_cpm_tables(cm32181); |
|---|
| 91 | 222 | |
|---|
| 92 | 223 | /* Initialize registers*/ |
|---|
| 93 | | - for (i = 0; i < CM32181_CONF_REG_NUM; i++) { |
|---|
| 94 | | - ret = i2c_smbus_write_word_data(client, cm32181_reg[i], |
|---|
| 95 | | - cm32181->conf_regs[i]); |
|---|
| 224 | + for_each_set_bit(i, &cm32181->init_regs_bitmap, CM32181_CONF_REG_NUM) { |
|---|
| 225 | + ret = i2c_smbus_write_word_data(client, i, |
|---|
| 226 | + cm32181->conf_regs[i]); |
|---|
| 96 | 227 | if (ret < 0) |
|---|
| 97 | 228 | return ret; |
|---|
| 98 | 229 | } |
|---|
| .. | .. |
|---|
| 105 | 236 | * @cm32181: pointer of struct cm32181 |
|---|
| 106 | 237 | * @val2: pointer of int to load the als_it value. |
|---|
| 107 | 238 | * |
|---|
| 108 | | - * Report the current integartion time by millisecond. |
|---|
| 239 | + * Report the current integration time in milliseconds. |
|---|
| 109 | 240 | * |
|---|
| 110 | 241 | * Return: IIO_VAL_INT_PLUS_MICRO for success, otherwise -EINVAL. |
|---|
| 111 | 242 | */ |
|---|
| .. | .. |
|---|
| 117 | 248 | als_it = cm32181->conf_regs[CM32181_REG_ADDR_CMD]; |
|---|
| 118 | 249 | als_it &= CM32181_CMD_ALS_IT_MASK; |
|---|
| 119 | 250 | als_it >>= CM32181_CMD_ALS_IT_SHIFT; |
|---|
| 120 | | - for (i = 0; i < ARRAY_SIZE(als_it_bits); i++) { |
|---|
| 121 | | - if (als_it == als_it_bits[i]) { |
|---|
| 122 | | - *val2 = als_it_value[i]; |
|---|
| 251 | + for (i = 0; i < cm32181->num_als_it; i++) { |
|---|
| 252 | + if (als_it == cm32181->als_it_bits[i]) { |
|---|
| 253 | + *val2 = cm32181->als_it_values[i]; |
|---|
| 123 | 254 | return IIO_VAL_INT_PLUS_MICRO; |
|---|
| 124 | 255 | } |
|---|
| 125 | 256 | } |
|---|
| .. | .. |
|---|
| 142 | 273 | u16 als_it; |
|---|
| 143 | 274 | int ret, i, n; |
|---|
| 144 | 275 | |
|---|
| 145 | | - n = ARRAY_SIZE(als_it_value); |
|---|
| 276 | + n = cm32181->num_als_it; |
|---|
| 146 | 277 | for (i = 0; i < n; i++) |
|---|
| 147 | | - if (val <= als_it_value[i]) |
|---|
| 278 | + if (val <= cm32181->als_it_values[i]) |
|---|
| 148 | 279 | break; |
|---|
| 149 | 280 | if (i >= n) |
|---|
| 150 | 281 | i = n - 1; |
|---|
| 151 | 282 | |
|---|
| 152 | | - als_it = als_it_bits[i]; |
|---|
| 283 | + als_it = cm32181->als_it_bits[i]; |
|---|
| 153 | 284 | als_it <<= CM32181_CMD_ALS_IT_SHIFT; |
|---|
| 154 | 285 | |
|---|
| 155 | 286 | mutex_lock(&cm32181->lock); |
|---|
| .. | .. |
|---|
| 178 | 309 | struct i2c_client *client = cm32181->client; |
|---|
| 179 | 310 | int ret; |
|---|
| 180 | 311 | int als_it; |
|---|
| 181 | | - unsigned long lux; |
|---|
| 312 | + u64 lux; |
|---|
| 182 | 313 | |
|---|
| 183 | 314 | ret = cm32181_read_als_it(cm32181, &als_it); |
|---|
| 184 | 315 | if (ret < 0) |
|---|
| 185 | 316 | return -EINVAL; |
|---|
| 186 | 317 | |
|---|
| 187 | | - lux = CM32181_MLUX_PER_BIT; |
|---|
| 188 | | - lux *= CM32181_MLUX_PER_BIT_BASE_IT; |
|---|
| 189 | | - lux /= als_it; |
|---|
| 318 | + lux = cm32181->lux_per_bit; |
|---|
| 319 | + lux *= cm32181->lux_per_bit_base_it; |
|---|
| 320 | + lux = div_u64(lux, als_it); |
|---|
| 190 | 321 | |
|---|
| 191 | 322 | ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ALS); |
|---|
| 192 | 323 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 194 | 325 | |
|---|
| 195 | 326 | lux *= ret; |
|---|
| 196 | 327 | lux *= cm32181->calibscale; |
|---|
| 197 | | - lux /= CM32181_CALIBSCALE_RESOLUTION; |
|---|
| 198 | | - lux /= MLUX_PER_LUX; |
|---|
| 328 | + lux = div_u64(lux, CM32181_CALIBSCALE_RESOLUTION); |
|---|
| 329 | + lux = div_u64(lux, CM32181_LUX_PER_BIT_RESOLUTION); |
|---|
| 199 | 330 | |
|---|
| 200 | 331 | if (lux > 0xFFFF) |
|---|
| 201 | 332 | lux = 0xFFFF; |
|---|
| .. | .. |
|---|
| 261 | 392 | static ssize_t cm32181_get_it_available(struct device *dev, |
|---|
| 262 | 393 | struct device_attribute *attr, char *buf) |
|---|
| 263 | 394 | { |
|---|
| 395 | + struct cm32181_chip *cm32181 = iio_priv(dev_to_iio_dev(dev)); |
|---|
| 264 | 396 | int i, n, len; |
|---|
| 265 | 397 | |
|---|
| 266 | | - n = ARRAY_SIZE(als_it_value); |
|---|
| 398 | + n = cm32181->num_als_it; |
|---|
| 267 | 399 | for (i = 0, len = 0; i < n; i++) |
|---|
| 268 | | - len += sprintf(buf + len, "0.%06u ", als_it_value[i]); |
|---|
| 400 | + len += sprintf(buf + len, "0.%06u ", cm32181->als_it_values[i]); |
|---|
| 269 | 401 | return len + sprintf(buf + len, "\n"); |
|---|
| 270 | 402 | } |
|---|
| 271 | 403 | |
|---|
| .. | .. |
|---|
| 297 | 429 | .attrs = &cm32181_attribute_group, |
|---|
| 298 | 430 | }; |
|---|
| 299 | 431 | |
|---|
| 300 | | -static int cm32181_probe(struct i2c_client *client, |
|---|
| 301 | | - const struct i2c_device_id *id) |
|---|
| 432 | +static void cm32181_unregister_dummy_client(void *data) |
|---|
| 302 | 433 | { |
|---|
| 434 | + struct i2c_client *client = data; |
|---|
| 435 | + |
|---|
| 436 | + /* Unregister the dummy client */ |
|---|
| 437 | + i2c_unregister_device(client); |
|---|
| 438 | +} |
|---|
| 439 | + |
|---|
| 440 | +static int cm32181_probe(struct i2c_client *client) |
|---|
| 441 | +{ |
|---|
| 442 | + struct device *dev = &client->dev; |
|---|
| 303 | 443 | struct cm32181_chip *cm32181; |
|---|
| 304 | 444 | struct iio_dev *indio_dev; |
|---|
| 305 | 445 | int ret; |
|---|
| 306 | 446 | |
|---|
| 307 | | - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*cm32181)); |
|---|
| 308 | | - if (!indio_dev) { |
|---|
| 309 | | - dev_err(&client->dev, "devm_iio_device_alloc failed\n"); |
|---|
| 447 | + indio_dev = devm_iio_device_alloc(dev, sizeof(*cm32181)); |
|---|
| 448 | + if (!indio_dev) |
|---|
| 310 | 449 | return -ENOMEM; |
|---|
| 450 | + |
|---|
| 451 | + /* |
|---|
| 452 | + * Some ACPI systems list 2 I2C resources for the CM3218 sensor, the |
|---|
| 453 | + * SMBus Alert Response Address (ARA, 0x0c) and the actual I2C address. |
|---|
| 454 | + * Detect this and take the following step to deal with it: |
|---|
| 455 | + * 1. When a SMBus Alert capable sensor has an Alert asserted, it will |
|---|
| 456 | + * not respond on its actual I2C address. Read a byte from the ARA |
|---|
| 457 | + * to clear any pending Alerts. |
|---|
| 458 | + * 2. Create a "dummy" client for the actual I2C address and |
|---|
| 459 | + * use that client to communicate with the sensor. |
|---|
| 460 | + */ |
|---|
| 461 | + if (ACPI_HANDLE(dev) && client->addr == SMBUS_ALERT_RESPONSE_ADDRESS) { |
|---|
| 462 | + struct i2c_board_info board_info = { .type = "dummy" }; |
|---|
| 463 | + |
|---|
| 464 | + i2c_smbus_read_byte(client); |
|---|
| 465 | + |
|---|
| 466 | + client = i2c_acpi_new_device(dev, 1, &board_info); |
|---|
| 467 | + if (IS_ERR(client)) |
|---|
| 468 | + return PTR_ERR(client); |
|---|
| 469 | + |
|---|
| 470 | + ret = devm_add_action_or_reset(dev, cm32181_unregister_dummy_client, client); |
|---|
| 471 | + if (ret) |
|---|
| 472 | + return ret; |
|---|
| 311 | 473 | } |
|---|
| 312 | 474 | |
|---|
| 313 | 475 | cm32181 = iio_priv(indio_dev); |
|---|
| 314 | | - i2c_set_clientdata(client, indio_dev); |
|---|
| 315 | 476 | cm32181->client = client; |
|---|
| 477 | + cm32181->dev = dev; |
|---|
| 316 | 478 | |
|---|
| 317 | 479 | mutex_init(&cm32181->lock); |
|---|
| 318 | | - indio_dev->dev.parent = &client->dev; |
|---|
| 319 | 480 | indio_dev->channels = cm32181_channels; |
|---|
| 320 | 481 | indio_dev->num_channels = ARRAY_SIZE(cm32181_channels); |
|---|
| 321 | 482 | indio_dev->info = &cm32181_info; |
|---|
| 322 | | - indio_dev->name = id->name; |
|---|
| 483 | + indio_dev->name = dev_name(dev); |
|---|
| 323 | 484 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 324 | 485 | |
|---|
| 325 | 486 | ret = cm32181_reg_init(cm32181); |
|---|
| 326 | 487 | if (ret) { |
|---|
| 327 | | - dev_err(&client->dev, |
|---|
| 328 | | - "%s: register init failed\n", |
|---|
| 329 | | - __func__); |
|---|
| 488 | + dev_err(dev, "%s: register init failed\n", __func__); |
|---|
| 330 | 489 | return ret; |
|---|
| 331 | 490 | } |
|---|
| 332 | 491 | |
|---|
| 333 | | - ret = devm_iio_device_register(&client->dev, indio_dev); |
|---|
| 492 | + ret = devm_iio_device_register(dev, indio_dev); |
|---|
| 334 | 493 | if (ret) { |
|---|
| 335 | | - dev_err(&client->dev, |
|---|
| 336 | | - "%s: regist device failed\n", |
|---|
| 337 | | - __func__); |
|---|
| 494 | + dev_err(dev, "%s: regist device failed\n", __func__); |
|---|
| 338 | 495 | return ret; |
|---|
| 339 | 496 | } |
|---|
| 340 | 497 | |
|---|
| 341 | 498 | return 0; |
|---|
| 342 | 499 | } |
|---|
| 343 | 500 | |
|---|
| 344 | | -static const struct i2c_device_id cm32181_id[] = { |
|---|
| 345 | | - { "cm32181", 0 }, |
|---|
| 346 | | - { } |
|---|
| 347 | | -}; |
|---|
| 348 | | - |
|---|
| 349 | | -MODULE_DEVICE_TABLE(i2c, cm32181_id); |
|---|
| 350 | | - |
|---|
| 351 | 501 | static const struct of_device_id cm32181_of_match[] = { |
|---|
| 502 | + { .compatible = "capella,cm3218" }, |
|---|
| 352 | 503 | { .compatible = "capella,cm32181" }, |
|---|
| 353 | 504 | { } |
|---|
| 354 | 505 | }; |
|---|
| 355 | 506 | MODULE_DEVICE_TABLE(of, cm32181_of_match); |
|---|
| 356 | 507 | |
|---|
| 508 | +#ifdef CONFIG_ACPI |
|---|
| 509 | +static const struct acpi_device_id cm32181_acpi_match[] = { |
|---|
| 510 | + { "CPLM3218", 0 }, |
|---|
| 511 | + { } |
|---|
| 512 | +}; |
|---|
| 513 | +MODULE_DEVICE_TABLE(acpi, cm32181_acpi_match); |
|---|
| 514 | +#endif |
|---|
| 515 | + |
|---|
| 357 | 516 | static struct i2c_driver cm32181_driver = { |
|---|
| 358 | 517 | .driver = { |
|---|
| 359 | 518 | .name = "cm32181", |
|---|
| 360 | | - .of_match_table = of_match_ptr(cm32181_of_match), |
|---|
| 519 | + .acpi_match_table = ACPI_PTR(cm32181_acpi_match), |
|---|
| 520 | + .of_match_table = cm32181_of_match, |
|---|
| 361 | 521 | }, |
|---|
| 362 | | - .id_table = cm32181_id, |
|---|
| 363 | | - .probe = cm32181_probe, |
|---|
| 522 | + .probe_new = cm32181_probe, |
|---|
| 364 | 523 | }; |
|---|
| 365 | 524 | |
|---|
| 366 | 525 | module_i2c_driver(cm32181_driver); |
|---|