| Welcome to AT91SAM Community Forum http://www.at91.com/samphpbb/ |
|
| configure spi http://www.at91.com/samphpbb/viewtopic.php?f=12&t=19046 |
Page 1 of 1 |
| Author: | federicololli [ Tue Mar 09, 2010 1:24 pm ] |
| Post subject: | configure spi |
Hi, I have this problem,I configured the SPI in the kernel as follows: in the board-foxg20.c: /* * SPI devices. */ static struct spi_board_info foxg20_spi_devices[] = { #if !defined(CONFIG_MMC_AT91) { .modalias = "mtd_dataflash", .chip_select = 1, .max_speed_hz = 15 * 1000 * 1000, .bus_num = 0, }, #endif }; static struct spi_board_info foxg20_spi_devices1[] = { { .modalias = "spidev", .chip_select = 0, .max_speed_hz = 15*1000*1000, .bus_num=1, }, }; and in the at91sam9260_devices.c: /* -------------------------------------------------------------------- * SPI * -------------------------------------------------------------------- */ #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE) static u64 spi_dmamask = DMA_BIT_MASK(32); static struct resource spi0_resources[] = { [0] = { .start = AT91SAM9260_BASE_SPI0, .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = AT91SAM9260_ID_SPI0, .end = AT91SAM9260_ID_SPI0, .flags = IORESOURCE_IRQ, }, }; static struct platform_device at91sam9260_spi0_device = { .name = "atmel_spi", .id = 0, .dev = { .dma_mask = &spi_dmamask, .coherent_dma_mask = DMA_BIT_MASK(32), }, .resource = spi0_resources, .num_resources = ARRAY_SIZE(spi0_resources), }; static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 }; static struct resource spi1_resources[] = { [0] = { .start = AT91SAM9260_BASE_SPI1, .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = AT91SAM9260_ID_SPI1, .end = AT91SAM9260_ID_SPI1, .flags = IORESOURCE_IRQ, }, }; static struct platform_device at91sam9260_spi1_device = { .name = "atmel_spi", .id = 1, .dev = { .dma_mask = &spi_dmamask, .coherent_dma_mask = DMA_BIT_MASK(32), }, .resource = spi1_resources, .num_resources = ARRAY_SIZE(spi1_resources), }; static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 }; void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) { int i; unsigned long cs_pin; short enable_spi0 = 0; short enable_spi1 = 0; /* Choose SPI chip-selects */ for (i = 0; i < nr_devices; i++) { if (devices[i].controller_data) cs_pin = (unsigned long) devices[i].controller_data; else if (devices[i].bus_num == 0) cs_pin = spi0_standard_cs[devices[i].chip_select]; else cs_pin = spi1_standard_cs[devices[i].chip_select]; if (devices[i].bus_num == 0) enable_spi0 = 1; else enable_spi1 = 1; /* enable chip-select pin */ at91_set_gpio_output(cs_pin, 1); /* pass chip-select pin to driver */ devices[i].controller_data = (void *) cs_pin; } spi_register_board_info(devices, nr_devices); /* Configure SPI bus(es) */ if (enable_spi0) { at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */ at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */ at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */ at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk"); platform_device_register(&at91sam9260_spi0_device); } if (enable_spi1) { at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */ at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */ at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */ at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk"); platform_device_register(&at91sam9260_spi1_device); } } #else void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {} #endif in dmesg : brd: module loaded loop: module loaded atmel_spi atmel_spi.1: Atmel SPI Controller at 0xfffcc000 (irq 13) MACB_mii_bus: probed in dev appares spidev1.0 if I try to run ./devspi_test it's run but in the scope SPI analyzer nothing appears. suggestions?????? |
|
| Author: | m-i-k-e.rm [ Wed Mar 10, 2010 6:04 pm ] |
| Post subject: | Re: configure spi |
Hi federicololli, according to a post on the following forum you have to adapt the spidev_test.c. http://forum.embedded-projects.net/view ... hp?id=1271 **************************************** Edit the test-programm "spidev_test.c" **************************************** struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, .len = ARRAY_SIZE(tx), .delay_usecs = (int) NULL, .speed_hz = (int) NULL, .bits_per_word = (int) NULL, }; **************************************** Michael |
|
| Author: | federicololli [ Fri Mar 12, 2010 2:03 pm ] |
| Post subject: | Re: configure spi |
good thanks! work |
|
| Author: | federicololli [ Fri Mar 12, 2010 6:35 pm ] |
| Post subject: | Re: configure spi |
is possible to reduce the speed of the SPI CLK at 500kHz? |
|
| Page 1 of 1 | All times are UTC + 1 hour [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|



Forum