Lines Matching refs:bt_bmc
59 struct bt_bmc { struct
78 static u8 bt_inb(struct bt_bmc *bt_bmc, int reg) in bt_inb() argument
83 rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val); in bt_inb()
89 static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg) in bt_outb() argument
93 rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data); in bt_outb()
97 static void clr_rd_ptr(struct bt_bmc *bt_bmc) in clr_rd_ptr() argument
99 bt_outb(bt_bmc, BT_CTRL_CLR_RD_PTR, BT_CTRL); in clr_rd_ptr()
102 static void clr_wr_ptr(struct bt_bmc *bt_bmc) in clr_wr_ptr() argument
104 bt_outb(bt_bmc, BT_CTRL_CLR_WR_PTR, BT_CTRL); in clr_wr_ptr()
107 static void clr_h2b_atn(struct bt_bmc *bt_bmc) in clr_h2b_atn() argument
109 bt_outb(bt_bmc, BT_CTRL_H2B_ATN, BT_CTRL); in clr_h2b_atn()
112 static void set_b_busy(struct bt_bmc *bt_bmc) in set_b_busy() argument
114 if (!(bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_B_BUSY)) in set_b_busy()
115 bt_outb(bt_bmc, BT_CTRL_B_BUSY, BT_CTRL); in set_b_busy()
118 static void clr_b_busy(struct bt_bmc *bt_bmc) in clr_b_busy() argument
120 if (bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_B_BUSY) in clr_b_busy()
121 bt_outb(bt_bmc, BT_CTRL_B_BUSY, BT_CTRL); in clr_b_busy()
124 static void set_b2h_atn(struct bt_bmc *bt_bmc) in set_b2h_atn() argument
126 bt_outb(bt_bmc, BT_CTRL_B2H_ATN, BT_CTRL); in set_b2h_atn()
129 static u8 bt_read(struct bt_bmc *bt_bmc) in bt_read() argument
131 return bt_inb(bt_bmc, BT_BMC2HOST); in bt_read()
134 static ssize_t bt_readn(struct bt_bmc *bt_bmc, u8 *buf, size_t n) in bt_readn() argument
139 buf[i] = bt_read(bt_bmc); in bt_readn()
143 static void bt_write(struct bt_bmc *bt_bmc, u8 c) in bt_write() argument
145 bt_outb(bt_bmc, c, BT_BMC2HOST); in bt_write()
148 static ssize_t bt_writen(struct bt_bmc *bt_bmc, u8 *buf, size_t n) in bt_writen() argument
153 bt_write(bt_bmc, buf[i]); in bt_writen()
157 static void set_sms_atn(struct bt_bmc *bt_bmc) in set_sms_atn() argument
159 bt_outb(bt_bmc, BT_CTRL_SMS_ATN, BT_CTRL); in set_sms_atn()
162 static struct bt_bmc *file_bt_bmc(struct file *file) in file_bt_bmc()
164 return container_of(file->private_data, struct bt_bmc, miscdev); in file_bt_bmc()
169 struct bt_bmc *bt_bmc = file_bt_bmc(file); in bt_bmc_open() local
172 clr_b_busy(bt_bmc); in bt_bmc_open()
196 struct bt_bmc *bt_bmc = file_bt_bmc(file); in bt_bmc_read() local
205 if (wait_event_interruptible(bt_bmc->queue, in bt_bmc_read()
206 bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_H2B_ATN)) in bt_bmc_read()
209 mutex_lock(&bt_bmc->mutex); in bt_bmc_read()
211 if (unlikely(!(bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_H2B_ATN))) { in bt_bmc_read()
216 set_b_busy(bt_bmc); in bt_bmc_read()
217 clr_h2b_atn(bt_bmc); in bt_bmc_read()
218 clr_rd_ptr(bt_bmc); in bt_bmc_read()
224 kbuffer[0] = bt_read(bt_bmc); in bt_bmc_read()
234 bt_readn(bt_bmc, kbuffer + len_byte, nread); in bt_bmc_read()
246 clr_b_busy(bt_bmc); in bt_bmc_read()
249 mutex_unlock(&bt_bmc->mutex); in bt_bmc_read()
262 struct bt_bmc *bt_bmc = file_bt_bmc(file); in bt_bmc_write() local
279 if (wait_event_interruptible(bt_bmc->queue, in bt_bmc_write()
280 !(bt_inb(bt_bmc, BT_CTRL) & in bt_bmc_write()
284 mutex_lock(&bt_bmc->mutex); in bt_bmc_write()
286 if (unlikely(bt_inb(bt_bmc, BT_CTRL) & in bt_bmc_write()
292 clr_wr_ptr(bt_bmc); in bt_bmc_write()
301 bt_writen(bt_bmc, kbuffer, nwritten); in bt_bmc_write()
308 set_b2h_atn(bt_bmc); in bt_bmc_write()
311 mutex_unlock(&bt_bmc->mutex); in bt_bmc_write()
318 struct bt_bmc *bt_bmc = file_bt_bmc(file); in bt_bmc_ioctl() local
322 set_sms_atn(bt_bmc); in bt_bmc_ioctl()
330 struct bt_bmc *bt_bmc = file_bt_bmc(file); in bt_bmc_release() local
333 set_b_busy(bt_bmc); in bt_bmc_release()
339 struct bt_bmc *bt_bmc = file_bt_bmc(file); in bt_bmc_poll() local
343 poll_wait(file, &bt_bmc->queue, wait); in bt_bmc_poll()
345 ctrl = bt_inb(bt_bmc, BT_CTRL); in bt_bmc_poll()
368 struct bt_bmc *bt_bmc = from_timer(bt_bmc, t, poll_timer); in poll_timer() local
370 bt_bmc->poll_timer.expires += msecs_to_jiffies(500); in poll_timer()
371 wake_up(&bt_bmc->queue); in poll_timer()
372 add_timer(&bt_bmc->poll_timer); in poll_timer()
377 struct bt_bmc *bt_bmc = arg; in bt_bmc_irq() local
381 rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, ®); in bt_bmc_irq()
390 regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg); in bt_bmc_irq()
392 wake_up(&bt_bmc->queue); in bt_bmc_irq()
396 static int bt_bmc_config_irq(struct bt_bmc *bt_bmc, in bt_bmc_config_irq() argument
402 bt_bmc->irq = platform_get_irq(pdev, 0); in bt_bmc_config_irq()
403 if (!bt_bmc->irq) in bt_bmc_config_irq()
406 rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED, in bt_bmc_config_irq()
407 DEVICE_NAME, bt_bmc); in bt_bmc_config_irq()
409 dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq); in bt_bmc_config_irq()
410 bt_bmc->irq = 0; in bt_bmc_config_irq()
420 rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1, in bt_bmc_config_irq()
429 struct bt_bmc *bt_bmc; in bt_bmc_probe() local
439 bt_bmc = devm_kzalloc(dev, sizeof(*bt_bmc), GFP_KERNEL); in bt_bmc_probe()
440 if (!bt_bmc) in bt_bmc_probe()
443 dev_set_drvdata(&pdev->dev, bt_bmc); in bt_bmc_probe()
445 bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node); in bt_bmc_probe()
446 if (IS_ERR(bt_bmc->map)) { in bt_bmc_probe()
459 bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg); in bt_bmc_probe()
460 bt_bmc->offset = 0; in bt_bmc_probe()
462 rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset); in bt_bmc_probe()
467 mutex_init(&bt_bmc->mutex); in bt_bmc_probe()
468 init_waitqueue_head(&bt_bmc->queue); in bt_bmc_probe()
470 bt_bmc->miscdev.minor = MISC_DYNAMIC_MINOR, in bt_bmc_probe()
471 bt_bmc->miscdev.name = DEVICE_NAME, in bt_bmc_probe()
472 bt_bmc->miscdev.fops = &bt_bmc_fops, in bt_bmc_probe()
473 bt_bmc->miscdev.parent = dev; in bt_bmc_probe()
474 rc = misc_register(&bt_bmc->miscdev); in bt_bmc_probe()
480 bt_bmc_config_irq(bt_bmc, pdev); in bt_bmc_probe()
482 if (bt_bmc->irq) { in bt_bmc_probe()
483 dev_info(dev, "Using IRQ %d\n", bt_bmc->irq); in bt_bmc_probe()
486 timer_setup(&bt_bmc->poll_timer, poll_timer, 0); in bt_bmc_probe()
487 bt_bmc->poll_timer.expires = jiffies + msecs_to_jiffies(10); in bt_bmc_probe()
488 add_timer(&bt_bmc->poll_timer); in bt_bmc_probe()
491 regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0, in bt_bmc_probe()
498 clr_b_busy(bt_bmc); in bt_bmc_probe()
505 struct bt_bmc *bt_bmc = dev_get_drvdata(&pdev->dev); in bt_bmc_remove() local
507 misc_deregister(&bt_bmc->miscdev); in bt_bmc_remove()
508 if (!bt_bmc->irq) in bt_bmc_remove()
509 del_timer_sync(&bt_bmc->poll_timer); in bt_bmc_remove()