MIPS: ath79: add common SPI controller device

Several boards are using the built-in SPI controller of the
AR71XX/AR724X/AR913X SoCs. This patch adds common platform_device
and helper code to register it. Additionally, the patch registers
the SPI bus on the PB44 board.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Cc: linux-mips@linux-mips.org
Cc: Imre Kaloz <kaloz@openwrt.org>
Cc: Luis R. Rodriguez <lrodriguez@atheros.com>
Cc: Cliff Holden <Cliff.Holden@Atheros.com>
Cc: Kathy Giori <Kathy.Giori@Atheros.com>
Patchwork: https://patchwork.linux-mips.org/patch/1956/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by Gabor Juhos and committed by Ralf Baechle 68a1d316 8efaef4d

+84
+4
arch/mips/ath79/Kconfig
··· 7 select SOC_AR71XX 8 select ATH79_DEV_GPIO_BUTTONS 9 select ATH79_DEV_LEDS_GPIO 10 help 11 Say 'Y' here if you want your kernel to support the 12 Atheros PB44 reference board. ··· 27 def_bool n 28 29 config ATH79_DEV_LEDS_GPIO 30 def_bool n 31 32 endif
··· 7 select SOC_AR71XX 8 select ATH79_DEV_GPIO_BUTTONS 9 select ATH79_DEV_LEDS_GPIO 10 + select ATH79_DEV_SPI 11 help 12 Say 'Y' here if you want your kernel to support the 13 Atheros PB44 reference board. ··· 26 def_bool n 27 28 config ATH79_DEV_LEDS_GPIO 29 + def_bool n 30 + 31 + config ATH79_DEV_SPI 32 def_bool n 33 34 endif
+1
arch/mips/ath79/Makefile
··· 18 obj-y += dev-common.o 19 obj-$(CONFIG_ATH79_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o 20 obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o 21 22 # 23 # Machines
··· 18 obj-y += dev-common.o 19 obj-$(CONFIG_ATH79_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o 20 obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o 21 + obj-$(CONFIG_ATH79_DEV_SPI) += dev-spi.o 22 23 # 24 # Machines
+38
arch/mips/ath79/dev-spi.c
···
··· 1 + /* 2 + * Atheros AR71XX/AR724X/AR913X SPI controller device 3 + * 4 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org> 5 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/platform_device.h> 13 + #include <asm/mach-ath79/ar71xx_regs.h> 14 + #include "dev-spi.h" 15 + 16 + static struct resource ath79_spi_resources[] = { 17 + { 18 + .start = AR71XX_SPI_BASE, 19 + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1, 20 + .flags = IORESOURCE_MEM, 21 + }, 22 + }; 23 + 24 + static struct platform_device ath79_spi_device = { 25 + .name = "ath79-spi", 26 + .id = -1, 27 + .resource = ath79_spi_resources, 28 + .num_resources = ARRAY_SIZE(ath79_spi_resources), 29 + }; 30 + 31 + void __init ath79_register_spi(struct ath79_spi_platform_data *pdata, 32 + struct spi_board_info const *info, 33 + unsigned n) 34 + { 35 + spi_register_board_info(info, n); 36 + ath79_spi_device.dev.platform_data = pdata; 37 + platform_device_register(&ath79_spi_device); 38 + }
+22
arch/mips/ath79/dev-spi.h
···
··· 1 + /* 2 + * Atheros AR71XX/AR724X/AR913X SPI controller device 3 + * 4 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org> 5 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #ifndef _ATH79_DEV_SPI_H 13 + #define _ATH79_DEV_SPI_H 14 + 15 + #include <linux/spi/spi.h> 16 + #include <asm/mach-ath79/ath79_spi_platform.h> 17 + 18 + void ath79_register_spi(struct ath79_spi_platform_data *pdata, 19 + struct spi_board_info const *info, 20 + unsigned n); 21 + 22 + #endif /* _ATH79_DEV_SPI_H */
+17
arch/mips/ath79/mach-pb44.c
··· 17 #include "machtypes.h" 18 #include "dev-gpio-buttons.h" 19 #include "dev-leds-gpio.h" 20 21 #define PB44_GPIO_I2C_SCL 0 22 #define PB44_GPIO_I2C_SDA 1 ··· 85 } 86 }; 87 88 static void __init pb44_init(void) 89 { 90 i2c_register_board_info(0, pb44_i2c_board_info, ··· 110 ath79_register_gpio_keys_polled(-1, PB44_KEYS_POLL_INTERVAL, 111 ARRAY_SIZE(pb44_gpio_keys), 112 pb44_gpio_keys); 113 } 114 115 MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",
··· 17 #include "machtypes.h" 18 #include "dev-gpio-buttons.h" 19 #include "dev-leds-gpio.h" 20 + #include "dev-spi.h" 21 22 #define PB44_GPIO_I2C_SCL 0 23 #define PB44_GPIO_I2C_SDA 1 ··· 84 } 85 }; 86 87 + static struct spi_board_info pb44_spi_info[] = { 88 + { 89 + .bus_num = 0, 90 + .chip_select = 0, 91 + .max_speed_hz = 25000000, 92 + .modalias = "m25p64", 93 + }, 94 + }; 95 + 96 + static struct ath79_spi_platform_data pb44_spi_data = { 97 + .bus_num = 0, 98 + .num_chipselect = 1, 99 + }; 100 + 101 static void __init pb44_init(void) 102 { 103 i2c_register_board_info(0, pb44_i2c_board_info, ··· 95 ath79_register_gpio_keys_polled(-1, PB44_KEYS_POLL_INTERVAL, 96 ARRAY_SIZE(pb44_gpio_keys), 97 pb44_gpio_keys); 98 + ath79_register_spi(&pb44_spi_data, pb44_spi_info, 99 + ARRAY_SIZE(pb44_spi_info)); 100 } 101 102 MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",
+2
arch/mips/include/asm/mach-ath79/ar71xx_regs.h
··· 20 #include <linux/bitops.h> 21 22 #define AR71XX_APB_BASE 0x18000000 23 24 #define AR71XX_DDR_CTRL_BASE (AR71XX_APB_BASE + 0x00000000) 25 #define AR71XX_DDR_CTRL_SIZE 0x100
··· 20 #include <linux/bitops.h> 21 22 #define AR71XX_APB_BASE 0x18000000 23 + #define AR71XX_SPI_BASE 0x1f000000 24 + #define AR71XX_SPI_SIZE 0x01000000 25 26 #define AR71XX_DDR_CTRL_BASE (AR71XX_APB_BASE + 0x00000000) 27 #define AR71XX_DDR_CTRL_SIZE 0x100