11 #include <linux/kernel.h>
12 #include <linux/module.h>
15 #include <linux/slab.h>
18 #include <linux/sched.h>
22 #include "../w1_int.h"
24 #define MOD_NAME "OMAP_HDQ:"
26 #define OMAP_HDQ_REVISION 0x00
27 #define OMAP_HDQ_TX_DATA 0x04
28 #define OMAP_HDQ_RX_DATA 0x08
29 #define OMAP_HDQ_CTRL_STATUS 0x0c
30 #define OMAP_HDQ_CTRL_STATUS_INTERRUPTMASK (1<<6)
31 #define OMAP_HDQ_CTRL_STATUS_CLOCKENABLE (1<<5)
32 #define OMAP_HDQ_CTRL_STATUS_GO (1<<4)
33 #define OMAP_HDQ_CTRL_STATUS_INITIALIZATION (1<<2)
34 #define OMAP_HDQ_CTRL_STATUS_DIR (1<<1)
35 #define OMAP_HDQ_CTRL_STATUS_MODE (1<<0)
36 #define OMAP_HDQ_INT_STATUS 0x10
37 #define OMAP_HDQ_INT_STATUS_TXCOMPLETE (1<<2)
38 #define OMAP_HDQ_INT_STATUS_RXCOMPLETE (1<<1)
39 #define OMAP_HDQ_INT_STATUS_TIMEOUT (1<<0)
40 #define OMAP_HDQ_SYSCONFIG 0x14
41 #define OMAP_HDQ_SYSCONFIG_SOFTRESET (1<<1)
42 #define OMAP_HDQ_SYSCONFIG_AUTOIDLE (1<<0)
43 #define OMAP_HDQ_SYSSTATUS 0x18
44 #define OMAP_HDQ_SYSSTATUS_RESETDONE (1<<0)
46 #define OMAP_HDQ_FLAG_CLEAR 0
47 #define OMAP_HDQ_FLAG_SET 1
48 #define OMAP_HDQ_TIMEOUT (HZ/5)
50 #define OMAP_HDQ_MAX_USER 4
76 .probe = omap_hdq_probe,
83 static u8 omap_w1_read_byte(
void *_hdq);
84 static void omap_w1_write_byte(
void *_hdq,
u8 byte);
85 static u8 omap_w1_reset_bus(
void *_hdq);
86 static void omap_w1_search_bus(
void *_hdq,
struct w1_master *master_dev,
87 u8 search_type, w1_slave_found_callback slave_found);
90 static struct w1_bus_master omap_w1_master = {
91 .read_byte = omap_w1_read_byte,
92 .write_byte = omap_w1_write_byte,
93 .reset_bus = omap_w1_reset_bus,
94 .search = omap_w1_search_bus,
124 static int hdq_wait_for_flag(
struct hdq_data *hdq_data,
u32 offset,
132 while (((*status = hdq_reg_in(hdq_data, offset)) & flag)
140 while (!((*status = hdq_reg_in(hdq_data, offset)) & flag)
144 if (!(*status & flag))
153 static int hdq_write_byte(
struct hdq_data *hdq_data,
u8 val,
u8 *status)
157 unsigned long irqflags;
166 spin_unlock_irqrestore(&hdq_data->
hdq_spinlock, irqflags);
186 " TXCOMPLETE/RXCOMPLETE, %x", *status);
196 dev_dbg(hdq_data->
dev,
"timeout waiting GO bit"
197 " return to zero, %x", tmp_status);
207 struct hdq_data *hdq_data = _hdq;
208 unsigned long irqflags;
212 spin_unlock_irqrestore(&hdq_data->
hdq_spinlock, irqflags);
226 static u8 omap_w1_reset_bus(
void *_hdq)
232 static void omap_w1_search_bus(
void *_hdq,
struct w1_master *master_dev,
233 u8 search_type, w1_slave_found_callback slave_found)
248 id = (cs << 56) | module_id;
250 slave_found(master_dev,
id);
253 static int _omap_hdq_reset(
struct hdq_data *hdq_data)
273 dev_dbg(hdq_data->
dev,
"timeout waiting HDQ reset, %x",
287 static int omap_hdq_break(
struct hdq_data *hdq_data)
291 unsigned long irqflags;
295 dev_dbg(hdq_data->
dev,
"Could not acquire mutex\n");
305 spin_unlock_irqrestore(&hdq_data->
hdq_spinlock, irqflags);
317 dev_dbg(hdq_data->
dev,
"break wait elapsed\n");
325 dev_dbg(hdq_data->
dev,
"timeout waiting for TIMEOUT, %x",
339 dev_dbg(hdq_data->
dev,
"timeout waiting INIT&GO bits"
340 " return to zero, %x", tmp_status);
348 static int hdq_read_byte(
struct hdq_data *hdq_data,
u8 *val)
382 " RXCOMPLETE, %x", status);
397 static int omap_hdq_get(
struct hdq_data *hdq_data)
408 dev_dbg(hdq_data->
dev,
"attempt to exceed the max use count");
416 pm_runtime_get_sync(hdq_data->
dev);
421 ret = _omap_hdq_reset(hdq_data);
444 static int omap_hdq_put(
struct hdq_data *hdq_data)
453 dev_dbg(hdq_data->
dev,
"attempt to decrement use count"
460 pm_runtime_put_sync(hdq_data->
dev);
468 static u8 omap_w1_read_byte(
void *_hdq)
470 struct hdq_data *hdq_data = _hdq;
474 ret = hdq_read_byte(hdq_data, &val);
478 dev_dbg(hdq_data->
dev,
"Could not acquire mutex\n");
483 omap_hdq_put(hdq_data);
491 dev_dbg(hdq_data->
dev,
"Could not acquire mutex\n");
496 omap_hdq_put(hdq_data);
503 static void omap_w1_write_byte(
void *_hdq,
u8 byte)
505 struct hdq_data *hdq_data = _hdq;
511 omap_hdq_get(hdq_data);
515 dev_dbg(hdq_data->
dev,
"Could not acquire mutex\n");
521 ret = hdq_write_byte(hdq_data, byte, &status);
523 dev_dbg(hdq_data->
dev,
"TX failure:Ctrl status %x\n", status);
529 omap_hdq_put(hdq_data);
532 dev_dbg(hdq_data->
dev,
"Could not acquire mutex\n");
543 struct hdq_data *hdq_data;
550 dev_dbg(&pdev->
dev,
"unable to allocate memory\n");
555 platform_set_drvdata(pdev, hdq_data);
559 dev_dbg(&pdev->
dev,
"unable to get resource\n");
573 pm_runtime_get_sync(&pdev->
dev);
576 dev_info(&pdev->
dev,
"OMAP HDQ Hardware Rev %c.%c. Driver in %s mode\n",
577 (rev >> 4) +
'0', (rev & 0x0f) +
'0',
"Interrupt");
588 "omap_hdq", hdq_data);
590 dev_dbg(&pdev->
dev,
"could not request irq\n");
594 omap_hdq_break(hdq_data);
596 pm_runtime_put_sync(&pdev->
dev);
598 omap_w1_master.data = hdq_data;
602 dev_dbg(&pdev->
dev,
"Failure in registering w1 master\n");
609 pm_runtime_put_sync(&pdev->
dev);
611 pm_runtime_disable(&pdev->
dev);
618 struct hdq_data *hdq_data = platform_get_drvdata(pdev);
623 dev_dbg(&pdev->
dev,
"removed when use count is not zero\n");
631 pm_runtime_disable(&pdev->
dev);