blob: ab7bf181a1052feb452f26efe34ca2089a291398 [file] [log] [blame]
Paul Walmsley9e1b7492012-05-08 11:34:27 -06001/*
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
Paul Walmsley96b1b292012-06-21 21:40:38 -060025#include <linux/kernel.h>
26#include <linux/init.h>
27#include <linux/err.h>
28#include <linux/platform_device.h>
29
Tony Lindgren2a296c82012-10-02 17:41:35 -070030#include "omap_hwmod.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070031#include "omap_device.h"
Tony Lindgrena0b30ca2012-09-20 11:41:48 -070032#include "hdq1w.h"
Paul Walmsley9e1b7492012-05-08 11:34:27 -060033
Paul Walmsleyb13159a2012-10-29 20:57:44 -060034#include "prm.h"
Paul Walmsley9e1b7492012-05-08 11:34:27 -060035#include "common.h"
36
Paul Walmsley9e1b7492012-05-08 11:34:27 -060037/**
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 */
49int 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}
Paul Walmsley96b1b292012-06-21 21:40:38 -060077
78static 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}
96arch_initcall(omap_init_hdq);