18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Helper module for board specific I2C bus registration 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2009 Nokia Corporation. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "soc.h" 98c2ecf20Sopenharmony_ci#include "omap_hwmod.h" 108c2ecf20Sopenharmony_ci#include "omap_device.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include "prm.h" 138c2ecf20Sopenharmony_ci#include "common.h" 148c2ecf20Sopenharmony_ci#include "i2c.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* In register I2C_CON, Bit 15 is the I2C enable bit */ 178c2ecf20Sopenharmony_ci#define I2C_EN BIT(15) 188c2ecf20Sopenharmony_ci#define OMAP2_I2C_CON_OFFSET 0x24 198c2ecf20Sopenharmony_ci#define OMAP4_I2C_CON_OFFSET 0xA4 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define MAX_OMAP_I2C_HWMOD_NAME_LEN 16 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/** 248c2ecf20Sopenharmony_ci * omap_i2c_reset - reset the omap i2c module. 258c2ecf20Sopenharmony_ci * @oh: struct omap_hwmod * 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * The i2c moudle in omap2, omap3 had a special sequence to reset. The 288c2ecf20Sopenharmony_ci * sequence is: 298c2ecf20Sopenharmony_ci * - Disable the I2C. 308c2ecf20Sopenharmony_ci * - Write to SOFTRESET bit. 318c2ecf20Sopenharmony_ci * - Enable the I2C. 328c2ecf20Sopenharmony_ci * - Poll on the RESETDONE bit. 338c2ecf20Sopenharmony_ci * The sequence is implemented in below function. This is called for 2420, 348c2ecf20Sopenharmony_ci * 2430 and omap3. 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_ciint omap_i2c_reset(struct omap_hwmod *oh) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci u32 v; 398c2ecf20Sopenharmony_ci u16 i2c_con; 408c2ecf20Sopenharmony_ci int c = 0; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci if (soc_is_omap24xx() || soc_is_omap34xx() || soc_is_am35xx()) 438c2ecf20Sopenharmony_ci i2c_con = OMAP2_I2C_CON_OFFSET; 448c2ecf20Sopenharmony_ci else 458c2ecf20Sopenharmony_ci i2c_con = OMAP4_I2C_CON_OFFSET; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci /* Disable I2C */ 488c2ecf20Sopenharmony_ci v = omap_hwmod_read(oh, i2c_con); 498c2ecf20Sopenharmony_ci v &= ~I2C_EN; 508c2ecf20Sopenharmony_ci omap_hwmod_write(v, oh, i2c_con); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci /* Write to the SOFTRESET bit */ 538c2ecf20Sopenharmony_ci omap_hwmod_softreset(oh); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci /* Enable I2C */ 568c2ecf20Sopenharmony_ci v = omap_hwmod_read(oh, i2c_con); 578c2ecf20Sopenharmony_ci v |= I2C_EN; 588c2ecf20Sopenharmony_ci omap_hwmod_write(v, oh, i2c_con); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /* Poll on RESETDONE bit */ 618c2ecf20Sopenharmony_ci omap_test_timeout((omap_hwmod_read(oh, 628c2ecf20Sopenharmony_ci oh->class->sysc->syss_offs) 638c2ecf20Sopenharmony_ci & SYSS_RESETDONE_MASK), 648c2ecf20Sopenharmony_ci MAX_MODULE_SOFTRESET_WAIT, c); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci if (c == MAX_MODULE_SOFTRESET_WAIT) 678c2ecf20Sopenharmony_ci pr_warn("%s: %s: softreset failed (waited %d usec)\n", 688c2ecf20Sopenharmony_ci __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT); 698c2ecf20Sopenharmony_ci else 708c2ecf20Sopenharmony_ci pr_debug("%s: %s: softreset in %d usec\n", __func__, 718c2ecf20Sopenharmony_ci oh->name, c); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci return 0; 748c2ecf20Sopenharmony_ci} 75