From patchwork Thu Jul 19 09:57:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 142332 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1543206ljj; Thu, 19 Jul 2018 03:03:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfIvGFt/Ft1/hMHAOFgAsCgE/wfw5EJd0soBf3qlocDraUzfBeLN+keoIBh5VBC96tjI7b2 X-Received: by 2002:a50:a93c:: with SMTP id l57-v6mr9966677edc.229.1531994610849; Thu, 19 Jul 2018 03:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531994610; cv=none; d=google.com; s=arc-20160816; b=x5zLcY+xPC+WrMp3iRM3dyQzi7ArV5b4KiPAMfxPZDzN2b3ZLwx6tCCucLQoYbqJgc uKYr/SXgaNhK2H+71WSrCXKrH8doOM15vnYYc/kODzh8ze2kIKOuMQNhDnRy3SRwyXvQ 6cLfjSHtrZgzLsl8kZ6+NkAYvljjXI19RNx5NL3ZF2BDH+UrFFRURDlxFuT6H+OjULuV Wn8QsX801i/6ZJxZf/57L8bQsCRbVBePRQxoGjZpjOycDdldtC1Owi5j75kDnkTAGNWa P8yRLbkYWt7phSxygbcT4UjzJTtdd8dsKEy0vQ6xnKRwpTD6rFRgeg23MC6UnIiQ+p2J Fehg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=fEE2p3+0RuZvHY1cKiI1BY5pfPvI4F7kIJkH/wq4qpM=; b=qPYgtn8RhYFZNSrZSQoWPgh3HQ7pqlYEtY8p9sgDo2vpJJuJtnDcfdRQF7AYdhWT7T TD+7Pf9+NNBtCYZN82CCNMF34rNa+XEazTcwaesq5oV+6L+H4gvnITLNqReMJpkQ4lBu kV17ngRzgrcIdog9lionTvp/yw9JI3WCMpcxJpqlKEPMwE87+2+5wW5QUIKMCEDjMFfe E2wnN8CAZarpKpmjA57tq+6N7Gkga+sL6UDGSz8XNy3G0jm408vJFvIs3P1qiyl23j8W hcbC2eUmugY8VVwqsb2/oljItnDfFXiu1QhDrLRnPYfXk8mRJR0s4EeVZ0fmwfAKG/SF Rg8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id d4-v6si3656205edq.426.2018.07.19.03.03.30; Thu, 19 Jul 2018 03:03:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 64285C21FD4; Thu, 19 Jul 2018 10:03:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E2D74C21E88; Thu, 19 Jul 2018 10:02:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9F9DFC21E88; Thu, 19 Jul 2018 10:02:40 +0000 (UTC) Received: from esa4.microchip.iphmx.com (esa4.microchip.iphmx.com [68.232.154.123]) by lists.denx.de (Postfix) with ESMTPS id 7FACCC21C27 for ; Thu, 19 Jul 2018 10:02:37 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,374,1526367600"; d="scan'208";a="16185309" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Jul 2018 03:02:35 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Thu, 19 Jul 2018 03:02:34 -0700 From: Eugen Hristev To: Date: Thu, 19 Jul 2018 12:57:49 +0300 Message-ID: <1531994288-19423-2-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> References: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Cc: maxime.ripard@bootlin.com, Maxime Ripard , nicolas.ferre@microchip.com Subject: [U-Boot] [PATCH 01/20] w1: Add 1-Wire uclass X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Maxime Ripard We might want to use 1-Wire devices connected on boards such as EEPROMs in U-Boot. Provide a framework to be able to do that. Signed-off-by: Maxime Ripard [eugen.hristev@microchip.com: fixed small issues and rebased] Signed-off-by: Eugen Hristev --- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/w1/Kconfig | 18 ++++ drivers/w1/Makefile | 1 + drivers/w1/w1-uclass.c | 268 +++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/w1.h | 48 +++++++++ 7 files changed, 339 insertions(+) create mode 040000 drivers/w1 create mode 100644 drivers/w1/Kconfig create mode 100644 drivers/w1/Makefile create mode 100644 drivers/w1/w1-uclass.c create mode 100644 include/w1.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 9e21b28..2cae829 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -102,6 +102,8 @@ source "drivers/usb/Kconfig" source "drivers/video/Kconfig" +source "drivers/w1/Kconfig" + source "drivers/watchdog/Kconfig" config PHYS_TO_BUS diff --git a/drivers/Makefile b/drivers/Makefile index a213ea9..728380b 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -101,6 +101,7 @@ obj-y += input/ obj-y += soc/ obj-$(CONFIG_REMOTEPROC) += remoteproc/ obj-y += thermal/ +obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_MACH_PIC32) += ddr/microchip/ endif diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig new file mode 100644 index 0000000..64b27c6 --- /dev/null +++ b/drivers/w1/Kconfig @@ -0,0 +1,18 @@ +# +# W1 subsystem configuration +# + +menu "1-Wire support" + +config W1 + bool "Enable 1-wire controllers support" + default no + depends on DM + help + Support for the Dallas 1-Wire bus. + +if W1 + +endif + +endmenu diff --git a/drivers/w1/Makefile b/drivers/w1/Makefile new file mode 100644 index 0000000..f81693b --- /dev/null +++ b/drivers/w1/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_W1) += w1-uclass.o diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c new file mode 100644 index 0000000..cfddda3 --- /dev/null +++ b/drivers/w1/w1-uclass.c @@ -0,0 +1,268 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2015 Free Electrons + * Copyright (c) 2015 NextThing Co. + * + * Maxime Ripard + * + */ + +#include +#include +#include + +#include + +#define W1_MATCH_ROM 0x55 +#define W1_SKIP_ROM 0xcc +#define W1_SEARCH 0xf0 + +int w1_init(void); + +struct w1_bus { + u64 search_id; +}; + +struct w1_device { + u64 id; +}; + +static int w1_new_device(struct udevice *bus, u64 id) +{ + struct w1_driver_entry *start, *entry; + int n_ents, ret = -ENODEV; + u8 family = id & 0xff; + + debug("%s: Detected new device 0x%llx (family 0x%x)\n", + bus->name, id, family); + + start = ll_entry_start(struct w1_driver_entry, w1_driver_entry); + n_ents = ll_entry_count(struct w1_driver_entry, w1_driver_entry); + + for (entry = start; entry != start + n_ents; entry++) { + const struct driver *drv; + struct w1_device *w1; + struct udevice *dev; + + if (entry->family != family) + continue; + + drv = entry->driver; + ret = device_bind(bus, drv, drv->name, NULL, -1, + &dev); + if (ret) + goto error; + + debug("%s: Match found: %s\n", __func__, drv->name); + + w1 = dev_get_parent_platdata(dev); + w1->id = id; + + return 0; + } + +error: + debug("%s: No matches found: error %d\n", __func__, ret); + return ret; +} + +static int w1_enumerate(struct udevice *bus) +{ + const struct w1_ops *ops = device_get_ops(bus); + struct w1_bus *w1 = dev_get_uclass_priv(bus); + u64 last_rn, rn = w1->search_id, tmp64; + bool last_device = false; + int search_bit, desc_bit = 64; + int last_zero = -1; + u8 triplet_ret = 0; + int i; + + if (!ops->reset || !ops->write_byte || !ops->triplet) + return -ENOSYS; + + while (!last_device) { + last_rn = rn; + rn = 0; + + /* + * Reset bus and all 1-wire device state machines + * so they can respond to our requests. + * + * Return 0 - device(s) present, 1 - no devices present. + */ + if (ops->reset(bus)) { + debug("%s: No devices present on the wire.\n", + __func__); + break; + } + + /* Start the search */ + ops->write_byte(bus, W1_SEARCH); + for (i = 0; i < 64; ++i) { + /* Determine the direction/search bit */ + if (i == desc_bit) + /* took the 0 path last time, so take the 1 path */ + search_bit = 1; + else if (i > desc_bit) + /* take the 0 path on the next branch */ + search_bit = 0; + else + search_bit = ((last_rn >> i) & 0x1); + + /* Read two bits and write one bit */ + triplet_ret = ops->triplet(bus, search_bit); + + /* quit if no device responded */ + if ((triplet_ret & 0x03) == 0x03) + break; + + /* If both directions were valid, and we took the 0 path... */ + if (triplet_ret == 0) + last_zero = i; + + /* extract the direction taken & update the device number */ + tmp64 = (triplet_ret >> 2); + rn |= (tmp64 << i); + } + + /* last device or error, aborting here */ + if ((triplet_ret & 0x03) == 0x03) + last_device = true; + + if ((triplet_ret & 0x03) != 0x03) { + if (desc_bit == last_zero || last_zero < 0) { + last_device = 1; + w1->search_id = 0; + } else { + w1->search_id = rn; + } + desc_bit = last_zero; + + w1_new_device(bus, rn); + } + } + + return 0; +} + +int w1_get_bus(int busnum, struct udevice **busp) +{ + int ret; + + w1_init(); + + ret = uclass_get_device_by_seq(UCLASS_W1, busnum, busp); + if (ret) { + debug("Cannot find w1 bus %d\n", busnum); + return ret; + } + + return 0; +} + +u8 w1_get_device_family(struct udevice *dev) +{ + struct w1_device *w1 = dev_get_parent_platdata(dev); + + return w1->id & 0xff; +} + +int w1_reset_select(struct udevice *dev) +{ + struct w1_device *w1 = dev_get_parent_platdata(dev); + struct udevice *bus = dev_get_parent(dev); + const struct w1_ops *ops = device_get_ops(bus); + int i; + + if (!ops->reset || !ops->write_byte) + return -ENOSYS; + + ops->reset(bus); + + ops->write_byte(bus, W1_MATCH_ROM); + + for (i = 0; i < sizeof(w1->id); i++) + ops->write_byte(bus, (w1->id >> (i * 8)) & 0xff); + + return 0; +} + +int w1_read_byte(struct udevice *dev) +{ + struct udevice *bus = dev_get_parent(dev); + const struct w1_ops *ops = device_get_ops(bus); + + if (!ops->read_byte) + return -ENOSYS; + + return ops->read_byte(bus); +} + +int w1_read_buf(struct udevice *dev, u8 *buf, unsigned int count) +{ + int i, ret; + + for (i = 0; i < count; i++) { + ret = w1_read_byte(dev); + if (ret < 0) + return ret; + + buf[i] = ret & 0xff; + } + + return 0; +} + +int w1_write_byte(struct udevice *dev, u8 byte) +{ + struct udevice *bus = dev_get_parent(dev); + const struct w1_ops *ops = device_get_ops(bus); + + if (!ops->write_byte) + return -ENOSYS; + + ops->write_byte(bus, byte); + + return 0; +} + +static int w1_post_probe(struct udevice *bus) +{ + w1_enumerate(bus); + + return 0; +} + +int w1_init(void) +{ + struct udevice *bus; + struct uclass *uc; + int ret; + + ret = uclass_get(UCLASS_W1, &uc); + if (ret) + return ret; + + uclass_foreach_dev(bus, uc) { + ret = device_probe(bus); + if (ret == -ENODEV) { /* No such device. */ + printf("W1 controller not available.\n"); + continue; + } + + if (ret) { /* Other error. */ + printf("W1 controller probe failed, error %d\n", ret); + continue; + } + } + return 0; +} + +UCLASS_DRIVER(w1) = { + .name = "w1", + .id = UCLASS_W1, + .flags = DM_UC_FLAG_SEQ_ALIAS, + .per_device_auto_alloc_size = sizeof(struct w1_bus), + .per_child_platdata_auto_alloc_size = sizeof(struct w1_device), + .post_probe = w1_post_probe, +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index d7f9df3..8eca9dc 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -89,6 +89,7 @@ enum uclass_id { UCLASS_VIDEO, /* Video or LCD device */ UCLASS_VIDEO_BRIDGE, /* Video bridge, e.g. DisplayPort to LVDS */ UCLASS_VIDEO_CONSOLE, /* Text console driver for video device */ + UCLASS_W1, /* Dallas 1-Wire bus */ UCLASS_WDT, /* Watchdot Timer driver */ UCLASS_COUNT, diff --git a/include/w1.h b/include/w1.h new file mode 100644 index 0000000..1ca1740 --- /dev/null +++ b/include/w1.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2015 Free Electrons + * Copyright (c) 2015 NextThing Co + * + */ + +#ifndef __W1_H +#define __W1_H + +#include + +#define W1_FAMILY_DS24B33 0x23 +#define W1_FAMILY_DS2431 0x2d + +/** + * struct w1_driver_entry - Matches a driver to its w1 family + * @driver: Driver to use + * @family: W1 family handled by this driver + */ +struct w1_driver_entry { + struct driver *driver; + u8 family; +}; + +#define U_BOOT_W1_DEVICE(__name, __family) \ + ll_entry_declare(struct w1_driver_entry, __name, w1_driver_entry) = { \ + .driver = llsym(struct driver, __name, driver), \ + .family = __family, \ + } + +struct w1_ops { + u8 (*read_byte)(struct udevice *dev); + bool (*reset)(struct udevice *dev); + u8 (*triplet)(struct udevice *dev, bool bdir); + void (*write_byte)(struct udevice *dev, u8 byte); +}; + +int w1_get_bus(int busnum, struct udevice **busp); +u8 w1_get_device_family(struct udevice *dev); + +int w1_read_buf(struct udevice *dev, u8 *buf, unsigned int count); +int w1_read_byte(struct udevice *dev); +int w1_reset_select(struct udevice *dev); +int w1_write_buf(struct udevice *dev, u8 *buf, unsigned int count); +int w1_write_byte(struct udevice *dev, u8 byte); + +#endif From patchwork Thu Jul 19 09:57:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 142333 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1544607ljj; Thu, 19 Jul 2018 03:04:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfA4AsLYevhcxAR6jZ9rvUGlGBr6keebj1FVs/4fmo7yMULrIlohfhtEM8IuZy7fFoEr/Nc X-Received: by 2002:a50:8607:: with SMTP id o7-v6mr10350805edo.243.1531994696679; Thu, 19 Jul 2018 03:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531994696; cv=none; d=google.com; s=arc-20160816; b=PzR5hSqRzg0TpAm0Fv69s/2EBNrf3AOxPIDT9QLSR6EbDfjaR7kNb5M2LZNS9WSMv5 OGUJLOwKkLMbjx0DbtcbSz/R5/0KeolZervbXQeYx9cMQsjHQyj5dDnCXN4BeIDC1pT1 51j41dCfVmWBQDL8XG8MCre89/3/Pq3S0ar2uhuXbqer7RdOzBBJ24aAF0/VrlUuWW8W vtgTI0I3CBBvtBRFT4mnVqeKzV/ShkLDd6JmH/mC99oWx5t3NPb8qLzh+iIkH+aegIUs AWnDZK5KrhDrTwqeTSUaIS6tj0tHe5AXIavXLFQNtzhQduZXeY05q8f3ic8bJ1+f8wuB IhzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=THLj9ue7YHsM5qqrYAGIx5J4y6EdnEs5mneFwjqlfzQ=; b=cnJK1gF//iuvbViNRKmFSFVZ778uTy9QdNmHgdUhqCDcp6Xdk7Gt8hKY5O4KSd8JWM KVYrX3rz3FT0wPH3j0q9fNdf3UfAC2vYTkCwLgEOrUf6gAKTKmPzG6vJh9TGFOfSWxKQ pKk4EmHeGyBMm19QOq+VQcr4JOvk5+Pp+oKPkyrv3ArSCrKg7rju7rBvg7WSNHZmjW+5 tq3963Uf6zHw6EFwXMHWiBa1hz7CVzxUnXYts/zuntQbJ/wLx/8f/nv3I8Gdy1t+mR3N X9W2dDzcwZwAAkFKeFwVE2o/77iP6oTN4q5nqeYkRwZJwz72FwvIWeSyj5rgQf7C7mg8 gLGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 92-v6si1184509edg.337.2018.07.19.03.04.56; Thu, 19 Jul 2018 03:04:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 3AF9AC21E57; Thu, 19 Jul 2018 10:04:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DFB49C21E3B; Thu, 19 Jul 2018 10:02:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E4821C21E5B; Thu, 19 Jul 2018 10:02:42 +0000 (UTC) Received: from esa6.microchip.iphmx.com (esa6.microchip.iphmx.com [216.71.154.253]) by lists.denx.de (Postfix) with ESMTPS id 0479CC21C4A for ; Thu, 19 Jul 2018 10:02:37 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,374,1526367600"; d="scan'208";a="13758110" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Jul 2018 03:02:37 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Thu, 19 Jul 2018 03:02:36 -0700 From: Eugen Hristev To: Date: Thu, 19 Jul 2018 12:57:50 +0300 Message-ID: <1531994288-19423-3-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> References: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Cc: maxime.ripard@bootlin.com, Maxime Ripard , nicolas.ferre@microchip.com Subject: [U-Boot] [PATCH 02/20] w1: Add 1-Wire gpio driver X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Maxime Ripard Add a bus driver for bitbanging a 1-Wire bus over a GPIO. Signed-off-by: Maxime Ripard [eugen.hristev@microchip.com: addressed review comments] Signed-off-by: Eugen Hristev --- drivers/w1/Kconfig | 7 +++ drivers/w1/Makefile | 2 + drivers/w1/w1-gpio.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 drivers/w1/w1-gpio.c diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig index 64b27c6..d6e0457 100644 --- a/drivers/w1/Kconfig +++ b/drivers/w1/Kconfig @@ -13,6 +13,13 @@ config W1 if W1 +config W1_GPIO + bool "Enable 1-wire GPIO bitbanging" + default no + depends on DM_GPIO + help + Emulate a 1-wire bus using a GPIO. + endif endmenu diff --git a/drivers/w1/Makefile b/drivers/w1/Makefile index f81693b..7fd8697 100644 --- a/drivers/w1/Makefile +++ b/drivers/w1/Makefile @@ -1 +1,3 @@ obj-$(CONFIG_W1) += w1-uclass.o + +obj-$(CONFIG_W1_GPIO) += w1-gpio.o diff --git a/drivers/w1/w1-gpio.c b/drivers/w1/w1-gpio.c new file mode 100644 index 0000000..941ab2c --- /dev/null +++ b/drivers/w1/w1-gpio.c @@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2015 Free Electrons + * Copyright (c) 2015 NextThing Co + * + * Maxime Ripard + * + */ + +#include +#include +#include + +#include + +#define W1_TIMING_A 6 +#define W1_TIMING_B 64 +#define W1_TIMING_C 60 +#define W1_TIMING_D 10 +#define W1_TIMING_E 9 +#define W1_TIMING_F 55 +#define W1_TIMING_G 0 +#define W1_TIMING_H 480 +#define W1_TIMING_I 70 +#define W1_TIMING_J 410 + +struct w1_gpio_pdata { + struct gpio_desc gpio; + u64 search_id; +}; + +static bool w1_gpio_read_bit(struct udevice *dev) +{ + struct w1_gpio_pdata *pdata = dev_get_platdata(dev); + int val; + + dm_gpio_set_dir_flags(&pdata->gpio, GPIOD_IS_OUT); + udelay(W1_TIMING_A); + + dm_gpio_set_dir_flags(&pdata->gpio, GPIOD_IS_IN); + udelay(W1_TIMING_E); + + val = dm_gpio_get_value(&pdata->gpio); + if (val < 0) + debug("error in retrieving GPIO value"); + udelay(W1_TIMING_F); + + return val; +} + +static u8 w1_gpio_read_byte(struct udevice *dev) +{ + int i; + u8 ret = 0; + + for (i = 0; i < 8; ++i) + ret |= (w1_gpio_read_bit(dev) ? 1 : 0) << i; + + return ret; +} + +static void w1_gpio_write_bit(struct udevice *dev, bool bit) +{ + struct w1_gpio_pdata *pdata = dev_get_platdata(dev); + + dm_gpio_set_dir_flags(&pdata->gpio, GPIOD_IS_OUT); + + bit ? udelay(W1_TIMING_A) : udelay(W1_TIMING_C); + + dm_gpio_set_value(&pdata->gpio, 1); + + bit ? udelay(W1_TIMING_B) : udelay(W1_TIMING_D); +} + +static void w1_gpio_write_byte(struct udevice *dev, u8 byte) +{ + int i; + + for (i = 0; i < 8; ++i) + w1_gpio_write_bit(dev, (byte >> i) & 0x1); +} + +static bool w1_gpio_reset(struct udevice *dev) +{ + struct w1_gpio_pdata *pdata = dev_get_platdata(dev); + int val; + + dm_gpio_set_dir_flags(&pdata->gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); + udelay(W1_TIMING_G); + + dm_gpio_set_value(&pdata->gpio, 0); + udelay(W1_TIMING_H); + + dm_gpio_set_dir_flags(&pdata->gpio, GPIOD_IS_IN); + udelay(W1_TIMING_I); + + val = dm_gpio_get_value(&pdata->gpio); + if (val < 0) + debug("error in retrieving GPIO value"); + udelay(W1_TIMING_J); + + return val; +} + +static u8 w1_gpio_triplet(struct udevice *dev, bool bdir) +{ + u8 id_bit = w1_gpio_read_bit(dev); + u8 comp_bit = w1_gpio_read_bit(dev); + u8 retval; + + if (id_bit && comp_bit) + return 0x03; /* error */ + + if (!id_bit && !comp_bit) { + /* Both bits are valid, take the direction given */ + retval = bdir ? 0x04 : 0; + } else { + /* Only one bit is valid, take that direction */ + bdir = id_bit; + retval = id_bit ? 0x05 : 0x02; + } + + w1_gpio_write_bit(dev, bdir); + return retval; +} + +static const struct w1_ops w1_gpio_ops = { + .read_byte = w1_gpio_read_byte, + .reset = w1_gpio_reset, + .triplet = w1_gpio_triplet, + .write_byte = w1_gpio_write_byte, +}; + +static int w1_gpio_ofdata_to_platdata(struct udevice *dev) +{ + struct w1_gpio_pdata *pdata = dev_get_platdata(dev); + int ret; + + ret = gpio_request_by_name(dev, "gpios", 0, &pdata->gpio, 0); + if (ret < 0) + printf("Error claiming GPIO %d\n", ret); + + return ret; +}; + +static const struct udevice_id w1_gpio_id[] = { + { "w1-gpio", 0 }, + { }, +}; + +U_BOOT_DRIVER(w1_gpio_drv) = { + .id = UCLASS_W1, + .name = "w1_gpio_drv", + .of_match = w1_gpio_id, + .ofdata_to_platdata = w1_gpio_ofdata_to_platdata, + .ops = &w1_gpio_ops, + .platdata_auto_alloc_size = sizeof(struct w1_gpio_pdata), +}; From patchwork Thu Jul 19 09:57:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 142334 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1547795ljj; Thu, 19 Jul 2018 03:08:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcrvcEn25Ak9C12mMfqhhihjMolV1sQ/VHtZkr4cd0aM090QgtRDjpgGpCUVIQrq4lwSOB5 X-Received: by 2002:a50:b2c6:: with SMTP id p64-v6mr10701495edd.293.1531994908200; Thu, 19 Jul 2018 03:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531994908; cv=none; d=google.com; s=arc-20160816; b=UwabbHyrocX1WFvnrN9iIX9a7dpxGSswEkrBTro9aDl4ht/1rIppsw5gBnJ+1dW6za SbRY4hdBiLvYmgz0NP7hh8wZ6DdMXZJPa+TqF44y5YuIswVNQ8ni3xmi/LNpbvsS/Pww 7IFF+EAkvcfYQHJGed0m0Uo+xpX3ccURwWM56lYSivH45aTMqJK2Yo77QCVkJ/L5wBfF 9C8iA+9QNIcvbZPFrmeTZxVfwZsHNSSZdZ5pQc+Gk7CFlrONZmJp1GWi7YhFwUWgSe8U HnxjrvtEXXMVYjiZBW2S4dZ6U9AzO6Jaq8IkyeJVXXvjhj6vGhc9nBOQgBSZvCCwuZsZ W/oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=FWNJ2Vf6/PuDNBmFaEZxOaPMnhrJxc2y9IWIWgXh+XU=; b=xUaRoeYE7+OU58d4tMVWFVAPyBU+U3luWQgdvn4QhYOtpm2ORCYl4Bj7aOVPE8Nj8C RSmBSEbn3LWIQejKgPjuNw1W7ZRbEvZ9oMc6h0hupF2CTZIH86h4GX3qEUL0IRxx8wJt mYQOPyDcm8vXtgrKZ8iCfdDMAlaSQXW6FTNDd3OP7OS/A9y0yj5sz0rlWnWg4cZb8CN8 UhD9RYww93NmlIdTQ/K2B2sWlIjnk4Jl3LfRTcYirnf4S1lXBaycTfpSmbDp5A9k8gCi 4Mo9lvU6urUkGu4X5Uj481ilkOvXBDfV9FIpHKvjU2Ext5YTXg7Cuxf/CiSWB1ixbvfb GH/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id b15-v6si1497738edm.391.2018.07.19.03.08.27; Thu, 19 Jul 2018 03:08:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id BEA2BC21E3B; Thu, 19 Jul 2018 10:07:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A0972C21F20; Thu, 19 Jul 2018 10:03:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3759BC21EF2; Thu, 19 Jul 2018 10:02:46 +0000 (UTC) Received: from esa6.microchip.iphmx.com (esa6.microchip.iphmx.com [216.71.154.253]) by lists.denx.de (Postfix) with ESMTPS id 4ADDFC21E7F for ; Thu, 19 Jul 2018 10:02:41 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,374,1526367600"; d="scan'208";a="13758112" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Jul 2018 03:02:40 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Thu, 19 Jul 2018 03:02:40 -0700 From: Eugen Hristev To: Date: Thu, 19 Jul 2018 12:57:52 +0300 Message-ID: <1531994288-19423-5-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> References: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Cc: maxime.ripard@bootlin.com, Maxime Ripard , nicolas.ferre@microchip.com Subject: [U-Boot] [PATCH 04/20] W1-EEPROM: Add an W1-EEPROM uclass for 1 wire EEPROMs X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Maxime Ripard We might want to access data stored onto one wire EEPROMs. Create a framework to provide a consistent API. Signed-off-by: Maxime Ripard [eugen.hristev@microchip.com: reworked patch] Signed-off-by: Eugen Hristev --- drivers/Kconfig | 2 ++ drivers/Makefile | 1 + drivers/w1-eeprom/Kconfig | 17 +++++++++++ drivers/w1-eeprom/Makefile | 2 ++ drivers/w1-eeprom/w1-eeprom-uclass.c | 56 ++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/w1-eeprom.h | 28 ++++++++++++++++++ 7 files changed, 107 insertions(+) create mode 040000 drivers/w1-eeprom create mode 100644 drivers/w1-eeprom/Kconfig create mode 100644 drivers/w1-eeprom/Makefile create mode 100644 drivers/w1-eeprom/w1-eeprom-uclass.c create mode 100644 include/w1-eeprom.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 2cae829..386af75 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -104,6 +104,8 @@ source "drivers/video/Kconfig" source "drivers/w1/Kconfig" +source "drivers/w1-eeprom/Kconfig" + source "drivers/watchdog/Kconfig" config PHYS_TO_BUS diff --git a/drivers/Makefile b/drivers/Makefile index 728380b..de67a17 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -102,6 +102,7 @@ obj-y += soc/ obj-$(CONFIG_REMOTEPROC) += remoteproc/ obj-y += thermal/ obj-$(CONFIG_W1) += w1/ +obj-$(CONFIG_W1_EEPROM) += w1-eeprom/ obj-$(CONFIG_MACH_PIC32) += ddr/microchip/ endif diff --git a/drivers/w1-eeprom/Kconfig b/drivers/w1-eeprom/Kconfig new file mode 100644 index 0000000..d5ddc80 --- /dev/null +++ b/drivers/w1-eeprom/Kconfig @@ -0,0 +1,17 @@ +# +# EEPROM subsystem configuration +# + +menu "1-wire EEPROM support" + +config W1_EEPROM + bool "Enable support for EEPROMs on 1wire interface" + depends on DM + help + Support for the EEPROMs connected on 1-wire Dallas protocol interface + +if W1_EEPROM + +endif + +endmenu diff --git a/drivers/w1-eeprom/Makefile b/drivers/w1-eeprom/Makefile new file mode 100644 index 0000000..b72950e --- /dev/null +++ b/drivers/w1-eeprom/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_W1_EEPROM) += w1-eeprom-uclass.o + diff --git a/drivers/w1-eeprom/w1-eeprom-uclass.c b/drivers/w1-eeprom/w1-eeprom-uclass.c new file mode 100644 index 0000000..4176baf --- /dev/null +++ b/drivers/w1-eeprom/w1-eeprom-uclass.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2015 Free Electrons + * Copyright (c) 2015 NextThing Co. + * + * Maxime Ripard + * + */ + +#include +#include +#include + +#include + +int w1_eeprom_read_buf(struct udevice *dev, unsigned int offset, + u8 *buf, unsigned int count) +{ + const struct w1_eeprom_ops *ops = device_get_ops(dev); + + if (!ops->read_buf) + return -ENOSYS; + + return ops->read_buf(dev, offset, buf, count); +} + +UCLASS_DRIVER(w1_eeprom) = { + .name = "w1_eeprom", + .id = UCLASS_W1_EEPROM, +}; + +int w1_eeprom_dm_init(void) +{ + struct udevice *bus; + struct uclass *uc; + int ret; + + ret = uclass_get(UCLASS_W1_EEPROM, &uc); + if (ret) + return ret; + + uclass_foreach_dev(bus, uc) { + ret = device_probe(bus); + if (ret == -ENODEV) { /* No such device. */ + debug("W1_EEPROM not available.\n"); + continue; + } + + if (ret) { /* Other error. */ + printf("W1_EEPROM probe failed, error %d\n", ret); + continue; + } + } + + return 0; +} diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 8eca9dc..06ff339 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -90,6 +90,7 @@ enum uclass_id { UCLASS_VIDEO_BRIDGE, /* Video bridge, e.g. DisplayPort to LVDS */ UCLASS_VIDEO_CONSOLE, /* Text console driver for video device */ UCLASS_W1, /* Dallas 1-Wire bus */ + UCLASS_W1_EEPROM, /* one-wire EEPROMs */ UCLASS_WDT, /* Watchdot Timer driver */ UCLASS_COUNT, diff --git a/include/w1-eeprom.h b/include/w1-eeprom.h new file mode 100644 index 0000000..7c9dd96 --- /dev/null +++ b/include/w1-eeprom.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2015 Free Electrons + * Copyright (c) 2015 NextThing Co + * Copyright (c) 2018 Microchip Technology, Inc. + * + */ + +#ifndef __W1_EEPROM_H +#define __W1_EEPROM_H + +struct udevice; + +struct w1_eeprom_ops { + /* + * Reads a buff from the given EEPROM memory, starting at + * given offset and place the results into the given buffer. + * Should read given count of bytes. + * Should return 0 on success, and normal error.h on error + */ + int (*read_buf)(struct udevice *dev, unsigned int offset, + u8 *buf, unsigned int count); +}; + +int w1_eeprom_read_buf(struct udevice *dev, unsigned int offset, + u8 *buf, unsigned int count); + +#endif From patchwork Thu Jul 19 09:57:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 142335 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1551213ljj; Thu, 19 Jul 2018 03:12:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpewZEzr4+4fxE56kjyzTmuoJQ1lM0n77jliCKzZaLexYZRHL6AgCOK2DBgscYgm2nf68mcW X-Received: by 2002:a50:b2a6:: with SMTP id p35-v6mr10765360edd.215.1531995136799; Thu, 19 Jul 2018 03:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531995136; cv=none; d=google.com; s=arc-20160816; b=xTwuiQvSxZwwovQYYp+6E85yA13QkmmocQ9319PxF8smMod5htDBFoQxxpzLx8Cnf5 pJTGPyaoiPR2IpPLDY4jqn26QiWHmn/zouDdQifT3yp7lNThmcuSXkmgKKPDnNhHMtPM GFG3n380VdUpm2V2bU1q9swablXwbezI/EPTTQj5mpaz4euwDwUM7Y/NgucO538FAoC9 YjIx9rgSXfy2AYZ3M7cyGRW+s96yGJlM3B7Xije3XQVCTRYEgQfUAKdTzOcuRzDMHr0C FQrIB/15QT1AMLaWChT7eZx7Rm01+zBfpr3k14appP2ZipCKwHBUxVOrWvJ1FKc2f7YL /HTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=pJB7Jnu9V8o4hmIxMJShMsf+mpRufajlq6P05J8f3e0=; b=NlcgIOBzCxCkXrafSfeG3/VK0faNUhaO69X3czugFrz+0unD/Cwum2rbooS+M04Swv LGT55Kh7rZE7dLwb9O6Kh/dGlZDegfZ5792eT7p56zyP4GwMzYlkQcZ4wqtVlH3ufVOY nT19CPujgRjc5QmVK2HJTNW9VwntYEF6epl4DQvr3ixRoDYcbo/6JyReEg02uxs9JqpB 2saZ7pICDPw8VnhLC6T/qR2oV1pDF/TClhQ2P1+yakV/5+MmNLhy+poXpTDN0cy/5i+f 7Dgc/lNjRJKxWfAC1E+Z0NpnsTLL3tjkPBOhbATopeGdlDS0Dii0KLovU5+X3UxjDxVZ NfTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id l22-v6si4211096eda.370.2018.07.19.03.12.16; Thu, 19 Jul 2018 03:12:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 4F904C21E3B; Thu, 19 Jul 2018 10:09:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BC51FC21E88; Thu, 19 Jul 2018 10:03:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 22212C21F63; Thu, 19 Jul 2018 10:02:48 +0000 (UTC) Received: from esa4.microchip.iphmx.com (esa4.microchip.iphmx.com [68.232.154.123]) by lists.denx.de (Postfix) with ESMTPS id 38BC4C21EA1 for ; Thu, 19 Jul 2018 10:02:43 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,374,1526367600"; d="scan'208";a="16185311" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Jul 2018 03:02:42 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Thu, 19 Jul 2018 03:02:42 -0700 From: Eugen Hristev To: Date: Thu, 19 Jul 2018 12:57:53 +0300 Message-ID: <1531994288-19423-6-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> References: <1531994288-19423-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Cc: maxime.ripard@bootlin.com, Maxime Ripard , nicolas.ferre@microchip.com Subject: [U-Boot] [PATCH 05/20] W1-EEPROM: add support for Maxim DS24 eeprom families X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Maxime Ripard Add a driver that supports Maxim 1 wire EEPROMs families DS24B33 and DS2431. Can be extended for other families as well. Signed-off-by: Maxime Ripard [eugen.hristev@microchip.com: reworked driver] Signed-off-by: Eugen Hristev --- drivers/w1-eeprom/Kconfig | 6 ++++++ drivers/w1-eeprom/Makefile | 2 ++ drivers/w1-eeprom/ds24xxx.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 drivers/w1-eeprom/ds24xxx.c diff --git a/drivers/w1-eeprom/Kconfig b/drivers/w1-eeprom/Kconfig index d5ddc80..20ec549 100644 --- a/drivers/w1-eeprom/Kconfig +++ b/drivers/w1-eeprom/Kconfig @@ -12,6 +12,12 @@ config W1_EEPROM if W1_EEPROM +config W1_EEPROM_DS24XXX + bool "Enable Maxim DS24 families EEPROM support" + depends on W1 + help + Maxim DS24 EEPROMs 1-Wire EEPROM support + endif endmenu diff --git a/drivers/w1-eeprom/Makefile b/drivers/w1-eeprom/Makefile index b72950e..3f4aa13 100644 --- a/drivers/w1-eeprom/Makefile +++ b/drivers/w1-eeprom/Makefile @@ -1,2 +1,4 @@ obj-$(CONFIG_W1_EEPROM) += w1-eeprom-uclass.o +obj-$(CONFIG_W1_EEPROM_DS24XXX) += ds24xxx.o + diff --git a/drivers/w1-eeprom/ds24xxx.c b/drivers/w1-eeprom/ds24xxx.c new file mode 100644 index 0000000..423aa99 --- /dev/null +++ b/drivers/w1-eeprom/ds24xxx.c @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2015 Free Electrons + * Copyright (c) 2015 NextThing Co + * Copyright (c) 2018 Microchip Technology, Inc. + * + */ + +#include +#include +#include +#include +#include + +#define W1_F2D_READ_EEPROM 0xf0 + +static int ds24xxx_read_buf(struct udevice *dev, unsigned int offset, + u8 *buf, unsigned int count) +{ + w1_reset_select(dev); + + w1_write_byte(dev, W1_F2D_READ_EEPROM); + w1_write_byte(dev, offset & 0xff); + w1_write_byte(dev, offset >> 8); + + return w1_read_buf(dev, buf, count); +} + +static const struct w1_eeprom_ops ds24xxx_ops = { + .read_buf = ds24xxx_read_buf, +}; + +U_BOOT_DRIVER(ds24b33) = { + .name = "ds24b33", + .id = UCLASS_W1_EEPROM, + .ops = &ds24xxx_ops, +}; + +U_BOOT_DRIVER(ds2431) = { + .name = "ds2431", + .id = UCLASS_W1_EEPROM, + .ops = &ds24xxx_ops, +}; + +U_BOOT_W1_DEVICE(ds24b33, W1_FAMILY_DS24B33); +U_BOOT_W1_DEVICE(ds2431, W1_FAMILY_DS2431);