Lines Matching +full:wait +full:- +full:pin
3 * Copyright © 2006-2008,2010 Intel Corporation
27 * Chris Wilson <chris@chris-wilson.co.uk>
31 #include <linux/i2c-algo-bit.h>
77 /* Map gmbus pin pairs to names and registers. */
153 unsigned int pin) in get_gmbus_pin() argument
155 struct drm_i915_private *i915 = to_i915(display->drm); in get_gmbus_pin()
188 if (pin >= size || !pins[pin].name) in get_gmbus_pin()
191 return &pins[pin]; in get_gmbus_pin()
194 bool intel_gmbus_is_valid_pin(struct intel_display *display, unsigned int pin) in intel_gmbus_is_valid_pin() argument
196 return get_gmbus_pin(display, pin); in intel_gmbus_is_valid_pin()
242 struct intel_display *display = bus->display; in get_reserved()
243 struct drm_i915_private *i915 = to_i915(display->drm); in get_reserved()
248 reserved = intel_de_read_notrace(display, bus->gpio_reg) & in get_reserved()
257 struct intel_display *display = bus->display; in get_clock()
260 intel_de_write_notrace(display, bus->gpio_reg, reserved | GPIO_CLOCK_DIR_MASK); in get_clock()
261 intel_de_write_notrace(display, bus->gpio_reg, reserved); in get_clock()
263 return (intel_de_read_notrace(display, bus->gpio_reg) & GPIO_CLOCK_VAL_IN) != 0; in get_clock()
269 struct intel_display *display = bus->display; in get_data()
272 intel_de_write_notrace(display, bus->gpio_reg, reserved | GPIO_DATA_DIR_MASK); in get_data()
273 intel_de_write_notrace(display, bus->gpio_reg, reserved); in get_data()
275 return (intel_de_read_notrace(display, bus->gpio_reg) & GPIO_DATA_VAL_IN) != 0; in get_data()
281 struct intel_display *display = bus->display; in set_clock()
291 intel_de_write_notrace(display, bus->gpio_reg, reserved | clock_bits); in set_clock()
292 intel_de_posting_read(display, bus->gpio_reg); in set_clock()
298 struct intel_display *display = bus->display; in set_data()
308 intel_de_write_notrace(display, bus->gpio_reg, reserved | data_bits); in set_data()
309 intel_de_posting_read(display, bus->gpio_reg); in set_data()
316 struct intel_display *display = bus->display; in intel_gpio_pre_xfer()
317 struct drm_i915_private *i915 = to_i915(display->drm); in intel_gpio_pre_xfer()
334 struct intel_display *display = bus->display; in intel_gpio_post_xfer()
335 struct drm_i915_private *i915 = to_i915(display->drm); in intel_gpio_post_xfer()
349 algo = &bus->bit_algo; in intel_gpio_setup()
351 bus->gpio_reg = gpio_reg; in intel_gpio_setup()
352 bus->adapter.algo_data = algo; in intel_gpio_setup()
353 algo->setsda = set_data; in intel_gpio_setup()
354 algo->setscl = set_clock; in intel_gpio_setup()
355 algo->getsda = get_data; in intel_gpio_setup()
356 algo->getscl = get_clock; in intel_gpio_setup()
357 algo->pre_xfer = intel_gpio_pre_xfer; in intel_gpio_setup()
358 algo->post_xfer = intel_gpio_post_xfer; in intel_gpio_setup()
359 algo->udelay = I2C_RISEFALL_TIME; in intel_gpio_setup()
360 algo->timeout = usecs_to_jiffies(2200); in intel_gpio_setup()
361 algo->data = bus; in intel_gpio_setup()
366 struct drm_i915_private *i915 = to_i915(display->drm); in has_gmbus_irq()
368 * encoder->shutdown() may want to use GMBUS in has_gmbus_irq()
376 DEFINE_WAIT(wait); in gmbus_wait()
387 add_wait_queue(&display->gmbus.wait_queue, &wait); in gmbus_wait()
398 remove_wait_queue(&display->gmbus.wait_queue, &wait); in gmbus_wait()
401 return -ENXIO; in gmbus_wait()
409 DEFINE_WAIT(wait); in gmbus_wait_idle()
418 add_wait_queue(&display->gmbus.wait_queue, &wait); in gmbus_wait_idle()
424 remove_wait_queue(&display->gmbus.wait_queue, &wait); in gmbus_wait_idle()
475 } while (--len && ++loop < 4); in gmbus_xfer_read_chunk()
477 if (burst_read && len == size - 4) in gmbus_xfer_read_chunk()
499 struct drm_i915_private *i915 = to_i915(display->drm); in gmbus_xfer_read()
500 u8 *buf = msg->buf; in gmbus_xfer_read()
501 unsigned int rx_size = msg->len; in gmbus_xfer_read()
511 ret = gmbus_xfer_read_chunk(display, msg->addr, buf, len, in gmbus_xfer_read()
516 rx_size -= len; in gmbus_xfer_read()
534 len -= 1; in gmbus_xfer_write_chunk()
546 } while (--len && ++loop < 4); in gmbus_xfer_write_chunk()
562 u8 *buf = msg->buf; in gmbus_xfer_write()
563 unsigned int tx_size = msg->len; in gmbus_xfer_write()
570 ret = gmbus_xfer_write_chunk(display, msg->addr, buf, len, in gmbus_xfer_write()
576 tx_size -= len; in gmbus_xfer_write()
611 /* GMBUS5 holds 16-bit index */ in gmbus_index_xfer()
633 struct intel_display *display = bus->display; in do_gmbus_xfer()
634 struct drm_i915_private *i915 = to_i915(display->drm); in do_gmbus_xfer()
645 intel_de_write_fw(display, GMBUS0(display), gmbus0_source | bus->reg0); in do_gmbus_xfer()
651 gmbus0_source | bus->reg0); in do_gmbus_xfer()
655 gmbus0_source | bus->reg0, 0); in do_gmbus_xfer()
663 if (ret == -ETIMEDOUT) in do_gmbus_xfer()
676 * We will re-enable it at the start of the next xfer, in do_gmbus_xfer()
680 drm_dbg_kms(display->drm, in do_gmbus_xfer()
682 adapter->name); in do_gmbus_xfer()
683 ret = -ETIMEDOUT; in do_gmbus_xfer()
691 * Wait for bus to IDLE before clearing NAK. in do_gmbus_xfer()
696 * adapter must report -ENXIO. It is not clear what to return if no ACK in do_gmbus_xfer()
698 * spurious -ENXIO because that will prevent i2c and drm edid functions in do_gmbus_xfer()
699 * from retrying. So return -ENXIO only when gmbus properly quiescents - in do_gmbus_xfer()
703 ret = -ENXIO; in do_gmbus_xfer()
705 drm_dbg_kms(display->drm, in do_gmbus_xfer()
707 adapter->name); in do_gmbus_xfer()
708 ret = -ETIMEDOUT; in do_gmbus_xfer()
719 drm_dbg_kms(display->drm, "GMBUS [%s] NAK for addr: %04x %c(%d)\n", in do_gmbus_xfer()
720 adapter->name, msgs[i].addr, in do_gmbus_xfer()
725 * message once on -ENXIO for GMBUS transfers; the bit banging algorithm in do_gmbus_xfer()
727 * drm_do_probe_ddc_edid, which bails out on the first -ENXIO. in do_gmbus_xfer()
729 if (ret == -ENXIO && i == 0 && try++ == 0) { in do_gmbus_xfer()
730 drm_dbg_kms(display->drm, in do_gmbus_xfer()
732 adapter->name); in do_gmbus_xfer()
739 drm_dbg_kms(display->drm, in do_gmbus_xfer()
740 "GMBUS [%s] timed out, falling back to bit banging on pin %d\n", in do_gmbus_xfer()
741 bus->adapter.name, bus->reg0 & 0xff); in do_gmbus_xfer()
748 ret = -EAGAIN; in do_gmbus_xfer()
764 struct intel_display *display = bus->display; in gmbus_xfer()
765 struct drm_i915_private *i915 = to_i915(display->drm); in gmbus_xfer()
771 if (bus->force_bit) { in gmbus_xfer()
774 bus->force_bit &= ~GMBUS_FORCE_BIT_RETRY; in gmbus_xfer()
777 if (ret == -EAGAIN) in gmbus_xfer()
778 bus->force_bit |= GMBUS_FORCE_BIT_RETRY; in gmbus_xfer()
789 struct intel_display *display = bus->display; in intel_gmbus_output_aksv()
790 struct drm_i915_private *i915 = to_i915(display->drm); in intel_gmbus_output_aksv()
811 mutex_lock(&display->gmbus.mutex); in intel_gmbus_output_aksv()
815 * pass the i2c command, and tell GMBUS to use the HW-provided value in intel_gmbus_output_aksv()
820 mutex_unlock(&display->gmbus.mutex); in intel_gmbus_output_aksv()
844 struct intel_display *display = bus->display; in gmbus_lock_bus()
846 mutex_lock(&display->gmbus.mutex); in gmbus_lock_bus()
853 struct intel_display *display = bus->display; in gmbus_trylock_bus()
855 return mutex_trylock(&display->gmbus.mutex); in gmbus_trylock_bus()
862 struct intel_display *display = bus->display; in gmbus_unlock_bus()
864 mutex_unlock(&display->gmbus.mutex); in gmbus_unlock_bus()
874 * intel_gmbus_setup - instantiate all Intel i2c GMBuses
879 struct drm_i915_private *i915 = to_i915(display->drm); in intel_gmbus_setup()
880 struct pci_dev *pdev = to_pci_dev(display->drm->dev); in intel_gmbus_setup()
881 unsigned int pin; in intel_gmbus_setup() local
885 display->gmbus.mmio_base = VLV_DISPLAY_BASE; in intel_gmbus_setup()
891 display->gmbus.mmio_base = PCH_DISPLAY_BASE; in intel_gmbus_setup()
893 mutex_init(&display->gmbus.mutex); in intel_gmbus_setup()
894 init_waitqueue_head(&display->gmbus.wait_queue); in intel_gmbus_setup()
896 for (pin = 0; pin < ARRAY_SIZE(display->gmbus.bus); pin++) { in intel_gmbus_setup()
900 gmbus_pin = get_gmbus_pin(display, pin); in intel_gmbus_setup()
906 ret = -ENOMEM; in intel_gmbus_setup()
910 bus->adapter.owner = THIS_MODULE; in intel_gmbus_setup()
911 snprintf(bus->adapter.name, in intel_gmbus_setup()
912 sizeof(bus->adapter.name), in intel_gmbus_setup()
913 "i915 gmbus %s", gmbus_pin->name); in intel_gmbus_setup()
915 bus->adapter.dev.parent = &pdev->dev; in intel_gmbus_setup()
916 bus->display = display; in intel_gmbus_setup()
918 bus->adapter.algo = &gmbus_algorithm; in intel_gmbus_setup()
919 bus->adapter.lock_ops = &gmbus_lock_ops; in intel_gmbus_setup()
925 bus->adapter.retries = 1; in intel_gmbus_setup()
928 bus->reg0 = pin | GMBUS_RATE_100KHZ; in intel_gmbus_setup()
932 bus->force_bit = 1; in intel_gmbus_setup()
934 intel_gpio_setup(bus, GPIO(display, gmbus_pin->gpio)); in intel_gmbus_setup()
936 ret = i2c_add_adapter(&bus->adapter); in intel_gmbus_setup()
942 display->gmbus.bus[pin] = bus; in intel_gmbus_setup()
956 unsigned int pin) in intel_gmbus_get_adapter() argument
958 if (drm_WARN_ON(display->drm, pin >= ARRAY_SIZE(display->gmbus.bus) || in intel_gmbus_get_adapter()
959 !display->gmbus.bus[pin])) in intel_gmbus_get_adapter()
962 return &display->gmbus.bus[pin]->adapter; in intel_gmbus_get_adapter()
968 struct intel_display *display = bus->display; in intel_gmbus_force_bit()
970 mutex_lock(&display->gmbus.mutex); in intel_gmbus_force_bit()
972 bus->force_bit += force_bit ? 1 : -1; in intel_gmbus_force_bit()
973 drm_dbg_kms(display->drm, in intel_gmbus_force_bit()
974 "%sabling bit-banging on %s. force bit now %d\n", in intel_gmbus_force_bit()
975 force_bit ? "en" : "dis", adapter->name, in intel_gmbus_force_bit()
976 bus->force_bit); in intel_gmbus_force_bit()
978 mutex_unlock(&display->gmbus.mutex); in intel_gmbus_force_bit()
985 return bus->force_bit; in intel_gmbus_is_forced_bit()
990 unsigned int pin; in intel_gmbus_teardown() local
992 for (pin = 0; pin < ARRAY_SIZE(display->gmbus.bus); pin++) { in intel_gmbus_teardown()
995 bus = display->gmbus.bus[pin]; in intel_gmbus_teardown()
999 i2c_del_adapter(&bus->adapter); in intel_gmbus_teardown()
1002 display->gmbus.bus[pin] = NULL; in intel_gmbus_teardown()
1008 wake_up_all(&display->gmbus.wait_queue); in intel_gmbus_irq_handler()