mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
d8a66f3621
These drivers don't use the driver_data member of struct i2c_device_id, so don't explicitly initialize this member. This prepares putting driver_data in an anonymous union which requires either no initialization or named designators. But it's also a nice cleanup on its own. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20240430085654.1028864-2-u.kleine-koenig@pengutronix.de Signed-off-by: Guenter Roeck <linux@roeck-us.net>
110 lines
2.3 KiB
C
110 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* ADT7410/ADT7420 digital temperature sensor driver
|
|
*
|
|
* Copyright 2012-2013 Analog Devices Inc.
|
|
* Author: Lars-Peter Clausen <lars@metafoo.de>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/regmap.h>
|
|
|
|
#include "adt7x10.h"
|
|
|
|
static bool adt7410_regmap_is_volatile(struct device *dev, unsigned int reg)
|
|
{
|
|
switch (reg) {
|
|
case ADT7X10_TEMPERATURE:
|
|
case ADT7X10_STATUS:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static int adt7410_reg_read(void *context, unsigned int reg, unsigned int *val)
|
|
{
|
|
struct i2c_client *client = context;
|
|
int regval;
|
|
|
|
switch (reg) {
|
|
case ADT7X10_TEMPERATURE:
|
|
case ADT7X10_T_ALARM_HIGH:
|
|
case ADT7X10_T_ALARM_LOW:
|
|
case ADT7X10_T_CRIT:
|
|
regval = i2c_smbus_read_word_swapped(client, reg);
|
|
break;
|
|
default:
|
|
regval = i2c_smbus_read_byte_data(client, reg);
|
|
break;
|
|
}
|
|
if (regval < 0)
|
|
return regval;
|
|
*val = regval;
|
|
return 0;
|
|
}
|
|
|
|
static int adt7410_reg_write(void *context, unsigned int reg, unsigned int val)
|
|
{
|
|
struct i2c_client *client = context;
|
|
int ret;
|
|
|
|
switch (reg) {
|
|
case ADT7X10_TEMPERATURE:
|
|
case ADT7X10_T_ALARM_HIGH:
|
|
case ADT7X10_T_ALARM_LOW:
|
|
case ADT7X10_T_CRIT:
|
|
ret = i2c_smbus_write_word_swapped(client, reg, val);
|
|
break;
|
|
default:
|
|
ret = i2c_smbus_write_byte_data(client, reg, val);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static const struct regmap_config adt7410_regmap_config = {
|
|
.reg_bits = 8,
|
|
.val_bits = 16,
|
|
.max_register = ADT7X10_ID,
|
|
.cache_type = REGCACHE_MAPLE,
|
|
.volatile_reg = adt7410_regmap_is_volatile,
|
|
.reg_read = adt7410_reg_read,
|
|
.reg_write = adt7410_reg_write,
|
|
};
|
|
|
|
static int adt7410_i2c_probe(struct i2c_client *client)
|
|
{
|
|
struct regmap *regmap;
|
|
|
|
regmap = devm_regmap_init(&client->dev, NULL, client,
|
|
&adt7410_regmap_config);
|
|
if (IS_ERR(regmap))
|
|
return PTR_ERR(regmap);
|
|
|
|
return adt7x10_probe(&client->dev, client->name, client->irq, regmap);
|
|
}
|
|
|
|
static const struct i2c_device_id adt7410_ids[] = {
|
|
{ "adt7410" },
|
|
{ "adt7420" },
|
|
{}
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, adt7410_ids);
|
|
|
|
static struct i2c_driver adt7410_driver = {
|
|
.driver = {
|
|
.name = "adt7410",
|
|
.pm = pm_sleep_ptr(&adt7x10_dev_pm_ops),
|
|
},
|
|
.probe = adt7410_i2c_probe,
|
|
.id_table = adt7410_ids,
|
|
};
|
|
module_i2c_driver(adt7410_driver);
|
|
|
|
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
|
|
MODULE_DESCRIPTION("ADT7410/AD7420 driver");
|
|
MODULE_LICENSE("GPL");
|