All pastes #740094 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-17 18:22 UTC
rendered paste body
static void __init fixup_device_tree_efika(void)
{
        /* Substitution table */
        #define prop_cstr(x) x, sizeof(x)
        int prop_sound_irq[3] = { 2, 2, 0 };
        int prop_mdio_irq[3] = { 3, 5, 2 };
        int prop_bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0,
                                     3,4,0, 3,5,0, 3,6,0, 3,7,0,
                                     3,8,0, 3,9,0, 3,10,0, 3,11,0,
                                     3,12,0, 3,13,0, 3,14,0, 3,15,0 };
        struct subst_entry efika_subst_table[] = {
                { "/",                  "device_type",  prop_cstr("efika") },
                { "/builtin",           "device_type",  prop_cstr("soc") },
                { "/builtin/ata",       "compatible",   prop_cstr("mpc5200b-ata\0mpc5200-ata"), },
                { "/builtin/bestcomm",  "compatible",   prop_cstr("mpc5200b-bestcomm\0mpc5200-bestcomm") },
                { "/builtin/bestcomm",  "interrupts",   prop_bcomm_irq, sizeof(prop_bcomm_irq) },
                { "/builtin/ethernet",  "compatible",   prop_cstr("mpc5200b-fec\0mpc5200-fec") },
                { "/builtin/pic",       "compatible",   prop_cstr("mpc5200b-pic\0mpc5200-pic") },
                { "/builtin/serial",    "compatible",   prop_cstr("mpc5200b-psc-uart\0mpc5200-psc-uart") },
                { "/builtin/sound",     "compatible",   prop_cstr("mpc5200b-psc-ac97\0mpc5200-psc-ac97") },
                { "/builtin/sound",     "interrupts",   prop_sound_irq, sizeof(prop_sound_irq) },
                { "/builtin/sram",      "compatible",   prop_cstr("mpc5200b-sram\0mpc5200-sram") },
                { "/builtin/sram",      "device_type",  prop_cstr("sram") },
                { "/builtin/mdio",      "device_type",  prop_cstr("mdio") },
                { "/builtin/mdio",      "compatible",   prop_cstr("pc5200b-fec-phy") },
                { "/builtin/mdio",      "interrupts",   prop_mdio_irq, sizeof(prop_mdio_irq) },
                { "/builtin/mdio/ethernet-phy", "device_type",  prop_cstr("ethernet-phy") },
                { "/builtin/mdio/ethernet-phy", "reg",  prop_int(0x10) },
                }
        };
        #undef prop_cstr
        /* Vars */
        u32 node;
        char prop[64];
        int rv, i;

        /* Check if we're really running on a EFIKA */
        node = call_prom("finddevice", 1, 1, ADDR("/"));
        if (!PHANDLE_VALID(node))
                return;

        rv = prom_getprop(node, "model", prop, sizeof(prop));
        if (rv == PROM_ERROR)
                return;
        if (strcmp(prop, "EFIKA5K2"))
                return;

        prom_printf("Applying EFIKA device tree fixups\n");

        /* Process substitution table */
        for (i=0; efika_subst_table[i].path; i++) {
                struct subst_entry *se = &efika_subst_table[i];

                node = call_prom("finddevice", 1, 1, ADDR(se->path));
                if (!PHANDLE_VALID(node)) {
                        prom_printf("fixup_device_tree_efika: ",
                                "skipped entry %x - not found\n", i);
                        continue;
                }

                rv = prom_setprop(node, se->path, se->property,
                                        se->value, se->value_len );
                if (rv == PROM_ERROR)
                        prom_printf("fixup_device_tree_efika: ",
                                "skipped entry %x - setprop error\n", i);
        }

        phy = call_prom("finddevice", 1, 1, "/builtin/mdio/ethernet-phy");
        node = call_prom("finddevice", 1, 1, "/builtin/ethernet");
        prom_setprop(node, "/builtin/ethernet", "phy-handle", phy, 4);
}