18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * IP block integration code for the HDQ1W/1-wire IP block 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Texas Instruments, Inc. 68c2ecf20Sopenharmony_ci * Paul Walmsley 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Based on the I2C reset code in arch/arm/mach-omap2/i2c.c by 98c2ecf20Sopenharmony_ci * Avinash.H.M <avinashhm@ti.com> 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/kernel.h> 138c2ecf20Sopenharmony_ci#include <linux/init.h> 148c2ecf20Sopenharmony_ci#include <linux/err.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include "soc.h" 188c2ecf20Sopenharmony_ci#include "omap_hwmod.h" 198c2ecf20Sopenharmony_ci#include "omap_device.h" 208c2ecf20Sopenharmony_ci#include "hdq1w.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include "prm.h" 238c2ecf20Sopenharmony_ci#include "common.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/** 268c2ecf20Sopenharmony_ci * omap_hdq1w_reset - reset the OMAP HDQ1W module 278c2ecf20Sopenharmony_ci * @oh: struct omap_hwmod * 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * OCP soft reset the HDQ1W IP block. Section 20.6.1.4 "HDQ1W/1-Wire 308c2ecf20Sopenharmony_ci * Software Reset" of the OMAP34xx Technical Reference Manual Revision 318c2ecf20Sopenharmony_ci * ZR (SWPU223R) does not include the rather important fact that, for 328c2ecf20Sopenharmony_ci * the reset to succeed, the HDQ1W module's internal clock gate must be 338c2ecf20Sopenharmony_ci * programmed to allow the clock to propagate to the rest of the 348c2ecf20Sopenharmony_ci * module. In this sense, it's rather similar to the I2C custom reset 358c2ecf20Sopenharmony_ci * function. Returns 0. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ciint omap_hdq1w_reset(struct omap_hwmod *oh) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci u32 v; 408c2ecf20Sopenharmony_ci int c = 0; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci /* Write to the SOFTRESET bit */ 438c2ecf20Sopenharmony_ci omap_hwmod_softreset(oh); 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci /* Enable the module's internal clocks */ 468c2ecf20Sopenharmony_ci v = omap_hwmod_read(oh, HDQ_CTRL_STATUS_OFFSET); 478c2ecf20Sopenharmony_ci v |= 1 << HDQ_CTRL_STATUS_CLOCKENABLE_SHIFT; 488c2ecf20Sopenharmony_ci omap_hwmod_write(v, oh, HDQ_CTRL_STATUS_OFFSET); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* Poll on RESETDONE bit */ 518c2ecf20Sopenharmony_ci omap_test_timeout((omap_hwmod_read(oh, 528c2ecf20Sopenharmony_ci oh->class->sysc->syss_offs) 538c2ecf20Sopenharmony_ci & SYSS_RESETDONE_MASK), 548c2ecf20Sopenharmony_ci MAX_MODULE_SOFTRESET_WAIT, c); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci if (c == MAX_MODULE_SOFTRESET_WAIT) 578c2ecf20Sopenharmony_ci pr_warn("%s: %s: softreset failed (waited %d usec)\n", 588c2ecf20Sopenharmony_ci __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT); 598c2ecf20Sopenharmony_ci else 608c2ecf20Sopenharmony_ci pr_debug("%s: %s: softreset in %d usec\n", __func__, 618c2ecf20Sopenharmony_ci oh->name, c); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci return 0; 648c2ecf20Sopenharmony_ci} 65