From patchwork Thu Mar 24 14:46:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 64394 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp700464lbc; Thu, 24 Mar 2016 07:53:28 -0700 (PDT) X-Received: by 10.98.71.92 with SMTP id u89mr13464444pfa.100.1458831208424; Thu, 24 Mar 2016 07:53:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tf6si12641455pac.233.2016.03.24.07.53.28; Thu, 24 Mar 2016 07:53:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752396AbcCXOxQ (ORCPT + 29 others); Thu, 24 Mar 2016 10:53:16 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:36888 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752460AbcCXOqV (ORCPT ); Thu, 24 Mar 2016 10:46:21 -0400 Received: by mail-wm0-f43.google.com with SMTP id p65so69184157wmp.0 for ; Thu, 24 Mar 2016 07:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6yQCBazx+Q4hU99rO20SWQUN9rfgkJNu6GMDS1Ir9Oo=; b=JqyHuvCFddnfdutYPZTxF1Vj5tOOT74MzdFNxLanshoTq6HlrdruXJyXrTXkamz1ys bdzcsnPd/XLqdXb2K2IigZJauSZF+fafMMP5bY0rZCxsa4bq+Dwn7LqT8iTCBJkt7Unk wGR3mNJR3Jy6Cyi089273XAXudAE7lrh0Yi8M6QjNo36TNKm5MKPtU1MfrSqvGWv81w9 WhjzM8QOrBqKr5o0tVuHDUOd8AmSSbNFnaT16CQU0ZXfzKAmdm953sYa+Kx1nwN6FMQq 1Xc6cEQLu2ZyKe5wWNVag2cPWKW2jiXjBEgfbmfg0RXTzab1VRIGtiwmipl80nSFt+d1 eH9Q== 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; bh=6yQCBazx+Q4hU99rO20SWQUN9rfgkJNu6GMDS1Ir9Oo=; b=bThI+KIoWES3l8rYV61y8xxVukfbfddBOwuR2+50n7XiQMbDeP+31z5zSFiIBLS6oB ZUcwvLF+PxgExskAZJ0M88xXDHR+0fn/C9nZ8OlUOKVVMZpjV4G8Sg5L63YqOt2AwqP7 X3RJ6exL60Qo2DCdxM+llQ7+sQAORvOxrIPwZdX0W+45kQRVcZsL/p1xZutgI9fNog1K YX3ANQ+88FmJqVbQQ6Mbh6Aox83yZocZTU9hVQEv172O00bElwrHEp057XzkvzwAsJyO a8ozdVA7eghevIM3xZS8d/zPsvcFz0QUcTiTyRFfyKmzcaq0nUzGMA3TuPwdqO2nTfkp frEQ== X-Gm-Message-State: AD7BkJJPlZtMiBQz/rtzPSmz/uCA1Y0+As+RWB+ncvPde4GM6KHaQsuCt1q1mI16azCKV8iC X-Received: by 10.28.125.195 with SMTP id y186mr10503485wmc.79.1458830778696; Thu, 24 Mar 2016 07:46:18 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id k125sm27255752wmb.14.2016.03.24.07.46.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Mar 2016 07:46:18 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML Cc: Andrew Lunn , Bartosz Golaszewski Subject: [PATCH 08/13] eeprom: at24: call read and write routines via function pointers Date: Thu, 24 Mar 2016 15:46:02 +0100 Message-Id: <1458830767-23816-9-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458830767-23816-1-git-send-email-bgolaszewski@baylibre.com> References: <1458830767-23816-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to support non-standard read/write functions (as part of the at24cs series support) introduce two function pointers in struct at24_data to which different implementations can be assigned. For now we continue to use the regular read/write routines by default. Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index a7d6c15..5b484bc 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -59,6 +59,9 @@ struct at24_data { int use_smbus; int use_smbus_write; + int (*read_func)(struct at24_data *, char *, loff_t, size_t); + int (*write_func)(struct at24_data *, const char *, loff_t, size_t); + u8 *writebuf; struct mutex wrbuf_lock; unsigned write_max; @@ -458,7 +461,7 @@ static int at24_regmap_read(void *context, const void *reg, size_t reg_size, off_t offset = *(u32 *)reg; int err; - err = at24_read(at24, val, offset, val_size); + err = at24->read_func(at24, val, offset, val_size); if (err) return err; return 0; @@ -476,7 +479,7 @@ static int at24_regmap_write(void *context, const void *data, size_t count) buf = (const char *)data + sizeof(offset); len = count - sizeof(offset); - err = at24_write(at24, buf, offset, len); + err = at24->write_func(at24, buf, offset, len); if (err) return err; return 0; @@ -611,6 +614,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->chip = chip; at24->num_addresses = num_addresses; + at24->read_func = at24_read; + at24->write_func = at24_write; + writable = !(chip.flags & AT24_FLAG_READONLY); if (writable) { if (!use_smbus || use_smbus_write) {