From patchwork Thu Nov 16 20:25:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 838782 X-Patchwork-Delegate: bartekgola@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HHrRkPE0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydCTj6zHRz9rxm for ; Fri, 17 Nov 2017 07:27:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759016AbdKPU1U (ORCPT ); Thu, 16 Nov 2017 15:27:20 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:40764 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759008AbdKPU1T (ORCPT ); Thu, 16 Nov 2017 15:27:19 -0500 Received: by mail-wr0-f195.google.com with SMTP id p96so240193wrb.7 for ; Thu, 16 Nov 2017 12:27:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=VondLYtRXytkZBNT0DptBu0LRqx4tIDOC7Q+W+or1y4=; b=HHrRkPE0rMepV1znsWDOP/UstpIyZdAtyNfFvUx/RRMje5lE4i/VDScaONHUIlrH26 qIGd9AC9SulWh/K9FOg4zwQ8vxfN10D49qNDnq0kCir7PJkOgt4mK0d1XVzi0fLH2+g1 ohkbV+31ymb7zWS/oPkD31CyWSN2JKookSDYIX8bFUw3+9zgu+MN1WBJQMH2VaA0um3H /R2y41IwXR9wjl+FHLNifNLoGq5oNE9oXd2dJpUYkwI+VPhh8/vEVM4yw9BjAHF2U8lG UKl1+TWcBtvDMwifWXQcZhPUzLeYJg+fKJU3t4Fiekh3fL6a/c7kkfWWqH0F07kutAFi 4oqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=VondLYtRXytkZBNT0DptBu0LRqx4tIDOC7Q+W+or1y4=; b=VIOfZXIiJMyJ+cpYKyrdibgn+TN7Lbfugi0liur0FWPBYOjNO8ycqyGD0dFjegrY3L D5hc+QmJlA4K7Tj1wZdQXpq+Ete1OoWEYRl4vn7Li3hCdUbM/Zm/YR4qRwZYB16TSEfb ldZp/UX6cUNAruI3Z2hgB8FNA6SScHCj41COItmM0rMWa7zUWYx/NuPKv5+U2Q7oDq3S XvvV5jH/pXh9p2e0C30qWx6ddT/YL0+M34rdBgS0IdibCO89m4PosYfkDMlmpGJeeTLM s3tl1XDVhzq+RIZYu+z/6LTIJkRNttQsGsRcLM11LiJN5p4f76nKTcCswKCVH/OLcjiw Nc2g== X-Gm-Message-State: AJaThX6GzFfZzrEsekqRBL9brwAxtCUzWjNX12Zt2oQb+6mdczTK65Jc Yf8eS6IGUO7ny5S1ESYXbPsXig== X-Google-Smtp-Source: AGs4zMYrxRyvTGVpiJPizLRPJwtcF4Ddomg7UWbxgzrA1MUMMyZ9D+8ozIFl3wRuufAE3DB7gUzKtQ== X-Received: by 10.223.176.143 with SMTP id i15mr984478wra.240.1510864037471; Thu, 16 Nov 2017 12:27:17 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0? (p200300EA8BC0E4005D3B3D3E54B739D0.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:5d3b:3d3e:54b7:39d0]) by smtp.googlemail.com with ESMTPSA id q13sm1236926wrg.97.2017.11.16.12.27.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 12:27:16 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 1/7] eeprom: at24: add basic regmap_i2c support To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <451022fc-e20e-3539-e459-63d64598327d@gmail.com> Date: Thu, 16 Nov 2017 21:25:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch adds basic regmap support to be used by subsequent patches of this series. Signed-off-by: Heiner Kallweit --- v2: - rebased --- drivers/misc/eeprom/Kconfig | 1 + drivers/misc/eeprom/at24.c | 53 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig index de5876209..68a1ac929 100644 --- a/drivers/misc/eeprom/Kconfig +++ b/drivers/misc/eeprom/Kconfig @@ -4,6 +4,7 @@ config EEPROM_AT24 tristate "I2C EEPROMs / RAMs / ROMs from most vendors" depends on I2C && SYSFS select NVMEM + select REGMAP_I2C help Enable this driver to get read/write support to most I2C EEPROMs and compatible devices like FRAMs, SRAMs, ROMs etc. After you diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index e0b4b36ef..911cce8ec 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,11 @@ * which won't work on pure SMBus systems. */ +struct at24_client { + struct i2c_client *client; + struct regmap *regmap; +}; + struct at24_data { struct at24_platform_data chip; int use_smbus; @@ -81,7 +87,7 @@ struct at24_data { * Some chips tie up multiple I2C addresses; dummy devices reserve * them for us, and we'll use them with SMBus calls. */ - struct i2c_client *client[]; + struct at24_client client[]; }; /* @@ -274,7 +280,7 @@ static struct i2c_client *at24_translate_offset(struct at24_data *at24, *offset &= 0xff; } - return at24->client[i]; + return at24->client[i].client; } static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, @@ -673,6 +679,16 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip) } } +static const struct regmap_config regmap_config_8 = { + .reg_bits = 8, + .val_bits = 8, +}; + +static const struct regmap_config regmap_config_16 = { + .reg_bits = 16, + .val_bits = 8, +}; + static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct at24_platform_data chip; @@ -683,6 +699,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) struct at24_data *at24; int err; unsigned i, num_addresses; + const struct regmap_config *config; u8 test_byte; if (client->dev.platform_data) { @@ -764,8 +781,13 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) num_addresses = DIV_ROUND_UP(chip.byte_len, (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); + if (chip.flags & AT24_FLAG_ADDR16) + config = ®map_config_16; + else + config = ®map_config_8; + at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + - num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); + num_addresses * sizeof(struct at24_client), GFP_KERNEL); if (!at24) return -ENOMEM; @@ -775,6 +797,11 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->chip = chip; at24->num_addresses = num_addresses; + at24->client[0].client = client; + at24->client[0].regmap = devm_regmap_init_i2c(client, config); + if (IS_ERR(at24->client[0].regmap)) + return PTR_ERR(at24->client[0].regmap); + if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { dev_err(&client->dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); @@ -822,18 +849,22 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) } } - at24->client[0] = client; - /* use dummy devices for multiple-address chips */ for (i = 1; i < num_addresses; i++) { - at24->client[i] = i2c_new_dummy(client->adapter, - client->addr + i); - if (!at24->client[i]) { + at24->client[i].client = i2c_new_dummy(client->adapter, + client->addr + i); + if (!at24->client[i].client) { dev_err(&client->dev, "address 0x%02x unavailable\n", client->addr + i); err = -EADDRINUSE; goto err_clients; } + at24->client[i].regmap = devm_regmap_init_i2c( + at24->client[i].client, config); + if (IS_ERR(at24->client[i].regmap)) { + err = PTR_ERR(at24->client[i].regmap); + goto err_clients; + } } i2c_set_clientdata(client, at24); @@ -892,8 +923,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) err_clients: for (i = 1; i < num_addresses; i++) - if (at24->client[i]) - i2c_unregister_device(at24->client[i]); + if (at24->client[i].client) + i2c_unregister_device(at24->client[i].client); pm_runtime_disable(&client->dev); @@ -910,7 +941,7 @@ static int at24_remove(struct i2c_client *client) nvmem_unregister(at24->nvmem); for (i = 1; i < at24->num_addresses; i++) - i2c_unregister_device(at24->client[i]); + i2c_unregister_device(at24->client[i].client); pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev);