cm32181.c (4f2c0a4acffbec01079c28f839422e64ddeff004) cm32181.c (ee3c5b644a0fdcfed27515a39fb2dd3a016704c1)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2013 Capella Microsystems Inc.
4 * Author: Kevin Tsai <ktsai@capellamicro.com>
5 */
6
7#include <linux/acpi.h>
8#include <linux/delay.h>

--- 426 unchanged lines hidden (view full) ---

435 struct cm32181_chip *cm32181;
436 struct iio_dev *indio_dev;
437 int ret;
438
439 indio_dev = devm_iio_device_alloc(dev, sizeof(*cm32181));
440 if (!indio_dev)
441 return -ENOMEM;
442
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2013 Capella Microsystems Inc.
4 * Author: Kevin Tsai <ktsai@capellamicro.com>
5 */
6
7#include <linux/acpi.h>
8#include <linux/delay.h>

--- 426 unchanged lines hidden (view full) ---

435 struct cm32181_chip *cm32181;
436 struct iio_dev *indio_dev;
437 int ret;
438
439 indio_dev = devm_iio_device_alloc(dev, sizeof(*cm32181));
440 if (!indio_dev)
441 return -ENOMEM;
442
443 i2c_set_clientdata(client, indio_dev);
444
443 /*
444 * Some ACPI systems list 2 I2C resources for the CM3218 sensor, the
445 * SMBus Alert Response Address (ARA, 0x0c) and the actual I2C address.
446 * Detect this and take the following step to deal with it:
447 * 1. When a SMBus Alert capable sensor has an Alert asserted, it will
448 * not respond on its actual I2C address. Read a byte from the ARA
449 * to clear any pending Alerts.
450 * 2. Create a "dummy" client for the actual I2C address and

--- 4 unchanged lines hidden (view full) ---

455
456 i2c_smbus_read_byte(client);
457
458 client = i2c_acpi_new_device(dev, 1, &board_info);
459 if (IS_ERR(client))
460 return PTR_ERR(client);
461 }
462
445 /*
446 * Some ACPI systems list 2 I2C resources for the CM3218 sensor, the
447 * SMBus Alert Response Address (ARA, 0x0c) and the actual I2C address.
448 * Detect this and take the following step to deal with it:
449 * 1. When a SMBus Alert capable sensor has an Alert asserted, it will
450 * not respond on its actual I2C address. Read a byte from the ARA
451 * to clear any pending Alerts.
452 * 2. Create a "dummy" client for the actual I2C address and

--- 4 unchanged lines hidden (view full) ---

457
458 i2c_smbus_read_byte(client);
459
460 client = i2c_acpi_new_device(dev, 1, &board_info);
461 if (IS_ERR(client))
462 return PTR_ERR(client);
463 }
464
463 i2c_set_clientdata(client, indio_dev);
464
465 cm32181 = iio_priv(indio_dev);
466 cm32181->client = client;
467 cm32181->dev = dev;
468
469 mutex_init(&cm32181->lock);
470 indio_dev->channels = cm32181_channels;
471 indio_dev->num_channels = ARRAY_SIZE(cm32181_channels);
472 indio_dev->info = &cm32181_info;

--- 12 unchanged lines hidden (view full) ---

485 return ret;
486 }
487
488 return 0;
489}
490
491static int cm32181_suspend(struct device *dev)
492{
465 cm32181 = iio_priv(indio_dev);
466 cm32181->client = client;
467 cm32181->dev = dev;
468
469 mutex_init(&cm32181->lock);
470 indio_dev->channels = cm32181_channels;
471 indio_dev->num_channels = ARRAY_SIZE(cm32181_channels);
472 indio_dev->info = &cm32181_info;

--- 12 unchanged lines hidden (view full) ---

485 return ret;
486 }
487
488 return 0;
489}
490
491static int cm32181_suspend(struct device *dev)
492{
493 struct i2c_client *client = to_i2c_client(dev);
493 struct cm32181_chip *cm32181 = iio_priv(dev_get_drvdata(dev));
494 struct i2c_client *client = cm32181->client;
494
495 return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
496 CM32181_CMD_ALS_DISABLE);
497}
498
499static int cm32181_resume(struct device *dev)
500{
495
496 return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
497 CM32181_CMD_ALS_DISABLE);
498}
499
500static int cm32181_resume(struct device *dev)
501{
501 struct i2c_client *client = to_i2c_client(dev);
502 struct cm32181_chip *cm32181 = iio_priv(dev_get_drvdata(dev));
502 struct cm32181_chip *cm32181 = iio_priv(dev_get_drvdata(dev));
503 struct i2c_client *client = cm32181->client;
503
504 return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
505 cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
506}
507
508static DEFINE_SIMPLE_DEV_PM_OPS(cm32181_pm_ops, cm32181_suspend, cm32181_resume);
509
510static const struct of_device_id cm32181_of_match[] = {

--- 29 unchanged lines hidden ---
504
505 return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
506 cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
507}
508
509static DEFINE_SIMPLE_DEV_PM_OPS(cm32181_pm_ops, cm32181_suspend, cm32181_resume);
510
511static const struct of_device_id cm32181_of_match[] = {

--- 29 unchanged lines hidden ---