| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 694f9bfb8efaef8a33e8992015ff9d0866faf4a2 Mon Sep 17 00:00:00 2001 |
| 2 | From: Christian Lamparter <chunkeey@gmail.com> |
| 3 | Date: Sun, 17 Dec 2017 17:27:15 +0100 |
| 4 | Subject: [PATCH 1/2] hwmon: tc654 add detection routine |
| 5 | |
| 6 | This patch adds a detection routine for the TC654/TC655 |
| 7 | chips. Both IDs are listed in the Datasheet. |
| 8 | |
| 9 | Signed-off-by: Christian Lamparter <chunkeey@gmail.com> |
| 10 | --- |
| 11 | drivers/hwmon/tc654.c | 29 +++++++++++++++++++++++++++++ |
| 12 | 1 file changed, 29 insertions(+) |
| 13 | |
| 14 | --- a/drivers/hwmon/tc654.c |
| 15 | +++ b/drivers/hwmon/tc654.c |
| 16 | @@ -55,6 +55,11 @@ enum tc654_regs { |
| 17 | /* Register data is read (and cached) at most once per second. */ |
| 18 | #define TC654_UPDATE_INTERVAL HZ |
| 19 | |
| 20 | +/* Manufacturer and Version Identification Register Values */ |
| 21 | +#define TC654_MFR_ID_MICROCHIP 0x84 |
| 22 | +#define TC654_VER_ID 0x00 |
| 23 | +#define TC655_VER_ID 0x01 |
| 24 | + |
| 25 | struct tc654_data { |
| 26 | struct i2c_client *client; |
| 27 | |
| 28 | @@ -482,6 +487,29 @@ static const struct i2c_device_id tc654_ |
| 29 | {} |
| 30 | }; |
| 31 | |
| 32 | +static int |
| 33 | +tc654_detect(struct i2c_client *new_client, struct i2c_board_info *info) |
| 34 | +{ |
| 35 | + struct i2c_adapter *adapter = new_client->adapter; |
| 36 | + int manufacturer, product; |
| 37 | + |
| 38 | + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 39 | + return -ENODEV; |
| 40 | + |
| 41 | + manufacturer = i2c_smbus_read_byte_data(new_client, TC654_REG_MFR_ID); |
| 42 | + if (manufacturer != TC654_MFR_ID_MICROCHIP) |
| 43 | + return -ENODEV; |
| 44 | + |
| 45 | + product = i2c_smbus_read_byte_data(new_client, TC654_REG_VER_ID); |
| 46 | + if (!((product == TC654_VER_ID) || (product == TC655_VER_ID))) |
| 47 | + return -ENODEV; |
| 48 | + |
| 49 | + strlcpy(info->type, product == TC654_VER_ID ? "tc654" : "tc655", |
| 50 | + I2C_NAME_SIZE); |
| 51 | + return 0; |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | MODULE_DEVICE_TABLE(i2c, tc654_id); |
| 56 | |
| 57 | static struct i2c_driver tc654_driver = { |
| 58 | @@ -490,6 +518,7 @@ static struct i2c_driver tc654_driver = |
| 59 | }, |
| 60 | .probe = tc654_probe, |
| 61 | .id_table = tc654_id, |
| 62 | + .detect = tc654_detect, |
| 63 | }; |
| 64 | |
| 65 | module_i2c_driver(tc654_driver); |