uboot/drivers/hwmon/adt7460.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2008
   3 * Ricado Ribalda-Universidad Autonoma de Madrid, ricardo.ribalda@uam.es
   4 * This work has been supported by: QTechnology  http://qtec.com/
   5 * SPDX-License-Identifier:     GPL-2.0+
   6 */
   7
   8#include <common.h>
   9#include <i2c.h>
  10#include <dtt.h>
  11
  12#define ADT7460_ADDRESS         0x2c
  13#define ADT7460_INVALID         128
  14#define ADT7460_CONFIG          0x40
  15#define ADT7460_REM1_TEMP       0x25
  16#define ADT7460_LOCAL_TEMP      0x26
  17#define ADT7460_REM2_TEMP       0x27
  18
  19int dtt_read(int sensor, int reg)
  20{
  21        u8 dir = reg;
  22        u8 data;
  23
  24        if (i2c_read(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
  25                return -1;
  26        if (data == ADT7460_INVALID)
  27                return -1;
  28
  29        return data;
  30}
  31
  32int dtt_write(int sensor, int reg, int val)
  33{
  34        u8 dir = reg;
  35        u8 data = val;
  36
  37        if (i2c_write(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
  38                return -1;
  39
  40        return 0;
  41}
  42
  43int dtt_init_one(int sensor)
  44{
  45        printf("ADT7460 at I2C address 0x%2x\n", ADT7460_ADDRESS);
  46
  47        if (dtt_write(0, ADT7460_CONFIG, 1) == -1) {
  48                puts("Error initialiting ADT7460\n");
  49                return -1;
  50        }
  51
  52        return 0;
  53}
  54
  55int dtt_get_temp(int sensor)
  56{
  57        int aux;
  58        u8 table[] =
  59            { ADT7460_REM1_TEMP, ADT7460_LOCAL_TEMP, ADT7460_REM2_TEMP };
  60
  61        if (sensor > 2) {
  62                puts("DTT sensor does not exist\n");
  63                return -1;
  64        }
  65
  66        aux = dtt_read(0, table[sensor]);
  67        if (aux == -1) {
  68                puts("DTT temperature read failed\n");
  69                return -1;
  70        }
  71
  72        return aux;
  73}
  74