dns320l-setup.c
author andy
Fri, 06 Sep 2013 00:08:26 +0200
changeset 2 459c75093fd1
child 3 f2f1be1cc4ba
permissions -rw-r--r--
Update DNS320L support patch
/*
 * arch/arm/mach-kirkwood/dns320l-setup.c
 *
 * D-Link DNS-320L Setup File
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/ata_platform.h>
#include <linux/mtd/partitions.h>
#include <linux/mv643xx_eth.h>
#include <linux/gpio.h>
#include <linux/leds.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <mach/kirkwood.h>
#include "common.h"
#include "mpp.h"
#include <linux/sysfs.h>
#include <linux/kobject.h>
#include <linux/mtd/nand.h>
#include <linux/i2c.h>
#include <linux/gpio_keys.h>
#include <linux/gpio-fan.h>
#include <linux/input.h>

#define DNS320L_GPIO_LED_SATA1          20
#define DNS320L_GPIO_LED_SATA0          21
#define DNS320L_GPIO_POWER_SATA         24
#define DNS320L_GPIO_LED_USB_BLUE       25
#define DNS320L_GPIO_LED_USB_ORANGE     26
#define DNS320L_GPIO_BUTTON_USB         27

static struct mtd_partition dns320l_nand_parts[] = {
	{
		.name = "u-boot",
		.offset = 0,
		.size = SZ_1M
	}, {
		.name = "uImage",
		.offset = MTDPART_OFS_NXTBLK,
		.size = 5 * SZ_1M
	}, {
		.name = "ramdisk",
		.offset = MTDPART_OFS_NXTBLK,
		.size = 5 * SZ_1M
	}, {
		.name = "image",
		.offset = MTDPART_OFS_NXTBLK,
		.size = 100 * SZ_1M
	}, {
	    .name = "rescue firmware",
	    .offset = MTDPART_OFS_NXTBLK,
	    .size = 10 * SZ_1M
	}, {
	    .name = "config",
	    .offset = MTDPART_OFS_NXTBLK,
	    .size = 5 * SZ_1M
	}, {
	    .name = "my-dlink",
	    .offset = MTDPART_OFS_NXTBLK,
	    .size = 2 * SZ_1M
	},
};


static struct mv643xx_eth_platform_data dns320l_ge00_data = {
	.phy_addr	= MV643XX_ETH_PHY_ADDR(0),
};

static struct mv_sata_platform_data dns320l_sata_data = {
	.n_ports	= 2,
};

static void __init dns320l_gpio_register(unsigned gpio, char *name, int def)
{
	if (gpio_request(gpio, name) == 0 &&
	    gpio_direction_output(gpio, 0) == 0) {
		gpio_set_value(gpio, def);
		if (gpio_export(gpio, 0) != 0)
			pr_err("dns320l: Failed to export GPIO %s\n", name);
	} else
		pr_err("dns320l: Failed to register %s\n", name);
}

/*****************************************************************************
 * Buttons
 ****************************************************************************/

static struct gpio_keys_button dns320l_button_pins[] = {
	{
		.code		= KEY_EJECTCD,
		.gpio		= DNS320L_GPIO_BUTTON_USB,
		.desc		= "USB unmount button",
		.active_low	= 1,
	}
};

static struct gpio_keys_platform_data dns320l_button_data = {
	.buttons	= dns320l_button_pins,
	.nbuttons	= ARRAY_SIZE(dns320l_button_pins),
};

static struct platform_device dns320l_button_device = {
	.name		= "gpio-keys",
	.id		= -1,
	.num_resources	= 0,
	.dev		= {
		.platform_data	= &dns320l_button_data,
	}
};

/*****************************************************************************
 * LEDs
 ****************************************************************************/

static struct gpio_led dns320l_led_pins[] = {
	{
		.name	= "dns320l:blue:usb",
		.gpio	= DNS320L_GPIO_LED_USB_BLUE,
		.default_trigger = "default-on",
	},
	{
		.name	= "dns320l:orange:usb",
		.gpio	= DNS320L_GPIO_LED_USB_ORANGE,
	},
	{
	    .name   = "dns320l:blue:sata0",
	    .gpio   = DNS320L_GPIO_LED_SATA0,
	    .default_trigger = "ide-disk"
	},
	{
	    .name   = "dns320l:blue:sata1",
	    .gpio   = DNS320L_GPIO_LED_SATA1,
	    .default_trigger = "ide-disk"
	},
//	{
//	    .name   = "dns320l:blue:power",
//	    .gpio   = DNS320L_GPIO_LED_POWER,
//	},
	
};

static struct gpio_led_platform_data dns320l_led_data = {
	.num_leds	= ARRAY_SIZE(dns320l_led_pins),
	.leds		= dns320l_led_pins,
};

static struct platform_device dns320l_led_device = {
	.name		= "leds-gpio",
	.id		= -1,
	.dev		= {
		.platform_data	= &dns320l_led_data,
	},
};

/*****************************************************************************
 * Fan
 ****************************************************************************/

static unsigned int dns320l_mpp_config[] __initdata = {
    MPP13_UART1_TXD,
	MPP14_UART1_RXD,
	MPP16_GPIO,
	MPP17_GPIO,
	MPP18_GPO,
	MPP19_GPO,
	MPP20_GPIO,    // SATA LED
	MPP21_GPIO,    // SATA LED
	MPP24_GPIO,    // SATA Power
	MPP25_GPIO,    // USB LED Blue
	MPP26_GPIO,	   // USB LED Orange
	MPP27_GPIO,	   // Button USB Copy
	MPP28_GPIO,	
	MPP29_GPIO,	 
	MPP30_GPIO,
	MPP31_GPIO,
	MPP32_GPIO,
	MPP33_GPO,
	MPP34_GPIO,	
	MPP35_GPIO,	
	MPP36_GPIO,	
	MPP37_GPIO,	
	MPP38_GPIO,
	MPP39_GPIO,	
	MPP40_GPIO,	
	MPP41_GPIO,
	MPP42_GPIO,
	MPP43_GPIO,	
	MPP44_GPIO,	
	MPP45_GPIO,	
	MPP46_GPIO,	
	MPP47_GPIO,	
	MPP48_GPIO,	
	MPP49_GPIO,
	0
};

static void __init dns320l_init(void)
{
    /*
     * Basic setup. Needs to be called early.
     */
    
    kirkwood_init();
    /* setup gpio pin select */
    kirkwood_mpp_conf(dns320l_mpp_config);
    kirkwood_uart0_init();
    kirkwood_uart1_init();
    kirkwood_nand_init(ARRAY_AND_SIZE(dns320l_nand_parts), 60);

    kirkwood_ehci_init();
    kirkwood_i2c_init();
    kirkwood_ge00_init(&dns320l_ge00_data);
    platform_device_register(&dns320l_led_device);
	dns320l_gpio_register(DNS320L_GPIO_POWER_SATA, "dns320l:power:sata", 1);
    kirkwood_sata_init(&dns320l_sata_data);
    
    platform_device_register(&dns320l_button_device);
}

MACHINE_START(DNS320L, "DNS-320L")
	/* Maintainer: Andreas Boehler <andreas@aboehler.at> */
	.boot_params	= 0x00000100,
	.init_machine	= dns320l_init,
	.map_io		= kirkwood_map_io,
	.init_early	= kirkwood_init_early,
	.init_irq	= kirkwood_init_irq,
	.timer		= &kirkwood_timer,
MACHINE_END