18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * arch/arm/mach-ep93xx/core.c
48c2ecf20Sopenharmony_ci * Core routines for Cirrus EP93xx chips.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
78c2ecf20Sopenharmony_ci * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Thanks go to Michael Burian and Ray Lehtiniemi for their key
108c2ecf20Sopenharmony_ci * role in the ep93xx linux community.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/kernel.h>
168c2ecf20Sopenharmony_ci#include <linux/init.h>
178c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
188c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
198c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
208c2ecf20Sopenharmony_ci#include <linux/sys_soc.h>
218c2ecf20Sopenharmony_ci#include <linux/irq.h>
228c2ecf20Sopenharmony_ci#include <linux/io.h>
238c2ecf20Sopenharmony_ci#include <linux/gpio.h>
248c2ecf20Sopenharmony_ci#include <linux/leds.h>
258c2ecf20Sopenharmony_ci#include <linux/termios.h>
268c2ecf20Sopenharmony_ci#include <linux/amba/bus.h>
278c2ecf20Sopenharmony_ci#include <linux/amba/serial.h>
288c2ecf20Sopenharmony_ci#include <linux/mtd/physmap.h>
298c2ecf20Sopenharmony_ci#include <linux/i2c.h>
308c2ecf20Sopenharmony_ci#include <linux/gpio/machine.h>
318c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
328c2ecf20Sopenharmony_ci#include <linux/export.h>
338c2ecf20Sopenharmony_ci#include <linux/irqchip/arm-vic.h>
348c2ecf20Sopenharmony_ci#include <linux/reboot.h>
358c2ecf20Sopenharmony_ci#include <linux/usb/ohci_pdriver.h>
368c2ecf20Sopenharmony_ci#include <linux/random.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include "hardware.h"
398c2ecf20Sopenharmony_ci#include <linux/platform_data/video-ep93xx.h>
408c2ecf20Sopenharmony_ci#include <linux/platform_data/keypad-ep93xx.h>
418c2ecf20Sopenharmony_ci#include <linux/platform_data/spi-ep93xx.h>
428c2ecf20Sopenharmony_ci#include <linux/soc/cirrus/ep93xx.h>
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#include "gpio-ep93xx.h"
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#include <asm/mach/arch.h>
478c2ecf20Sopenharmony_ci#include <asm/mach/map.h>
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#include "soc.h"
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/*************************************************************************
528c2ecf20Sopenharmony_ci * Static I/O mappings that are needed for all EP93xx platforms
538c2ecf20Sopenharmony_ci *************************************************************************/
548c2ecf20Sopenharmony_cistatic struct map_desc ep93xx_io_desc[] __initdata = {
558c2ecf20Sopenharmony_ci	{
568c2ecf20Sopenharmony_ci		.virtual	= EP93XX_AHB_VIRT_BASE,
578c2ecf20Sopenharmony_ci		.pfn		= __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
588c2ecf20Sopenharmony_ci		.length		= EP93XX_AHB_SIZE,
598c2ecf20Sopenharmony_ci		.type		= MT_DEVICE,
608c2ecf20Sopenharmony_ci	}, {
618c2ecf20Sopenharmony_ci		.virtual	= EP93XX_APB_VIRT_BASE,
628c2ecf20Sopenharmony_ci		.pfn		= __phys_to_pfn(EP93XX_APB_PHYS_BASE),
638c2ecf20Sopenharmony_ci		.length		= EP93XX_APB_SIZE,
648c2ecf20Sopenharmony_ci		.type		= MT_DEVICE,
658c2ecf20Sopenharmony_ci	},
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_civoid __init ep93xx_map_io(void)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/*************************************************************************
748c2ecf20Sopenharmony_ci * EP93xx IRQ handling
758c2ecf20Sopenharmony_ci *************************************************************************/
768c2ecf20Sopenharmony_civoid __init ep93xx_init_irq(void)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
798c2ecf20Sopenharmony_ci	vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/*************************************************************************
848c2ecf20Sopenharmony_ci * EP93xx System Controller Software Locked register handling
858c2ecf20Sopenharmony_ci *************************************************************************/
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/*
888c2ecf20Sopenharmony_ci * syscon_swlock prevents anything else from writing to the syscon
898c2ecf20Sopenharmony_ci * block while a software locked register is being written.
908c2ecf20Sopenharmony_ci */
918c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(syscon_swlock);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_civoid ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	unsigned long flags;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	spin_lock_irqsave(&syscon_swlock, flags);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	__raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
1008c2ecf20Sopenharmony_ci	__raw_writel(val, reg);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&syscon_swlock, flags);
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_civoid ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	unsigned long flags;
1088c2ecf20Sopenharmony_ci	unsigned int val;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	spin_lock_irqsave(&syscon_swlock, flags);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	val = __raw_readl(EP93XX_SYSCON_DEVCFG);
1138c2ecf20Sopenharmony_ci	val &= ~clear_bits;
1148c2ecf20Sopenharmony_ci	val |= set_bits;
1158c2ecf20Sopenharmony_ci	__raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
1168c2ecf20Sopenharmony_ci	__raw_writel(val, EP93XX_SYSCON_DEVCFG);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&syscon_swlock, flags);
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/**
1228c2ecf20Sopenharmony_ci * ep93xx_chip_revision() - returns the EP93xx chip revision
1238c2ecf20Sopenharmony_ci *
1248c2ecf20Sopenharmony_ci * See "platform.h" for more information.
1258c2ecf20Sopenharmony_ci */
1268c2ecf20Sopenharmony_ciunsigned int ep93xx_chip_revision(void)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	unsigned int v;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	v = __raw_readl(EP93XX_SYSCON_SYSCFG);
1318c2ecf20Sopenharmony_ci	v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
1328c2ecf20Sopenharmony_ci	v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
1338c2ecf20Sopenharmony_ci	return v;
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ep93xx_chip_revision);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/*************************************************************************
1388c2ecf20Sopenharmony_ci * EP93xx GPIO
1398c2ecf20Sopenharmony_ci *************************************************************************/
1408c2ecf20Sopenharmony_cistatic struct resource ep93xx_gpio_resource[] = {
1418c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_GPIO_PHYS_BASE, 0xcc),
1428c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO_AB),
1438c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO0MUX),
1448c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO1MUX),
1458c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO2MUX),
1468c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO3MUX),
1478c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO4MUX),
1488c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO5MUX),
1498c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO6MUX),
1508c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_GPIO7MUX),
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_gpio_device = {
1548c2ecf20Sopenharmony_ci	.name		= "gpio-ep93xx",
1558c2ecf20Sopenharmony_ci	.id		= -1,
1568c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_gpio_resource),
1578c2ecf20Sopenharmony_ci	.resource	= ep93xx_gpio_resource,
1588c2ecf20Sopenharmony_ci};
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/*************************************************************************
1618c2ecf20Sopenharmony_ci * EP93xx peripheral handling
1628c2ecf20Sopenharmony_ci *************************************************************************/
1638c2ecf20Sopenharmony_ci#define EP93XX_UART_MCR_OFFSET		(0x0100)
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic void ep93xx_uart_set_mctrl(struct amba_device *dev,
1668c2ecf20Sopenharmony_ci				  void __iomem *base, unsigned int mctrl)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	unsigned int mcr;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	mcr = 0;
1718c2ecf20Sopenharmony_ci	if (mctrl & TIOCM_RTS)
1728c2ecf20Sopenharmony_ci		mcr |= 2;
1738c2ecf20Sopenharmony_ci	if (mctrl & TIOCM_DTR)
1748c2ecf20Sopenharmony_ci		mcr |= 1;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	__raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
1778c2ecf20Sopenharmony_ci}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic struct amba_pl010_data ep93xx_uart_data = {
1808c2ecf20Sopenharmony_ci	.set_mctrl	= ep93xx_uart_set_mctrl,
1818c2ecf20Sopenharmony_ci};
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic AMBA_APB_DEVICE(uart1, "apb:uart1", 0x00041010, EP93XX_UART1_PHYS_BASE,
1848c2ecf20Sopenharmony_ci	{ IRQ_EP93XX_UART1 }, &ep93xx_uart_data);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistatic AMBA_APB_DEVICE(uart2, "apb:uart2", 0x00041010, EP93XX_UART2_PHYS_BASE,
1878c2ecf20Sopenharmony_ci	{ IRQ_EP93XX_UART2 }, NULL);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic AMBA_APB_DEVICE(uart3, "apb:uart3", 0x00041010, EP93XX_UART3_PHYS_BASE,
1908c2ecf20Sopenharmony_ci	{ IRQ_EP93XX_UART3 }, &ep93xx_uart_data);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistatic struct resource ep93xx_rtc_resource[] = {
1938c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_RTC_PHYS_BASE, 0x10c),
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_rtc_device = {
1978c2ecf20Sopenharmony_ci	.name		= "ep93xx-rtc",
1988c2ecf20Sopenharmony_ci	.id		= -1,
1998c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_rtc_resource),
2008c2ecf20Sopenharmony_ci	.resource	= ep93xx_rtc_resource,
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/*************************************************************************
2048c2ecf20Sopenharmony_ci * EP93xx OHCI USB Host
2058c2ecf20Sopenharmony_ci *************************************************************************/
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic struct clk *ep93xx_ohci_host_clock;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistatic int ep93xx_ohci_power_on(struct platform_device *pdev)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	if (!ep93xx_ohci_host_clock) {
2128c2ecf20Sopenharmony_ci		ep93xx_ohci_host_clock = devm_clk_get(&pdev->dev, NULL);
2138c2ecf20Sopenharmony_ci		if (IS_ERR(ep93xx_ohci_host_clock))
2148c2ecf20Sopenharmony_ci			return PTR_ERR(ep93xx_ohci_host_clock);
2158c2ecf20Sopenharmony_ci	}
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	return clk_enable(ep93xx_ohci_host_clock);
2188c2ecf20Sopenharmony_ci}
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic void ep93xx_ohci_power_off(struct platform_device *pdev)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	clk_disable(ep93xx_ohci_host_clock);
2238c2ecf20Sopenharmony_ci}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic struct usb_ohci_pdata ep93xx_ohci_pdata = {
2268c2ecf20Sopenharmony_ci	.power_on	= ep93xx_ohci_power_on,
2278c2ecf20Sopenharmony_ci	.power_off	= ep93xx_ohci_power_off,
2288c2ecf20Sopenharmony_ci	.power_suspend	= ep93xx_ohci_power_off,
2298c2ecf20Sopenharmony_ci};
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistatic struct resource ep93xx_ohci_resources[] = {
2328c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000),
2338c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_USB),
2348c2ecf20Sopenharmony_ci};
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_cistatic u64 ep93xx_ohci_dma_mask = DMA_BIT_MASK(32);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_ohci_device = {
2398c2ecf20Sopenharmony_ci	.name		= "ohci-platform",
2408c2ecf20Sopenharmony_ci	.id		= -1,
2418c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_ohci_resources),
2428c2ecf20Sopenharmony_ci	.resource	= ep93xx_ohci_resources,
2438c2ecf20Sopenharmony_ci	.dev		= {
2448c2ecf20Sopenharmony_ci		.dma_mask		= &ep93xx_ohci_dma_mask,
2458c2ecf20Sopenharmony_ci		.coherent_dma_mask	= DMA_BIT_MASK(32),
2468c2ecf20Sopenharmony_ci		.platform_data		= &ep93xx_ohci_pdata,
2478c2ecf20Sopenharmony_ci	},
2488c2ecf20Sopenharmony_ci};
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/*************************************************************************
2518c2ecf20Sopenharmony_ci * EP93xx physmap'ed flash
2528c2ecf20Sopenharmony_ci *************************************************************************/
2538c2ecf20Sopenharmony_cistatic struct physmap_flash_data ep93xx_flash_data;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic struct resource ep93xx_flash_resource = {
2568c2ecf20Sopenharmony_ci	.flags		= IORESOURCE_MEM,
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_flash = {
2608c2ecf20Sopenharmony_ci	.name		= "physmap-flash",
2618c2ecf20Sopenharmony_ci	.id		= 0,
2628c2ecf20Sopenharmony_ci	.dev		= {
2638c2ecf20Sopenharmony_ci		.platform_data	= &ep93xx_flash_data,
2648c2ecf20Sopenharmony_ci	},
2658c2ecf20Sopenharmony_ci	.num_resources	= 1,
2668c2ecf20Sopenharmony_ci	.resource	= &ep93xx_flash_resource,
2678c2ecf20Sopenharmony_ci};
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/**
2708c2ecf20Sopenharmony_ci * ep93xx_register_flash() - Register the external flash device.
2718c2ecf20Sopenharmony_ci * @width:	bank width in octets
2728c2ecf20Sopenharmony_ci * @start:	resource start address
2738c2ecf20Sopenharmony_ci * @size:	resource size
2748c2ecf20Sopenharmony_ci */
2758c2ecf20Sopenharmony_civoid __init ep93xx_register_flash(unsigned int width,
2768c2ecf20Sopenharmony_ci				  resource_size_t start, resource_size_t size)
2778c2ecf20Sopenharmony_ci{
2788c2ecf20Sopenharmony_ci	ep93xx_flash_data.width		= width;
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	ep93xx_flash_resource.start	= start;
2818c2ecf20Sopenharmony_ci	ep93xx_flash_resource.end	= start + size - 1;
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_flash);
2848c2ecf20Sopenharmony_ci}
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/*************************************************************************
2888c2ecf20Sopenharmony_ci * EP93xx ethernet peripheral handling
2898c2ecf20Sopenharmony_ci *************************************************************************/
2908c2ecf20Sopenharmony_cistatic struct ep93xx_eth_data ep93xx_eth_data;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic struct resource ep93xx_eth_resource[] = {
2938c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_ETHERNET_PHYS_BASE, 0x10000),
2948c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_ETHERNET),
2958c2ecf20Sopenharmony_ci};
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistatic u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_eth_device = {
3008c2ecf20Sopenharmony_ci	.name		= "ep93xx-eth",
3018c2ecf20Sopenharmony_ci	.id		= -1,
3028c2ecf20Sopenharmony_ci	.dev		= {
3038c2ecf20Sopenharmony_ci		.platform_data		= &ep93xx_eth_data,
3048c2ecf20Sopenharmony_ci		.coherent_dma_mask	= DMA_BIT_MASK(32),
3058c2ecf20Sopenharmony_ci		.dma_mask		= &ep93xx_eth_dma_mask,
3068c2ecf20Sopenharmony_ci	},
3078c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_eth_resource),
3088c2ecf20Sopenharmony_ci	.resource	= ep93xx_eth_resource,
3098c2ecf20Sopenharmony_ci};
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci/**
3128c2ecf20Sopenharmony_ci * ep93xx_register_eth - Register the built-in ethernet platform device.
3138c2ecf20Sopenharmony_ci * @data:	platform specific ethernet configuration (__initdata)
3148c2ecf20Sopenharmony_ci * @copy_addr:	flag indicating that the MAC address should be copied
3158c2ecf20Sopenharmony_ci *		from the IndAd registers (as programmed by the bootloader)
3168c2ecf20Sopenharmony_ci */
3178c2ecf20Sopenharmony_civoid __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
3188c2ecf20Sopenharmony_ci{
3198c2ecf20Sopenharmony_ci	if (copy_addr)
3208c2ecf20Sopenharmony_ci		memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	ep93xx_eth_data = *data;
3238c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_eth_device);
3248c2ecf20Sopenharmony_ci}
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/*************************************************************************
3288c2ecf20Sopenharmony_ci * EP93xx i2c peripheral handling
3298c2ecf20Sopenharmony_ci *************************************************************************/
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci/* All EP93xx devices use the same two GPIO pins for I2C bit-banging */
3328c2ecf20Sopenharmony_cistatic struct gpiod_lookup_table ep93xx_i2c_gpiod_table = {
3338c2ecf20Sopenharmony_ci	.dev_id		= "i2c-gpio.0",
3348c2ecf20Sopenharmony_ci	.table		= {
3358c2ecf20Sopenharmony_ci		/* Use local offsets on gpiochip/port "G" */
3368c2ecf20Sopenharmony_ci		GPIO_LOOKUP_IDX("G", 1, NULL, 0,
3378c2ecf20Sopenharmony_ci				GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
3388c2ecf20Sopenharmony_ci		GPIO_LOOKUP_IDX("G", 0, NULL, 1,
3398c2ecf20Sopenharmony_ci				GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
3408c2ecf20Sopenharmony_ci	},
3418c2ecf20Sopenharmony_ci};
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_i2c_device = {
3448c2ecf20Sopenharmony_ci	.name		= "i2c-gpio",
3458c2ecf20Sopenharmony_ci	.id		= 0,
3468c2ecf20Sopenharmony_ci	.dev		= {
3478c2ecf20Sopenharmony_ci		.platform_data	= NULL,
3488c2ecf20Sopenharmony_ci	},
3498c2ecf20Sopenharmony_ci};
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/**
3528c2ecf20Sopenharmony_ci * ep93xx_register_i2c - Register the i2c platform device.
3538c2ecf20Sopenharmony_ci * @devices:	platform specific i2c bus device information (__initdata)
3548c2ecf20Sopenharmony_ci * @num:	the number of devices on the i2c bus
3558c2ecf20Sopenharmony_ci */
3568c2ecf20Sopenharmony_civoid __init ep93xx_register_i2c(struct i2c_board_info *devices, int num)
3578c2ecf20Sopenharmony_ci{
3588c2ecf20Sopenharmony_ci	/*
3598c2ecf20Sopenharmony_ci	 * FIXME: this just sets the two pins as non-opendrain, as no
3608c2ecf20Sopenharmony_ci	 * platforms tries to do that anyway. Flag the applicable lines
3618c2ecf20Sopenharmony_ci	 * as open drain in the GPIO_LOOKUP above and the driver or
3628c2ecf20Sopenharmony_ci	 * gpiolib will handle open drain/open drain emulation as need
3638c2ecf20Sopenharmony_ci	 * be. Right now i2c-gpio emulates open drain which is not
3648c2ecf20Sopenharmony_ci	 * optimal.
3658c2ecf20Sopenharmony_ci	 */
3668c2ecf20Sopenharmony_ci	__raw_writel((0 << 1) | (0 << 0),
3678c2ecf20Sopenharmony_ci		     EP93XX_GPIO_EEDRIVE);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	i2c_register_board_info(0, devices, num);
3708c2ecf20Sopenharmony_ci	gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table);
3718c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_i2c_device);
3728c2ecf20Sopenharmony_ci}
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci/*************************************************************************
3758c2ecf20Sopenharmony_ci * EP93xx SPI peripheral handling
3768c2ecf20Sopenharmony_ci *************************************************************************/
3778c2ecf20Sopenharmony_cistatic struct ep93xx_spi_info ep93xx_spi_master_data;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistatic struct resource ep93xx_spi_resources[] = {
3808c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_SPI_PHYS_BASE, 0x18),
3818c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_SSP),
3828c2ecf20Sopenharmony_ci};
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_cistatic u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_spi_device = {
3878c2ecf20Sopenharmony_ci	.name		= "ep93xx-spi",
3888c2ecf20Sopenharmony_ci	.id		= 0,
3898c2ecf20Sopenharmony_ci	.dev		= {
3908c2ecf20Sopenharmony_ci		.platform_data		= &ep93xx_spi_master_data,
3918c2ecf20Sopenharmony_ci		.coherent_dma_mask	= DMA_BIT_MASK(32),
3928c2ecf20Sopenharmony_ci		.dma_mask		= &ep93xx_spi_dma_mask,
3938c2ecf20Sopenharmony_ci	},
3948c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_spi_resources),
3958c2ecf20Sopenharmony_ci	.resource	= ep93xx_spi_resources,
3968c2ecf20Sopenharmony_ci};
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci/**
3998c2ecf20Sopenharmony_ci * ep93xx_register_spi() - registers spi platform device
4008c2ecf20Sopenharmony_ci * @info: ep93xx board specific spi master info (__initdata)
4018c2ecf20Sopenharmony_ci * @devices: SPI devices to register (__initdata)
4028c2ecf20Sopenharmony_ci * @num: number of SPI devices to register
4038c2ecf20Sopenharmony_ci *
4048c2ecf20Sopenharmony_ci * This function registers platform device for the EP93xx SPI controller and
4058c2ecf20Sopenharmony_ci * also makes sure that SPI pins are muxed so that I2S is not using those pins.
4068c2ecf20Sopenharmony_ci */
4078c2ecf20Sopenharmony_civoid __init ep93xx_register_spi(struct ep93xx_spi_info *info,
4088c2ecf20Sopenharmony_ci				struct spi_board_info *devices, int num)
4098c2ecf20Sopenharmony_ci{
4108c2ecf20Sopenharmony_ci	/*
4118c2ecf20Sopenharmony_ci	 * When SPI is used, we need to make sure that I2S is muxed off from
4128c2ecf20Sopenharmony_ci	 * SPI pins.
4138c2ecf20Sopenharmony_ci	 */
4148c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	ep93xx_spi_master_data = *info;
4178c2ecf20Sopenharmony_ci	spi_register_board_info(devices, num);
4188c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_spi_device);
4198c2ecf20Sopenharmony_ci}
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci/*************************************************************************
4228c2ecf20Sopenharmony_ci * EP93xx LEDs
4238c2ecf20Sopenharmony_ci *************************************************************************/
4248c2ecf20Sopenharmony_cistatic const struct gpio_led ep93xx_led_pins[] __initconst = {
4258c2ecf20Sopenharmony_ci	{
4268c2ecf20Sopenharmony_ci		.name	= "platform:grled",
4278c2ecf20Sopenharmony_ci		.gpio	= EP93XX_GPIO_LINE_GRLED,
4288c2ecf20Sopenharmony_ci	}, {
4298c2ecf20Sopenharmony_ci		.name	= "platform:rdled",
4308c2ecf20Sopenharmony_ci		.gpio	= EP93XX_GPIO_LINE_RDLED,
4318c2ecf20Sopenharmony_ci	},
4328c2ecf20Sopenharmony_ci};
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_cistatic const struct gpio_led_platform_data ep93xx_led_data __initconst = {
4358c2ecf20Sopenharmony_ci	.num_leds	= ARRAY_SIZE(ep93xx_led_pins),
4368c2ecf20Sopenharmony_ci	.leds		= ep93xx_led_pins,
4378c2ecf20Sopenharmony_ci};
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci/*************************************************************************
4408c2ecf20Sopenharmony_ci * EP93xx pwm peripheral handling
4418c2ecf20Sopenharmony_ci *************************************************************************/
4428c2ecf20Sopenharmony_cistatic struct resource ep93xx_pwm0_resource[] = {
4438c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE, 0x10),
4448c2ecf20Sopenharmony_ci};
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_pwm0_device = {
4478c2ecf20Sopenharmony_ci	.name		= "ep93xx-pwm",
4488c2ecf20Sopenharmony_ci	.id		= 0,
4498c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_pwm0_resource),
4508c2ecf20Sopenharmony_ci	.resource	= ep93xx_pwm0_resource,
4518c2ecf20Sopenharmony_ci};
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_cistatic struct resource ep93xx_pwm1_resource[] = {
4548c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE + 0x20, 0x10),
4558c2ecf20Sopenharmony_ci};
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_pwm1_device = {
4588c2ecf20Sopenharmony_ci	.name		= "ep93xx-pwm",
4598c2ecf20Sopenharmony_ci	.id		= 1,
4608c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_pwm1_resource),
4618c2ecf20Sopenharmony_ci	.resource	= ep93xx_pwm1_resource,
4628c2ecf20Sopenharmony_ci};
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_civoid __init ep93xx_register_pwm(int pwm0, int pwm1)
4658c2ecf20Sopenharmony_ci{
4668c2ecf20Sopenharmony_ci	if (pwm0)
4678c2ecf20Sopenharmony_ci		platform_device_register(&ep93xx_pwm0_device);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci	/* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
4708c2ecf20Sopenharmony_ci	if (pwm1)
4718c2ecf20Sopenharmony_ci		platform_device_register(&ep93xx_pwm1_device);
4728c2ecf20Sopenharmony_ci}
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ciint ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
4758c2ecf20Sopenharmony_ci{
4768c2ecf20Sopenharmony_ci	int err;
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci	if (pdev->id == 0) {
4798c2ecf20Sopenharmony_ci		err = 0;
4808c2ecf20Sopenharmony_ci	} else if (pdev->id == 1) {
4818c2ecf20Sopenharmony_ci		err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
4828c2ecf20Sopenharmony_ci				   dev_name(&pdev->dev));
4838c2ecf20Sopenharmony_ci		if (err)
4848c2ecf20Sopenharmony_ci			return err;
4858c2ecf20Sopenharmony_ci		err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
4868c2ecf20Sopenharmony_ci		if (err)
4878c2ecf20Sopenharmony_ci			goto fail;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci		/* PWM 1 output on EGPIO[14] */
4908c2ecf20Sopenharmony_ci		ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
4918c2ecf20Sopenharmony_ci	} else {
4928c2ecf20Sopenharmony_ci		err = -ENODEV;
4938c2ecf20Sopenharmony_ci	}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci	return err;
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_cifail:
4988c2ecf20Sopenharmony_ci	gpio_free(EP93XX_GPIO_LINE_EGPIO14);
4998c2ecf20Sopenharmony_ci	return err;
5008c2ecf20Sopenharmony_ci}
5018c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_civoid ep93xx_pwm_release_gpio(struct platform_device *pdev)
5048c2ecf20Sopenharmony_ci{
5058c2ecf20Sopenharmony_ci	if (pdev->id == 1) {
5068c2ecf20Sopenharmony_ci		gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
5078c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_EGPIO14);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci		/* EGPIO[14] used for GPIO */
5108c2ecf20Sopenharmony_ci		ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
5118c2ecf20Sopenharmony_ci	}
5128c2ecf20Sopenharmony_ci}
5138c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_pwm_release_gpio);
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci/*************************************************************************
5178c2ecf20Sopenharmony_ci * EP93xx video peripheral handling
5188c2ecf20Sopenharmony_ci *************************************************************************/
5198c2ecf20Sopenharmony_cistatic struct ep93xxfb_mach_info ep93xxfb_data;
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_cistatic struct resource ep93xx_fb_resource[] = {
5228c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE, 0x800),
5238c2ecf20Sopenharmony_ci};
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_fb_device = {
5268c2ecf20Sopenharmony_ci	.name			= "ep93xx-fb",
5278c2ecf20Sopenharmony_ci	.id			= -1,
5288c2ecf20Sopenharmony_ci	.dev			= {
5298c2ecf20Sopenharmony_ci		.platform_data		= &ep93xxfb_data,
5308c2ecf20Sopenharmony_ci		.coherent_dma_mask	= DMA_BIT_MASK(32),
5318c2ecf20Sopenharmony_ci		.dma_mask		= &ep93xx_fb_device.dev.coherent_dma_mask,
5328c2ecf20Sopenharmony_ci	},
5338c2ecf20Sopenharmony_ci	.num_resources		= ARRAY_SIZE(ep93xx_fb_resource),
5348c2ecf20Sopenharmony_ci	.resource		= ep93xx_fb_resource,
5358c2ecf20Sopenharmony_ci};
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci/* The backlight use a single register in the framebuffer's register space */
5388c2ecf20Sopenharmony_ci#define EP93XX_RASTER_REG_BRIGHTNESS 0x20
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_cistatic struct resource ep93xx_bl_resources[] = {
5418c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE +
5428c2ecf20Sopenharmony_ci		       EP93XX_RASTER_REG_BRIGHTNESS, 0x04),
5438c2ecf20Sopenharmony_ci};
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_bl_device = {
5468c2ecf20Sopenharmony_ci	.name		= "ep93xx-bl",
5478c2ecf20Sopenharmony_ci	.id		= -1,
5488c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_bl_resources),
5498c2ecf20Sopenharmony_ci	.resource	= ep93xx_bl_resources,
5508c2ecf20Sopenharmony_ci};
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci/**
5538c2ecf20Sopenharmony_ci * ep93xx_register_fb - Register the framebuffer platform device.
5548c2ecf20Sopenharmony_ci * @data:	platform specific framebuffer configuration (__initdata)
5558c2ecf20Sopenharmony_ci */
5568c2ecf20Sopenharmony_civoid __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
5578c2ecf20Sopenharmony_ci{
5588c2ecf20Sopenharmony_ci	ep93xxfb_data = *data;
5598c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_fb_device);
5608c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_bl_device);
5618c2ecf20Sopenharmony_ci}
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci/*************************************************************************
5658c2ecf20Sopenharmony_ci * EP93xx matrix keypad peripheral handling
5668c2ecf20Sopenharmony_ci *************************************************************************/
5678c2ecf20Sopenharmony_cistatic struct ep93xx_keypad_platform_data ep93xx_keypad_data;
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_cistatic struct resource ep93xx_keypad_resource[] = {
5708c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_KEY_MATRIX_PHYS_BASE, 0x0c),
5718c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_KEY),
5728c2ecf20Sopenharmony_ci};
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_keypad_device = {
5758c2ecf20Sopenharmony_ci	.name		= "ep93xx-keypad",
5768c2ecf20Sopenharmony_ci	.id		= -1,
5778c2ecf20Sopenharmony_ci	.dev		= {
5788c2ecf20Sopenharmony_ci		.platform_data	= &ep93xx_keypad_data,
5798c2ecf20Sopenharmony_ci	},
5808c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_keypad_resource),
5818c2ecf20Sopenharmony_ci	.resource	= ep93xx_keypad_resource,
5828c2ecf20Sopenharmony_ci};
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci/**
5858c2ecf20Sopenharmony_ci * ep93xx_register_keypad - Register the keypad platform device.
5868c2ecf20Sopenharmony_ci * @data:	platform specific keypad configuration (__initdata)
5878c2ecf20Sopenharmony_ci */
5888c2ecf20Sopenharmony_civoid __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
5898c2ecf20Sopenharmony_ci{
5908c2ecf20Sopenharmony_ci	ep93xx_keypad_data = *data;
5918c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_keypad_device);
5928c2ecf20Sopenharmony_ci}
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ciint ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
5958c2ecf20Sopenharmony_ci{
5968c2ecf20Sopenharmony_ci	int err;
5978c2ecf20Sopenharmony_ci	int i;
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
6008c2ecf20Sopenharmony_ci		err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
6018c2ecf20Sopenharmony_ci		if (err)
6028c2ecf20Sopenharmony_ci			goto fail_gpio_c;
6038c2ecf20Sopenharmony_ci		err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
6048c2ecf20Sopenharmony_ci		if (err)
6058c2ecf20Sopenharmony_ci			goto fail_gpio_d;
6068c2ecf20Sopenharmony_ci	}
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci	/* Enable the keypad controller; GPIO ports C and D used for keypad */
6098c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
6108c2ecf20Sopenharmony_ci				 EP93XX_SYSCON_DEVCFG_GONK);
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	return 0;
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_cifail_gpio_d:
6158c2ecf20Sopenharmony_ci	gpio_free(EP93XX_GPIO_LINE_C(i));
6168c2ecf20Sopenharmony_cifail_gpio_c:
6178c2ecf20Sopenharmony_ci	for (--i; i >= 0; --i) {
6188c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_C(i));
6198c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_D(i));
6208c2ecf20Sopenharmony_ci	}
6218c2ecf20Sopenharmony_ci	return err;
6228c2ecf20Sopenharmony_ci}
6238c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_civoid ep93xx_keypad_release_gpio(struct platform_device *pdev)
6268c2ecf20Sopenharmony_ci{
6278c2ecf20Sopenharmony_ci	int i;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
6308c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_C(i));
6318c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_D(i));
6328c2ecf20Sopenharmony_ci	}
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	/* Disable the keypad controller; GPIO ports C and D used for GPIO */
6358c2ecf20Sopenharmony_ci	ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
6368c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_GONK);
6378c2ecf20Sopenharmony_ci}
6388c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_keypad_release_gpio);
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_ci/*************************************************************************
6418c2ecf20Sopenharmony_ci * EP93xx I2S audio peripheral handling
6428c2ecf20Sopenharmony_ci *************************************************************************/
6438c2ecf20Sopenharmony_cistatic struct resource ep93xx_i2s_resource[] = {
6448c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_I2S_PHYS_BASE, 0x100),
6458c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_SAI),
6468c2ecf20Sopenharmony_ci};
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_i2s_device = {
6498c2ecf20Sopenharmony_ci	.name		= "ep93xx-i2s",
6508c2ecf20Sopenharmony_ci	.id		= -1,
6518c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_i2s_resource),
6528c2ecf20Sopenharmony_ci	.resource	= ep93xx_i2s_resource,
6538c2ecf20Sopenharmony_ci};
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_pcm_device = {
6568c2ecf20Sopenharmony_ci	.name		= "ep93xx-pcm-audio",
6578c2ecf20Sopenharmony_ci	.id		= -1,
6588c2ecf20Sopenharmony_ci};
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_civoid __init ep93xx_register_i2s(void)
6618c2ecf20Sopenharmony_ci{
6628c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_i2s_device);
6638c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_pcm_device);
6648c2ecf20Sopenharmony_ci}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci#define EP93XX_SYSCON_DEVCFG_I2S_MASK	(EP93XX_SYSCON_DEVCFG_I2SONSSP | \
6678c2ecf20Sopenharmony_ci					 EP93XX_SYSCON_DEVCFG_I2SONAC97)
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci#define EP93XX_I2SCLKDIV_MASK		(EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
6708c2ecf20Sopenharmony_ci					 EP93XX_SYSCON_I2SCLKDIV_SPOL)
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ciint ep93xx_i2s_acquire(void)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	unsigned val;
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_I2SONAC97,
6778c2ecf20Sopenharmony_ci			EP93XX_SYSCON_DEVCFG_I2S_MASK);
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci	/*
6808c2ecf20Sopenharmony_ci	 * This is potentially racy with the clock api for i2s_mclk, sclk and
6818c2ecf20Sopenharmony_ci	 * lrclk. Since the i2s driver is the only user of those clocks we
6828c2ecf20Sopenharmony_ci	 * rely on it to prevent parallel use of this function and the
6838c2ecf20Sopenharmony_ci	 * clock api for the i2s clocks.
6848c2ecf20Sopenharmony_ci	 */
6858c2ecf20Sopenharmony_ci	val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
6868c2ecf20Sopenharmony_ci	val &= ~EP93XX_I2SCLKDIV_MASK;
6878c2ecf20Sopenharmony_ci	val |= EP93XX_SYSCON_I2SCLKDIV_ORIDE | EP93XX_SYSCON_I2SCLKDIV_SPOL;
6888c2ecf20Sopenharmony_ci	ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	return 0;
6918c2ecf20Sopenharmony_ci}
6928c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_i2s_acquire);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_civoid ep93xx_i2s_release(void)
6958c2ecf20Sopenharmony_ci{
6968c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
6978c2ecf20Sopenharmony_ci}
6988c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_i2s_release);
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci/*************************************************************************
7018c2ecf20Sopenharmony_ci * EP93xx AC97 audio peripheral handling
7028c2ecf20Sopenharmony_ci *************************************************************************/
7038c2ecf20Sopenharmony_cistatic struct resource ep93xx_ac97_resources[] = {
7048c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_AAC_PHYS_BASE, 0xac),
7058c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_AACINTR),
7068c2ecf20Sopenharmony_ci};
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_ac97_device = {
7098c2ecf20Sopenharmony_ci	.name		= "ep93xx-ac97",
7108c2ecf20Sopenharmony_ci	.id		= -1,
7118c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_ac97_resources),
7128c2ecf20Sopenharmony_ci	.resource	= ep93xx_ac97_resources,
7138c2ecf20Sopenharmony_ci};
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_civoid __init ep93xx_register_ac97(void)
7168c2ecf20Sopenharmony_ci{
7178c2ecf20Sopenharmony_ci	/*
7188c2ecf20Sopenharmony_ci	 * Make sure that the AC97 pins are not used by I2S.
7198c2ecf20Sopenharmony_ci	 */
7208c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_ac97_device);
7238c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_pcm_device);
7248c2ecf20Sopenharmony_ci}
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci/*************************************************************************
7278c2ecf20Sopenharmony_ci * EP93xx Watchdog
7288c2ecf20Sopenharmony_ci *************************************************************************/
7298c2ecf20Sopenharmony_cistatic struct resource ep93xx_wdt_resources[] = {
7308c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_WATCHDOG_PHYS_BASE, 0x08),
7318c2ecf20Sopenharmony_ci};
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_wdt_device = {
7348c2ecf20Sopenharmony_ci	.name		= "ep93xx-wdt",
7358c2ecf20Sopenharmony_ci	.id		= -1,
7368c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_wdt_resources),
7378c2ecf20Sopenharmony_ci	.resource	= ep93xx_wdt_resources,
7388c2ecf20Sopenharmony_ci};
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci/*************************************************************************
7418c2ecf20Sopenharmony_ci * EP93xx IDE
7428c2ecf20Sopenharmony_ci *************************************************************************/
7438c2ecf20Sopenharmony_cistatic struct resource ep93xx_ide_resources[] = {
7448c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_IDE_PHYS_BASE, 0x38),
7458c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_EXT3),
7468c2ecf20Sopenharmony_ci};
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_ide_device = {
7498c2ecf20Sopenharmony_ci	.name		= "ep93xx-ide",
7508c2ecf20Sopenharmony_ci	.id		= -1,
7518c2ecf20Sopenharmony_ci	.dev		= {
7528c2ecf20Sopenharmony_ci		.dma_mask		= &ep93xx_ide_device.dev.coherent_dma_mask,
7538c2ecf20Sopenharmony_ci		.coherent_dma_mask	= DMA_BIT_MASK(32),
7548c2ecf20Sopenharmony_ci	},
7558c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_ide_resources),
7568c2ecf20Sopenharmony_ci	.resource	= ep93xx_ide_resources,
7578c2ecf20Sopenharmony_ci};
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_civoid __init ep93xx_register_ide(void)
7608c2ecf20Sopenharmony_ci{
7618c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_ide_device);
7628c2ecf20Sopenharmony_ci}
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ciint ep93xx_ide_acquire_gpio(struct platform_device *pdev)
7658c2ecf20Sopenharmony_ci{
7668c2ecf20Sopenharmony_ci	int err;
7678c2ecf20Sopenharmony_ci	int i;
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_ci	err = gpio_request(EP93XX_GPIO_LINE_EGPIO2, dev_name(&pdev->dev));
7708c2ecf20Sopenharmony_ci	if (err)
7718c2ecf20Sopenharmony_ci		return err;
7728c2ecf20Sopenharmony_ci	err = gpio_request(EP93XX_GPIO_LINE_EGPIO15, dev_name(&pdev->dev));
7738c2ecf20Sopenharmony_ci	if (err)
7748c2ecf20Sopenharmony_ci		goto fail_egpio15;
7758c2ecf20Sopenharmony_ci	for (i = 2; i < 8; i++) {
7768c2ecf20Sopenharmony_ci		err = gpio_request(EP93XX_GPIO_LINE_E(i), dev_name(&pdev->dev));
7778c2ecf20Sopenharmony_ci		if (err)
7788c2ecf20Sopenharmony_ci			goto fail_gpio_e;
7798c2ecf20Sopenharmony_ci	}
7808c2ecf20Sopenharmony_ci	for (i = 4; i < 8; i++) {
7818c2ecf20Sopenharmony_ci		err = gpio_request(EP93XX_GPIO_LINE_G(i), dev_name(&pdev->dev));
7828c2ecf20Sopenharmony_ci		if (err)
7838c2ecf20Sopenharmony_ci			goto fail_gpio_g;
7848c2ecf20Sopenharmony_ci	}
7858c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
7868c2ecf20Sopenharmony_ci		err = gpio_request(EP93XX_GPIO_LINE_H(i), dev_name(&pdev->dev));
7878c2ecf20Sopenharmony_ci		if (err)
7888c2ecf20Sopenharmony_ci			goto fail_gpio_h;
7898c2ecf20Sopenharmony_ci	}
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	/* GPIO ports E[7:2], G[7:4] and H used by IDE */
7928c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
7938c2ecf20Sopenharmony_ci				 EP93XX_SYSCON_DEVCFG_GONIDE |
7948c2ecf20Sopenharmony_ci				 EP93XX_SYSCON_DEVCFG_HONIDE);
7958c2ecf20Sopenharmony_ci	return 0;
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_cifail_gpio_h:
7988c2ecf20Sopenharmony_ci	for (--i; i >= 0; --i)
7998c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_H(i));
8008c2ecf20Sopenharmony_ci	i = 8;
8018c2ecf20Sopenharmony_cifail_gpio_g:
8028c2ecf20Sopenharmony_ci	for (--i; i >= 4; --i)
8038c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_G(i));
8048c2ecf20Sopenharmony_ci	i = 8;
8058c2ecf20Sopenharmony_cifail_gpio_e:
8068c2ecf20Sopenharmony_ci	for (--i; i >= 2; --i)
8078c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_E(i));
8088c2ecf20Sopenharmony_ci	gpio_free(EP93XX_GPIO_LINE_EGPIO15);
8098c2ecf20Sopenharmony_cifail_egpio15:
8108c2ecf20Sopenharmony_ci	gpio_free(EP93XX_GPIO_LINE_EGPIO2);
8118c2ecf20Sopenharmony_ci	return err;
8128c2ecf20Sopenharmony_ci}
8138c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_ide_acquire_gpio);
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_civoid ep93xx_ide_release_gpio(struct platform_device *pdev)
8168c2ecf20Sopenharmony_ci{
8178c2ecf20Sopenharmony_ci	int i;
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci	for (i = 2; i < 8; i++)
8208c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_E(i));
8218c2ecf20Sopenharmony_ci	for (i = 4; i < 8; i++)
8228c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_G(i));
8238c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++)
8248c2ecf20Sopenharmony_ci		gpio_free(EP93XX_GPIO_LINE_H(i));
8258c2ecf20Sopenharmony_ci	gpio_free(EP93XX_GPIO_LINE_EGPIO15);
8268c2ecf20Sopenharmony_ci	gpio_free(EP93XX_GPIO_LINE_EGPIO2);
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	/* GPIO ports E[7:2], G[7:4] and H used by GPIO */
8308c2ecf20Sopenharmony_ci	ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
8318c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_GONIDE |
8328c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_HONIDE);
8338c2ecf20Sopenharmony_ci}
8348c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ep93xx_ide_release_gpio);
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci/*************************************************************************
8378c2ecf20Sopenharmony_ci * EP93xx ADC
8388c2ecf20Sopenharmony_ci *************************************************************************/
8398c2ecf20Sopenharmony_cistatic struct resource ep93xx_adc_resources[] = {
8408c2ecf20Sopenharmony_ci	DEFINE_RES_MEM(EP93XX_ADC_PHYS_BASE, 0x28),
8418c2ecf20Sopenharmony_ci	DEFINE_RES_IRQ(IRQ_EP93XX_TOUCH),
8428c2ecf20Sopenharmony_ci};
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_cistatic struct platform_device ep93xx_adc_device = {
8458c2ecf20Sopenharmony_ci	.name		= "ep93xx-adc",
8468c2ecf20Sopenharmony_ci	.id		= -1,
8478c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(ep93xx_adc_resources),
8488c2ecf20Sopenharmony_ci	.resource	= ep93xx_adc_resources,
8498c2ecf20Sopenharmony_ci};
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_civoid __init ep93xx_register_adc(void)
8528c2ecf20Sopenharmony_ci{
8538c2ecf20Sopenharmony_ci	/* Power up ADC, deactivate Touch Screen Controller */
8548c2ecf20Sopenharmony_ci	ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_TIN,
8558c2ecf20Sopenharmony_ci				EP93XX_SYSCON_DEVCFG_ADCPD);
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_adc_device);
8588c2ecf20Sopenharmony_ci}
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci/*************************************************************************
8618c2ecf20Sopenharmony_ci * EP93xx Security peripheral
8628c2ecf20Sopenharmony_ci *************************************************************************/
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci/*
8658c2ecf20Sopenharmony_ci * The Maverick Key is 256 bits of micro fuses blown at the factory during
8668c2ecf20Sopenharmony_ci * manufacturing to uniquely identify a part.
8678c2ecf20Sopenharmony_ci *
8688c2ecf20Sopenharmony_ci * See: http://arm.cirrus.com/forum/viewtopic.php?t=486&highlight=maverick+key
8698c2ecf20Sopenharmony_ci */
8708c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_REG(x)		(EP93XX_SECURITY_BASE + (x))
8718c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_SECFLG		EP93XX_SECURITY_REG(0x2400)
8728c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_FUSEFLG		EP93XX_SECURITY_REG(0x2410)
8738c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQID		EP93XX_SECURITY_REG(0x2440)
8748c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQCHK		EP93XX_SECURITY_REG(0x2450)
8758c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQVAL		EP93XX_SECURITY_REG(0x2460)
8768c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_SECID1		EP93XX_SECURITY_REG(0x2500)
8778c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_SECID2		EP93XX_SECURITY_REG(0x2504)
8788c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_SECCHK1		EP93XX_SECURITY_REG(0x2520)
8798c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_SECCHK2		EP93XX_SECURITY_REG(0x2524)
8808c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQID2		EP93XX_SECURITY_REG(0x2700)
8818c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQID3		EP93XX_SECURITY_REG(0x2704)
8828c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQID4		EP93XX_SECURITY_REG(0x2708)
8838c2ecf20Sopenharmony_ci#define EP93XX_SECURITY_UNIQID5		EP93XX_SECURITY_REG(0x270c)
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_cistatic char ep93xx_soc_id[33];
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_cistatic const char __init *ep93xx_get_soc_id(void)
8888c2ecf20Sopenharmony_ci{
8898c2ecf20Sopenharmony_ci	unsigned int id, id2, id3, id4, id5;
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_ci	if (__raw_readl(EP93XX_SECURITY_UNIQVAL) != 1)
8928c2ecf20Sopenharmony_ci		return "bad Hamming code";
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci	id = __raw_readl(EP93XX_SECURITY_UNIQID);
8958c2ecf20Sopenharmony_ci	id2 = __raw_readl(EP93XX_SECURITY_UNIQID2);
8968c2ecf20Sopenharmony_ci	id3 = __raw_readl(EP93XX_SECURITY_UNIQID3);
8978c2ecf20Sopenharmony_ci	id4 = __raw_readl(EP93XX_SECURITY_UNIQID4);
8988c2ecf20Sopenharmony_ci	id5 = __raw_readl(EP93XX_SECURITY_UNIQID5);
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	if (id != id2)
9018c2ecf20Sopenharmony_ci		return "invalid";
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	/* Toss the unique ID into the entropy pool */
9048c2ecf20Sopenharmony_ci	add_device_randomness(&id2, 4);
9058c2ecf20Sopenharmony_ci	add_device_randomness(&id3, 4);
9068c2ecf20Sopenharmony_ci	add_device_randomness(&id4, 4);
9078c2ecf20Sopenharmony_ci	add_device_randomness(&id5, 4);
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	snprintf(ep93xx_soc_id, sizeof(ep93xx_soc_id),
9108c2ecf20Sopenharmony_ci		 "%08x%08x%08x%08x", id2, id3, id4, id5);
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci	return ep93xx_soc_id;
9138c2ecf20Sopenharmony_ci}
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_cistatic const char __init *ep93xx_get_soc_rev(void)
9168c2ecf20Sopenharmony_ci{
9178c2ecf20Sopenharmony_ci	int rev = ep93xx_chip_revision();
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci	switch (rev) {
9208c2ecf20Sopenharmony_ci	case EP93XX_CHIP_REV_D0:
9218c2ecf20Sopenharmony_ci		return "D0";
9228c2ecf20Sopenharmony_ci	case EP93XX_CHIP_REV_D1:
9238c2ecf20Sopenharmony_ci		return "D1";
9248c2ecf20Sopenharmony_ci	case EP93XX_CHIP_REV_E0:
9258c2ecf20Sopenharmony_ci		return "E0";
9268c2ecf20Sopenharmony_ci	case EP93XX_CHIP_REV_E1:
9278c2ecf20Sopenharmony_ci		return "E1";
9288c2ecf20Sopenharmony_ci	case EP93XX_CHIP_REV_E2:
9298c2ecf20Sopenharmony_ci		return "E2";
9308c2ecf20Sopenharmony_ci	default:
9318c2ecf20Sopenharmony_ci		return "unknown";
9328c2ecf20Sopenharmony_ci	}
9338c2ecf20Sopenharmony_ci}
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_cistatic const char __init *ep93xx_get_machine_name(void)
9368c2ecf20Sopenharmony_ci{
9378c2ecf20Sopenharmony_ci	return kasprintf(GFP_KERNEL,"%s", machine_desc->name);
9388c2ecf20Sopenharmony_ci}
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_cistatic struct device __init *ep93xx_init_soc(void)
9418c2ecf20Sopenharmony_ci{
9428c2ecf20Sopenharmony_ci	struct soc_device_attribute *soc_dev_attr;
9438c2ecf20Sopenharmony_ci	struct soc_device *soc_dev;
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
9468c2ecf20Sopenharmony_ci	if (!soc_dev_attr)
9478c2ecf20Sopenharmony_ci		return NULL;
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	soc_dev_attr->machine = ep93xx_get_machine_name();
9508c2ecf20Sopenharmony_ci	soc_dev_attr->family = "Cirrus Logic EP93xx";
9518c2ecf20Sopenharmony_ci	soc_dev_attr->revision = ep93xx_get_soc_rev();
9528c2ecf20Sopenharmony_ci	soc_dev_attr->soc_id = ep93xx_get_soc_id();
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci	soc_dev = soc_device_register(soc_dev_attr);
9558c2ecf20Sopenharmony_ci	if (IS_ERR(soc_dev)) {
9568c2ecf20Sopenharmony_ci		kfree(soc_dev_attr->machine);
9578c2ecf20Sopenharmony_ci		kfree(soc_dev_attr);
9588c2ecf20Sopenharmony_ci		return NULL;
9598c2ecf20Sopenharmony_ci	}
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci	return soc_device_to_device(soc_dev);
9628c2ecf20Sopenharmony_ci}
9638c2ecf20Sopenharmony_ci
9648c2ecf20Sopenharmony_cistruct device __init *ep93xx_init_devices(void)
9658c2ecf20Sopenharmony_ci{
9668c2ecf20Sopenharmony_ci	struct device *parent;
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_ci	/* Disallow access to MaverickCrunch initially */
9698c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_ci	/* Default all ports to GPIO */
9728c2ecf20Sopenharmony_ci	ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
9738c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_GONK |
9748c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_EONIDE |
9758c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_GONIDE |
9768c2ecf20Sopenharmony_ci			       EP93XX_SYSCON_DEVCFG_HONIDE);
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_ci	parent = ep93xx_init_soc();
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci	/* Get the GPIO working early, other devices need it */
9818c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_gpio_device);
9828c2ecf20Sopenharmony_ci
9838c2ecf20Sopenharmony_ci	amba_device_register(&uart1_device, &iomem_resource);
9848c2ecf20Sopenharmony_ci	amba_device_register(&uart2_device, &iomem_resource);
9858c2ecf20Sopenharmony_ci	amba_device_register(&uart3_device, &iomem_resource);
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_rtc_device);
9888c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_ohci_device);
9898c2ecf20Sopenharmony_ci	platform_device_register(&ep93xx_wdt_device);
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_ci	gpio_led_register_device(-1, &ep93xx_led_data);
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_ci	return parent;
9948c2ecf20Sopenharmony_ci}
9958c2ecf20Sopenharmony_ci
9968c2ecf20Sopenharmony_civoid ep93xx_restart(enum reboot_mode mode, const char *cmd)
9978c2ecf20Sopenharmony_ci{
9988c2ecf20Sopenharmony_ci	/*
9998c2ecf20Sopenharmony_ci	 * Set then clear the SWRST bit to initiate a software reset
10008c2ecf20Sopenharmony_ci	 */
10018c2ecf20Sopenharmony_ci	ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST);
10028c2ecf20Sopenharmony_ci	ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST);
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_ci	while (1)
10058c2ecf20Sopenharmony_ci		;
10068c2ecf20Sopenharmony_ci}
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_civoid __init ep93xx_init_late(void)
10098c2ecf20Sopenharmony_ci{
10108c2ecf20Sopenharmony_ci	crunch_init();
10118c2ecf20Sopenharmony_ci}
1012