Lines Matching +full:burst +full:- +full:read
75 #define DO_POLL(sc) (cold || kdb_active || SCHEDULER_STOPPED() || sc->poll)
147 * 0 - Try read clock registers from ACPI and fallback to p.1.
148 * 1 - Calculate values based on controller type (IC clock rate).
149 * 2 - Use values inherited from DragonflyBSD driver (old behavior).
150 * 3 - Keep clock registers intact.
157 * Low-level inline support functions
162 bus_write_4(sc->regs_res, reg, value);
163 bus_barrier(sc->regs_res, reg, 4, BUS_SPACE_BARRIER_WRITE);
171 bus_barrier(sc->regs_res, reg, 4, BUS_SPACE_BARRIER_READ);
172 value = bus_read_4(sc->regs_res, reg);
179 if (sc->intr_mask != val) {
181 sc->intr_mask = val;
200 /* User-requested abort. Not really a error */
224 * detection or driver's read/write pipelining errors.
256 for (retry = 100; retry > 0; --retry) {
275 int txlvl = -1;
313 mtx_lock_spin(&sc->io_lock);
315 msleep_spin(sc, &sc->io_lock, "i2cwait",
318 mtx_unlock_spin(&sc->io_lock);
344 if (sc->slave_valid && sc->last_slave == slave &&
345 sc->use_10bit == use_10bit) {
348 sc->use_10bit = use_10bit;
362 if (sc->use_10bit) {
369 sc->slave_valid = true;
370 sc->last_slave = slave;
421 * Amount of unread data before next burst to get better I2C bus utilization.
423 * Intel-recommended value is 16 for DMA transfers with 64-byte depth FIFOs.
434 int burst, target, lowat = 0;
442 burst = sc->cfg.txfifo_depth -
444 if (burst <= 0) {
449 burst = sc->cfg.txfifo_depth -
453 burst = MIN(burst, sc->cfg.rxfifo_depth -
454 (requested - received));
455 target = MIN(requested + burst, (int)len);
460 if (stop && requested == len - 1)
467 if (requested != len && requested - received > IG4_FIFO_LOWAT)
470 while (received < requested - lowat) {
471 burst = MIN(requested - received,
473 if (burst > 0) {
474 while (burst--)
479 requested - received - lowat - 1);
496 int burst, target;
503 burst = sc->cfg.txfifo_depth -
505 target = MIN(sent + burst, (int)len);
510 if (stop && sent == len - 1)
516 if (len - sent <= sc->cfg.txfifo_depth)
517 lowat = sc->cfg.txfifo_depth - (len - sent);
566 if (i == nmsgs - 1 && (msgs[i].flags & IIC_M_NOSTOP) != 0) {
577 (msgs[i - 1].flags & IIC_M_NOSTOP) == 0) {
581 if ((msgs[i - 1].flags & IIC_M_NOSTOP) != 0 &&
582 msgs[i].slave != msgs[i - 1].slave) {
588 (msgs[i - 1].flags & IIC_M_RD)) {
602 allocated = sx_xlocked(&sc->call_lock) != 0;
604 sx_xlock(&sc->call_lock);
606 /* Debugging - dump registers. */
627 if (!sc->slave_valid ||
628 (msgs[i].slave >> 1) != sc->last_slave) {
662 device_printf(sc->dev, "Failed to abort "
683 sx_unlock(&sc->call_lock);
693 allocated = sx_xlocked(&sc->call_lock) != 0;
695 sx_xlock(&sc->call_lock);
699 *oldaddr = sc->last_slave << 1;
702 sc->slave_valid = false;
705 sx_unlock(&sc->call_lock);
721 if (sx_try_xlock(&sc->call_lock) == 0)
724 sc->poll = true;
726 sx_xlock(&sc->call_lock);
730 sc->poll = false;
731 sx_unlock(&sc->call_lock);
778 sda_fall_time = hw->sda_fall_time == 0 ? tf_max : hw->sda_fall_time;
780 ((hw->ic_clock_rate * (thigh + sda_fall_time) + 500) / 1000 - 3);
782 scl_fall_time = hw->scl_fall_time == 0 ? tf_max : hw->scl_fall_time;
784 ((hw->ic_clock_rate * (tlow + scl_fall_time) + 500) / 1000 - 1);
790 if (hw->sda_hold_time != 0)
792 ((hw->ic_clock_rate * hw->sda_hold_time + 500) / 1000);
815 if (obj->Type == ACPI_TYPE_PACKAGE && obj->Package.Count == 3) {
816 elems = obj->Package.Elements;
838 sc->cfg.version = reg_read(sc, IG4_REG_COMP_VER);
839 sc->cfg.bus_speed = reg_read(sc, IG4_REG_CTL) & IG4_CTL_SPEED_MASK;
840 sc->cfg.ss_scl_hcnt =
842 sc->cfg.ss_scl_lcnt =
844 sc->cfg.fs_scl_hcnt =
846 sc->cfg.fs_scl_lcnt =
848 sc->cfg.ss_sda_hold = sc->cfg.fs_sda_hold =
851 if (sc->cfg.bus_speed != IG4_CTL_SPEED_STD)
852 sc->cfg.bus_speed = IG4_CTL_SPEED_FAST;
855 if (sc->version == IG4_HASWELL || sc->version == IG4_ATOM) {
858 sc->cfg.txfifo_depth = IG4_PARAM1_TXFIFO_DEPTH(v);
860 sc->cfg.rxfifo_depth = IG4_PARAM1_RXFIFO_DEPTH(v);
863 /* Override hardware config with IC_clock-based counter values */
864 if (ig4_timings < 2 && sc->version < nitems(ig4iic_hw)) {
865 hw = &ig4iic_hw[sc->version];
866 sc->cfg.bus_speed = IG4_CTL_SPEED_FAST;
867 ig4iic_clk_params(hw, IG4_CTL_SPEED_STD, &sc->cfg.ss_scl_hcnt,
868 &sc->cfg.ss_scl_lcnt, &sc->cfg.ss_sda_hold);
869 ig4iic_clk_params(hw, IG4_CTL_SPEED_FAST, &sc->cfg.fs_scl_hcnt,
870 &sc->cfg.fs_scl_lcnt, &sc->cfg.fs_sda_hold);
871 if (hw->txfifo_depth != 0)
872 sc->cfg.txfifo_depth = hw->txfifo_depth;
873 if (hw->rxfifo_depth != 0)
874 sc->cfg.rxfifo_depth = hw->rxfifo_depth;
884 sc->cfg.bus_speed = IG4_CTL_SPEED_STD;
885 sc->cfg.ss_scl_hcnt = sc->cfg.fs_scl_hcnt = 100;
886 sc->cfg.ss_scl_lcnt = sc->cfg.fs_scl_lcnt = 125;
887 if (sc->version == IG4_SKYLAKE)
888 sc->cfg.ss_sda_hold = sc->cfg.fs_sda_hold = 28;
893 if (ig4_timings == 0 && (handle = acpi_get_handle(sc->dev)) != NULL) {
894 ig4iic_acpi_params(handle, "SSCN", &sc->cfg.ss_scl_hcnt,
895 &sc->cfg.ss_scl_lcnt, &sc->cfg.ss_sda_hold);
896 ig4iic_acpi_params(handle, "FMCN", &sc->cfg.fs_scl_hcnt,
897 &sc->cfg.fs_scl_lcnt, &sc->cfg.fs_sda_hold);
902 device_printf(sc->dev, "Controller parameters:\n");
904 sc->cfg.bus_speed == IG4_CTL_SPEED_STD ? "Std" : "Fast");
907 sc->cfg.ss_scl_hcnt, sc->cfg.ss_scl_lcnt,
908 sc->cfg.ss_sda_hold);
910 sc->cfg.fs_scl_hcnt, sc->cfg.fs_scl_lcnt,
911 sc->cfg.fs_sda_hold);
921 if (IG4_HAS_ADDREGS(sc->version) && (v & IG4_RESTORE_REQUIRED)) {
928 if ((sc->version == IG4_HASWELL || sc->version == IG4_ATOM) && reset) {
931 } else if (IG4_HAS_ADDREGS(sc->version) && reset) {
936 if (sc->version == IG4_ATOM)
939 if (sc->version == IG4_HASWELL || sc->version == IG4_ATOM) {
946 if (sc->version == IG4_HASWELL &&
954 if (sc->version == IG4_HASWELL) {
957 } else if (IG4_HAS_ADDREGS(sc->version)) {
962 if (sc->version == IG4_HASWELL || sc->version == IG4_ATOM) {
969 device_printf(sc->dev, "controller error during attach-1\n");
975 sc->intr_mask = 0;
977 reg_write(sc, IG4_REG_SS_SCL_HCNT, sc->cfg.ss_scl_hcnt);
978 reg_write(sc, IG4_REG_SS_SCL_LCNT, sc->cfg.ss_scl_lcnt);
979 reg_write(sc, IG4_REG_FS_SCL_HCNT, sc->cfg.fs_scl_hcnt);
980 reg_write(sc, IG4_REG_FS_SCL_LCNT, sc->cfg.fs_scl_lcnt);
982 (sc->cfg.bus_speed & IG4_CTL_SPEED_MASK) == IG4_CTL_SPEED_STD ?
983 sc->cfg.ss_sda_hold : sc->cfg.fs_sda_hold);
992 (sc->cfg.bus_speed & IG4_CTL_SPEED_MASK));
995 sc->slave_valid = false;
1010 if (sc->cfg.txfifo_depth == 0) {
1013 sc->cfg.txfifo_depth =
1017 if (sc->cfg.rxfifo_depth == 0) {
1020 sc->cfg.rxfifo_depth =
1026 sc->cfg.rxfifo_depth, sc->cfg.txfifo_depth);
1038 mtx_init(&sc->io_lock, "IG4 I/O lock", NULL, MTX_SPIN);
1039 sx_init(&sc->call_lock, "IG4 call lock");
1043 error = ig4iic_set_config(sc, IG4_HAS_ADDREGS(sc->version));
1048 sc->iicbus = device_add_child(sc->dev, "iicbus", DEVICE_UNIT_ANY);
1049 if (sc->iicbus == NULL) {
1050 device_printf(sc->dev, "iicbus driver not found\n");
1056 device_printf(sc->dev, "controller error during attach-2\n");
1061 device_printf(sc->dev, "controller error during attach-3\n");
1065 error = bus_setup_intr(sc->dev, sc->intr_res, INTR_TYPE_MISC | INTR_MPSAFE,
1066 ig4iic_intr, NULL, sc, &sc->intr_handle);
1068 device_printf(sc->dev,
1072 error = bus_generic_attach(sc->dev);
1074 device_printf(sc->dev,
1087 if (device_is_attached(sc->dev)) {
1088 error = bus_generic_detach(sc->dev);
1092 if (sc->iicbus)
1093 device_delete_child(sc->dev, sc->iicbus);
1094 if (sc->intr_handle)
1095 bus_teardown_intr(sc->dev, sc->intr_res, sc->intr_handle);
1097 sx_xlock(&sc->call_lock);
1099 sc->iicbus = NULL;
1100 sc->intr_handle = NULL;
1104 sx_xunlock(&sc->call_lock);
1106 mtx_destroy(&sc->io_lock);
1107 sx_destroy(&sc->call_lock);
1118 error = bus_generic_suspend(sc->dev);
1120 sx_xlock(&sc->call_lock);
1122 if (IG4_HAS_ADDREGS(sc->version)) {
1134 sx_xunlock(&sc->call_lock);
1143 sx_xlock(&sc->call_lock);
1144 if (ig4iic_set_config(sc, IG4_HAS_ADDREGS(sc->version)))
1145 device_printf(sc->dev, "controller error during resume\n");
1146 sx_xunlock(&sc->call_lock);
1148 error = bus_generic_resume(sc->dev);
1162 mtx_lock_spin(&sc->io_lock);
1164 if (sc->intr_mask != 0 && reg_read(sc, IG4_REG_INTR_STAT) != 0) {
1170 mtx_unlock_spin(&sc->io_lock);
1176 device_printf(sc->dev, " %-23s %08x\n", #reg, reg_read(sc, reg))
1181 device_printf(sc->dev, "ig4iic register dump:\n");
1207 if (sc->version == IG4_ATOM) {
1211 if (sc->version == IG4_HASWELL || sc->version == IG4_ATOM) {
1214 } else if (sc->version == IG4_SKYLAKE) {
1217 if (sc->version == IG4_HASWELL) {
1220 } else if (IG4_HAS_ADDREGS(sc->version)) {