From patchwork Tue Apr 30 12:05:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri Fedrau X-Patchwork-Id: 13648886 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 770E112D758; Tue, 30 Apr 2024 12:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478759; cv=none; b=HBTJM2qrmVVbvZjs4YB3+G+JlNPITa/aTiUdzkkg5U0DLSQ8sD1BTgLxoGgCmhDT2ADcsoB2Jhu6o1E4q8dCnuljEhV9vwUsffziC7EKaTtsaflyjDEqHFuT4ZAScLl3/D/oHd2SZjmyMKkzAdqmUjOs/lsiKxVdvaPjq5dFJMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478759; c=relaxed/simple; bh=tnuyjcpQVNyMCFZIY0ylT1N+8NqvFw7TtTCwnHPldU8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M+qm6SLuqRWHB5Z7RWHqszdU+h8vmj0UsLqH9SVex9A0LCPXWfw939YNdPiEuxl8T/IjeVutAj9SqTXJhabLk3UuGzrQx2FCkFmY9qFFtxErH/3bOncpX45qjlSgJe98/xG3pLhRQFgTu1pU9sLEckRdcvkruS6+QgfnPPLEU7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GCryqmqu; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GCryqmqu" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-41b5e74fa2fso34884155e9.1; Tue, 30 Apr 2024 05:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714478757; x=1715083557; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I9IvzhHN84puUIqzRaEK8QdNvvnVmt/rg0fAQUr5Bqs=; b=GCryqmquhVkynnDHrAOP+wjpfHIO7zqI+9YHxcL/lCsUM6pURrRGzG4MC1xQuXOQmO CJsP93gaVJiK+2xiB+NI20na6BrpCuc3R0TsAWlR9jO61TvEfsnicf4/vFhO6VQFBxmm yZbqqFQG97LKo1Oue1Mgu1b5dNyhy3mmKy/LCOyNUhZ92C3m9zsKEgEsx6gEsRhVopKX 0MfdrdjG1FCu2ljZTiwxzlfYZ4jGBfs53+cJOGtrQrtdrAnzBPSCAFAC8Oqzl1slFjvT odsUGNhl4WgK+lkx2Bo4ovXZlr3ShgpURNvEeJtwpQ6k9/Taa0iol6gNuQn828TLD/h+ u1Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714478757; x=1715083557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I9IvzhHN84puUIqzRaEK8QdNvvnVmt/rg0fAQUr5Bqs=; b=cZZQYB1KFaVdNWbLM70LiniaNO8WJ9qfNhR3MbaAtJptScSBm6t7/ah2W6r9Q89THY FmCDslVOf+aPitvAxjgks37KgtkchTNYEvJxZ2YuZ+VIRHYhlBY22irGKKxFIe9O0rdZ iPJuaMrwijHNJmUwvRogDirswdafGjlLuh7BH1GBiVsZGLVmdF2lOPLRJG/GkufEI8+2 nFhMdDSDiIVSlbwkjeayNbcNIE7qW+5a4y80nHFODpEoQN3rTD0AwUMtKQOTXeYxeo3p KrMqk4qWfMS1CQyGb5ptMMBaz1cPyM9DeYQfZGLMp5skbjUTAsU2HbW5WZPBgSY8jan4 mIGQ== X-Forwarded-Encrypted: i=1; AJvYcCXSjhQIN6rl9h0qoa75hPDkXz60Qi/5isc6X5iXq4GqxU+szgsuUH73C0Lysf9RHKBpxbt74mI6wW8l8PXoqo9xRGkHiCHygzTZRCZVJ+6C6yE0e/dsCS67pC/ALGTaHXasihg2pJVv X-Gm-Message-State: AOJu0YxuI13ebByND4lXjDLhBvKJkGaAwcpFlLS2k2loWktctefDPHhI OePKJ943RkBRn6B/pZgfzAP+SulDJ7ReaKk+ZhtYvigw045NaCK7 X-Google-Smtp-Source: AGHT+IFJimAmOWTm/cM5LrYCg9GTBY0JnEXu0rgDu6K1goOrbcWRWMygHBUDIyvFsDZymEQxIiTrYQ== X-Received: by 2002:a05:600c:1d98:b0:41b:a670:a9f1 with SMTP id p24-20020a05600c1d9800b0041ba670a9f1mr8921046wms.7.1714478756637; Tue, 30 Apr 2024 05:05:56 -0700 (PDT) Received: from debian.fritz.box ([93.184.186.109]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c35d500b0041bf45c0665sm11054324wmq.15.2024.04.30.05.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:05:56 -0700 (PDT) From: Dimitri Fedrau To: Cc: Jonathan Cameron , Lars-Peter Clausen , Dimitri Fedrau , Andrew Hepp , Marcelo Schmitt , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] iio: temperature: mcp9600: set channel2 member Date: Tue, 30 Apr 2024 14:05:31 +0200 Message-Id: <20240430120535.46097-2-dima.fedrau@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430120535.46097-1-dima.fedrau@gmail.com> References: <20240430120535.46097-1-dima.fedrau@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Set channel2 member of channel 0 to IIO_MOD_TEMP_OBJECT and set modified member to 1. Signed-off-by: Dimitri Fedrau --- drivers/iio/temperature/mcp9600.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c index 7a3eef5d5e75..e277edb4ae4b 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -26,6 +26,8 @@ static const struct iio_chan_spec mcp9600_channels[] = { { .type = IIO_TEMP, .address = MCP9600_HOT_JUNCTION, + .channel2 = IIO_MOD_TEMP_OBJECT, + .modified = 1, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), }, From patchwork Tue Apr 30 12:05:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri Fedrau X-Patchwork-Id: 13648887 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE4A313DDA1; Tue, 30 Apr 2024 12:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478763; cv=none; b=PyBKGs4ENrY6NUeeg+6Q9hSl5y1cbCVvHGDMvUOuanbVeqkVf/Ky0mx+rg/xb1TqGjlmBKY2vpEZpgWPfeRtK+2gIGuLUtQLb4zigmfkVoNj4MKZNEYbc/eufardevvA1lga+Tr+wdFotWQbApOMY/fXOSOz3lLYQ1nU0DT1zTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478763; c=relaxed/simple; bh=2JxZ46VcZWvbyPVPb1cyk2/6uf/4Aaz91vZxN6diARc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bQgOIHh0H7woJyGTT/OKNE5ef2p+tDa5I69QdE+OCzyV2Mi044JGq33eNDBycsS0z/KEW2tbnAWogLL5xq+vok3eCUId+igKEJL0yDvJZlwBCegIs+kskkg12bN2JxfxYXbZ5+YYVrECohmAyIIZEXyYSf6QvXu3O1HuIqTaofc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=U7JkBQY7; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U7JkBQY7" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-51c077cfc09so6575732e87.2; Tue, 30 Apr 2024 05:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714478758; x=1715083558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y3BgglTbE282Y2tGBI8He/8kJHXPAXkHQuRLmbZ/HRs=; b=U7JkBQY74oqDn3BEEhek1ktuSrYOJz/2yS7KNAvUsEoQbtNWhijF6AZ+3TjrZmdHSL XnwLfW2Fb5Zqz1lt/9UJCFbKm04keXaXn92lLvktqU+UMFpmsiXhW+pgxmG3a/ag+Cb6 pJ8YiNMI1ejTQ3CgGFRxXMCk/Lu3MK8ECTpBddI7xxD2AFr3ozJro9heQzqlINatEHlE QgDOAPG/SXnlHUxkfJmod+eo1k84l/5fh2ieuxa43hnDfA8t74tvMjiNiyFtXnqD0VJC IhyE747ku07lmigJaW8uJRxVJw5r6ml1vEBvGwSc6D+dTffIzcvEUp+1JrkvX9wAG7q4 T0fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714478758; x=1715083558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y3BgglTbE282Y2tGBI8He/8kJHXPAXkHQuRLmbZ/HRs=; b=qamNMNQl6msR6gTeJOv3WE0hh8WpHDojdyhQU4MLv92aMSue6Lywqemn4C72FuifBp a+Ml1dI8BAxMNWdoLNysD5YPl68VmsGI3h0LN2ONiWumLF8C6YYF3Y1+2f1CmJo6O/+L pdpTjGvLlRiQGqySES6nhPz7GUDWitiGQtcQCuo6twzh574CDyNhlAFhSxm/NJu2nNaY RSRzllOulVXWneg58BN7A1cZegX4hTpIN5VvgU3jAZIvuDWYQEyODloPY7VhKf4t42Ju Z5ZWgZGOdFv/C6c52B5ZYTBOKY1D0Wo4RVVEmDnL42+9qPTgosEONADvoyqM6QlRCYm2 7rzg== X-Forwarded-Encrypted: i=1; AJvYcCVFs3CS4AQ9e5bd79H0lhuAjAcFyTOWxGM0We8xCVO5qgg4EKYE5ut7rrRLsFixW5WdvmrPgWc53LKqiqEU0ubDP14PFDKnWa8lFAd3ZW3kL+3RPn5X2tXDks6CGaAXfbEaUJtLqjBg X-Gm-Message-State: AOJu0YyQPMHCn/+on1Nr46293hoq3Y6mKP33/HD+fV/7XEMfCauy0WKq Y+OucBbHVLS0aAmolblvpjTKvjGXn1MQgP0Y62RGyjXtMV0/IQKQ2NT/gA== X-Google-Smtp-Source: AGHT+IGphn33MZVh9pKlfqfYP5sg5WD/OrJnrosO9Za7cgxUkmGC6HupzhUC2qyZ3fGy4E0cTANOQw== X-Received: by 2002:ac2:4e90:0:b0:51d:998e:e0c1 with SMTP id o16-20020ac24e90000000b0051d998ee0c1mr4087282lfr.13.1714478757704; Tue, 30 Apr 2024 05:05:57 -0700 (PDT) Received: from debian.fritz.box ([93.184.186.109]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c35d500b0041bf45c0665sm11054324wmq.15.2024.04.30.05.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:05:57 -0700 (PDT) From: Dimitri Fedrau To: Cc: Jonathan Cameron , Lars-Peter Clausen , Dimitri Fedrau , Andrew Hepp , Marcelo Schmitt , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] iio: temperature: mcp9600: Share scale by all channels Date: Tue, 30 Apr 2024 14:05:32 +0200 Message-Id: <20240430120535.46097-3-dima.fedrau@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430120535.46097-1-dima.fedrau@gmail.com> References: <20240430120535.46097-1-dima.fedrau@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move bit IIO_CHAN_INFO_SCALE from info_mask_separate to info_mask_shared_by_all since temperature format is the same for all channels. Signed-off-by: Dimitri Fedrau --- drivers/iio/temperature/mcp9600.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c index e277edb4ae4b..74e0782fb073 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -28,16 +28,16 @@ static const struct iio_chan_spec mcp9600_channels[] = { .address = MCP9600_HOT_JUNCTION, .channel2 = IIO_MOD_TEMP_OBJECT, .modified = 1, - .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), }, { .type = IIO_TEMP, .address = MCP9600_COLD_JUNCTION, .channel2 = IIO_MOD_TEMP_AMBIENT, .modified = 1, - .info_mask_separate = - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), }, }; From patchwork Tue Apr 30 12:05:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri Fedrau X-Patchwork-Id: 13648888 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AACE140384; Tue, 30 Apr 2024 12:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478763; cv=none; b=IBnwhE9oK+Ew7UiyAPWhB87ko/Q/DXGDl/D2cJd6i6FpsZzUMo8I+kFyJtBEPxsttVdt5NP5w2+/6DuL0HUG0rNlc7Fg+kzeh3YrLjR08ioXt+QCg51cl6tvPqr5klJuDI2AW/k7qXqjwc2SVPm49ScGlv/YXqDFDjL4tbkSMVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478763; c=relaxed/simple; bh=bR3QmlDfhQeZK3/nzddsjkAyB6NL01lZ7SYdVCaJrBk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YoimFDUpxtv0Rvvg8+2GPryZVBkBrhhk/6tVEZ/g0ofCWkF8/Oi5DnlR58c88kHdS1MbiVJ3RJ4yI7/+p1YGyk4/jKK3XXhAphrUAwKqXfqsSeoAedxPW0XK9m4RGS+qzBX6GVE34Vda/9bl+sN0G7FRPE6CCObSQgBuhUbtw1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FD3TX3zD; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FD3TX3zD" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-41c7ac73fddso15283785e9.3; Tue, 30 Apr 2024 05:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714478759; x=1715083559; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=50O7JUjzPqq3MrEGeaDK/IH1iyedTVT6be/Or9mCL6k=; b=FD3TX3zDUh/lcXx+ccVYSw/xocVr4Q/2wMPqosUCp5PLOL+D1/l208uzAGEHfPVeuD kb178j/6ZhZjQeRdgyuYFZwTafZ6puZhCrQb9Soz4V//2hO3Zd90/b8lhBIG6TuMLrp4 fKLJ8A1+J/NDJvxQItHlvPuCm1hPfcSsC4BxSJLjPCeJ60ue1Oj1SObIyfMRadyJm3oc QHZbljdqnmlEuWHNY47dYl/+h0NCMFkqtVnbASqudtA8p3/nuw+qGIP1BU2BtL13E+S4 UWBX5Pj9WiBsNEmzNYiywFwod+XOhjJ7QDhH8pBEvNpIgdvuN3md8qMso+srfUHoAkv5 ttxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714478759; x=1715083559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=50O7JUjzPqq3MrEGeaDK/IH1iyedTVT6be/Or9mCL6k=; b=g1ml9x1eg5QbV+w69ARPNaXkdliFL/KVPmlDwHdntEuIphz3UPbKAr8oesm7ruCpu+ h1+LASDh8s7EC7KKk0SrjHVRzccpREiAgP/HkrMvWEXEotj84dZBX2pN6orf/ufs0R2d ecXvUX7IVk7eyRh+y9rdCdgNYaW6m/dGNwIeA5J/gH3iXJBqbpZ3TiC09J7laAS3fL+H rdENWmNiU791VN8BpbrbDbMLyTQC3RmWZocpmJiPekjERkpGSl7g1LQN1rrAPqxSqmv4 56iaBkc00r4iuEQyasOjDkH74c40Q26EVf8wi2Ulzbi2rVeGD6HcIWHKcS2rNhi3KPYY qUKQ== X-Forwarded-Encrypted: i=1; AJvYcCWwjzIFqiPfFHTSn0RG2JwftY6qSObjEX2Lq83hNK4ATqxLNqe5gvtJaHtoT9JY4jkn8ayAxhyMzOmsi0+kVCaTLYnywgG6JF146x8LMPZ0GpcOvbXKAodd085NTuWZrXjWeVF5efWY X-Gm-Message-State: AOJu0YwPec8xut7DJwr7gtTKj0YUSxb/g2sVw6CIKkOAMlUb127Nuykw lyiIOmbft53lYiMeyak7vIhK3QMP40YafJ69dmvkCr+fEywfdVOji+NKiQ== X-Google-Smtp-Source: AGHT+IHoswtU02obG7H9oSPi9PRewBFiNnqWHmYgp5VXU6PSBqYsk8bSbmrH+vIJNXuEBPXKoCIZmw== X-Received: by 2002:a05:600c:3d9b:b0:41b:e94f:1e88 with SMTP id bi27-20020a05600c3d9b00b0041be94f1e88mr8679821wmb.24.1714478758721; Tue, 30 Apr 2024 05:05:58 -0700 (PDT) Received: from debian.fritz.box ([93.184.186.109]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c35d500b0041bf45c0665sm11054324wmq.15.2024.04.30.05.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:05:58 -0700 (PDT) From: Dimitri Fedrau To: Cc: Jonathan Cameron , Lars-Peter Clausen , Dimitri Fedrau , Andrew Hepp , Marcelo Schmitt , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] iio: temperature: mcp9600: add newlines after if statements Date: Tue, 30 Apr 2024 14:05:33 +0200 Message-Id: <20240430120535.46097-4-dima.fedrau@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430120535.46097-1-dima.fedrau@gmail.com> References: <20240430120535.46097-1-dima.fedrau@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add newlines after if statements following coding guide lines. Signed-off-by: Dimitri Fedrau --- drivers/iio/temperature/mcp9600.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c index 74e0782fb073..4003bc8c83d3 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -72,6 +72,7 @@ static int mcp9600_read_raw(struct iio_dev *indio_dev, ret = mcp9600_read(data, chan, val); if (ret) return ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 62; @@ -95,6 +96,7 @@ static int mcp9600_probe(struct i2c_client *client) ret = i2c_smbus_read_byte_data(client, MCP9600_DEVICE_ID); if (ret < 0) return dev_err_probe(&client->dev, ret, "Failed to read device ID\n"); + if (ret != MCP9600_DEVICE_ID_MCP9600) dev_warn(&client->dev, "Expected ID %x, got %x\n", MCP9600_DEVICE_ID_MCP9600, ret); From patchwork Tue Apr 30 12:05:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri Fedrau X-Patchwork-Id: 13648889 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D458141995; Tue, 30 Apr 2024 12:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478763; cv=none; b=EuZvLhHMl9XvB6qkHIQtQz7OcDy2XxbkB2phDwJJMln4QstQxiqnJC4Fhlsyj55nJxg9R0VUXPLhSva0EC9IzGGMwOSotpJDHfdgkgMOAfj7MZuVxacjZi+cK1R+DYW0bEtNrl5FOELn/ehx72u0EsRcoUBJ0ktp7IGsMwvKzz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478763; c=relaxed/simple; bh=nRD3dR3XiS4O2pkMTYgKRZdJOJRmKsBkVoKSFraFbCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qVnl8tItWFTw7zbRa2WYP/DP3PuGzaBbxojj0fukV0MY2YteyXL5LA5hYdTBXfg/h6piXIIcLF8/yX5c+5vaulIIuRPIPPaHl+k4uyba8VRUbiSM7fsiaD/fu7ZPR15iZnZ9dcGpXJoURToxWt9/oeRQyAXHavFURhlrWsbfM4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HvvdYvaH; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HvvdYvaH" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-51e1b9fba81so1610569e87.3; Tue, 30 Apr 2024 05:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714478760; x=1715083560; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XXZzTP12Y0hh4c4gYikxBkSiOjWjQelhhWRiIzMHGTs=; b=HvvdYvaHsVXAuN1zYbelFwbvwAnmYwP3xCEJloO8gipAB/Yp6hXUk4Et5XpmPmOTb1 o1KYv1Cr1u4i4aS3Pcj4MWF49KmFFH2vbnkgMEC1OySoh0xjGqOTTbSVLH6DKIP+4Mhq kA2uBHw9TORn0+eOyiO5IKQHNv1bNM/95yQG2bB9TUvxJcAurcH+pYS5afJApL7zk0yB QFzauopdsX852skMpWMazIatnAgnKwnpufuZo8K4affToyYd7N5Gkb6Dtu4+OPUsIygn Z9UjEIRcHnB6qH0dZGSP51XhffEGdAAZE5BE+ubOmmnFTPpB//Ct++frmAADIpydlwPK S+Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714478760; x=1715083560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XXZzTP12Y0hh4c4gYikxBkSiOjWjQelhhWRiIzMHGTs=; b=T1zh/XZUvPxS6aNU6RS6fzzAdFR/C/VPVLNIKoXBhWrW88177xz3Fn5nbvG2+gBsxA PXJM2/wOEfugffgS00MZHpPSPuW4IekWK/g8tCWmdhsQUF7HyMHvjI6YeZMKny0vuT+W 7I48zx9LNbK28LuIz9Ke7Bv5s63TiCnZ5tPuZNVy82mT92tM4SvmwJTt22i/9XSH3UjP i39B5ZXxRTNpa/ZMfzK18PJKZ272yNNJJEowa4YsUXaVocMq/pJDL1UqJaqPQ15w4ATt WvS3d4uKncNJLHDABcd+FbPavt1xbKj4ge3Ko7BiTmpozdQhw1667zJu9JGSL8ctSOKI 7bAw== X-Forwarded-Encrypted: i=1; AJvYcCUkV2hBuarJQlS1ZfetzQQhr5cTwyv81PhjDk4PCN9wIaF2w2NXhZ9O24EXpSaaI4zMfZRcPgrKRvP6xcYqlc5uGuo/EwIsHqiWw7cPi7xeeoFcps+eejQBgcZtsY2MnIt2kO3yvd6C X-Gm-Message-State: AOJu0YxwdQifq68EWttDsQslDcBxZkd0giV3l6dRpjj+XUqclewE1GXV 9s9aYaayqhUXoviuHwPCeoVFvVzSaTFebwMsDvGy0Ls5P3BMtvAC X-Google-Smtp-Source: AGHT+IEOERiyJM9ihi0i3SchdhZahYeOxvdDGTzEg0Ou9/KbolawOiew6JV38L4WA7hzczR15+SlGg== X-Received: by 2002:a19:5219:0:b0:51e:2e0a:c38c with SMTP id m25-20020a195219000000b0051e2e0ac38cmr2248733lfb.45.1714478759717; Tue, 30 Apr 2024 05:05:59 -0700 (PDT) Received: from debian.fritz.box ([93.184.186.109]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c35d500b0041bf45c0665sm11054324wmq.15.2024.04.30.05.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:05:59 -0700 (PDT) From: Dimitri Fedrau To: Cc: Jonathan Cameron , Lars-Peter Clausen , Dimitri Fedrau , Andrew Hepp , Marcelo Schmitt , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] iio: temperature: mcp9600: Fix line exceeding 80 columns Date: Tue, 30 Apr 2024 14:05:34 +0200 Message-Id: <20240430120535.46097-5-dima.fedrau@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430120535.46097-1-dima.fedrau@gmail.com> References: <20240430120535.46097-1-dima.fedrau@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix line exceeding 80 columns by introducing new variable "dev" and apply it wherever possible in mcp9600_probe. Signed-off-by: Dimitri Fedrau --- drivers/iio/temperature/mcp9600.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c index 4003bc8c83d3..cb1c1c1c361d 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -89,19 +89,20 @@ static const struct iio_info mcp9600_info = { static int mcp9600_probe(struct i2c_client *client) { + struct device *dev = &client->dev; struct iio_dev *indio_dev; struct mcp9600_data *data; int ret; ret = i2c_smbus_read_byte_data(client, MCP9600_DEVICE_ID); if (ret < 0) - return dev_err_probe(&client->dev, ret, "Failed to read device ID\n"); + return dev_err_probe(dev, ret, "Failed to read device ID\n"); if (ret != MCP9600_DEVICE_ID_MCP9600) - dev_warn(&client->dev, "Expected ID %x, got %x\n", - MCP9600_DEVICE_ID_MCP9600, ret); + dev_warn(dev, "Expected ID %x, got %x\n", + MCP9600_DEVICE_ID_MCP9600, ret); - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -114,7 +115,7 @@ static int mcp9600_probe(struct i2c_client *client) indio_dev->channels = mcp9600_channels; indio_dev->num_channels = ARRAY_SIZE(mcp9600_channels); - return devm_iio_device_register(&client->dev, indio_dev); + return devm_iio_device_register(dev, indio_dev); } static const struct i2c_device_id mcp9600_id[] = { From patchwork Tue Apr 30 12:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dimitri Fedrau X-Patchwork-Id: 13648890 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDDED14535E; Tue, 30 Apr 2024 12:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478765; cv=none; b=g+m6f2wQn56paakrXHV+HWyVuJQpA4bUEZ9NLn9ZhDrcccKsp3qygF3rZYUFqCbH0ezAeO0NChM6pQOfq+ZyQ8m5++48QYFYpOrfsq3UwmG3XXazI1HilWkFlxSsFAAktMxyBh7w2pkXEu2kApdxvycwNlygwi2vm2scxA/jyMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714478765; c=relaxed/simple; bh=h51PIdWJMbhHLXoQSCH/hNxJQjBIStdp9I7ajhbwaM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=tVIhldt+WiSJZxrzE65gDBZOGjCxi8bIsfPLEfYyk8H3f/eGPoQyiGYBhmXf9fE4lVUlSC9isb50ZFQYA9sYNYGq56MXpUmd7qFXwKIqyKFagsxoksUb47sKUUeJo8wzM1vri2oZTOtbfh6+jrHQDdr+rCRoCFIFrrmgvQLirHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AwpY4sh7; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AwpY4sh7" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-51b09c3a111so7912668e87.1; Tue, 30 Apr 2024 05:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714478761; x=1715083561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XVfmzv9+M83+3dtszQOFJXPN2DCqsj2JOs+0IqmE2GE=; b=AwpY4sh7MTlEOEbaLhrRD7TGZFhdHaIBfh7DcCSuXzafHZXuzn3F9ZPKNOyK2NFMNa oETHuPrYniuVbUE+LHFHtnCfe2FGuZ+UDBkpQTJPBpFAG+MBGGO2NBUgDdq7Vvt1DVE5 C/GgXCgo00SV9W9vETZLlVMZQUv2DdqygGt5Xn91AdkOOnvPb2xploLZjR5JJQJ+nzP/ za7eEUq1z76KleKc5KHz0dI4mAT7jNONGvlddWZZHgv3G2Btil65ar6vQzkVQ/k6R/eD BDbUi5DLGoeFvAASXpMIEqVFtj5fT5n5juBzVTkJ1fetnVK7gSO1nykbl7lT0r5ibz6M Hxsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714478761; x=1715083561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XVfmzv9+M83+3dtszQOFJXPN2DCqsj2JOs+0IqmE2GE=; b=vxilPoRMZMyH5dsFP+2M2mofC+BJjAH0bsrpVM+t+BnBFZR+ZI/Rl8W48OiTFnXYPl ZPBGyTiXlmwgIrGSNomVAq4RAljkIpYghlFVwAkbWQX8jUP8uGhw6OdDAcYf1CZoF2WW 3zdgVuacNa5SxtlomK0W2CGd3QiJkadBkA1k5thBBhoALv2JEAql6Xr+zwNC/vJiQQn7 2SGIAihvMLTg1RZ7gChRgW4ikL3rTw2gUZeX0FISoEsFChcJmiqxCeF4OJEg0kaBULZk B6aWokJLYkO0UlcF1f0433vyCDi8CgYXfvqDAv0Y0ACLKaixnKaKzaZ+x67NrSvqYa0P YhGw== X-Forwarded-Encrypted: i=1; AJvYcCWPT8klSfJueKZuf3x1hX1NFWhrfibkpkkSJBClGqKo6p57weRquL04Il/+m3SdCJyMelOnCX26pIM+JcZMAam1LZ0t6s5R502sLlftzoO4IaetQAOm0Qg0A8p4yHaei+S4hxigv+91 X-Gm-Message-State: AOJu0YwL3SpZiePq0Oc8to0+mO1q0WLD6y4PqDGF9ZyHfh+3xA9NC1LB pClvMyQyRBKaL4v+YqOgc01q28zOGUEnoThmk4+C6A7moMsNQJJf X-Google-Smtp-Source: AGHT+IHR0YLkYkN7kcebQLnWolrqsg1wtV6tlAVJCIRtmojLPrO5oCvuyJQod00OjkCNOEdZB3EHkA== X-Received: by 2002:ac2:5235:0:b0:51d:4260:4bf8 with SMTP id i21-20020ac25235000000b0051d42604bf8mr4738999lfl.35.1714478760811; Tue, 30 Apr 2024 05:06:00 -0700 (PDT) Received: from debian.fritz.box ([93.184.186.109]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c35d500b0041bf45c0665sm11054324wmq.15.2024.04.30.05.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:06:00 -0700 (PDT) From: Dimitri Fedrau To: Cc: Jonathan Cameron , Lars-Peter Clausen , Dimitri Fedrau , Andrew Hepp , Marcelo Schmitt , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] iio: temperature: mcp9600: add threshold events support Date: Tue, 30 Apr 2024 14:05:35 +0200 Message-Id: <20240430120535.46097-6-dima.fedrau@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430120535.46097-1-dima.fedrau@gmail.com> References: <20240430120535.46097-1-dima.fedrau@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The device has four programmable temperature alert outputs which can be used to monitor hot or cold-junction temperatures and detect falling and rising temperatures. It supports up to 255 degree celsius programmable hysteresis. Each alert can be individually configured by setting following options in the associated alert configuration register: - monitor hot or cold junction temperature - monitor rising or falling temperature - set comparator or interrupt mode - set output polarity - enable alert This patch binds alert outputs to iio events: - alert1: hot junction, rising temperature - alert2: hot junction, falling temperature - alert3: cold junction, rising temperature - alert4: cold junction, falling temperature All outputs are set in comparator mode and polarity depends on interrupt configuration. Signed-off-by: Dimitri Fedrau --- drivers/iio/temperature/mcp9600.c | 358 +++++++++++++++++++++++++++++- 1 file changed, 354 insertions(+), 4 deletions(-) diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c index cb1c1c1c361d..f7e1b4e3253d 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -6,21 +6,80 @@ * Author: */ +#include +#include #include #include #include +#include +#include #include #include +#include +#include +#include #include /* MCP9600 registers */ -#define MCP9600_HOT_JUNCTION 0x0 -#define MCP9600_COLD_JUNCTION 0x2 -#define MCP9600_DEVICE_ID 0x20 +#define MCP9600_HOT_JUNCTION 0x0 +#define MCP9600_COLD_JUNCTION 0x2 +#define MCP9600_STATUS 0x4 +#define MCP9600_STATUS_ALERT(x) BIT(x) +#define MCP9600_ALERT_CFG1 0x8 +#define MCP9600_ALERT_CFG(x) (MCP9600_ALERT_CFG1 + (x - 1)) +#define MCP9600_ALERT_CFG_ENABLE BIT(0) +#define MCP9600_ALERT_CFG_ACTIVE_HIGH BIT(2) +#define MCP9600_ALERT_CFG_FALLING BIT(3) +#define MCP9600_ALERT_CFG_COLD_JUNCTION BIT(4) +#define MCP9600_ALERT_HYSTERESIS1 0xc +#define MCP9600_ALERT_HYSTERESIS(x) (MCP9600_ALERT_HYSTERESIS1 + (x - 1)) +#define MCP9600_ALERT_LIMIT1 0x10 +#define MCP9600_ALERT_LIMIT(x) (MCP9600_ALERT_LIMIT1 + (x - 1)) + +#define MCP9600_DEVICE_ID 0x20 /* MCP9600 device id value */ -#define MCP9600_DEVICE_ID_MCP9600 0x40 +#define MCP9600_DEVICE_ID_MCP9600 0x40 + +#define MCP9600_ALERT_COUNT 4 + +#define MCP9600_MIN_TEMP_HOT_JUNCTION -200 +#define MCP9600_MAX_TEMP_HOT_JUNCTION 1800 + +#define MCP9600_MIN_TEMP_COLD_JUNCTION -40 +#define MCP9600_MAX_TEMP_COLD_JUNCTION 125 + +enum mcp9600_alert { + MCP9600_ALERT1, + MCP9600_ALERT2, + MCP9600_ALERT3, + MCP9600_ALERT4 +}; + +static const char * const mcp9600_alert_name[MCP9600_ALERT_COUNT] = { + [MCP9600_ALERT1] = "alert1", + [MCP9600_ALERT2] = "alert2", + [MCP9600_ALERT3] = "alert3", + [MCP9600_ALERT4] = "alert4", +}; + +static const struct iio_event_spec mcp9600_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_HYSTERESIS), + }, + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_HYSTERESIS), + }, +}; static const struct iio_chan_spec mcp9600_channels[] = { { @@ -30,6 +89,8 @@ static const struct iio_chan_spec mcp9600_channels[] = { .modified = 1, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), + .event_spec = mcp9600_events, + .num_event_specs = ARRAY_SIZE(mcp9600_events), }, { .type = IIO_TEMP, @@ -38,11 +99,15 @@ static const struct iio_chan_spec mcp9600_channels[] = { .modified = 1, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), + .event_spec = mcp9600_events, + .num_event_specs = ARRAY_SIZE(mcp9600_events), }, }; struct mcp9600_data { struct i2c_client *client; + struct mutex lock[MCP9600_ALERT_COUNT]; + int irq[MCP9600_ALERT_COUNT]; }; static int mcp9600_read(struct mcp9600_data *data, @@ -83,10 +148,292 @@ static int mcp9600_read_raw(struct iio_dev *indio_dev, } } +static int mcp9600_get_alert_index(int channel2, enum iio_event_direction dir) +{ + switch (channel2) { + case IIO_MOD_TEMP_OBJECT: + if (dir == IIO_EV_DIR_RISING) + return MCP9600_ALERT1; + else + return MCP9600_ALERT2; + case IIO_MOD_TEMP_AMBIENT: + if (dir == IIO_EV_DIR_RISING) + return MCP9600_ALERT3; + else + return MCP9600_ALERT4; + default: + return -EINVAL; + } +} + +static int mcp9600_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct mcp9600_data *data = iio_priv(indio_dev); + struct i2c_client *client = data->client; + int i, ret; + + i = mcp9600_get_alert_index(chan->channel2, dir); + if (i < 0) + return i; + + ret = i2c_smbus_read_byte_data(client, MCP9600_ALERT_CFG(i + 1)); + if (ret < 0) + return ret; + + return (ret & MCP9600_ALERT_CFG_ENABLE); +} + +static int mcp9600_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + int state) +{ + struct mcp9600_data *data = iio_priv(indio_dev); + struct i2c_client *client = data->client; + int i, ret; + + i = mcp9600_get_alert_index(chan->channel2, dir); + if (i < 0) + return i; + + ret = i2c_smbus_read_byte_data(client, MCP9600_ALERT_CFG(i + 1)); + if (ret < 0) + return ret; + + if (state) + ret |= MCP9600_ALERT_CFG_ENABLE; + else + ret &= ~MCP9600_ALERT_CFG_ENABLE; + + return i2c_smbus_write_byte_data(client, MCP9600_ALERT_CFG(i + 1), ret); +} + +static int mcp9600_read_thresh(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, int *val, int *val2) +{ + struct mcp9600_data *data = iio_priv(indio_dev); + struct i2c_client *client = data->client; + s32 ret; + int i; + + i = mcp9600_get_alert_index(chan->channel2, dir); + if (i < 0) + return i; + + guard(mutex)(&data->lock[i]); + ret = i2c_smbus_read_word_swapped(client, MCP9600_ALERT_LIMIT(i + 1)); + if (ret < 0) + return ret; + + /* + * Temperature is stored in two’s complement format in bits(15:2), + * LSB is 0.25 degree celsius. + */ + *val = sign_extend32(ret, 15) >> 2; + *val2 = 4; + if (info == IIO_EV_INFO_VALUE) + return IIO_VAL_FRACTIONAL; + + ret = i2c_smbus_read_byte_data(client, MCP9600_ALERT_HYSTERESIS(i + 1)); + if (ret < 0) + return ret; + + /* + * Hysteresis is stored as offset which is not signed, therefore we have + * to include directions when calculating the real hysteresis value. + */ + if (dir == IIO_EV_DIR_RISING) + *val -= (*val2 * ret); + else + *val += (*val2 * ret); + + return IIO_VAL_FRACTIONAL; +} + +static int mcp9600_write_thresh(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, int val, int val2) +{ + struct mcp9600_data *data = iio_priv(indio_dev); + struct i2c_client *client = data->client; + int s_val, s_thresh, i; + s16 thresh; + s32 ret; + u8 hyst; + + /* Scale value to include decimal part into calculations */ + s_val = (val < 0) ? ((val * (int)MICRO) - val2) : + ((val * (int)MICRO) + val2); + + /* Hot junction temperature range is from –200 to 1800 degree celsius */ + if (chan->channel2 == IIO_MOD_TEMP_OBJECT && + (s_val < (MCP9600_MIN_TEMP_HOT_JUNCTION * (int)MICRO) || + s_val > (MCP9600_MAX_TEMP_HOT_JUNCTION * (int)MICRO))) + return -EINVAL; + + /* Cold junction temperature range is from –40 to 125 degree celsius */ + if (chan->channel2 == IIO_MOD_TEMP_AMBIENT && + (s_val < (MCP9600_MIN_TEMP_COLD_JUNCTION * (int)MICRO) || + s_val > (MCP9600_MAX_TEMP_COLD_JUNCTION * (int)MICRO))) + return -EINVAL; + + i = mcp9600_get_alert_index(chan->channel2, dir); + if (i < 0) + return i; + + guard(mutex)(&data->lock[i]); + if (info == IIO_EV_INFO_VALUE) { + /* + * Shift length 4 bits = 2(15:2) + 2(0.25 LSB), temperature is + * stored in two’s complement format. + */ + thresh = (s16)(s_val / (int)(MICRO >> 4)); + return i2c_smbus_write_word_swapped(client, + MCP9600_ALERT_LIMIT(i + 1), + thresh); + } + + /* Read out threshold, hysteresis is stored as offset */ + ret = i2c_smbus_read_word_swapped(client, MCP9600_ALERT_LIMIT(i + 1)); + if (ret < 0) + return ret; + + /* Shift length 4 bits = 2(15:2) + 2(0.25 LSB), see above. */ + s_thresh = sign_extend32(ret, 15) * (int)(MICRO >> 4); + + /* + * Hysteresis is stored as offset, for rising temperatures, the + * hysteresis range is below the alert limit where, as for falling + * temperatures, the hysteresis range is above the alert limit. + */ + hyst = min(255, abs(s_thresh - s_val) / MICRO); + + return i2c_smbus_write_byte_data(client, + MCP9600_ALERT_HYSTERESIS(i + 1), + hyst); +} + static const struct iio_info mcp9600_info = { .read_raw = mcp9600_read_raw, + .read_event_config = mcp9600_read_event_config, + .write_event_config = mcp9600_write_event_config, + .read_event_value = mcp9600_read_thresh, + .write_event_value = mcp9600_write_thresh, }; +static irqreturn_t mcp9600_alert_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct mcp9600_data *data = iio_priv(indio_dev); + enum iio_event_direction dir; + enum iio_modifier mod; + int i, ret; + + for (i = 0; i < MCP9600_ALERT_COUNT; i++) { + if (data->irq[i] == irq) + break; + } + + if (i >= MCP9600_ALERT_COUNT) + return IRQ_NONE; + + ret = i2c_smbus_read_byte_data(data->client, MCP9600_STATUS); + if (ret < 0) + return IRQ_HANDLED; + + switch (ret & MCP9600_STATUS_ALERT(i)) { + case 0: + return IRQ_NONE; + case MCP9600_STATUS_ALERT(MCP9600_ALERT1): + mod = IIO_MOD_TEMP_OBJECT; + dir = IIO_EV_DIR_RISING; + break; + case MCP9600_STATUS_ALERT(MCP9600_ALERT2): + mod = IIO_MOD_TEMP_OBJECT; + dir = IIO_EV_DIR_FALLING; + break; + case MCP9600_STATUS_ALERT(MCP9600_ALERT3): + mod = IIO_MOD_TEMP_AMBIENT; + dir = IIO_EV_DIR_RISING; + break; + case MCP9600_STATUS_ALERT(MCP9600_ALERT4): + mod = IIO_MOD_TEMP_AMBIENT; + dir = IIO_EV_DIR_FALLING; + break; + default: + return IRQ_HANDLED; + } + + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_TEMP, 0, mod, + IIO_EV_TYPE_THRESH, dir), + iio_get_time_ns(indio_dev)); + + return IRQ_HANDLED; +} + +static int mcp9600_probe_alerts(struct iio_dev *indio_dev) +{ + struct mcp9600_data *data = iio_priv(indio_dev); + struct i2c_client *client = data->client; + struct device *dev = &client->dev; + struct fwnode_handle *fwnode = dev_fwnode(dev); + unsigned int irq_type; + int ret, irq, i; + u8 val; + + /* + * alert1: hot junction, rising temperature + * alert2: hot junction, falling temperature + * alert3: cold junction, rising temperature + * alert4: cold junction, falling temperature + */ + for (i = 0; i < MCP9600_ALERT_COUNT; i++) { + data->irq[i] = 0; + mutex_init(&data->lock[i]); + irq = fwnode_irq_get_byname(fwnode, mcp9600_alert_name[i]); + if (irq <= 0) + continue; + + val = 0; + irq_type = irq_get_trigger_type(irq); + if (irq_type == IRQ_TYPE_EDGE_RISING) + val |= MCP9600_ALERT_CFG_ACTIVE_HIGH; + + if (i == MCP9600_ALERT2 || i == MCP9600_ALERT4) + val |= MCP9600_ALERT_CFG_FALLING; + + if (i == MCP9600_ALERT3 || i == MCP9600_ALERT4) + val |= MCP9600_ALERT_CFG_COLD_JUNCTION; + + ret = i2c_smbus_write_byte_data(client, + MCP9600_ALERT_CFG(i + 1), + val); + if (ret < 0) + return ret; + + ret = devm_request_threaded_irq(dev, irq, NULL, + mcp9600_alert_handler, + IRQF_ONESHOT, "mcp9600", + indio_dev); + if (ret) + return ret; + + data->irq[i] = irq; + } + + return 0; +} + static int mcp9600_probe(struct i2c_client *client) { struct device *dev = &client->dev; @@ -109,6 +456,8 @@ static int mcp9600_probe(struct i2c_client *client) data = iio_priv(indio_dev); data->client = client; + mcp9600_probe_alerts(indio_dev); + indio_dev->info = &mcp9600_info; indio_dev->name = "mcp9600"; indio_dev->modes = INDIO_DIRECT_MODE; @@ -140,6 +489,7 @@ static struct i2c_driver mcp9600_driver = { }; module_i2c_driver(mcp9600_driver); +MODULE_AUTHOR("Dimitri Fedrau "); MODULE_AUTHOR("Andrew Hepp "); MODULE_DESCRIPTION("Microchip MCP9600 thermocouple EMF converter driver"); MODULE_LICENSE("GPL");