本帖最后由 wolf 于 2014-1-16 16:39 编辑
开发板 : Cubie2
linux内核: linux 3.4
android : 4.2
问题:设置好 fex 和 config后, 我自己写了个spi设备驱动, 由于手头有一个驱动原形, 就没有参照内核带的spidev的驱动. 现在情况是 :能够正确的读写寄存器, 但是在gpio上却没有 数据输出,也没有时钟.控制片选倒是高低电平能够通过示波器测量到.
请各位大神帮忙看看, 问题到底出在哪里了...
--------------------------------------------------------------------------------
内核 .config部分
- 1456 CONFIG_SPI_SUN7I=y
- 1457 CONFIG_SPI=y
- 1458 CONFIG_SPI_MASTER=y
- 1460 CONFIG_EXPERIMENTAL=y
复制代码 ___________________________________________________
system.fex 部分- 256 [spi0_para]
- 257 spi_used = 1
- 258 spi_cs_bitmap = 1
- 259 spi_cs0 = port:PI10<2><default><default><default>
- 260 spi_sclk = port:PI11<2><default><default><default>
- 261 spi_mosi = port:PI12<2><default><default><default>
- 262 spi_miso = port:PI13<2><default><default><default>
- 294 [spi_devices]
- 295 spi_dev_num = 1
- 296
- 297 [spi_board0]
- 298 modalias = "ads1298"
- 299 max_speed_hz = 12000000
- 300 bus_num = 0
- 301 chip_select = 0
- 302 mode = 0
- 303 full_duplex = 0
- 304 manual_cs = 0
复制代码 __________________________________________________________________
GPIO 设置- 491 static void pio_init(void)
- 492 {
- 493 u32 regVal;
- 494 volatile void __iomem *pig_cfg1_v;
- 495
- 496 pig_cfg1_v = ioremap(PI_CFG1,4);//used const u32 PI_CFG1
- 499 regVal = readl(pig_cfg1_v);
- 501
- 502 /*
- 503 * config PI10 - PI15 register
- 504 * | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
- 505 * | / | pwm 1mv | / |Drdy EINT26/input?000| / | MISO | / | MOSI |
- 506 * | / | 0 | 0 | 0 | / | 1 | 1 | 0 | / | 0 | 1 | 0 | / | 0 | 1 | 0 |
- 507 *
- 508 * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 - 0 |
- 509 * | / | CLK | / | CS0 | - |
- 510 * | / | 0 | 1 | 0 | / | 0 | 1 | 0 | - |
- 511 */
- 512
- 513 /* PI10-PI15 */
- 514 regVal &= 0x000000FF;
- 515 regVal |= 0x06222200;
- 516 writel(regVal, pig_cfg1_v);
- 519 }
复制代码 ___________________________________________________________________
spi 寄存器 初始化- static void spi_init(void)
- 419 {
- 420 //u32 mr;
- 421 volatile u32 regVal;
- 422 void __iomem *cpu_ahb_apb0_cfg_reg_v;
- 423 void __iomem *ahb_gating_reg0_v;
- 424 void __iomem *spi0_clk_v;
- 425 int i;
- 426
- 428 //spi0_CLK
- 430 regVal = 0x80030000; //osc/8/1 = 3M sclk=3M
- 431 spi0_clk_v = ioremap(SPI0_CLK, 4);
- 432 writel(regVal, spi0_clk_v);
- 436 /* AHB setting */
- 437 cpu_ahb_apb0_cfg_reg_v = ioremap(CPU_AHB_APB0_CFG_REG, 4);
- 438 regVal = readl(cpu_ahb_apb0_cfg_reg_v );
- 439 regVal&= 0xFFFFFF0F; //set default AHB val
- 441 regVal|= (0x01 << 6); //pll6/2 = 300M
- 442 writel(regVal, cpu_ahb_apb0_cfg_reg_v);
- 445 iounmap(cpu_ahb_apb0_cfg_reg_v);
- 446
- 447 ahb_gating_reg0_v = ioremap(AHB_GATING_REG0,4);
- 448 regVal = readl(ahb_gating_reg0_v);
- 450 regVal |= (0x01 << 20); // set gating pass
- 451 regVal |= (0x01 << 6); // set gating pass for dma , 好像没用.
- 453 writel(regVal, ahb_gating_reg0_v);
- 456 iounmap(ahb_gating_reg0_v);
- 459
- 460 /*SPI0 setting*/
- 461 spi0_base_addr_v = ioremap(SPI0_BASE_ADDR, 44); //spi reg count = 11
- 466 //spi0_CCTL
- 469 regVal = 0x0000101D; //sclk=5M 0x1D = 29 ,2 *(29+1) = 60
- 470 writel(regVal, spi0_base_addr_v+SPI_CLK_RATE_REG);
- 476 for(i=0;i<11;i++) //打印出来看看寄存器的设置
- 477 {
- 478 regVal = readl(spi0_base_addr_v+i*4);
- 479 spi_err("SPI0_BASE_ADDR_V+%d = %08X", i, regVal);
- 480 }
- 481
- 484 regVal = 0x00130013; //manual set ss 1 , 0 , mode=0
- 485 writel(regVal, spi0_base_addr_v+SPI_CTL_REG);
- 490 }
复制代码 -------------------------------------------------------------------
spi_write 函数- static inline ssize_t writeByte(const char *buffer)
- 140 {
- 141 u32 regVal;
- 143 cs_activate(); //片选拉低
- 153 writel(*buffer, spi0_base_addr_v+SPI_TXDATA_REG);
- 154 cs_inactivate(); //片选拉高
- 156 return 1;
- 157 }
复制代码 |