Commit 7ff485c68b7e5573e5a4a877066e98398283a24f

Authored by Tom Rini

Merge branch 'master' of git://git.denx.de/u-boot-i2c

- DM_I2C_COMPAT removal for all ti platforms from Jean-Jacques Hiblot
- Fix in i2c command help output from Chirstoph Muellner.

Showing 53 changed files Side-by-side Diff

arch/arm/dts/am437x-gp-evm-u-boot.dtsi
... ... @@ -36,4 +36,8 @@
36 36 &phy_sel {
37 37 u-boot,dm-spl;
38 38 };
  39 +
  40 +&i2c0 {
  41 + u-boot,dm-spl;
  42 +};
arch/arm/dts/omap5-u-boot.dtsi
... ... @@ -95,4 +95,8 @@
95 95 &gpio7 {
96 96 u-boot,dm-spl;
97 97 };
  98 +
  99 +&i2c1 {
  100 + u-boot,dm-spl;
  101 +};
arch/arm/include/asm/arch-am33xx/i2c.h
... ... @@ -6,56 +6,13 @@
6 6 #ifndef _I2C_AM33XX_H_
7 7 #define _I2C_AM33XX_H_
8 8  
  9 +#include <asm/omap_i2c.h>
  10 +
9 11 #define I2C_BASE1 0x44E0B000
10 12 #define I2C_BASE2 0x4802A000
11 13 #define I2C_BASE3 0x4819C000
12 14  
13 15 #define I2C_DEFAULT_BASE I2C_BASE1
14   -
15   -struct i2c {
16   - unsigned short revnb_lo; /* 0x00 */
17   - unsigned short res1;
18   - unsigned short revnb_hi; /* 0x04 */
19   - unsigned short res2[5];
20   - unsigned short sysc; /* 0x10 */
21   - unsigned short res3[9];
22   - unsigned short irqstatus_raw; /* 0x24 */
23   - unsigned short res4;
24   - unsigned short stat; /* 0x28 */
25   - unsigned short res5;
26   - unsigned short ie; /* 0x2C */
27   - unsigned short res6;
28   - unsigned short irqenable_clr; /* 0x30 */
29   - unsigned short res7;
30   - unsigned short iv; /* 0x34 */
31   - unsigned short res8[45];
32   - unsigned short syss; /* 0x90 */
33   - unsigned short res9;
34   - unsigned short buf; /* 0x94 */
35   - unsigned short res10;
36   - unsigned short cnt; /* 0x98 */
37   - unsigned short res11;
38   - unsigned short data; /* 0x9C */
39   - unsigned short res13;
40   - unsigned short res14; /* 0xA0 */
41   - unsigned short res15;
42   - unsigned short con; /* 0xA4 */
43   - unsigned short res16;
44   - unsigned short oa; /* 0xA8 */
45   - unsigned short res17;
46   - unsigned short sa; /* 0xAC */
47   - unsigned short res18;
48   - unsigned short psc; /* 0xB0 */
49   - unsigned short res19;
50   - unsigned short scll; /* 0xB4 */
51   - unsigned short res20;
52   - unsigned short sclh; /* 0xB8 */
53   - unsigned short res21;
54   - unsigned short systest; /* 0xBC */
55   - unsigned short res22;
56   - unsigned short bufstat; /* 0xC0 */
57   - unsigned short res23;
58   -};
59 16  
60 17 #define I2C_IP_CLK 48000000
61 18 #define I2C_INTERNAL_SAMPLING_CLK 12000000
arch/arm/include/asm/arch-omap3/i2c.h
... ... @@ -8,52 +8,5 @@
8 8  
9 9 #define I2C_DEFAULT_BASE I2C_BASE1
10 10  
11   -struct i2c {
12   - unsigned short rev; /* 0x00 */
13   - unsigned short res1;
14   - unsigned short ie; /* 0x04 */
15   - unsigned short res2;
16   - unsigned short stat; /* 0x08 */
17   - unsigned short res3;
18   - unsigned short we; /* 0x0C */
19   - unsigned short res4;
20   - unsigned short syss; /* 0x10 */
21   - unsigned short res4a;
22   - unsigned short buf; /* 0x14 */
23   - unsigned short res5;
24   - unsigned short cnt; /* 0x18 */
25   - unsigned short res6;
26   - unsigned short data; /* 0x1C */
27   - unsigned short res7;
28   - unsigned short sysc; /* 0x20 */
29   - unsigned short res8;
30   - unsigned short con; /* 0x24 */
31   - unsigned short res9;
32   - unsigned short oa; /* 0x28 */
33   - unsigned short res10;
34   - unsigned short sa; /* 0x2C */
35   - unsigned short res11;
36   - unsigned short psc; /* 0x30 */
37   - unsigned short res12;
38   - unsigned short scll; /* 0x34 */
39   - unsigned short res13;
40   - unsigned short sclh; /* 0x38 */
41   - unsigned short res14;
42   - unsigned short systest; /* 0x3c */
43   - unsigned short res15;
44   - unsigned short bufstat; /* 0x40 */
45   - unsigned short res16;
46   - unsigned short oa1; /* 0x44 */
47   - unsigned short res17;
48   - unsigned short oa2; /* 0x48 */
49   - unsigned short res18;
50   - unsigned short oa3; /* 0x4c */
51   - unsigned short res19;
52   - unsigned short actoa; /* 0x50 */
53   - unsigned short res20;
54   - unsigned short sblock; /* 0x54 */
55   - unsigned short res21;
56   -};
57   -
58 11 #endif /* _OMAP3_I2C_H_ */
arch/arm/include/asm/arch-omap4/i2c.h
... ... @@ -8,50 +8,5 @@
8 8  
9 9 #define I2C_DEFAULT_BASE I2C_BASE1
10 10  
11   -struct i2c {
12   - unsigned short revnb_lo; /* 0x00 */
13   - unsigned short res1;
14   - unsigned short revnb_hi; /* 0x04 */
15   - unsigned short res2[5];
16   - unsigned short sysc; /* 0x10 */
17   - unsigned short res3[9];
18   - unsigned short irqstatus_raw; /* 0x24 */
19   - unsigned short res4;
20   - unsigned short stat; /* 0x28 */
21   - unsigned short res5;
22   - unsigned short ie; /* 0x2C */
23   - unsigned short res6;
24   - unsigned short irqenable_clr; /* 0x30 */
25   - unsigned short res7;
26   - unsigned short iv; /* 0x34 */
27   - unsigned short res8[45];
28   - unsigned short syss; /* 0x90 */
29   - unsigned short res9;
30   - unsigned short buf; /* 0x94 */
31   - unsigned short res10;
32   - unsigned short cnt; /* 0x98 */
33   - unsigned short res11;
34   - unsigned short data; /* 0x9C */
35   - unsigned short res13;
36   - unsigned short res14; /* 0xA0 */
37   - unsigned short res15;
38   - unsigned short con; /* 0xA4 */
39   - unsigned short res16;
40   - unsigned short oa; /* 0xA8 */
41   - unsigned short res17;
42   - unsigned short sa; /* 0xAC */
43   - unsigned short res18;
44   - unsigned short psc; /* 0xB0 */
45   - unsigned short res19;
46   - unsigned short scll; /* 0xB4 */
47   - unsigned short res20;
48   - unsigned short sclh; /* 0xB8 */
49   - unsigned short res21;
50   - unsigned short systest; /* 0xBC */
51   - unsigned short res22;
52   - unsigned short bufstat; /* 0xC0 */
53   - unsigned short res23;
54   -};
55   -
56 11 #endif /* _OMAP4_I2C_H_ */
arch/arm/include/asm/arch-omap5/i2c.h
... ... @@ -8,50 +8,5 @@
8 8  
9 9 #define I2C_DEFAULT_BASE I2C_BASE1
10 10  
11   -struct i2c {
12   - unsigned short revnb_lo; /* 0x00 */
13   - unsigned short res1;
14   - unsigned short revnb_hi; /* 0x04 */
15   - unsigned short res2[5];
16   - unsigned short sysc; /* 0x10 */
17   - unsigned short res3[9];
18   - unsigned short irqstatus_raw; /* 0x24 */
19   - unsigned short res4;
20   - unsigned short stat; /* 0x28 */
21   - unsigned short res5;
22   - unsigned short ie; /* 0x2C */
23   - unsigned short res6;
24   - unsigned short irqenable_clr; /* 0x30 */
25   - unsigned short res7;
26   - unsigned short iv; /* 0x34 */
27   - unsigned short res8[45];
28   - unsigned short syss; /* 0x90 */
29   - unsigned short res9;
30   - unsigned short buf; /* 0x94 */
31   - unsigned short res10;
32   - unsigned short cnt; /* 0x98 */
33   - unsigned short res11;
34   - unsigned short data; /* 0x9C */
35   - unsigned short res13;
36   - unsigned short res14; /* 0xA0 */
37   - unsigned short res15;
38   - unsigned short con; /* 0xA4 */
39   - unsigned short res16;
40   - unsigned short oa; /* 0xA8 */
41   - unsigned short res17;
42   - unsigned short sa; /* 0xAC */
43   - unsigned short res18;
44   - unsigned short psc; /* 0xB0 */
45   - unsigned short res19;
46   - unsigned short scll; /* 0xB4 */
47   - unsigned short res20;
48   - unsigned short sclh; /* 0xB8 */
49   - unsigned short res21;
50   - unsigned short systest; /* 0xBC */
51   - unsigned short res22;
52   - unsigned short bufstat; /* 0xC0 */
53   - unsigned short res23;
54   -};
55   -
56 11 #endif /* _OMAP5_I2C_H_ */
arch/arm/include/asm/omap_i2c.h
  1 +/* SPDX-License-Identifier: GPL-2.0 */
  2 +
  3 +#ifndef _OMAP_I2C_H
  4 +#define _OMAP_I2C_H
  5 +
  6 +#include <asm/arch/cpu.h>
  7 +
  8 +#ifdef CONFIG_DM_I2C
  9 +
  10 +/* Information about a GPIO bank */
  11 +struct omap_i2c_platdata {
  12 + ulong base; /* address of registers in physical memory */
  13 + int speed;
  14 + int ip_rev;
  15 +};
  16 +
  17 +#endif
  18 +
  19 +enum {
  20 + OMAP_I2C_REV_V1 = 0,
  21 + OMAP_I2C_REV_V2 = 1,
  22 +};
  23 +
  24 +#endif /* _OMAP_I2C_H */
arch/arm/mach-keystone/ddr3_spd.c
... ... @@ -403,6 +403,7 @@
403 403 static int ddr3_read_spd(ddr3_spd_eeprom_t *spd_params)
404 404 {
405 405 int ret;
  406 +#ifndef CONFIG_DM_I2C
406 407 int old_bus;
407 408  
408 409 i2c_init(CONFIG_SYS_DAVINCI_I2C_SPEED, CONFIG_SYS_DAVINCI_I2C_SLAVE);
409 410  
... ... @@ -413,7 +414,13 @@
413 414 ret = i2c_read(0x53, 0, 1, (unsigned char *)spd_params, 256);
414 415  
415 416 i2c_set_bus_num(old_bus);
  417 +#else
  418 + struct udevice *dev;
416 419  
  420 + ret = i2c_get_chip_for_busnum(1, 0x53, 1, &dev);
  421 + if (!ret)
  422 + ret = dm_i2c_read(dev, 0, (unsigned char *)spd_params, 256);
  423 +#endif
417 424 if (ret) {
418 425 printf("Cannot read DIMM params\n");
419 426 return 1;
arch/arm/mach-omap2/am33xx/board.c
... ... @@ -19,6 +19,7 @@
19 19 #include <asm/arch/ddr_defs.h>
20 20 #include <asm/arch/clock.h>
21 21 #include <asm/arch/gpio.h>
  22 +#include <asm/arch/i2c.h>
22 23 #include <asm/arch/mem.h>
23 24 #include <asm/arch/mmc_host_def.h>
24 25 #include <asm/arch/sys_proto.h>
... ... @@ -93,6 +94,20 @@
93 94 # endif
94 95 };
95 96  
  97 +#ifdef CONFIG_DM_I2C
  98 +static const struct omap_i2c_platdata am33xx_i2c[] = {
  99 + { I2C_BASE1, 100000, OMAP_I2C_REV_V2},
  100 + { I2C_BASE2, 100000, OMAP_I2C_REV_V2},
  101 + { I2C_BASE3, 100000, OMAP_I2C_REV_V2},
  102 +};
  103 +
  104 +U_BOOT_DEVICES(am33xx_i2c) = {
  105 + { "i2c_omap", &am33xx_i2c[0] },
  106 + { "i2c_omap", &am33xx_i2c[1] },
  107 + { "i2c_omap", &am33xx_i2c[2] },
  108 +};
  109 +#endif
  110 +
96 111 #ifdef CONFIG_DM_GPIO
97 112 static const struct omap_gpio_platdata am33xx_gpio[] = {
98 113 { 0, AM33XX_GPIO0_BASE },
99 114  
... ... @@ -457,12 +472,15 @@
457 472 #ifdef CONFIG_DEBUG_UART_OMAP
458 473 debug_uart_init();
459 474 #endif
460   -#ifdef CONFIG_TI_I2C_BOARD_DETECT
461   - do_board_detect();
462   -#endif
  475 +
463 476 #ifdef CONFIG_SPL_BUILD
464 477 spl_early_init();
465 478 #endif
  479 +
  480 +#ifdef CONFIG_TI_I2C_BOARD_DETECT
  481 + do_board_detect();
  482 +#endif
  483 +
466 484 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
467 485 /* Enable RTC32K clock */
468 486 rtc32k_enable();
arch/arm/mach-omap2/am33xx/clk_synthesizer.c
... ... @@ -14,6 +14,7 @@
14 14  
15 15 /**
16 16 * clk_synthesizer_reg_read - Read register from synthesizer.
  17 + * dev: i2c bus device (not used if CONFIG_DM_I2C is not set)
17 18 * @addr: addr within the i2c device
18 19 * buf: Buffer to which value is to be read.
19 20 *
20 21  
... ... @@ -21,13 +22,14 @@
21 22 * be send along with enabling byte read more, and then read can happen.
22 23 * Returns 0 on success
23 24 */
24   -static int clk_synthesizer_reg_read(int addr, uint8_t *buf)
  25 +static int clk_synthesizer_reg_read(struct udevice *dev, int addr, u8 *buf)
25 26 {
26 27 int rc;
27 28  
28 29 /* Enable Bye read */
29 30 addr = addr | CLK_SYNTHESIZER_BYTE_MODE;
30 31  
  32 +#ifndef CONFIG_DM_I2C
31 33 /* Send the command byte */
32 34 rc = i2c_write(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, buf, 1);
33 35 if (rc)
34 36  
35 37  
36 38  
37 39  
38 40  
... ... @@ -35,26 +37,46 @@
35 37  
36 38 /* Read the Data */
37 39 return i2c_read(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, buf, 1);
  40 +#else
  41 + /* Send the command byte */
  42 + rc = dm_i2c_reg_write(dev, addr, *buf);
  43 + if (rc)
  44 + printf("Failed to send command to clock synthesizer\n");
  45 +
  46 + /* Read the Data */
  47 + rc = dm_i2c_reg_read(dev, addr);
  48 + if (rc < 0)
  49 + return rc;
  50 +
  51 + *buf = (u8)rc;
  52 + return 0;
  53 +#endif
  54 +
38 55 }
39 56  
40 57 /**
41 58 * clk_synthesizer_reg_write - Write a value to register in synthesizer.
  59 + * dev: i2c bus device (not used if CONFIG_DM_I2C is not set)
42 60 * @addr: addr within the i2c device
43 61 * val: Value to be written in the addr.
44 62 *
45 63 * Enable the byte read mode in the address and start the i2c transfer.
46 64 * Returns 0 on success
47 65 */
48   -static int clk_synthesizer_reg_write(int addr, uint8_t val)
  66 +static int clk_synthesizer_reg_write(struct udevice *dev, int addr, u8 val)
49 67 {
50   - uint8_t cmd[2];
  68 + u8 cmd[2];
51 69 int rc = 0;
52 70  
53 71 /* Enable byte write */
54 72 cmd[0] = addr | CLK_SYNTHESIZER_BYTE_MODE;
55 73 cmd[1] = val;
56 74  
  75 +#ifndef CONFIG_DM_I2C
57 76 rc = i2c_write(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, cmd, 2);
  77 +#else
  78 + rc = dm_i2c_write(dev, addr, cmd, 2);
  79 +#endif
58 80 if (rc)
59 81 printf("Clock synthesizer reg write failed at addr = 0x%x\n",
60 82 addr);
61 83  
62 84  
63 85  
64 86  
65 87  
... ... @@ -72,30 +94,42 @@
72 94 int setup_clock_synthesizer(struct clk_synth *data)
73 95 {
74 96 int rc;
75   - uint8_t val;
76   -
  97 + u8 val = 0;
  98 + struct udevice *dev = NULL;
  99 +#ifndef CONFIG_DM_I2C
77 100 rc = i2c_probe(CLK_SYNTHESIZER_I2C_ADDR);
78 101 if (rc) {
79 102 printf("i2c probe failed at address 0x%x\n",
80 103 CLK_SYNTHESIZER_I2C_ADDR);
81 104 return rc;
82 105 }
83   -
84   - rc = clk_synthesizer_reg_read(CLK_SYNTHESIZER_ID_REG, &val);
  106 +#else
  107 + rc = i2c_get_chip_for_busnum(0, CLK_SYNTHESIZER_I2C_ADDR, 1, &dev);
  108 + if (rc) {
  109 + printf("failed to get device for synthesizer at address 0x%x\n",
  110 + CLK_SYNTHESIZER_I2C_ADDR);
  111 + return rc;
  112 + }
  113 +#endif
  114 + rc = clk_synthesizer_reg_read(dev, CLK_SYNTHESIZER_ID_REG, &val);
85 115 if (val != data->id)
86 116 return rc;
87 117  
88 118 /* Crystal Load capacitor selection */
89   - rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_XCSEL, data->capacitor);
  119 + rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_XCSEL,
  120 + data->capacitor);
90 121 if (rc)
91 122 return rc;
92   - rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_MUX_REG, data->mux);
  123 + rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_MUX_REG,
  124 + data->mux);
93 125 if (rc)
94 126 return rc;
95   - rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_PDIV2_REG, data->pdiv2);
  127 + rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_PDIV2_REG,
  128 + data->pdiv2);
96 129 if (rc)
97 130 return rc;
98   - rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_PDIV3_REG, data->pdiv3);
  131 + rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_PDIV3_REG,
  132 + data->pdiv3);
99 133 if (rc)
100 134 return rc;
101 135  
arch/arm/mach-omap2/clocks-common.c
... ... @@ -909,6 +909,7 @@
909 909 enable_basic_uboot_clocks();
910 910 }
911 911  
  912 +#if !defined(CONFIG_DM_I2C)
912 913 void gpi2c_init(void)
913 914 {
914 915 static int gpi2c = 1;
... ... @@ -919,4 +920,5 @@
919 920 gpi2c = 0;
920 921 }
921 922 }
  923 +#endif
arch/arm/mach-omap2/hwinit-common.c
... ... @@ -12,6 +12,7 @@
12 12 */
13 13 #include <common.h>
14 14 #include <debug_uart.h>
  15 +#include <fdtdec.h>
15 16 #include <spl.h>
16 17 #include <asm/arch/sys_proto.h>
17 18 #include <linux/sizes.h>
... ... @@ -19,6 +20,7 @@
19 20 #include <asm/omap_common.h>
20 21 #include <linux/compiler.h>
21 22 #include <asm/system.h>
  23 +#include <dm/root.h>
22 24  
23 25 DECLARE_GLOBAL_DATA_PTR;
24 26  
... ... @@ -171,6 +173,10 @@
171 173 */
172 174 void early_system_init(void)
173 175 {
  176 +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
  177 + int ret;
  178 + int rescan;
  179 +#endif
174 180 init_omap_revision();
175 181 hw_data_init();
176 182 init_package_revision();
... ... @@ -186,6 +192,7 @@
186 192 do_io_settings();
187 193 #endif
188 194 setup_early_clocks();
  195 +
189 196 #ifdef CONFIG_SPL_BUILD
190 197 /*
191 198 * Save the boot parameters passed from romcode.
192 199  
193 200  
... ... @@ -193,11 +200,23 @@
193 200 * to prevent overwrites.
194 201 */
195 202 save_omap_boot_params();
  203 + spl_early_init();
196 204 #endif
197 205 do_board_detect();
198   -#ifdef CONFIG_SPL_BUILD
199   - spl_early_init();
  206 +
  207 +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
  208 + /*
  209 + * Board detection has been done.
  210 + * Let us see if another dtb wouldn't be a better match
  211 + * for our board
  212 + */
  213 + ret = fdtdec_resetup(&rescan);
  214 + if (!ret && rescan) {
  215 + dm_uninit();
  216 + dm_init_and_scan(true);
  217 + }
200 218 #endif
  219 +
201 220 vcores_init();
202 221 #ifdef CONFIG_DEBUG_UART_OMAP
203 222 debug_uart_init();
board/eets/pdu001/board.c
... ... @@ -209,7 +209,6 @@
209 209 const struct dpll_params *get_dpll_ddr_params(void)
210 210 {
211 211 enable_i2c0_pin_mux();
212   - i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
213 212  
214 213 return &dpll_ddr;
215 214 }
board/ti/am335x/board.c
... ... @@ -70,8 +70,9 @@
70 70 void do_board_detect(void)
71 71 {
72 72 enable_i2c0_pin_mux();
  73 +#ifndef CONFIG_DM_I2C
73 74 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
74   -
  75 +#endif
75 76 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
76 77 CONFIG_EEPROM_CHIP_ADDRESS))
77 78 printf("ti_i2c_eeprom_init failed\n");
78 79  
79 80  
... ... @@ -328,9 +329,15 @@
328 329 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
329 330 return;
330 331  
  332 +#ifndef CONFIG_DM_I2C
331 333 if (i2c_probe(TPS65217_CHIP_PM))
332 334 return;
  335 +#else
  336 + if (power_tps65217_init(0))
  337 + return;
  338 +#endif
333 339  
  340 +
334 341 /*
335 342 * On Beaglebone White we need to ensure we have AC power
336 343 * before increasing the frequency.
337 344  
... ... @@ -421,9 +428,13 @@
421 428 * 1.10V. For MPU voltage we need to switch based on
422 429 * the frequency we are running at.
423 430 */
  431 +#ifndef CONFIG_DM_I2C
424 432 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
425 433 return;
426   -
  434 +#else
  435 + if (power_tps65910_init(0))
  436 + return;
  437 +#endif
427 438 /*
428 439 * Depending on MPU clock and PG we will need a different
429 440 * VDD to drive at that speed.
430 441  
... ... @@ -451,8 +462,10 @@
451 462  
452 463 if (first_time) {
453 464 enable_i2c0_pin_mux();
  465 +#ifndef CONFIG_DM_I2C
454 466 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
455 467 CONFIG_SYS_OMAP24_I2C_SLAVE);
  468 +#endif
456 469 first_time = false;
457 470 }
458 471 }
board/ti/am335x/mux.c
... ... @@ -329,12 +329,23 @@
329 329 {
330 330 unsigned short val;
331 331  
  332 +#ifndef CONFIG_DM_I2C
332 333 if (i2c_probe(I2C_CPLD_ADDR))
333 334 return PROFILE_NONE;
334 335  
335 336 if (i2c_read(I2C_CPLD_ADDR, CFG_REG, 1, (unsigned char *)(&val), 2))
336 337 return PROFILE_NONE;
  338 +#else
  339 + struct udevice *dev = NULL;
  340 + int rc;
337 341  
  342 + rc = i2c_get_chip_for_busnum(0, I2C_CPLD_ADDR, 1, &dev);
  343 + if (rc)
  344 + return PROFILE_NONE;
  345 + rc = dm_i2c_read(dev, CFG_REG, (unsigned char *)(&val), 2);
  346 + if (rc)
  347 + return PROFILE_NONE;
  348 +#endif
338 349 return (1 << (val & PROFILE_MASK));
339 350 }
340 351  
board/ti/am43xx/board.c
... ... @@ -43,6 +43,8 @@
43 43 #ifdef CONFIG_TI_I2C_BOARD_DETECT
44 44 void do_board_detect(void)
45 45 {
  46 + /* Ensure I2C is initialized for EEPROM access*/
  47 + gpi2c_init();
46 48 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
47 49 CONFIG_EEPROM_CHIP_ADDRESS))
48 50 printf("ti_i2c_eeprom_init failed\n");
49 51  
... ... @@ -386,8 +388,13 @@
386 388 {
387 389 int mpu_vdd, ddr_volt;
388 390  
  391 +#ifndef CONFIG_DM_I2C
389 392 if (i2c_probe(TPS65218_CHIP_PM))
390 393 return;
  394 +#else
  395 + if (power_tps65218_init(0))
  396 + return;
  397 +#endif
391 398  
392 399 switch (m) {
393 400 case 1000:
394 401  
... ... @@ -439,8 +446,13 @@
439 446 {
440 447 int mpu_vdd;
441 448  
  449 +#ifndef CONFIG_DM_I2C
442 450 if (i2c_probe(TPS62362_I2C_ADDR))
443 451 return;
  452 +#else
  453 + if (power_tps62362_init(0))
  454 + return;
  455 +#endif
444 456  
445 457 switch (m) {
446 458 case 1000:
447 459  
... ... @@ -462,14 +474,12 @@
462 474 puts("Unknown MPU clock, not scaling\n");
463 475 return;
464 476 }
465   -
466 477 /* Set VDD_MPU voltage */
467 478 if (tps62362_voltage_update(TPS62362_SET3, mpu_vdd)) {
468 479 printf("%s failure\n", __func__);
469 480 return;
470 481 }
471 482 }
472   -
473 483 void gpi2c_init(void)
474 484 {
475 485 /* When needed to be invoked prior to BSS initialization */
476 486  
... ... @@ -477,8 +487,10 @@
477 487  
478 488 if (first_time) {
479 489 enable_i2c0_pin_mux();
  490 +#ifndef CONFIG_DM_I2C
480 491 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
481 492 CONFIG_SYS_OMAP24_I2C_SLAVE);
  493 +#endif
482 494 first_time = false;
483 495 }
484 496 }
485 497  
486 498  
487 499  
488 500  
489 501  
... ... @@ -614,20 +626,32 @@
614 626 /* setup board specific PMIC */
615 627 int power_init_board(void)
616 628 {
617   - struct pmic *p;
618   -
  629 + int rc;
  630 +#ifndef CONFIG_DM_I2C
  631 + struct pmic *p = NULL;
  632 +#endif
619 633 if (board_is_idk()) {
620   - power_tps62362_init(I2C_PMIC);
  634 + rc = power_tps62362_init(0);
  635 + if (rc)
  636 + goto done;
  637 +#ifndef CONFIG_DM_I2C
621 638 p = pmic_get("TPS62362");
622   - if (p && !pmic_probe(p))
623   - puts("PMIC: TPS62362\n");
  639 + if (!p || pmic_probe(p))
  640 + goto done;
  641 +#endif
  642 + puts("PMIC: TPS62362\n");
624 643 } else {
625   - power_tps65218_init(I2C_PMIC);
  644 + rc = power_tps65218_init(0);
  645 + if (rc)
  646 + goto done;
  647 +#ifndef CONFIG_DM_I2C
626 648 p = pmic_get("TPS65218_PMIC");
627   - if (p && !pmic_probe(p))
628   - puts("PMIC: TPS65218\n");
  649 + if (!p || pmic_probe(p))
  650 + goto done;
  651 +#endif
  652 + puts("PMIC: TPS65218\n");
629 653 }
630   -
  654 +done:
631 655 return 0;
632 656 }
633 657  
board/ti/am57xx/board.c
... ... @@ -623,7 +623,7 @@
623 623 {
624 624 int r = -ENODEV;
625 625 char *idk_lcd = "no";
626   - uint8_t buf = 0;
  626 + struct udevice *dev;
627 627  
628 628 /* Only valid for IDKs */
629 629 if (board_is_x15() || board_is_am572x_evm())
630 630  
631 631  
632 632  
633 633  
634 634  
... ... @@ -633,32 +633,29 @@
633 633 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
634 634 goto out;
635 635  
636   - r = i2c_set_bus_num(OSD_TS_FT_BUS_ADDRESS);
  636 + r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
  637 + OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
637 638 if (r) {
638   - printf("%s: Failed to set bus address to %d: %d\n",
639   - __func__, OSD_TS_FT_BUS_ADDRESS, r);
640   - goto out;
641   - }
642   - r = i2c_probe(OSD_TS_FT_CHIP_ADDRESS);
643   - if (r) {
  639 + printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
  640 + __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
  641 + r);
644 642 /* AM572x IDK has no explicit settings for optional LCD kit */
645   - if (board_is_am571x_idk()) {
  643 + if (board_is_am571x_idk())
646 644 printf("%s: Touch screen detect failed: %d!\n",
647 645 __func__, r);
648   - }
649 646 goto out;
650 647 }
651 648  
652 649 /* Read FT ID */
653   - r = i2c_read(OSD_TS_FT_CHIP_ADDRESS, OSD_TS_FT_REG_ID, 1, &buf, 1);
654   - if (r) {
  650 + r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
  651 + if (r < 0) {
655 652 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
656 653 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
657 654 OSD_TS_FT_REG_ID, r);
658 655 goto out;
659 656 }
660 657  
661   - switch (buf) {
  658 + switch (r) {
662 659 case OSD_TS_FT_ID_5606:
663 660 idk_lcd = "osd101t2045";
664 661 break;
... ... @@ -667,7 +664,7 @@
667 664 break;
668 665 default:
669 666 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
670   - __func__, buf);
  667 + __func__, r);
671 668 /* we will let default be "no lcd" */
672 669 }
673 670 out:
board/ti/common/board_detect.c
... ... @@ -14,43 +14,8 @@
14 14  
15 15 #include "board_detect.h"
16 16  
17   -#if defined(CONFIG_DM_I2C_COMPAT)
  17 +#if !defined(CONFIG_DM_I2C)
18 18 /**
19   - * ti_i2c_set_alen - Set chip's i2c address length
20   - * @bus_addr - I2C bus number
21   - * @dev_addr - I2C eeprom id
22   - * @alen - I2C address length in bytes
23   - *
24   - * DM_I2C by default sets the address length to be used to 1. This
25   - * function allows this address length to be changed to match the
26   - * eeprom used for board detection.
27   - */
28   -int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen)
29   -{
30   - struct udevice *dev;
31   - struct udevice *bus;
32   - int rc;
33   -
34   - rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus);
35   - if (rc)
36   - return rc;
37   - rc = i2c_get_chip(bus, dev_addr, 1, &dev);
38   - if (rc)
39   - return rc;
40   - rc = i2c_set_chip_offset_len(dev, alen);
41   - if (rc)
42   - return rc;
43   -
44   - return 0;
45   -}
46   -#else
47   -int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen)
48   -{
49   - return 0;
50   -}
51   -#endif
52   -
53   -/**
54 19 * ti_i2c_eeprom_init - Initialize an i2c bus and probe for a device
55 20 * @i2c_bus: i2c bus number to initialize
56 21 * @dev_addr: Device address to probe for
57 22  
... ... @@ -82,18 +47,9 @@
82 47 static int __maybe_unused ti_i2c_eeprom_read(int dev_addr, int offset,
83 48 uchar *ep, int epsize)
84 49 {
85   - int bus_num, rc, alen;
86   -
87   - bus_num = i2c_get_bus_num();
88   -
89   - alen = 2;
90   -
91   - rc = ti_i2c_set_alen(bus_num, dev_addr, alen);
92   - if (rc)
93   - return rc;
94   -
95   - return i2c_read(dev_addr, offset, alen, ep, epsize);
  50 + return i2c_read(dev_addr, offset, 2, ep, epsize);
96 51 }
  52 +#endif
97 53  
98 54 /**
99 55 * ti_eeprom_string_cleanup() - Handle eeprom programming errors
100 56  
101 57  
102 58  
103 59  
104 60  
... ... @@ -122,23 +78,67 @@
122 78 static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
123 79 u32 header, u32 size, uint8_t *ep)
124 80 {
125   - u32 byte, hdr_read;
  81 + u32 hdr_read;
126 82 int rc;
127 83  
128   - gpi2c_init();
129   - rc = ti_i2c_eeprom_init(bus_addr, dev_addr);
  84 +#if defined(CONFIG_DM_I2C)
  85 + struct udevice *dev;
  86 + struct udevice *bus;
  87 +
  88 + rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus);
130 89 if (rc)
131 90 return rc;
  91 + rc = i2c_get_chip(bus, dev_addr, 1, &dev);
  92 + if (rc)
  93 + return rc;
132 94  
133 95 /*
134 96 * Read the header first then only read the other contents.
135 97 */
136   - byte = 2;
  98 + rc = i2c_set_chip_offset_len(dev, 2);
  99 + if (rc)
  100 + return rc;
137 101  
138   - rc = ti_i2c_set_alen(bus_addr, dev_addr, byte);
  102 + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
139 103 if (rc)
140 104 return rc;
141 105  
  106 + /* Corrupted data??? */
  107 + if (hdr_read != header) {
  108 + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
  109 + /*
  110 + * read the eeprom header using i2c again, but use only a
  111 + * 1 byte address (some legacy boards need this..)
  112 + */
  113 + if (rc) {
  114 + rc = i2c_set_chip_offset_len(dev, 1);
  115 + if (rc)
  116 + return rc;
  117 +
  118 + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
  119 + }
  120 + if (rc)
  121 + return rc;
  122 + }
  123 + if (hdr_read != header)
  124 + return -1;
  125 +
  126 + rc = dm_i2c_read(dev, 0, ep, size);
  127 + if (rc)
  128 + return rc;
  129 +#else
  130 + u32 byte;
  131 +
  132 + gpi2c_init();
  133 + rc = ti_i2c_eeprom_init(bus_addr, dev_addr);
  134 + if (rc)
  135 + return rc;
  136 +
  137 + /*
  138 + * Read the header first then only read the other contents.
  139 + */
  140 + byte = 2;
  141 +
142 142 rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, 4);
143 143 if (rc)
144 144 return rc;
... ... @@ -152,10 +152,6 @@
152 152 */
153 153 byte = 1;
154 154 if (rc) {
155   - rc = ti_i2c_set_alen(bus_addr, dev_addr, byte);
156   - if (rc)
157   - return rc;
158   -
159 155 rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read,
160 156 4);
161 157 }
... ... @@ -168,7 +164,7 @@
168 164 rc = i2c_read(dev_addr, 0x0, byte, ep, size);
169 165 if (rc)
170 166 return rc;
171   -
  167 +#endif
172 168 return 0;
173 169 }
174 170  
board/ti/ks2_evm/board_k2g.c
... ... @@ -251,6 +251,7 @@
251 251 #if defined(CONFIG_DTB_RESELECT)
252 252 static int k2g_alt_board_detect(void)
253 253 {
  254 +#ifndef CONFIG_DM_I2C
254 255 int rc;
255 256  
256 257 rc = i2c_set_bus_num(1);
257 258  
... ... @@ -260,7 +261,17 @@
260 261 rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
261 262 if (rc)
262 263 return rc;
  264 +#else
  265 + struct udevice *bus, *dev;
  266 + int rc;
263 267  
  268 + rc = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus);
  269 + if (rc)
  270 + return rc;
  271 + rc = dm_i2c_probe(bus, K2G_GP_AUDIO_CODEC_ADDRESS, 0, &dev);
  272 + if (rc)
  273 + return rc;
  274 +#endif
264 275 ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
265 276  
266 277 return 0;
... ... @@ -445,6 +445,7 @@
445 445  
446 446 config CMD_EEPROM
447 447 bool "eeprom - EEPROM subsystem"
  448 + depends on !DM_I2C || DM_I2C_COMPAT
448 449 help
449 450 (deprecated, needs conversion to driver model)
450 451 Provides commands to read and write EEPROM (Electrically Erasable
... ... @@ -2023,6 +2023,7 @@
2023 2023 static char i2c_help_text[] =
2024 2024 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
2025 2025 "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
  2026 + "i2c " /* That's the prefix for the crc32 command below. */
2026 2027 #endif
2027 2028 "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
2028 2029 #if defined(CONFIG_SYS_I2C) || \
configs/am335x_pdu001_defconfig
... ... @@ -36,6 +36,7 @@
36 36 CONFIG_DEFAULT_DEVICE_TREE="am335x-pdu001"
37 37 # CONFIG_NET is not set
38 38 CONFIG_SPL_DM=y
  39 +CONFIG_SPL_DM_SEQ_ALIAS=y
39 40 CONFIG_DM_GPIO=y
40 41 CONFIG_DM_I2C=y
41 42 CONFIG_BLK=y
configs/am57xx_evm_defconfig
... ... @@ -37,6 +37,7 @@
37 37 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
38 38 CONFIG_DM=y
39 39 CONFIG_SPL_DM=y
  40 +CONFIG_SPL_DM_SEQ_ALIAS=y
40 41 CONFIG_SCSI_AHCI=y
41 42 # CONFIG_BLK is not set
42 43 CONFIG_DFU_MMC=y
configs/am57xx_hs_evm_defconfig
... ... @@ -40,6 +40,7 @@
40 40 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
41 41 CONFIG_DM=y
42 42 CONFIG_SPL_DM=y
  43 +CONFIG_SPL_DM_SEQ_ALIAS=y
43 44 CONFIG_SCSI_AHCI=y
44 45 # CONFIG_BLK is not set
45 46 CONFIG_DFU_MMC=y
configs/dra7xx_evm_defconfig
1 1 CONFIG_ARM=y
2 2 CONFIG_ARCH_OMAP2PLUS=y
3 3 CONFIG_TI_COMMON_CMD_OPTIONS=y
4   -CONFIG_SYS_MALLOC_F_LEN=0x2000
  4 +CONFIG_SYS_MALLOC_F_LEN=0x18000
5 5 CONFIG_OMAP54XX=y
6 6 CONFIG_TARGET_DRA7XX_EVM=y
7 7 CONFIG_SPL=y
8 8  
... ... @@ -34,11 +34,13 @@
34 34 CONFIG_DEFAULT_DEVICE_TREE="dra7-evm"
35 35 CONFIG_OF_LIST="dra7-evm dra72-evm dra72-evm-revc dra71-evm dra76-evm"
36 36 CONFIG_SPL_MULTI_DTB_FIT=y
  37 +CONFIG_SPL_MULTI_DTB_FIT_UNCOMPRESS_SZ=0x9000
37 38 CONFIG_OF_SPL_REMOVE_PROPS="clocks clock-names interrupt-parent"
38 39 CONFIG_ENV_IS_IN_MMC=y
39 40 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
40 41 CONFIG_DM=y
41 42 CONFIG_SPL_DM=y
  43 +CONFIG_SPL_DM_DEVICE_REMOVE=y
42 44 CONFIG_SPL_DM_SEQ_ALIAS=y
43 45 CONFIG_SPL_REGMAP=y
44 46 CONFIG_SPL_SYSCON=y
configs/dra7xx_hs_evm_defconfig
... ... @@ -41,6 +41,7 @@
41 41 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
42 42 CONFIG_DM=y
43 43 CONFIG_SPL_DM=y
  44 +CONFIG_SPL_DM_SEQ_ALIAS=y
44 45 CONFIG_SPL_REGMAP=y
45 46 CONFIG_SPL_SYSCON=y
46 47 CONFIG_DWC_AHCI=y
configs/omap3_logic_defconfig
... ... @@ -34,6 +34,7 @@
34 34 # CONFIG_ENV_IS_IN_FAT is not set
35 35 CONFIG_ENV_IS_IN_NAND=y
36 36 CONFIG_SPL_DM=y
  37 +CONFIG_SPL_DM_SEQ_ALIAS=y
37 38 CONFIG_USB_FUNCTION_FASTBOOT=y
38 39 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
39 40 CONFIG_DM_I2C=y
doc/README.fdt-control
... ... @@ -184,6 +184,24 @@
184 184 'SPL Support' in doc/driver-model/README.txt for more details.
185 185  
186 186  
  187 +Using several DTBs in the SPL (CONFIG_SPL_MULTI_DTB)
  188 +----------------------------------------------------
  189 +In some rare cases it is desirable to let SPL be able to select one DTB among
  190 +many. This usually not very useful as the DTB for the SPL is small and usually
  191 +fits several platforms. However the DTB sometimes include information that do
  192 +work on several platforms (like IO tuning parameters).
  193 +In this case it is possible to use CONFIG_SPL_MULTI_DTB. This option appends to
  194 +the SPL a FIT image containing several DTBs listed in SPL_OF_LIST.
  195 +board_fit_config_name_match() is called to select the right DTB.
  196 +
  197 +If board_fit_config_name_match() relies on DM (DM driver to access an EEPROM
  198 +containing the board ID for example), it possible to start with a generic DTB
  199 +and then switch over to the right DTB after the detection. For this purpose,
  200 +the platform code must call fdtdec_resetup(). Based on the returned flag, the
  201 +platform may have to re-initiliaze the DM subusystem using dm_uninit() and
  202 +dm_init_and_scan().
  203 +
  204 +
187 205 Limitations
188 206 -----------
189 207  
drivers/core/Kconfig
... ... @@ -57,12 +57,20 @@
57 57 default y
58 58 help
59 59 We can save some code space by dropping support for removing a
60   - device. This is not normally required in SPL, so by default this
61   - option is disabled for SPL.
  60 + device.
62 61  
63 62 Note that this may have undesirable results in the USB subsystem as
64 63 it causes unplugged devices to linger around in the dm-tree, and it
65 64 causes USB host controllers to not be stopped when booting the OS.
  65 +
  66 +config SPL_DM_DEVICE_REMOVE
  67 + bool "Support device removal in SPL"
  68 + depends on SPL_DM
  69 + default n
  70 + help
  71 + We can save some code space by dropping support for removing a
  72 + device. This is not normally required in SPL, so by default this
  73 + option is disabled for SPL.
66 74  
67 75 config DM_STDIO
68 76 bool "Support stdio registration"
drivers/core/device.c
... ... @@ -70,7 +70,8 @@
70 70  
71 71 dev->seq = -1;
72 72 dev->req_seq = -1;
73   - if (CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_SEQ_ALIAS)) {
  73 + if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
  74 + (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
74 75 /*
75 76 * Some devices, such as a SPI bus, I2C bus and serial ports
76 77 * are numbered using aliases.
77 78  
... ... @@ -78,10 +79,11 @@
78 79 * This is just a 'requested' sequence, and will be
79 80 * resolved (and ->seq updated) when the device is probed.
80 81 */
81   - if (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS) {
82   - if (uc->uc_drv->name && ofnode_valid(node)) {
  82 + if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
  83 + if (uc->uc_drv->name && ofnode_valid(node))
83 84 dev_read_alias_seq(dev, &dev->req_seq);
84   - }
  85 + } else {
  86 + dev->req_seq = uclass_find_next_free_req_seq(drv->id);
85 87 }
86 88 }
87 89  
... ... @@ -187,6 +187,7 @@
187 187 {
188 188 device_remove(dm_root(), DM_REMOVE_NORMAL);
189 189 device_unbind(dm_root());
  190 + gd->dm_root = NULL;
190 191  
191 192 return 0;
192 193 }
drivers/core/uclass.c
... ... @@ -269,6 +269,30 @@
269 269 return -ENODEV;
270 270 }
271 271  
  272 +#if !CONFIG_IS_ENABLED(OF_CONTROL) || CONFIG_IS_ENABLED(OF_PLATDATA)
  273 +int uclass_find_next_free_req_seq(enum uclass_id id)
  274 +{
  275 + struct uclass *uc;
  276 + struct udevice *dev;
  277 + int ret;
  278 + int max = -1;
  279 +
  280 + ret = uclass_get(id, &uc);
  281 + if (ret)
  282 + return ret;
  283 +
  284 + list_for_each_entry(dev, &uc->dev_head, uclass_node) {
  285 + if ((dev->req_seq != -1) && (dev->req_seq > max))
  286 + max = dev->req_seq;
  287 + }
  288 +
  289 + if (max == -1)
  290 + return 0;
  291 +
  292 + return max + 1;
  293 +}
  294 +#endif
  295 +
272 296 int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
273 297 bool find_req_seq, struct udevice **devp)
274 298 {
drivers/i2c/i2c-uclass.c
... ... @@ -347,6 +347,17 @@
347 347 debug("Cannot find I2C bus %d\n", busnum);
348 348 return ret;
349 349 }
  350 +
  351 + /* detect the presence of the chip on the bus */
  352 + ret = i2c_probe_chip(bus, chip_addr, 0);
  353 + debug("%s: bus='%s', address %02x, ret=%d\n", __func__, bus->name,
  354 + chip_addr, ret);
  355 + if (ret) {
  356 + debug("Cannot detect I2C chip %02x on bus %d\n", chip_addr,
  357 + busnum);
  358 + return ret;
  359 + }
  360 +
350 361 ret = i2c_get_chip(bus, chip_addr, offset_len, devp);
351 362 if (ret) {
352 363 debug("Cannot find I2C chip %02x on bus %d\n", chip_addr,
drivers/i2c/omap24xx_i2c.c
... ... @@ -42,9 +42,19 @@
42 42 #include <dm.h>
43 43 #include <i2c.h>
44 44  
45   -#include <asm/arch/i2c.h>
46 45 #include <asm/io.h>
  46 +#include <asm/omap_i2c.h>
47 47  
  48 +/*
  49 + * Provide access to architecture-specific I2C header files for platforms
  50 + * that are NOT yet solely relying on CONFIG_DM_I2C, CONFIG_OF_CONTROL, and
  51 + * the defaults provided in 'omap24xx_i2c.h' for all U-Boot stages where I2C
  52 + * access is desired.
  53 + */
  54 +#ifndef CONFIG_ARCH_K3
  55 +#include <asm/arch/i2c.h>
  56 +#endif
  57 +
48 58 #include "omap24xx_i2c.h"
49 59  
50 60 #define I2C_TIMEOUT 1000
51 61  
52 62  
... ... @@ -52,14 +62,107 @@
52 62 /* Absolutely safe for status update at 100 kHz I2C: */
53 63 #define I2C_WAIT 200
54 64  
  65 +enum {
  66 + OMAP_I2C_REV_REG = 0, /* Only on IP V1 (OMAP34XX) */
  67 + OMAP_I2C_IE_REG, /* Only on IP V1 (OMAP34XX) */
  68 + OMAP_I2C_STAT_REG,
  69 + OMAP_I2C_WE_REG,
  70 + OMAP_I2C_SYSS_REG,
  71 + OMAP_I2C_BUF_REG,
  72 + OMAP_I2C_CNT_REG,
  73 + OMAP_I2C_DATA_REG,
  74 + OMAP_I2C_SYSC_REG,
  75 + OMAP_I2C_CON_REG,
  76 + OMAP_I2C_OA_REG,
  77 + OMAP_I2C_SA_REG,
  78 + OMAP_I2C_PSC_REG,
  79 + OMAP_I2C_SCLL_REG,
  80 + OMAP_I2C_SCLH_REG,
  81 + OMAP_I2C_SYSTEST_REG,
  82 + OMAP_I2C_BUFSTAT_REG,
  83 + /* Only on IP V2 (OMAP4430, etc.) */
  84 + OMAP_I2C_IP_V2_REVNB_LO,
  85 + OMAP_I2C_IP_V2_REVNB_HI,
  86 + OMAP_I2C_IP_V2_IRQSTATUS_RAW,
  87 + OMAP_I2C_IP_V2_IRQENABLE_SET,
  88 + OMAP_I2C_IP_V2_IRQENABLE_CLR,
  89 +};
  90 +
  91 +static const u8 __maybe_unused reg_map_ip_v1[] = {
  92 + [OMAP_I2C_REV_REG] = 0x00,
  93 + [OMAP_I2C_IE_REG] = 0x04,
  94 + [OMAP_I2C_STAT_REG] = 0x08,
  95 + [OMAP_I2C_WE_REG] = 0x0c,
  96 + [OMAP_I2C_SYSS_REG] = 0x10,
  97 + [OMAP_I2C_BUF_REG] = 0x14,
  98 + [OMAP_I2C_CNT_REG] = 0x18,
  99 + [OMAP_I2C_DATA_REG] = 0x1c,
  100 + [OMAP_I2C_SYSC_REG] = 0x20,
  101 + [OMAP_I2C_CON_REG] = 0x24,
  102 + [OMAP_I2C_OA_REG] = 0x28,
  103 + [OMAP_I2C_SA_REG] = 0x2c,
  104 + [OMAP_I2C_PSC_REG] = 0x30,
  105 + [OMAP_I2C_SCLL_REG] = 0x34,
  106 + [OMAP_I2C_SCLH_REG] = 0x38,
  107 + [OMAP_I2C_SYSTEST_REG] = 0x3c,
  108 + [OMAP_I2C_BUFSTAT_REG] = 0x40,
  109 +};
  110 +
  111 +static const u8 __maybe_unused reg_map_ip_v2[] = {
  112 + [OMAP_I2C_STAT_REG] = 0x28,
  113 + [OMAP_I2C_WE_REG] = 0x34,
  114 + [OMAP_I2C_SYSS_REG] = 0x90,
  115 + [OMAP_I2C_BUF_REG] = 0x94,
  116 + [OMAP_I2C_CNT_REG] = 0x98,
  117 + [OMAP_I2C_DATA_REG] = 0x9c,
  118 + [OMAP_I2C_SYSC_REG] = 0x10,
  119 + [OMAP_I2C_CON_REG] = 0xa4,
  120 + [OMAP_I2C_OA_REG] = 0xa8,
  121 + [OMAP_I2C_SA_REG] = 0xac,
  122 + [OMAP_I2C_PSC_REG] = 0xb0,
  123 + [OMAP_I2C_SCLL_REG] = 0xb4,
  124 + [OMAP_I2C_SCLH_REG] = 0xb8,
  125 + [OMAP_I2C_SYSTEST_REG] = 0xbc,
  126 + [OMAP_I2C_BUFSTAT_REG] = 0xc0,
  127 + [OMAP_I2C_IP_V2_REVNB_LO] = 0x00,
  128 + [OMAP_I2C_IP_V2_REVNB_HI] = 0x04,
  129 + [OMAP_I2C_IP_V2_IRQSTATUS_RAW] = 0x24,
  130 + [OMAP_I2C_IP_V2_IRQENABLE_SET] = 0x2c,
  131 + [OMAP_I2C_IP_V2_IRQENABLE_CLR] = 0x30,
  132 +};
  133 +
55 134 struct omap_i2c {
56 135 struct udevice *clk;
  136 + int ip_rev;
57 137 struct i2c *regs;
58 138 unsigned int speed;
59 139 int waitdelay;
60 140 int clk_id;
61 141 };
62 142  
  143 +static inline const u8 *omap_i2c_get_ip_reg_map(int ip_rev)
  144 +{
  145 + switch (ip_rev) {
  146 + case OMAP_I2C_REV_V1:
  147 + return reg_map_ip_v1;
  148 + case OMAP_I2C_REV_V2:
  149 + /* Fall through... */
  150 + default:
  151 + return reg_map_ip_v2;
  152 + }
  153 +}
  154 +
  155 +static inline void omap_i2c_write_reg(void __iomem *base, int ip_rev,
  156 + u16 val, int reg)
  157 +{
  158 + writew(val, base + omap_i2c_get_ip_reg_map(ip_rev)[reg]);
  159 +}
  160 +
  161 +static inline u16 omap_i2c_read_reg(void __iomem *base, int ip_rev, int reg)
  162 +{
  163 + return readw(base + omap_i2c_get_ip_reg_map(ip_rev)[reg]);
  164 +}
  165 +
63 166 static int omap24_i2c_findpsc(u32 *pscl, u32 *psch, uint speed)
64 167 {
65 168 unsigned long internal_clk = 0, fclk;
66 169  
67 170  
68 171  
69 172  
70 173  
... ... @@ -114,29 +217,31 @@
114 217 * Wait for the bus to be free by checking the Bus Busy (BB)
115 218 * bit to become clear
116 219 */
117   -static int wait_for_bb(struct i2c *i2c_base, int waitdelay)
  220 +static int wait_for_bb(void __iomem *i2c_base, int ip_rev, int waitdelay)
118 221 {
119 222 int timeout = I2C_TIMEOUT;
  223 + int irq_stat_reg;
120 224 u16 stat;
121 225  
122   - writew(0xFFFF, &i2c_base->stat); /* clear current interrupts...*/
123   -#if defined(CONFIG_OMAP34XX)
124   - while ((stat = readw(&i2c_base->stat) & I2C_STAT_BB) && timeout--) {
125   -#else
126   - /* Read RAW status */
127   - while ((stat = readw(&i2c_base->irqstatus_raw) &
  226 + irq_stat_reg = (ip_rev == OMAP_I2C_REV_V1) ?
  227 + OMAP_I2C_STAT_REG : OMAP_I2C_IP_V2_IRQSTATUS_RAW;
  228 +
  229 + /* clear current interrupts */
  230 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
  231 +
  232 + while ((stat = omap_i2c_read_reg(i2c_base, ip_rev, irq_stat_reg) &
128 233 I2C_STAT_BB) && timeout--) {
129   -#endif
130   - writew(stat, &i2c_base->stat);
  234 + omap_i2c_write_reg(i2c_base, ip_rev, stat, OMAP_I2C_STAT_REG);
131 235 udelay(waitdelay);
132 236 }
133 237  
134 238 if (timeout <= 0) {
135   - printf("Timed out in wait_for_bb: status=%04x\n",
136   - stat);
  239 + printf("Timed out in %s: status=%04x\n", __func__, stat);
137 240 return 1;
138 241 }
139   - writew(0xFFFF, &i2c_base->stat); /* clear delayed stuff*/
  242 +
  243 + /* clear delayed stuff */
  244 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
140 245 return 0;
141 246 }
142 247  
143 248  
144 249  
145 250  
146 251  
147 252  
148 253  
... ... @@ -144,40 +249,37 @@
144 249 * Wait for the I2C controller to complete current action
145 250 * and update status
146 251 */
147   -static u16 wait_for_event(struct i2c *i2c_base, int waitdelay)
  252 +static u16 wait_for_event(void __iomem *i2c_base, int ip_rev, int waitdelay)
148 253 {
149 254 u16 status;
150 255 int timeout = I2C_TIMEOUT;
  256 + int irq_stat_reg;
151 257  
  258 + irq_stat_reg = (ip_rev == OMAP_I2C_REV_V1) ?
  259 + OMAP_I2C_STAT_REG : OMAP_I2C_IP_V2_IRQSTATUS_RAW;
152 260 do {
153 261 udelay(waitdelay);
154   -#if defined(CONFIG_OMAP34XX)
155   - status = readw(&i2c_base->stat);
156   -#else
157   - /* Read RAW status */
158   - status = readw(&i2c_base->irqstatus_raw);
159   -#endif
  262 + status = omap_i2c_read_reg(i2c_base, ip_rev, irq_stat_reg);
160 263 } while (!(status &
161 264 (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY |
162 265 I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK |
163 266 I2C_STAT_AL)) && timeout--);
164 267  
165 268 if (timeout <= 0) {
166   - printf("Timed out in wait_for_event: status=%04x\n",
167   - status);
  269 + printf("Timed out in %s: status=%04x\n", __func__, status);
168 270 /*
169 271 * If status is still 0 here, probably the bus pads have
170 272 * not been configured for I2C, and/or pull-ups are missing.
171 273 */
172 274 printf("Check if pads/pull-ups of bus are properly configured\n");
173   - writew(0xFFFF, &i2c_base->stat);
  275 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
174 276 status = 0;
175 277 }
176 278  
177 279 return status;
178 280 }
179 281  
180   -static void flush_fifo(struct i2c *i2c_base)
  282 +static void flush_fifo(void __iomem *i2c_base, int ip_rev)
181 283 {
182 284 u16 stat;
183 285  
184 286  
185 287  
... ... @@ -186,17 +288,18 @@
186 288 * you get a bus error
187 289 */
188 290 while (1) {
189   - stat = readw(&i2c_base->stat);
  291 + stat = omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_STAT_REG);
190 292 if (stat == I2C_STAT_RRDY) {
191   - readb(&i2c_base->data);
192   - writew(I2C_STAT_RRDY, &i2c_base->stat);
  293 + omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_DATA_REG);
  294 + omap_i2c_write_reg(i2c_base, ip_rev,
  295 + I2C_STAT_RRDY, OMAP_I2C_STAT_REG);
193 296 udelay(1000);
194 297 } else
195 298 break;
196 299 }
197 300 }
198 301  
199   -static int __omap24_i2c_setspeed(struct i2c *i2c_base, uint speed,
  302 +static int __omap24_i2c_setspeed(void __iomem *i2c_base, int ip_rev, uint speed,
200 303 int *waitdelay)
201 304 {
202 305 int psc, fsscll = 0, fssclh = 0;
203 306  
204 307  
205 308  
206 309  
207 310  
208 311  
209 312  
210 313  
211 314  
212 315  
213 316  
214 317  
215 318  
216 319  
217 320  
218 321  
... ... @@ -248,79 +351,89 @@
248 351 }
249 352 }
250 353  
251   - *waitdelay = (10000000 / speed) * 2; /* wait for 20 clkperiods */
252   - writew(0, &i2c_base->con);
253   - writew(psc, &i2c_base->psc);
254   - writew(scll, &i2c_base->scll);
255   - writew(sclh, &i2c_base->sclh);
256   - writew(I2C_CON_EN, &i2c_base->con);
257   - writew(0xFFFF, &i2c_base->stat); /* clear all pending status */
  354 + /* wait for 20 clkperiods */
  355 + *waitdelay = (10000000 / speed) * 2;
258 356  
  357 + omap_i2c_write_reg(i2c_base, ip_rev, 0, OMAP_I2C_CON_REG);
  358 + omap_i2c_write_reg(i2c_base, ip_rev, psc, OMAP_I2C_PSC_REG);
  359 + omap_i2c_write_reg(i2c_base, ip_rev, scll, OMAP_I2C_SCLL_REG);
  360 + omap_i2c_write_reg(i2c_base, ip_rev, sclh, OMAP_I2C_SCLH_REG);
  361 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN, OMAP_I2C_CON_REG);
  362 +
  363 + /* clear all pending status */
  364 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
  365 +
259 366 return 0;
260 367 }
261 368  
262   -static void omap24_i2c_deblock(struct i2c *i2c_base)
  369 +static void omap24_i2c_deblock(void __iomem *i2c_base, int ip_rev)
263 370 {
264 371 int i;
265 372 u16 systest;
266 373 u16 orgsystest;
267 374  
268 375 /* set test mode ST_EN = 1 */
269   - orgsystest = readw(&i2c_base->systest);
  376 + orgsystest = omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_SYSTEST_REG);
270 377 systest = orgsystest;
  378 +
271 379 /* enable testmode */
272 380 systest |= I2C_SYSTEST_ST_EN;
273   - writew(systest, &i2c_base->systest);
  381 + omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG);
274 382 systest &= ~I2C_SYSTEST_TMODE_MASK;
275 383 systest |= 3 << I2C_SYSTEST_TMODE_SHIFT;
276   - writew(systest, &i2c_base->systest);
  384 + omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG);
277 385  
278 386 /* set SCL, SDA = 1 */
279 387 systest |= I2C_SYSTEST_SCL_O | I2C_SYSTEST_SDA_O;
280   - writew(systest, &i2c_base->systest);
  388 + omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG);
281 389 udelay(10);
282 390  
283 391 /* toggle scl 9 clocks */
284 392 for (i = 0; i < 9; i++) {
285 393 /* SCL = 0 */
286 394 systest &= ~I2C_SYSTEST_SCL_O;
287   - writew(systest, &i2c_base->systest);
  395 + omap_i2c_write_reg(i2c_base, ip_rev,
  396 + systest, OMAP_I2C_SYSTEST_REG);
288 397 udelay(10);
289 398 /* SCL = 1 */
290 399 systest |= I2C_SYSTEST_SCL_O;
291   - writew(systest, &i2c_base->systest);
  400 + omap_i2c_write_reg(i2c_base, ip_rev,
  401 + systest, OMAP_I2C_SYSTEST_REG);
292 402 udelay(10);
293 403 }
294 404  
295 405 /* send stop */
296 406 systest &= ~I2C_SYSTEST_SDA_O;
297   - writew(systest, &i2c_base->systest);
  407 + omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG);
298 408 udelay(10);
299 409 systest |= I2C_SYSTEST_SCL_O | I2C_SYSTEST_SDA_O;
300   - writew(systest, &i2c_base->systest);
  410 + omap_i2c_write_reg(i2c_base, ip_rev, systest, OMAP_I2C_SYSTEST_REG);
301 411 udelay(10);
302 412  
303 413 /* restore original mode */
304   - writew(orgsystest, &i2c_base->systest);
  414 + omap_i2c_write_reg(i2c_base, ip_rev, orgsystest, OMAP_I2C_SYSTEST_REG);
305 415 }
306 416  
307   -static void __omap24_i2c_init(struct i2c *i2c_base, int speed, int slaveadd,
308   - int *waitdelay)
  417 +static void __omap24_i2c_init(void __iomem *i2c_base, int ip_rev, int speed,
  418 + int slaveadd, int *waitdelay)
309 419 {
310 420 int timeout = I2C_TIMEOUT;
311 421 int deblock = 1;
312 422  
313 423 retry:
314   - if (readw(&i2c_base->con) & I2C_CON_EN) {
315   - writew(0, &i2c_base->con);
  424 + if (omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_CON_REG) &
  425 + I2C_CON_EN) {
  426 + omap_i2c_write_reg(i2c_base, ip_rev, 0, OMAP_I2C_CON_REG);
316 427 udelay(50000);
317 428 }
318 429  
319   - writew(0x2, &i2c_base->sysc); /* for ES2 after soft reset */
  430 + /* for ES2 after soft reset */
  431 + omap_i2c_write_reg(i2c_base, ip_rev, 0x2, OMAP_I2C_SYSC_REG);
320 432 udelay(1000);
321 433  
322   - writew(I2C_CON_EN, &i2c_base->con);
323   - while (!(readw(&i2c_base->syss) & I2C_SYSS_RDONE) && timeout--) {
  434 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN, OMAP_I2C_CON_REG);
  435 + while (!(omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_SYSS_REG) &
  436 + I2C_SYSS_RDONE) && timeout--) {
324 437 if (timeout <= 0) {
325 438 puts("ERROR: Timeout in soft-reset\n");
326 439 return;
327 440  
328 441  
329 442  
330 443  
331 444  
... ... @@ -328,30 +441,33 @@
328 441 udelay(1000);
329 442 }
330 443  
331   - if (0 != __omap24_i2c_setspeed(i2c_base, speed, waitdelay)) {
  444 + if (__omap24_i2c_setspeed(i2c_base, ip_rev, speed, waitdelay)) {
332 445 printf("ERROR: failed to setup I2C bus-speed!\n");
333 446 return;
334 447 }
335 448  
336 449 /* own address */
337   - writew(slaveadd, &i2c_base->oa);
  450 + omap_i2c_write_reg(i2c_base, ip_rev, slaveadd, OMAP_I2C_OA_REG);
338 451  
339   -#if defined(CONFIG_OMAP34XX)
340   - /*
341   - * Have to enable interrupts for OMAP2/3, these IPs don't have
342   - * an 'irqstatus_raw' register and we shall have to poll 'stat'
343   - */
344   - writew(I2C_IE_XRDY_IE | I2C_IE_RRDY_IE | I2C_IE_ARDY_IE |
345   - I2C_IE_NACK_IE | I2C_IE_AL_IE, &i2c_base->ie);
346   -#endif
  452 + if (ip_rev == OMAP_I2C_REV_V1) {
  453 + /*
  454 + * Have to enable interrupts for OMAP2/3, these IPs don't have
  455 + * an 'irqstatus_raw' register and we shall have to poll 'stat'
  456 + */
  457 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_IE_XRDY_IE |
  458 + I2C_IE_RRDY_IE | I2C_IE_ARDY_IE |
  459 + I2C_IE_NACK_IE | I2C_IE_AL_IE,
  460 + OMAP_I2C_IE_REG);
  461 + }
  462 +
347 463 udelay(1000);
348   - flush_fifo(i2c_base);
349   - writew(0xFFFF, &i2c_base->stat);
  464 + flush_fifo(i2c_base, ip_rev);
  465 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
350 466  
351 467 /* Handle possible failed I2C state */
352   - if (wait_for_bb(i2c_base, *waitdelay))
  468 + if (wait_for_bb(i2c_base, ip_rev, *waitdelay))
353 469 if (deblock == 1) {
354   - omap24_i2c_deblock(i2c_base);
  470 + omap24_i2c_deblock(i2c_base, ip_rev);
355 471 deblock = 0;
356 472 goto retry;
357 473 }
358 474  
359 475  
360 476  
361 477  
362 478  
... ... @@ -361,25 +477,28 @@
361 477 * i2c_probe: Use write access. Allows to identify addresses that are
362 478 * write-only (like the config register of dual-port EEPROMs)
363 479 */
364   -static int __omap24_i2c_probe(struct i2c *i2c_base, int waitdelay, uchar chip)
  480 +static int __omap24_i2c_probe(void __iomem *i2c_base, int ip_rev, int waitdelay,
  481 + uchar chip)
365 482 {
366 483 u16 status;
367 484 int res = 1; /* default = fail */
368 485  
369   - if (chip == readw(&i2c_base->oa))
  486 + if (chip == omap_i2c_read_reg(i2c_base, ip_rev, OMAP_I2C_OA_REG))
370 487 return res;
371 488  
372 489 /* Wait until bus is free */
373   - if (wait_for_bb(i2c_base, waitdelay))
  490 + if (wait_for_bb(i2c_base, ip_rev, waitdelay))
374 491 return res;
375 492  
376 493 /* No data transfer, slave addr only */
377   - writew(chip, &i2c_base->sa);
  494 + omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG);
  495 +
378 496 /* Stop bit needed here */
379   - writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
380   - I2C_CON_STP, &i2c_base->con);
  497 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST |
  498 + I2C_CON_STT | I2C_CON_TRX | I2C_CON_STP,
  499 + OMAP_I2C_CON_REG);
381 500  
382   - status = wait_for_event(i2c_base, waitdelay);
  501 + status = wait_for_event(i2c_base, ip_rev, waitdelay);
383 502  
384 503 if ((status & ~I2C_STAT_XRDY) == 0 || (status & I2C_STAT_AL)) {
385 504 /*
386 505  
387 506  
388 507  
... ... @@ -400,14 +519,17 @@
400 519 res = 0; /* Device found */
401 520 udelay(waitdelay);/* Required by AM335X in SPL */
402 521 /* Abort transfer (force idle state) */
403   - writew(I2C_CON_MST | I2C_CON_TRX, &i2c_base->con); /* Reset */
  522 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_MST | I2C_CON_TRX,
  523 + OMAP_I2C_CON_REG); /* Reset */
404 524 udelay(1000);
405   - writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_TRX |
406   - I2C_CON_STP, &i2c_base->con); /* STP */
  525 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST |
  526 + I2C_CON_TRX | I2C_CON_STP,
  527 + OMAP_I2C_CON_REG); /* STP */
407 528 }
  529 +
408 530 pr_exit:
409   - flush_fifo(i2c_base);
410   - writew(0xFFFF, &i2c_base->stat);
  531 + flush_fifo(i2c_base, ip_rev);
  532 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
411 533 return res;
412 534 }
413 535  
... ... @@ -424,8 +546,9 @@
424 546 * or that do not need a register address at all (such as some clock
425 547 * distributors).
426 548 */
427   -static int __omap24_i2c_read(struct i2c *i2c_base, int waitdelay, uchar chip,
428   - uint addr, int alen, uchar *buffer, int len)
  549 +static int __omap24_i2c_read(void __iomem *i2c_base, int ip_rev, int waitdelay,
  550 + uchar chip, uint addr, int alen, uchar *buffer,
  551 + int len)
429 552 {
430 553 int i2c_error = 0;
431 554 u16 status;
432 555  
... ... @@ -434,10 +557,12 @@
434 557 puts("I2C read: addr len < 0\n");
435 558 return 1;
436 559 }
  560 +
437 561 if (len < 0) {
438 562 puts("I2C read: data len < 0\n");
439 563 return 1;
440 564 }
  565 +
441 566 if (buffer == NULL) {
442 567 puts("I2C read: NULL pointer passed\n");
443 568 return 1;
444 569  
445 570  
446 571  
447 572  
448 573  
... ... @@ -471,28 +596,29 @@
471 596 #endif
472 597  
473 598 /* Wait until bus not busy */
474   - if (wait_for_bb(i2c_base, waitdelay))
  599 + if (wait_for_bb(i2c_base, ip_rev, waitdelay))
475 600 return 1;
476 601  
477 602 /* Zero, one or two bytes reg address (offset) */
478   - writew(alen, &i2c_base->cnt);
  603 + omap_i2c_write_reg(i2c_base, ip_rev, alen, OMAP_I2C_CNT_REG);
479 604 /* Set slave address */
480   - writew(chip, &i2c_base->sa);
  605 + omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG);
481 606  
482 607 if (alen) {
483 608 /* Must write reg offset first */
484 609 #ifdef CONFIG_I2C_REPEATED_START
485 610 /* No stop bit, use Repeated Start (Sr) */
486   - writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT |
487   - I2C_CON_TRX, &i2c_base->con);
  611 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST |
  612 + I2C_CON_STT | I2C_CON_TRX, OMAP_I2C_CON_REG);
488 613 #else
489 614 /* Stop - Start (P-S) */
490   - writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_STP |
491   - I2C_CON_TRX, &i2c_base->con);
  615 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST |
  616 + I2C_CON_STT | I2C_CON_STP | I2C_CON_TRX,
  617 + OMAP_I2C_CON_REG);
492 618 #endif
493 619 /* Send register offset */
494 620 while (1) {
495   - status = wait_for_event(i2c_base, waitdelay);
  621 + status = wait_for_event(i2c_base, ip_rev, waitdelay);
496 622 /* Try to identify bus that is not padconf'd for I2C */
497 623 if (status == I2C_STAT_XRDY) {
498 624 i2c_error = 2;
499 625  
500 626  
501 627  
502 628  
503 629  
504 630  
505 631  
... ... @@ -508,31 +634,37 @@
508 634 }
509 635 if (alen) {
510 636 if (status & I2C_STAT_XRDY) {
  637 + u8 addr_byte;
511 638 alen--;
512   - /* Do we have to use byte access? */
513   - writeb((addr >> (8 * alen)) & 0xff,
514   - &i2c_base->data);
515   - writew(I2C_STAT_XRDY, &i2c_base->stat);
  639 + addr_byte = (addr >> (8 * alen)) & 0xff;
  640 + omap_i2c_write_reg(i2c_base, ip_rev,
  641 + addr_byte,
  642 + OMAP_I2C_DATA_REG);
  643 + omap_i2c_write_reg(i2c_base, ip_rev,
  644 + I2C_STAT_XRDY,
  645 + OMAP_I2C_STAT_REG);
516 646 }
517 647 }
518 648 if (status & I2C_STAT_ARDY) {
519   - writew(I2C_STAT_ARDY, &i2c_base->stat);
  649 + omap_i2c_write_reg(i2c_base, ip_rev,
  650 + I2C_STAT_ARDY,
  651 + OMAP_I2C_STAT_REG);
520 652 break;
521 653 }
522 654 }
523 655 }
  656 +
524 657 /* Set slave address */
525   - writew(chip, &i2c_base->sa);
  658 + omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG);
526 659 /* Read len bytes from slave */
527   - writew(len, &i2c_base->cnt);
  660 + omap_i2c_write_reg(i2c_base, ip_rev, len, OMAP_I2C_CNT_REG);
528 661 /* Need stop bit here */
529   - writew(I2C_CON_EN | I2C_CON_MST |
530   - I2C_CON_STT | I2C_CON_STP,
531   - &i2c_base->con);
  662 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST |
  663 + I2C_CON_STT | I2C_CON_STP, OMAP_I2C_CON_REG);
532 664  
533 665 /* Receive data */
534 666 while (1) {
535   - status = wait_for_event(i2c_base, waitdelay);
  667 + status = wait_for_event(i2c_base, ip_rev, waitdelay);
536 668 /*
537 669 * Try to identify bus that is not padconf'd for I2C. This
538 670 * state could be left over from previous transactions if
539 671  
540 672  
541 673  
... ... @@ -549,24 +681,28 @@
549 681 goto rd_exit;
550 682 }
551 683 if (status & I2C_STAT_RRDY) {
552   - *buffer++ = readb(&i2c_base->data);
553   - writew(I2C_STAT_RRDY, &i2c_base->stat);
  684 + *buffer++ = omap_i2c_read_reg(i2c_base, ip_rev,
  685 + OMAP_I2C_DATA_REG);
  686 + omap_i2c_write_reg(i2c_base, ip_rev,
  687 + I2C_STAT_RRDY, OMAP_I2C_STAT_REG);
554 688 }
555 689 if (status & I2C_STAT_ARDY) {
556   - writew(I2C_STAT_ARDY, &i2c_base->stat);
  690 + omap_i2c_write_reg(i2c_base, ip_rev,
  691 + I2C_STAT_ARDY, OMAP_I2C_STAT_REG);
557 692 break;
558 693 }
559 694 }
560 695  
561 696 rd_exit:
562   - flush_fifo(i2c_base);
563   - writew(0xFFFF, &i2c_base->stat);
  697 + flush_fifo(i2c_base, ip_rev);
  698 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
564 699 return i2c_error;
565 700 }
566 701  
567 702 /* i2c_write: Address (reg offset) may be 0, 1 or 2 bytes long. */
568   -static int __omap24_i2c_write(struct i2c *i2c_base, int waitdelay, uchar chip,
569   - uint addr, int alen, uchar *buffer, int len)
  703 +static int __omap24_i2c_write(void __iomem *i2c_base, int ip_rev, int waitdelay,
  704 + uchar chip, uint addr, int alen, uchar *buffer,
  705 + int len)
570 706 {
571 707 int i;
572 708 u16 status;
573 709  
574 710  
575 711  
576 712  
... ... @@ -617,20 +753,21 @@
617 753 #endif
618 754  
619 755 /* Wait until bus not busy */
620   - if (wait_for_bb(i2c_base, waitdelay))
  756 + if (wait_for_bb(i2c_base, ip_rev, waitdelay))
621 757 return 1;
622 758  
623 759 /* Start address phase - will write regoffset + len bytes data */
624   - writew(alen + len, &i2c_base->cnt);
  760 + omap_i2c_write_reg(i2c_base, ip_rev, alen + len, OMAP_I2C_CNT_REG);
625 761 /* Set slave address */
626   - writew(chip, &i2c_base->sa);
  762 + omap_i2c_write_reg(i2c_base, ip_rev, chip, OMAP_I2C_SA_REG);
627 763 /* Stop bit needed here */
628   - writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
629   - I2C_CON_STP, &i2c_base->con);
  764 + omap_i2c_write_reg(i2c_base, ip_rev, I2C_CON_EN | I2C_CON_MST |
  765 + I2C_CON_STT | I2C_CON_TRX | I2C_CON_STP,
  766 + OMAP_I2C_CON_REG);
630 767  
631 768 while (alen) {
632 769 /* Must write reg offset (one or two bytes) */
633   - status = wait_for_event(i2c_base, waitdelay);
  770 + status = wait_for_event(i2c_base, ip_rev, waitdelay);
634 771 /* Try to identify bus that is not padconf'd for I2C */
635 772 if (status == I2C_STAT_XRDY) {
636 773 i2c_error = 2;
... ... @@ -646,8 +783,11 @@
646 783 }
647 784 if (status & I2C_STAT_XRDY) {
648 785 alen--;
649   - writeb((addr >> (8 * alen)) & 0xff, &i2c_base->data);
650   - writew(I2C_STAT_XRDY, &i2c_base->stat);
  786 + omap_i2c_write_reg(i2c_base, ip_rev,
  787 + (addr >> (8 * alen)) & 0xff,
  788 + OMAP_I2C_DATA_REG);
  789 + omap_i2c_write_reg(i2c_base, ip_rev,
  790 + I2C_STAT_XRDY, OMAP_I2C_STAT_REG);
651 791 } else {
652 792 i2c_error = 1;
653 793 printf("i2c_write: bus not ready for addr Tx (status=0x%x)\n",
654 794  
... ... @@ -655,9 +795,10 @@
655 795 goto wr_exit;
656 796 }
657 797 }
  798 +
658 799 /* Address phase is over, now write data */
659 800 for (i = 0; i < len; i++) {
660   - status = wait_for_event(i2c_base, waitdelay);
  801 + status = wait_for_event(i2c_base, ip_rev, waitdelay);
661 802 if (status == 0 || (status & I2C_STAT_NACK)) {
662 803 i2c_error = 1;
663 804 printf("i2c_write: error waiting for data ACK (status=0x%x)\n",
... ... @@ -665,8 +806,10 @@
665 806 goto wr_exit;
666 807 }
667 808 if (status & I2C_STAT_XRDY) {
668   - writeb(buffer[i], &i2c_base->data);
669   - writew(I2C_STAT_XRDY, &i2c_base->stat);
  809 + omap_i2c_write_reg(i2c_base, ip_rev,
  810 + buffer[i], OMAP_I2C_DATA_REG);
  811 + omap_i2c_write_reg(i2c_base, ip_rev,
  812 + I2C_STAT_XRDY, OMAP_I2C_STAT_REG);
670 813 } else {
671 814 i2c_error = 1;
672 815 printf("i2c_write: bus not ready for data Tx (i=%d)\n",
673 816  
674 817  
... ... @@ -674,19 +817,20 @@
674 817 goto wr_exit;
675 818 }
676 819 }
  820 +
677 821 /*
678 822 * poll ARDY bit for making sure that last byte really has been
679 823 * transferred on the bus.
680 824 */
681 825 do {
682   - status = wait_for_event(i2c_base, waitdelay);
  826 + status = wait_for_event(i2c_base, ip_rev, waitdelay);
683 827 } while (!(status & I2C_STAT_ARDY) && timeout--);
684 828 if (timeout <= 0)
685 829 printf("i2c_write: timed out writig last byte!\n");
686 830  
687 831 wr_exit:
688   - flush_fifo(i2c_base);
689   - writew(0xFFFF, &i2c_base->stat);
  832 + flush_fifo(i2c_base, ip_rev);
  833 + omap_i2c_write_reg(i2c_base, ip_rev, 0xFFFF, OMAP_I2C_STAT_REG);
690 834 return i2c_error;
691 835 }
692 836  
693 837  
694 838  
695 839  
696 840  
697 841  
... ... @@ -695,26 +839,26 @@
695 839 * The legacy I2C functions. These need to get removed once
696 840 * all users of this driver are converted to DM.
697 841 */
698   -static struct i2c *omap24_get_base(struct i2c_adapter *adap)
  842 +static void __iomem *omap24_get_base(struct i2c_adapter *adap)
699 843 {
700 844 switch (adap->hwadapnr) {
701 845 case 0:
702   - return (struct i2c *)I2C_BASE1;
  846 + return (void __iomem *)I2C_BASE1;
703 847 break;
704 848 case 1:
705   - return (struct i2c *)I2C_BASE2;
  849 + return (void __iomem *)I2C_BASE2;
706 850 break;
707 851 #if (CONFIG_SYS_I2C_BUS_MAX > 2)
708 852 case 2:
709   - return (struct i2c *)I2C_BASE3;
  853 + return (void __iomem *)I2C_BASE3;
710 854 break;
711 855 #if (CONFIG_SYS_I2C_BUS_MAX > 3)
712 856 case 3:
713   - return (struct i2c *)I2C_BASE4;
  857 + return (void __iomem *)I2C_BASE4;
714 858 break;
715 859 #if (CONFIG_SYS_I2C_BUS_MAX > 4)
716 860 case 4:
717   - return (struct i2c *)I2C_BASE5;
  861 + return (void __iomem *)I2C_BASE5;
718 862 break;
719 863 #endif
720 864 #endif
721 865  
722 866  
723 867  
724 868  
725 869  
726 870  
727 871  
728 872  
... ... @@ -723,35 +867,46 @@
723 867 printf("wrong hwadapnr: %d\n", adap->hwadapnr);
724 868 break;
725 869 }
  870 +
726 871 return NULL;
727 872 }
728 873  
  874 +static int omap24_get_ip_rev(void)
  875 +{
  876 +#ifdef CONFIG_OMAP34XX
  877 + return OMAP_I2C_REV_V1;
  878 +#else
  879 + return OMAP_I2C_REV_V2;
  880 +#endif
  881 +}
729 882  
730 883 static int omap24_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr,
731 884 int alen, uchar *buffer, int len)
732 885 {
733   - struct i2c *i2c_base = omap24_get_base(adap);
  886 + void __iomem *i2c_base = omap24_get_base(adap);
  887 + int ip_rev = omap24_get_ip_rev();
734 888  
735   - return __omap24_i2c_read(i2c_base, adap->waitdelay, chip, addr,
  889 + return __omap24_i2c_read(i2c_base, ip_rev, adap->waitdelay, chip, addr,
736 890 alen, buffer, len);
737 891 }
738 892  
739   -
740 893 static int omap24_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr,
741 894 int alen, uchar *buffer, int len)
742 895 {
743   - struct i2c *i2c_base = omap24_get_base(adap);
  896 + void __iomem *i2c_base = omap24_get_base(adap);
  897 + int ip_rev = omap24_get_ip_rev();
744 898  
745   - return __omap24_i2c_write(i2c_base, adap->waitdelay, chip, addr,
  899 + return __omap24_i2c_write(i2c_base, ip_rev, adap->waitdelay, chip, addr,
746 900 alen, buffer, len);
747 901 }
748 902  
749 903 static uint omap24_i2c_setspeed(struct i2c_adapter *adap, uint speed)
750 904 {
751   - struct i2c *i2c_base = omap24_get_base(adap);
  905 + void __iomem *i2c_base = omap24_get_base(adap);
  906 + int ip_rev = omap24_get_ip_rev();
752 907 int ret;
753 908  
754   - ret = __omap24_i2c_setspeed(i2c_base, speed, &adap->waitdelay);
  909 + ret = __omap24_i2c_setspeed(i2c_base, ip_rev, speed, &adap->waitdelay);
755 910 if (ret) {
756 911 pr_err("%s: set i2c speed failed\n", __func__);
757 912 return ret;
758 913  
759 914  
760 915  
... ... @@ -764,16 +919,19 @@
764 919  
765 920 static void omap24_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
766 921 {
767   - struct i2c *i2c_base = omap24_get_base(adap);
  922 + void __iomem *i2c_base = omap24_get_base(adap);
  923 + int ip_rev = omap24_get_ip_rev();
768 924  
769   - return __omap24_i2c_init(i2c_base, speed, slaveadd, &adap->waitdelay);
  925 + return __omap24_i2c_init(i2c_base, ip_rev, speed, slaveadd,
  926 + &adap->waitdelay);
770 927 }
771 928  
772 929 static int omap24_i2c_probe(struct i2c_adapter *adap, uchar chip)
773 930 {
774   - struct i2c *i2c_base = omap24_get_base(adap);
  931 + void __iomem *i2c_base = omap24_get_base(adap);
  932 + int ip_rev = omap24_get_ip_rev();
775 933  
776   - return __omap24_i2c_probe(i2c_base, adap->waitdelay, chip);
  934 + return __omap24_i2c_probe(i2c_base, ip_rev, adap->waitdelay, chip);
777 935 }
778 936  
779 937 #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED1)
... ... @@ -793,6 +951,7 @@
793 951 CONFIG_SYS_OMAP24_I2C_SPEED1,
794 952 CONFIG_SYS_OMAP24_I2C_SLAVE1,
795 953 1)
  954 +
796 955 #if (CONFIG_SYS_I2C_BUS_MAX > 2)
797 956 #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED2)
798 957 #define CONFIG_SYS_OMAP24_I2C_SPEED2 CONFIG_SYS_OMAP24_I2C_SPEED
799 958  
... ... @@ -847,11 +1006,13 @@
847 1006 for (; nmsgs > 0; nmsgs--, msg++) {
848 1007 debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
849 1008 if (msg->flags & I2C_M_RD) {
850   - ret = __omap24_i2c_read(priv->regs, priv->waitdelay,
  1009 + ret = __omap24_i2c_read(priv->regs, priv->ip_rev,
  1010 + priv->waitdelay,
851 1011 msg->addr, 0, 0, msg->buf,
852 1012 msg->len);
853 1013 } else {
854   - ret = __omap24_i2c_write(priv->regs, priv->waitdelay,
  1014 + ret = __omap24_i2c_write(priv->regs, priv->ip_rev,
  1015 + priv->waitdelay,
855 1016 msg->addr, 0, 0, msg->buf,
856 1017 msg->len);
857 1018 }
... ... @@ -870,7 +1031,8 @@
870 1031  
871 1032 priv->speed = speed;
872 1033  
873   - return __omap24_i2c_setspeed(priv->regs, speed, &priv->waitdelay);
  1034 + return __omap24_i2c_setspeed(priv->regs, priv->ip_rev, speed,
  1035 + &priv->waitdelay);
874 1036 }
875 1037  
876 1038 static int omap_i2c_probe_chip(struct udevice *bus, uint chip_addr,
877 1039  
878 1040  
879 1041  
880 1042  
881 1043  
882 1044  
... ... @@ -878,33 +1040,41 @@
878 1040 {
879 1041 struct omap_i2c *priv = dev_get_priv(bus);
880 1042  
881   - return __omap24_i2c_probe(priv->regs, priv->waitdelay, chip_addr);
  1043 + return __omap24_i2c_probe(priv->regs, priv->ip_rev, priv->waitdelay,
  1044 + chip_addr);
882 1045 }
883 1046  
884 1047 static int omap_i2c_probe(struct udevice *bus)
885 1048 {
886 1049 struct omap_i2c *priv = dev_get_priv(bus);
  1050 + struct omap_i2c_platdata *plat = dev_get_platdata(bus);
887 1051  
888   - __omap24_i2c_init(priv->regs, priv->speed, 0, &priv->waitdelay);
  1052 + priv->speed = plat->speed;
  1053 + priv->regs = map_physmem(plat->base, sizeof(void *),
  1054 + MAP_NOCACHE);
  1055 + priv->ip_rev = plat->ip_rev;
889 1056  
  1057 + __omap24_i2c_init(priv->regs, priv->ip_rev, priv->speed, 0,
  1058 + &priv->waitdelay);
  1059 +
890 1060 return 0;
891 1061 }
892 1062  
893 1063 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
894 1064 static int omap_i2c_ofdata_to_platdata(struct udevice *bus)
895 1065 {
896   - struct omap_i2c *priv = dev_get_priv(bus);
  1066 + struct omap_i2c_platdata *plat = dev_get_platdata(bus);
897 1067  
898   - priv->regs = map_physmem(devfdt_get_addr(bus), sizeof(void *),
899   - MAP_NOCACHE);
900   - priv->speed = CONFIG_SYS_OMAP24_I2C_SPEED;
  1068 + plat->base = devfdt_get_addr(bus);
  1069 + plat->speed = dev_read_u32_default(bus, "clock-frequency", 100000);
  1070 + plat->ip_rev = dev_get_driver_data(bus);
901 1071  
902 1072 return 0;
903 1073 }
904 1074  
905 1075 static const struct udevice_id omap_i2c_ids[] = {
906   - { .compatible = "ti,omap3-i2c" },
907   - { .compatible = "ti,omap4-i2c" },
  1076 + { .compatible = "ti,omap3-i2c", .data = OMAP_I2C_REV_V1 },
  1077 + { .compatible = "ti,omap4-i2c", .data = OMAP_I2C_REV_V2 },
908 1078 { }
909 1079 };
910 1080 #endif
... ... @@ -921,6 +1091,7 @@
921 1091 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
922 1092 .of_match = omap_i2c_ids,
923 1093 .ofdata_to_platdata = omap_i2c_ofdata_to_platdata,
  1094 + .platdata_auto_alloc_size = sizeof(struct omap_i2c_platdata),
924 1095 #endif
925 1096 .probe = omap_i2c_probe,
926 1097 .priv_auto_alloc_size = sizeof(struct omap_i2c),
drivers/power/palmas.c
... ... @@ -175,4 +175,43 @@
175 175 val, err);
176 176 return err;
177 177 }
  178 +
  179 +#ifdef CONFIG_DM_I2C
  180 +int palmas_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
  181 +{
  182 + struct udevice *dev;
  183 + int ret;
  184 +
  185 + ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
  186 + if (ret) {
  187 + pr_err("unable to get I2C bus. ret %d\n", ret);
  188 + return ret;
  189 + }
  190 + ret = dm_i2c_reg_write(dev, reg, val);
  191 + if (ret) {
  192 + pr_err("writing to palmas failed. ret %d\n", ret);
  193 + return ret;
  194 + }
  195 + return 0;
  196 +}
  197 +
  198 +int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
  199 +{
  200 + struct udevice *dev;
  201 + int ret;
  202 +
  203 + ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
  204 + if (ret) {
  205 + pr_err("unable to get I2C bus. ret %d\n", ret);
  206 + return ret;
  207 + }
  208 + ret = dm_i2c_reg_read(dev, reg);
  209 + if (ret < 0) {
  210 + pr_err("reading from palmas failed. ret %d\n", ret);
  211 + return ret;
  212 + }
  213 + *valp = (u8)ret;
  214 + return 0;
  215 +}
  216 +#endif
drivers/power/pmic/pmic_tps62362.c
... ... @@ -10,6 +10,10 @@
10 10 #include <power/pmic.h>
11 11 #include <power/tps62362.h>
12 12  
  13 +#ifdef CONFIG_DM_I2C
  14 +struct udevice *tps62362_dev __attribute__((section(".data"))) = NULL;
  15 +#endif
  16 +
13 17 /**
14 18 * tps62362_voltage_update() - Function to change a voltage level, as this
15 19 * is a multi-step process.
16 20  
17 21  
... ... @@ -22,9 +26,16 @@
22 26 if (reg > TPS62362_NUM_REGS)
23 27 return 1;
24 28  
  29 +#ifndef CONFIG_DM_I2C
25 30 return i2c_write(TPS62362_I2C_ADDR, reg, 1, &volt_sel, 1);
  31 +#else
  32 + if (!tps62362_dev)
  33 + return -ENODEV;
  34 + return dm_i2c_reg_write(tps62362_dev, reg, volt_sel);
  35 +#endif
26 36 }
27 37  
  38 +#ifndef CONFIG_DM_I2C
28 39 int power_tps62362_init(unsigned char bus)
29 40 {
30 41 static const char name[] = "TPS62362";
... ... @@ -44,4 +55,17 @@
44 55  
45 56 return 0;
46 57 }
  58 +#else
  59 +int power_tps62362_init(unsigned char bus)
  60 +{
  61 + struct udevice *dev = NULL;
  62 + int rc;
  63 +
  64 + rc = i2c_get_chip_for_busnum(bus, TPS62362_I2C_ADDR, 1, &dev);
  65 + if (rc)
  66 + return rc;
  67 + tps62362_dev = dev;
  68 + return 0;
  69 +}
  70 +#endif
drivers/power/pmic/pmic_tps65217.c
... ... @@ -8,6 +8,8 @@
8 8 #include <i2c.h>
9 9 #include <power/tps65217.h>
10 10  
  11 +struct udevice *tps65217_dev __attribute__((section(".data"))) = NULL;
  12 +
11 13 /**
12 14 * tps65217_reg_read() - Generic function that can read a TPS65217 register
13 15 * @src_reg: Source register address
14 16  
... ... @@ -16,7 +18,11 @@
16 18 */
17 19 int tps65217_reg_read(uchar src_reg, uchar *src_val)
18 20 {
  21 +#ifndef CONFIG_DM_I2C
19 22 return i2c_read(TPS65217_CHIP_PM, src_reg, 1, src_val, 1);
  23 +#else
  24 + return dm_i2c_read(tps65217_dev, src_reg, src_val, 1);
  25 +#endif
20 26 }
21 27  
22 28 /**
23 29  
24 30  
... ... @@ -46,9 +52,14 @@
46 52 * mask
47 53 */
48 54 if (mask != TPS65217_MASK_ALL_BITS) {
  55 +#ifndef CONFIG_DM_I2C
49 56 ret = i2c_read(TPS65217_CHIP_PM, dest_reg, 1, &read_val, 1);
  57 +#else
  58 + ret = dm_i2c_read(tps65217_dev, dest_reg, &read_val, 1);
  59 +#endif
50 60 if (ret)
51 61 return ret;
  62 +
52 63 read_val &= (~mask);
53 64 read_val |= (dest_val & mask);
54 65 dest_val = read_val;
55 66  
56 67  
57 68  
58 69  
59 70  
60 71  
61 72  
... ... @@ -56,23 +67,40 @@
56 67  
57 68 if (prot_level > 0) {
58 69 xor_reg = dest_reg ^ TPS65217_PASSWORD_UNLOCK;
  70 +#ifndef CONFIG_DM_I2C
59 71 ret = i2c_write(TPS65217_CHIP_PM, TPS65217_PASSWORD, 1,
60 72 &xor_reg, 1);
  73 +#else
  74 + ret = dm_i2c_write(tps65217_dev, TPS65217_PASSWORD,
  75 + &xor_reg, 1);
  76 +#endif
61 77 if (ret)
62 78 return ret;
63 79 }
64   -
  80 +#ifndef CONFIG_DM_I2C
65 81 ret = i2c_write(TPS65217_CHIP_PM, dest_reg, 1, &dest_val, 1);
  82 +#else
  83 + ret = dm_i2c_write(tps65217_dev, dest_reg, &dest_val, 1);
  84 +#endif
66 85 if (ret)
67 86 return ret;
68 87  
69 88 if (prot_level == TPS65217_PROT_LEVEL_2) {
  89 +#ifndef CONFIG_DM_I2C
70 90 ret = i2c_write(TPS65217_CHIP_PM, TPS65217_PASSWORD, 1,
71 91 &xor_reg, 1);
  92 +#else
  93 + ret = dm_i2c_write(tps65217_dev, TPS65217_PASSWORD,
  94 + &xor_reg, 1);
  95 +#endif
72 96 if (ret)
73 97 return ret;
74 98  
  99 +#ifndef CONFIG_DM_I2C
75 100 ret = i2c_write(TPS65217_CHIP_PM, dest_reg, 1, &dest_val, 1);
  101 +#else
  102 + ret = dm_i2c_write(tps65217_dev, dest_reg, &dest_val, 1);
  103 +#endif
76 104 if (ret)
77 105 return ret;
78 106 }
... ... @@ -104,6 +132,20 @@
104 132 TPS65217_DCDC_GO, TPS65217_DCDC_GO))
105 133 return 1;
106 134  
  135 + return 0;
  136 +}
  137 +
  138 +int power_tps65217_init(unsigned char bus)
  139 +{
  140 +#ifdef CONFIG_DM_I2C
  141 + struct udevice *dev = NULL;
  142 + int rc;
  143 +
  144 + rc = i2c_get_chip_for_busnum(bus, TPS65217_CHIP_PM, 1, &dev);
  145 + if (rc)
  146 + return rc;
  147 + tps65217_dev = dev;
  148 +#endif
107 149 return 0;
108 150 }
drivers/power/pmic/pmic_tps65218.c
... ... @@ -10,6 +10,7 @@
10 10 #include <power/pmic.h>
11 11 #include <power/tps65218.h>
12 12  
  13 +#ifndef CONFIG_DM_I2C
13 14 int tps65218_reg_read(uchar dest_reg, uchar *dest_val)
14 15 {
15 16 uchar read_val;
16 17  
... ... @@ -84,7 +85,77 @@
84 85  
85 86 return 0;
86 87 }
  88 +#else
  89 +struct udevice *tps65218_dev __attribute__((section(".data"))) = NULL;
87 90  
  91 +int tps65218_reg_read(uchar dest_reg, uchar *dest_val)
  92 +{
  93 + uchar read_val;
  94 + int ret;
  95 +
  96 + if (!tps65218_dev)
  97 + return -ENODEV;
  98 +
  99 + ret = dm_i2c_read(tps65218_dev, dest_reg, &read_val, 1);
  100 + if (ret)
  101 + return ret;
  102 +
  103 + *dest_val = read_val;
  104 +
  105 + return 0;
  106 +}
  107 +
  108 +int tps65218_reg_write(uchar prot_level, uchar dest_reg, uchar dest_val,
  109 + uchar mask)
  110 +{
  111 + uchar read_val;
  112 + uchar xor_reg;
  113 + int ret;
  114 +
  115 + if (!tps65218_dev)
  116 + return -ENODEV;
  117 +
  118 + /*
  119 + * If we are affecting only a bit field, read dest_reg and apply the
  120 + * mask
  121 + */
  122 + if (mask != TPS65218_MASK_ALL_BITS) {
  123 + ret = dm_i2c_read(tps65218_dev, dest_reg, &read_val, 1);
  124 + if (ret)
  125 + return ret;
  126 +
  127 + read_val &= (~mask);
  128 + read_val |= (dest_val & mask);
  129 + dest_val = read_val;
  130 + }
  131 +
  132 + if (prot_level > 0) {
  133 + xor_reg = dest_reg ^ TPS65218_PASSWORD_UNLOCK;
  134 + ret = dm_i2c_write(tps65218_dev, TPS65218_PASSWORD, &xor_reg,
  135 + 1);
  136 + if (ret)
  137 + return ret;
  138 + }
  139 +
  140 + ret = dm_i2c_write(tps65218_dev, dest_reg, &dest_val, 1);
  141 + if (ret)
  142 + return ret;
  143 +
  144 + if (prot_level == TPS65218_PROT_LEVEL_2) {
  145 + ret = dm_i2c_write(tps65218_dev, TPS65218_PASSWORD, &xor_reg,
  146 + 1);
  147 + if (ret)
  148 + return ret;
  149 +
  150 + ret = dm_i2c_write(tps65218_dev, dest_reg, &dest_val, 1);
  151 + if (ret)
  152 + return ret;
  153 + }
  154 +
  155 + return 0;
  156 +}
  157 +#endif
  158 +
88 159 /**
89 160 * tps65218_voltage_update() - Function to change a voltage level, as this
90 161 * is a multi-step process.
... ... @@ -154,6 +225,7 @@
154 225 return 0;
155 226 }
156 227  
  228 +#ifndef CONFIG_DM_I2C
157 229 int power_tps65218_init(unsigned char bus)
158 230 {
159 231 static const char name[] = "TPS65218_PMIC";
... ... @@ -173,4 +245,17 @@
173 245  
174 246 return 0;
175 247 }
  248 +#else
  249 +int power_tps65218_init(unsigned char bus)
  250 +{
  251 + struct udevice *dev = NULL;
  252 + int rc;
  253 +
  254 + rc = i2c_get_chip_for_busnum(bus, TPS65218_CHIP_PM, 1, &dev);
  255 + if (rc)
  256 + return rc;
  257 + tps65218_dev = dev;
  258 + return 0;
  259 +}
  260 +#endif
drivers/power/pmic/pmic_tps65910.c
... ... @@ -8,6 +8,47 @@
8 8 #include <i2c.h>
9 9 #include <power/tps65910.h>
10 10  
  11 +struct udevice *tps65910_dev __attribute__((section(".data"))) = NULL;
  12 +
  13 +static inline int tps65910_read_reg(int addr, uchar *buf)
  14 +{
  15 +#ifndef CONFIG_DM_I2C
  16 + return i2c_read(TPS65910_CTRL_I2C_ADDR, addr, 1, buf, 1);
  17 +#else
  18 + int rc;
  19 +
  20 + rc = dm_i2c_reg_read(tps65910_dev, addr);
  21 + if (rc < 0)
  22 + return rc;
  23 + *buf = (uchar)rc;
  24 + return 0;
  25 +#endif
  26 +}
  27 +
  28 +static inline int tps65910_write_reg(int addr, uchar *buf)
  29 +{
  30 +#ifndef CONFIG_DM_I2C
  31 + return i2c_write(TPS65910_CTRL_I2C_ADDR, addr, 1, buf, 1);
  32 +#else
  33 + return dm_i2c_reg_write(tps65910_dev, addr, *buf);
  34 +#endif
  35 +}
  36 +
  37 +int power_tps65910_init(unsigned char bus)
  38 +{
  39 +#ifdef CONFIG_DM_I2C
  40 + struct udevice *dev = NULL;
  41 + int rc;
  42 +
  43 + rc = i2c_get_chip_for_busnum(bus, TPS65910_CTRL_I2C_ADDR, 1, &dev);
  44 +
  45 + if (rc)
  46 + return rc;
  47 + tps65910_dev = dev;
  48 +#endif
  49 + return 0;
  50 +}
  51 +
11 52 /*
12 53 * tps65910_set_i2c_control() - Set the TPS65910 to be controlled via the I2C
13 54 * interface.
14 55  
... ... @@ -19,16 +60,14 @@
19 60 uchar buf;
20 61  
21 62 /* VDD1/2 voltage selection register access by control i/f */
22   - ret = i2c_read(TPS65910_CTRL_I2C_ADDR, TPS65910_DEVCTRL_REG, 1,
23   - &buf, 1);
  63 + ret = tps65910_read_reg(TPS65910_DEVCTRL_REG, &buf);
24 64  
25 65 if (ret)
26 66 return ret;
27 67  
28 68 buf |= TPS65910_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C;
29 69  
30   - return i2c_write(TPS65910_CTRL_I2C_ADDR, TPS65910_DEVCTRL_REG, 1,
31   - &buf, 1);
  70 + return tps65910_write_reg(TPS65910_DEVCTRL_REG, &buf);
32 71 }
33 72  
34 73 /*
35 74  
36 75  
37 76  
38 77  
... ... @@ -49,29 +88,29 @@
49 88 reg_offset = TPS65910_VDD2_OP_REG;
50 89  
51 90 /* Select VDDx OP */
52   - ret = i2c_read(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
  91 + ret = tps65910_read_reg(reg_offset, &buf);
53 92 if (ret)
54 93 return ret;
55 94  
56 95 buf &= ~TPS65910_OP_REG_CMD_MASK;
57 96  
58   - ret = i2c_write(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
  97 + ret = tps65910_write_reg(reg_offset, &buf);
59 98 if (ret)
60 99 return ret;
61 100  
62 101 /* Configure VDDx OP Voltage */
63   - ret = i2c_read(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
  102 + ret = tps65910_read_reg(reg_offset, &buf);
64 103 if (ret)
65 104 return ret;
66 105  
67 106 buf &= ~TPS65910_OP_REG_SEL_MASK;
68 107 buf |= vddx_op_vol_sel;
69 108  
70   - ret = i2c_write(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
  109 + ret = tps65910_write_reg(reg_offset, &buf);
71 110 if (ret)
72 111 return ret;
73 112  
74   - ret = i2c_read(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
  113 + ret = tps65910_read_reg(reg_offset, &buf);
75 114 if (ret)
76 115 return ret;
77 116  
drivers/power/twl4030.c
... ... @@ -179,4 +179,43 @@
179 179 return 0;
180 180 }
181 181 #endif
  182 +
  183 +#ifdef CONFIG_DM_I2C
  184 +int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
  185 +{
  186 + struct udevice *dev;
  187 + int ret;
  188 +
  189 + ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
  190 + if (ret) {
  191 + pr_err("unable to get I2C bus. ret %d\n", ret);
  192 + return ret;
  193 + }
  194 + ret = dm_i2c_reg_write(dev, reg, val);
  195 + if (ret) {
  196 + pr_err("writing to twl4030 failed. ret %d\n", ret);
  197 + return ret;
  198 + }
  199 + return 0;
  200 +}
  201 +
  202 +int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
  203 +{
  204 + struct udevice *dev;
  205 + int ret;
  206 +
  207 + ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
  208 + if (ret) {
  209 + pr_err("unable to get I2C bus. ret %d\n", ret);
  210 + return ret;
  211 + }
  212 + ret = dm_i2c_reg_read(dev, reg);
  213 + if (ret < 0) {
  214 + pr_err("reading from twl4030 failed. ret %d\n", ret);
  215 + return ret;
  216 + }
  217 + *valp = (u8)ret;
  218 + return 0;
  219 +}
  220 +#endif
drivers/power/twl6030.c
... ... @@ -268,4 +268,43 @@
268 268 value &= ~TWL6030_MISC2_VUSB_IN_PMID;
269 269 twl6030_i2c_write_u8(TWL6030_CHIP_PM, TWL6030_MISC2, value);
270 270 }
  271 +
  272 +#ifdef CONFIG_DM_I2C
  273 +int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
  274 +{
  275 + struct udevice *dev;
  276 + int ret;
  277 +
  278 + ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
  279 + if (ret) {
  280 + pr_err("unable to get I2C bus. ret %d\n", ret);
  281 + return ret;
  282 + }
  283 + ret = dm_i2c_reg_write(dev, reg, val);
  284 + if (ret) {
  285 + pr_err("writing to twl6030 failed. ret %d\n", ret);
  286 + return ret;
  287 + }
  288 + return 0;
  289 +}
  290 +
  291 +int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
  292 +{
  293 + struct udevice *dev;
  294 + int ret;
  295 +
  296 + ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
  297 + if (ret) {
  298 + pr_err("unable to get I2C bus. ret %d\n", ret);
  299 + return ret;
  300 + }
  301 + ret = dm_i2c_reg_read(dev, reg);
  302 + if (ret < 0) {
  303 + pr_err("reading from twl6030 failed. ret %d\n", ret);
  304 + return ret;
  305 + }
  306 + *valp = (u8)ret;
  307 + return 0;
  308 +}
  309 +#endif
include/asm-generic/global_data.h
... ... @@ -77,6 +77,10 @@
77 77 #ifdef CONFIG_OF_LIVE
78 78 struct device_node *of_root;
79 79 #endif
  80 +
  81 +#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  82 + const void *multi_dtb_fit; /* uncompressed multi-dtb FIT image */
  83 +#endif
80 84 struct jt_funcs *jt; /* jump table */
81 85 char env_buf[32]; /* buffer for env_get() before reloc. */
82 86 #ifdef CONFIG_TRACE
include/configs/am43xx_evm.h
... ... @@ -27,8 +27,10 @@
27 27 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2
28 28  
29 29 /* Power */
  30 +#ifndef CONFIG_DM_I2C
30 31 #define CONFIG_POWER
31 32 #define CONFIG_POWER_I2C
  33 +#endif
32 34 #define CONFIG_POWER_TPS65218
33 35 #define CONFIG_POWER_TPS62362
34 36  
include/configs/pdu001.h
... ... @@ -12,12 +12,6 @@
12 12  
13 13 #include <configs/ti_am335x_common.h>
14 14  
15   -/* No more need for I2C legacy compatibility for this board.
16   - * CONFIG_DM_I2C_COMPAT is defined in ti_armv7_common.h. See the comment there
17   - * for the right moment to delete the following line.
18   - */
19   -#undef CONFIG_DM_I2C_COMPAT
20   -
21 15 /* Using 32K of volatile storage for environment */
22 16 #define CONFIG_ENV_SIZE 0x4000
23 17  
include/configs/ti_armv7_common.h
... ... @@ -74,24 +74,10 @@
74 74 /* Timer information. */
75 75 #define CONFIG_SYS_PTV 2 /* Divisor: 2^(PTV+1) => 8 */
76 76  
77   -/*
78   - * Disable DM_* for SPL build and can be re-enabled after adding
79   - * DM support in SPL
80   - */
81   -#ifdef CONFIG_SPL_BUILD
82   -#undef CONFIG_DM_I2C
83   -#endif
84   -
85   -/* I2C IP block */
  77 +/* If DM_I2C, enable non-DM I2C support */
  78 +#if !defined(CONFIG_DM_I2C)
86 79 #define CONFIG_I2C
87   -#ifndef CONFIG_DM_I2C
88 80 #define CONFIG_SYS_I2C
89   -#else
90   -/*
91   - * Enable CONFIG_DM_I2C_COMPAT temporarily until all the i2c client
92   - * devices are adopted to DM
93   - */
94   -#define CONFIG_DM_I2C_COMPAT
95 81 #endif
96 82  
97 83 /*
include/dm/uclass-internal.h
... ... @@ -12,6 +12,19 @@
12 12 #include <dm/ofnode.h>
13 13  
14 14 /**
  15 + * uclass_find_next_free_req_seq() - Get the next free req_seq number
  16 + *
  17 + * This returns the next free req_seq number. This is useful only if
  18 + * OF_CONTROL is not used. The next free req_seq number is simply the
  19 + * maximum req_seq of the uclass + 1.
  20 + * This allows assiging req_seq number in the binding order.
  21 + *
  22 + * @id: Id number of the uclass
  23 + * @return The next free req_seq number
  24 + */
  25 +int uclass_find_next_free_req_seq(enum uclass_id id);
  26 +
  27 +/**
15 28 * uclass_get_device_tail() - handle the end of a get_device call
16 29 *
17 30 * This handles returning an error or probing a device as needed.
... ... @@ -951,6 +951,27 @@
951 951 */
952 952 int fdtdec_setup(void);
953 953  
  954 +#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  955 +/**
  956 + * fdtdec_resetup() - Set up the device tree again
  957 + *
  958 + * The main difference with fdtdec_setup() is that it returns if the fdt has
  959 + * changed because a better match has been found.
  960 + * This is typically used for boards that rely on a DM driver to detect the
  961 + * board type. This function sould be called by the board code after the stuff
  962 + * needed by board_fit_config_name_match() to operate porperly is available.
  963 + * If this functions signals that a rescan is necessary, the board code must
  964 + * unbind all the drivers using dm_uninit() and then rescan the DT with
  965 + * dm_init_and_scan().
  966 + *
  967 + * @param rescan Returns a flag indicating that fdt has changed and rescanning
  968 + * the fdt is required
  969 + *
  970 + * @return 0 if OK, -ve on error
  971 + */
  972 +int fdtdec_resetup(int *rescan);
  973 +#endif
  974 +
954 975 /**
955 976 * Board-specific FDT initialization. Returns the address to a device tree blob.
956 977 * Called when CONFIG_OF_BOARD is defined, or if CONFIG_OF_SEPARATE is defined
... ... @@ -117,6 +117,7 @@
117 117 #define BB_VSEL_VBAT (3 << 1)
118 118 #define BB_CHRG_EN (1 << 0)
119 119  
  120 +#ifndef CONFIG_DM_I2C
120 121 /*
121 122 * Functions to read and write from TPS659038/TWL6035/TWL6037
122 123 * or other Palmas family of TI PMICs
... ... @@ -130,6 +131,10 @@
130 131 {
131 132 return i2c_read(chip_no, reg, 1, val, 1);
132 133 }
  134 +#else
  135 +int palmas_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
  136 +int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
  137 +#endif
133 138  
134 139 void palmas_init_settings(void);
135 140 int palmas_mmc1_poweron_ldo(uint ldo_volt, uint ldo_ctrl, uint voltage);
include/power/tps65217.h
... ... @@ -80,6 +80,8 @@
80 80 #define TPS65217_PWR_SRC_USB_BITMASK 0x4
81 81 #define TPS65217_PWR_SRC_AC_BITMASK 0x8
82 82  
  83 +int power_tps65217_init(unsigned char bus);
  84 +
83 85 int tps65217_reg_read(uchar src_reg, uchar *src_val);
84 86 int tps65217_reg_write(uchar prot_level, uchar dest_reg, uchar dest_val,
85 87 uchar mask);
include/power/tps65910.h
... ... @@ -72,6 +72,7 @@
72 72 #define TPS65910_DEVCTRL_REG_SR_CTL_I2C_SEL_SR_I2C (0x0 << 4)
73 73 #define TPS65910_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C (0x1 << 4)
74 74  
  75 +int power_tps65910_init(unsigned char bus);
75 76 int tps65910_set_i2c_control(void);
76 77 int tps65910_voltage_update(unsigned int module, unsigned char vddx_op_vol_sel);
77 78 #endif /* __POWER_TPS65910_H__ */
... ... @@ -648,6 +648,7 @@
648 648 * examples are TWL4030_PM_RECEIVER_VMMC1_DEV_GRP and
649 649 * TWL4030_LED_LEDEN.
650 650 */
  651 +#ifndef CONFIG_DM_I2C
651 652 static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
652 653 {
653 654 return i2c_write(chip_no, reg, 1, &val, 1);
... ... @@ -657,7 +658,10 @@
657 658 {
658 659 return i2c_read(chip_no, reg, 1, val, 1);
659 660 }
660   -
  661 +#else
  662 +int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
  663 +int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
  664 +#endif
661 665 /*
662 666 * Power
663 667 */
... ... @@ -186,6 +186,7 @@
186 186 };
187 187  
188 188 /* Functions to read and write from TWL6030 */
  189 +#ifndef CONFIG_DM_I2C
189 190 static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
190 191 {
191 192 return i2c_write(chip_no, reg, 1, &val, 1);
... ... @@ -195,6 +196,10 @@
195 196 {
196 197 return i2c_read(chip_no, reg, 1, val, 1);
197 198 }
  199 +#else
  200 +int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
  201 +int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
  202 +#endif
198 203  
199 204 /*
200 205 * Power
... ... @@ -1275,13 +1275,54 @@
1275 1275 * If so, pick the most relevant
1276 1276 */
1277 1277 fdt_blob = locate_dtb_in_fit(gd->fdt_blob);
1278   - if (fdt_blob)
  1278 + if (fdt_blob) {
  1279 + gd->multi_dtb_fit = gd->fdt_blob;
1279 1280 gd->fdt_blob = fdt_blob;
  1281 + }
  1282 +
1280 1283 # endif
1281 1284 #endif
1282 1285  
1283 1286 return fdtdec_prepare_fdt();
1284 1287 }
  1288 +
  1289 +#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  1290 +int fdtdec_resetup(int *rescan)
  1291 +{
  1292 + void *fdt_blob;
  1293 +
  1294 + /*
  1295 + * If the current DTB is part of a compressed FIT image,
  1296 + * try to locate the best match from the uncompressed
  1297 + * FIT image stillpresent there. Save the time and space
  1298 + * required to uncompress it again.
  1299 + */
  1300 + if (gd->multi_dtb_fit) {
  1301 + fdt_blob = locate_dtb_in_fit(gd->multi_dtb_fit);
  1302 +
  1303 + if (fdt_blob == gd->fdt_blob) {
  1304 + /*
  1305 + * The best match did not change. no need to tear down
  1306 + * the DM and rescan the fdt.
  1307 + */
  1308 + *rescan = 0;
  1309 + return 0;
  1310 + }
  1311 +
  1312 + *rescan = 1;
  1313 + gd->fdt_blob = fdt_blob;
  1314 + return fdtdec_prepare_fdt();
  1315 + }
  1316 +
  1317 + /*
  1318 + * If multi_dtb_fit is NULL, it means that blob appended to u-boot is
  1319 + * not a FIT image containings DTB, but a single DTB. There is no need
  1320 + * to teard down DM and rescan the DT in this case.
  1321 + */
  1322 + *rescan = 0;
  1323 + return 0;
  1324 +}
  1325 +#endif
1285 1326  
1286 1327 #ifdef CONFIG_NR_DRAM_BANKS
1287 1328 int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,