18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * MSDI IP block reset 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Texas Instruments, Inc. 68c2ecf20Sopenharmony_ci * Paul Walmsley 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * XXX What about pad muxing? 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/kernel.h> 128c2ecf20Sopenharmony_ci#include <linux/err.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "prm.h" 158c2ecf20Sopenharmony_ci#include "common.h" 168c2ecf20Sopenharmony_ci#include "control.h" 178c2ecf20Sopenharmony_ci#include "omap_hwmod.h" 188c2ecf20Sopenharmony_ci#include "omap_device.h" 198c2ecf20Sopenharmony_ci#include "mmc.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * MSDI_CON_OFFSET: offset in bytes of the MSDI IP block's CON register 238c2ecf20Sopenharmony_ci * from the IP block's base address 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci#define MSDI_CON_OFFSET 0x0c 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* Register bitfields in the CON register */ 288c2ecf20Sopenharmony_ci#define MSDI_CON_POW_MASK BIT(11) 298c2ecf20Sopenharmony_ci#define MSDI_CON_CLKD_MASK (0x3f << 0) 308c2ecf20Sopenharmony_ci#define MSDI_CON_CLKD_SHIFT 0 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* MSDI_TARGET_RESET_CLKD: clock divisor to use throughout the reset */ 338c2ecf20Sopenharmony_ci#define MSDI_TARGET_RESET_CLKD 0x3ff 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/** 368c2ecf20Sopenharmony_ci * omap_msdi_reset - reset the MSDI IP block 378c2ecf20Sopenharmony_ci * @oh: struct omap_hwmod * 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * The MSDI IP block on OMAP2420 has to have both the POW and CLKD 408c2ecf20Sopenharmony_ci * fields set inside its CON register for a reset to complete 418c2ecf20Sopenharmony_ci * successfully. This is not documented in the TRM. For CLKD, we use 428c2ecf20Sopenharmony_ci * the value that results in the lowest possible clock rate, to attempt 438c2ecf20Sopenharmony_ci * to avoid disturbing any cards. 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ciint omap_msdi_reset(struct omap_hwmod *oh) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci u16 v = 0; 488c2ecf20Sopenharmony_ci int c = 0; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* Write to the SOFTRESET bit */ 518c2ecf20Sopenharmony_ci omap_hwmod_softreset(oh); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci /* Enable the MSDI core and internal clock */ 548c2ecf20Sopenharmony_ci v |= MSDI_CON_POW_MASK; 558c2ecf20Sopenharmony_ci v |= MSDI_TARGET_RESET_CLKD << MSDI_CON_CLKD_SHIFT; 568c2ecf20Sopenharmony_ci omap_hwmod_write(v, oh, MSDI_CON_OFFSET); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci /* Poll on RESETDONE bit */ 598c2ecf20Sopenharmony_ci omap_test_timeout((omap_hwmod_read(oh, oh->class->sysc->syss_offs) 608c2ecf20Sopenharmony_ci & SYSS_RESETDONE_MASK), 618c2ecf20Sopenharmony_ci MAX_MODULE_SOFTRESET_WAIT, c); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci if (c == MAX_MODULE_SOFTRESET_WAIT) 648c2ecf20Sopenharmony_ci pr_warn("%s: %s: softreset failed (waited %d usec)\n", 658c2ecf20Sopenharmony_ci __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT); 668c2ecf20Sopenharmony_ci else 678c2ecf20Sopenharmony_ci pr_debug("%s: %s: softreset in %d usec\n", __func__, 688c2ecf20Sopenharmony_ci oh->name, c); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* Disable the MSDI internal clock */ 718c2ecf20Sopenharmony_ci v &= ~MSDI_CON_CLKD_MASK; 728c2ecf20Sopenharmony_ci omap_hwmod_write(v, oh, MSDI_CON_OFFSET); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci} 76