dm: sandbox: i2c: Use new emulator parent uclass
Update the device tree, sandbox i2c driver and tests to use the new emulation parent to hold emulators. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
b7c25b11b6
commit
031a650e13
@ -95,19 +95,11 @@
|
||||
eeprom@2c {
|
||||
reg = <0x2c>;
|
||||
compatible = "i2c-eeprom";
|
||||
emul {
|
||||
compatible = "sandbox,i2c-eeprom";
|
||||
sandbox,filename = "i2c.bin";
|
||||
sandbox,size = <128>;
|
||||
};
|
||||
};
|
||||
|
||||
rtc_0: rtc@43 {
|
||||
reg = <0x43>;
|
||||
compatible = "sandbox-rtc";
|
||||
emul {
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
};
|
||||
sandbox_pmic: sandbox_pmic {
|
||||
reg = <0x40>;
|
||||
@ -116,6 +108,23 @@
|
||||
mc34708: pmic@41 {
|
||||
reg = <0x41>;
|
||||
};
|
||||
|
||||
i2c_emul: emul {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
reg = <0xff>;
|
||||
compatible = "sandbox,i2c-emul-parent";
|
||||
emul-eeprom {
|
||||
reg = <0x2c>;
|
||||
compatible = "sandbox,i2c-eeprom";
|
||||
sandbox,filename = "i2c.bin";
|
||||
sandbox,size = <256>;
|
||||
};
|
||||
emul0 {
|
||||
reg = <0x43>;
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
lcd {
|
||||
|
@ -90,19 +90,11 @@
|
||||
eeprom@2c {
|
||||
reg = <0x2c>;
|
||||
compatible = "i2c-eeprom";
|
||||
emul {
|
||||
compatible = "sandbox,i2c-eeprom";
|
||||
sandbox,filename = "i2c.bin";
|
||||
sandbox,size = <128>;
|
||||
};
|
||||
};
|
||||
|
||||
rtc_0: rtc@43 {
|
||||
reg = <0x43>;
|
||||
compatible = "sandbox-rtc";
|
||||
emul {
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
};
|
||||
sandbox_pmic: sandbox_pmic {
|
||||
reg = <0x40>;
|
||||
@ -111,6 +103,19 @@
|
||||
mc34708: pmic@41 {
|
||||
reg = <0x41>;
|
||||
};
|
||||
|
||||
i2c_emul: emul {
|
||||
reg = <0xff>;
|
||||
compatible = "sandbox,i2c-emul-parent";
|
||||
emul-eeprom {
|
||||
compatible = "sandbox,i2c-eeprom";
|
||||
sandbox,filename = "i2c.bin";
|
||||
sandbox,size = <256>;
|
||||
};
|
||||
emul0 {
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
lcd {
|
||||
|
@ -11,40 +11,6 @@
|
||||
&sandbox_pmic {
|
||||
compatible = "sandbox,pmic";
|
||||
|
||||
pmic_emul {
|
||||
compatible = "sandbox,i2c-pmic";
|
||||
|
||||
/*
|
||||
* Default PMICs register values are set by macro
|
||||
* VAL2REG(min, step, value) [uV/uA]
|
||||
* VAL2OMREG(mode id)
|
||||
* reg-defaults - byte array
|
||||
*/
|
||||
reg-defaults = /bits/ 8 <
|
||||
/* BUCK1 */
|
||||
VAL2REG(800000, 25000, 1000000)
|
||||
VAL2REG(150000, 25000, 150000)
|
||||
VAL2OMREG(BUCK_OM_OFF)
|
||||
/* BUCK2 */
|
||||
VAL2REG(750000, 50000, 3000000)
|
||||
VAL2REG(150000, 25000, 150000)
|
||||
VAL2OMREG(0)
|
||||
/* LDO1 */
|
||||
VAL2REG(800000, 25000, 1600000)
|
||||
VAL2REG(100000, 50000, 150000)
|
||||
VAL2OMREG(LDO_OM_OFF)
|
||||
/* LDO2 */
|
||||
VAL2REG(750000, 50000, 3000000)
|
||||
VAL2REG(150000, 25000, 150000)
|
||||
VAL2OMREG(0)
|
||||
/* reg[12:15] - not used */
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
>;
|
||||
};
|
||||
|
||||
buck1 {
|
||||
regulator-name = "SUPPLY_1.2V";
|
||||
regulator-min-microvolt = <1200000>;
|
||||
@ -84,10 +50,45 @@
|
||||
|
||||
&mc34708 {
|
||||
compatible = "fsl,mc34708";
|
||||
};
|
||||
|
||||
pmic_emul {
|
||||
&i2c_emul {
|
||||
emul_pmic0: pmic-emul0 {
|
||||
compatible = "sandbox,i2c-pmic";
|
||||
|
||||
/*
|
||||
* Default PMICs register values are set by macro
|
||||
* VAL2REG(min, step, value) [uV/uA]
|
||||
* VAL2OMREG(mode id)
|
||||
* reg-defaults - byte array
|
||||
*/
|
||||
reg-defaults = /bits/ 8 <
|
||||
/* BUCK1 */
|
||||
VAL2REG(800000, 25000, 1000000)
|
||||
VAL2REG(150000, 25000, 150000)
|
||||
VAL2OMREG(BUCK_OM_OFF)
|
||||
/* BUCK2 */
|
||||
VAL2REG(750000, 50000, 3000000)
|
||||
VAL2REG(150000, 25000, 150000)
|
||||
VAL2OMREG(0)
|
||||
/* LDO1 */
|
||||
VAL2REG(800000, 25000, 1600000)
|
||||
VAL2REG(100000, 50000, 150000)
|
||||
VAL2OMREG(LDO_OM_OFF)
|
||||
/* LDO2 */
|
||||
VAL2REG(750000, 50000, 3000000)
|
||||
VAL2REG(150000, 25000, 150000)
|
||||
VAL2OMREG(0)
|
||||
/* reg[12:15] - not used */
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
>;
|
||||
};
|
||||
|
||||
emul_pmic1: pmic-emul1 {
|
||||
compatible = "sandbox,i2c-pmic";
|
||||
reg-defaults = /bits/ 8 <
|
||||
0x00 0x80 0x08 0xff 0xff 0xff 0x2e 0x01 0x08
|
||||
0x40 0x80 0x81 0x5f 0xff 0xfb 0x1e 0x80 0x18
|
||||
|
@ -266,35 +266,45 @@
|
||||
eeprom@2c {
|
||||
reg = <0x2c>;
|
||||
compatible = "i2c-eeprom";
|
||||
emul {
|
||||
compatible = "sandbox,i2c-eeprom";
|
||||
sandbox,filename = "i2c.bin";
|
||||
sandbox,size = <256>;
|
||||
};
|
||||
sandbox,emul = <&emul_eeprom>;
|
||||
};
|
||||
|
||||
rtc_0: rtc@43 {
|
||||
reg = <0x43>;
|
||||
compatible = "sandbox-rtc";
|
||||
emul {
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
sandbox,emul = <&emul0>;
|
||||
};
|
||||
|
||||
rtc_1: rtc@61 {
|
||||
reg = <0x61>;
|
||||
compatible = "sandbox-rtc";
|
||||
emul {
|
||||
sandbox,emul = <&emul1>;
|
||||
};
|
||||
|
||||
i2c_emul: emul {
|
||||
reg = <0xff>;
|
||||
compatible = "sandbox,i2c-emul-parent";
|
||||
emul_eeprom: emul-eeprom {
|
||||
compatible = "sandbox,i2c-eeprom";
|
||||
sandbox,filename = "i2c.bin";
|
||||
sandbox,size = <256>;
|
||||
};
|
||||
emul0: emul0 {
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
emul1: emull {
|
||||
compatible = "sandbox,i2c-rtc";
|
||||
};
|
||||
};
|
||||
|
||||
sandbox_pmic: sandbox_pmic {
|
||||
reg = <0x40>;
|
||||
sandbox,emul = <&emul_pmic0>;
|
||||
};
|
||||
|
||||
mc34708: pmic@41 {
|
||||
reg = <0x41>;
|
||||
sandbox,emul = <&emul_pmic1>;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -21,33 +21,15 @@ static int get_emul(struct udevice *dev, struct udevice **devp,
|
||||
struct dm_i2c_ops **opsp)
|
||||
{
|
||||
struct dm_i2c_chip *plat;
|
||||
struct udevice *child;
|
||||
int ret;
|
||||
|
||||
*devp = NULL;
|
||||
*opsp = NULL;
|
||||
plat = dev_get_parent_platdata(dev);
|
||||
if (!plat->emul) {
|
||||
ret = dm_scan_fdt_dev(dev);
|
||||
ret = i2c_emul_find(dev, &plat->emul);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
for (device_find_first_child(dev, &child); child;
|
||||
device_find_next_child(&child)) {
|
||||
if (device_get_uclass_id(child) != UCLASS_I2C_EMUL)
|
||||
continue;
|
||||
|
||||
ret = device_probe(child);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (child)
|
||||
plat->emul = child;
|
||||
else
|
||||
return -ENODEV;
|
||||
}
|
||||
*devp = plat->emul;
|
||||
*opsp = i2c_get_ops(plat->emul);
|
||||
|
@ -104,7 +104,7 @@ static int sandbox_i2c_pmic_xfer(struct udevice *emul, struct i2c_msg *msg,
|
||||
static int sandbox_i2c_pmic_ofdata_to_platdata(struct udevice *emul)
|
||||
{
|
||||
struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul);
|
||||
struct udevice *pmic_dev = dev_get_parent(emul);
|
||||
struct udevice *pmic_dev = i2c_emul_get_device(emul);
|
||||
struct uc_pmic_priv *priv = dev_get_uclass_priv(pmic_dev);
|
||||
const u8 *reg_defaults;
|
||||
|
||||
|
@ -35,7 +35,7 @@ static int dm_test_i2c_find(struct unit_test_state *uts)
|
||||
*/
|
||||
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
||||
ut_assertok(dm_i2c_probe(bus, chip, 0, &dev));
|
||||
ut_asserteq(-ENODEV, dm_i2c_probe(bus, no_chip, 0, &dev));
|
||||
ut_asserteq(-ENOENT, dm_i2c_probe(bus, no_chip, 0, &dev));
|
||||
ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_I2C, 1, &bus));
|
||||
|
||||
return 0;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
#include <i2c.h>
|
||||
#include <rtc.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/test.h>
|
||||
@ -60,7 +61,7 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts)
|
||||
ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
|
||||
ut_assertok(dm_rtc_get(dev, &now));
|
||||
|
||||
ut_assertok(device_find_first_child(dev, &emul));
|
||||
ut_assertok(i2c_emul_find(dev, &emul));
|
||||
ut_assert(emul != NULL);
|
||||
|
||||
/* Tell the RTC to go into manual mode */
|
||||
@ -125,7 +126,7 @@ static int dm_test_rtc_reset(struct unit_test_state *uts)
|
||||
ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
|
||||
ut_assertok(dm_rtc_get(dev, &now));
|
||||
|
||||
ut_assertok(device_find_first_child(dev, &emul));
|
||||
ut_assertok(i2c_emul_find(dev, &emul));
|
||||
ut_assert(emul != NULL);
|
||||
|
||||
old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, 0);
|
||||
@ -154,9 +155,9 @@ static int dm_test_rtc_dual(struct unit_test_state *uts)
|
||||
ut_assertok(uclass_get_device(UCLASS_RTC, 1, &dev2));
|
||||
ut_assertok(dm_rtc_get(dev2, &now2));
|
||||
|
||||
ut_assertok(device_find_first_child(dev1, &emul1));
|
||||
ut_assertok(i2c_emul_find(dev1, &emul1));
|
||||
ut_assert(emul1 != NULL);
|
||||
ut_assertok(device_find_first_child(dev2, &emul2));
|
||||
ut_assertok(i2c_emul_find(dev2, &emul2));
|
||||
ut_assert(emul2 != NULL);
|
||||
|
||||
offset = sandbox_i2c_rtc_set_offset(emul1, false, -1);
|
||||
|
Loading…
Reference in New Issue
Block a user