Linux Audio

Check our new training course

Loading...
v3.15
 
 1/*
 2 * Helper module for board specific I2C bus registration
 3 *
 4 * Copyright (C) 2009 Nokia Corporation.
 5 *
 6 * This program is free software; you can redistribute it and/or
 7 * modify it under the terms of the GNU General Public License
 8 * version 2 as published by the Free Software Foundation.
 9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/i2c-omap.h>
23#include <mach/mux.h>
24#include "soc.h"
25
26#include <plat/i2c.h>
 
 
27
28#define OMAP_I2C_SIZE		0x3f
29#define OMAP1_I2C_BASE		0xfffb3800
30#define OMAP1_INT_I2C		(32 + 4)
31
32static const char name[] = "omap_i2c";
33
34static struct resource i2c_resources[2] = {
35};
36
37static struct platform_device omap_i2c_devices[1] = {
38};
39
40static void __init omap1_i2c_mux_pins(int bus_id)
41{
42	if (cpu_is_omap7xx()) {
43		omap_cfg_reg(I2C_7XX_SDA);
44		omap_cfg_reg(I2C_7XX_SCL);
45	} else {
46		omap_cfg_reg(I2C_SDA);
47		omap_cfg_reg(I2C_SCL);
48	}
49}
50
51int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *pdata,
52				int bus_id)
53{
54	struct platform_device *pdev;
55	struct resource *res;
56
57	if (bus_id > 1)
58		return -EINVAL;
59
60	omap1_i2c_mux_pins(bus_id);
61
62	pdev = &omap_i2c_devices[bus_id - 1];
63	pdev->id = bus_id;
64	pdev->name = name;
65	pdev->num_resources = ARRAY_SIZE(i2c_resources);
66	res = i2c_resources;
67	res[0].start = OMAP1_I2C_BASE;
68	res[0].end = res[0].start + OMAP_I2C_SIZE;
69	res[0].flags = IORESOURCE_MEM;
70	res[1].start = OMAP1_INT_I2C;
71	res[1].flags = IORESOURCE_IRQ;
72	pdev->resource = res;
73
74	/* all OMAP1 have IP version 1 register set */
75	pdata->rev = OMAP_I2C_IP_VERSION_1;
76
77	/* all OMAP1 I2C are implemented like this */
78	pdata->flags = OMAP_I2C_FLAG_NO_FIFO |
79		       OMAP_I2C_FLAG_SIMPLE_CLOCK |
80		       OMAP_I2C_FLAG_16BIT_DATA_REG |
81		       OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK;
82
83	/* how the cpu bus is wired up differs for 7xx only */
84
85	if (cpu_is_omap7xx())
86		pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_1;
87	else
88		pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2;
89
90	pdev->dev.platform_data = pdata;
91
92	return platform_device_register(pdev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93}
94
95static  int __init omap_i2c_cmdline(void)
96{
97	return omap_register_i2c_bus_cmdline();
98}
99subsys_initcall(omap_i2c_cmdline);
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Helper module for board specific I2C bus registration
  4 *
  5 * Copyright (C) 2009 Nokia Corporation.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include <linux/i2c.h>
  9#include <linux/platform_data/i2c-omap.h>
 
 10
 11#include "mux.h"
 12#include "soc.h"
 13#include "i2c.h"
 14
 15#define OMAP_I2C_SIZE		0x3f
 16#define OMAP1_I2C_BASE		0xfffb3800
 
 17
 18static const char name[] = "omap_i2c";
 19
 20static struct resource i2c_resources[2] = {
 21};
 22
 23static struct platform_device omap_i2c_devices[1] = {
 24};
 25
 26static void __init omap1_i2c_mux_pins(int bus_id)
 27{
 28	omap_cfg_reg(I2C_SDA);
 29	omap_cfg_reg(I2C_SCL);
 
 
 
 
 
 30}
 31
 32int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *pdata,
 33				int bus_id)
 34{
 35	struct platform_device *pdev;
 36	struct resource *res;
 37
 38	if (bus_id > 1)
 39		return -EINVAL;
 40
 41	omap1_i2c_mux_pins(bus_id);
 42
 43	pdev = &omap_i2c_devices[bus_id - 1];
 44	pdev->id = bus_id;
 45	pdev->name = name;
 46	pdev->num_resources = ARRAY_SIZE(i2c_resources);
 47	res = i2c_resources;
 48	res[0].start = OMAP1_I2C_BASE;
 49	res[0].end = res[0].start + OMAP_I2C_SIZE;
 50	res[0].flags = IORESOURCE_MEM;
 51	res[1].start = INT_I2C;
 52	res[1].flags = IORESOURCE_IRQ;
 53	pdev->resource = res;
 54
 55	/* all OMAP1 have IP version 1 register set */
 56	pdata->rev = OMAP_I2C_IP_VERSION_1;
 57
 58	/* all OMAP1 I2C are implemented like this */
 59	pdata->flags = OMAP_I2C_FLAG_NO_FIFO |
 60		       OMAP_I2C_FLAG_SIMPLE_CLOCK |
 61		       OMAP_I2C_FLAG_16BIT_DATA_REG |
 62		       OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK;
 63
 64	/* how the cpu bus is wired up differs for 7xx only */
 65
 66	pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2;
 
 
 
 67
 68	pdev->dev.platform_data = pdata;
 69
 70	return platform_device_register(pdev);
 71}
 72
 73#define OMAP_I2C_MAX_CONTROLLERS 4
 74static struct omap_i2c_bus_platform_data i2c_pdata[OMAP_I2C_MAX_CONTROLLERS];
 75
 76#define OMAP_I2C_CMDLINE_SETUP	(BIT(31))
 77
 78/**
 79 * omap_i2c_bus_setup - Process command line options for the I2C bus speed
 80 * @str: String of options
 81 *
 82 * This function allow to override the default I2C bus speed for given I2C
 83 * bus with a command line option.
 84 *
 85 * Format: i2c_bus=bus_id,clkrate (in kHz)
 86 *
 87 * Returns 1 on success, 0 otherwise.
 88 */
 89static int __init omap_i2c_bus_setup(char *str)
 90{
 91	int ints[3];
 92
 93	get_options(str, 3, ints);
 94	if (ints[0] < 2 || ints[1] < 1 ||
 95			ints[1] > OMAP_I2C_MAX_CONTROLLERS)
 96		return 0;
 97	i2c_pdata[ints[1] - 1].clkrate = ints[2];
 98	i2c_pdata[ints[1] - 1].clkrate |= OMAP_I2C_CMDLINE_SETUP;
 99
100	return 1;
101}
102__setup("i2c_bus=", omap_i2c_bus_setup);
103
104/*
105 * Register busses defined in command line but that are not registered with
106 * omap_register_i2c_bus from board initialization code.
107 */
108int __init omap_register_i2c_bus_cmdline(void)
109{
110	int i, err = 0;
111
112	for (i = 0; i < ARRAY_SIZE(i2c_pdata); i++)
113		if (i2c_pdata[i].clkrate & OMAP_I2C_CMDLINE_SETUP) {
114			i2c_pdata[i].clkrate &= ~OMAP_I2C_CMDLINE_SETUP;
115			err = omap_i2c_add_bus(&i2c_pdata[i], i + 1);
116			if (err)
117				goto out;
118		}
119
120out:
121	return err;
122}
123
124/**
125 * omap_register_i2c_bus - register I2C bus with device descriptors
126 * @bus_id: bus id counting from number 1
127 * @clkrate: clock rate of the bus in kHz
128 * @info: pointer into I2C device descriptor table or NULL
129 * @len: number of descriptors in the table
130 *
131 * Returns 0 on success or an error code.
132 */
133int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
134			  struct i2c_board_info const *info,
135			  unsigned len)
136{
137	int err;
138
139	BUG_ON(bus_id < 1 || bus_id > OMAP_I2C_MAX_CONTROLLERS);
140
141	if (info) {
142		err = i2c_register_board_info(bus_id, info, len);
143		if (err)
144			return err;
145	}
146
147	if (!i2c_pdata[bus_id - 1].clkrate)
148		i2c_pdata[bus_id - 1].clkrate = clkrate;
149
150	i2c_pdata[bus_id - 1].clkrate &= ~OMAP_I2C_CMDLINE_SETUP;
151
152	return omap_i2c_add_bus(&i2c_pdata[bus_id - 1], bus_id);
153}
154
155static  int __init omap_i2c_cmdline(void)
156{
157	return omap_register_i2c_bus_cmdline();
158}
159subsys_initcall(omap_i2c_cmdline);