--- zzzz-none-000/linux-3.10.107/drivers/hwmon/tmp421.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/tmp421.c 2021-02-04 17:41:59.000000000 +0000 @@ -13,15 +13,11 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Driver for the Texas Instruments TMP421 SMBus temperature sensor IC. - * Supported models: TMP421, TMP422, TMP423 + * Supported models: TMP421, TMP422, TMP423, TMP441, TMP442 */ #include @@ -39,9 +35,10 @@ static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; -enum chips { tmp421, tmp422, tmp423 }; +enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 }; /* The TMP421 registers */ +#define TMP421_STATUS_REG 0x08 #define TMP421_CONFIG_REG_1 0x09 #define TMP421_CONVERSION_RATE_REG 0x0B #define TMP421_MANUFACTURER_ID_REG 0xFE @@ -59,17 +56,21 @@ #define TMP421_DEVICE_ID 0x21 #define TMP422_DEVICE_ID 0x22 #define TMP423_DEVICE_ID 0x23 +#define TMP441_DEVICE_ID 0x41 +#define TMP442_DEVICE_ID 0x42 static const struct i2c_device_id tmp421_id[] = { { "tmp421", 2 }, { "tmp422", 3 }, { "tmp423", 4 }, + { "tmp441", 2 }, + { "tmp442", 3 }, { } }; MODULE_DEVICE_TABLE(i2c, tmp421_id); struct tmp421_data { - struct device *hwmon_dev; + struct i2c_client *client; struct mutex update_lock; char valid; unsigned long last_updated; @@ -99,8 +100,8 @@ static struct tmp421_data *tmp421_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct tmp421_data *data = i2c_get_clientdata(client); + struct tmp421_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int i; mutex_lock(&data->update_lock); @@ -198,6 +199,11 @@ .is_visible = tmp421_is_visible, }; +static const struct attribute_group *tmp421_groups[] = { + &tmp421_group, + NULL +}; + static int tmp421_init_client(struct i2c_client *client) { int config, config_orig; @@ -210,7 +216,7 @@ if (config < 0) { dev_err(&client->dev, "Could not read configuration register (%d)\n", config); - return -ENODEV; + return config; } config_orig = config; @@ -229,7 +235,9 @@ { enum chips kind; struct i2c_adapter *adapter = client->adapter; - const char *names[] = { "TMP421", "TMP422", "TMP423" }; + const char * const names[] = { "TMP421", "TMP422", "TMP423", + "TMP441", "TMP442" }; + int addr = client->addr; u8 reg; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) @@ -239,17 +247,37 @@ if (reg != TMP421_MANUFACTURER_ID) return -ENODEV; + reg = i2c_smbus_read_byte_data(client, TMP421_CONVERSION_RATE_REG); + if (reg & 0xf8) + return -ENODEV; + + reg = i2c_smbus_read_byte_data(client, TMP421_STATUS_REG); + if (reg & 0x7f) + return -ENODEV; + reg = i2c_smbus_read_byte_data(client, TMP421_DEVICE_ID_REG); switch (reg) { case TMP421_DEVICE_ID: kind = tmp421; break; case TMP422_DEVICE_ID: + if (addr == 0x2a) + return -ENODEV; kind = tmp422; break; case TMP423_DEVICE_ID: + if (addr != 0x4c && addr != 0x4d) + return -ENODEV; kind = tmp423; break; + case TMP441_DEVICE_ID: + kind = tmp441; + break; + case TMP442_DEVICE_ID: + if (addr != 0x4c && addr != 0x4d) + return -ENODEV; + kind = tmp442; + break; default: return -ENODEV; } @@ -264,47 +292,26 @@ static int tmp421_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; + struct device *hwmon_dev; struct tmp421_data *data; int err; - data = devm_kzalloc(&client->dev, sizeof(struct tmp421_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct tmp421_data), GFP_KERNEL); if (!data) return -ENOMEM; - i2c_set_clientdata(client, data); mutex_init(&data->update_lock); data->channels = id->driver_data; + data->client = client; err = tmp421_init_client(client); if (err) return err; - err = sysfs_create_group(&client->dev.kobj, &tmp421_group); - if (err) - return err; - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - data->hwmon_dev = NULL; - goto exit_remove; - } - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &tmp421_group); - return err; -} - -static int tmp421_remove(struct i2c_client *client) -{ - struct tmp421_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &tmp421_group); - - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, tmp421_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } static struct i2c_driver tmp421_driver = { @@ -313,7 +320,6 @@ .name = "tmp421", }, .probe = tmp421_probe, - .remove = tmp421_remove, .id_table = tmp421_id, .detect = tmp421_detect, .address_list = normal_i2c, @@ -322,5 +328,5 @@ module_i2c_driver(tmp421_driver); MODULE_AUTHOR("Andre Prendel "); -MODULE_DESCRIPTION("Texas Instruments TMP421/422/423 temperature sensor driver"); +MODULE_DESCRIPTION("Texas Instruments TMP421/422/423/441/442 temperature sensor driver"); MODULE_LICENSE("GPL");