Merge remote-tracking branch 'spi/fix/core' into spi-linus
[linux-drm-fsl-dcu.git] / arch / arm / mach-kirkwood / lacie_v2-common.c
1 /*
2  * arch/arm/mach-kirkwood/lacie_v2-common.c
3  *
4  * This file is licensed under the terms of the GNU General Public
5  * License version 2.  This program is licensed "as is" without any
6  * warranty of any kind, whether express or implied.
7  */
8
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/mtd/physmap.h>
12 #include <linux/spi/flash.h>
13 #include <linux/spi/spi.h>
14 #include <linux/i2c.h>
15 #include <linux/platform_data/at24.h>
16 #include <linux/gpio.h>
17 #include <asm/mach/time.h>
18 #include <mach/kirkwood.h>
19 #include <mach/irqs.h>
20 #include <plat/time.h>
21 #include "common.h"
22 #include "lacie_v2-common.h"
23
24 /*****************************************************************************
25  * 512KB SPI Flash on Boot Device (MACRONIX MX25L4005)
26  ****************************************************************************/
27
28 static struct mtd_partition lacie_v2_flash_parts[] = {
29         {
30                 .name = "u-boot",
31                 .size = MTDPART_SIZ_FULL,
32                 .offset = 0,
33                 .mask_flags = MTD_WRITEABLE, /* force read-only */
34         },
35 };
36
37 static const struct flash_platform_data lacie_v2_flash = {
38         .type           = "mx25l4005a",
39         .name           = "spi_flash",
40         .parts          = lacie_v2_flash_parts,
41         .nr_parts       = ARRAY_SIZE(lacie_v2_flash_parts),
42 };
43
44 static struct spi_board_info __initdata lacie_v2_spi_slave_info[] = {
45         {
46                 .modalias       = "m25p80",
47                 .platform_data  = &lacie_v2_flash,
48                 .irq            = -1,
49                 .max_speed_hz   = 20000000,
50                 .bus_num        = 0,
51                 .chip_select    = 0,
52         },
53 };
54
55 void __init lacie_v2_register_flash(void)
56 {
57         spi_register_board_info(lacie_v2_spi_slave_info,
58                                 ARRAY_SIZE(lacie_v2_spi_slave_info));
59         kirkwood_spi_init();
60 }
61
62 /*****************************************************************************
63  * I2C devices
64  ****************************************************************************/
65
66 static struct at24_platform_data at24c04 = {
67         .byte_len       = SZ_4K / 8,
68         .page_size      = 16,
69 };
70
71 /*
72  * i2c addr | chip         | description
73  * 0x50     | HT24LC04     | eeprom (512B)
74  */
75
76 static struct i2c_board_info __initdata lacie_v2_i2c_info[] = {
77         {
78                 I2C_BOARD_INFO("24c04", 0x50),
79                 .platform_data  = &at24c04,
80         }
81 };
82
83 void __init lacie_v2_register_i2c_devices(void)
84 {
85         kirkwood_i2c_init();
86         i2c_register_board_info(0, lacie_v2_i2c_info,
87                                 ARRAY_SIZE(lacie_v2_i2c_info));
88 }
89
90 /*****************************************************************************
91  * Hard Disk power
92  ****************************************************************************/
93
94 static int __initdata lacie_v2_gpio_hdd_power[] = { 16, 17, 41, 42, 43 };
95
96 void __init lacie_v2_hdd_power_init(int hdd_num)
97 {
98         int i;
99         int err;
100
101         /* Power up all hard disks. */
102         for (i = 0; i < hdd_num; i++) {
103                 err = gpio_request(lacie_v2_gpio_hdd_power[i], NULL);
104                 if (err == 0) {
105                         err = gpio_direction_output(
106                                         lacie_v2_gpio_hdd_power[i], 1);
107                         /* Free the HDD power GPIOs. This allow user-space to
108                          * configure them via the gpiolib sysfs interface. */
109                         gpio_free(lacie_v2_gpio_hdd_power[i]);
110                 }
111                 if (err)
112                         pr_err("Failed to power up HDD%d\n", i + 1);
113         }
114 }