Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1949244
  • 博文数量: 185
  • 博客积分: 10707
  • 博客等级: 上将
  • 技术积分: 1777
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-19 17:31
文章分类

全部博文(185)

文章存档

2014年(1)

2012年(6)

2011年(27)

2010年(13)

2009年(75)

2008年(63)

分类: LINUX

2008-12-21 13:24:01

--------------------------------------------
本文系本站原创,欢迎转载!
转载请注明出处:http://zhiqiang0071.cublog.cn
--------------------------------------------

针对serial.c的硬件手册是SPRUE33A.pdf,可到TI的网站()上下载,或直接在谷歌里搜索。
以下是文件
serial.c的浅析。

/*
 * linux/arch/arm/mach-davinci/serial.c
 *
 * TI DaVinci serial driver hookup file
 *
 * Copyright (C) 2006 Texas Instruments.
 *
 * ----------------------------------------------------------------------------
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * ----------------------------------------------------------------------------
 *
 */


#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/serial_8250.h>
#include <linux/serial_reg.h>
#include <linux/delay.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/hardware.h>
#include <asm/hardware/clock.h>
#include <asm/serial.h>
#include <asm/arch/hardware.h>
#include <asm/arch/irqs.h>
#include <asm/arch/cpu.h>

#define UART_DAVINCI_PWREMU 0x0c

/*
 对于DM644x平台来说,该文件的作用只是打开串口0模块的时钟和电源。
 DM644x平台的串口采用的是TL16C550工业标准异步通信模块。内核中已经包含
 该标准((8250/16550))串口的驱动的代码:drivers/serial/8250.c。

*/


// 从串口寄存器offset读出值

static inline unsigned int davinci_serial_in(struct plat_serial8250_port *up,
                     int offset)
{
    offset <<= up->regshift;
    return (unsigned int)__raw_readb(up->membase + offset);
}

// 向串口寄存器offset写入值value

static inline void davinci_serial_outp(struct plat_serial8250_port *p,
                 int offset, int value)
{
    offset <<= p->regshift;
    __raw_writeb(value, p->membase + offset);
}

// 复位串口。UART_DAVINCI_PWREMU寄存器是达芬奇平台专有的,通用的8250串口没有。

static void __init davinci_serial_reset(struct plat_serial8250_port *p)
{
    /* reset both transmitter and receiver: bits 14,13 = UTRST, URRST */
    unsigned int pwremu = 0;

    davinci_serial_outp(p, UART_IER, 0);    /* disable all interrupts */

    davinci_serial_outp(p, UART_DAVINCI_PWREMU, pwremu);// 禁止发送和接收,停止UART

    mdelay(10);

    pwremu |= (0x3 << 13);
    pwremu |= 0x1;
    // 打开接收和发送,启动UART

    davinci_serial_outp(p, UART_DAVINCI_PWREMU, pwremu);
}

#define UART_DM6467_SCR        __REG(DAVINCI_UART0_BASE + 0x40)
/*
 * Internal UARTs need to be initialized for the 8250 autoconfig to work
 * properly. Note that the TX watermark initialization may not be needed
 * once the 8250.c watermark handling code is merged.
 */

static int __init dm646x_serial_reset(void)
{
    UART_DM6467_SCR = 0x08;

    return 0;
}

/*
 串口初始化,打开时钟和电源。
 davinci_serial_init()例程由board_evm.c中的board_init()例程调用,后者被
 davinci_map_io()例程调用,而其又被注册到board_evm.c中的机器描述符中(struct machine_desc),
 故具体调用过程是:
 start_kernel()-->setup_arch()-->paging_init()-->mdesc->map_io()
 (其就是davinci_map_io())-->board_init()-->davinci_serial_init()。
 
*/

void __init davinci_serial_init(struct platform_device *pdev)
{
    struct clk *uart_clk;
    struct device *dev = &pdev->dev;
    struct plat_serial8250_port *p;
    int uart;
    char uart_name[6];

    memset(uart_name, 0, sizeof(uart_name));
    for (p = dev->platform_data; p && p->flags; p++) {
        switch (p->mapbase) {// 获取串口号

        case DAVINCI_UART0_BASE:
            uart = 0;
            break;
        case DAVINCI_UART1_BASE:
            uart = 1;
            break;
        case DM644X_UART2_BASE:
        case DM355_UART2_BASE:
            uart = 2;
            break;
        default:
            dev_err(dev,
                "Unknown UART base address 0x%08lx\n",
                p->mapbase);
            continue;
        }
        sprintf(uart_name, "UART%i", uart);
        uart_clk = clk_get(dev, uart_name);// 获取时钟

        if (IS_ERR(uart_clk))
            dev_err(dev, "failed to get %s clock\n", uart_name);
        else
            clk_enable(uart_clk);    // 打开时钟和电源

        // 如果是DM355平台,则复位

        if (cpu_is_davinci_dm355())
            davinci_serial_reset(p);
    }
}

late_initcall(dm646x_serial_reset);

阅读(2761) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~