static void am335x_pmic_start(void *xdev) { struct am335x_pmic_softc *sc; device_t dev = (device_t)xdev; uint8_t reg; char name[20]; char pwr[4][11] = {"Unknown", "USB", "AC", "USB and AC"}; sc = device_get_softc(dev); am335x_pmic_read(dev, TPS65217_CHIPID_REG, ®, 1); switch (reg>>4) { case TPS65217A: sprintf(name, "TPS65217A ver 1.%u", reg & 0xF); break; case TPS65217B: sprintf(name, "TPS65217B ver 1.%u", reg & 0xF); break; default: sprintf(name, "Unknown PMIC"); } am335x_pmic_read(dev, TPS65217_STATUS_REG, ®, 1); device_printf(dev, "%s powered by %s\n", name, pwr[(reg>>2)&0x03]); config_intrhook_disestablish(&sc->enum_hook); }
static void am335x_pmic_intr(void *arg) { struct am335x_pmic_softc *sc = (struct am335x_pmic_softc *)arg; struct tps65217_status_reg status_reg; struct tps65217_int_reg int_reg; int rv; char notify_buf[16]; THREAD_SLEEPING_OK(); rv = am335x_pmic_read(sc->sc_dev, TPS65217_INT_REG, (uint8_t *)&int_reg, 1); if (rv != 0) { device_printf(sc->sc_dev, "Cannot read interrupt register\n"); THREAD_NO_SLEEPING(); return; } rv = am335x_pmic_read(sc->sc_dev, TPS65217_STATUS_REG, (uint8_t *)&status_reg, 1); if (rv != 0) { device_printf(sc->sc_dev, "Cannot read status register\n"); THREAD_NO_SLEEPING(); return; } THREAD_NO_SLEEPING(); if (int_reg.pbi && status_reg.pb) shutdown_nice(RB_POWEROFF); if (int_reg.aci) { snprintf(notify_buf, sizeof(notify_buf), "notify=0x%02x", status_reg.acpwr); devctl_notify_f("ACPI", "ACAD", "power", notify_buf, M_NOWAIT); } }
static void am335x_pmic_dump_chgconfig(device_t dev) { struct tps65217_chgconfig0_reg reg0; struct tps65217_chgconfig1_reg reg1; struct tps65217_chgconfig2_reg reg2; struct tps65217_chgconfig3_reg reg3; const char *e_d[] = {"enabled", "disabled"}; const char *d_e[] = {"disabled", "enabled"}; const char *i_a[] = {"inactive", "active"}; const char *f_t[] = {"false", "true"}; const char *timer_c[] = {"4h", "5h", "6h", "8h"}; const char *ntc_type_c[] = {"100k", "10k"}; const char *vprechg_c[] = {"2.9V", "2.5V"}; const char *trange_c[] = {"0-45 C", "0-60 C"}; const char *termif_c[] = {"2.5%", "7.5%", "15%", "18%"}; const char *pchrgt_c[] = {"30 min", "60 min"}; const char *dppmth_c[] = {"3.50V", "3.75V", "4.00V", "4.25V"}; const char *ichrg_c[] = {"300mA", "400mA", "500mA", "700mA"}; am335x_pmic_read(dev, TPS65217_CHGCONFIG0_REG, (uint8_t *)®0, 1); device_printf(dev, " BAT TEMP/NTC ERROR: %s\n", f_t[reg0.battemp]); device_printf(dev, " Pre-charge timer time-out: %s\n", f_t[reg0.pchgtout]); device_printf(dev, " Charge timer time-out: %s\n", f_t[reg0.chgtout]); device_printf(dev, " Charger active: %s\n", f_t[reg0.active]); device_printf(dev, " Termination current detected: %s\n", f_t[reg0.termi]); device_printf(dev, " Thermal suspend: %s\n", f_t[reg0.tsusp]); device_printf(dev, " DPPM active: %s\n", f_t[reg0.dppm]); device_printf(dev, " Thermal regulation: %s\n", i_a[reg0.treg]); am335x_pmic_read(dev, TPS65217_CHGCONFIG1_REG, (uint8_t *)®1, 1); device_printf(dev, " Charger: %s\n", d_e[reg1.chg_en]); device_printf(dev, " Suspend charge: %s\n", i_a[reg1.susp]); device_printf(dev, " Charge termination: %s\n", e_d[reg1.term]); device_printf(dev, " Charger reset: %s\n", i_a[reg1.reset]); device_printf(dev, " NTC TYPE: %s\n", ntc_type_c[reg1.ntc_type]); device_printf(dev, " Safety timer: %s\n", d_e[reg1.tmr_en]); device_printf(dev, " Charge safety timer: %s\n", timer_c[reg1.timer]); am335x_pmic_read(dev, TPS65217_CHGCONFIG2_REG, (uint8_t *)®2, 1); device_printf(dev, " Charge voltage: %s\n", tps65217_voreg_c[reg2.voreg]); device_printf(dev, " Pre-charge to fast charge transition voltage: %s\n", vprechg_c[reg2.vprechg]); device_printf(dev, " Dynamic timer function: %s\n", d_e[reg2.dyntmr]); am335x_pmic_read(dev, TPS65217_CHGCONFIG3_REG, (uint8_t *)®3, 1); device_printf(dev, " Temperature range for charging: %s\n", trange_c[reg3.trange]); device_printf(dev, " Termination current factor: %s\n", termif_c[reg3.termif]); device_printf(dev, " Pre-charge time: %s\n", pchrgt_c[reg3.pchrgt]); device_printf(dev, " Power path DPPM threshold: %s\n", dppmth_c[reg3.dppmth]); device_printf(dev, " Charge current: %s\n", ichrg_c[reg3.ichrg]); }
static void am335x_pmic_setvo(device_t dev, uint8_t vo) { struct tps65217_chgconfig2_reg reg2; am335x_pmic_read(dev, TPS65217_CHGCONFIG2_REG, (uint8_t *)®2, 1); reg2.voreg = vo; am335x_pmic_write(dev, TPS65217_CHGCONFIG2_REG, (uint8_t *)®2, 1); }
static void am335x_pmic_shutdown(void *xdev, int howto) { device_t dev; struct tps65217_status_reg reg; if (!(howto & RB_POWEROFF)) return; dev = (device_t)xdev; am335x_pmic_read(dev, TPS65217_STATUS_REG, (uint8_t *)®, 1); /* Set the OFF bit on status register to start the shutdown sequence. */ reg.off = 1; am335x_pmic_write(dev, TPS65217_STATUS_REG, (uint8_t *)®, 1); /* Toggle pmic_pwr_enable to shutdown the PMIC. */ am335x_rtc_pmic_pwr_toggle(); }
static void am335x_pmic_start(void *xdev) { struct am335x_pmic_softc *sc; device_t dev = (device_t)xdev; struct tps65217_status_reg status_reg; struct tps65217_chipid_reg chipid_reg; uint8_t reg, vo; char name[20]; char pwr[4][11] = {"Battery", "USB", "AC", "USB and AC"}; int rv; sc = device_get_softc(dev); am335x_pmic_read(dev, TPS65217_CHIPID_REG, (uint8_t *)&chipid_reg, 1); switch (chipid_reg.chip) { case TPS65217A: sprintf(name, "TPS65217A ver 1.%u", chipid_reg.rev); break; case TPS65217B: sprintf(name, "TPS65217B ver 1.%u", chipid_reg.rev); break; case TPS65217C: sprintf(name, "TPS65217C ver 1.%u", chipid_reg.rev); break; case TPS65217D: sprintf(name, "TPS65217D ver 1.%u", chipid_reg.rev); break; default: sprintf(name, "Unknown PMIC"); } am335x_pmic_read(dev, TPS65217_STATUS_REG, (uint8_t *)&status_reg, 1); device_printf(dev, "%s powered by %s\n", name, pwr[status_reg.usbpwr | (status_reg.acpwr << 1)]); if (am335x_pmic_vo[0] != '\0') { for (vo = 0; vo < 4; vo++) { if (strcmp(tps65217_voreg_c[vo], am335x_pmic_vo) == 0) break; } if (vo == 4) { device_printf(dev, "WARNING: hw.am335x_pmic.vo=\"%s\"" ": unsupported value\n", am335x_pmic_vo); } else { am335x_pmic_setvo(dev, vo); } } if (bootverbose || am335x_pmic_bootverbose) { am335x_pmic_dump_chgconfig(dev); } EVENTHANDLER_REGISTER(shutdown_final, am335x_pmic_shutdown, dev, SHUTDOWN_PRI_LAST); config_intrhook_disestablish(&sc->enum_hook); /* Unmask all interrupts and clear pending status */ reg = 0; am335x_pmic_write(dev, TPS65217_INT_REG, ®, 1); am335x_pmic_read(dev, TPS65217_INT_REG, ®, 1); if (sc->sc_irq_res != NULL) { rv = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, NULL, am335x_pmic_intr, sc, &sc->sc_intrhand); if (rv != 0) device_printf(dev, "Unable to setup the irq handler.\n"); } }