18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/arch/arm/mach-mmp/pxa168.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Code specific to PXA168
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#include <linux/module.h>
88c2ecf20Sopenharmony_ci#include <linux/kernel.h>
98c2ecf20Sopenharmony_ci#include <linux/init.h>
108c2ecf20Sopenharmony_ci#include <linux/list.h>
118c2ecf20Sopenharmony_ci#include <linux/io.h>
128c2ecf20Sopenharmony_ci#include <linux/clk.h>
138c2ecf20Sopenharmony_ci#include <linux/clk/mmp.h>
148c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
158c2ecf20Sopenharmony_ci#include <linux/platform_data/mv_usb.h>
168c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <asm/mach/time.h>
198c2ecf20Sopenharmony_ci#include <asm/system_misc.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "addr-map.h"
228c2ecf20Sopenharmony_ci#include "common.h"
238c2ecf20Sopenharmony_ci#include <linux/soc/mmp/cputype.h>
248c2ecf20Sopenharmony_ci#include "devices.h"
258c2ecf20Sopenharmony_ci#include "irqs.h"
268c2ecf20Sopenharmony_ci#include "mfp.h"
278c2ecf20Sopenharmony_ci#include "pxa168.h"
288c2ecf20Sopenharmony_ci#include "regs-apbc.h"
298c2ecf20Sopenharmony_ci#include "regs-apmu.h"
308c2ecf20Sopenharmony_ci#include "regs-usb.h"
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define MFPR_VIRT_BASE	(APB_VIRT_BASE + 0x1e000)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic struct mfp_addr_map pxa168_mfp_addr_map[] __initdata =
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	MFP_ADDR_X(GPIO0,   GPIO36,  0x04c),
378c2ecf20Sopenharmony_ci	MFP_ADDR_X(GPIO37,  GPIO55,  0x000),
388c2ecf20Sopenharmony_ci	MFP_ADDR_X(GPIO56,  GPIO123, 0x0e0),
398c2ecf20Sopenharmony_ci	MFP_ADDR_X(GPIO124, GPIO127, 0x0f4),
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	MFP_ADDR_END,
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_civoid __init pxa168_init_irq(void)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	icu_init_irq();
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic int __init pxa168_init(void)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	if (cpu_is_pxa168()) {
528c2ecf20Sopenharmony_ci		mfp_init_base(MFPR_VIRT_BASE);
538c2ecf20Sopenharmony_ci		mfp_init_addr(pxa168_mfp_addr_map);
548c2ecf20Sopenharmony_ci		pxa168_clk_init(APB_PHYS_BASE + 0x50000,
558c2ecf20Sopenharmony_ci				AXI_PHYS_BASE + 0x82800,
568c2ecf20Sopenharmony_ci				APB_PHYS_BASE + 0x15000);
578c2ecf20Sopenharmony_ci	}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	return 0;
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_cipostcore_initcall(pxa168_init);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* system timer - clock enabled, 3.25MHz */
648c2ecf20Sopenharmony_ci#define TIMER_CLK_RST	(APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(3))
658c2ecf20Sopenharmony_ci#define APBC_TIMERS	APBC_REG(0x34)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_civoid __init pxa168_timer_init(void)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	/* this is early, we have to initialize the CCU registers by
708c2ecf20Sopenharmony_ci	 * ourselves instead of using clk_* API. Clock rate is defined
718c2ecf20Sopenharmony_ci	 * by APBC_TIMERS_CLK_RST (3.25MHz) and enabled free-running
728c2ecf20Sopenharmony_ci	 */
738c2ecf20Sopenharmony_ci	__raw_writel(APBC_APBCLK | APBC_RST, APBC_TIMERS);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	/* 3.25MHz, bus/functional clock enabled, release reset */
768c2ecf20Sopenharmony_ci	__raw_writel(TIMER_CLK_RST, APBC_TIMERS);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	mmp_timer_init(IRQ_PXA168_TIMER1, 3250000);
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_civoid pxa168_clear_keypad_wakeup(void)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	uint32_t val;
848c2ecf20Sopenharmony_ci	uint32_t mask = APMU_PXA168_KP_WAKE_CLR;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* wake event clear is needed in order to clear keypad interrupt */
878c2ecf20Sopenharmony_ci	val = __raw_readl(APMU_WAKE_CLR);
888c2ecf20Sopenharmony_ci	__raw_writel(val |  mask, APMU_WAKE_CLR);
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/* on-chip devices */
928c2ecf20Sopenharmony_ciPXA168_DEVICE(uart1, "pxa2xx-uart", 0, UART1, 0xd4017000, 0x30, 21, 22);
938c2ecf20Sopenharmony_ciPXA168_DEVICE(uart2, "pxa2xx-uart", 1, UART2, 0xd4018000, 0x30, 23, 24);
948c2ecf20Sopenharmony_ciPXA168_DEVICE(uart3, "pxa2xx-uart", 2, UART3, 0xd4026000, 0x30, 23, 24);
958c2ecf20Sopenharmony_ciPXA168_DEVICE(twsi0, "pxa2xx-i2c", 0, TWSI0, 0xd4011000, 0x28);
968c2ecf20Sopenharmony_ciPXA168_DEVICE(twsi1, "pxa2xx-i2c", 1, TWSI1, 0xd4025000, 0x28);
978c2ecf20Sopenharmony_ciPXA168_DEVICE(pwm1, "pxa168-pwm", 0, NONE, 0xd401a000, 0x10);
988c2ecf20Sopenharmony_ciPXA168_DEVICE(pwm2, "pxa168-pwm", 1, NONE, 0xd401a400, 0x10);
998c2ecf20Sopenharmony_ciPXA168_DEVICE(pwm3, "pxa168-pwm", 2, NONE, 0xd401a800, 0x10);
1008c2ecf20Sopenharmony_ciPXA168_DEVICE(pwm4, "pxa168-pwm", 3, NONE, 0xd401ac00, 0x10);
1018c2ecf20Sopenharmony_ciPXA168_DEVICE(nand, "pxa3xx-nand", -1, NAND, 0xd4283000, 0x80, 97, 99);
1028c2ecf20Sopenharmony_ciPXA168_DEVICE(ssp1, "pxa168-ssp", 0, SSP1, 0xd401b000, 0x40, 52, 53);
1038c2ecf20Sopenharmony_ciPXA168_DEVICE(ssp2, "pxa168-ssp", 1, SSP2, 0xd401c000, 0x40, 54, 55);
1048c2ecf20Sopenharmony_ciPXA168_DEVICE(ssp3, "pxa168-ssp", 2, SSP3, 0xd401f000, 0x40, 56, 57);
1058c2ecf20Sopenharmony_ciPXA168_DEVICE(ssp4, "pxa168-ssp", 3, SSP4, 0xd4020000, 0x40, 58, 59);
1068c2ecf20Sopenharmony_ciPXA168_DEVICE(ssp5, "pxa168-ssp", 4, SSP5, 0xd4021000, 0x40, 60, 61);
1078c2ecf20Sopenharmony_ciPXA168_DEVICE(fb, "pxa168-fb", -1, LCD, 0xd420b000, 0x1c8);
1088c2ecf20Sopenharmony_ciPXA168_DEVICE(keypad, "pxa27x-keypad", -1, KEYPAD, 0xd4012000, 0x4c);
1098c2ecf20Sopenharmony_ciPXA168_DEVICE(eth, "pxa168-eth", -1, MFU, 0xc0800000, 0x0fff);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct resource pxa168_resource_gpio[] = {
1128c2ecf20Sopenharmony_ci	{
1138c2ecf20Sopenharmony_ci		.start	= 0xd4019000,
1148c2ecf20Sopenharmony_ci		.end	= 0xd4019fff,
1158c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
1168c2ecf20Sopenharmony_ci	}, {
1178c2ecf20Sopenharmony_ci		.start	= IRQ_PXA168_GPIOX,
1188c2ecf20Sopenharmony_ci		.end	= IRQ_PXA168_GPIOX,
1198c2ecf20Sopenharmony_ci		.name	= "gpio_mux",
1208c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_IRQ,
1218c2ecf20Sopenharmony_ci	},
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistruct platform_device pxa168_device_gpio = {
1258c2ecf20Sopenharmony_ci	.name		= "mmp-gpio",
1268c2ecf20Sopenharmony_ci	.id		= -1,
1278c2ecf20Sopenharmony_ci	.num_resources	= ARRAY_SIZE(pxa168_resource_gpio),
1288c2ecf20Sopenharmony_ci	.resource	= pxa168_resource_gpio,
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct resource pxa168_usb_host_resources[] = {
1328c2ecf20Sopenharmony_ci	/* USB Host conroller register base */
1338c2ecf20Sopenharmony_ci	[0] = {
1348c2ecf20Sopenharmony_ci		.start	= PXA168_U2H_REGBASE + U2x_CAPREGS_OFFSET,
1358c2ecf20Sopenharmony_ci		.end	= PXA168_U2H_REGBASE + USB_REG_RANGE,
1368c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
1378c2ecf20Sopenharmony_ci		.name	= "capregs",
1388c2ecf20Sopenharmony_ci	},
1398c2ecf20Sopenharmony_ci	/* USB PHY register base */
1408c2ecf20Sopenharmony_ci	[1] = {
1418c2ecf20Sopenharmony_ci		.start	= PXA168_U2H_PHYBASE,
1428c2ecf20Sopenharmony_ci		.end	= PXA168_U2H_PHYBASE + USB_PHY_RANGE,
1438c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_MEM,
1448c2ecf20Sopenharmony_ci		.name	= "phyregs",
1458c2ecf20Sopenharmony_ci	},
1468c2ecf20Sopenharmony_ci	[2] = {
1478c2ecf20Sopenharmony_ci		.start	= IRQ_PXA168_USB2,
1488c2ecf20Sopenharmony_ci		.end	= IRQ_PXA168_USB2,
1498c2ecf20Sopenharmony_ci		.flags	= IORESOURCE_IRQ,
1508c2ecf20Sopenharmony_ci	},
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic u64 pxa168_usb_host_dmamask = DMA_BIT_MASK(32);
1548c2ecf20Sopenharmony_cistruct platform_device pxa168_device_usb_host = {
1558c2ecf20Sopenharmony_ci	.name = "pxa-sph",
1568c2ecf20Sopenharmony_ci	.id   = -1,
1578c2ecf20Sopenharmony_ci	.dev  = {
1588c2ecf20Sopenharmony_ci		.dma_mask = &pxa168_usb_host_dmamask,
1598c2ecf20Sopenharmony_ci		.coherent_dma_mask = DMA_BIT_MASK(32),
1608c2ecf20Sopenharmony_ci	},
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	.num_resources = ARRAY_SIZE(pxa168_usb_host_resources),
1638c2ecf20Sopenharmony_ci	.resource      = pxa168_usb_host_resources,
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciint __init pxa168_add_usb_host(struct mv_usb_platform_data *pdata)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	pxa168_device_usb_host.dev.platform_data = pdata;
1698c2ecf20Sopenharmony_ci	return platform_device_register(&pxa168_device_usb_host);
1708c2ecf20Sopenharmony_ci}
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_civoid pxa168_restart(enum reboot_mode mode, const char *cmd)
1738c2ecf20Sopenharmony_ci{
1748c2ecf20Sopenharmony_ci	soft_restart(0xffff0000);
1758c2ecf20Sopenharmony_ci}
176