Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp44322lqb; Fri, 15 Mar 2024 14:36:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8Eb+S/zygQjPtAPbFdP8X3ZQ4L3FizRm4RBcoM4qN1/Z3/n3wMSTX4bmSsvavv7NMXi1QcBmkOGr2DfWnhlP9WB6w1VnhnhgszPXGeg== X-Google-Smtp-Source: AGHT+IHGUPLlo3JV7Y51xY+hR1NwfUNfxfKj6+3qu0NsE/YfOWtESJu0mWJr/NAvHNinlBqFerzz X-Received: by 2002:a17:90a:d716:b0:29d:d8ca:74f1 with SMTP id y22-20020a17090ad71600b0029dd8ca74f1mr4553382pju.14.1710538570891; Fri, 15 Mar 2024 14:36:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710538570; cv=pass; d=google.com; s=arc-20160816; b=QwIOouheoMWCcTHDDNiHVrmaAZAp67MTJNKUeCVWkNu4IBjkod2h1e+pH/Mwu1k3Fu +5eNvTyZN6PYZvBbpjpzNaaTtY8V4TaZw8SlgjWdCZFFkLOK4S+7UN1PxucqDbVnC6ym aoF8mY8njbf26tTRyN0mSKe85nwVObyF/KOGKx8MEu96z7Ri/F/i56bDhjIQ7JHLUQDS n++HYSUCUAQ9tRT6d/Yoz4JjrIN0iNeQk3J4SBFLr+FhoFB4MvGtJEATc/aaKD6OaRK5 QbmCG4WN49ZWtqHJqQ1wc5jrEAJo74LHBVi5lRmoTwnhVYdW/muJA8gaIP9FL+rO+W90 usXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=zLhbNCpAsdnAMm/9yoY8p/qO8u7ebloSJXuKEpMzYWA=; fh=b9mvzR7AA/ckztCoc8rs+VWtD9gtlt5VvRcU6BS8mGY=; b=DoIhhaZQuTcbnmw3HUGJAd3aAeS5sPyWuKQVYJBrHNePRDXt6U0Ezrx2J9qtJEcQSn 2hd09puJEO6Nj4dFgVd7ZxlShBAiXsI/k64UhFflpvUVloIo3KMpY3erGBPNJu08p1cl xfvwLxqP/py6b0PYsUkm9Yuxy/619g3s33ad4fz0SmWMOnWS+SP9vN+bWn56g0N2tTUt VUVM4zX/42K6d93qL7JVdK+/kXhD9M5q6GGL4Ak5+0oXXyHKzCe3rhCrsAcmN2H/ay6K 0zaNJQWKTHGt685ZppAj0RRlEewfS9PzD7qKzEV51TGCPj2g+IVulE9ZeHgNPwTfwy6f 9UHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TR8k0t9H; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-104940-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x2-20020a17090a6c0200b0029b93965180si3415423pjj.108.2024.03.15.14.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 14:36:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104940-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TR8k0t9H; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-104940-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DC26BB20ED9 for ; Fri, 15 Mar 2024 21:36:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E406B54914; Fri, 15 Mar 2024 21:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="TR8k0t9H" Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCFAB548F4 for ; Fri, 15 Mar 2024 21:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710538561; cv=none; b=lFyldYsdPLgLF1dz7pWeIetMfsxZvSQYWXjeckx8Z3krLR5Ye11KkEncuyUjCU05A5kszCEh3msqN7P3+snJtghhZ9UTMTrM6y+X/xZarHw7qXC449DAMTxooln1vsoU73fp12x2X7U/qiXKVk/dcZm9YhnVD/3MFWj/7IGF9PI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710538561; c=relaxed/simple; bh=CG2MR7sO9yin4h+PbF8Oq5ga4DEY+K/45S38A5VbGSU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=vCRi+UO5XaMTRFAo3DbyoApVGNIA24qlxl+W+fWRX3ApRFB5ZSwO5sjwzRAIm1YtCbvifxn7ShEmlDouLiYwEVJ2ZLknRmBnzkaL3rz2cDT+KSFwVXQKtK7GaT6VPig3IQpf0n/ODMwgdD+VbKX9d34lKp8N4aPUjEjaktYqFGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=TR8k0t9H; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710538555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zLhbNCpAsdnAMm/9yoY8p/qO8u7ebloSJXuKEpMzYWA=; b=TR8k0t9HMgzywrFBM7L3wdTnNZLquR0M5r0jLh9Abig5sBkYd36GADUjpcYywentdEmUNr 9DdvV5lea2SIDb6hN//OpuPmBH5d5pLucUzqcdYpfjShUSGLtn64SkcbK0vaEqwUD3zkbp RFlObyIa4rSHXGt1MwbBQeenS3otouU= From: Sean Anderson To: Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Sean Anderson Subject: [PATCH] misc: ds1682: Add NVMEM support Date: Fri, 15 Mar 2024 17:35:40 -0400 Message-Id: <20240315213540.1682964-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Add NVMEM support for the internal EEPROM. Signed-off-by: Sean Anderson --- drivers/misc/ds1682.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c index 21fc5bc85c5c..5f8dcd0e3848 100644 --- a/drivers/misc/ds1682.c +++ b/drivers/misc/ds1682.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -197,11 +198,43 @@ static const struct bin_attribute ds1682_eeprom_attr = { .write = ds1682_eeprom_write, }; +static int ds1682_nvmem_read(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct i2c_client *client = priv; + int ret; + + ret = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + offset, + bytes, val); + return ret < 0 ? ret : 0; +} + +static int ds1682_nvmem_write(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + struct i2c_client *client = priv; + int ret; + + ret = i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + offset, + bytes, val); + return ret < 0 ? ret : 0; +} + /* * Called when a ds1682 device is matched with this driver */ static int ds1682_probe(struct i2c_client *client) { + struct nvmem_config config = { + .dev = &client->dev, + .owner = THIS_MODULE, + .type = NVMEM_TYPE_EEPROM, + .reg_read = ds1682_nvmem_read, + .reg_write = ds1682_nvmem_write, + .size = DS1682_EEPROM_SIZE, + .priv = client, + }; + struct nvmem_device *nvmem; int rc; if (!i2c_check_functionality(client->adapter, @@ -211,6 +244,10 @@ static int ds1682_probe(struct i2c_client *client) goto exit; } + nvmem = devm_nvmem_register(&client->dev, &config); + if (IS_ENABLED(CONFIG_NVMEM) && IS_ERR(nvmem)) + return PTR_ERR(nvmem); + rc = sysfs_create_group(&client->dev.kobj, &ds1682_group); if (rc) goto exit; -- 2.35.1.1320.gc452695387.dirty