From patchwork Tue Aug 16 11:07:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Cestonaro X-Patchwork-Id: 9283589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A0BE60839 for ; Tue, 16 Aug 2016 11:12:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59FAA286EC for ; Tue, 16 Aug 2016 11:12:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EC08286F0; Tue, 16 Aug 2016 11:12:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 097E728700 for ; Tue, 16 Aug 2016 11:11:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753422AbcHPLLs (ORCPT ); Tue, 16 Aug 2016 07:11:48 -0400 Received: from mail1.bemta3.messagelabs.com ([195.245.230.164]:34994 "EHLO mail1.bemta3.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753182AbcHPLLr (ORCPT ); Tue, 16 Aug 2016 07:11:47 -0400 Received: from [195.245.230.51] by server-4.bemta-3.messagelabs.com id 6A/A9-15788-9E4F2B75; Tue, 16 Aug 2016 11:11:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRWlGSWpSXmKPExsViZ8MxRffll03 hBgskLdpfb2V0YPT4vEkugDGKNTMvKb8igTVjcod/wTnRiuub5jI3MG4S6mLk5BASOMYo8fxY BITdzSjx4YB/FyMHB5uAmcS39YUgYREBeYm+VT2MIDazgJrEgscH2EBsYQFviZltk9lBbBYBV Ym3DdNZQWxeAT+Js7OeM4HYEgJyEpenP2CbwMi5gJFhFaNGcWpRWWqRrpGxXlJRZnpGSW5iZo 6uoYGxXm5qcXFiempOYlKxXnJ+7iZGoJfqGRgYdzD27fU7xCjJwaQkyjtz4sZwIb6k/JTKjMT ijPii0pzU4kOMMhwcShK8qz5vChcSLEpNT61Iy8wBhgtMWoKDR0mElxkYMkK8xQWJucWZ6RCp U4zGHEt2PVjLxHEBRAqx5OXnpUqJ824AmSQAUppRmgc3CBbGlxhlpYR5GRkYGIR4ClKLcjNLU OVfMYpzMCoJ854AmcKTmVcCt+8V0ClMQKfoS28AOaUkESEl1cBYqsV+u77rY8rd+rY++5bqu/ Nv37weJuSj/s5k44NXGvXih2PV3LpY7b+cOO64SEGic9bpla8qxGUXX48/9nrV7y/vqxhaLmo sy+ladHLuwaPbTxYJh17bE7xy7grJ3ZNnHxCsUJvR7tKuaCOmt3ZTZe6p4q9ap6+9dvh5p+K+ XD3/YoftCvEXlFiKMxINtZiLihMBrOO6ZF4CAAA= X-Env-Sender: thilo.cestonaro@ts.fujitsu.com X-Msg-Ref: server-2.tower-33.messagelabs.com!1471345893!12748381!1 X-Originating-IP: [62.60.8.148] X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7692 invoked from network); 16 Aug 2016 11:11:33 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-2.tower-33.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Aug 2016 11:11:33 -0000 Received: from abgdgate60u.abg.fsc.net ([172.25.138.90]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with ESMTP id u7GBC6Co002874 for ; Tue, 16 Aug 2016 12:12:22 +0100 Received: from unknown (HELO abg4858n-lnx.CSOD.local) ([10.172.228.10]) by abgdgate60u.abg.fsc.net with ESMTP; 16 Aug 2016 13:11:17 +0200 From: Thilo Cestonaro To: linux-hwmon@vger.kernel.org Cc: Thilo Cestonaro Subject: [PATCH] hwmon: add i2c detect functionality to fts teutates driver Date: Tue, 16 Aug 2016 13:07:53 +0200 Message-Id: <1471345673-17729-1-git-send-email-thilo.cestonaro@ts.fujitsu.com> X-Mailer: git-send-email 2.8.1 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thilo Cestonaro Signed-off-by: Thilo Cestonaro --- drivers/hwmon/ftsteutates.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index 48633e5..0f0277e 100644 --- a/drivers/hwmon/ftsteutates.c +++ b/drivers/hwmon/ftsteutates.c @@ -36,6 +36,10 @@ #define FTS_EVENT_STATUS_REG 0x0006 #define FTS_GLOBAL_CONTROL_REG 0x0007 +#define FTS_DEVICE_DETECT_REG_1 0x0C +#define FTS_DEVICE_DETECT_REG_2 0x0D +#define FTS_DEVICE_DETECT_REG_3 0x0E + #define FTS_SENSOR_EVENT_REG 0x0010 #define FTS_FAN_EVENT_REG 0x0014 @@ -54,6 +58,8 @@ #define FTS_NO_TEMP_SENSORS 0x10 #define FTS_NO_VOLT_SENSORS 0x04 +static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; + static struct i2c_device_id fts_id[] = { { "ftsteutates", 0 }, { } @@ -734,6 +740,42 @@ static const struct attribute_group *fts_attr_groups[] = { /*****************************************************************************/ /* Module initialization / remove functions */ /*****************************************************************************/ +static int fts_detect(struct i2c_client *client, + struct i2c_board_info *info) +{ + int val; + + /* detection works with revsion greater or equal to 0x2b */ + val = i2c_smbus_read_byte_data(client, FTS_DEVICE_REVISION_REG); + if (val < 0x2b) + return -ENODEV; + + /* Device Detect Regs must have 0x17 0x34 and 0x54 */ + val = i2c_smbus_read_byte_data(client, FTS_DEVICE_DETECT_REG_1); + if (val != 0x17) + return -ENODEV; + + val = i2c_smbus_read_byte_data(client, FTS_DEVICE_DETECT_REG_2); + if (val != 0x34) + return -ENODEV; + + val = i2c_smbus_read_byte_data(client, FTS_DEVICE_DETECT_REG_3); + if (val != 0x54) + return -ENODEV; + + /* + * 0x10 == Baseboard Management Controller, 0x01 == Teutates + * Device ID Reg needs to be 0x11 + */ + val = i2c_smbus_read_byte_data(client, FTS_DEVICE_ID_REG); + if (val != 0x11) + return -ENODEV; + + strlcpy(info->type, fts_id[0].name, I2C_NAME_SIZE); + info->flags = 0; + return 0; +} + static int fts_remove(struct i2c_client *client) { struct fts_data *data = dev_get_drvdata(&client->dev); @@ -804,12 +846,15 @@ static int fts_probe(struct i2c_client *client, const struct i2c_device_id *id) /* Module Details */ /*****************************************************************************/ static struct i2c_driver fts_driver = { + .class = I2C_CLASS_HWMON, .driver = { .name = "ftsteutates", }, .id_table = fts_id, .probe = fts_probe, .remove = fts_remove, + .detect = fts_detect, + .address_list = normal_i2c, }; module_i2c_driver(fts_driver);