Merge branch 'for-rmk/perf' into for-rmk/virt/kvm/core
[deliverable/linux.git] / arch / arm / mach-omap2 / hdq1w.c
1 /*
2 * IP block integration code for the HDQ1W/1-wire IP block
3 *
4 * Copyright (C) 2012 Texas Instruments, Inc.
5 * Paul Walmsley
6 *
7 * Based on the I2C reset code in arch/arm/mach-omap2/i2c.c by
8 * Avinash.H.M <avinashhm@ti.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/err.h>
28 #include <linux/platform_device.h>
29
30 #include "omap_hwmod.h"
31 #include "omap_device.h"
32 #include "hdq1w.h"
33
34 #include "prm.h"
35 #include "common.h"
36
37 /**
38 * omap_hdq1w_reset - reset the OMAP HDQ1W module
39 * @oh: struct omap_hwmod *
40 *
41 * OCP soft reset the HDQ1W IP block. Section 20.6.1.4 "HDQ1W/1-Wire
42 * Software Reset" of the OMAP34xx Technical Reference Manual Revision
43 * ZR (SWPU223R) does not include the rather important fact that, for
44 * the reset to succeed, the HDQ1W module's internal clock gate must be
45 * programmed to allow the clock to propagate to the rest of the
46 * module. In this sense, it's rather similar to the I2C custom reset
47 * function. Returns 0.
48 */
49 int omap_hdq1w_reset(struct omap_hwmod *oh)
50 {
51 u32 v;
52 int c = 0;
53
54 /* Write to the SOFTRESET bit */
55 omap_hwmod_softreset(oh);
56
57 /* Enable the module's internal clocks */
58 v = omap_hwmod_read(oh, HDQ_CTRL_STATUS_OFFSET);
59 v |= 1 << HDQ_CTRL_STATUS_CLOCKENABLE_SHIFT;
60 omap_hwmod_write(v, oh, HDQ_CTRL_STATUS_OFFSET);
61
62 /* Poll on RESETDONE bit */
63 omap_test_timeout((omap_hwmod_read(oh,
64 oh->class->sysc->syss_offs)
65 & SYSS_RESETDONE_MASK),
66 MAX_MODULE_SOFTRESET_WAIT, c);
67
68 if (c == MAX_MODULE_SOFTRESET_WAIT)
69 pr_warning("%s: %s: softreset failed (waited %d usec)\n",
70 __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
71 else
72 pr_debug("%s: %s: softreset in %d usec\n", __func__,
73 oh->name, c);
74
75 return 0;
76 }
77
78 static int __init omap_init_hdq(void)
79 {
80 int id = -1;
81 struct platform_device *pdev;
82 struct omap_hwmod *oh;
83 char *oh_name = "hdq1w";
84 char *devname = "omap_hdq";
85
86 oh = omap_hwmod_lookup(oh_name);
87 if (!oh)
88 return 0;
89
90 pdev = omap_device_build(devname, id, oh, NULL, 0, NULL, 0, 0);
91 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
92 devname, oh->name);
93
94 return 0;
95 }
96 arch_initcall(omap_init_hdq);
This page took 0.035246 seconds and 5 git commands to generate.