From patchwork Wed Jul 17 20:53:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Lutomirski X-Patchwork-Id: 259765 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 9731A2C00A2 for ; Thu, 18 Jul 2013 06:53:23 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752005Ab3GQUxW (ORCPT ); Wed, 17 Jul 2013 16:53:22 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:52232 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755402Ab3GQUxV (ORCPT ); Wed, 17 Jul 2013 16:53:21 -0400 Received: by mail-pa0-f52.google.com with SMTP id kq14so1273699pab.25 for ; Wed, 17 Jul 2013 13:53:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references:x-gm-message-state; bh=g/h62ySl0HhfMzXUBHStJegSBDL8y4UbOvfIxgzy8m0=; b=OX6O9fG+0kBoG50Xfs1AwlmjqSpdRplxDMdlW3U5pBv8F+n3IFDQV8kVQb9cmH99HU KY8I5aFVKMiRYy/rpLzQNSVpUyjjKgGW6vSZBbITKiaHJCBLmstqgRWctGbtBfXl4GPG HrJ5WO/FWZS/VJmexMq1AejYIVSW3Z1C7Hx7U2viy7LIn6gXnfgghxvjqHhhenzTr2KA rBmPCWhUnVzaNp6NhXbrl1wULarYGyLNJalS40gtIEtxelWDdJMS/c1vLARnDCxT8Czw Vf1PkDPMQBtjgp86crBs7o6hRGNp3ZP4NIm1o5I6FBCl5zZ4ZammiKxcgvrUJj5PGKf/ f0yA== X-Received: by 10.66.13.202 with SMTP id j10mr9728119pac.181.1374094401062; Wed, 17 Jul 2013 13:53:21 -0700 (PDT) Received: from localhost (50-76-60-73-ip-static.hfc.comcastbusiness.net. [50.76.60.73]) by mx.google.com with ESMTPSA id ep4sm9580631pbd.35.2013.07.17.13.53.19 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 17 Jul 2013 13:53:20 -0700 (PDT) From: Andy Lutomirski To: lm-sensors@lm-sensors.org, linux-i2c@vger.kernel.org, Jean Delvare , Guenter Roeck Cc: James Ralston , Andy Lutomirski Subject: [PATCH v3 1/4] i2c: Add DIMM bus code Date: Wed, 17 Jul 2013 13:53:05 -0700 Message-Id: X-Mailer: git-send-email 1.8.1.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQkRmdH8KSBfA5upAyMCD38baGyYFqnPLn3WcS3k2RGG4rxgzXDGDEUWmUQ7k6W9PXgZm/fJ Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add i2c_scan_dimm_bus to declare that a particular i2c_adapter contains DIMMs. This will probe (and autoload modules!) for useful SMBUS devices that live on DIMMs. As more SMBUS-addressable DIMM components become supported, this code can be extended to probe for them. Signed-off-by: Andy Lutomirski --- drivers/i2c/busses/Kconfig | 4 +++ drivers/i2c/busses/Makefile | 4 +++ drivers/i2c/busses/dimm-bus.c | 84 +++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c/dimm-bus.h | 24 +++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 drivers/i2c/busses/dimm-bus.c create mode 100644 include/linux/i2c/dimm-bus.h diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index adfee98..e837f0e 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -133,6 +133,10 @@ config I2C_ISMT This driver can also be built as a module. If so, the module will be called i2c-ismt. +config I2C_DIMM_BUS + tristate + default n + config I2C_PIIX4 tristate "Intel PIIX4 and compatible (ATI/AMD/Serverworks/Broadcom/SMSC)" depends on PCI diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 8f4fc23..226bb2e 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -24,6 +24,10 @@ obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o obj-$(CONFIG_I2C_VIA) += i2c-via.o obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o +# DIMM busses +obj-$(CONFIG_I2C_DIMM_BUS) += dimm-bus.o +obj-$(CONFIG_I2C_IMC) += i2c-imc.o + # Mac SMBus host controller drivers obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o diff --git a/drivers/i2c/busses/dimm-bus.c b/drivers/i2c/busses/dimm-bus.c new file mode 100644 index 0000000..9012638 --- /dev/null +++ b/drivers/i2c/busses/dimm-bus.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2013 Andrew Lutomirski + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +static bool probe_addr(struct i2c_adapter *adapter, int addr) +{ + /* + * So far, all known devices that live on DIMMs can be safely + * and reliably detected by trying to read a byte at address + * zero. + */ + union i2c_smbus_data dummy; + return i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_READ, 0, + I2C_SMBUS_BYTE_DATA, &dummy) >= 0; +} + +/** + * i2c_scan_dimm_bus() - Scans an SMBUS segment known to contain DIMMs + * @adapter: The SMBUS adapter to scan + * + * This function tells the DIMM-bus code that the adapter is known to + * contain DIMMs. i2c_scan_dimm_bus will probe for devices known to + * live on DIMMs. + * + * Do NOT call this function on general-purpose system SMBUS segments + * unless you know that the only things on the bus are DIMMs. + * Otherwise is it very likely to mis-identify other things on the + * bus. + * + * Callers are advised not to set adapter->class = I2C_CLASS_SPD. + */ +void i2c_scan_dimm_bus(struct i2c_adapter *adapter) +{ + struct i2c_board_info info = {}; + int slot; + + /* + * We probe with "read byte data". If any DIMM SMBUS driver can't + * support that access type, this function should be updated. + */ + if (WARN_ON(!i2c_check_functionality(adapter, + I2C_FUNC_SMBUS_READ_BYTE_DATA))) + return; + + for (slot = 0; slot < 8; slot++) { + /* If there's no SPD, then assume there's no DIMM here. */ + if (!probe_addr(adapter, 0x50 | slot)) + continue; + + strcpy(info.type, "eeprom"); + info.addr = 0x50 | slot; + i2c_new_device(adapter, &info); + + if (probe_addr(adapter, 0x18 | slot)) { + /* This is a temperature sensor. */ + strcpy(info.type, "tsod"); + info.addr = 0x18 | slot; + i2c_new_device(adapter, &info); + } + } +} +EXPORT_SYMBOL(i2c_scan_dimm_bus); + +MODULE_AUTHOR("Andrew Lutomirski "); +MODULE_DESCRIPTION("i2c DIMM bus support"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/i2c/dimm-bus.h b/include/linux/i2c/dimm-bus.h new file mode 100644 index 0000000..3d44df4 --- /dev/null +++ b/include/linux/i2c/dimm-bus.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2013 Andrew Lutomirski + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef _I2C_DIMM_BUS +#define _I2C_DIMM_BUS + +struct i2c_adapter; +void i2c_scan_dimm_bus(struct i2c_adapter *adapter); + +#endif /* _I2C_DIMM_BUS */