device tree activation SPI on AT91SAM9G20-EK_2MMC

This forum is for users of Atmel's SAM Series and who are interested in using Linux OS.

Moderator: nferre

cali90
Posts: 8
Joined: Tue Mar 03, 2015 10:54 am

device tree activation SPI on AT91SAM9G20-EK_2MMC

Thu Jan 26, 2017 6:27 pm

Hi all,
I'm a beginner with the device tree support.
I using a custom board bases on at91samg20ek_2mmc.
I created a custom device tree support based on file at91sam9g20ek_2mmc.dts
On this custom file I actived spidev as below :
#include "at91sam9g20ek_common.dtsi"

Code: Select all

/ {
	model = "Atmel at91sam9g20 powelco __date__";
	compatible = "atmel,at91sam9g20ek_2mmc", "atmel,at91sam9g20", "atmel,at91sam9";

	ahb {
		apb{
			spipwl0: spi@fffc8000 {
			status = "okay";
			#cs-gpios = <&pioC 25 0>;
			spidev@0 {
				compatible = "linux,spidev";
				spi-max-frequency = <50000000>;
				reg = <0>;
				}; 
			};
		};
	};

	leds {
		compatible = "gpio-leds";

		ds1 {
			label = "ds1";
			gpios = <&pioB 9 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
		};

		ds5 {
			label = "ds5";
			gpios = <&pioB 8 GPIO_ACTIVE_LOW>;
		};
	};
};
after built and load in my board
I found in directory /proc/device-tree/ahb/apb/spi@fffc8000/ a "configuration" of mtd_dataflash (Which corresponding at the default configuration of evaluation board at91sam9g20-ek_2mmc )
With the "module" mtd_dataflash loaded I remark than my spi frequency output is limited.
SO I had tried to inhibited the mtd_dataflash module in device tree .
I tried different solution with status "disabled" without success
Only one solution is to suppress configuration of mtd_dataflash in file at91sam9g20ek_common.dtsi .
with this solution the module mtd_dataflash deactivated. and my spi has a good performance.

QUESTION :
  • 1>What is the good solution for inhibited the mtd_dataflash without suppressed line in file t91sam9g20ek_common.dtsi ?
  • 2>During boot I had the message bellow :
    • atmel_spi fffc8000.spi: version: 0x199
      atmel_spi fffc8000.spi: Atmel SPI Controller at 0xfffc8000 (irq 32)
      spidev spi32766.0: buggy DT: spidev listed directly in DT
      ------------[ cut here ]------------
      WARNING: CPU: 0 PID: 1 at drivers/spi/spidev.c:757 spidev_probe+0x160/0x198
      Modules linked in:
      CPU: 0 PID: 1 Comm: swapper Not tainted 4.8.6 #3
      Hardware name: Atmel AT91SAM9
      [<c000f4dc>] (unwind_backtrace) from [<c000cf64>] (show_stack+0x10/0x14)
      [<c000cf64>] (show_stack) from [<c001743c>] (__warn+0xc0/0xec)
      [<c001743c>] (__warn) from [<c001750c>] (warn_slowpath_null+0x1c/0x24)
      [<c001750c>] (warn_slowpath_null) from [<c0288b90>] (spidev_probe+0x160/0x198)
      [<c0288b90>] (spidev_probe) from [<c0285a08>] (spi_drv_probe+0x84/0x9c)
      [<c0285a08>] (spi_drv_probe) from [<c0232edc>] (driver_probe_device+0x130/0x298)
      [<c0232edc>] (driver_probe_device) from [<c0231844>] (bus_for_each_drv+0x84/0x94)
      [<c0231844>] (bus_for_each_drv) from [<c0232d14>] (__device_attach+0x84/0xf8)
      [<c0232d14>] (__device_attach) from [<c02323d8>] (bus_probe_device+0x24/0x7c)
      [<c02323d8>] (bus_probe_device) from [<c0230b5c>] (device_add+0x3e4/0x4f0)
      [<c0230b5c>] (device_add) from [<c0286574>] (spi_add_device+0xd0/0x124)
      [<c0286574>] (spi_add_device) from [<c0287a74>] (spi_register_master+0x5b8/0x6c4)
      [<c0287a74>] (spi_register_master) from [<c0287bb0>] (devm_spi_register_master+0x30/0x6c)
      [<c0287bb0>] (devm_spi_register_master) from [<c028b1fc>] (atmel_spi_probe+0x4d8/0x634)
      [<c028b1fc>] (atmel_spi_probe) from [<c02346cc>] (platform_drv_probe+0x54/0xa0)
      [<c02346cc>] (platform_drv_probe) from [<c0232edc>] (driver_probe_device+0x130/0x298)
      [<c0232edc>] (driver_probe_device) from [<c02330c0>] (__driver_attach+0x7c/0x9c)
      [<c02330c0>] (__driver_attach) from [<c0231788>] (bus_for_each_dev+0x6c/0x90)
      [<c0231788>] (bus_for_each_dev) from [<c02325dc>] (bus_add_driver+0xc8/0x1dc)
      [<c02325dc>] (bus_add_driver) from [<c0233890>] (driver_register+0x9c/0xe0)
      [<c0233890>] (driver_register) from [<c000978c>] (do_one_initcall+0xbc/0x16c)
      [<c000978c>] (do_one_initcall) from [<c0536d24>] (kernel_init_freeable+0x100/0x1bc)
      [<c0536d24>] (kernel_init_freeable) from [<c03ca648>] (kernel_init+0x8/0xec)
      [<c03ca648>] (kernel_init) from [<c000a3b0>] (ret_from_fork+0x14/0x24)
      ---[ end trace a23f41837ba6e6d7 ]---

    this message is due at the debug option activated in kernel ? ???? right / Wrong ?
  • 3>How can I verify DMA activation with spidev ?
    Do I modify the device tree for DMA activation ?




Thank you for your help.

Cali
blue_z
Location: USA
Posts: 1507
Joined: Thu Apr 19, 2007 10:15 pm

Re: device tree activation SPI on AT91SAM9G20-EK_2MMC

Fri Jan 27, 2017 6:52 am

cali90 wrote:I using a custom board bases on at91samg20ek_2mmc.
I created a custom device tree support based on file at91sam9g20ek_2mmc.dts
On this custom file I actived spidev as below :
#include "at91sam9g20ek_common.dtsi"
Apparently your "custom device tree" is not customized enough for your custom board.
Since you have your own board there's no reason for you to be including at91sam9g20ek_common.dtsi, which is for an Atmel EK board.
You only need the at91sam9g20.dtsi for your SoC (which happens to also include at91sam9260.dtsi).
These .dtsi files have the basic definitions for the SoC and all of its integrated peripherals.
Only the essential devices are enabled, and all optional and/or non-essential devices are disabled.

For your board you only want the salient definitions in your .dts file. For the devices that are used on your board, you can copy node definitions from the .dts and .dtsi files for Atmel EK boards, and then edit/paste them into your .dts file.

Using modifed DT files for Atmel boards is IMO a bad idea. Only use the basic .dtsi files for SoCs.
cali90 wrote:What is the good solution for inhibited the mtd_dataflash without suppressed line in file t91sam9g20ek_common.dtsi ?
The simple solution is don't use DT files that are not applicable for your board.
When you compose your own .dts file as suggested, it's written for your board, so you don't have to inhibit something that won't even be there.
cali90 wrote:2>During boot I had the message bellow : ...
this message is due at the debug option activated in kernel ? ???? right / Wrong ?
Well, your DT syntax looks unusual.
The hash mark before "cs-gpio" should not be there.
Typical syntax for "cs-gpio" has four chipselects, not just one.
Your `compatible = "linux,spidev"` statement looks incorrect; usually it's `compatible = "spidev"`.
cali90 wrote:3>How can I verify DMA activation with spidev ?
Draw a block diagram for your SPI device.
Your SPI device should have no path to main memory except through its SPI interface to the master SPI controller (in the Atmel SoC).
IOW your SPI device and the spidev driver cannot utilize DMA. The master SPI controller can utilize DMA (or the PDC).
cali90 wrote:Do I modify the device tree for DMA activation ?
Inspect the DT definition for the master SPI controller(s).
I see nothing for the SAM9G20/9260 SoCs, whereas other SAM9x and SAMA5D3 SoCs specify DMA in the master SPI controller node.
I don't know what this means. You'll have to experiment.

Regards
lantzvillian
Posts: 4
Joined: Mon Nov 14, 2016 10:21 pm

Re: device tree activation SPI on AT91SAM9G20-EK_2MMC

Tue Feb 21, 2017 5:14 pm

I am not sure if the board you are using has DMA as well. From all documents I have read, DMA is available on the later A5 boards and not the board you are using (I am using it too).

As blue_z stated, you will need to complete your DTB to enable everything including clocks etc... and all of your pinctl settings. I am running the kernel, u-boot and bootstrap from the dataflash, and the rootfs etc... on the NAND. Then you need to adjust the MTD partmap for the kernel.

Code: Select all

	spi0: spi@fffc8000 {
				status = "okay";
				compatible = "atmel,at91rm9200-spi";
				status = "okay";
				cs-gpios = <0>, <&pioC 11 0>, <0>, <0>;
			
				mtd_dataflash@0 {
					#address-cells = <1>;
					#size-cells = <1>;
					compatible = "atmel,at45db321d", "atmel,at45", "atmel,dataflash";
					spi-max-frequency = <50000000>;
					reg = <1>;
					status = "okay";
					
					partition@0 {
						label = "Bootstrap";
						reg = <0x0 0x00004200>;
						read-only;
					};
					partition@00004200 {
						label = "Environment";
						reg = <0x00004200 0x4200>;
					};
					partition@00008400 {
						label = "U-Boot";
						reg = <0x00008400 0x7BC00>;
					};
					partition@00084000 {
						label = "kernel";
						reg = <0x00084000 0x186A00>;
					};
					partition@0030AA00 {
						label = "dtb";
						reg = <0x0030AA00 0x61A8>;
					};
				};
                };

Driver... Note I just borrowed this as an example from https://raw.githubusercontent.com/respe ... at91part.c

Code: Select all

/*
 * 
 * Copyright (C) 2007 OpenWrt.org
 * 
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Atmel AT91 flash partition table. (Modified by Hamish Guthrie).
 * Based on ar7 map by Felix Fietkau.
 *
 */

#include <linux/kernel.h>
#include <linux/slab.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/bootmem.h>
#include <linux/squashfs_fs.h>

static struct mtd_partition at91_parts[6];

static int create_mtd_partitions(struct mtd_info *master, 
				 struct mtd_partition **pparts, 
				 unsigned long origin)
{
	unsigned int offset, len;
	unsigned int pre_size = 0x42000, root_max = 0x362400;
	unsigned char buf[512];
	struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;

	printk("Parsing AT91 partition map...\n");

	at91_parts[0].name = "loaders";
	at91_parts[0].offset = 0;
	at91_parts[0].size = 0x21000;
	at91_parts[0].mask_flags = MTD_WRITEABLE;

	at91_parts[1].name = "ubparams";
	at91_parts[1].offset = 0x21000;
	at91_parts[1].size = 0x8400;
	at91_parts[1].mask_flags = 0;

	at91_parts[2].name = "kernel";
	at91_parts[2].offset = pre_size;
	at91_parts[2].size = 0;
	at91_parts[2].mask_flags = 0;

	at91_parts[3].name = "rootfs";
	at91_parts[3].offset = 0;
	at91_parts[3].size = 0;
	at91_parts[3].mask_flags = 0;

	for(offset = pre_size; offset < root_max; offset += master->erasesize) {

		memset(&buf, 0xe5, sizeof(buf));

		if (master->read(master, offset, sizeof(buf), &len, buf) || len != sizeof(buf))
			break;

		if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
			printk(KERN_INFO "%s: Filesystem type: squashfs, size=0x%x\n",
							master->name, (u32) sb->bytes_used);

			at91_parts[3].size = sb->bytes_used;
			at91_parts[3].offset = offset;
			len = at91_parts[3].offset + at91_parts[3].size;
			len = ((len / (master->erasesize * 8)) + 1) * master->erasesize * 8;
			at91_parts[3].size = len - at91_parts[3].offset;
			at91_parts[2].size = offset - at91_parts[2].offset;
			break;
			}
		}

	if (at91_parts[3].size == 0) {
		printk(KERN_NOTICE "%s: Couldn't find root filesystem\n", master->name);
		return -1;
		}

	at91_parts[4].name = "rootfs_data";
	at91_parts[4].offset = root_max;
	at91_parts[4].size = master->size - root_max;
	at91_parts[4].mask_flags = 0;

	at91_parts[5].name = "complete";
	at91_parts[5].offset = 0;
	at91_parts[5].size = master->size;
	at91_parts[5].mask_flags = 0;

	*pparts = at91_parts;
	return 6;
}

static struct mtd_part_parser at91_parser = {
	.owner = THIS_MODULE,
	.parse_fn = create_mtd_partitions,
	.name = "at91part",
};

static int __init at91_parser_init(void)
{
	register_mtd_parser(&at91_parser);

	return 0;
}

module_init(at91_parser_init);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Felix Fietkau, Eugene Konev, Hamish Guthrie");
MODULE_DESCRIPTION("MTD partitioning for Atmel at91");
I hope this helps once you get the SPI setup and operating.

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest