Lines Matching refs:hdq_data
48 struct hdq_data { struct
62 static inline u8 hdq_reg_in(struct hdq_data *hdq_data, u32 offset) in hdq_reg_in() argument
64 return __raw_readl(hdq_data->hdq_base + offset); in hdq_reg_in()
67 static inline void hdq_reg_out(struct hdq_data *hdq_data, u32 offset, u8 val) in hdq_reg_out() argument
69 __raw_writel(val, hdq_data->hdq_base + offset); in hdq_reg_out()
72 static inline u8 hdq_reg_merge(struct hdq_data *hdq_data, u32 offset, in hdq_reg_merge() argument
75 u8 new_val = (__raw_readl(hdq_data->hdq_base + offset) & ~mask) in hdq_reg_merge()
77 __raw_writel(new_val, hdq_data->hdq_base + offset); in hdq_reg_merge()
88 static int hdq_wait_for_flag(struct hdq_data *hdq_data, u32 offset, in hdq_wait_for_flag() argument
96 while (((*status = hdq_reg_in(hdq_data, offset)) & flag) in hdq_wait_for_flag()
104 while (!((*status = hdq_reg_in(hdq_data, offset)) & flag) in hdq_wait_for_flag()
117 static u8 hdq_reset_irqstatus(struct hdq_data *hdq_data, u8 bits) in hdq_reset_irqstatus() argument
122 spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags); in hdq_reset_irqstatus()
123 status = hdq_data->hdq_irqstatus; in hdq_reset_irqstatus()
125 hdq_data->hdq_irqstatus &= ~bits; in hdq_reset_irqstatus()
126 spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags); in hdq_reset_irqstatus()
132 static int hdq_write_byte(struct hdq_data *hdq_data, u8 val, u8 *status) in hdq_write_byte() argument
137 ret = mutex_lock_interruptible(&hdq_data->hdq_mutex); in hdq_write_byte()
143 if (hdq_data->hdq_irqstatus) in hdq_write_byte()
144 dev_err(hdq_data->dev, "TX irqstatus not cleared (%02x)\n", in hdq_write_byte()
145 hdq_data->hdq_irqstatus); in hdq_write_byte()
149 hdq_reg_out(hdq_data, OMAP_HDQ_TX_DATA, val); in hdq_write_byte()
152 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, OMAP_HDQ_CTRL_STATUS_GO, in hdq_write_byte()
156 (hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_TXCOMPLETE), in hdq_write_byte()
158 *status = hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_TXCOMPLETE); in hdq_write_byte()
160 dev_dbg(hdq_data->dev, "TX wait elapsed\n"); in hdq_write_byte()
167 dev_dbg(hdq_data->dev, "timeout waiting for" in hdq_write_byte()
174 ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_CTRL_STATUS, in hdq_write_byte()
178 dev_dbg(hdq_data->dev, "timeout waiting GO bit" in hdq_write_byte()
183 mutex_unlock(&hdq_data->hdq_mutex); in hdq_write_byte()
191 struct hdq_data *hdq_data = _hdq; in hdq_isr() local
194 spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags); in hdq_isr()
195 hdq_data->hdq_irqstatus |= hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS); in hdq_isr()
196 spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags); in hdq_isr()
197 dev_dbg(hdq_data->dev, "hdq_isr: %x\n", hdq_data->hdq_irqstatus); in hdq_isr()
199 if (hdq_data->hdq_irqstatus & in hdq_isr()
232 static int omap_hdq_break(struct hdq_data *hdq_data) in omap_hdq_break() argument
237 ret = mutex_lock_interruptible(&hdq_data->hdq_mutex); in omap_hdq_break()
239 dev_dbg(hdq_data->dev, "Could not acquire mutex\n"); in omap_hdq_break()
244 if (hdq_data->hdq_irqstatus) in omap_hdq_break()
245 dev_err(hdq_data->dev, "break irqstatus not cleared (%02x)\n", in omap_hdq_break()
246 hdq_data->hdq_irqstatus); in omap_hdq_break()
249 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, in omap_hdq_break()
256 (hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_TIMEOUT), in omap_hdq_break()
258 tmp_status = hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_TIMEOUT); in omap_hdq_break()
260 dev_dbg(hdq_data->dev, "break wait elapsed\n"); in omap_hdq_break()
267 dev_dbg(hdq_data->dev, "timeout waiting for TIMEOUT, %x\n", in omap_hdq_break()
277 if (!(hdq_reg_in(hdq_data, OMAP_HDQ_CTRL_STATUS) & in omap_hdq_break()
279 dev_dbg(hdq_data->dev, "Presence bit not set\n"); in omap_hdq_break()
288 ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_CTRL_STATUS, in omap_hdq_break()
293 dev_dbg(hdq_data->dev, "timeout waiting INIT&GO bits" in omap_hdq_break()
297 mutex_unlock(&hdq_data->hdq_mutex); in omap_hdq_break()
302 static int hdq_read_byte(struct hdq_data *hdq_data, u8 *val) in hdq_read_byte() argument
307 ret = mutex_lock_interruptible(&hdq_data->hdq_mutex); in hdq_read_byte()
313 if (pm_runtime_suspended(hdq_data->dev)) { in hdq_read_byte()
318 if (!(hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_RXCOMPLETE)) { in hdq_read_byte()
319 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, in hdq_read_byte()
326 (hdq_data->hdq_irqstatus in hdq_read_byte()
330 status = hdq_reset_irqstatus(hdq_data, in hdq_read_byte()
333 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, 0, in hdq_read_byte()
338 dev_dbg(hdq_data->dev, "timeout waiting for" in hdq_read_byte()
344 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_RXCOMPLETE); in hdq_read_byte()
347 *val = hdq_reg_in(hdq_data, OMAP_HDQ_RX_DATA); in hdq_read_byte()
349 mutex_unlock(&hdq_data->hdq_mutex); in hdq_read_byte()
364 struct hdq_data *hdq_data = _hdq; in omap_w1_triplet() local
369 err = pm_runtime_get_sync(hdq_data->dev); in omap_w1_triplet()
371 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_triplet()
376 err = mutex_lock_interruptible(&hdq_data->hdq_mutex); in omap_w1_triplet()
378 dev_dbg(hdq_data->dev, "Could not acquire mutex\n"); in omap_w1_triplet()
386 (hdq_data->hdq_irqstatus in omap_w1_triplet()
390 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_RXCOMPLETE); in omap_w1_triplet()
393 dev_dbg(hdq_data->dev, "RX wait elapsed\n"); in omap_w1_triplet()
402 (hdq_data->hdq_irqstatus in omap_w1_triplet()
406 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_RXCOMPLETE); in omap_w1_triplet()
409 dev_dbg(hdq_data->dev, "RX wait elapsed\n"); in omap_w1_triplet()
431 (hdq_data->hdq_irqstatus in omap_w1_triplet()
435 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_TXCOMPLETE); in omap_w1_triplet()
438 dev_dbg(hdq_data->dev, "TX wait elapsed\n"); in omap_w1_triplet()
446 mutex_unlock(&hdq_data->hdq_mutex); in omap_w1_triplet()
448 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_triplet()
449 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_triplet()
457 struct hdq_data *hdq_data = _hdq; in omap_w1_reset_bus() local
460 err = pm_runtime_get_sync(hdq_data->dev); in omap_w1_reset_bus()
462 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_reset_bus()
467 omap_hdq_break(hdq_data); in omap_w1_reset_bus()
469 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_reset_bus()
470 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_reset_bus()
478 struct hdq_data *hdq_data = _hdq; in omap_w1_read_byte() local
482 ret = pm_runtime_get_sync(hdq_data->dev); in omap_w1_read_byte()
484 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_read_byte()
489 ret = hdq_read_byte(hdq_data, &val); in omap_w1_read_byte()
493 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_read_byte()
494 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_read_byte()
502 struct hdq_data *hdq_data = _hdq; in omap_w1_write_byte() local
506 ret = pm_runtime_get_sync(hdq_data->dev); in omap_w1_write_byte()
508 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_write_byte()
519 omap_hdq_break(hdq_data); in omap_w1_write_byte()
521 ret = hdq_write_byte(hdq_data, byte, &status); in omap_w1_write_byte()
523 dev_dbg(hdq_data->dev, "TX failure:Ctrl status %x\n", status); in omap_w1_write_byte()
528 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_write_byte()
529 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_write_byte()
540 struct hdq_data *hdq_data = dev_get_drvdata(dev); in omap_hdq_runtime_suspend() local
542 hdq_reg_out(hdq_data, 0, hdq_data->mode); in omap_hdq_runtime_suspend()
543 hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS); in omap_hdq_runtime_suspend()
550 struct hdq_data *hdq_data = dev_get_drvdata(dev); in omap_hdq_runtime_resume() local
553 hdq_reg_out(hdq_data, OMAP_HDQ_CTRL_STATUS, in omap_hdq_runtime_resume()
556 hdq_data->mode); in omap_hdq_runtime_resume()
557 hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS); in omap_hdq_runtime_resume()
570 struct hdq_data *hdq_data; in omap_hdq_probe() local
575 hdq_data = devm_kzalloc(dev, sizeof(*hdq_data), GFP_KERNEL); in omap_hdq_probe()
576 if (!hdq_data) in omap_hdq_probe()
579 hdq_data->dev = dev; in omap_hdq_probe()
580 platform_set_drvdata(pdev, hdq_data); in omap_hdq_probe()
582 hdq_data->hdq_base = devm_platform_ioremap_resource(pdev, 0); in omap_hdq_probe()
583 if (IS_ERR(hdq_data->hdq_base)) in omap_hdq_probe()
584 return PTR_ERR(hdq_data->hdq_base); in omap_hdq_probe()
586 mutex_init(&hdq_data->hdq_mutex); in omap_hdq_probe()
590 hdq_data->mode = 0; in omap_hdq_probe()
593 hdq_data->mode = 1; in omap_hdq_probe()
607 rev = hdq_reg_in(hdq_data, OMAP_HDQ_REVISION); in omap_hdq_probe()
611 spin_lock_init(&hdq_data->hdq_spinlock); in omap_hdq_probe()
620 ret = devm_request_irq(dev, irq, hdq_isr, 0, "omap_hdq", hdq_data); in omap_hdq_probe()
626 omap_hdq_break(hdq_data); in omap_hdq_probe()
631 omap_w1_master.data = hdq_data; in omap_hdq_probe()