18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/arm/mach-ep93xx/snappercl15.c 48c2ecf20Sopenharmony_ci * Bluewater Systems Snapper CL15 system module 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2009 Bluewater Systems Ltd 78c2ecf20Sopenharmony_ci * Author: Ryan Mallon 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * NAND code adapted from driver by: 108c2ecf20Sopenharmony_ci * Andre Renaud <andre@bluewatersys.com> 118c2ecf20Sopenharmony_ci * James R. McKaskill 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 158c2ecf20Sopenharmony_ci#include <linux/kernel.h> 168c2ecf20Sopenharmony_ci#include <linux/init.h> 178c2ecf20Sopenharmony_ci#include <linux/io.h> 188c2ecf20Sopenharmony_ci#include <linux/i2c.h> 198c2ecf20Sopenharmony_ci#include <linux/fb.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include <linux/mtd/platnand.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include "hardware.h" 248c2ecf20Sopenharmony_ci#include <linux/platform_data/video-ep93xx.h> 258c2ecf20Sopenharmony_ci#include "gpio-ep93xx.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include <asm/mach-types.h> 288c2ecf20Sopenharmony_ci#include <asm/mach/arch.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include "soc.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define SNAPPERCL15_NAND_BASE (EP93XX_CS7_PHYS_BASE + SZ_16M) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define SNAPPERCL15_NAND_WPN (1 << 8) /* Write protect (active low) */ 358c2ecf20Sopenharmony_ci#define SNAPPERCL15_NAND_ALE (1 << 9) /* Address latch */ 368c2ecf20Sopenharmony_ci#define SNAPPERCL15_NAND_CLE (1 << 10) /* Command latch */ 378c2ecf20Sopenharmony_ci#define SNAPPERCL15_NAND_CEN (1 << 11) /* Chip enable (active low) */ 388c2ecf20Sopenharmony_ci#define SNAPPERCL15_NAND_RDY (1 << 14) /* Device ready */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define NAND_CTRL_ADDR(chip) (chip->legacy.IO_ADDR_W + 0x40) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic void snappercl15_nand_cmd_ctrl(struct nand_chip *chip, int cmd, 438c2ecf20Sopenharmony_ci unsigned int ctrl) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci static u16 nand_state = SNAPPERCL15_NAND_WPN; 468c2ecf20Sopenharmony_ci u16 set; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci if (ctrl & NAND_CTRL_CHANGE) { 498c2ecf20Sopenharmony_ci set = SNAPPERCL15_NAND_CEN | SNAPPERCL15_NAND_WPN; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci if (ctrl & NAND_NCE) 528c2ecf20Sopenharmony_ci set &= ~SNAPPERCL15_NAND_CEN; 538c2ecf20Sopenharmony_ci if (ctrl & NAND_CLE) 548c2ecf20Sopenharmony_ci set |= SNAPPERCL15_NAND_CLE; 558c2ecf20Sopenharmony_ci if (ctrl & NAND_ALE) 568c2ecf20Sopenharmony_ci set |= SNAPPERCL15_NAND_ALE; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci nand_state &= ~(SNAPPERCL15_NAND_CEN | 598c2ecf20Sopenharmony_ci SNAPPERCL15_NAND_CLE | 608c2ecf20Sopenharmony_ci SNAPPERCL15_NAND_ALE); 618c2ecf20Sopenharmony_ci nand_state |= set; 628c2ecf20Sopenharmony_ci __raw_writew(nand_state, NAND_CTRL_ADDR(chip)); 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci if (cmd != NAND_CMD_NONE) 668c2ecf20Sopenharmony_ci __raw_writew((cmd & 0xff) | nand_state, 678c2ecf20Sopenharmony_ci chip->legacy.IO_ADDR_W); 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic int snappercl15_nand_dev_ready(struct nand_chip *chip) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic struct mtd_partition snappercl15_nand_parts[] = { 768c2ecf20Sopenharmony_ci { 778c2ecf20Sopenharmony_ci .name = "Kernel", 788c2ecf20Sopenharmony_ci .offset = 0, 798c2ecf20Sopenharmony_ci .size = SZ_2M, 808c2ecf20Sopenharmony_ci }, 818c2ecf20Sopenharmony_ci { 828c2ecf20Sopenharmony_ci .name = "Filesystem", 838c2ecf20Sopenharmony_ci .offset = MTDPART_OFS_APPEND, 848c2ecf20Sopenharmony_ci .size = MTDPART_SIZ_FULL, 858c2ecf20Sopenharmony_ci }, 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic struct platform_nand_data snappercl15_nand_data = { 898c2ecf20Sopenharmony_ci .chip = { 908c2ecf20Sopenharmony_ci .nr_chips = 1, 918c2ecf20Sopenharmony_ci .partitions = snappercl15_nand_parts, 928c2ecf20Sopenharmony_ci .nr_partitions = ARRAY_SIZE(snappercl15_nand_parts), 938c2ecf20Sopenharmony_ci .chip_delay = 25, 948c2ecf20Sopenharmony_ci }, 958c2ecf20Sopenharmony_ci .ctrl = { 968c2ecf20Sopenharmony_ci .dev_ready = snappercl15_nand_dev_ready, 978c2ecf20Sopenharmony_ci .cmd_ctrl = snappercl15_nand_cmd_ctrl, 988c2ecf20Sopenharmony_ci }, 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic struct resource snappercl15_nand_resource[] = { 1028c2ecf20Sopenharmony_ci { 1038c2ecf20Sopenharmony_ci .start = SNAPPERCL15_NAND_BASE, 1048c2ecf20Sopenharmony_ci .end = SNAPPERCL15_NAND_BASE + SZ_4K - 1, 1058c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 1068c2ecf20Sopenharmony_ci }, 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic struct platform_device snappercl15_nand_device = { 1108c2ecf20Sopenharmony_ci .name = "gen_nand", 1118c2ecf20Sopenharmony_ci .id = -1, 1128c2ecf20Sopenharmony_ci .dev.platform_data = &snappercl15_nand_data, 1138c2ecf20Sopenharmony_ci .resource = snappercl15_nand_resource, 1148c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(snappercl15_nand_resource), 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistatic struct ep93xx_eth_data __initdata snappercl15_eth_data = { 1188c2ecf20Sopenharmony_ci .phy_id = 1, 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic struct i2c_board_info __initdata snappercl15_i2c_data[] = { 1228c2ecf20Sopenharmony_ci { 1238c2ecf20Sopenharmony_ci /* Audio codec */ 1248c2ecf20Sopenharmony_ci I2C_BOARD_INFO("tlv320aic23", 0x1a), 1258c2ecf20Sopenharmony_ci }, 1268c2ecf20Sopenharmony_ci}; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic struct ep93xxfb_mach_info __initdata snappercl15_fb_info = { 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic struct platform_device snappercl15_audio_device = { 1328c2ecf20Sopenharmony_ci .name = "snappercl15-audio", 1338c2ecf20Sopenharmony_ci .id = -1, 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic void __init snappercl15_register_audio(void) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci ep93xx_register_i2s(); 1398c2ecf20Sopenharmony_ci platform_device_register(&snappercl15_audio_device); 1408c2ecf20Sopenharmony_ci} 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cistatic void __init snappercl15_init_machine(void) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci ep93xx_init_devices(); 1458c2ecf20Sopenharmony_ci ep93xx_register_eth(&snappercl15_eth_data, 1); 1468c2ecf20Sopenharmony_ci ep93xx_register_i2c(snappercl15_i2c_data, 1478c2ecf20Sopenharmony_ci ARRAY_SIZE(snappercl15_i2c_data)); 1488c2ecf20Sopenharmony_ci ep93xx_register_fb(&snappercl15_fb_info); 1498c2ecf20Sopenharmony_ci snappercl15_register_audio(); 1508c2ecf20Sopenharmony_ci platform_device_register(&snappercl15_nand_device); 1518c2ecf20Sopenharmony_ci} 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ciMACHINE_START(SNAPPER_CL15, "Bluewater Systems Snapper CL15") 1548c2ecf20Sopenharmony_ci /* Maintainer: Ryan Mallon */ 1558c2ecf20Sopenharmony_ci .atag_offset = 0x100, 1568c2ecf20Sopenharmony_ci .map_io = ep93xx_map_io, 1578c2ecf20Sopenharmony_ci .init_irq = ep93xx_init_irq, 1588c2ecf20Sopenharmony_ci .init_time = ep93xx_timer_init, 1598c2ecf20Sopenharmony_ci .init_machine = snappercl15_init_machine, 1608c2ecf20Sopenharmony_ci .init_late = ep93xx_init_late, 1618c2ecf20Sopenharmony_ci .restart = ep93xx_restart, 1628c2ecf20Sopenharmony_ciMACHINE_END 163