Root/target/linux/ubicom32/files/arch/ubicom32/mach-ip7k/board-ip7500av.c

1/*
2 * arch/ubicom32/mach-ip7k/board-ip7500av.c
3 * Support for IP7500 Audio Video Board + CPU module board.
4 *
5 * This file supports the IP7500 Audio Video Board:
6 * 8007-0810 Rev 1.0
7 * with one of the following CPU module boards:
8 * 8007-0510 Rev 1.0
9 * 8007-0510A Rev 1.0 (with ethernet)
10 *
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
15 * POS 4: unused
16 *
17 * (C) Copyright 2009, Ubicom, Inc.
18 *
19 * This file is part of the Ubicom32 Linux Kernel Port.
20 *
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.
25 *
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.
30 *
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/>.
34 */
35
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>
49
50/******************************************************************************
51 * Devices on the I2C bus
52 *
53 * BEWARE of changing the order of things in this array as we depend on
54 * certain things to be in certain places.
55 */
56static struct i2c_board_info __initdata ip7500av_i2c_board_info[] = {
57    /*
58     * U6, CS4384 DAC, address 0x19
59     */
60    {
61        .type = "cs4384",
62        .addr = 0x19,
63    },
64};
65
66/*
67 * I2C bus on the board, SDA PD1, SCL PD2
68 */
69static struct i2c_gpio_platform_data ip7500av_i2c_data = {
70    .sda_pin = GPIO_RD_6,
71    .scl_pin = GPIO_RD_3,
72    .sda_is_open_drain = 0,
73    .scl_is_open_drain = 0,
74    .udelay = 50,
75};
76
77static struct platform_device ip7500av_i2c_device = {
78    .name = "i2c-gpio",
79    .id = 0,
80    .dev = {
81        .platform_data = &ip7500av_i2c_data,
82    },
83};
84
85/*
86 * List of possible mclks we can generate. This depends on the CPU frequency.
87 */
88static struct ubi32_cs4384_mclk_entry ip7500av_cs4384_mclk_entries[] = {
89    {
90        .rate = 12288000,
91        .div = 44,
92    },
93    {
94        .rate = 11289600,
95        .div = 48,
96    },
97};
98
99/*
100 * List of all devices in our system
101 */
102static struct platform_device *ip7500av_devices[] __initdata = {
103    &ip7500av_i2c_device,
104};
105
106/*
107 * ip7500av_vdac_write
108 */
109static int __init ip7500av_vdac_write(int reg, int val)
110{
111    struct i2c_adapter *adap;
112    struct i2c_msg msg[1];
113    unsigned char data[2];
114    int err;
115
116    adap = i2c_get_adapter(0);
117    if (!adap) {
118        printk(KERN_WARNING "%s: failed to get i2c adapter\n", __FUNCTION__);
119        return -ENODEV;
120    }
121    msg->addr = 0x2B;
122    msg->flags = 0;
123    msg->len = 2;
124    msg->buf = data;
125    data[0] = reg;
126    data[1] = val;
127    err = i2c_transfer(adap, msg, 1);
128    i2c_put_adapter(adap);
129    if (err >= 0) {
130        return 0;
131    }
132    return err;
133}
134
135/*
136 * ip7500av_vdac_init
137 * Initializes the video DAC via I2C
138 *
139 * Equivalent mode line: 720x480p = 27 Mhz, 720 736 800 858 480 484 492 525
140 */
141static int __init ip7500av_vdac_init(void)
142{
143    int err;
144
145    printk(KERN_INFO "Initializing ADV7393 DAC\n");
146
147    /*
148     * Reset the VDAC
149     */
150    if (gpio_request(GPIO_RF_6, "VDAC Reset")) {
151        printk(KERN_WARNING "%s: failed to allocate VDAC Reset\n", __FUNCTION__);
152        return -EBUSY;
153    }
154    gpio_direction_output(GPIO_RF_6, 0);
155    udelay(1);
156    gpio_set_value(GPIO_RF_6, 1);
157
158    /*
159     * See table 100 of ADV7393 data sheet: 16-bit 525p YCrCb In, YPbPr Out
160     */
161    err = ip7500av_vdac_write(0x17, 0x02);
162    if (err) {
163        printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
164        return err;
165    }
166    err = ip7500av_vdac_write(0x00, 0x1c);
167    if (err) {
168        printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
169        return err;
170    }
171    err = ip7500av_vdac_write(0x01, 0x10);
172    if (err) {
173        printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
174        return err;
175    }
176    err = ip7500av_vdac_write(0x31, 0x01);
177    if (err) {
178        printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
179        return err;
180    }
181#ifdef IP7500AV_VDAC_SWAP_PBPR
182    err = ip7500av_vdac_write(0x35, 0x08);
183    if (err) {
184        printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
185        return err;
186    }
187#endif
188#ifdef IP7500AV_VDAC_FULL_RANGE
189    err = ip7500av_vdac_write(0x30, 0x02);
190    if (err) {
191        printk(KERN_WARNING "%s: failed to write VDAC\n", __FUNCTION__);
192        return err;
193    }
194#endif
195    return 0;
196}
197late_initcall(ip7500av_vdac_init);
198
199/*
200 * ip7500av_init
201 * Called to add the devices which we have on this board
202 */
203static int __init ip7500av_init(void)
204{
205    struct platform_device *audio_dev;
206    struct platform_device *audio_dev2;
207    struct ubi32_cs4384_platform_data *cs4384_pd;
208
209    board_init();
210
211    ubi_gpio_init();
212
213    vdc_tio_init();
214
215    printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
216    platform_add_devices(ip7500av_devices, ARRAY_SIZE(ip7500av_devices));
217
218    /*
219     * CS4384 DAC
220     */
221    audio_dev = audio_device_alloc("snd-ubi32-cs4384", "audio", "audio-i2sout",
222            sizeof(struct ubi32_cs4384_platform_data));
223    if (audio_dev) {
224        /*
225         * Attempt to figure out a good divisor. This will only work
226         * assuming the core frequency is compatible.
227         */
228        int i;
229        unsigned int freq = processor_frequency();
230        for (i = 0; i < ARRAY_SIZE(ip7500av_cs4384_mclk_entries); i++) {
231            unsigned int div;
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);
236        }
237
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;
243
244        /*
245         * Reset the DAC
246         */
247        if (gpio_request(GPIO_RF_4, "DAC Reset") == 0) {
248            gpio_direction_output(GPIO_RF_4, 0);
249            udelay(1);
250            gpio_direction_output(GPIO_RF_4, 1);
251        } else {
252            printk("Unable to request DAC reset GPIO\n");
253        }
254    }
255
256    /*
257     * SPDIF port
258     */
259    audio_dev2 = audio_device_alloc("snd-ubi32-generic", "audio", "audio-spdifout", 0);
260    if (audio_dev2) {
261        platform_device_register(audio_dev2);
262    }
263
264    /*
265     * Register all of the devices which sit on the I2C bus
266     */
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));
269
270    printk(KERN_INFO "IP7500 Audio/Video Board\n");
271    return 0;
272}
273arch_initcall(ip7500av_init);
274

Archive Download this file



interactive