From patchwork Wed Feb 8 19:53:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardner X-Patchwork-Id: 725845 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 3vJblZ1mpKz9s7D for ; Thu, 9 Feb 2017 09:40:58 +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="CCVHbFTM"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752254AbdBHWkj (ORCPT ); Wed, 8 Feb 2017 17:40:39 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:34863 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752169AbdBHWka (ORCPT ); Wed, 8 Feb 2017 17:40:30 -0500 Received: by mail-io0-f195.google.com with SMTP id m98so452166iod.2; Wed, 08 Feb 2017 14:40:29 -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; bh=bzDKx9l1Agbi3qPjuDFovn8AtyXtuwcsbBoG/ntjEiM=; b=CCVHbFTMJ6zExLrscTlX/JSzhcSgNRVFdLe2Y4M03rOagrAwczeGxY+Z2m/tZtTHWb omT5Z6eIqoTEi1CF8ATT2Vl+3nFfqfx8HnrhOhrlyuHiLvQanr2iN5um2UG6Sv7XS1rL kcJdw9vnRpCdMmt3iPq2bdL2MPGkqi35nRkm1i/jX+Wb+NeqS/qu7MttGbsfI44sSPVN QfSnqFIb1DaCEo9YRcpx6ho+FCNjIZbwd3mFnnebiPAZWMiRLuwbrdGhIWAJIPkfjBFY YgB7f2bxXGN+gRfuPS0fcQVFXHU5pP72TXFyjj50qCLlga4uJLojKwMn0jhu22UA1coS H7nA== 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; bh=bzDKx9l1Agbi3qPjuDFovn8AtyXtuwcsbBoG/ntjEiM=; b=n1fvvVZSIktNGX0vHBI20hS6bQME/EW/froDCCzG7R06j2EPiuwC0+JLADyNLvbePZ N8Z8imx4CETP6jeQfs9LT5LIveWq4mnnSR+HOk6lC2JDl5z4nPcpon9FXmpTWh+A6+Ug 0mn6qghVMcwTW04gGFheK3rMY5CG+4bX4lt8419aLU13Is3w1+tLC60+/Pmw13eEFATW 74u2a8pbxe/pBE+j+ZoZ0hGvBqW9YeqwBfxWaHsHf12vHux57GpzUJIOI2Q5jz0zxDRX 4fKV/mfcHb84YbLyNnsxqlFUpGsVt+NEE9iWquX+FYNymUpOtzMlfM6bTLgGdqS/4UTB o60Q== X-Gm-Message-State: AMke39mTmXTZxzN68cJRDw3SRGlP+FCXK3+qmmWzzoPtN0oW6pvZJYkyoYEUr9//z/6FWA== X-Received: by 10.107.189.197 with SMTP id n188mr11841685iof.88.1486583652308; Wed, 08 Feb 2017 11:54:12 -0800 (PST) Received: from wcrdsk1072.ad.wabtec.com ([216.243.219.251]) by smtp.gmail.com with ESMTPSA id x26sm1561551ita.11.2017.02.08.11.54.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Feb 2017 11:54:11 -0800 (PST) From: Ben Gardner To: Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardner Subject: [PATCH] eeprom/at24: use device_property_*() functions instead of of_get_property() Date: Wed, 8 Feb 2017 13:53:56 -0600 Message-Id: <1486583636-8940-1-git-send-email-gardner.ben@gmail.com> X-Mailer: git-send-email 2.7.4 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 Reviewed-by: Andy Shevchenko --- drivers/misc/eeprom/at24.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 051b147..9cb8904 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,17 @@ 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, +static void at24_fw_to_chip(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 -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) { @@ -621,7 +611,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) chip.page_size = 1; /* update chipdata if OF is present */ - at24_get_ofdata(client, &chip); + at24_fw_to_chip(&client->dev, &chip); chip.setup = NULL; chip.context = NULL;