Lines Matching refs:hdq_data
54 struct hdq_data { struct
68 static inline u8 hdq_reg_in(struct hdq_data *hdq_data, u32 offset) in hdq_reg_in() argument
70 return __raw_readl(hdq_data->hdq_base + offset); in hdq_reg_in()
73 static inline void hdq_reg_out(struct hdq_data *hdq_data, u32 offset, u8 val) in hdq_reg_out() argument
75 __raw_writel(val, hdq_data->hdq_base + offset); in hdq_reg_out()
78 static inline u8 hdq_reg_merge(struct hdq_data *hdq_data, u32 offset, in hdq_reg_merge() argument
81 u8 new_val = (__raw_readl(hdq_data->hdq_base + offset) & ~mask) in hdq_reg_merge()
83 __raw_writel(new_val, hdq_data->hdq_base + offset); in hdq_reg_merge()
94 static int hdq_wait_for_flag(struct hdq_data *hdq_data, u32 offset, in hdq_wait_for_flag() argument
102 while (((*status = hdq_reg_in(hdq_data, offset)) & flag) in hdq_wait_for_flag()
110 while (!((*status = hdq_reg_in(hdq_data, offset)) & flag) in hdq_wait_for_flag()
123 static u8 hdq_reset_irqstatus(struct hdq_data *hdq_data, u8 bits) in hdq_reset_irqstatus() argument
128 spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags); in hdq_reset_irqstatus()
129 status = hdq_data->hdq_irqstatus; in hdq_reset_irqstatus()
131 hdq_data->hdq_irqstatus &= ~bits; in hdq_reset_irqstatus()
132 spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags); in hdq_reset_irqstatus()
138 static int hdq_write_byte(struct hdq_data *hdq_data, u8 val, u8 *status) in hdq_write_byte() argument
143 ret = mutex_lock_interruptible(&hdq_data->hdq_mutex); in hdq_write_byte()
149 if (hdq_data->hdq_irqstatus) in hdq_write_byte()
150 dev_err(hdq_data->dev, "TX irqstatus not cleared (%02x)\n", in hdq_write_byte()
151 hdq_data->hdq_irqstatus); in hdq_write_byte()
155 hdq_reg_out(hdq_data, OMAP_HDQ_TX_DATA, val); in hdq_write_byte()
158 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, OMAP_HDQ_CTRL_STATUS_GO, in hdq_write_byte()
162 (hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_TXCOMPLETE), in hdq_write_byte()
164 *status = hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_TXCOMPLETE); in hdq_write_byte()
166 dev_dbg(hdq_data->dev, "TX wait elapsed\n"); in hdq_write_byte()
173 dev_dbg(hdq_data->dev, "timeout waiting for" in hdq_write_byte()
180 ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_CTRL_STATUS, in hdq_write_byte()
184 dev_dbg(hdq_data->dev, "timeout waiting GO bit" in hdq_write_byte()
189 mutex_unlock(&hdq_data->hdq_mutex); in hdq_write_byte()
197 struct hdq_data *hdq_data = _hdq; in hdq_isr() local
200 spin_lock_irqsave(&hdq_data->hdq_spinlock, irqflags); in hdq_isr()
201 hdq_data->hdq_irqstatus |= hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS); in hdq_isr()
202 spin_unlock_irqrestore(&hdq_data->hdq_spinlock, irqflags); in hdq_isr()
203 dev_dbg(hdq_data->dev, "hdq_isr: %x\n", hdq_data->hdq_irqstatus); in hdq_isr()
205 if (hdq_data->hdq_irqstatus & in hdq_isr()
238 static int omap_hdq_break(struct hdq_data *hdq_data) in omap_hdq_break() argument
243 ret = mutex_lock_interruptible(&hdq_data->hdq_mutex); in omap_hdq_break()
245 dev_dbg(hdq_data->dev, "Could not acquire mutex\n"); in omap_hdq_break()
250 if (hdq_data->hdq_irqstatus) in omap_hdq_break()
251 dev_err(hdq_data->dev, "break irqstatus not cleared (%02x)\n", in omap_hdq_break()
252 hdq_data->hdq_irqstatus); in omap_hdq_break()
255 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, in omap_hdq_break()
262 (hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_TIMEOUT), in omap_hdq_break()
264 tmp_status = hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_TIMEOUT); in omap_hdq_break()
266 dev_dbg(hdq_data->dev, "break wait elapsed\n"); in omap_hdq_break()
273 dev_dbg(hdq_data->dev, "timeout waiting for TIMEOUT, %x\n", in omap_hdq_break()
283 if (!(hdq_reg_in(hdq_data, OMAP_HDQ_CTRL_STATUS) & in omap_hdq_break()
285 dev_dbg(hdq_data->dev, "Presence bit not set\n"); in omap_hdq_break()
294 ret = hdq_wait_for_flag(hdq_data, OMAP_HDQ_CTRL_STATUS, in omap_hdq_break()
299 dev_dbg(hdq_data->dev, "timeout waiting INIT&GO bits" in omap_hdq_break()
303 mutex_unlock(&hdq_data->hdq_mutex); in omap_hdq_break()
308 static int hdq_read_byte(struct hdq_data *hdq_data, u8 *val) in hdq_read_byte() argument
313 ret = mutex_lock_interruptible(&hdq_data->hdq_mutex); in hdq_read_byte()
319 if (pm_runtime_suspended(hdq_data->dev)) { in hdq_read_byte()
324 if (!(hdq_data->hdq_irqstatus & OMAP_HDQ_INT_STATUS_RXCOMPLETE)) { in hdq_read_byte()
325 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, in hdq_read_byte()
332 (hdq_data->hdq_irqstatus in hdq_read_byte()
336 status = hdq_reset_irqstatus(hdq_data, in hdq_read_byte()
339 hdq_reg_merge(hdq_data, OMAP_HDQ_CTRL_STATUS, 0, in hdq_read_byte()
344 dev_dbg(hdq_data->dev, "timeout waiting for" in hdq_read_byte()
350 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_RXCOMPLETE); in hdq_read_byte()
353 *val = hdq_reg_in(hdq_data, OMAP_HDQ_RX_DATA); in hdq_read_byte()
355 mutex_unlock(&hdq_data->hdq_mutex); in hdq_read_byte()
370 struct hdq_data *hdq_data = _hdq; in omap_w1_triplet() local
375 err = pm_runtime_get_sync(hdq_data->dev); in omap_w1_triplet()
377 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_triplet()
382 err = mutex_lock_interruptible(&hdq_data->hdq_mutex); in omap_w1_triplet()
384 dev_dbg(hdq_data->dev, "Could not acquire mutex\n"); in omap_w1_triplet()
392 (hdq_data->hdq_irqstatus in omap_w1_triplet()
396 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_RXCOMPLETE); in omap_w1_triplet()
399 dev_dbg(hdq_data->dev, "RX wait elapsed\n"); in omap_w1_triplet()
408 (hdq_data->hdq_irqstatus in omap_w1_triplet()
412 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_RXCOMPLETE); in omap_w1_triplet()
415 dev_dbg(hdq_data->dev, "RX wait elapsed\n"); in omap_w1_triplet()
437 (hdq_data->hdq_irqstatus in omap_w1_triplet()
441 hdq_reset_irqstatus(hdq_data, OMAP_HDQ_INT_STATUS_TXCOMPLETE); in omap_w1_triplet()
444 dev_dbg(hdq_data->dev, "TX wait elapsed\n"); in omap_w1_triplet()
452 mutex_unlock(&hdq_data->hdq_mutex); in omap_w1_triplet()
454 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_triplet()
455 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_triplet()
463 struct hdq_data *hdq_data = _hdq; in omap_w1_reset_bus() local
466 err = pm_runtime_get_sync(hdq_data->dev); in omap_w1_reset_bus()
468 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_reset_bus()
473 omap_hdq_break(hdq_data); in omap_w1_reset_bus()
475 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_reset_bus()
476 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_reset_bus()
484 struct hdq_data *hdq_data = _hdq; in omap_w1_read_byte() local
488 ret = pm_runtime_get_sync(hdq_data->dev); in omap_w1_read_byte()
490 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_read_byte()
495 ret = hdq_read_byte(hdq_data, &val); in omap_w1_read_byte()
499 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_read_byte()
500 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_read_byte()
508 struct hdq_data *hdq_data = _hdq; in omap_w1_write_byte() local
512 ret = pm_runtime_get_sync(hdq_data->dev); in omap_w1_write_byte()
514 pm_runtime_put_noidle(hdq_data->dev); in omap_w1_write_byte()
525 omap_hdq_break(hdq_data); in omap_w1_write_byte()
527 ret = hdq_write_byte(hdq_data, byte, &status); in omap_w1_write_byte()
529 dev_dbg(hdq_data->dev, "TX failure:Ctrl status %x\n", status); in omap_w1_write_byte()
534 pm_runtime_mark_last_busy(hdq_data->dev); in omap_w1_write_byte()
535 pm_runtime_put_autosuspend(hdq_data->dev); in omap_w1_write_byte()
546 struct hdq_data *hdq_data = dev_get_drvdata(dev); in omap_hdq_runtime_suspend() local
548 hdq_reg_out(hdq_data, 0, hdq_data->mode); in omap_hdq_runtime_suspend()
549 hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS); in omap_hdq_runtime_suspend()
556 struct hdq_data *hdq_data = dev_get_drvdata(dev); in omap_hdq_runtime_resume() local
559 hdq_reg_out(hdq_data, OMAP_HDQ_CTRL_STATUS, in omap_hdq_runtime_resume()
562 hdq_data->mode); in omap_hdq_runtime_resume()
563 hdq_reg_in(hdq_data, OMAP_HDQ_INT_STATUS); in omap_hdq_runtime_resume()
576 struct hdq_data *hdq_data; in omap_hdq_probe() local
581 hdq_data = devm_kzalloc(dev, sizeof(*hdq_data), GFP_KERNEL); in omap_hdq_probe()
582 if (!hdq_data) { in omap_hdq_probe()
587 hdq_data->dev = dev; in omap_hdq_probe()
588 platform_set_drvdata(pdev, hdq_data); in omap_hdq_probe()
590 hdq_data->hdq_base = devm_platform_ioremap_resource(pdev, 0); in omap_hdq_probe()
591 if (IS_ERR(hdq_data->hdq_base)) in omap_hdq_probe()
592 return PTR_ERR(hdq_data->hdq_base); in omap_hdq_probe()
594 mutex_init(&hdq_data->hdq_mutex); in omap_hdq_probe()
598 hdq_data->mode = 0; in omap_hdq_probe()
601 hdq_data->mode = 1; in omap_hdq_probe()
615 rev = hdq_reg_in(hdq_data, OMAP_HDQ_REVISION); in omap_hdq_probe()
619 spin_lock_init(&hdq_data->hdq_spinlock); in omap_hdq_probe()
628 ret = devm_request_irq(dev, irq, hdq_isr, 0, "omap_hdq", hdq_data); in omap_hdq_probe()
634 omap_hdq_break(hdq_data); in omap_hdq_probe()
639 omap_w1_master.data = hdq_data; in omap_hdq_probe()