From patchwork Tue Sep 3 14:03:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11127985 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 445ED1395 for ; Tue, 3 Sep 2019 14:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B29420870 for ; Tue, 3 Sep 2019 14:03:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o5HOXBEE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729053AbfICODM (ORCPT ); Tue, 3 Sep 2019 10:03:12 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43977 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfICODM (ORCPT ); Tue, 3 Sep 2019 10:03:12 -0400 Received: by mail-pf1-f194.google.com with SMTP id d15so1332551pfo.10 for ; Tue, 03 Sep 2019 07:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=Kw8a8bqj3P9Hh0PHeKKY0r+G2TwLACh/CwOupCuF5IY=; b=o5HOXBEEzNX07vFS5UYTGTQEojOzrgEDgCIdSJTxgDZn3JyYM6mG9DlNUCcHt8Tgq8 jXNRYuXeZrMBDuamL5cH2x6r84IQZDe1d/tsOA0To3O9/yk4kvpVPgZaD6vPyoVw1B08 iA96iJt72BN0Ddfbc6cAy6J0qZO6vUFAU0tAObekZeR1RRiMCEeVm0Yf6InD6lMbT/3+ /1yoC8IbJekxKLtxS9tOrWuFDSACi4/BWiVTuyMVJ9lyDVMs0hQesBTkVvWJ21EVc/GD 2VtrF4lhv/9xnezNW3k5B6GmMG1mv9tggkWs0HJ+ULtspfVYWSkznEBm/bPXP7iRG+dd c1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=Kw8a8bqj3P9Hh0PHeKKY0r+G2TwLACh/CwOupCuF5IY=; b=PZpkgHZj3NHas3WkXgbYtKePwg+GLJUr87gMK9DYTP1lPiLD3dx7jgXw8117QM+gle bdaTGfip3q4XdOP1jUylaSutaVdscuZ5ufK3pHyGi9OxuoEs7fJyQ+BdXuTj6sQMDswB nmiabLfAhXSkhYut9H0NFiqnWOII1eAj5lPJ+QRpQzr/qvtTBEzgYE3mKG5wkmabTOFz 5smo69Ba5R7w9qiWNgBskzIz1WMuIvrRhvOICoO8avd38cCH1uQnw0+nF6bjPoXA3FMO 4Y8ehyZMlxlLb5e6jwiokBdui0A+Cb+IVzXnhXYLZyiYBLjHddCagHDW8aj4ggcAiKFa h/vg== X-Gm-Message-State: APjAAAWU6GzvY4jK9Cxk/vOBKpAn7YHLgHYrdT/gVllgnhGBll9fsV2u 8ZsRvKZE8OteTb6vrnG2mgZCFvWt X-Google-Smtp-Source: APXvYqxha8kZWzny3uGB5bmMXxcch4FEz4ENVoehKSm957Dzs03WIBxnDq5AjACRv9b+wCNdPPgDMg== X-Received: by 2002:a17:90a:350:: with SMTP id 16mr177081pjf.110.1567519391292; Tue, 03 Sep 2019 07:03:11 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id n10sm17133829pgv.67.2019.09.03.07.03.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Sep 2019 07:03:10 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Iker Perez del Palomar , Guenter Roeck Subject: [PATCH 1/4] hwmon: (lm75) Support configuring the sample time for various chips Date: Tue, 3 Sep 2019 07:03:06 -0700 Message-Id: <1567519389-16561-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The conversion (sample) time is configurable for several chips supported by the lm75 driver. With the necessary infrastructure in place, enable this support for all chips using the configuration register for this purpose. DS1775: Conversion time: 187.5, 375, 750, 1500 ms Sensor resolution: 9, 10, 11, 12 bit DS75, STDS75: Conversion time: 150, 300, 600, 1200 ms Sensor resolution: 9, 10, 11, 12 bit DS7505: Conversion time: 25, 50, 100, 200 ms Sensor resolution: 9, 10, 11, 12 bit MCP980[0123]: Conversion time: 75, 150, 300, 600 ms Sensor resolution: 9, 10, 11, 12 bit TMP100, TMP101: Conversion time: 75, 150, 300, 600 ms Sensor resolution: 9, 10, 11, 12 bit TMP75, TMP105, TMP175, TMP275: Conversion time: 38, 75, 150, 300 ms Sensor resolution: 9, 10, 11, 12 bit While doing this, it became obvious that the masks and values to set the converion (sample) time is similar for all those chips, and that other chips with configurable sample times will need separate code anyway. For that reason, replace the sample_set_masks and sample_clr_mask configuration parameters with a single array and with a constant. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm75.c | 83 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index f68ef9d451ab..6474b8f21981 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -73,10 +73,6 @@ enum lm75_type { /* keep sorted in alphabetical order */ * @sample_times: All the possible sample times to be set. Mandatory if * num_sample_times is larger than 1. If set, number of * entries must match num_sample_times. - * @sample_set_masks: All the set_masks for the possible sample times. - * Mandatory if num_sample_times is larger than 1. - * If set, number of entries must match num_sample_times. - * @sample_clr_mask: Clear mask used to set the sample time. */ struct lm75_params { @@ -88,8 +84,6 @@ struct lm75_params { unsigned int default_sample_time; u8 num_sample_times; const unsigned int *sample_times; - const u8 *sample_set_masks; - u8 sample_clr_mask; }; /* Addresses scanned */ @@ -115,6 +109,11 @@ struct lm75_data { }; /*-----------------------------------------------------------------------*/ + +static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 }; + +#define LM75_SAMPLE_CLEAR_MASK (3 << 5) + /* The structure below stores the configuration values of the supported devices. * In case of being supported multiple configurations, the default one must * always be the first element of the array @@ -129,19 +128,28 @@ static const struct lm75_params device_params[] = { .clr_mask = 3 << 5, .set_mask = 2 << 5, /* 11-bit mode */ .default_resolution = 11, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 750, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 188, 375, 750, 1500 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [ds75] = { .clr_mask = 3 << 5, .set_mask = 2 << 5, /* 11-bit mode */ .default_resolution = 11, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 600, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 150, 300, 600, 1200 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [stds75] = { .clr_mask = 3 << 5, .set_mask = 2 << 5, /* 11-bit mode */ .default_resolution = 11, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 600, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 150, 300, 600, 1200 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [stlm75] = { .default_resolution = 9, @@ -150,7 +158,10 @@ static const struct lm75_params device_params[] = { [ds7505] = { .set_mask = 3 << 5, /* 12-bit mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 4, + .default_sample_time = 200, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 25, 50, 100, 200 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [g751] = { .default_resolution = 9, @@ -194,56 +205,74 @@ static const struct lm75_params device_params[] = { .clr_mask = 1 << 7, /* not one-shot mode */ .default_resolution = 12, .resolution_limits = 9, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 240, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 75, 150, 300, 600 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp100] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode */ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 320, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 75, 150, 300, 600 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp101] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode */ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 320, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 75, 150, 300, 600 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, - [tmp112] = { + [tmp105] = { .set_mask = 3 << 5, /* 12-bit mode */ - .clr_mask = 1 << 7, /* no one-shot mode*/ + .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 4, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, - [tmp105] = { + [tmp112] = { .set_mask = 3 << 5, /* 12-bit mode */ - .clr_mask = 1 << 7, /* not one-shot mode*/ + .clr_mask = 1 << 7, /* no one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = MSEC_PER_SEC / 4, }, [tmp175] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp275] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp75] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp75b] = { /* not one-shot mode, Conversion rate 37Hz */ .clr_mask = 1 << 7 | 3 << 5, .default_resolution = 12, - .sample_set_masks = (u8 []){ 0 << 5, 1 << 5, 2 << 5, - 3 << 5 }, - .sample_clr_mask = 3 << 5, .default_sample_time = MSEC_PER_SEC / 37, .sample_times = (unsigned int []){ MSEC_PER_SEC / 37, MSEC_PER_SEC / 18, @@ -371,8 +400,8 @@ static int lm75_write_chip(struct device *dev, u32 attr, long val) (int)data->params->num_sample_times); err = lm75_write_config(data, - data->params->sample_set_masks[index], - data->params->sample_clr_mask); + lm75_sample_set_masks[index], + LM75_SAMPLE_CLEAR_MASK); if (err) return err; data->sample_time = data->params->sample_times[index]; From patchwork Tue Sep 3 14:03:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11127987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FE921399 for ; Tue, 3 Sep 2019 14:03:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 002C123717 for ; Tue, 3 Sep 2019 14:03:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tk/B50Gw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725782AbfICODN (ORCPT ); Tue, 3 Sep 2019 10:03:13 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43032 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729113AbfICODN (ORCPT ); Tue, 3 Sep 2019 10:03:13 -0400 Received: by mail-pl1-f193.google.com with SMTP id 4so7927401pld.10 for ; Tue, 03 Sep 2019 07:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=OTt2H0rWEepZWJ5NJvH+YQ+TpMzB2d+id5Jx+TVKStE=; b=Tk/B50Gw29TuWEboKHm0AFXvia/BEhqOLoIh2P5fQtYClGSZUiAFHAaVTCfZXTpO1f Abg0m5LBCDtew0i+XMHn9IHFBHyOe1pEJZSyu+Yp26dQXsLq9FmKV3qCJLnqh7f7wItj U1Cy3YWxNcxjKP0lh8TCAT5661gyQn/iJk0258zQnswSzAgwsNX/qNFMRIPTitiL2r8K JOKkw5kj34/5A5kU/4rq9A9JlWSbfT7BKylKjO1+Q+ETKTj/7D4XIrODGchDIB8QCaaD Muk1gtSWUoqzg6qht25KUqRxG5+NOKSfJKBa7lH1x/xg7yLOpCW/r41N1WNeC1JHQA6g NbSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=OTt2H0rWEepZWJ5NJvH+YQ+TpMzB2d+id5Jx+TVKStE=; b=WvO8StctN0kCI963bYEJu3PuEuvxOZRdL+Yc1qMF7MAB+EOUINrULlcdHMkchpx4E0 pFfY3zIwL0GlYXR6bXY94M4QdIuYmC+66wLMTEjtnCxo1Yd2IRoQ2J8TZMYYNlkIM11W UTGgVAwCWUFj3Fvz7oqbfDOWqGGpveXWPvQBPeg6XTQ/xHY9osdDsB0o1tpOeDH5jZDm fFdFwk1EhF26/GVmqkfj3NRVYXl1mrIg5SZKsmrXRbm3xB+k4RTZ+aanDdul4+/XUzBx +01v2V/kiRVjyYUcMMSkKhwvSzQtjJ0aM54NoLMavDoY9s25W85TceO/q0KlSKVBm8jD JcnQ== X-Gm-Message-State: APjAAAUsZTu7Mo4ag5D86Aqf66snhpMqDz1TsRljIGZJFNN0hKKERWI+ RCSki7dbH9Yy21V+gEEyfho2jgyS X-Google-Smtp-Source: APXvYqyeVbgGk1G4F6BzLu6eXIvnwZb4hLNkEwo6mJEYIdJ0GaY6O833eyB36ro+OGLvHdd1zAqjcA== X-Received: by 2002:a17:902:7b97:: with SMTP id w23mr35536808pll.283.1567519392659; Tue, 03 Sep 2019 07:03:12 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id s5sm19724379pfm.97.2019.09.03.07.03.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Sep 2019 07:03:12 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Iker Perez del Palomar , Guenter Roeck Subject: [PATCH 2/4] hwmon: (lm75) Move updating the sample interval to its own function Date: Tue, 3 Sep 2019 07:03:07 -0700 Message-Id: <1567519389-16561-2-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1567519389-16561-1-git-send-email-linux@roeck-us.net> References: <1567519389-16561-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org We'll need per-chip handling for updating the sample interval. To prepare for it, separate the code implementing it into its own function. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm75.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 6474b8f21981..644da2620a26 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -388,27 +388,32 @@ static int lm75_write_temp(struct device *dev, u32 attr, long temp) return regmap_write(data->regmap, reg, (u16)temp); } -static int lm75_write_chip(struct device *dev, u32 attr, long val) +static int lm75_update_interval(struct device *dev, long val) { struct lm75_data *data = dev_get_drvdata(dev); u8 index; s32 err; - switch (attr) { - case hwmon_chip_update_interval: - index = find_closest(val, data->params->sample_times, - (int)data->params->num_sample_times); + index = find_closest(val, data->params->sample_times, + (int)data->params->num_sample_times); - err = lm75_write_config(data, - lm75_sample_set_masks[index], - LM75_SAMPLE_CLEAR_MASK); - if (err) - return err; - data->sample_time = data->params->sample_times[index]; + err = lm75_write_config(data, lm75_sample_set_masks[index], + LM75_SAMPLE_CLEAR_MASK); + if (err) + return err; - if (data->params->resolutions) - data->resolution = data->params->resolutions[index]; - break; + data->sample_time = data->params->sample_times[index]; + if (data->params->resolutions) + data->resolution = data->params->resolutions[index]; + + return 0; +} + +static int lm75_write_chip(struct device *dev, u32 attr, long val) +{ + switch (attr) { + case hwmon_chip_update_interval: + return lm75_update_interval(dev, val); default: return -EINVAL; } From patchwork Tue Sep 3 14:03:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11127989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 234141395 for ; Tue, 3 Sep 2019 14:03:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 035552341F for ; Tue, 3 Sep 2019 14:03:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q5DAemor" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729117AbfICODP (ORCPT ); Tue, 3 Sep 2019 10:03:15 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35261 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729113AbfICODP (ORCPT ); Tue, 3 Sep 2019 10:03:15 -0400 Received: by mail-pf1-f195.google.com with SMTP id 205so8393309pfw.2 for ; Tue, 03 Sep 2019 07:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3dSfSHVGieE7IvASZ3V/n6QYdtNVeR4Co4wZeStVBu8=; b=Q5DAemor5r6nk9bbIFFZaVb+i+i+zy9FPHxQQcbz8FWkdHzVa+ON/ddIaEpoXYpPaa kl5HQa1wKNgJzKpe6Qw+JJZpRItPN3z+bivlNLL3XTWmKQ8/btVfo2e1fOZyVUBgyQMA 3w2r1nn54E0ALlqjM6hhMwzqvYcxj5s+XTbdPQ7PNEIzT2+i7cnsLBjrVaPnEMHhlyCF h9vIyDyvpmeRhjJxr3sOgWalWLfohYTV/DxG+t247cwrMjz7RwLvEv2EZ/mwR2kDKWzd sP3sEqHEd8E2J0y6hWfMMKxNq9iPUK7aCptb70JCe2z7uzP2yljoAx10gTSLlWh4gLpy ciGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=3dSfSHVGieE7IvASZ3V/n6QYdtNVeR4Co4wZeStVBu8=; b=npEyziCB17DvygKFB6xWXcQMObb0+lbydDFX85QFx9WCqueDDbGwVZNkca1f+IgnVE KJD7f2vPQI8OIMOW1XWn8uPkzkoGMyz9e9q3Q3n0e3okBBA6nRGgJCg/cPuGdbFnyWid lBebZfFRW2RnRByWeMbWa3P61Wo4kLP3UoUxOVITbK6mFNz+UrxGapXB5yZPd+9C3rSO lQQ6TARjs3Vl5mgjIuOskzr+Tiay3J/icfB4xAqJqTr+N+0tXKjIxHjH0wcvfz4YXlyS GODMhDmvaZhK4RHoaXFcYd75GDK2qej08U79+CJ6yAV7GuxJg97jhdkdZcYbhkJCo659 c6mw== X-Gm-Message-State: APjAAAXxNu7QRivbRdksNUxs/SJsQ3GyDFqrFM5g5E5GErkErBZ+/aSG bqAAAF07wmrzTtdj64MGUo7KtpwP X-Google-Smtp-Source: APXvYqxoC7tmV6O7tCU3GYqQH5Ek8YX3stcKcJfELCUqGgcQE3R32YjF82xJ6DNffTNOWRGSXuY0Lg== X-Received: by 2002:a65:62d7:: with SMTP id m23mr30387539pgv.358.1567519394325; Tue, 03 Sep 2019 07:03:14 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id q71sm5819742pjb.26.2019.09.03.07.03.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Sep 2019 07:03:13 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Iker Perez del Palomar , Guenter Roeck Subject: [PATCH 3/4] hwmon: (lm75) Add support for writing conversion time for TMP112 Date: Tue, 3 Sep 2019 07:03:08 -0700 Message-Id: <1567519389-16561-3-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1567519389-16561-1-git-send-email-linux@roeck-us.net> References: <1567519389-16561-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org TMP112 uses an uncommon method to write the conversion time: its configuration register is 16 bit wide, and the conversion time is configured in its second byte. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm75.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 644da2620a26..ce0f6c671b8f 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -242,6 +242,8 @@ static const struct lm75_params device_params[] = { .clr_mask = 1 << 7, /* no one-shot mode*/ .default_resolution = 12, .default_sample_time = MSEC_PER_SEC / 4, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 125, 250, 1000, 4000 }, }, [tmp175] = { .set_mask = 3 << 5, /* 12-bit mode */ @@ -391,21 +393,36 @@ static int lm75_write_temp(struct device *dev, u32 attr, long temp) static int lm75_update_interval(struct device *dev, long val) { struct lm75_data *data = dev_get_drvdata(dev); + unsigned int reg; u8 index; s32 err; index = find_closest(val, data->params->sample_times, (int)data->params->num_sample_times); - err = lm75_write_config(data, lm75_sample_set_masks[index], - LM75_SAMPLE_CLEAR_MASK); - if (err) - return err; - - data->sample_time = data->params->sample_times[index]; - if (data->params->resolutions) - data->resolution = data->params->resolutions[index]; + switch (data->kind) { + default: + err = lm75_write_config(data, lm75_sample_set_masks[index], + LM75_SAMPLE_CLEAR_MASK); + if (err) + return err; + data->sample_time = data->params->sample_times[index]; + if (data->params->resolutions) + data->resolution = data->params->resolutions[index]; + break; + case tmp112: + err = regmap_read(data->regmap, LM75_REG_CONF, ®); + if (err < 0) + return err; + reg &= ~0x00c0; + reg |= (3 - index) << 6; + err = regmap_write(data->regmap, LM75_REG_CONF, reg); + if (err < 0) + return err; + data->sample_time = data->params->sample_times[index]; + break; + } return 0; } @@ -489,7 +506,7 @@ static bool lm75_is_writeable_reg(struct device *dev, unsigned int reg) static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg) { - return reg == LM75_REG_TEMP; + return reg == LM75_REG_TEMP || reg == LM75_REG_CONF; } static const struct regmap_config lm75_regmap_config = { From patchwork Tue Sep 3 14:03:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11127991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20ED21395 for ; Tue, 3 Sep 2019 14:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0082820870 for ; Tue, 3 Sep 2019 14:03:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XM0NVVId" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729137AbfICODQ (ORCPT ); Tue, 3 Sep 2019 10:03:16 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35690 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbfICODQ (ORCPT ); Tue, 3 Sep 2019 10:03:16 -0400 Received: by mail-pl1-f195.google.com with SMTP id gn20so7933579plb.2 for ; Tue, 03 Sep 2019 07:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=lpZLE/DpkVnus3lIpDgoILHMRUCogKYwMdezVU0Vw9M=; b=XM0NVVIdBcg9bLKk4i+L4+7RkwtB8JYSyqarBScyNVZsyOiiKpGOcAlraGuplhMX0j JoEz8bUpnt4Hhd1wGNYClUK7A/tGiK7W/GMtSMpPzGIPTMpSbGQb5D64ZtyhIhza46Bh 98EpyTUxIVnObClM6ZRTqe+fRrkLmZ3Q2sLTYF91v9ExDgxbGXxIIQhiHyqapvl9OGcB u3dLmdghUeuGwUTscKvQXmoaxAhmMALchLt/53CBJM6mAXT830UAGNm1SeET4KQClUsd 0DwvePR+7B6WnPnq83p6cRFFV5UjzZOxORqaYwLnFPtBYE0/cZL/44SEJR4kbbNJBY7y DT6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=lpZLE/DpkVnus3lIpDgoILHMRUCogKYwMdezVU0Vw9M=; b=UaeoOKBF5Mz+YvwveKA90EImMiVjVzVfE+59Pf8jHpVhV+etN1ILSbA+qvIc9AyWLp lIx5cgNbuk2KVthcIJYFrKf0tPUi5al5SoOeB06rU7h2P8e9BGc2Ku7QsF3ml10ga8l7 klua/IzV5I3Ivifb87AENHWYBUggjHIdngB8ORu03s0unSf8D8Hb6X2cNyFOGQ2JQTaI 5GWopei6HO6/kGmF++bOWfdndoY62J/dsndFPaWJF04boUYyZNNQM/GbpJGG77ukJJZC qMZwrSmcbL/9rmpUhBl7rcDQXnBqV6tIDejdp4A9kxm5+g0umv5mB8XSj9z13GEB5tPj wHNA== X-Gm-Message-State: APjAAAXhETSHQ0UPPn/ayyj+D9wnr157j68Jl1Kjvr18i676hS6ADnzn OLs9CKh8Rr8FH31vWug87jJS6CcZ X-Google-Smtp-Source: APXvYqwTmKQr2KSG1E3zHK4BgfXgiZovTszQFSCbrQbTfGbYg92yV2cy7XL4WQcXxMIDNbZGT29F5A== X-Received: by 2002:a17:902:7c91:: with SMTP id y17mr17124146pll.46.1567519395811; Tue, 03 Sep 2019 07:03:15 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j1sm16508730pgl.12.2019.09.03.07.03.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Sep 2019 07:03:15 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Iker Perez del Palomar , Guenter Roeck Subject: [PATCH 4/4] hwmon: (lm75) Add support for writing sampling period on PCT2075 Date: Tue, 3 Sep 2019 07:03:09 -0700 Message-Id: <1567519389-16561-4-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1567519389-16561-1-git-send-email-linux@roeck-us.net> References: <1567519389-16561-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org For PCT7027, the sampling period is configured using a dedicated register. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm75.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index ce0f6c671b8f..d45e5cc4adf5 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -95,6 +95,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, #define LM75_REG_CONF 0x01 #define LM75_REG_HYST 0x02 #define LM75_REG_MAX 0x03 +#define PCT2075_REG_IDLE 0x04 /* Each client has this additional data */ struct lm75_data { @@ -199,6 +200,11 @@ static const struct lm75_params device_params[] = { [pct2075] = { .default_resolution = 11, .default_sample_time = MSEC_PER_SEC / 10, + .num_sample_times = 31, + .sample_times = (unsigned int []){ 100, 200, 300, 400, 500, 600, + 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, + 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, + 2800, 2900, 3000, 3100 }, }, [mcp980x] = { .set_mask = 3 << 5, /* 12-bit mode */ @@ -422,6 +428,13 @@ static int lm75_update_interval(struct device *dev, long val) return err; data->sample_time = data->params->sample_times[index]; break; + case pct2075: + err = i2c_smbus_write_byte_data(data->client, PCT2075_REG_IDLE, + index + 1); + if (err) + return err; + data->sample_time = data->params->sample_times[index]; + break; } return 0; } @@ -512,7 +525,7 @@ static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg) static const struct regmap_config lm75_regmap_config = { .reg_bits = 8, .val_bits = 16, - .max_register = LM75_REG_MAX, + .max_register = PCT2075_REG_IDLE, .writeable_reg = lm75_is_writeable_reg, .volatile_reg = lm75_is_volatile_reg, .val_format_endian = REGMAP_ENDIAN_BIG,