aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/sunxi/patches-3.14/149-dt-sun7i-add-spi-on-olinuxinom.patch
blob: cbcfea7c9cbd49408ec9b9df36ba2eda107339f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From 3f134732aaf4d785532c716f4ef7703d631a510b Mon Sep 17 00:00:00 2001
From: Maxime Ripard <maxime.ripard@free-electrons.com>
Date: Sat, 22 Feb 2014 22:35:59 +0100
Subject: [PATCH] ARM: dts: sun7i: Enable the SPI controllers of the
 A20-olinuxino-micro

The A20-Olinuxino-micro has two SPI bus exposed on its UEXT connectors, enable
them.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

--- a/arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts
+++ b/arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts
@@ -18,7 +18,24 @@
 	model = "Olimex A20-Olinuxino Micro";
 	compatible = "olimex,a20-olinuxino-micro", "allwinner,sun7i-a20";
 
+	aliases {
+		spi0 = &spi1;
+		spi1 = &spi2;
+	};
+
 	soc@01c00000 {
+		spi1: spi@01c06000 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&spi1_pins_a>;
+			status = "okay";
+		};
+
+		spi2: spi@01c17000 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&spi2_pins_a>;
+			status = "okay";
+		};
+
 		pinctrl@01c20800 {
 			led_pins_olinuxino: led_pins@0 {
 				allwinner,pins = "PH2";
hlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Copyright (C) 2014  Claudio Leite <leitec@staticky.com>
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/*
 * Builds a proper flash image for routers using some Gemtek
 * OEM boards. These include the Airlink101 AR725W, the
 * Asante SmartHub 600 (AWRT-600N), and Linksys WRT100/110.
 *
 * The resulting image is compatible with the factory firmware
 * web upgrade and TFTP interface.
 *
 * To build:
 *  gcc -O2 -o mkheader_gemtek mkheader_gemtek.c -lz
 *
 * Claudio Leite <leitec@staticky.com>
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include <zlib.h>		/* for crc32() */

/*
 * The header is in little-endian format. In case
 * we are on a BE host, we need to swap binary
 * values.
 */
#ifdef __APPLE__
# include <libkern/OSByteOrder.h>
# define le32 OSSwapHostToLittleInt32
#else
# if defined(__linux__)
#  include <endian.h>
#  if __BYTE_ORDER == __BIG_ENDIAN
#   define CPU_BIG_ENDIAN
#  endif
# else
#  include <sys/endian.h>		/* BSD's should have this */
#  if _BYTE_ORDER == _BIG_ENDIAN
#   define CPU_BIG_ENDIAN
#  endif
# endif
# ifdef CPU_BIG_ENDIAN
#  define le32(x) (((x & 0xff000000) >> 24) | \
                   ((x & 0x00ff0000) >> 8)  | \
                   ((x & 0x0000ff00) << 8)  | \
                   ((x & 0x000000ff) << 24))
# else
#  define le32(x) (x)
# endif
#endif

struct gemtek_header {
	uint8_t 	magic[4];
	uint8_t 	version[4];
	uint32_t 	product_id;
	uint32_t 	imagesz;
	uint32_t 	checksum;
	uint32_t 	fast_checksum;
	uint8_t 	build[4];
	uint8_t 	lang[4];
};

#define HDRLEN	sizeof(struct gemtek_header)

struct machines {
	char           *desc;
	char           *id;
	uint32_t 	maxsize;
	struct gemtek_header header;
};

struct machines mach_def[] = {
	{"Airlink101 AR725W", "ar725w", 0x340000,
		{"GMTK", "1003", le32(0x03000001), 0, 0,
		  0, "01\0\0", "EN\0\0"}},
	{"Asante AWRT-600N", "awrt600n", 0x340000,
		{"A600", "1005", le32(0x03000001), 0, 0,
		  0, "01\0\0", "EN\0\0"}},
	{"Linksys WRT100", "wrt100", 0x320000,
		{"GMTK", "1007", le32(0x03040001), 0, 0,
		  0, "2\0\0\0", "EN\0\0"}},
	{"Linksys WRT110", "wrt110", 0x320000,
		{"GMTK", "1007", le32(0x03040001), 0, 0,
		  0, "2\0\0\0", "EN\0\0"}},
	{0}
};

int
main(int argc, char *argv[])
{
	unsigned long 	res, flen;
	struct gemtek_header my_hdr;
	FILE           *f, *f_out;
	int 		image_type = -1, index;
	uint8_t        *buf;
	uint32_t 	crc;

	if (argc < 3) {
		fprintf(stderr, "mkheader_gemtek <uImage> <webflash image> [machine ID]\n");
		fprintf(stderr, "  where [machine ID] is one of:\n");
		for (index = 0; mach_def[index].desc != 0; index++) {
			fprintf(stderr, "    %-10s  %s", mach_def[index].id, mach_def[index].desc);
			if (index == 0)
				fprintf(stderr, " (default)\n");
			else
				fprintf(stderr, "\n");
		}

		exit(-1);
	}

	if (argc == 4) {
		for(index = 0; mach_def[index].id != 0; index++) {
			if(strcmp(mach_def[index].id, argv[3]) == 0) {
				image_type = index;
				break;
			}
		}

		if(image_type == -1) {
			fprintf(stderr, "\nERROR: invalid machine type\n");
			exit(-1);
		}
	} else
		image_type = 0;

	printf("Opening %s...\n", argv[1]);

	f = fopen(argv[1], "r");
	if(!f) {
		fprintf(stderr, "\nERROR: couldn't open input image\n");
		exit(-1);
	}

	fseek(f, 0, SEEK_END);
	flen = (unsigned long) ftell(f);

	printf("  %lu (0x%lX) bytes long\n", flen, flen);

	if (flen > mach_def[image_type].maxsize) {
		fprintf(stderr, "\nERROR: image exceeds maximum compatible size\n");
		goto f_error;
	}

	buf = malloc(flen + HDRLEN);
	if (!buf) {
		fprintf(stderr, "\nERROR: couldn't allocate buffer\n");
		goto f_error;
	}
	rewind(f);
	res = fread(buf + HDRLEN, 1, flen, f);
	if (res != flen) {
		perror("Couldn't read entire file: fread()");
		goto f_error;
	}
	fclose(f);

	printf("\nCreating %s...\n", argv[2]);

	memcpy(&my_hdr, &mach_def[image_type].header, HDRLEN);

	printf("  Using %s magic\n", mach_def[image_type].desc);

	my_hdr.imagesz = le32(flen + HDRLEN);
	memcpy(my_hdr.lang, "EN", 2);

	memcpy(buf, &my_hdr, HDRLEN);

	crc = crc32(0, buf, flen + HDRLEN);
	printf("  CRC32: %08X\n", crc);

	my_hdr.checksum = le32(crc);
	memcpy(buf, &my_hdr, HDRLEN);

	printf("  Writing...\n");

	f_out = fopen(argv[2], "w");
	if(!f_out) {
		fprintf(stderr, "\nERROR: couldn't open output image\n");
		exit(-1);
	}

	fwrite(buf, 1, flen + HDRLEN, f_out);

	fclose(f_out);

	free(buf);
	return 0;

f_error:
	fclose(f);
	exit(-1);
}