天嵌 ARM开发社区

 找回密码
 注册
查看: 2478|回复: 3

tq2440 ide硬盘的问题

[复制链接]
kelly 发表于 2012-10-24 16:51:26 | 显示全部楼层 |阅读模式
由于我们需要进行数据存储,所以给tq2440加了ide硬盘,并进行了驱动移植。

内核是2.6.30.4,修改了ide-generic.c如下:
  1. /*
  2. * generic/default IDE host driver
  3. *
  4. * Copyright (C) 2004, 2008-2009 Bartlomiej Zolnierkiewicz
  5. * This code was split off from ide.c.  See it for original copyrights.
  6. *
  7. * May be copied or modified under the terms of the GNU General Public License.
  8. */

  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/ide.h>
  13. #include <linux/pci_ids.h>

  14. /* FIXME: convert arm and m32r to use ide_platform host driver */
  15. #ifdef CONFIG_ARM
  16. #include <asm/irq.h>
  17. #endif
  18. #ifdef CONFIG_M32R
  19. #include <asm/m32r.h>
  20. #endif
  21. #ifdef CONFIG_ARCH_S3C2410
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/ide.h>
  26. #include <linux/pci_ids.h>
  27. #include <asm/mach-types.h>
  28. #include <linux/init.h>
  29. #include <linux/ide.h>
  30. #include <linux/irq.h>
  31. #include <linux/interrupt.h>
  32. #include <mach/regs-mem.h>
  33. #include <mach/regs-gpio.h>
  34. #include <mach/regs-gpioj.h>
  35. #include <asm/io.h>
  36. #include <asm/irq.h>

  37. #define IDE_ARM_IRQPIN S3C2410_GPF6
  38. #define IDE_DATA_OFFSET                0
  39. #define IDE_STATUS_OFFSET        7
  40. #define IDE_CONTROL_OFFSET        8
  41. #endif

  42. #define DRV_NAME        "ide_generic"

  43. static int probe_mask;
  44. module_param(probe_mask, int, 0);
  45. MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");

  46. static const struct ide_port_info ide_generic_port_info = {
  47.         .host_flags                = IDE_HFLAG_NO_DMA,
  48.         .chipset                = ide_generic,
  49. };
  50. #ifdef CONFIG_ARM
  51. static const u16 legacy_bases[] = { 0x1f0 };
  52. static const int legacy_irqs[]  = { 14 };
  53. #elif defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) || \
  54.       defined(CONFIG_PLAT_OPSPUT)
  55. static const u16 legacy_bases[] = { 0x1f0 };
  56. static const int legacy_irqs[]  = { PLD_IRQ_CFIREQ };
  57. #elif defined(CONFIG_PLAT_MAPPI3)
  58. static const u16 legacy_bases[] = { 0x1f0, 0x170 };
  59. static const int legacy_irqs[]  = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ };
  60. #elif defined(CONFIG_ALPHA)
  61. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
  62. static const int legacy_irqs[]  = { 14, 15, 11, 10 };
  63. #else
  64. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
  65. static const int legacy_irqs[]  = { 14, 15, 11, 10, 8, 12 };
  66. #endif

  67. static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
  68. {
  69. #ifdef CONFIG_PCI
  70.         struct pci_dev *p = NULL;
  71.         u16 val;

  72.         for_each_pci_dev(p) {
  73.                 if (pci_resource_start(p, 0) == 0x1f0)
  74.                         *primary = 1;
  75.                 if (pci_resource_start(p, 2) == 0x170)
  76.                         *secondary = 1;

  77.                 /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
  78.                 if (p->vendor == PCI_VENDOR_ID_CYRIX &&
  79.                     (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
  80.                      p->device == PCI_DEVICE_ID_CYRIX_5520))
  81.                         *primary = *secondary = 1;

  82.                 /* Intel MPIIX - PIO ATA on non PCI side of bridge */
  83.                 if (p->vendor == PCI_VENDOR_ID_INTEL &&
  84.                     p->device == PCI_DEVICE_ID_INTEL_82371MX) {
  85.                         pci_read_config_word(p, 0x6C, &val);
  86.                         if (val & 0x8000) {
  87.                                 /* ATA port enabled */
  88.                                 if (val & 0x4000)
  89.                                         *secondary = 1;
  90.                                 else
  91.                                         *primary = 1;
  92.                         }
  93.                 }
  94.         }
  95. #endif
  96. }

  97. extern int s3c2410_gpio_getirq(unsigned int pin);
  98. extern void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function);


  99. /*设置IDE接口的寄存器地址,总线宽度,
  100.   *nWAIT等参数,使用nGCS1作为控制(CS1),
  101.   *nGCS2作为命令(CS0)*/
  102. static inline void s3c2410_hw_setup(hw_regs_t *hw)
  103. {
  104.     int i;
  105.     unsigned int oldval_bwscon; /* 用来保存BWSCON寄存器的值 */
  106.     unsigned long mapaddr0;
  107.     unsigned long mapaddr1;
  108.     unsigned long baseaddr[] =  {0x10000000, 0x08000000};  //ngcs2 接cs0,ngcs1接cs1
  109.     /* 设置BANK1/2: 总线宽度为16 */
  110.     oldval_bwscon = readl(S3C2410_BWSCON);
  111.     writel((oldval_bwscon & ~(3<<8)) \
  112.                 | S3C2410_BWSCON_DW1_16 | S3C2410_BWSCON_WS1
  113.         | S3C2410_BWSCON_DW2_16 | S3C2410_BWSCON_WS2, S3C2410_BWSCON);
  114.     /* 设置BANK1/2的时间参数 */
  115.         writel((S3C2410_BANKCON_Tacs4 | S3C2410_BANKCON_Tcos4 | S3C2410_BANKCON_Tacc14
  116.           | S3C2410_BANKCON_Tcoh4 | S3C2410_BANKCON_Tcah4 | S3C2410_BANKCON_Tacp6
  117.           | S3C2410_BANKCON_PMCnorm), S3C2410_BANKCON1);
  118.     writel((S3C2410_BANKCON_Tacs4 | S3C2410_BANKCON_Tcos4 | S3C2410_BANKCON_Tacc14
  119.           | S3C2410_BANKCON_Tcoh4 | S3C2410_BANKCON_Tcah4 | S3C2410_BANKCON_Tacp6
  120.           | S3C2410_BANKCON_PMCnorm), S3C2410_BANKCON2);
  121.     /*
  122.      * 设置IDE接口的地址, ADDR3~1接到IDE接口的A02~00
  123.      * 注意:没有使用ADDR0,所以下面确定地址时,都左移1位
  124.      */
  125.     memset(hw, 0, sizeof(*hw));
  126.     mapaddr0 = (unsigned long)ioremap(baseaddr[0], 16);
  127.     mapaddr1 = (unsigned long)ioremap(baseaddr[1], 16);
  128.     for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  129.         hw->io_ports_array[i] = mapaddr0 + (i<<1);
  130.     hw->io_ports.ctl_addr = mapaddr1 + (6<<1);
  131.     hw->irq = s3c2410_gpio_getirq(IDE_ARM_IRQPIN);
  132.     s3c2410_gpio_cfgpin(IDE_ARM_IRQPIN, S3C2410_GPIO_IRQ);
  133.     set_irq_type(hw->irq, IRQF_TRIGGER_RISING);
  134.     printk("*******ARM IDE register!\n");
  135. }

  136. static int __init ide_generic_init(void)
  137. {
  138.     hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  139.     unsigned long io_addr;
  140.     int i, rc = 0, primary = 0, secondary = 0;
  141.     ide_generic_check_pci_legacy_iobases(&primary, &secondary);
  142.     if (!probe_mask) {
  143.         printk(KERN_INFO DRV_NAME ": please use "probe_mask=0x3f" "
  144.             "module parameter for probing all legacy ISA IDE ports\n");

  145.         if (primary == 0)
  146.             probe_mask |= 0x1;

  147.         if (secondary == 0)
  148.             probe_mask |= 0x2;
  149.     } else
  150.         printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
  151.             "upon user request\n");

  152.     for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
  153.         io_addr = legacy_bases[i];

  154.         if ((probe_mask & (1 << i)) && io_addr) {
  155.             if (!request_region(io_addr, 8, DRV_NAME)) {
  156.                 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  157.                          "not free.\n",
  158.                          DRV_NAME, io_addr, io_addr + 7);
  159.                 rc = -EBUSY;
  160.                 continue;
  161.             }

  162.             if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  163.                 printk(KERN_ERR "%s: I/O resource 0x%lX "
  164.                          "not free.\n",
  165.                          DRV_NAME, io_addr + 0x206);
  166.                 release_region(io_addr, 8);
  167.                 rc = -EBUSY;
  168.                 continue;
  169.             }

  170.             memset(&hw, 0, sizeof(hw));
  171. #ifdef CONFIG_ARCH_S3C2410
  172.                         printk("*******s3c2410_hw_setup.......\n");
  173.             s3c2410_hw_setup(&hw);
  174.                         printk("*******s3c2410_hw_setup OKKKKK\n");
  175.                         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  176.                         printk("io_ports_array[%d] = 0x%lX\n", i, hw.io_ports_array[i]);
  177.                         printk("io_ports.ctl_addr = 0x%lX\n", hw.io_ports.ctl_addr);
  178.                         printk("irq = %d\n", hw.irq);
  179.                         printk("io_ports.status_addr = 0x%lx\n", hw.io_ports.status_addr);
  180.         #else
  181.                         printk("*******s3c2410 ELSE\n");
  182.             ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
  183.                 #ifdef CONFIG_IA64
  184.                         printk("*******IA64.....................\n");
  185.             hw.irq = isa_irq_to_vector(legacy_irqs);
  186.                 #else
  187.                         printk("*******IA64 ELSE.....................\n");
  188.             hw.irq = legacy_irqs;
  189.                         printk("*******IA64 ELSE OK.....................\n");
  190.         #endif

  191. #endif                       
  192.                         printk("IDE_HOST_ADD\n");
  193.                         printk("**************\n***************\n");
  194.                         hw.chipset = ide_generic;
  195.             rc = ide_host_add(&ide_generic_port_info, hws, NULL);
  196.             if (rc) {
  197.                                 printk("*******rc........................\n");
  198.                 release_region(io_addr + 0x206, 1);
  199.                 release_region(io_addr, 8);
  200.             }
  201.         }
  202.     }

  203.     return rc;
  204.         printk("*******END OF IDE_GENERIC_INIT.....................\n");
  205. }

  206. module_init(ide_generic_init);

  207. MODULE_LICENSE("GPL");
复制代码
下面是启动信息,我打印了一些io申请信息方便调试。硬盘的信息也读到了,hitachi什么的。但是读着读着就lost interrupt。不知道是什么原因,请大侠们帮忙看一下,谢谢了!

Uniform Multi-Platform E-IDE driver
ide_generic: please use "probe_mask=0x3f" module parameter for probing all legacy ISA IDE ports
*******ARM IDE register!**********
io_ports_array[0] = 0xC4820000
io_ports_array[1] = 0xC4820002
io_ports_array[2] = 0xC4820004
io_ports_array[3] = 0xC4820006
io_ports_array[4] = 0xC4820008
io_ports_array[5] = 0xC482000A
io_ports_array[6] = 0xC482000C
io_ports_array[7] = 0xC482000E
io_ports.ctl_addr = 0xC482400C
irq = 50
io_ports.status_addr = 0xc482000e
hda: Hitachi HTS542580K9SA00, ATA DISK drive
ide0 at 0xc4820000-0xc482000e,0xc482400c on irq 50
ide-gd driver 1.18
hda: max request size: 128KiB
hda: 16514064 sectors (8455 MB) w/7229KiB Cache, CHS=16383/16/63
hda:<4>hda: lost interrupt
hda: lost interrupt
hda: lost interrupt
hda: lost interrupt
unknown partition table
Driver 'sd' needs updating - please use bus_type methods
**********dm9000 Ethernet Driver, V1.31**********
iosize = 4, addr-start = 0x20000000, io_addr = 0xc4828000

embedsky_lhh 发表于 2012-10-24 17:36:36 | 显示全部楼层
楼主可以贴下原理图,和platform注册那部分的代码,方便大家查看,对了中断申请了么?
 楼主| kelly 发表于 2012-10-24 17:56:36 | 显示全部楼层
本帖最后由 kelly 于 2012-10-24 18:04 编辑

感谢回复!

中断使用的是EINT6,即端口GPF6。

#define IDE_ARM_IRQPIN S3C2410_GPF6

hw->irq = s3c2410_gpio_getirq(IDE_ARM_IRQPIN);
s3c2410_gpio_cfgpin(IDE_ARM_IRQPIN, S3C2410_GPIO_IRQ);
set_irq_type(hw->irq, IRQF_TRIGGER_RISING);


下面是原理图,IORDY脚已经改了,接到2440的nwait脚上。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| kelly 发表于 2012-10-24 18:02:57 | 显示全部楼层
还有platform注册的话,我是参照网上的代码,好像没有那部分的代码,都是修改ide-generic.c文件。
端口配置和注册在static inline void s3c2410_hw_setup(hw_regs_t *hw)函数中完成。其他的操作函数,用的是内核自带的函数。
  1. /*设置IDE接口的寄存器地址,总线宽度,
  2.   *nWAIT等参数,使用nGCS1作为控制(CS1),
  3.   *nGCS2作为命令(CS0)*/
  4. static inline void s3c2410_hw_setup(hw_regs_t *hw)
  5. {
  6.     int i;
  7.     unsigned int oldval_bwscon; /* 用来保存BWSCON寄存器的值 */
  8.     unsigned long mapaddr0;
  9.     unsigned long mapaddr1;
  10.     unsigned long baseaddr[] =  {0x10000000, 0x08000000};  //ngcs2 接cs0,ngcs1接cs1
  11.     /* 设置BANK1/2: 总线宽度为16 */
  12.     oldval_bwscon = readl(S3C2410_BWSCON);
  13.     writel((oldval_bwscon & ~(3<<8)) \
  14.                 | S3C2410_BWSCON_DW1_16 | S3C2410_BWSCON_WS1
  15.         | S3C2410_BWSCON_DW2_16 | S3C2410_BWSCON_WS2, S3C2410_BWSCON);
  16.     /* 设置BANK1/2的时间参数 */
  17.         writel((S3C2410_BANKCON_Tacs4 | S3C2410_BANKCON_Tcos4 | S3C2410_BANKCON_Tacc14
  18.           | S3C2410_BANKCON_Tcoh4 | S3C2410_BANKCON_Tcah4 | S3C2410_BANKCON_Tacp6
  19.           | S3C2410_BANKCON_PMCnorm), S3C2410_BANKCON1);
  20.     writel((S3C2410_BANKCON_Tacs4 | S3C2410_BANKCON_Tcos4 | S3C2410_BANKCON_Tacc14
  21.           | S3C2410_BANKCON_Tcoh4 | S3C2410_BANKCON_Tcah4 | S3C2410_BANKCON_Tacp6
  22.           | S3C2410_BANKCON_PMCnorm), S3C2410_BANKCON2);
  23.     /*
  24.      * 设置IDE接口的地址, ADDR3~1接到IDE接口的A02~00
  25.      * 注意:没有使用ADDR0,所以下面确定地址时,都左移1位
  26.      */
  27.     memset(hw, 0, sizeof(*hw));
  28.     mapaddr0 = (unsigned long)ioremap(baseaddr[0], 16);
  29.     mapaddr1 = (unsigned long)ioremap(baseaddr[1], 16);
  30.     for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  31.         hw->io_ports_array[i] = mapaddr0 + (i<<1);
  32.     hw->io_ports.ctl_addr = mapaddr1 + (6<<1);
  33.     hw->irq = s3c2410_gpio_getirq(IDE_ARM_IRQPIN);
  34.     s3c2410_gpio_cfgpin(IDE_ARM_IRQPIN, S3C2410_GPIO_IRQ);
  35.     set_irq_type(hw->irq, IRQF_TRIGGER_RISING);
  36.     printk("*******ARM IDE register!\n");
  37. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-18 16:35 , Processed in 1.062500 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表