Lines Matching defs:bt_bmc
57 struct bt_bmc {
69 static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
71 return readb(bt_bmc->base + reg);
74 static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
76 writeb(data, bt_bmc->base + reg);
79 static void clr_rd_ptr(struct bt_bmc *bt_bmc)
81 bt_outb(bt_bmc, BT_CTRL_CLR_RD_PTR, BT_CTRL);
84 static void clr_wr_ptr(struct bt_bmc *bt_bmc)
86 bt_outb(bt_bmc, BT_CTRL_CLR_WR_PTR, BT_CTRL);
89 static void clr_h2b_atn(struct bt_bmc *bt_bmc)
91 bt_outb(bt_bmc, BT_CTRL_H2B_ATN, BT_CTRL);
94 static void set_b_busy(struct bt_bmc *bt_bmc)
96 if (!(bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_B_BUSY))
97 bt_outb(bt_bmc, BT_CTRL_B_BUSY, BT_CTRL);
100 static void clr_b_busy(struct bt_bmc *bt_bmc)
102 if (bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_B_BUSY)
103 bt_outb(bt_bmc, BT_CTRL_B_BUSY, BT_CTRL);
106 static void set_b2h_atn(struct bt_bmc *bt_bmc)
108 bt_outb(bt_bmc, BT_CTRL_B2H_ATN, BT_CTRL);
111 static u8 bt_read(struct bt_bmc *bt_bmc)
113 return bt_inb(bt_bmc, BT_BMC2HOST);
116 static ssize_t bt_readn(struct bt_bmc *bt_bmc, u8 *buf, size_t n)
121 buf[i] = bt_read(bt_bmc);
125 static void bt_write(struct bt_bmc *bt_bmc, u8 c)
127 bt_outb(bt_bmc, c, BT_BMC2HOST);
130 static ssize_t bt_writen(struct bt_bmc *bt_bmc, u8 *buf, size_t n)
135 bt_write(bt_bmc, buf[i]);
139 static void set_sms_atn(struct bt_bmc *bt_bmc)
141 bt_outb(bt_bmc, BT_CTRL_SMS_ATN, BT_CTRL);
144 static struct bt_bmc *file_bt_bmc(struct file *file)
146 return container_of(file->private_data, struct bt_bmc, miscdev);
151 struct bt_bmc *bt_bmc = file_bt_bmc(file);
154 clr_b_busy(bt_bmc);
178 struct bt_bmc *bt_bmc = file_bt_bmc(file);
187 if (wait_event_interruptible(bt_bmc->queue,
188 bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_H2B_ATN))
191 mutex_lock(&bt_bmc->mutex);
193 if (unlikely(!(bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_H2B_ATN))) {
198 set_b_busy(bt_bmc);
199 clr_h2b_atn(bt_bmc);
200 clr_rd_ptr(bt_bmc);
206 kbuffer[0] = bt_read(bt_bmc);
216 bt_readn(bt_bmc, kbuffer + len_byte, nread);
228 clr_b_busy(bt_bmc);
231 mutex_unlock(&bt_bmc->mutex);
244 struct bt_bmc *bt_bmc = file_bt_bmc(file);
261 if (wait_event_interruptible(bt_bmc->queue,
262 !(bt_inb(bt_bmc, BT_CTRL) &
266 mutex_lock(&bt_bmc->mutex);
268 if (unlikely(bt_inb(bt_bmc, BT_CTRL) &
274 clr_wr_ptr(bt_bmc);
283 bt_writen(bt_bmc, kbuffer, nwritten);
290 set_b2h_atn(bt_bmc);
293 mutex_unlock(&bt_bmc->mutex);
300 struct bt_bmc *bt_bmc = file_bt_bmc(file);
304 set_sms_atn(bt_bmc);
312 struct bt_bmc *bt_bmc = file_bt_bmc(file);
315 set_b_busy(bt_bmc);
321 struct bt_bmc *bt_bmc = file_bt_bmc(file);
325 poll_wait(file, &bt_bmc->queue, wait);
327 ctrl = bt_inb(bt_bmc, BT_CTRL);
350 struct bt_bmc *bt_bmc = from_timer(bt_bmc, t, poll_timer);
352 bt_bmc->poll_timer.expires += msecs_to_jiffies(500);
353 wake_up(&bt_bmc->queue);
354 add_timer(&bt_bmc->poll_timer);
359 struct bt_bmc *bt_bmc = arg;
362 reg = readl(bt_bmc->base + BT_CR2);
369 writel(reg, bt_bmc->base + BT_CR2);
371 wake_up(&bt_bmc->queue);
375 static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
382 bt_bmc->irq = platform_get_irq_optional(pdev, 0);
383 if (bt_bmc->irq < 0)
384 return bt_bmc->irq;
386 rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED,
387 DEVICE_NAME, bt_bmc);
389 dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq);
390 bt_bmc->irq = rc;
400 reg = readl(bt_bmc->base + BT_CR1);
402 writel(reg, bt_bmc->base + BT_CR1);
409 struct bt_bmc *bt_bmc;
416 bt_bmc = devm_kzalloc(dev, sizeof(*bt_bmc), GFP_KERNEL);
417 if (!bt_bmc)
420 dev_set_drvdata(&pdev->dev, bt_bmc);
422 bt_bmc->base = devm_platform_ioremap_resource(pdev, 0);
423 if (IS_ERR(bt_bmc->base))
424 return PTR_ERR(bt_bmc->base);
426 mutex_init(&bt_bmc->mutex);
427 init_waitqueue_head(&bt_bmc->queue);
429 bt_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
430 bt_bmc->miscdev.name = DEVICE_NAME;
431 bt_bmc->miscdev.fops = &bt_bmc_fops;
432 bt_bmc->miscdev.parent = dev;
433 rc = misc_register(&bt_bmc->miscdev);
439 bt_bmc_config_irq(bt_bmc, pdev);
441 if (bt_bmc->irq >= 0) {
442 dev_info(dev, "Using IRQ %d\n", bt_bmc->irq);
445 timer_setup(&bt_bmc->poll_timer, poll_timer, 0);
446 bt_bmc->poll_timer.expires = jiffies + msecs_to_jiffies(10);
447 add_timer(&bt_bmc->poll_timer);
455 bt_bmc->base + BT_CR0);
457 clr_b_busy(bt_bmc);
464 struct bt_bmc *bt_bmc = dev_get_drvdata(&pdev->dev);
466 misc_deregister(&bt_bmc->miscdev);
467 if (bt_bmc->irq < 0)
468 del_timer_sync(&bt_bmc->poll_timer);