From patchwork Thu Feb 9 15:33:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardner X-Patchwork-Id: 726194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vK2vP6jc1z9s6n for ; Fri, 10 Feb 2017 03:04:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JRGMcc6d"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753482AbdBIQD4 (ORCPT ); Thu, 9 Feb 2017 11:03:56 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:35443 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753340AbdBIQC3 (ORCPT ); Thu, 9 Feb 2017 11:02:29 -0500 Received: by mail-io0-f193.google.com with SMTP id m98so2441980iod.2; Thu, 09 Feb 2017 08:01:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+E5QSgFRlqs3AjZviFk1hwiA7X9pbU1c1qLYLzfPmJY=; b=JRGMcc6dMzLXnFPxs5zDYGjYhJMHRBrhtXDEVkZ2JYqvEyeqilPT1ghLZm62zOm3R7 mpMGgKF+0taslEsmsRUrod6dmMjFL+EHiPprAKc16iMQuW05KFtgBNOR8YDj0SrEY/Wu V9LTJ6CCF6Nh5l+ta9tt3J1oaUP52mN2bF1PsgxTWJ1TWT9AiPRyOszX6FSa/JQzzTTW Xo8VEDCJp5Vc3+Xe8uhQS2rpkOb8+wk4oUJYDjQJrMhXwXpqQ7T5YolJjoH3Xu+lzRBe RzNnWfBNu4koWRq/Y5JYSfgIrDqOqg4zbBRvtQKBiJhh0weFddiSPCNSKqaOvVwmyv8+ L3Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+E5QSgFRlqs3AjZviFk1hwiA7X9pbU1c1qLYLzfPmJY=; b=AYE9mmUAYx59DLViIMnXBlRHqHdSbMzQvPXHqIWQEYpDvuMrR7Ezf+lVHPhSRX19ce TQIUyx8S/BfKIcJCBrrV87qVur6TkRdVPpDCFH5NS+Twyv1oHoKgxBR8ZN2Q+b1SM/Y7 X4I91qsS+HG6F2cS3zF10YUdwW20dzy3t4KH/zwBmLQklUr9q4AGQHCnipB6rfp24M/H J7lOMx+DzxvguHQvACUNI8Vqn6A+f20gBeUaFZmM6C++2P2TTCllOGJkzxEBnmOGjCSZ LLsH7LdnQcQ3KRraqbfa0IQjggXr0smgCpb4Abvqk1D6Q6nD3YowGGzxPj//nY+XgJM4 vo3w== X-Gm-Message-State: AMke39kPovcS736nPzZHYRHin7BxzGERd1QGyT3IhCJ+2nhAH0lnwRldwq8NSwPoCE56rg== X-Received: by 10.107.18.12 with SMTP id a12mr4188035ioj.155.1486654481434; Thu, 09 Feb 2017 07:34:41 -0800 (PST) Received: from wcrdsk1072.ad.wabtec.com ([216.243.219.251]) by smtp.gmail.com with ESMTPSA id y138sm13311083iod.30.2017.02.09.07.34.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Feb 2017 07:34:40 -0800 (PST) From: Ben Gardner To: Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , Ben Gardner Subject: [PATCH v2] eeprom/at24: use device_property_*() functions instead of of_get_property() Date: Thu, 9 Feb 2017 09:33:53 -0600 Message-Id: <1486654433-20148-1-git-send-email-gardner.ben@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486583636-8940-1-git-send-email-gardner.ben@gmail.com> References: <1486583636-8940-1-git-send-email-gardner.ben@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Allow the at24 driver to get configuration information from both OF and ACPI by using the more generic device_property functions. This change was inspired by the at25.c driver. I have a custom board with a ST M24C02 EEPROM attached to an I2C bus. With the following ACPI construct, this patch instantiates a working instance of the driver. Device (EEP0) { Name (_HID, "PRP0001") Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () {"compatible", Package () {"st,24c02"}}, Package () {"size", 256}, Package () {"pagesize", 16}, }, }) Name (_CRS, ResourceTemplate () { I2cSerialBus ( 0x0057, ControllerInitiated, 400000, AddressingMode7Bit, "\\_SB.PCI0.I2C3", 0x00, ResourceConsumer,,) }) } Note: Matching the driver to the I2C device requires another patch. http://www.spinics.net/lists/linux-acpi/msg71914.html Signed-off-by: Ben Gardner --- drivers/misc/eeprom/at24.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 051b147..81099f3 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -562,26 +561,25 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) return 0; } -#ifdef CONFIG_OF -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) +static void at24_get_pdata(struct device *dev, + struct at24_platform_data *chip) { - const __be32 *val; - struct device_node *node = client->dev.of_node; - - if (node) { - if (of_get_property(node, "read-only", NULL)) - chip->flags |= AT24_FLAG_READONLY; - val = of_get_property(node, "pagesize", NULL); - if (val) - chip->page_size = be32_to_cpup(val); + u32 val; + + if (device_property_present(dev, "read-only")) + chip->flags |= AT24_FLAG_READONLY; + + if (device_property_read_u32(dev, "pagesize", &val) == 0) { + chip->page_size = val; + } else { + /* + * This is slow, but we can't know all eeproms, so we better + * play safe. Specifying custom eeprom-types via platform_data + * is recommended anyhow. + */ + chip.page_size = 1; } } -#else -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) -{ } -#endif /* CONFIG_OF */ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -613,15 +611,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); magic >>= AT24_SIZE_BYTELEN; chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); - /* - * This is slow, but we can't know all eeproms, so we better - * play safe. Specifying custom eeprom-types via platform_data - * is recommended anyhow. - */ - chip.page_size = 1; - /* update chipdata if OF is present */ - at24_get_ofdata(client, &chip); + at24_get_pdata(&client->dev, &chip); chip.setup = NULL; chip.context = NULL;