diff -Naur linux-4.7.3/arch/avr32/boards/grasshopper/button.c linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/button.c --- linux-4.7.3/arch/avr32/boards/grasshopper/button.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/button.c 2016-09-13 11:23:21.454833158 +0200 @@ -0,0 +1,55 @@ +/* + * init code specific for grasshoppers Buttons + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static struct gpio_keys_button grasshopper_buttons_btn[] = { + { + .gpio = GPIO_PIN_PA(31), + .code = BTN_0, + .desc = "Button 0", + .active_low = 1, + .type = EV_KEY, + }, +}; + +static struct gpio_keys_platform_data grasshopper_buttons_data = { + .buttons = grasshopper_buttons_btn, + .nbuttons = 1, +}; + +static struct platform_device grasshopper_buttons = { + .name = "gpio-keys", + .id = -1, + .num_resources = 0, + .dev = { + .platform_data = &grasshopper_buttons_data, + }, +}; + +static int __init grasshopper_init_buttons(void) +{ + int i; + + for (i=0; i +#include +#include +#include +#include + +#include + +static struct smc_timing flash_timing __initdata = { + .ncs_read_setup = 0, + .nrd_setup = 40, + .ncs_write_setup = 0, + .nwe_setup = 10, + + .ncs_read_pulse = 80, + .nrd_pulse = 40, + .ncs_write_pulse = 65, + .nwe_pulse = 55, + + .read_cycle = 120, + .write_cycle = 120, +}; + +static struct smc_config flash_config __initdata = { + .bus_width = 2, + .nrd_controlled = 1, + .nwe_controlled = 1, + .byte_write = 1, +}; + +// To prevent trouble when flashing with Linux, take care that the same values for offsets +// and lengths are set here and in the file +// 'buildroot_basedir/project_build_avr32/grasshopper/u-boot-1.3.4/include/configs/grasshopper.h' !!! +static struct mtd_partition flash_parts[] = { + { + .name = "u-boot", + .offset = 0x00000000, + .size = 0x00020000, /* 128 KiB */ + .mask_flags = MTD_WRITEABLE, + }, + { + .name = "env", /* 64 KB */ + .offset = 0x00020000, + .size = 0x00010000, + .mask_flags = MTD_WRITEABLE, + }, + { + .name = "root", + .offset = 0x00030000, + .size = 0x007d0000, + }, +}; + +static struct physmap_flash_data flash_data = { + .width = 2, + .nr_parts = ARRAY_SIZE(flash_parts), + .parts = flash_parts, +}; + +static struct resource flash_resource = { + .start = 0x00000000, + .end = 0x007fffff, + .flags = IORESOURCE_MEM, +}; + +static struct platform_device flash_device = { + .name = "physmap-flash", + .id = 0, + .resource = &flash_resource, + .num_resources = 1, + .dev = { + .platform_data = &flash_data, + }, +}; + +/* This needs to be called after the SMC has been initialized */ +static int __init grasshopper_flash_init(void) +{ + int ret; + + smc_set_timing(&flash_config, &flash_timing); + ret = smc_set_configuration(0, &flash_config); + if (ret < 0) { + printk(KERN_ERR "grasshopper: failed to set NOR flash timing\n"); + return ret; + } + + platform_device_register(&flash_device); + + return 0; +} +device_initcall(grasshopper_flash_init); diff -Naur linux-4.7.3/arch/avr32/boards/grasshopper/Kconfig linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/Kconfig --- linux-4.7.3/arch/avr32/boards/grasshopper/Kconfig 1970-01-01 01:00:00.000000000 +0100 +++ linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/Kconfig 2016-09-13 11:23:21.454833158 +0200 @@ -0,0 +1,5 @@ +# Grasshopper customization + +if BOARD_GRASSHOPPER + +endif # BOARD_GRASSHOPPER diff -Naur linux-4.7.3/arch/avr32/boards/grasshopper/led.c linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/led.c --- linux-4.7.3/arch/avr32/boards/grasshopper/led.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/led.c 2016-09-13 11:23:21.454833158 +0200 @@ -0,0 +1,155 @@ +/* + * init code specific for grasshoppers LEDs + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + // LEDs +static struct gpio_led grasshopper_led[] = { +#ifndef CONFIG_BOARD_GRASSHOPPER_PWM0 + { + .name = "pwrled:red", + .gpio = GPIO_PIN_PA(22), + .active_low = 1, + }, +#endif + { + .name = "led1:green", + .gpio = GPIO_PIN_PA(23), + .default_trigger = "heartbeat", + }, + { + .name = "led2:green", + .gpio = GPIO_PIN_PA(24), + }, + { + .name = "led3:green", + .gpio = GPIO_PIN_PA(25), + }, + { + .name = "led4:green", + .gpio = GPIO_PIN_PA(26), + }, + { + .name = "led5:green", + .gpio = GPIO_PIN_PA(27), + }, +#ifndef CONFIG_BOARD_GRASSHOPPER_PWM0 + { + .name = "led6:green", + .gpio = GPIO_PIN_PA(28), + }, +#endif +#ifndef CONFIG_BOARD_GRASSHOPPER_PWM1 + { + .name = "led7:green", + .gpio = GPIO_PIN_PA(29), + }, +#endif + { + .name = "led8:green", + .gpio = GPIO_PIN_PA(30), + }, +}; + +static struct gpio_led_platform_data grasshopper_led_data = { + .num_leds = ARRAY_SIZE(grasshopper_led), + .leds = grasshopper_led, +}; + +static struct platform_device grasshopper_led_dev = { + .name = "leds-gpio", + .dev = { + .platform_data = &grasshopper_led_data, + }, +}; + +/* PWM */ +#ifdef CONFIG_LEDS_ATMEL_PWM +static struct gpio_led pwm_led[] = { + /* here the "gpio" is actually a PWM channel */ +#ifdef CONFIG_BOARD_GRASSHOPPER_PWM0 + { + .name = "pwm0", + .gpio = 0, + }, +#endif +#ifdef CONFIG_BOARD_GRASSHOPPER_PWM1 + { + .name = "pwm1", + .gpio = 1, + }, +#endif +#ifdef CONFIG_BOARD_GRASSHOPPER_PWM2 + { + .name = "pwm2", + .gpio = 2, + }, +#endif +#ifdef CONFIG_BOARD_GRASSHOPPER_PWM3 + { + .name = "pwm3", + .gpio = 3, + }, +#endif +}; + +static struct gpio_led_platform_data pwm_led_data = { + .num_leds = ARRAY_SIZE(pwm_led), + .leds = pwm_led, +}; + +static struct platform_device pwm_led_dev = { + .name = "leds-atmel-pwm", + .id = -1, + .dev = { + .platform_data = &pwm_led_data, + }, +}; +#endif + +static int __init grasshopper_setup_leds(void) +{ + printk("Grasshopper: Setting up %d LEDs\n", grasshopper_led_data.num_leds); + //for (i=0; i +#include +#include +#include + +#include + +#include + +/* Initialized by bootloader-specific startup code. */ +struct tag *bootloader_tags __initdata; + +/* Ethernet */ +struct eth_addr { + u8 addr[6]; +}; + +static struct eth_addr __initdata hw_addr[1]; +static struct macb_platform_data __initdata eth_data[] = { + { + .phy_mask = ~(1U << 0), + }, +}; + +/* + * The next two functions should go away as the boot loader is + * supposed to initialize the macb address registers with a valid + * ethernet address. But we need to keep it around for a while until + * we can be reasonably sure the boot loader does this. + * + * The phy_id is ignored as the driver will probe for it. + */ +static int __init parse_tag_ethernet(struct tag *tag) +{ + int i; + + i = tag->u.ethernet.mac_index; + if (i < ARRAY_SIZE(hw_addr)) + memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address, + sizeof(hw_addr[i].addr)); + + return 0; +} +__tagtable(ATAG_ETHERNET, parse_tag_ethernet); + +static void __init set_hw_addr(struct platform_device *pdev) +{ + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + const u8 *addr; + void __iomem *regs; + struct clk *pclk; + + if (!res) + return; + if (pdev->id >= ARRAY_SIZE(hw_addr)) + return; + + addr = hw_addr[pdev->id].addr; + if (!is_valid_ether_addr(addr)) + return; + + /* + * Since this is board-specific code, we'll cheat and use the + * physical address directly as we happen to know that it's + * the same as the virtual address. + */ + regs = (void __iomem __force *)res->start; + pclk = clk_get(&pdev->dev, "pclk"); + if (!pclk) + return; + + clk_enable(pclk); + __raw_writel((addr[3] << 24) | (addr[2] << 16) + | (addr[1] << 8) | addr[0], regs + 0x98); + __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c); + clk_disable(pclk); + clk_put(pclk); +} + +static int __init grasshopper_init_mac(void) +{ + printk("Grasshopper: Setting up Ethernet\n"); + set_hw_addr(at32_add_device_eth(0, ð_data[0])); + + return 0; +} +arch_initcall(grasshopper_init_mac); diff -Naur linux-4.7.3/arch/avr32/boards/grasshopper/Makefile linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/Makefile --- linux-4.7.3/arch/avr32/boards/grasshopper/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/Makefile 2016-09-13 11:23:21.454833158 +0200 @@ -0,0 +1,5 @@ +obj-y += button.o +obj-y += flash.o +obj-y += led.o +obj-y += mac.o +obj-y += setup.o diff -Naur linux-4.7.3/arch/avr32/boards/grasshopper/setup.c linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/setup.c --- linux-4.7.3/arch/avr32/boards/grasshopper/setup.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-4.7.3.grasshopper/arch/avr32/boards/grasshopper/setup.c 2016-09-13 11:23:21.454833158 +0200 @@ -0,0 +1,210 @@ +/* + * init code specific for grasshopper + * + * based on icnova_base.c from in-circuit.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include