2 * arch/ubicom32/mach-ip7k/board-ip7500av.c
3 * Support for IP7500 Audio Video Board + CPU module board.
5 * This file supports the IP7500 Audio Video Board:
7 * with one of the following CPU module boards:
9 * 8007-0510A Rev 1.0 (with ethernet)
11 * DIP Switch SW2 configuration: (*) default
12 * POS 1: on(*) = PCI enabled, off = PCI disabled
13 * POS 2: on(*) = TTYX => PA6, off = TTYX => PF12
14 * POS 3: on(*) = TTYY => PA7, off = TTYY => PF15
17 * (C) Copyright 2009, Ubicom, Inc.
19 * This file is part of the Ubicom32 Linux Kernel Port.
21 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
22 * it and/or modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation, either version 2 of the
24 * License, or (at your option) any later version.
26 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
27 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
28 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
29 * the GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with the Ubicom32 Linux Kernel Port. If not,
33 * see <http://www.gnu.org/licenses/>.
36 #include <linux/platform_device.h>
37 #include <linux/device.h>
38 #include <linux/gpio.h>
39 #include <linux/i2c.h>
40 #include <linux/i2c-gpio.h>
41 #include <linux/delay.h>
42 #include <asm/board.h>
43 #include <asm/machdep.h>
44 #include <asm/ring_tio.h>
45 #include <asm/vdc_tio.h>
46 #include <asm/audio.h>
47 #include <asm/ubi32-pcm.h>
48 #include <asm/ubi32-cs4384.h>
50 /******************************************************************************
51 * Devices on the I2C bus
53 * BEWARE of changing the order of things in this array as we depend on
54 * certain things to be in certain places.
56 static struct i2c_board_info __initdata ip7500av_i2c_board_info[] = {
58 * U6, CS4384 DAC, address 0x19
67 * I2C bus on the board, SDA PD1, SCL PD2
69 static struct i2c_gpio_platform_data ip7500av_i2c_data = {
72 .sda_is_open_drain = 0,
73 .scl_is_open_drain = 0,
77 static struct platform_device ip7500av_i2c_device = {
81 .platform_data = &ip7500av_i2c_data,
86 * List of possible mclks we can generate. This depends on the CPU frequency.
88 static struct ubi32_cs4384_mclk_entry ip7500av_cs4384_mclk_entries[] = {
100 * List of all devices in our system
102 static struct platform_device *ip7500av_devices[] __initdata = {
103 &ip7500av_i2c_device,
107 * ip7500av_vdac_write
109 static int __init ip7500av_vdac_write(int reg, int val)
111 struct i2c_adapter *adap;
112 struct i2c_msg msg[1];
113 unsigned char data[2];
116 adap = i2c_get_adapter(0);
118 printk(KERN_WARNING "%s: failed to get i2c adapter\n", __FUNCTION__);
127 err = i2c_transfer(adap, msg, 1);
128 i2c_put_adapter(adap);
137 * Initializes the video DAC via I2C
139 * Equivalent mode line: 720x480p = 27 Mhz, 720 736 800 858 480 484 492 525
141 static int __init ip7500av_vdac_init(void)
145 printk(KERN_INFO "Initializing ADV7393 DAC\n");
150 if (gpio_request(GPIO_RF_6, "VDAC Reset")) {
151 printk(KERN_WARNING "%s: failed to allocate VDAC Reset\n", __FUNCTION__);
154 gpio_direction_output(GPIO_RF_6, 0);
156 gpio_set_value(GPIO_RF_6, 1);
159 * See table 100 of ADV7393 data sheet: 16-bit 525p YCrCb In, YPbPr Out
161 err = ip7500av_vdac_write(0x17, 0x02);
163 printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
166 err = ip7500av_vdac_write(0x00, 0x1c);
168 printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
171 err = ip7500av_vdac_write(0x01, 0x10);
173 printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
176 err = ip7500av_vdac_write(0x31, 0x01);
178 printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
181 #ifdef IP7500AV_VDAC_SWAP_PBPR
182 err = ip7500av_vdac_write(0x35, 0x08);
184 printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
188 #ifdef IP7500AV_VDAC_FULL_RANGE
189 err = ip7500av_vdac_write(0x30, 0x02);
191 printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
197 late_initcall(ip7500av_vdac_init);
201 * Called to add the devices which we have on this board
203 static int __init ip7500av_init(void)
205 struct platform_device *audio_dev;
206 struct platform_device *audio_dev2;
207 struct ubi32_cs4384_platform_data *cs4384_pd;
215 printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
216 platform_add_devices(ip7500av_devices, ARRAY_SIZE(ip7500av_devices));
221 audio_dev = audio_device_alloc("snd-ubi32-cs4384", "audio", "audio-i2sout",
222 sizeof(struct ubi32_cs4384_platform_data));
225 * Attempt to figure out a good divisor. This will only work
226 * assuming the core frequency is compatible.
229 unsigned int freq = processor_frequency();
230 for (i = 0; i < ARRAY_SIZE(ip7500av_cs4384_mclk_entries); i++) {
232 unsigned int rate = ip7500av_cs4384_mclk_entries[i].rate / 1000;
233 div = ((freq / rate) + 500) / 1000;
234 ip7500av_cs4384_mclk_entries[i].div = div;
235 printk("CS4384 mclk %d rate %u000Hz div %u act %u\n", i, rate, div, freq / div);
238 cs4384_pd = audio_device_priv(audio_dev);
239 cs4384_pd->mclk_src = UBI32_CS4384_MCLK_PWM_0;
240 cs4384_pd->n_mclk = ARRAY_SIZE(ip7500av_cs4384_mclk_entries);
241 cs4384_pd->mclk_entries = ip7500av_cs4384_mclk_entries;
242 ip7500av_i2c_board_info[0].platform_data = audio_dev;
247 if (gpio_request(GPIO_RF_4, "DAC Reset") == 0) {
248 gpio_direction_output(GPIO_RF_4, 0);
250 gpio_direction_output(GPIO_RF_4, 1);
252 printk("Unable to request DAC reset GPIO\n");
259 audio_dev2 = audio_device_alloc("snd-ubi32-generic", "audio", "audio-spdifout", 0);
261 platform_device_register(audio_dev2);
265 * Register all of the devices which sit on the I2C bus
267 printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
268 i2c_register_board_info(0, ip7500av_i2c_board_info, ARRAY_SIZE(ip7500av_i2c_board_info));
270 printk(KERN_INFO "IP7500 Audio/Video Board\n");
273 arch_initcall(ip7500av_init);