Blame view

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