Lines Matching refs:dev

81 static void dump_iic_regs(const char* header, struct ibm_iic_private* dev)  in dump_iic_regs()  argument
83 volatile struct iic_regs __iomem *iic = dev->vaddr; in dump_iic_regs()
84 printk(KERN_DEBUG "ibm-iic%d: %s\n", dev->idx, header); in dump_iic_regs()
94 # define DUMP_REGS(h,dev) dump_iic_regs((h),(dev)) argument
96 # define DUMP_REGS(h,dev) ((void)0) argument
125 static inline void iic_interrupt_mode(struct ibm_iic_private* dev, int enable) in iic_interrupt_mode() argument
127 out_8(&dev->vaddr->intmsk, enable ? INTRMSK_EIMTC : 0); in iic_interrupt_mode()
133 static void iic_dev_init(struct ibm_iic_private* dev) in iic_dev_init() argument
135 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_dev_init()
137 DBG("%d: init\n", dev->idx); in iic_dev_init()
153 out_8(&iic->clkdiv, dev->clckdiv); in iic_dev_init()
166 iic_interrupt_mode(dev, dev->irq >= 0); in iic_dev_init()
170 | (dev->fast_mode ? MDCNTL_FSM : 0)); in iic_dev_init()
172 DUMP_REGS("iic_init", dev); in iic_dev_init()
178 static void iic_dev_reset(struct ibm_iic_private* dev) in iic_dev_reset() argument
180 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_dev_reset()
184 DBG("%d: soft reset\n", dev->idx); in iic_dev_reset()
185 DUMP_REGS("reset", dev); in iic_dev_reset()
193 DBG("%d: trying to regain bus control\n", dev->idx); in iic_dev_reset()
220 iic_dev_init(dev); in iic_dev_reset()
239 static int iic_smbus_quick(struct ibm_iic_private* dev, const struct i2c_msg* p) in iic_smbus_quick() argument
241 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_smbus_quick()
242 const struct ibm_iic_timings *t = &timings[dev->fast_mode ? 1 : 0]; in iic_smbus_quick()
249 dev->idx); in iic_smbus_quick()
253 DBG("%d: smbus_quick(0x%02x)\n", dev->idx, p->addr); in iic_smbus_quick()
306 DBG("%d: smbus_quick -> %s\n", dev->idx, res ? "NACK" : "ACK"); in iic_smbus_quick()
312 iic_dev_init(dev); in iic_smbus_quick()
316 DBG("%d: smbus_quick - bus is stuck\n", dev->idx); in iic_smbus_quick()
326 struct ibm_iic_private* dev = (struct ibm_iic_private*)dev_id; in iic_handler() local
327 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_handler()
330 dev->idx, in_8(&iic->sts), in_8(&iic->extsts)); in iic_handler()
334 wake_up_interruptible(&dev->wq); in iic_handler()
343 static int iic_xfer_result(struct ibm_iic_private* dev) in iic_xfer_result() argument
345 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_xfer_result()
348 DBG("%d: xfer error, EXTSTS = 0x%02x\n", dev->idx, in iic_xfer_result()
364 DBG("%d: bus is stuck, resetting\n", dev->idx); in iic_xfer_result()
365 iic_dev_reset(dev); in iic_xfer_result()
376 static void iic_abort_xfer(struct ibm_iic_private* dev) in iic_abort_xfer() argument
378 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_abort_xfer()
381 DBG("%d: iic_abort_xfer\n", dev->idx); in iic_abort_xfer()
392 DBG("%d: abort timeout, resetting...\n", dev->idx); in iic_abort_xfer()
393 iic_dev_reset(dev); in iic_abort_xfer()
400 iic_xfer_result(dev); in iic_abort_xfer()
408 static int iic_wait_for_tc(struct ibm_iic_private* dev){ in iic_wait_for_tc() argument
410 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_wait_for_tc()
413 if (dev->irq >= 0){ in iic_wait_for_tc()
415 ret = wait_event_interruptible_timeout(dev->wq, in iic_wait_for_tc()
416 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout); in iic_wait_for_tc()
419 DBG("%d: wait interrupted\n", dev->idx); in iic_wait_for_tc()
421 DBG("%d: wait timeout\n", dev->idx); in iic_wait_for_tc()
427 unsigned long x = jiffies + dev->adap.timeout; in iic_wait_for_tc()
431 DBG("%d: poll timeout\n", dev->idx); in iic_wait_for_tc()
437 DBG("%d: poll interrupted\n", dev->idx); in iic_wait_for_tc()
446 iic_abort_xfer(dev); in iic_wait_for_tc()
448 ret = iic_xfer_result(dev); in iic_wait_for_tc()
450 DBG2("%d: iic_wait_for_tc -> %d\n", dev->idx, ret); in iic_wait_for_tc()
458 static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm, in iic_xfer_bytes() argument
461 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_xfer_bytes()
484 DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, count, cmd); in iic_xfer_bytes()
490 ret = iic_wait_for_tc(dev); in iic_xfer_bytes()
496 dev->idx, count, ret); in iic_xfer_bytes()
500 iic_abort_xfer(dev); in iic_xfer_bytes()
517 static inline void iic_address(struct ibm_iic_private* dev, struct i2c_msg* msg) in iic_address() argument
519 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_address()
522 DBG2("%d: iic_address, 0x%03x (%d-bit)\n", dev->idx, in iic_address()
554 struct ibm_iic_private* dev = (struct ibm_iic_private*)(i2c_get_adapdata(adap)); in iic_xfer() local
555 volatile struct iic_regs __iomem *iic = dev->vaddr; in iic_xfer()
558 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num); in iic_xfer()
564 DBG("%d: invalid address 0x%03x (%d-bit)\n", dev->idx, in iic_xfer()
575 return iic_smbus_quick(dev, &msgs[0]); in iic_xfer()
577 DBG("%d: invalid len %d in msg[%d]\n", dev->idx, in iic_xfer()
582 DBG("%d: invalid addr in msg[%d]\n", dev->idx, i); in iic_xfer()
589 DBG("%d: iic_xfer, bus is not free\n", dev->idx); in iic_xfer()
599 iic_dev_reset(dev); in iic_xfer()
602 DBG("%d: iic_xfer, bus is still not free\n", dev->idx); in iic_xfer()
612 iic_address(dev, &msgs[0]); in iic_xfer()
616 ret = iic_xfer_bytes(dev, &msgs[i], i < num - 1); in iic_xfer()
659 struct ibm_iic_private *dev) in iic_request_irq() argument
661 struct device_node *np = ofdev->dev.of_node; in iic_request_irq()
669 dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n"); in iic_request_irq()
676 iic_interrupt_mode(dev, 0); in iic_request_irq()
677 if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) { in iic_request_irq()
678 dev_err(&ofdev->dev, "request_irq %d failed\n", irq); in iic_request_irq()
691 struct device_node *np = ofdev->dev.of_node; in iic_probe()
692 struct ibm_iic_private *dev; in iic_probe() local
697 dev = kzalloc(sizeof(*dev), GFP_KERNEL); in iic_probe()
698 if (!dev) in iic_probe()
701 platform_set_drvdata(ofdev, dev); in iic_probe()
703 dev->vaddr = of_iomap(np, 0); in iic_probe()
704 if (dev->vaddr == NULL) { in iic_probe()
705 dev_err(&ofdev->dev, "failed to iomap device\n"); in iic_probe()
710 init_waitqueue_head(&dev->wq); in iic_probe()
712 dev->irq = iic_request_irq(ofdev, dev); in iic_probe()
713 if (!dev->irq) in iic_probe()
714 dev_warn(&ofdev->dev, "using polling mode\n"); in iic_probe()
718 dev->fast_mode = 1; in iic_probe()
724 dev_err(&ofdev->dev, "Unable to get bus frequency\n"); in iic_probe()
730 dev->clckdiv = iic_clckdiv(*freq); in iic_probe()
731 dev_dbg(&ofdev->dev, "clckdiv = %d\n", dev->clckdiv); in iic_probe()
734 iic_dev_init(dev); in iic_probe()
737 adap = &dev->adap; in iic_probe()
738 adap->dev.parent = &ofdev->dev; in iic_probe()
739 adap->dev.of_node = of_node_get(np); in iic_probe()
741 i2c_set_adapdata(adap, dev); in iic_probe()
750 dev_info(&ofdev->dev, "using %s mode\n", in iic_probe()
751 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); in iic_probe()
756 if (dev->irq) { in iic_probe()
757 iic_interrupt_mode(dev, 0); in iic_probe()
758 free_irq(dev->irq, dev); in iic_probe()
761 if (dev->vaddr) in iic_probe()
762 iounmap(dev->vaddr); in iic_probe()
764 kfree(dev); in iic_probe()
773 struct ibm_iic_private *dev = platform_get_drvdata(ofdev); in iic_remove() local
775 i2c_del_adapter(&dev->adap); in iic_remove()
777 if (dev->irq) { in iic_remove()
778 iic_interrupt_mode(dev, 0); in iic_remove()
779 free_irq(dev->irq, dev); in iic_remove()
782 iounmap(dev->vaddr); in iic_remove()
783 kfree(dev); in iic_remove()