From patchwork Wed Jul 13 19:23:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 648026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rqTNh2g17z9s8d for ; Thu, 14 Jul 2016 05:27:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.b=X04B16H9; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNPlO-0000Wn-J9; Wed, 13 Jul 2016 19:24:06 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNPlE-0000MQ-8e for lede-dev@lists.infradead.org; Wed, 13 Jul 2016 19:24:04 +0000 Received: by mail-wm0-x243.google.com with SMTP id i5so6960897wmg.2 for ; Wed, 13 Jul 2016 12:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=N1urvO5XP9mfnhkCMAnUeWe06eh09JbAm/JqvEFANYo=; b=X04B16H9cbfsrxnqYLIgQWnRwn+hk5ahKkcX4rtLrXVB4/iYw6lUCcueMY2M97W7E8 x3aDlenXkXber5l4bxxWNnjX5LDX1hfsVNdTZxczwpBAiP38ZAHY38m+tVNdo9ZAOBvg ql3N/Zq+XFnl0JOZar/CurMydebjMvfEFRzV+RL+qJ5lXv2Y6IhKnzA7fPxA5ndkpCKY XoFk7AvpPEPZJLCuJ7vAvSjiiIEjW7Xff30kRtBLB293BLmzXCvq7ktbQSnI20sekG5X uNjOfJ1YOKV7N7eJ+SePojKbmG/yke9xxFtLiaIOmS1O9HJyMPyaUcRYR3gRkK4zCFke aYbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=N1urvO5XP9mfnhkCMAnUeWe06eh09JbAm/JqvEFANYo=; b=FnHAlYHgsYVt4RJOz81MDWhe2ertU4agTXMSCOAmFCnc9J89vlSpRrxu0jljIKPNAV cDKA6Ssdj2UnNgVUcMWHAI07jEf9JwJOEQ//uKSm15ii1leUMC9sKV+sk0KpdlaMFHcu lYOrzZSaJbfOB1gqV/HGpog1ub3o7U6RcJ7qu6pgTsY1J7hFSbriWwjwGIcc9sBZCvXp 1sjH3eLJmvP8sExAkgyllodNL3UaTTmGIPqhZnwi/23ZmQEiC+SVYiRrH+oxlCX9IZ5Y YssBQqMSJv6yokLyKwQ3Wlk2xa1AefAcrV0gAD/fmgZWES9Y0tSnWjjmop3WcJ0lXm57 XLGw== X-Gm-Message-State: ALyK8tKtvjNrCqBUzq7EJIUrsX0ou27ngQY3er9Gj0IQNUlA+Y6n5Vf5dDGnALD4m0jqoA== X-Received: by 10.28.184.67 with SMTP id i64mr531319wmf.31.1468437816063; Wed, 13 Jul 2016 12:23:36 -0700 (PDT) Received: from debian64.daheim (pD9F8A10B.dip0.t-ipconnect.de. [217.248.161.11]) by smtp.gmail.com with ESMTPSA id b200sm13659115wmb.9.2016.07.13.12.23.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jul 2016 12:23:34 -0700 (PDT) From: Christian Lamparter X-Google-Original-From: Christian Lamparter Received: from chuck by debian64.daheim with local (Exim 4.87) (envelope-from ) id 1bNPkq-0001NO-8A; Wed, 13 Jul 2016 21:23:32 +0200 To: lede-dev@lists.infradead.org Date: Wed, 13 Jul 2016 21:23:20 +0200 Message-Id: X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: <4b39932f8b33d453a95bc1f4050aaa4e440bf33e.1468437389.git.chunkeey@gmail.com> References: <08de197b961892dc60847a572b7700e5257da550.1468437389.git.chunkeey@gmail.com> <13382f9ab9fd93e17e16bcfb7d2167ce43252a07.1468437389.git.chunkeey@gmail.com> <1f30c1b11d2dd24bfa5fcc48174f4a2cd88ad719.1468437389.git.chunkeey@gmail.com> <4b39932f8b33d453a95bc1f4050aaa4e440bf33e.1468437389.git.chunkeey@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160713_122356_746178_B8D88AD9 X-CRM114-Status: GOOD ( 18.63 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (chunkeey[at]googlemail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [LEDE-DEV] [PATCH v2 7/8] apm821xx: lm90 add thermal sensor interface support for device tree X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netz.kernel@gmail.com, chrisrblake93@gmail.com, Christian Lamparter MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From 912-hwmon-lm90-expose-to-thermal-fw-via-DT.patch: "This patch adds to lm90 temperature sensor the possibility to expose itself as thermal zone device, registered on the thermal framework. The thermal zone is built only if a device tree node describing a thermal zone for this sensor is present inside the lm90 DT node. Otherwise, the driver behavior will be the same." Signed-off-by: Christian Lamparter --- ...0-split-set-and-show-temp-as-common-codes.patch | 302 +++++++++++++++++++++ ...12-hwmon-lm90-expose-to-thermal-fw-via-DT.patch | 151 +++++++++++ 2 files changed, 453 insertions(+) create mode 100644 target/linux/apm821xx/patches-4.4/911-hwmon-lm90-split-set-and-show-temp-as-common-codes.patch create mode 100644 target/linux/apm821xx/patches-4.4/912-hwmon-lm90-expose-to-thermal-fw-via-DT.patch diff --git a/target/linux/apm821xx/patches-4.4/911-hwmon-lm90-split-set-and-show-temp-as-common-codes.patch b/target/linux/apm821xx/patches-4.4/911-hwmon-lm90-split-set-and-show-temp-as-common-codes.patch new file mode 100644 index 0000000..a2e38c5 --- /dev/null +++ b/target/linux/apm821xx/patches-4.4/911-hwmon-lm90-split-set-and-show-temp-as-common-codes.patch @@ -0,0 +1,302 @@ +From: Wei Ni +Subject: hwmon: lm90: split set and show temp as common codes + +Split set and show temp codes as common functions, so we can use +it directly when implement linux thermal framework. +And handle error return value for the lm90_select_remote_channel +and write_tempx, then set_temp8 and set_temp11 could return it +to user-space. + +Discussed in: +http://www.spinics.net/lists/linux-tegra/msg14020.html . +Applied with Jean. + +BUG=chrome-os-partner:30834 +TEST=None + +Signed-off-by: Wei Ni +Signed-off-by: Jean Delvare +Reviewed-on: https://chromium-review.googlesource.com/175114 +Tested-by: Wei Ni +Commit-Queue: Dylan Reid +Reviewed-by: Dylan Reid +(cherry picked from commit 614a96decdc7a3784128c9f21c5471367e2c627d) +Change-Id: Idbe3948812c6737cba94810cd147c29cc527c3cf +Reviewed-on: https://chromium-review.googlesource.com/212413 +Reviewed-by: Olof Johansson +Commit-Queue: Olof Johansson +--- +diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c +index c9ff08d..fb9e224 100644 +--- a/drivers/hwmon/lm90.c ++++ b/drivers/hwmon/lm90.c +@@ -473,20 +473,29 @@ + * various registers have different meanings as a result of selecting a + * non-default remote channel. + */ +-static inline void lm90_select_remote_channel(struct i2c_client *client, +- struct lm90_data *data, +- int channel) ++static inline int lm90_select_remote_channel(struct i2c_client *client, ++ struct lm90_data *data, ++ int channel) + { + u8 config; ++ int err; + + if (data->kind == max6696) { + lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); + config &= ~0x08; + if (channel) + config |= 0x08; +- i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, +- config); ++ err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, ++ config); ++ if (err < 0) { ++ dev_err(&client->dev, ++ "Failed to select remote channel %d, err %d\n", ++ channel, err); ++ return err; ++ } + } ++ ++ return 0; + } + + /* +@@ -759,29 +768,34 @@ + * Sysfs stuff + */ + +-static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, +- char *buf) ++static int read_temp8(struct device *dev, int index) + { +- struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct lm90_data *data = lm90_update_device(dev); + int temp; + + if (data->kind == adt7461 || data->kind == tmp451) +- temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); ++ temp = temp_from_u8_adt7461(data, data->temp8[index]); + else if (data->kind == max6646) +- temp = temp_from_u8(data->temp8[attr->index]); ++ temp = temp_from_u8(data->temp8[index]); + else +- temp = temp_from_s8(data->temp8[attr->index]); ++ temp = temp_from_s8(data->temp8[index]); + + /* +16 degrees offset for temp2 for the LM99 */ +- if (data->kind == lm99 && attr->index == 3) ++ if (data->kind == lm99 && index == 3) + temp += 16000; + +- return sprintf(buf, "%d\n", temp); ++ return temp; + } + +-static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, +- const char *buf, size_t count) ++static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, ++ char *buf) ++{ ++ struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); ++ ++ return sprintf(buf, "%d\n", read_temp8(dev, attr->index)); ++} ++ ++static int write_temp8(struct device *dev, int index, long val) + { + static const u8 reg[TEMP8_REG_NUM] = { + LM90_REG_W_LOCAL_LOW, +@@ -794,10 +808,37 @@ + MAX6659_REG_W_REMOTE_EMERG, + }; + +- struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct lm90_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; +- int nr = attr->index; ++ int err; ++ ++ /* +16 degrees offset for temp2 for the LM99 */ ++ if (data->kind == lm99 && index == 3) ++ val -= 16000; ++ ++ mutex_lock(&data->update_lock); ++ if (data->kind == adt7461 || data->kind == tmp451) ++ data->temp8[index] = temp_to_u8_adt7461(data, val); ++ else if (data->kind == max6646) ++ data->temp8[index] = temp_to_u8(val); ++ else ++ data->temp8[index] = temp_to_s8(val); ++ ++ if ((err = lm90_select_remote_channel(client, data, index >= 6)) || ++ (err = i2c_smbus_write_byte_data(client, reg[index], ++ data->temp8[index])) || ++ (err = lm90_select_remote_channel(client, data, 0))) ++ dev_err(dev, "write_temp8 failed, err %d\n", err); ++ mutex_unlock(&data->update_lock); ++ ++ return err; ++} ++ ++static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, ++ const char *buf, size_t count) ++{ ++ struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); ++ int index = attr->index; + long val; + int err; + +@@ -805,49 +846,41 @@ + if (err < 0) + return err; + +- /* +16 degrees offset for temp2 for the LM99 */ +- if (data->kind == lm99 && attr->index == 3) +- val -= 16000; ++ err = write_temp8(dev, index, val); ++ if (err < 0) ++ return err; + +- mutex_lock(&data->update_lock); +- if (data->kind == adt7461 || data->kind == tmp451) +- data->temp8[nr] = temp_to_u8_adt7461(data, val); +- else if (data->kind == max6646) +- data->temp8[nr] = temp_to_u8(val); +- else +- data->temp8[nr] = temp_to_s8(val); +- +- lm90_select_remote_channel(client, data, nr >= 6); +- i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]); +- lm90_select_remote_channel(client, data, 0); +- +- mutex_unlock(&data->update_lock); + return count; ++} ++ ++static int read_temp11(struct device *dev, int index) ++{ ++ struct lm90_data *data = lm90_update_device(dev); ++ int temp; ++ ++ if (data->kind == adt7461 || data->kind == tmp451) ++ temp = temp_from_u16_adt7461(data, data->temp11[index]); ++ else if (data->kind == max6646) ++ temp = temp_from_u16(data->temp11[index]); ++ else ++ temp = temp_from_s16(data->temp11[index]); ++ ++ /* +16 degrees offset for temp2 for the LM99 */ ++ if (data->kind == lm99 && index <= 2) ++ temp += 16000; ++ ++ return temp; + } + + static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, + char *buf) + { + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); +- struct lm90_data *data = lm90_update_device(dev); +- int temp; + +- if (data->kind == adt7461 || data->kind == tmp451) +- temp = temp_from_u16_adt7461(data, data->temp11[attr->index]); +- else if (data->kind == max6646) +- temp = temp_from_u16(data->temp11[attr->index]); +- else +- temp = temp_from_s16(data->temp11[attr->index]); +- +- /* +16 degrees offset for temp2 for the LM99 */ +- if (data->kind == lm99 && attr->index <= 2) +- temp += 16000; +- +- return sprintf(buf, "%d\n", temp); ++ return sprintf(buf, "%d\n", read_temp11(dev, attr->index)); + } + +-static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, +- const char *buf, size_t count) ++static int write_temp11(struct device *dev, int nr, int index, long val) + { + struct { + u8 high; +@@ -861,17 +894,9 @@ + { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 } + }; + +- struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); + struct lm90_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; +- int nr = attr->nr; +- int index = attr->index; +- long val; + int err; +- +- err = kstrtol(buf, 10, &val); +- if (err < 0) +- return err; + + /* +16 degrees offset for temp2 for the LM99 */ + if (data->kind == lm99 && index <= 2) +@@ -887,15 +912,50 @@ + else + data->temp11[index] = temp_to_s8(val) << 8; + +- lm90_select_remote_channel(client, data, reg[nr].channel); +- i2c_smbus_write_byte_data(client, reg[nr].high, +- data->temp11[index] >> 8); +- if (data->flags & LM90_HAVE_REM_LIMIT_EXT) +- i2c_smbus_write_byte_data(client, reg[nr].low, +- data->temp11[index] & 0xff); +- lm90_select_remote_channel(client, data, 0); ++ err = lm90_select_remote_channel(client, data, reg[nr].channel); ++ if (err) ++ goto error; ++ ++ err = i2c_smbus_write_byte_data(client, reg[nr].high, ++ data->temp11[index] >> 8); ++ if (err) ++ goto error; ++ ++ if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { ++ err = i2c_smbus_write_byte_data(client, reg[nr].low, ++ data->temp11[index] & 0xff); ++ if (err) ++ goto error; ++ } ++ ++ err = lm90_select_remote_channel(client, data, 0); ++ ++error: ++ if (err) ++ dev_err(dev, "write_temp11 failed, err %d\n", err); + + mutex_unlock(&data->update_lock); ++ ++ return err; ++} ++ ++static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, ++ const char *buf, size_t count) ++{ ++ struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); ++ int nr = attr->nr; ++ int index = attr->index; ++ long val; ++ int err; ++ ++ err = kstrtol(buf, 10, &val); ++ if (err < 0) ++ return err; ++ ++ err = write_temp11(dev, nr, index, val); ++ if (err < 0) ++ return err; ++ + return count; + } + diff --git a/target/linux/apm821xx/patches-4.4/912-hwmon-lm90-expose-to-thermal-fw-via-DT.patch b/target/linux/apm821xx/patches-4.4/912-hwmon-lm90-expose-to-thermal-fw-via-DT.patch new file mode 100644 index 0000000..fe7337b --- /dev/null +++ b/target/linux/apm821xx/patches-4.4/912-hwmon-lm90-expose-to-thermal-fw-via-DT.patch @@ -0,0 +1,151 @@ +From: Wei Ni +Subject: hwmon: lm90: expose to thermal fw via DT nodes + +This patch adds to lm90 temperature sensor the possibility +to expose itself as thermal zone device, registered on the +thermal framework. + +The thermal zone is built only if a device tree node +describing a thermal zone for this sensor is present +inside the lm90 DT node. Otherwise, the driver behavior +will be the same. + +Discussed in: +http://www.gossamer-threads.com/lists/linux/kernel/1992853 + +BUG=chrome-os-partner:30834 +TEST=Verified. Build and boot up system. + +Signed-off-by: Wei Ni +Reviewed-on: https://chromium-review.googlesource.com/181447 +Reviewed-by: Dylan Reid +Tested-by: Dylan Reid +Commit-Queue: Dylan Reid +Change-Id: Id356b94d7e8f4b49ec15e46b17a1fa2ff0cbf8cf +Reviewed-on: https://chromium-review.googlesource.com/212414 +Tested-by: Wei Ni +Reviewed-by: Olof Johansson +Commit-Queue: Olof Johansson +--- +diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c +index fb9e224..c54d3c8 100644 +--- a/drivers/hwmon/lm90.c ++++ b/drivers/hwmon/lm90.c +@@ -96,6 +96,8 @@ + #include + #include + #include ++#include ++#include + + /* + * Addresses to scan +@@ -118,6 +120,13 @@ + + enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, + max6646, w83l771, max6696, sa56004, g781, tmp451 }; ++ ++enum sensor_id { ++ LOCAL = 0, ++ REMOTE, ++ REMOTE2, ++ SENSOR_ID_END, ++}; + + /* + * The LM90 registers +@@ -368,6 +377,7 @@ + struct i2c_client *client; + struct device *hwmon_dev; + const struct attribute_group *groups[6]; ++ struct thermal_zone_device *tz[SENSOR_ID_END]; + struct mutex update_lock; + struct regulator *regulator; + char valid; /* zero until following fields are valid */ +@@ -878,6 +888,24 @@ + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); + + return sprintf(buf, "%d\n", read_temp11(dev, attr->index)); ++} ++ ++static int lm90_read_local_temp(void *dev, int *temp) ++{ ++ *temp = read_temp11(dev, 4); ++ return 0; ++} ++ ++static int lm90_read_remote_temp(void *dev, int *temp) ++{ ++ *temp = read_temp11(dev, 0); ++ return 0; ++} ++ ++static int lm90_read_remote2_temp(void *dev, int *temp) ++{ ++ *temp = read_temp11(dev, 5); ++ return 0; + } + + static int write_temp11(struct device *dev, int nr, int index, long val) +@@ -1150,6 +1238,18 @@ + .attrs = lm90_temp3_attributes, + }; + ++static const struct thermal_zone_of_device_ops local_temp_sensor = { ++ .get_temp = lm90_read_local_temp, ++}; ++ ++static const struct thermal_zone_of_device_ops remote_temp_sensor = { ++ .get_temp = lm90_read_remote_temp, ++}; ++ ++static const struct thermal_zone_of_device_ops remote2_temp_sensor = { ++ .get_temp = lm90_read_remote2_temp, ++}; ++ + /* pec used for ADM1032 only */ + static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, + char *buf) +@@ -1599,6 +1699,30 @@ + } + } + ++ data->tz[LOCAL] = thermal_zone_of_sensor_register(&client->dev, ++ LOCAL, ++ &client->dev, ++ &local_temp_sensor); ++ if (IS_ERR(data->tz[LOCAL])) ++ data->tz[LOCAL] = NULL; ++ ++ data->tz[REMOTE] = thermal_zone_of_sensor_register(&client->dev, ++ REMOTE, ++ &client->dev, ++ &remote_temp_sensor); ++ if (IS_ERR(data->tz[REMOTE])) ++ data->tz[REMOTE] = NULL; ++ ++ if (data->flags & LM90_HAVE_TEMP3) { ++ data->tz[REMOTE2] = thermal_zone_of_sensor_register( ++ &client->dev, ++ REMOTE2, ++ &client->dev, ++ &remote2_temp_sensor); ++ if (IS_ERR(data->tz[REMOTE2])) ++ data->tz[REMOTE2] = NULL; ++ } ++ + return 0; + + exit_unregister: +@@ -1674,8 +1726,11 @@ + + static int lm90_remove(struct i2c_client *client) + { ++ int i; + struct lm90_data *data = i2c_get_clientdata(client); + ++ for (i = 0; i < SENSOR_ID_END; i++) ++ thermal_zone_of_sensor_unregister(&client->dev, data->tz[i]); + hwmon_device_unregister(data->hwmon_dev); + device_remove_file(&client->dev, &dev_attr_pec); + lm90_restore_conf(client, data);