Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Helper module for board specific I2C bus registration
0004  *
0005  * Copyright (C) 2009 Nokia Corporation.
0006  */
0007 
0008 #include "soc.h"
0009 #include "omap_hwmod.h"
0010 #include "omap_device.h"
0011 
0012 #include "prm.h"
0013 #include "common.h"
0014 #include "i2c.h"
0015 
0016 /* In register I2C_CON, Bit 15 is the I2C enable bit */
0017 #define I2C_EN                  BIT(15)
0018 #define OMAP2_I2C_CON_OFFSET            0x24
0019 #define OMAP4_I2C_CON_OFFSET            0xA4
0020 
0021 #define MAX_OMAP_I2C_HWMOD_NAME_LEN 16
0022 
0023 /**
0024  * omap_i2c_reset - reset the omap i2c module.
0025  * @oh: struct omap_hwmod *
0026  *
0027  * The i2c moudle in omap2, omap3 had a special sequence to reset. The
0028  * sequence is:
0029  * - Disable the I2C.
0030  * - Write to SOFTRESET bit.
0031  * - Enable the I2C.
0032  * - Poll on the RESETDONE bit.
0033  * The sequence is implemented in below function. This is called for 2420,
0034  * 2430 and omap3.
0035  */
0036 int omap_i2c_reset(struct omap_hwmod *oh)
0037 {
0038     u32 v;
0039     u16 i2c_con;
0040     int c = 0;
0041 
0042     if (soc_is_omap24xx() || soc_is_omap34xx() || soc_is_am35xx())
0043         i2c_con = OMAP2_I2C_CON_OFFSET;
0044     else
0045         i2c_con = OMAP4_I2C_CON_OFFSET;
0046 
0047     /* Disable I2C */
0048     v = omap_hwmod_read(oh, i2c_con);
0049     v &= ~I2C_EN;
0050     omap_hwmod_write(v, oh, i2c_con);
0051 
0052     /* Write to the SOFTRESET bit */
0053     omap_hwmod_softreset(oh);
0054 
0055     /* Enable I2C */
0056     v = omap_hwmod_read(oh, i2c_con);
0057     v |= I2C_EN;
0058     omap_hwmod_write(v, oh, i2c_con);
0059 
0060     /* Poll on RESETDONE bit */
0061     omap_test_timeout((omap_hwmod_read(oh,
0062                 oh->class->sysc->syss_offs)
0063                 & SYSS_RESETDONE_MASK),
0064                 MAX_MODULE_SOFTRESET_WAIT, c);
0065 
0066     if (c == MAX_MODULE_SOFTRESET_WAIT)
0067         pr_warn("%s: %s: softreset failed (waited %d usec)\n",
0068             __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
0069     else
0070         pr_debug("%s: %s: softreset in %d usec\n", __func__,
0071             oh->name, c);
0072 
0073     return 0;
0074 }