Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: i.MX: mx21ads: Replace direct handling of peripheral bits with GPIOs

This patch replaces direct handling of peripheral bits with GPIOs by
using basic-mmio-gpio driver. As a result this change eliminate some
low-level code and removes custom io_map() from the board.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>

authored by

Alexander Shiyan and committed by
Shawn Guo
477fbf1d d1db0eea

+66 -70
+66 -70
arch/arm/mach-imx/mach-mx21ads.c
··· 17 17 #include <linux/platform_device.h> 18 18 #include <linux/mtd/mtd.h> 19 19 #include <linux/mtd/physmap.h> 20 + #include <linux/basic_mmio_gpio.h> 20 21 #include <linux/gpio.h> 21 22 #include <asm/mach-types.h> 22 23 #include <asm/mach/arch.h> 23 24 #include <asm/mach/time.h> 24 - #include <asm/mach/map.h> 25 25 26 26 #include "common.h" 27 27 #include "devices-imx21.h" 28 28 #include "hardware.h" 29 29 #include "iomux-mx21.h" 30 30 31 - /* 32 - * Memory-mapped I/O on MX21ADS base board 33 - */ 34 - #define MX21ADS_MMIO_BASE_ADDR 0xf5000000 35 - #define MX21ADS_MMIO_SIZE 0xc00000 31 + #define MX21ADS_CS8900A_REG (MX21_CS1_BASE_ADDR + 0x000000) 32 + #define MX21ADS_ST16C255_IOBASE_REG (MX21_CS1_BASE_ADDR + 0x200000) 33 + #define MX21ADS_VERSION_REG (MX21_CS1_BASE_ADDR + 0x400000) 34 + #define MX21ADS_IO_REG (MX21_CS1_BASE_ADDR + 0x800000) 36 35 37 - #define MX21ADS_REG_ADDR(offset) (void __force __iomem *) \ 38 - (MX21ADS_MMIO_BASE_ADDR + (offset)) 39 - 40 - #define MX21ADS_CS8900A_MMIO_SIZE 0x200000 41 - #define MX21ADS_CS8900A_IRQ_GPIO IMX_GPIO_NR(5, 11) 42 - #define MX21ADS_ST16C255_IOBASE_REG MX21ADS_REG_ADDR(0x200000) 43 - #define MX21ADS_VERSION_REG MX21ADS_REG_ADDR(0x400000) 44 - #define MX21ADS_IO_REG MX21ADS_REG_ADDR(0x800000) 36 + #define MX21ADS_MMC_CD IMX_GPIO_NR(4, 25) 37 + #define MX21ADS_CS8900A_IRQ_GPIO IMX_GPIO_NR(5, 11) 38 + #define MX21ADS_MMGPIO_BASE (6 * 32) 45 39 46 40 /* MX21ADS_IO_REG bit definitions */ 47 - #define MX21ADS_IO_SD_WP 0x0001 /* read */ 48 - #define MX21ADS_IO_TP6 0x0001 /* write */ 49 - #define MX21ADS_IO_SW_SEL 0x0002 /* read */ 50 - #define MX21ADS_IO_TP7 0x0002 /* write */ 51 - #define MX21ADS_IO_RESET_E_UART 0x0004 52 - #define MX21ADS_IO_RESET_BASE 0x0008 53 - #define MX21ADS_IO_CSI_CTL2 0x0010 54 - #define MX21ADS_IO_CSI_CTL1 0x0020 55 - #define MX21ADS_IO_CSI_CTL0 0x0040 56 - #define MX21ADS_IO_UART1_EN 0x0080 57 - #define MX21ADS_IO_UART4_EN 0x0100 58 - #define MX21ADS_IO_LCDON 0x0200 59 - #define MX21ADS_IO_IRDA_EN 0x0400 60 - #define MX21ADS_IO_IRDA_FIR_SEL 0x0800 61 - #define MX21ADS_IO_IRDA_MD0_B 0x1000 62 - #define MX21ADS_IO_IRDA_MD1 0x2000 63 - #define MX21ADS_IO_LED4_ON 0x4000 64 - #define MX21ADS_IO_LED3_ON 0x8000 41 + #define MX21ADS_IO_SD_WP (MX21ADS_MMGPIO_BASE + 0) 42 + #define MX21ADS_IO_TP6 (MX21ADS_IO_SD_WP) 43 + #define MX21ADS_IO_SW_SEL (MX21ADS_MMGPIO_BASE + 1) 44 + #define MX21ADS_IO_TP7 (MX21ADS_IO_SW_SEL) 45 + #define MX21ADS_IO_RESET_E_UART (MX21ADS_MMGPIO_BASE + 2) 46 + #define MX21ADS_IO_RESET_BASE (MX21ADS_MMGPIO_BASE + 3) 47 + #define MX21ADS_IO_CSI_CTL2 (MX21ADS_MMGPIO_BASE + 4) 48 + #define MX21ADS_IO_CSI_CTL1 (MX21ADS_MMGPIO_BASE + 5) 49 + #define MX21ADS_IO_CSI_CTL0 (MX21ADS_MMGPIO_BASE + 6) 50 + #define MX21ADS_IO_UART1_EN (MX21ADS_MMGPIO_BASE + 7) 51 + #define MX21ADS_IO_UART4_EN (MX21ADS_MMGPIO_BASE + 8) 52 + #define MX21ADS_IO_LCDON (MX21ADS_MMGPIO_BASE + 9) 53 + #define MX21ADS_IO_IRDA_EN (MX21ADS_MMGPIO_BASE + 10) 54 + #define MX21ADS_IO_IRDA_FIR_SEL (MX21ADS_MMGPIO_BASE + 11) 55 + #define MX21ADS_IO_IRDA_MD0_B (MX21ADS_MMGPIO_BASE + 12) 56 + #define MX21ADS_IO_IRDA_MD1 (MX21ADS_MMGPIO_BASE + 13) 57 + #define MX21ADS_IO_LED4_ON (MX21ADS_MMGPIO_BASE + 14) 58 + #define MX21ADS_IO_LED3_ON (MX21ADS_MMGPIO_BASE + 15) 65 59 66 60 static const int mx21ads_pins[] __initconst = { 67 61 ··· 154 160 }; 155 161 156 162 static struct resource mx21ads_cs8900_resources[] __initdata = { 157 - DEFINE_RES_MEM(MX21_CS1_BASE_ADDR, MX21ADS_CS8900A_MMIO_SIZE), 163 + DEFINE_RES_MEM(MX21_CS1_BASE_ADDR, SZ_1K), 158 164 /* irq number is run-time assigned */ 159 165 DEFINE_RES_IRQ(-1), 160 166 }; ··· 173 179 static const struct imxuart_platform_data uart_pdata_norts __initconst = { 174 180 }; 175 181 182 + static struct resource mx21ads_mmgpio_resource = 183 + DEFINE_RES_MEM_NAMED(MX21ADS_IO_REG, SZ_2, "dat"); 184 + 185 + static struct bgpio_pdata mx21ads_mmgpio_pdata = { 186 + .base = MX21ADS_MMGPIO_BASE, 187 + .ngpio = 16, 188 + }; 189 + 190 + static struct platform_device mx21ads_mmgpio = { 191 + .name = "basic-mmio-gpio", 192 + .id = PLATFORM_DEVID_AUTO, 193 + .resource = &mx21ads_mmgpio_resource, 194 + .num_resources = 1, 195 + .dev = { 196 + .platform_data = &mx21ads_mmgpio_pdata, 197 + }, 198 + }; 199 + 176 200 static int mx21ads_fb_init(struct platform_device *pdev) 177 201 { 178 - u16 tmp; 202 + int ret; 179 203 180 - tmp = __raw_readw(MX21ADS_IO_REG); 181 - tmp |= MX21ADS_IO_LCDON; 182 - __raw_writew(tmp, MX21ADS_IO_REG); 183 - return 0; 204 + ret = gpio_request(MX21ADS_IO_LCDON, "fb-lcdon"); 205 + if (ret) 206 + return ret; 207 + 208 + return gpio_direction_output(MX21ADS_IO_LCDON, 1); 184 209 } 185 210 186 211 static void mx21ads_fb_exit(struct platform_device *pdev) 187 212 { 188 - u16 tmp; 189 - 190 - tmp = __raw_readw(MX21ADS_IO_REG); 191 - tmp &= ~MX21ADS_IO_LCDON; 192 - __raw_writew(tmp, MX21ADS_IO_REG); 213 + gpio_set_value(MX21ADS_IO_LCDON, 0); 214 + gpio_free(MX21ADS_IO_LCDON); 193 215 } 194 216 195 217 /* ··· 246 236 247 237 static int mx21ads_sdhc_get_ro(struct device *dev) 248 238 { 249 - return (__raw_readw(MX21ADS_IO_REG) & MX21ADS_IO_SD_WP) ? 1 : 0; 239 + return gpio_get_value(MX21ADS_IO_SD_WP); 250 240 } 251 241 252 242 static int mx21ads_sdhc_init(struct device *dev, irq_handler_t detect_irq, 253 243 void *data) 254 244 { 255 - return request_irq(gpio_to_irq(IMX_GPIO_NR(4, 25)), detect_irq, 256 - IRQF_TRIGGER_FALLING, "mmc-detect", data); 245 + int ret; 246 + 247 + ret = gpio_request(MX21ADS_IO_SD_WP, "mmc-ro"); 248 + if (ret) 249 + return ret; 250 + 251 + return request_irq(gpio_to_irq(MX21ADS_MMC_CD), detect_irq, 252 + IRQF_TRIGGER_FALLING, "mmc-detect", data); 257 253 } 258 254 259 255 static void mx21ads_sdhc_exit(struct device *dev, void *data) 260 256 { 261 - free_irq(gpio_to_irq(IMX_GPIO_NR(4, 25)), data); 257 + free_irq(gpio_to_irq(MX21ADS_MMC_CD), data); 258 + gpio_free(MX21ADS_IO_SD_WP); 262 259 } 263 260 264 261 static const struct imxmmc_platform_data mx21ads_sdhc_pdata __initconst = { ··· 281 264 .hw_ecc = 1, 282 265 }; 283 266 284 - static struct map_desc mx21ads_io_desc[] __initdata = { 285 - /* 286 - * Memory-mapped I/O on MX21ADS Base board: 287 - * - CS8900A Ethernet controller 288 - * - ST16C2552CJ UART 289 - * - CPU and Base board version 290 - * - Base board I/O register 291 - */ 292 - { 293 - .virtual = MX21ADS_MMIO_BASE_ADDR, 294 - .pfn = __phys_to_pfn(MX21_CS1_BASE_ADDR), 295 - .length = MX21ADS_MMIO_SIZE, 296 - .type = MT_DEVICE, 297 - }, 298 - }; 299 - 300 - static void __init mx21ads_map_io(void) 301 - { 302 - mx21_map_io(); 303 - iotable_init(mx21ads_io_desc, ARRAY_SIZE(mx21ads_io_desc)); 304 - } 305 - 306 267 static struct platform_device *platform_devices[] __initdata = { 268 + &mx21ads_mmgpio, 307 269 &mx21ads_nor_mtd_device, 308 270 }; 309 271 ··· 317 321 MACHINE_START(MX21ADS, "Freescale i.MX21ADS") 318 322 /* maintainer: Freescale Semiconductor, Inc. */ 319 323 .atag_offset = 0x100, 320 - .map_io = mx21ads_map_io, 324 + .map_io = mx21_map_io, 321 325 .init_early = imx21_init_early, 322 326 .init_irq = mx21_init_irq, 323 327 .handle_irq = imx21_handle_irq,