blob: 3b4b9514f4fa0c0ac01f5cf5ccedc1496d06dd27 [file] [log] [blame]
Thomas Gleixner2b27bdc2019-05-29 16:57:50 -07001// SPDX-License-Identifier: GPL-2.0-only
Tony Lindgrenb63128e2009-12-11 16:16:32 -08002/*
3 * Helper module for board specific I2C bus registration
4 *
5 * Copyright (C) 2009 Nokia Corporation.
Tony Lindgrenb63128e2009-12-11 16:16:32 -08006 */
7
Tony Lindgrene4c060d2012-10-05 13:25:59 -07008#include "soc.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -07009#include "omap_hwmod.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070010#include "omap_device.h"
Tony Lindgrenb63128e2009-12-11 16:16:32 -080011
Paul Walmsleyb13159a2012-10-29 20:57:44 -060012#include "prm.h"
13#include "common.h"
Tony Lindgren3a8761c2012-10-08 09:11:22 -070014#include "i2c.h"
Tony Lindgrenb63128e2009-12-11 16:16:32 -080015
Avinash.H.M6d3c55f2011-07-10 05:27:16 -060016/* In register I2C_CON, Bit 15 is the I2C enable bit */
17#define I2C_EN BIT(15)
18#define OMAP2_I2C_CON_OFFSET 0x24
19#define OMAP4_I2C_CON_OFFSET 0xA4
20
Tony Lindgren3a8761c2012-10-08 09:11:22 -070021#define MAX_OMAP_I2C_HWMOD_NAME_LEN 16
22
Avinash.H.M6d3c55f2011-07-10 05:27:16 -060023/**
24 * omap_i2c_reset - reset the omap i2c module.
25 * @oh: struct omap_hwmod *
26 *
27 * The i2c moudle in omap2, omap3 had a special sequence to reset. The
28 * sequence is:
29 * - Disable the I2C.
30 * - Write to SOFTRESET bit.
31 * - Enable the I2C.
32 * - Poll on the RESETDONE bit.
33 * The sequence is implemented in below function. This is called for 2420,
34 * 2430 and omap3.
35 */
36int omap_i2c_reset(struct omap_hwmod *oh)
37{
38 u32 v;
39 u16 i2c_con;
40 int c = 0;
41
Tony Lindgren70451122019-03-21 11:00:21 -070042 if (soc_is_omap24xx() || soc_is_omap34xx() || soc_is_am35xx())
Avinash.H.M6d3c55f2011-07-10 05:27:16 -060043 i2c_con = OMAP2_I2C_CON_OFFSET;
Tony Lindgren70451122019-03-21 11:00:21 -070044 else
45 i2c_con = OMAP4_I2C_CON_OFFSET;
Avinash.H.M6d3c55f2011-07-10 05:27:16 -060046
47 /* Disable I2C */
48 v = omap_hwmod_read(oh, i2c_con);
49 v &= ~I2C_EN;
50 omap_hwmod_write(v, oh, i2c_con);
51
52 /* Write to the SOFTRESET bit */
53 omap_hwmod_softreset(oh);
54
55 /* Enable I2C */
56 v = omap_hwmod_read(oh, i2c_con);
57 v |= I2C_EN;
58 omap_hwmod_write(v, oh, i2c_con);
59
60 /* Poll on RESETDONE bit */
61 omap_test_timeout((omap_hwmod_read(oh,
62 oh->class->sysc->syss_offs)
63 & SYSS_RESETDONE_MASK),
64 MAX_MODULE_SOFTRESET_WAIT, c);
65
66 if (c == MAX_MODULE_SOFTRESET_WAIT)
Joe Perches3d0cb732014-09-13 11:31:16 -070067 pr_warn("%s: %s: softreset failed (waited %d usec)\n",
Avinash.H.M6d3c55f2011-07-10 05:27:16 -060068 __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
69 else
70 pr_debug("%s: %s: softreset in %d usec\n", __func__,
71 oh->name, c);
72
73 return 0;
74}