MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rk_i2c_attach

Function rk_i2c_attach

freebsd/arm64/rockchip/rk_i2c.c:566–633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

564}
565
566static int
567rk_i2c_attach(device_t dev)
568{
569 struct rk_i2c_softc *sc;
570 int error;
571
572 sc = device_get_softc(dev);
573 sc->dev = dev;
574
575 mtx_init(&sc->mtx, device_get_nameunit(dev), "rk_i2c", MTX_DEF);
576
577 if (bus_alloc_resources(dev, rk_i2c_spec, sc->res) != 0) {
578 device_printf(dev, "cannot allocate resources for device\n");
579 error = ENXIO;
580 goto fail;
581 }
582
583 if (bus_setup_intr(dev, sc->res[1],
584 INTR_TYPE_MISC | INTR_MPSAFE, NULL, rk_i2c_intr, sc,
585 &sc->intrhand)) {
586 bus_release_resources(dev, rk_i2c_spec, sc->res);
587 device_printf(dev, "cannot setup interrupt handler\n");
588 return (ENXIO);
589 }
590
591 clk_set_assigned(dev, ofw_bus_get_node(dev));
592
593 /* Activate the module clocks. */
594 error = clk_get_by_ofw_name(dev, 0, "i2c", &sc->sclk);
595 if (error != 0) {
596 device_printf(dev, "cannot get i2c clock\n");
597 goto fail;
598 }
599 error = clk_enable(sc->sclk);
600 if (error != 0) {
601 device_printf(dev, "cannot enable i2c clock\n");
602 goto fail;
603 }
604 /* pclk clock is optional. */
605 error = clk_get_by_ofw_name(dev, 0, "pclk", &sc->pclk);
606 if (error != 0 && error != ENOENT) {
607 device_printf(dev, "cannot get pclk clock\n");
608 goto fail;
609 }
610 if (sc->pclk != NULL) {
611 error = clk_enable(sc->pclk);
612 if (error != 0) {
613 device_printf(dev, "cannot enable pclk clock\n");
614 goto fail;
615 }
616 }
617
618 sc->iicbus = device_add_child(dev, "iicbus", -1);
619 if (sc->iicbus == NULL) {
620 device_printf(dev, "cannot add iicbus child device\n");
621 error = ENXIO;
622 goto fail;
623 }

Callers

nothing calls this directly

Calls 10

device_get_softcFunction · 0.85
mtx_initFunction · 0.85
device_get_nameunitFunction · 0.85
bus_alloc_resourcesFunction · 0.85
device_printfFunction · 0.85
bus_setup_intrFunction · 0.85
bus_release_resourcesFunction · 0.85
device_add_childFunction · 0.85
bus_generic_attachFunction · 0.85
rk_i2c_detachFunction · 0.85

Tested by

no test coverage detected