Commit 0dc018ece13effc689e47479ea9ebf1c98a507f5

Authored by Stefan Roese
1 parent 4037ed3b63

[PATCH] I2C: Add support for multiple I2C busses for RTC & DTT

This patch switches to the desired I2C bus when the date/dtt
commands are called. This can be configured using the
CFG_RTC_BUS_NUM and/or CFG_DTT_BUS_NUM defines.

Signed-off-by: Stefan Roese <sr@denx.de>

Showing 4 changed files with 40 additions and 9 deletions Side-by-side Diff

... ... @@ -1347,6 +1347,16 @@
1347 1347 If defined, then this indicates the I2C bus number for DDR SPD.
1348 1348 If not defined, then U-Boot assumes that SPD is on I2C bus 0.
1349 1349  
  1350 + CFG_RTC_BUS_NUM
  1351 +
  1352 + If defined, then this indicates the I2C bus number for the RTC.
  1353 + If not defined, then U-Boot assumes that RTC is on I2C bus 0.
  1354 +
  1355 + CFG_DTT_BUS_NUM
  1356 +
  1357 + If defined, then this indicates the I2C bus number for the DTT.
  1358 + If not defined, then U-Boot assumes that DTT is on I2C bus 0.
  1359 +
1350 1360 CONFIG_FSL_I2C
1351 1361  
1352 1362 Define this option if you want to use Freescale's I2C driver in
... ... @@ -27,6 +27,7 @@
27 27 #include <common.h>
28 28 #include <command.h>
29 29 #include <rtc.h>
  30 +#include <i2c.h>
30 31  
31 32 DECLARE_GLOBAL_DATA_PTR;
32 33  
33 34  
... ... @@ -44,7 +45,12 @@
44 45 {
45 46 struct rtc_time tm;
46 47 int rcode = 0;
  48 + int old_bus;
47 49  
  50 + /* switch to correct I2C bus */
  51 + old_bus = I2C_GET_BUS();
  52 + I2C_SET_BUS(CFG_RTC_BUS_NUM);
  53 +
48 54 switch (argc) {
49 55 case 2: /* set date & time */
50 56 if (strcmp(argv[1],"reset") == 0) {
... ... @@ -56,7 +62,7 @@
56 62 /* insert new date & time */
57 63 if (mk_date (argv[1], &tm) != 0) {
58 64 puts ("## Bad date format\n");
59   - return 1;
  65 + break;
60 66 }
61 67 /* and write to RTC */
62 68 rtc_set (&tm);
63 69  
... ... @@ -71,11 +77,15 @@
71 77 "unknown " : RELOC(weekdays[tm.tm_wday]),
72 78 tm.tm_hour, tm.tm_min, tm.tm_sec);
73 79  
74   - return 0;
  80 + break;
75 81 default:
76 82 printf ("Usage:\n%s\n", cmdtp->usage);
77 83 rcode = 1;
78 84 }
  85 +
  86 + /* switch back to original I2C bus */
  87 + I2C_SET_BUS(old_bus);
  88 +
79 89 return rcode;
80 90 }
81 91  
... ... @@ -28,19 +28,27 @@
28 28 #if (CONFIG_COMMANDS & CFG_CMD_DTT)
29 29  
30 30 #include <dtt.h>
  31 +#include <i2c.h>
31 32  
32 33 int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
33 34 {
34 35 int i;
35 36 unsigned char sensors[] = CONFIG_DTT_SENSORS;
  37 + int old_bus;
36 38  
  39 + /* switch to correct I2C bus */
  40 + old_bus = I2C_GET_BUS();
  41 + I2C_SET_BUS(CFG_DTT_BUS_NUM);
  42 +
37 43 /*
38 44 * Loop through sensors, read
39 45 * temperature, and output it.
40 46 */
41   - for (i = 0; i < sizeof (sensors); i++) {
  47 + for (i = 0; i < sizeof (sensors); i++)
42 48 printf ("DTT%d: %i C\n", i + 1, dtt_get_temp (sensors[i]));
43   - }
  49 +
  50 + /* switch back to original I2C bus */
  51 + I2C_SET_BUS(old_bus);
44 52  
45 53 return 0;
46 54 } /* do_dtt() */
... ... @@ -144,12 +144,15 @@
144 144 unsigned char sensors[] = CONFIG_DTT_SENSORS;
145 145 const char *const header = "DTT: ";
146 146  
  147 + /* switch to correct I2C bus */
  148 + I2C_SET_BUS(CFG_DTT_BUS_NUM);
  149 +
147 150 for (i = 0; i < sizeof(sensors); i++) {
148   - if (_dtt_init(sensors[i]) != 0)
149   - printf ("%s%d FAILED INIT\n", header, i+1);
150   - else
151   - printf ("%s%d is %i C\n", header, i+1,
152   - dtt_get_temp(sensors[i]));
  151 + if (_dtt_init(sensors[i]) != 0)
  152 + printf ("%s%d FAILED INIT\n", header, i+1);
  153 + else
  154 + printf ("%s%d is %i C\n", header, i+1,
  155 + dtt_get_temp(sensors[i]));
153 156 }
154 157  
155 158 return (0);