uboot/drivers/w1-eeprom/ds24xxx.c
<<
>>
Prefs
   1// SPDX-License-Identifier:     GPL-2.0+
   2/*
   3 *
   4 * Copyright (c) 2015 Free Electrons
   5 * Copyright (c) 2015 NextThing Co
   6 * Copyright (c) 2018 Microchip Technology, Inc.
   7 *
   8 */
   9
  10#include <common.h>
  11#include <linux/err.h>
  12#include <dm.h>
  13#include <w1-eeprom.h>
  14#include <w1.h>
  15
  16#define W1_F2D_READ_EEPROM      0xf0
  17
  18static int ds24xxx_read_buf(struct udevice *dev, unsigned int offset,
  19                            u8 *buf, unsigned int count)
  20{
  21        w1_reset_select(dev);
  22
  23        w1_write_byte(dev, W1_F2D_READ_EEPROM);
  24        w1_write_byte(dev, offset & 0xff);
  25        w1_write_byte(dev, offset >> 8);
  26
  27        return w1_read_buf(dev, buf, count);
  28}
  29
  30static int ds24xxx_probe(struct udevice *dev)
  31{
  32        struct w1_device *w1;
  33
  34        w1 = dev_get_parent_plat(dev);
  35        w1->id = 0;
  36        return 0;
  37}
  38
  39static const struct w1_eeprom_ops ds24xxx_ops = {
  40        .read_buf       = ds24xxx_read_buf,
  41};
  42
  43static const struct udevice_id ds24xxx_id[] = {
  44        { .compatible = "maxim,ds24b33", .data = W1_FAMILY_DS24B33 },
  45        { .compatible = "maxim,ds2431", .data = W1_FAMILY_DS2431 },
  46        { },
  47};
  48
  49U_BOOT_DRIVER(ds24xxx) = {
  50        .name           = "ds24xxx",
  51        .id             = UCLASS_W1_EEPROM,
  52        .of_match       = ds24xxx_id,
  53        .ops            = &ds24xxx_ops,
  54        .probe          = ds24xxx_probe,
  55};
  56
  57u8 family_supported[] = {
  58        W1_FAMILY_DS24B33,
  59        W1_FAMILY_DS2431,
  60};
  61
  62U_BOOT_W1_DEVICE(ds24xxx, family_supported);
  63