code:
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  linux/arch/arm/mach-pxa/viper.c
 *
 *  Support for the Arcom VIPER SBC.
 *
 *  Author:	Ian Campbell
 *  Created:    Feb 03, 2003
 *  Copyright:  Arcom Control Systems
 *
 *  Maintained by Marc Zyngier <maz@misterjones.org>
 *                             <marc.zyngier@altran.com>
 *
 * Based on lubbock.c:
 *  Author:	Nicolas Pitre
 *  Created:	Jun 15, 2001
 *  Copyright:	MontaVista Software Inc.
 */

#include <linux/types.h>
#include <linux/memory.h>
#include <linux/cpu.h>
#include <linux/cpufreq.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/major.h>
#include <linux/module.h>
#include <linux/pm.h>
#include <linux/sched.h>
#include <linux/gpio.h>
#include <linux/jiffies.h>
#include <linux/platform_data/i2c-gpio.h>
#include <linux/gpio/machine.h>
#include <linux/platform_data/i2c-pxa.h>
#include <linux/serial_8250.h>
#include <linux/smc91x.h>
#include <linux/pwm.h>
#include <linux/pwm_backlight.h>
#include <linux/usb/isp116x.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
#include <linux/syscore_ops.h>

#include "pxa25x.h"
#include <linux/platform_data/asoc-pxa.h>
#include <linux/platform_data/video-pxafb.h>
#include "regs-uart.h"
#include "viper-pcmcia.h"
#include "viper.h"

#include <asm/setup.h>
#include <asm/mach-types.h>
#include <asm/irq.h>
#include <linux/sizes.h>
#include <asm/system_info.h>

#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/mach/irq.h>

#include "generic.h"
#include "devices.h"

static unsigned int icr;

static void viper_icr_set_bit(unsigned int bit)
{
	icr |= bit;
	VIPER_ICR = icr;
}

static void viper_icr_clear_bit(unsigned int bit)
{
	icr &= ~bit;
	VIPER_ICR = icr;
}

/* This function is used from the pcmcia module to reset the CF */
static void viper_cf_reset(int state)
{
	if (state)
		viper_icr_set_bit(VIPER_ICR_CF_RST);
	else
		viper_icr_clear_bit(VIPER_ICR_CF_RST);
}

static struct arcom_pcmcia_pdata viper_pcmcia_info = {
	.cd_gpio	= VIPER_CF_CD_GPIO,
	.rdy_gpio	= VIPER_CF_RDY_GPIO,
	.pwr_gpio	= VIPER_CF_POWER_GPIO,
	.reset		= viper_cf_reset,
};

static struct platform_device viper_pcmcia_device = {
	.name		= "viper-pcmcia",
	.id		= -1,
	.dev		= {
		.platform_data	= &viper_pcmcia_info,
	},
};

/*
 * The CPLD version register was not present on VIPER boards prior to
 * v2i1. On v1 boards where the version register is not present we
 * will just read back the previous value from the databus.
 *
 * Therefore we do two reads. The first time we write 0 to the
 * (read-only) register before reading and the second time we write
 * 0xff first. If the two reads do not match or they read back as 0xff
 * or 0x00 then we have version 1 hardware.
 */
static u8 viper_hw_version(void)
{
	u8 v1, v2;
	unsigned long flags;

	local_irq_save(flags);

	VIPER_VERSION = 0;
	v1 = VIPER_VERSION;
	VIPER_VERSION = 0xff;
	v2 = VIPER_VERSION;

	v1 = (v1 != v2 || v1 == 0xff) ? 0 : v1;

	local_irq_restore(flags);
	return v1;
}

/* CPU system core operations. */
static int viper_cpu_suspend(void)
{
	viper_icr_set_bit(VIPER_ICR_R_DIS);
	return 0;
}

static void viper_cpu_resume(void)
{
	viper_icr_clear_bit(VIPER_ICR_R_DIS);
}

static struct syscore_ops viper_cpu_syscore_ops = {
	.suspend	= viper_cpu_suspend,
	.resume		= viper_cpu_resume,
};

static unsigned int current_voltage_divisor;

/*
 * If force is not true then step from existing to new divisor. If
 * force is true then jump straight to the new divisor. Stepping is
 * used because if the jump in voltage is too large, the VCC can dip
 * too low and the regulator cuts out.
 *
 * force can be used to initialize the divisor to a know state by
 * setting the value for the current clock speed, since we are already
 * running at that speed we know the voltage should be pretty close so
 * the jump won't be too large
 */
static void viper_set_core_cpu_voltage(unsigned long khz, int force)
{
	int i = 0;
	unsigned int divisor = 0;
	const char *v;

	if (khz < 200000) {
		v = "1.0"; divisor = 0xfff;
	} else if (khz < 300000) {
		v = "1.1"; divisor = 0xde5;
	} else {
		v = "1.3"; divisor = 0x325;
	}

	pr_debug("viper: setting CPU core voltage to %sV at %d.%03dMHz\n",
		 v, (int)khz / 1000, (int)khz % 1000);

#define STEP 0x100
	do {
		int step;

		if (force)
			step = divisor;
		else if (current_voltage_divisor < divisor - STEP)
			step = current_voltage_divisor + STEP;
		else if (current_voltage_divisor > divisor + STEP)
			step = current_voltage_divisor - STEP;
		else
			step = divisor;
		force = 0;

		gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
		gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);

		for (i = 1 << 11 ; i > 0 ; i >>= 1) {
			udelay(1);

			gpio_set_value(VIPER_PSU_DATA_GPIO, step & i);
			udelay(1);

			gpio_set_value(VIPER_PSU_CLK_GPIO, 1);
			udelay(1);

			gpio_set_value(VIPER_PSU_CLK_GPIO, 0);
		}
		udelay(1);

		gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 1);
		udelay(1);

		gpio_set_value(VIPER_PSU_nCS_LD_GPIO, 0);

		current_voltage_divisor = step;
	} while (current_voltage_divisor != divisor);
}

/* Interrupt handling */
static unsigned long viper_irq_enabled_mask;
static const int viper_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, 9, 14, 15 };
static const int viper_isa_irq_map[] = {
	0,		/* ISA irq #0, invalid */
	0,		/* ISA irq #1, invalid */
	0,		/* ISA irq #2, invalid */
	1 << 0,		/* ISA irq #3 */
	1 << 1,		/* ISA irq #4 */
	1 << 2,		/* ISA irq #5 */
	1 << 3,		/* ISA irq #6 */
	1 << 4,		/* ISA irq #7 */
	0,		/* ISA irq #8, invalid */
	1 << 8,		/* ISA irq #9 */
	1 << 5,		/* ISA irq #10 */
	1 << 6,		/* ISA irq #11 */
	1 << 7,		/* ISA irq #12 */
	0,		/* ISA irq #13, invalid */
	1 << 9,		/* ISA irq #14 */
	1 << 10,	/* ISA irq #15 */
};

static inline int viper_irq_to_bitmask(unsigned int irq)
{
	return viper_isa_irq_map[irq - PXA_ISA_IRQ(0)];
}

static inline int viper_bit_to_irq(int bit)
{
	return viper_isa_irqs[bit] + PXA_ISA_IRQ(0);
}

static void viper_ack_irq(struct irq_data *d)
{
	int viper_irq = viper_irq_to_bitmask(d->irq);

	if (viper_irq & 0xff)
		VIPER_LO_IRQ_STATUS = viper_irq;
	else
		VIPER_HI_IRQ_STATUS = (viper_irq >> 8);
}

static void viper_mask_irq(struct irq_data *d)
{
	viper_irq_enabled_mask &= ~(viper_irq_to_bitmask(d->irq));
}

static void viper_unmask_irq(struct irq_data *d)
{
	viper_irq_enabled_mask |= viper_irq_to_bitmask(d->irq);
}

static inline unsigned long viper_irq_pending(void)
{
	return (VIPER_HI_IRQ_STATUS << 8 | VIPER_LO_IRQ_STATUS) &
			viper_irq_enabled_mask;
}

static void viper_irq_handler(struct irq_desc *desc)
{
	unsigned int irq;
	unsigned long pending;

	pending = viper_irq_pending();
	do {
		/* we're in a chained irq handler,
		 * so ack the interrupt by hand */
		desc->irq_data.chip->irq_ack(&desc->irq_data);

		if (likely(pending)) {
			irq = viper_bit_to_irq(__ffs(pending));
			generic_handle_irq(irq);
		}
		pending = viper_irq_pending();
	} while (pending);
}

static struct irq_chip viper_irq_chip = {
	.name		= "ISA",
	.irq_ack	= viper_ack_irq,
	.irq_mask	= viper_mask_irq,
	.irq_unmask	= viper_unmask_irq
};

static void __init viper_init_irq(void)
{
	int level;
	int isa_irq;

	pxa25x_init_irq();

	/* setup ISA IRQs */
	for (level = 0; level < ARRAY_SIZE(viper_isa_irqs); level++) {
		isa_irq = viper_bit_to_irq(level);
		irq_set_chip_and_handler(isa_irq, &viper_irq_chip,
					 handle_edge_irq);
		irq_clear_status_flags(isa_irq, IRQ_NOREQUEST | IRQ_NOPROBE);
	}

	irq_set_chained_handler(gpio_to_irq(VIPER_CPLD_GPIO),
				viper_irq_handler);
	irq_set_irq_type(gpio_to_irq(VIPER_CPLD_GPIO), IRQ_TYPE_EDGE_BOTH);
}

/* Flat Panel */
static struct pxafb_mode_info fb_mode_info[] = {
	{
		.pixclock	= 157500,

		.xres		= 320,
		.yres		= 240,

		.bpp		= 16,

		.hsync_len	= 63,
		.left_margin	= 7,
		.right_margin	= 13,

		.vsync_len	= 20,
		.upper_margin	= 0,
		.lower_margin	= 0,

		.sync		= 0,
	},
};

static struct pxafb_mach_info fb_info = {
	.modes			= fb_mode_info,
	.num_modes		= 1,
	.lcd_conn		= LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
};

static struct pwm_lookup viper_pwm_lookup[] = {
	PWM_LOOKUP("pxa25x-pwm.0", 0, "pwm-backlight.0", NULL, 1000000,
		   PWM_POLARITY_NORMAL),
};

static int viper_backlight_init(struct device *dev)
{
	int ret;

	/* GPIO9 and 10 control FB backlight. Initialise to off */
	ret = gpio_request(VIPER_BCKLIGHT_EN_GPIO, "Backlight");
	if (ret)
		goto err_request_bckl;

	ret = gpio_request(VIPER_LCD_EN_GPIO, "LCD");
	if (ret)
		goto err_request_lcd;

	ret = gpio_direction_output(VIPER_BCKLIGHT_EN_GPIO, 0);
	if (ret)
		goto err_dir;

	ret = gpio_direction_output(VIPER_LCD_EN_GPIO, 0);
	if (ret)
		goto err_dir;

	return 0;

err_dir:
	gpio_free(VIPER_LCD_EN_GPIO);
err_request_lcd:
	gpio_free(VIPER_BCKLIGHT_EN_GPIO);
err_request_bckl:
	dev_err(dev, "Failed to setup LCD GPIOs\n");

	return ret;
}

static int viper_backlight_notify(struct device *dev, int brightness)
{
	gpio_set_value(VIPER_LCD_EN_GPIO, !!brightness);
	gpio_set_value(VIPER_BCKLIGHT_EN_GPIO, !!brightness);

	return brightness;
}

static void viper_backlight_exit(struct device *dev)
{
	gpio_free(VIPER_LCD_EN_GPIO);
	gpio_free(VIPER_BCKLIGHT_EN_GPIO);
}

static struct platform_pwm_backlight_data viper_backlight_data = {
	.max_brightness	= 100,
	.dft_brightness	= 100,
	.init		= viper_backlight_init,
	.notify		= viper_backlight_notify,
	.exit		= viper_backlight_exit,
};

static struct platform_device viper_backlight_device = {
	.name		= "pwm-backlight",
	.dev		= {
		.parent		= &pxa25x_device_pwm0.dev,
		.platform_data	= &viper_backlight_data,
	},
};

/* Ethernet */
static struct resource smc91x_resources[] = {
	[0] = {
		.name	= "smc91x-regs",
		.start  = VIPER_ETH_PHYS + 0x300,
		.end    = VIPER_ETH_PHYS + 0x30f,
		.flags  = IORESOURCE_MEM,
	},
	[1] = {
		.start  = PXA_GPIO_TO_IRQ(VIPER_ETH_GPIO),
		.end    = PXA_GPIO_TO_IRQ(VIPER_ETH_GPIO),
		.flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
	},
	[2] = {
		.name	= "smc91x-data32",
		.start  = VIPER_ETH_DATA_PHYS,
		.end    = VIPER_ETH_DATA_PHYS + 3,
		.flags  = IORESOURCE_MEM,
	},
};

static struct smc91x_platdata viper_smc91x_info = {
	.flags	= SMC91X_USE_16BIT | SMC91X_NOWAIT,
	.leda	= RPC_LED_100_10,
	.ledb	= RPC_LED_TX_RX,
};

static struct platform_device smc91x_device = {
	.name		= "smc91x",
	.id		= -1,
	.num_resources  = ARRAY_SIZE(smc91x_resources),
	.resource       = smc91x_resources,
	.dev		= {
		.platform_data	= &viper_smc91x_info,
	},
};

/* i2c */
static struct gpiod_lookup_table viper_i2c_gpiod_table = {
	.dev_id		= "i2c-gpio.1",
	.table		= {
		GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO,
				NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
		GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO,
				NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
	},
};

static struct i2c_gpio_platform_data i2c_bus_data = {
	.udelay  = 10,
	.timeout = HZ,
};

static struct platform_device i2c_bus_device = {
	.name		= "i2c-gpio",
	.id		= 1, /* pxa2xx-i2c is bus 0, so start at 1 */
	.dev = {
		.platform_data = &i2c_bus_data,
	}
};

static struct i2c_board_info __initdata viper_i2c_devices[] = {
	{
		I2C_BOARD_INFO("ds1338", 0x68),
	},
};

/*
 * Serial configuration:
 * You can either have the standard PXA ports driven by the PXA driver,
 * or all the ports (PXA + 16850) driven by the 8250 driver.
 * Choose your poison.
 */

static struct resource viper_serial_resources[] = {
#ifndef CONFIG_SERIAL_PXA
	{
		.start	= 0x40100000,
		.end	= 0x4010001f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x40200000,
		.end	= 0x4020001f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x40700000,
		.end	= 0x4070001f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= VIPER_UARTA_PHYS,
		.end	= VIPER_UARTA_PHYS + 0xf,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= VIPER_UARTB_PHYS,
		.end	= VIPER_UARTB_PHYS + 0xf,
		.flags	= IORESOURCE_MEM,
	},
#else
	{
		0,
	},
#endif
};

static struct plat_serial8250_port serial_platform_data[] = {
#ifndef CONFIG_SERIAL_PXA
	/* Internal UARTs */
	{
		.membase	= (void *)&FFUART,
		.mapbase	= __PREG(FFUART),
		.irq		= IRQ_FFUART,
		.uartclk	= 921600 * 16,
		.regshift	= 2,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{
		.membase	= (void *)&BTUART,
		.mapbase	= __PREG(BTUART),
		.irq		= IRQ_BTUART,
		.uartclk	= 921600 * 16,
		.regshift	= 2,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{
		.membase	= (void *)&STUART,
		.mapbase	= __PREG(STUART),
		.irq		= IRQ_STUART,
		.uartclk	= 921600 * 16,
		.regshift	= 2,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	/* External UARTs */
	{
		.mapbase	= VIPER_UARTA_PHYS,
		.irq		= PXA_GPIO_TO_IRQ(VIPER_UARTA_GPIO),
		.irqflags	= IRQF_TRIGGER_RISING,
		.uartclk	= 1843200,
		.regshift	= 1,
		.iotype		= UPIO_MEM,
		.flags		= UPF_BOOT_AUTOCONF | UPF_IOREMAP |
				  UPF_SKIP_TEST,
	},
	{
		.mapbase	= VIPER_UARTB_PHYS,
		.irq		= PXA_GPIO_TO_IRQ(VIPER_UARTB_GPIO),
		.irqflags	= IRQF_TRIGGER_RISING,
		.uartclk	= 1843200,
		.regshift	= 1,
		.iotype		= UPIO_MEM,
		.flags		= UPF_BOOT_AUTOCONF | UPF_IOREMAP |
				  UPF_SKIP_TEST,
	},
#endif
	{ },
};

static struct platform_device serial_device = {
	.name			= "serial8250",
	.id			= 0,
	.dev			= {
		.platform_data	= serial_platform_data,
	},
	.num_resources		= ARRAY_SIZE(viper_serial_resources),
	.resource		= viper_serial_resources,
};

/* USB */
static void isp116x_delay(struct device *dev, int delay)
{
	ndelay(delay);
}

static struct resource isp116x_resources[] = {
	[0] = { /* DATA */
		.start  = VIPER_USB_PHYS + 0,
		.end    = VIPER_USB_PHYS + 1,
		.flags  = IORESOURCE_MEM,
	},
	[1] = { /* ADDR */
		.start  = VIPER_USB_PHYS + 2,
		.end    = VIPER_USB_PHYS + 3,
		.flags  = IORESOURCE_MEM,
	},
	[2] = {
		.start  = PXA_GPIO_TO_IRQ(VIPER_USB_GPIO),
		.end    = PXA_GPIO_TO_IRQ(VIPER_USB_GPIO),
		.flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
	},
};

/* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
static struct isp116x_platform_data isp116x_platform_data = {
	/* Enable internal resistors on downstream ports */
	.sel15Kres		= 1,
	/* On-chip overcurrent protection */
	.oc_enable		= 1,
	/* INT output polarity */
	.int_act_high		= 1,
	/* INT edge or level triggered */
	.int_edge_triggered	= 0,

	/* WAKEUP pin connected - NOT SUPPORTED  */
	/* .remote_wakeup_connected = 0, */
	/* Wakeup by devices on usb bus enabled */
	.remote_wakeup_enable	= 0,
	.delay			= isp116x_delay,
};

static struct platform_device isp116x_device = {
	.name			= "isp116x-hcd",
	.id			= -1,
	.num_resources  	= ARRAY_SIZE(isp116x_resources),
	.resource       	= isp116x_resources,
	.dev			= {
		.platform_data	= &isp116x_platform_data,
	},

};

/* MTD */
static struct resource mtd_resources[] = {
	[0] = {	/* RedBoot config + filesystem flash */
		.start	= VIPER_FLASH_PHYS,
		.end	= VIPER_FLASH_PHYS + SZ_32M - 1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {	/* Boot flash */
		.start	= VIPER_BOOT_PHYS,
		.end	= VIPER_BOOT_PHYS + SZ_1M - 1,
		.flags	= IORESOURCE_MEM,
	},
	[2] = { /*
		 * SRAM size is actually 256KB, 8bits, with a sparse mapping
		 * (each byte is on a 16bit boundary).
		 */
		.start	= _VIPER_SRAM_BASE,
		.end	= _VIPER_SRAM_BASE + SZ_512K - 1,
		.flags	= IORESOURCE_MEM,
	},
};

static struct mtd_partition viper_boot_flash_partition = {
	.name		= "RedBoot",
	.size		= SZ_1M,
	.offset		= 0,
	.mask_flags	= MTD_WRITEABLE,	/* force R/O */
};

static struct physmap_flash_data viper_flash_data[] = {
	[0] = {
		.width		= 2,
		.parts		= NULL,
		.nr_parts	= 0,
	},
	[1] = {
		.width		= 2,
		.parts		= &viper_boot_flash_partition,
		.nr_parts	= 1,
	},
};

static struct platform_device viper_mtd_devices[] = {
	[0] = {
		.name		= "physmap-flash",
		.id		= 0,
		.dev		= {
			.platform_data	= &viper_flash_data[0],
		},
		.resource	= &mtd_resources[0],
		.num_resources	= 1,
	},
	[1] = {
		.name		= "physmap-flash",
		.id		= 1,
		.dev		= {
			.platform_data	= &viper_flash_data[1],
		},
		.resource	= &mtd_resources[1],
		.num_resources	= 1,
	},
};

static struct platform_device *viper_devs[] __initdata = {
	&smc91x_device,
	&i2c_bus_device,
	&serial_device,
	&isp116x_device,
	&viper_mtd_devices[0],
	&viper_mtd_devices[1],
	&viper_backlight_device,
	&viper_pcmcia_device,
};

static mfp_cfg_t viper_pin_config[] __initdata = {
	/* Chip selects */
	GPIO15_nCS_1,
	GPIO78_nCS_2,
	GPIO79_nCS_3,
	GPIO80_nCS_4,
	GPIO33_nCS_5,

	/* AC97 */
	GPIO28_AC97_BITCLK,
	GPIO29_AC97_SDATA_IN_0,
	GPIO30_AC97_SDATA_OUT,
	GPIO31_AC97_SYNC,

	/* FP Backlight */
	GPIO9_GPIO, 				/* VIPER_BCKLIGHT_EN_GPIO */
	GPIO10_GPIO,				/* VIPER_LCD_EN_GPIO */
	GPIO16_PWM0_OUT,

	/* Ethernet PHY Ready */
	GPIO18_RDY,

	/* Serial shutdown */
	GPIO12_GPIO | MFP_LPM_DRIVE_HIGH,	/* VIPER_UART_SHDN_GPIO */

	/* Compact-Flash / PC104 */
	GPIO48_nPOE,
	GPIO49_nPWE,
	GPIO50_nPIOR,
	GPIO51_nPIOW,
	GPIO52_nPCE_1,
	GPIO53_nPCE_2,
	GPIO54_nPSKTSEL,
	GPIO55_nPREG,
	GPIO56_nPWAIT,
	GPIO57_nIOIS16,
	GPIO8_GPIO,				/* VIPER_CF_RDY_GPIO */
	GPIO32_GPIO,				/* VIPER_CF_CD_GPIO */
	GPIO82_GPIO,				/* VIPER_CF_POWER_GPIO */

	/* Integrated UPS control */
	GPIO20_GPIO,				/* VIPER_UPS_GPIO */

	/* Vcc regulator control */
	GPIO6_GPIO,				/* VIPER_PSU_DATA_GPIO */
	GPIO11_GPIO,				/* VIPER_PSU_CLK_GPIO */
	GPIO19_GPIO,				/* VIPER_PSU_nCS_LD_GPIO */

	/* i2c busses */
	GPIO26_GPIO,				/* VIPER_TPM_I2C_SDA_GPIO */
	GPIO27_GPIO,				/* VIPER_TPM_I2C_SCL_GPIO */
	GPIO83_GPIO,				/* VIPER_RTC_I2C_SDA_GPIO */
	GPIO84_GPIO,				/* VIPER_RTC_I2C_SCL_GPIO */

	/* PC/104 Interrupt */
	GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,	/* VIPER_CPLD_GPIO */
};

static unsigned long viper_tpm;

static int __init viper_tpm_setup(char *str)
{
	return kstrtoul(str, 10, &viper_tpm) >= 0;
}

__setup("tpm=", viper_tpm_setup);

struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = {
	.dev_id = "i2c-gpio.2",
	.table = {
		GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO,
				NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
		GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO,
				NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
	},
};

static void __init viper_tpm_init(void)
{
	struct platform_device *tpm_device;
	struct i2c_gpio_platform_data i2c_tpm_data = {
		.udelay  = 10,
		.timeout = HZ,
	};
	char *errstr;

	/* Allocate TPM i2c bus if requested */
	if (!viper_tpm)
		return;

	gpiod_add_lookup_table(&viper_tpm_i2c_gpiod_table);
	tpm_device = platform_device_alloc("i2c-gpio", 2);
	if (tpm_device) {
		if (!platform_device_add_data(tpm_device,
					      &i2c_tpm_data,
					      sizeof(i2c_tpm_data))) {
			if (platform_device_add(tpm_device)) {
				errstr = "register TPM i2c bus";
				goto error_free_tpm;
			}
		} else {
			errstr = "allocate TPM i2c bus data";
			goto error_free_tpm;
		}
	} else {
		errstr = "allocate TPM i2c device";
		goto error_tpm;
	}

	return;

error_free_tpm:
	kfree(tpm_device);
error_tpm:
	pr_err("viper: Couldn't %s, giving up\n", errstr);
}

static void __init viper_init_vcore_gpios(void)
{
	if (gpio_request(VIPER_PSU_DATA_GPIO, "PSU data"))
		goto err_request_data;

	if (gpio_request(VIPER_PSU_CLK_GPIO, "PSU clock"))
		goto err_request_clk;

	if (gpio_request(VIPER_PSU_nCS_LD_GPIO, "PSU cs"))
		goto err_request_cs;

	if (gpio_direction_output(VIPER_PSU_DATA_GPIO, 0) ||
	    gpio_direction_output(VIPER_PSU_CLK_GPIO, 0) ||
	    gpio_direction_output(VIPER_PSU_nCS_LD_GPIO, 0))
		goto err_dir;

	/* c/should assume redboot set the correct level ??? */
	viper_set_core_cpu_voltage(pxa25x_get_clk_frequency_khz(0), 1);

	return;

err_dir:
	gpio_free(VIPER_PSU_nCS_LD_GPIO);
err_request_cs:
	gpio_free(VIPER_PSU_CLK_GPIO);
err_request_clk:
	gpio_free(VIPER_PSU_DATA_GPIO);
err_request_data:
	pr_err("viper: Failed to setup vcore control GPIOs\n");
}

static void __init viper_init_serial_gpio(void)
{
	if (gpio_request(VIPER_UART_SHDN_GPIO, "UARTs shutdown"))
		goto err_request;

	if (gpio_direction_output(VIPER_UART_SHDN_GPIO, 0))
		goto err_dir;

	return;

err_dir:
	gpio_free(VIPER_UART_SHDN_GPIO);
err_request:
	pr_err("viper: Failed to setup UART shutdown GPIO\n");
}

#ifdef CONFIG_CPU_FREQ
static int viper_cpufreq_notifier(struct notifier_block *nb,
				  unsigned long val, void *data)
{
	struct cpufreq_freqs *freq = data;

	/* TODO: Adjust timings??? */

	switch (val) {
	case CPUFREQ_PRECHANGE:
		if (freq->old < freq->new) {
			/* we are getting faster so raise the voltage
			 * before we change freq */
			viper_set_core_cpu_voltage(freq->new, 0);
		}
		break;
	case CPUFREQ_POSTCHANGE:
		if (freq->old > freq->new) {
			/* we are slowing down so drop the power
			 * after we change freq */
			viper_set_core_cpu_voltage(freq->new, 0);
		}
		break;
	default:
		/* ignore */
		break;
	}

	return 0;
}

static struct notifier_block viper_cpufreq_notifier_block = {
	.notifier_call  = viper_cpufreq_notifier
};

static void __init viper_init_cpufreq(void)
{
	if (cpufreq_register_notifier(&viper_cpufreq_notifier_block,
				      CPUFREQ_TRANSITION_NOTIFIER))
		pr_err("viper: Failed to setup cpufreq notifier\n");
}
#else
static inline void viper_init_cpufreq(void) {}
#endif

static void viper_power_off(void)
{
	pr_notice("Shutting off UPS\n");
	gpio_set_value(VIPER_UPS_GPIO, 1);
	/* Spin to death... */
	while (1);
}

static void __init viper_init(void)
{
	u8 version;

	pm_power_off = viper_power_off;

	pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));

	pxa_set_ffuart_info(NULL);
	pxa_set_btuart_info(NULL);
	pxa_set_stuart_info(NULL);

	/* Wake-up serial console */
	viper_init_serial_gpio();

	pxa_set_fb_info(NULL, &fb_info);

	/* v1 hardware cannot use the datacs line */
	version = viper_hw_version();
	if (version == 0)
		smc91x_device.num_resources--;

	pxa_set_i2c_info(NULL);
	gpiod_add_lookup_table(&viper_i2c_gpiod_table);
	pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup));
	platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));

	viper_init_vcore_gpios();
	viper_init_cpufreq();

	register_syscore_ops(&viper_cpu_syscore_ops);

	if (version) {
		pr_info("viper: hardware v%di%d detected. "
			"CPLD revision %d.\n",
			VIPER_BOARD_VERSION(version),
			VIPER_BOARD_ISSUE(version),
			VIPER_CPLD_REVISION(version));
		system_rev = (VIPER_BOARD_VERSION(version) << 8) |
			     (VIPER_BOARD_ISSUE(version) << 4) |
			     VIPER_CPLD_REVISION(version);
	} else {
		pr_info("viper: No version register.\n");
	}

	i2c_register_board_info(1, ARRAY_AND_SIZE(viper_i2c_devices));

	viper_tpm_init();
	pxa_set_ac97_info(NULL);
}

static struct map_desc viper_io_desc[] __initdata = {
	{
		.virtual = VIPER_CPLD_BASE,
		.pfn     = __phys_to_pfn(VIPER_CPLD_PHYS),
		.length  = 0x00300000,
		.type    = MT_DEVICE,
	},
	{
		.virtual = VIPER_PC104IO_BASE,
		.pfn     = __phys_to_pfn(0x30000000),
		.length  = 0x00800000,
		.type    = MT_DEVICE,
	},
	{
		/*
		 * ISA I/O space mapping:
		 * -  ports 0x0000-0x0fff are PC/104
		 * -  ports 0x10000-0x10fff are PCMCIA slot 1
		 * -  ports 0x11000-0x11fff are PC/104
		 */
		.virtual = PCI_IO_VIRT_BASE,
		.pfn     = __phys_to_pfn(0x30000000),
		.length  = 0x1000,
		.type    = MT_DEVICE,
	},
};

static void __init viper_map_io(void)
{
	pxa25x_map_io();

	iotable_init(viper_io_desc, ARRAY_SIZE(viper_io_desc));

	PCFR |= PCFR_OPDE;
}

MACHINE_START(VIPER, "Arcom/Eurotech VIPER SBC")
	/* Maintainer: Marc Zyngier <maz@misterjones.org> */
	.atag_offset	= 0x100,
	.map_io		= viper_map_io,
	.nr_irqs	= PXA_NR_IRQS,
	.init_irq	= viper_init_irq,
	.handle_irq	= pxa25x_handle_irq,
	.init_time	= pxa_timer_init,
	.init_machine	= viper_init,
	.restart	= pxa_restart,
MACHINE_END


code:
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * arch/arm/mach-pxa/include/mach/viper.h
 *
 * Author:	Ian Campbell
 * Created:	Feb 03, 2003
 * Copyright:	Arcom Control Systems.
 *
 * Maintained by Marc Zyngier <maz@misterjones.org>
 *			      <marc.zyngier@altran.com>
 *
 * Created based on lubbock.h:
 *  Author:	Nicolas Pitre
 *  Created:	Jun 15, 2001
 *  Copyright:	MontaVista Software Inc.
 */

#ifndef ARCH_VIPER_H
#define ARCH_VIPER_H

#define VIPER_BOOT_PHYS		PXA_CS0_PHYS
#define VIPER_FLASH_PHYS	PXA_CS1_PHYS
#define VIPER_ETH_PHYS		PXA_CS2_PHYS
#define VIPER_USB_PHYS		PXA_CS3_PHYS
#define VIPER_ETH_DATA_PHYS	PXA_CS4_PHYS
#define VIPER_CPLD_PHYS		PXA_CS5_PHYS

#define VIPER_CPLD_BASE		(0xf0000000)
#define VIPER_PC104IO_BASE	(0xf1000000)
#define VIPER_USB_BASE		(0xf1800000)

#define VIPER_ETH_GPIO		(0)
#define VIPER_CPLD_GPIO		(1)
#define VIPER_USB_GPIO		(2)
#define VIPER_UARTA_GPIO	(4)
#define VIPER_UARTB_GPIO	(3)
#define VIPER_CF_CD_GPIO	(32)
#define VIPER_CF_RDY_GPIO	(8)
#define VIPER_BCKLIGHT_EN_GPIO	(9)
#define VIPER_LCD_EN_GPIO	(10)
#define VIPER_PSU_DATA_GPIO	(6)
#define VIPER_PSU_CLK_GPIO	(11)
#define VIPER_UART_SHDN_GPIO	(12)
#define VIPER_BRIGHTNESS_GPIO	(16)
#define VIPER_PSU_nCS_LD_GPIO	(19)
#define VIPER_UPS_GPIO		(20)
#define VIPER_CF_POWER_GPIO	(82)
#define VIPER_TPM_I2C_SDA_GPIO	(26)
#define VIPER_TPM_I2C_SCL_GPIO	(27)
#define VIPER_RTC_I2C_SDA_GPIO	(83)
#define VIPER_RTC_I2C_SCL_GPIO	(84)

#define VIPER_CPLD_P2V(x)	((x) - VIPER_CPLD_PHYS + VIPER_CPLD_BASE)
#define VIPER_CPLD_V2P(x)	((x) - VIPER_CPLD_BASE + VIPER_CPLD_PHYS)

#ifndef __ASSEMBLY__
#  define __VIPER_CPLD_REG(x)	(*((volatile u16 *)VIPER_CPLD_P2V(x)))
#endif

/* board level registers in the CPLD: (offsets from CPLD_BASE) ... */

/* ... Physical addresses */
#define _VIPER_LO_IRQ_STATUS	(VIPER_CPLD_PHYS + 0x100000)
#define _VIPER_ICR_PHYS		(VIPER_CPLD_PHYS + 0x100002)
#define _VIPER_HI_IRQ_STATUS	(VIPER_CPLD_PHYS + 0x100004)
#define _VIPER_VERSION_PHYS	(VIPER_CPLD_PHYS + 0x100006)
#define VIPER_UARTA_PHYS	(VIPER_CPLD_PHYS + 0x300010)
#define VIPER_UARTB_PHYS	(VIPER_CPLD_PHYS + 0x300000)
#define _VIPER_SRAM_BASE	(VIPER_CPLD_PHYS + 0x800000)

/* ... Virtual addresses */
#define VIPER_LO_IRQ_STATUS	__VIPER_CPLD_REG(_VIPER_LO_IRQ_STATUS)
#define VIPER_HI_IRQ_STATUS	__VIPER_CPLD_REG(_VIPER_HI_IRQ_STATUS)
#define VIPER_VERSION		__VIPER_CPLD_REG(_VIPER_VERSION_PHYS)
#define VIPER_ICR		__VIPER_CPLD_REG(_VIPER_ICR_PHYS)

/* Decode VIPER_VERSION register */
#define VIPER_CPLD_REVISION(x)	(((x) >> 5) & 0x7)
#define VIPER_BOARD_VERSION(x)	(((x) >> 3) & 0x3)
#define VIPER_BOARD_ISSUE(x)	(((x) >> 0) & 0x7)

/* Interrupt and Configuration Register (VIPER_ICR) */
/* This is a write only register. Only CF_RST is used under Linux */

#define VIPER_ICR_RETRIG	(1 << 0)
#define VIPER_ICR_AUTO_CLR	(1 << 1)
#define VIPER_ICR_R_DIS		(1 << 2)
#define VIPER_ICR_CF_RST	(1 << 3)

#endif

repo_name: angery/linux


code:
// SPDX-License-Identifier: GPL-2.0-only
/*
 * linux/drivers/pcmcia/pxa2xx_vpac270.c
 *
 * Driver for Voipac PXA270 PCMCIA and CF sockets
 *
 * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
 */

#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/platform_device.h>

#include <asm/mach-types.h>

#include "vpac270.h"

#include <pcmcia/soc_common.h>

static struct gpio vpac270_pcmcia_gpios[] = {
	{ GPIO107_VPAC270_PCMCIA_PPEN,	GPIOF_INIT_LOW,	"PCMCIA PPEN" },
	{ GPIO11_VPAC270_PCMCIA_RESET,	GPIOF_INIT_LOW,	"PCMCIA Reset" },
};

static struct gpio vpac270_cf_gpios[] = {
	{ GPIO16_VPAC270_CF_RESET,	GPIOF_INIT_LOW,	"CF Reset" },
};

static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
{
	int ret;

	if (skt->nr == 0) {
		ret = gpio_request_array(vpac270_pcmcia_gpios,
				ARRAY_SIZE(vpac270_pcmcia_gpios));

		skt->stat[SOC_STAT_CD].gpio = GPIO84_VPAC270_PCMCIA_CD;
		skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
		skt->stat[SOC_STAT_RDY].gpio = GPIO35_VPAC270_PCMCIA_RDY;
		skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
	} else {
		ret = gpio_request_array(vpac270_cf_gpios,
				ARRAY_SIZE(vpac270_cf_gpios));

		skt->stat[SOC_STAT_CD].gpio = GPIO17_VPAC270_CF_CD;
		skt->stat[SOC_STAT_CD].name = "CF CD";
		skt->stat[SOC_STAT_RDY].gpio = GPIO12_VPAC270_CF_RDY;
		skt->stat[SOC_STAT_RDY].name = "CF Ready";
	}

	return ret;
}

static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
{
	if (skt->nr == 0)
		gpio_free_array(vpac270_pcmcia_gpios,
					ARRAY_SIZE(vpac270_pcmcia_gpios));
	else
		gpio_free_array(vpac270_cf_gpios,
					ARRAY_SIZE(vpac270_cf_gpios));
}

static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
					struct pcmcia_state *state)
{
	state->vs_3v  = 1;
	state->vs_Xv  = 0;
}

static int
vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
				const socket_state_t *state)
{
	if (skt->nr == 0) {
		gpio_set_value(GPIO11_VPAC270_PCMCIA_RESET,
			(state->flags & SS_RESET));
		gpio_set_value(GPIO107_VPAC270_PCMCIA_PPEN,
			!(state->Vcc == 33 || state->Vcc == 50));
	} else {
		gpio_set_value(GPIO16_VPAC270_CF_RESET,
			(state->flags & SS_RESET));
	}

	return 0;
}

static struct pcmcia_low_level vpac270_pcmcia_ops = {
	.owner			= THIS_MODULE,

	.first			= 0,
	.nr			= 2,

	.hw_init		= vpac270_pcmcia_hw_init,
	.hw_shutdown		= vpac270_pcmcia_hw_shutdown,

	.socket_state		= vpac270_pcmcia_socket_state,
	.configure_socket	= vpac270_pcmcia_configure_socket,
};

static struct platform_device *vpac270_pcmcia_device;

static int __init vpac270_pcmcia_init(void)
{
	int ret;

	if (!machine_is_vpac270())
		return -ENODEV;

	vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
	if (!vpac270_pcmcia_device)
		return -ENOMEM;

	ret = platform_device_add_data(vpac270_pcmcia_device,
		&vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops));

	if (!ret)
		ret = platform_device_add(vpac270_pcmcia_device);

	if (ret)
		platform_device_put(vpac270_pcmcia_device);

	return ret;
}

static void __exit vpac270_pcmcia_exit(void)
{
	platform_device_unregister(vpac270_pcmcia_device);
}

module_init(vpac270_pcmcia_init);
module_exit(vpac270_pcmcia_exit);

MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270");
MODULE_ALIAS("platform:pxa2xx-pcmcia");
MODULE_LICENSE("GPL");


code:
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Hardware definitions for Voipac PXA270
 *
 * Copyright (C) 2010
 * Marek Vasut <marek.vasut@gmail.com>
 */

#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/gpio_keys.h>
#include <linux/input.h>
#include <linux/leds.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
#include <linux/mtd/onenand.h>
#include <linux/dm9000.h>
#include <linux/ucb1400.h>
#include <linux/ata_platform.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/max1586.h>
#include <linux/platform_data/i2c-pxa.h>

#include <asm/mach-types.h>
#include <asm/mach/arch.h>

#include "pxa27x.h"
#include <linux/platform_data/asoc-pxa.h>
#include "vpac270.h"
#include <linux/platform_data/mmc-pxamci.h>
#include <linux/platform_data/video-pxafb.h>
#include <linux/platform_data/usb-ohci-pxa27x.h>
#include "pxa27x-udc.h"
#include "udc.h"
#include <linux/platform_data/ata-pxa.h>

#include "generic.h"
#include "devices.h"

/******************************************************************************
 * Pin configuration
 ******************************************************************************/
static unsigned long vpac270_pin_config[] __initdata = {
	/* MMC */
	GPIO32_MMC_CLK,
	GPIO92_MMC_DAT_0,
	GPIO109_MMC_DAT_1,
	GPIO110_MMC_DAT_2,
	GPIO111_MMC_DAT_3,
	GPIO112_MMC_CMD,
	GPIO53_GPIO,	/* SD detect */
	GPIO52_GPIO,	/* SD r/o switch */

	/* GPIO KEYS */
	GPIO1_GPIO,	/* USER BTN */

	/* LEDs */
	GPIO15_GPIO,	/* orange led */

	/* FFUART */
	GPIO34_FFUART_RXD,
	GPIO39_FFUART_TXD,
	GPIO27_FFUART_RTS,
	GPIO100_FFUART_CTS,
	GPIO33_FFUART_DSR,
	GPIO40_FFUART_DTR,
	GPIO10_FFUART_DCD,
	GPIO38_FFUART_RI,

	/* LCD */
	GPIO58_LCD_LDD_0,
	GPIO59_LCD_LDD_1,
	GPIO60_LCD_LDD_2,
	GPIO61_LCD_LDD_3,
	GPIO62_LCD_LDD_4,
	GPIO63_LCD_LDD_5,
	GPIO64_LCD_LDD_6,
	GPIO65_LCD_LDD_7,
	GPIO66_LCD_LDD_8,
	GPIO67_LCD_LDD_9,
	GPIO68_LCD_LDD_10,
	GPIO69_LCD_LDD_11,
	GPIO70_LCD_LDD_12,
	GPIO71_LCD_LDD_13,
	GPIO72_LCD_LDD_14,
	GPIO73_LCD_LDD_15,
	GPIO86_LCD_LDD_16,
	GPIO87_LCD_LDD_17,
	GPIO74_LCD_FCLK,
	GPIO75_LCD_LCLK,
	GPIO76_LCD_PCLK,
	GPIO77_LCD_BIAS,

	/* PCMCIA */
	GPIO48_nPOE,
	GPIO49_nPWE,
	GPIO50_nPIOR,
	GPIO51_nPIOW,
	GPIO85_nPCE_1,
	GPIO54_nPCE_2,
	GPIO55_nPREG,
	GPIO57_nIOIS16,
	GPIO56_nPWAIT,
	GPIO104_PSKTSEL,
	GPIO84_GPIO,	/* PCMCIA CD */
	GPIO35_GPIO,	/* PCMCIA RDY */
	GPIO107_GPIO,	/* PCMCIA PPEN */
	GPIO11_GPIO,	/* PCMCIA RESET */
	GPIO17_GPIO,	/* CF CD */
	GPIO12_GPIO,	/* CF RDY */
	GPIO16_GPIO,	/* CF RESET */

	/* UHC */
	GPIO88_USBH1_PWR,
	GPIO89_USBH1_PEN,
	GPIO119_USBH2_PWR,
	GPIO120_USBH2_PEN,

	/* UDC */
	GPIO41_GPIO,

	/* Ethernet */
	GPIO114_GPIO,	/* IRQ */

	/* AC97 */
	GPIO28_AC97_BITCLK,
	GPIO29_AC97_SDATA_IN_0,
	GPIO30_AC97_SDATA_OUT,
	GPIO31_AC97_SYNC,
	GPIO95_AC97_nRESET,
	GPIO98_AC97_SYSCLK,
	GPIO113_GPIO,	/* TS IRQ */

	/* I2C */
	GPIO117_I2C_SCL,
	GPIO118_I2C_SDA,

	/* IDE */
	GPIO36_GPIO,	/* IDE IRQ */
	GPIO80_DREQ_1,
};

/******************************************************************************
 * NOR Flash
 ******************************************************************************/
#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
static struct mtd_partition vpac270_nor_partitions[] = {
	{
		.name		= "Flash",
		.offset		= 0x00000000,
		.size		= MTDPART_SIZ_FULL,
	}
};

static struct physmap_flash_data vpac270_flash_data[] = {
	{
		.width		= 2,	/* bankwidth in bytes */
		.parts		= vpac270_nor_partitions,
		.nr_parts	= ARRAY_SIZE(vpac270_nor_partitions)
	}
};

static struct resource vpac270_flash_resource = {
	.start	= PXA_CS0_PHYS,
	.end	= PXA_CS0_PHYS + SZ_64M - 1,
	.flags	= IORESOURCE_MEM,
};

static struct platform_device vpac270_flash = {
	.name		= "physmap-flash",
	.id		= 0,
	.resource	= &vpac270_flash_resource,
	.num_resources	= 1,
	.dev 		= {
		.platform_data = vpac270_flash_data,
	},
};
static void __init vpac270_nor_init(void)
{
	platform_device_register(&vpac270_flash);
}
#else
static inline void vpac270_nor_init(void) {}
#endif

/******************************************************************************
 * OneNAND Flash
 ******************************************************************************/
#if defined(CONFIG_MTD_ONENAND) || defined(CONFIG_MTD_ONENAND_MODULE)
static struct mtd_partition vpac270_onenand_partitions[] = {
	{
		.name		= "Flash",
		.offset		= 0x00000000,
		.size		= MTDPART_SIZ_FULL,
	}
};

static struct onenand_platform_data vpac270_onenand_info = {
	.parts		= vpac270_onenand_partitions,
	.nr_parts	= ARRAY_SIZE(vpac270_onenand_partitions),
};

static struct resource vpac270_onenand_resources[] = {
	[0] = {
		.start	= PXA_CS0_PHYS,
		.end	= PXA_CS0_PHYS + SZ_1M,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device vpac270_onenand = {
	.name		= "onenand-flash",
	.id		= -1,
	.resource	= vpac270_onenand_resources,
	.num_resources	= ARRAY_SIZE(vpac270_onenand_resources),
	.dev		= {
		.platform_data	= &vpac270_onenand_info,
	},
};

static void __init vpac270_onenand_init(void)
{
	platform_device_register(&vpac270_onenand);
}
#else
static void __init vpac270_onenand_init(void) {}
#endif

/******************************************************************************
 * SD/MMC card controller
 ******************************************************************************/
#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
static struct pxamci_platform_data vpac270_mci_platform_data = {
	.ocr_mask		= MMC_VDD_32_33 | MMC_VDD_33_34,
	.detect_delay_ms	= 200,
};

static struct gpiod_lookup_table vpac270_mci_gpio_table = {
	.dev_id = "pxa2xx-mci.0",
	.table = {
		GPIO_LOOKUP("gpio-pxa", GPIO53_VPAC270_SD_DETECT_N,
			    "cd", GPIO_ACTIVE_LOW),
		GPIO_LOOKUP("gpio-pxa", GPIO52_VPAC270_SD_READONLY,
			    "wp", GPIO_ACTIVE_LOW),
		{ },
	},
};

static void __init vpac270_mmc_init(void)
{
	gpiod_add_lookup_table(&vpac270_mci_gpio_table);
	pxa_set_mci_info(&vpac270_mci_platform_data);
}
#else
static inline void vpac270_mmc_init(void) {}
#endif

/******************************************************************************
 * GPIO keys
 ******************************************************************************/
#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
static struct gpio_keys_button vpac270_pxa_buttons[] = {
	{KEY_POWER, GPIO1_VPAC270_USER_BTN, 0, "USER BTN"},
};

static struct gpio_keys_platform_data vpac270_pxa_keys_data = {
	.buttons	= vpac270_pxa_buttons,
	.nbuttons	= ARRAY_SIZE(vpac270_pxa_buttons),
};

static struct platform_device vpac270_pxa_keys = {
	.name	= "gpio-keys",
	.id	= -1,
	.dev	= {
		.platform_data = &vpac270_pxa_keys_data,
	},
};

static void __init vpac270_keys_init(void)
{
	platform_device_register(&vpac270_pxa_keys);
}
#else
static inline void vpac270_keys_init(void) {}
#endif

/******************************************************************************
 * LED
 ******************************************************************************/
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
struct gpio_led vpac270_gpio_leds[] = {
{
	.name			= "vpac270:orange:user",
	.default_trigger	= "none",
	.gpio			= GPIO15_VPAC270_LED_ORANGE,
	.active_low		= 1,
}
};

static struct gpio_led_platform_data vpac270_gpio_led_info = {
	.leds		= vpac270_gpio_leds,
	.num_leds	= ARRAY_SIZE(vpac270_gpio_leds),
};

static struct platform_device vpac270_leds = {
	.name	= "leds-gpio",
	.id	= -1,
	.dev	= {
		.platform_data	= &vpac270_gpio_led_info,
	}
};

static void __init vpac270_leds_init(void)
{
	platform_device_register(&vpac270_leds);
}
#else
static inline void vpac270_leds_init(void) {}
#endif

/******************************************************************************
 * USB Host
 ******************************************************************************/
#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
static int vpac270_ohci_init(struct device *dev)
{
	UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
	return 0;
}

static struct pxaohci_platform_data vpac270_ohci_info = {
	.port_mode	= PMM_PERPORT_MODE,
	.flags		= ENABLE_PORT1 | ENABLE_PORT2 |
			POWER_CONTROL_LOW | POWER_SENSE_LOW,
	.init		= vpac270_ohci_init,
};

static void __init vpac270_uhc_init(void)
{
	pxa_set_ohci_info(&vpac270_ohci_info);
}
#else
static inline void vpac270_uhc_init(void) {}
#endif

/******************************************************************************
 * USB Gadget
 ******************************************************************************/
#if defined(CONFIG_USB_PXA27X)||defined(CONFIG_USB_PXA27X_MODULE)
static struct gpiod_lookup_table vpac270_gpio_vbus_gpiod_table = {
	.dev_id = "gpio-vbus",
	.table = {
		GPIO_LOOKUP("gpio-pxa", GPIO41_VPAC270_UDC_DETECT,
			    "vbus", GPIO_ACTIVE_HIGH),
		{ },
	},
};

static struct platform_device vpac270_gpio_vbus = {
	.name	= "gpio-vbus",
	.id	= -1,
};

static void vpac270_udc_command(int cmd)
{
	if (cmd == PXA2XX_UDC_CMD_CONNECT)
		UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE;
	else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
		UP2OCR = UP2OCR_HXOE;
}

static struct pxa2xx_udc_mach_info vpac270_udc_info __initdata = {
	.udc_command		= vpac270_udc_command,
	.gpio_pullup		= -1,
};

static void __init vpac270_udc_init(void)
{
	pxa_set_udc_info(&vpac270_udc_info);
	gpiod_add_lookup_table(&vpac270_gpio_vbus_gpiod_table);
	platform_device_register(&vpac270_gpio_vbus);
}
#else
static inline void vpac270_udc_init(void) {}
#endif

/******************************************************************************
 * Ethernet
 ******************************************************************************/
#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
static struct resource vpac270_dm9000_resources[] = {
	[0] = {
		.start	= PXA_CS2_PHYS + 0x300,
		.end	= PXA_CS2_PHYS + 0x303,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start	= PXA_CS2_PHYS + 0x304,
		.end	= PXA_CS2_PHYS + 0x343,
		.flags	= IORESOURCE_MEM,
	},
	[2] = {
		.start	= PXA_GPIO_TO_IRQ(GPIO114_VPAC270_ETH_IRQ),
		.end	= PXA_GPIO_TO_IRQ(GPIO114_VPAC270_ETH_IRQ),
		.flags	= IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
	},
};

static struct dm9000_plat_data vpac270_dm9000_platdata = {
	.flags		= DM9000_PLATF_32BITONLY,
};

static struct platform_device vpac270_dm9000_device = {
	.name		= "dm9000",
	.id		= -1,
	.num_resources	= ARRAY_SIZE(vpac270_dm9000_resources),
	.resource	= vpac270_dm9000_resources,
	.dev		= {
		.platform_data = &vpac270_dm9000_platdata,
	}
};

static void __init vpac270_eth_init(void)
{
	platform_device_register(&vpac270_dm9000_device);
}
#else
static inline void vpac270_eth_init(void) {}
#endif

/******************************************************************************
 * Audio and Touchscreen
 ******************************************************************************/
#if	defined(CONFIG_TOUCHSCREEN_UCB1400) || \
	defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
static pxa2xx_audio_ops_t vpac270_ac97_pdata = {
	.reset_gpio	= 95,
};

static struct ucb1400_pdata vpac270_ucb1400_pdata = {
	.irq		= PXA_GPIO_TO_IRQ(GPIO113_VPAC270_TS_IRQ),
};

static struct platform_device vpac270_ucb1400_device = {
	.name		= "ucb1400_core",
	.id		= -1,
	.dev		= {
		.platform_data = &vpac270_ucb1400_pdata,
	},
};

static void __init vpac270_ts_init(void)
{
	pxa_set_ac97_info(&vpac270_ac97_pdata);
	platform_device_register(&vpac270_ucb1400_device);
}
#else
static inline void vpac270_ts_init(void) {}
#endif

/******************************************************************************
 * RTC
 ******************************************************************************/
#if defined(CONFIG_RTC_DRV_DS1307) || defined(CONFIG_RTC_DRV_DS1307_MODULE)
static struct i2c_board_info __initdata vpac270_i2c_devs[] = {
	{
		I2C_BOARD_INFO("ds1339", 0x68),
	},
};

static void __init vpac270_rtc_init(void)
{
	i2c_register_board_info(0, ARRAY_AND_SIZE(vpac270_i2c_devs));
}
#else
static inline void vpac270_rtc_init(void) {}
#endif

/******************************************************************************
 * Framebuffer
 ******************************************************************************/
#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
static struct pxafb_mode_info vpac270_lcd_modes[] = {
{
	.pixclock	= 57692,
	.xres		= 640,
	.yres		= 480,
	.bpp		= 32,
	.depth		= 18,

	.left_margin	= 144,
	.right_margin	= 32,
	.upper_margin	= 13,
	.lower_margin	= 30,

	.hsync_len	= 32,
	.vsync_len	= 2,

	.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
}, {	/* CRT 640x480 */
	.pixclock	= 35000,
	.xres		= 640,
	.yres		= 480,
	.bpp		= 16,
	.depth		= 16,

	.left_margin	= 96,
	.right_margin	= 48,
	.upper_margin	= 33,
	.lower_margin	= 10,

	.hsync_len	= 48,
	.vsync_len	= 1,

	.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
}, {	/* CRT 800x600 H=30kHz V=48HZ */
	.pixclock	= 25000,
	.xres		= 800,
	.yres		= 600,
	.bpp		= 16,
	.depth		= 16,

	.left_margin	= 50,
	.right_margin	= 1,
	.upper_margin	= 21,
	.lower_margin	= 12,

	.hsync_len	= 8,
	.vsync_len	= 1,

	.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
}, {	/* CRT 1024x768 H=40kHz V=50Hz */
	.pixclock	= 15000,
	.xres		= 1024,
	.yres		= 768,
	.bpp		= 16,
	.depth		= 16,

	.left_margin	= 220,
	.right_margin	= 8,
	.upper_margin	= 33,
	.lower_margin	= 2,

	.hsync_len	= 48,
	.vsync_len	= 1,

	.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
}
};

static struct pxafb_mach_info vpac270_lcd_screen = {
	.modes		= vpac270_lcd_modes,
	.num_modes	= ARRAY_SIZE(vpac270_lcd_modes),
	.lcd_conn	= LCD_COLOR_TFT_18BPP,
};

static void vpac270_lcd_power(int on, struct fb_var_screeninfo *info)
{
	gpio_set_value(GPIO81_VPAC270_BKL_ON, on);
}

static void __init vpac270_lcd_init(void)
{
	int ret;

	ret = gpio_request(GPIO81_VPAC270_BKL_ON, "BKL-ON");
	if (ret) {
		pr_err("Requesting BKL-ON GPIO failed!\n");
		goto err;
	}

	ret = gpio_direction_output(GPIO81_VPAC270_BKL_ON, 1);
	if (ret) {
		pr_err("Setting BKL-ON GPIO direction failed!\n");
		goto err2;
	}

	vpac270_lcd_screen.pxafb_lcd_power = vpac270_lcd_power;
	pxa_set_fb_info(NULL, &vpac270_lcd_screen);
	return;

err2:
	gpio_free(GPIO81_VPAC270_BKL_ON);
err:
	return;
}
#else
static inline void vpac270_lcd_init(void) {}
#endif

/******************************************************************************
 * PATA IDE
 ******************************************************************************/
#if defined(CONFIG_PATA_PXA) || defined(CONFIG_PATA_PXA_MODULE)
static struct pata_pxa_pdata vpac270_pata_pdata = {
	.reg_shift	= 1,
	.dma_dreq	= 1,
	.irq_flags	= IRQF_TRIGGER_RISING,
};

static struct resource vpac270_ide_resources[] = {
	[0] = {	/* I/O Base address */
	       .start	= PXA_CS3_PHYS + 0x120,
	       .end	= PXA_CS3_PHYS + 0x13f,
	       .flags	= IORESOURCE_MEM
	},
	[1] = {	/* CTL Base address */
	       .start	= PXA_CS3_PHYS + 0x15c,
	       .end	= PXA_CS3_PHYS + 0x15f,
	       .flags	= IORESOURCE_MEM
	},
	[2] = {	/* DMA Base address */
	       .start	= PXA_CS3_PHYS + 0x20,
	       .end	= PXA_CS3_PHYS + 0x2f,
	       .flags	= IORESOURCE_DMA
	},
	[3] = {	/* IDE IRQ pin */
	       .start	= PXA_GPIO_TO_IRQ(GPIO36_VPAC270_IDE_IRQ),
	       .end	= PXA_GPIO_TO_IRQ(GPIO36_VPAC270_IDE_IRQ),
	       .flags	= IORESOURCE_IRQ
	}
};

static struct platform_device vpac270_ide_device = {
	.name		= "pata_pxa",
	.num_resources	= ARRAY_SIZE(vpac270_ide_resources),
	.resource	= vpac270_ide_resources,
	.dev		= {
		.platform_data	= &vpac270_pata_pdata,
		.coherent_dma_mask	= 0xffffffff,
	}
};

static void __init vpac270_ide_init(void)
{
	platform_device_register(&vpac270_ide_device);
}
#else
static inline void vpac270_ide_init(void) {}
#endif

/******************************************************************************
 * Core power regulator
 ******************************************************************************/
#if defined(CONFIG_REGULATOR_MAX1586) || \
    defined(CONFIG_REGULATOR_MAX1586_MODULE)
static struct regulator_consumer_supply vpac270_max1587a_consumers[] = {
	REGULATOR_SUPPLY("vcc_core", NULL),
};

static struct regulator_init_data vpac270_max1587a_v3_info = {
	.constraints = {
		.name		= "vcc_core range",
		.min_uV		= 900000,
		.max_uV		= 1705000,
		.always_on	= 1,
		.valid_ops_mask	= REGULATOR_CHANGE_VOLTAGE,
	},
	.consumer_supplies	= vpac270_max1587a_consumers,
	.num_consumer_supplies	= ARRAY_SIZE(vpac270_max1587a_consumers),
};

static struct max1586_subdev_data vpac270_max1587a_subdevs[] = {
	{
		.name		= "vcc_core",
		.id		= MAX1586_V3,
		.platform_data	= &vpac270_max1587a_v3_info,
	}
};

static struct max1586_platform_data vpac270_max1587a_info = {
	.subdevs     = vpac270_max1587a_subdevs,
	.num_subdevs = ARRAY_SIZE(vpac270_max1587a_subdevs),
	.v3_gain     = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
};

static struct i2c_board_info __initdata vpac270_pi2c_board_info[] = {
	{
		I2C_BOARD_INFO("max1586", 0x14),
		.platform_data	= &vpac270_max1587a_info,
	},
};

static void __init vpac270_pmic_init(void)
{
	i2c_register_board_info(1, ARRAY_AND_SIZE(vpac270_pi2c_board_info));
}
#else
static inline void vpac270_pmic_init(void) {}
#endif

/******************************************************************************
 * Machine init
 ******************************************************************************/
static void __init vpac270_init(void)
{
	pxa2xx_mfp_config(ARRAY_AND_SIZE(vpac270_pin_config));

	pxa_set_ffuart_info(NULL);
	pxa_set_btuart_info(NULL);
	pxa_set_stuart_info(NULL);
	pxa_set_i2c_info(NULL);
	pxa27x_set_i2c_power_info(NULL);

	vpac270_pmic_init();
	vpac270_lcd_init();
	vpac270_mmc_init();
	vpac270_nor_init();
	vpac270_onenand_init();
	vpac270_leds_init();
	vpac270_keys_init();
	vpac270_uhc_init();
	vpac270_udc_init();
	vpac270_eth_init();
	vpac270_ts_init();
	vpac270_rtc_init();
	vpac270_ide_init();

	regulator_has_full_constraints();
}

MACHINE_START(VPAC270, "Voipac PXA270")
	.atag_offset	= 0x100,
	.map_io		= pxa27x_map_io,
	.nr_irqs	= PXA_NR_IRQS,
	.init_irq	= pxa27x_init_irq,
	.handle_irq	= pxa27x_handle_irq,
	.init_time	= pxa_timer_init,
	.init_machine	= vpac270_init,
	.restart	= pxa_restart,
MACHINE_END


code:
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * GPIOs and interrupts for Voipac PXA270
 *
 * Copyright (C) 2010
 * Marek Vasut <marek.vasut@gmail.com>
 */

#ifndef _INCLUDE_VPAC270_H_
#define _INCLUDE_VPAC270_H_

#define	GPIO1_VPAC270_USER_BTN		1

#define	GPIO15_VPAC270_LED_ORANGE	15

#define	GPIO81_VPAC270_BKL_ON		81
#define	GPIO83_VPAC270_NL_ON		83

#define	GPIO52_VPAC270_SD_READONLY	52
#define	GPIO53_VPAC270_SD_DETECT_N	53

#define	GPIO84_VPAC270_PCMCIA_CD	84
#define	GPIO35_VPAC270_PCMCIA_RDY	35
#define	GPIO107_VPAC270_PCMCIA_PPEN	107
#define	GPIO11_VPAC270_PCMCIA_RESET	11
#define	GPIO17_VPAC270_CF_CD		17
#define	GPIO12_VPAC270_CF_RDY		12
#define	GPIO16_VPAC270_CF_RESET		16

#define	GPIO41_VPAC270_UDC_DETECT	41

#define	GPIO114_VPAC270_ETH_IRQ		114

#define	GPIO36_VPAC270_IDE_IRQ		36

#define	GPIO113_VPAC270_TS_IRQ		113

#endif


code:
// SPDX-License-Identifier: GPL-2.0-only
/*  linux/arch/arm/mach-pxa/xcep.c
 *
 *  Support for the Iskratel Electronics XCEP platform as used in
 *  the Libera instruments from Instrumentation Technologies.
 *
 *  Author:     Ales Bardorfer <ales@i-tech.si>
 *  Contributions by: Abbott, MG (Michael) <michael.abbott@diamond.ac.uk>
 *  Contributions by: Matej Kenda <matej.kenda@i-tech.si>
 *  Created:    June 2006
 *  Copyright:  (C) 2006-2009 Instrumentation Technologies
 */

#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/platform_data/i2c-pxa.h>
#include <linux/smc91x.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>

#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/irq.h>
#include <asm/mach/map.h>

#include "pxa25x.h"
#include "addr-map.h"
#include "smemc.h"

#include "generic.h"
#include "devices.h"

#define XCEP_ETH_PHYS		(PXA_CS3_PHYS + 0x00000300)
#define XCEP_ETH_PHYS_END	(PXA_CS3_PHYS + 0x000fffff)
#define XCEP_ETH_ATTR		(PXA_CS3_PHYS + 0x02000000)
#define XCEP_ETH_ATTR_END	(PXA_CS3_PHYS + 0x020fffff)
#define XCEP_ETH_IRQ		IRQ_GPIO0

/*  XCEP CPLD base */
#define XCEP_CPLD_BASE		0xf0000000

/* Flash partitions. */

static struct mtd_partition xcep_partitions[] = {
	{
		.name =		"Bootloader",
		.size =		0x00040000,
		.offset =	0,
		.mask_flags =	MTD_WRITEABLE
	}, {
		.name =		"Bootloader ENV",
		.size =		0x00040000,
		.offset =	0x00040000,
		.mask_flags =	MTD_WRITEABLE
	}, {
		.name =		"Kernel",
		.size =		0x00100000,
		.offset =	0x00080000,
	}, {
		.name =		"Rescue fs",
		.size =		0x00280000,
		.offset =	0x00180000,
	}, {
		.name =		"Filesystem",
		.size =		MTDPART_SIZ_FULL,
		.offset =	0x00400000
	}
};

static struct physmap_flash_data xcep_flash_data[] = {
	{
		.width		= 4,		/* bankwidth in bytes */
		.parts		= xcep_partitions,
		.nr_parts	= ARRAY_SIZE(xcep_partitions)
	}
};

static struct resource flash_resource = {
	.start	= PXA_CS0_PHYS,
	.end	= PXA_CS0_PHYS + SZ_32M - 1,
	.flags	= IORESOURCE_MEM,
};

static struct platform_device flash_device = {
	.name	= "physmap-flash",
	.id	= 0,
	.dev 	= {
		.platform_data = xcep_flash_data,
	},
	.resource = &flash_resource,
	.num_resources = 1,
};

/* SMC LAN91C111 network controller. */

static struct resource smc91x_resources[] = {
	[0] = {
		.name	= "smc91x-regs",
		.start	= XCEP_ETH_PHYS,
		.end	= XCEP_ETH_PHYS_END,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start	= XCEP_ETH_IRQ,
		.end	= XCEP_ETH_IRQ,
		.flags	= IORESOURCE_IRQ,
	},
	[2] = {
		.name	= "smc91x-attrib",
		.start	= XCEP_ETH_ATTR,
		.end	= XCEP_ETH_ATTR_END,
		.flags	= IORESOURCE_MEM,
	},
};

static struct smc91x_platdata xcep_smc91x_info = {
	.flags	= SMC91X_USE_8BIT | SMC91X_USE_16BIT | SMC91X_USE_32BIT |
		  SMC91X_NOWAIT | SMC91X_USE_DMA,
};

static struct platform_device smc91x_device = {
	.name		= "smc91x",
	.id		= -1,
	.num_resources	= ARRAY_SIZE(smc91x_resources),
	.resource	= smc91x_resources,
	.dev		= {
		.platform_data = &xcep_smc91x_info,
	},
};

static struct platform_device *devices[] __initdata = {
	&flash_device,
	&smc91x_device,
};

/* We have to state that there are HWMON devices on the I2C bus on XCEP.
 * Drivers for HWMON verify capabilities of the adapter when loading and
 * refuse to attach if the adapter doesn't support HWMON class of devices. */
static struct i2c_pxa_platform_data xcep_i2c_platform_data  = {
	.class = I2C_CLASS_HWMON
};

static mfp_cfg_t xcep_pin_config[] __initdata = {
	GPIO79_nCS_3,	/* SMC 91C111 chip select. */
	GPIO80_nCS_4,	/* CPLD chip select. */
	/* SSP communication to MSP430 */
	GPIO23_SSP1_SCLK,
	GPIO24_SSP1_SFRM,
	GPIO25_SSP1_TXD,
	GPIO26_SSP1_RXD,
	GPIO27_SSP1_EXTCLK
};

static void __init xcep_init(void)
{
	pxa2xx_mfp_config(ARRAY_AND_SIZE(xcep_pin_config));

	pxa_set_ffuart_info(NULL);
	pxa_set_btuart_info(NULL);
	pxa_set_stuart_info(NULL);
	pxa_set_hwuart_info(NULL);

	/* See Intel XScale Developer's Guide for details */
	/* Set RDF and RDN to appropriate values (chip select 3 (smc91x)) */
	__raw_writel((__raw_readl(MSC1) & 0xffff) | 0xD5540000, MSC1);
	/* Set RDF and RDN to appropriate values (chip select 5 (fpga)) */
	__raw_writel((__raw_readl(MSC2) & 0xffff) | 0x72A00000, MSC2);

	platform_add_devices(ARRAY_AND_SIZE(devices));
	pxa_set_i2c_info(&xcep_i2c_platform_data);
}

MACHINE_START(XCEP, "Iskratel XCEP")
	.atag_offset	= 0x100,
	.init_machine	= xcep_init,
	.map_io		= pxa25x_map_io,
	.nr_irqs	= PXA_NR_IRQS,
	.init_irq	= pxa25x_init_irq,
	.handle_irq	= pxa25x_handle_irq,
	.init_time	= pxa_timer_init,
	.restart	= pxa_restart,
MACHINE_END


code:
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  linux/arch/arm/mach-pxa/z2.c
 *
 *  Support for the Zipit Z2 Handheld device.
 *
 *  Copyright (C) 2009-2010 Marek Vasut <marek.vasut@gmail.com>
 *
 *  Based on research and code by: Ken McGuire
 *  Based on mainstone.c as modified for the Zipit Z2.
 */

#include <linux/platform_device.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/pwm.h>
#include <linux/pwm_backlight.h>
#include <linux/z2_battery.h>
#include <linux/dma-mapping.h>
#include <linux/spi/spi.h>
#include <linux/spi/pxa2xx_spi.h>
#include <linux/spi/libertas_spi.h>
#include <linux/power_supply.h>
#include <linux/mtd/physmap.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/gpio_keys.h>
#include <linux/delay.h>
#include <linux/regulator/machine.h>
#include <linux/platform_data/i2c-pxa.h>

#include <asm/mach-types.h>
#include <asm/mach/arch.h>

#include "pxa27x.h"
#include "mfp-pxa27x.h"
#include "z2.h"
#include <linux/platform_data/video-pxafb.h>
#include <linux/platform_data/mmc-pxamci.h>
#include <linux/platform_data/keypad-pxa27x.h>
#include "pm.h"

#include "generic.h"
#include "devices.h"

/******************************************************************************
 * Pin configuration
 ******************************************************************************/
static unsigned long z2_pin_config[] = {

	/* LCD - 16bpp Active TFT */
	GPIO58_LCD_LDD_0,
	GPIO59_LCD_LDD_1,
	GPIO60_LCD_LDD_2,
	GPIO61_LCD_LDD_3,
	GPIO62_LCD_LDD_4,
	GPIO63_LCD_LDD_5,
	GPIO64_LCD_LDD_6,
	GPIO65_LCD_LDD_7,
	GPIO66_LCD_LDD_8,
	GPIO67_LCD_LDD_9,
	GPIO68_LCD_LDD_10,
	GPIO69_LCD_LDD_11,
	GPIO70_LCD_LDD_12,
	GPIO71_LCD_LDD_13,
	GPIO72_LCD_LDD_14,
	GPIO73_LCD_LDD_15,
	GPIO74_LCD_FCLK,
	GPIO75_LCD_LCLK,
	GPIO76_LCD_PCLK,
	GPIO77_LCD_BIAS,
	GPIO19_GPIO,		/* LCD reset */
	GPIO88_GPIO,		/* LCD chipselect */

	/* PWM */
	GPIO115_PWM1_OUT,	/* Keypad Backlight */
	GPIO11_PWM2_OUT,	/* LCD Backlight */

	/* MMC */
	GPIO32_MMC_CLK,
	GPIO112_MMC_CMD,
	GPIO92_MMC_DAT_0,
	GPIO109_MMC_DAT_1,
	GPIO110_MMC_DAT_2,
	GPIO111_MMC_DAT_3,
	GPIO96_GPIO,		/* SD detect */

	/* STUART */
	GPIO46_STUART_RXD,
	GPIO47_STUART_TXD,

	/* Keypad */
	GPIO100_KP_MKIN_0,
	GPIO101_KP_MKIN_1,
	GPIO102_KP_MKIN_2,
	GPIO34_KP_MKIN_3,
	GPIO38_KP_MKIN_4,
	GPIO16_KP_MKIN_5,
	GPIO17_KP_MKIN_6,
	GPIO103_KP_MKOUT_0,
	GPIO104_KP_MKOUT_1,
	GPIO105_KP_MKOUT_2,
	GPIO106_KP_MKOUT_3,
	GPIO107_KP_MKOUT_4,
	GPIO108_KP_MKOUT_5,
	GPIO35_KP_MKOUT_6,
	GPIO41_KP_MKOUT_7,

	/* I2C */
	GPIO117_I2C_SCL,
	GPIO118_I2C_SDA,

	/* SSP1 */
	GPIO23_SSP1_SCLK,	/* SSP1_SCK */
	GPIO25_SSP1_TXD,	/* SSP1_TXD */
	GPIO26_SSP1_RXD,	/* SSP1_RXD */

	/* SSP2 */
	GPIO22_SSP2_SCLK,	/* SSP2_SCK */
	GPIO13_SSP2_TXD,	/* SSP2_TXD */
	GPIO40_SSP2_RXD,	/* SSP2_RXD */

	/* LEDs */
	GPIO10_GPIO,		/* WiFi LED */
	GPIO83_GPIO,		/* Charging LED */
	GPIO85_GPIO,		/* Charged LED */

	/* I2S */
	GPIO28_I2S_BITCLK_OUT,
	GPIO29_I2S_SDATA_IN,
	GPIO30_I2S_SDATA_OUT,
	GPIO31_I2S_SYNC,
	GPIO113_I2S_SYSCLK,

	/* MISC */
	GPIO0_GPIO,		/* AC power detect */
	GPIO1_GPIO,		/* Power button */
	GPIO37_GPIO,		/* Headphone detect */
	GPIO98_GPIO,		/* Lid switch */
	GPIO14_GPIO,		/* WiFi Power */
	GPIO24_GPIO,		/* WiFi CS */
	GPIO36_GPIO,		/* WiFi IRQ */
	GPIO88_GPIO,		/* LCD CS */
};

/******************************************************************************
 * NOR Flash
 ******************************************************************************/
#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
static struct resource z2_flash_resource = {
	.start	= PXA_CS0_PHYS,
	.end	= PXA_CS0_PHYS + SZ_8M - 1,
	.flags	= IORESOURCE_MEM,
};

static struct mtd_partition z2_flash_parts[] = {
	{
		.name	= "U-Boot Bootloader",
		.offset	= 0x0,
		.size	= 0x40000,
	}, {
		.name	= "U-Boot Environment",
		.offset	= 0x40000,
		.size	= 0x20000,
	}, {
		.name	= "Flash",
		.offset	= 0x60000,
		.size	= MTDPART_SIZ_FULL,
	},
};

static struct physmap_flash_data z2_flash_data = {
	.width		= 2,
	.parts		= z2_flash_parts,
	.nr_parts	= ARRAY_SIZE(z2_flash_parts),
};

static struct platform_device z2_flash = {
	.name		= "physmap-flash",
	.id		= -1,
	.resource	= &z2_flash_resource,
	.num_resources	= 1,
	.dev = {
		.platform_data	= &z2_flash_data,
	},
};

static void __init z2_nor_init(void)
{
	platform_device_register(&z2_flash);
}
#else
static inline void z2_nor_init(void) {}
#endif

/******************************************************************************
 * Backlight
 ******************************************************************************/
#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
static struct pwm_lookup z2_pwm_lookup[] = {
	PWM_LOOKUP("pxa27x-pwm.1", 0, "pwm-backlight.0", NULL, 1260320,
		   PWM_POLARITY_NORMAL),
	PWM_LOOKUP("pxa27x-pwm.0", 1, "pwm-backlight.1", NULL, 1260320,
		   PWM_POLARITY_NORMAL),
};

static struct platform_pwm_backlight_data z2_backlight_data[] = {
	[0] = {
		/* Keypad Backlight */
		.max_brightness	= 1023,
		.dft_brightness	= 0,
	},
	[1] = {
		/* LCD Backlight */
		.max_brightness	= 1023,
		.dft_brightness	= 512,
	},
};

static struct platform_device z2_backlight_devices[2] = {
	{
		.name	= "pwm-backlight",
		.id	= 0,
		.dev	= {
			.platform_data	= &z2_backlight_data[1],
		},
	},
	{
		.name	= "pwm-backlight",
		.id	= 1,
		.dev	= {
			.platform_data	= &z2_backlight_data[0],
		},
	},
};
static void __init z2_pwm_init(void)
{
	pwm_add_table(z2_pwm_lookup, ARRAY_SIZE(z2_pwm_lookup));
	platform_device_register(&z2_backlight_devices[0]);
	platform_device_register(&z2_backlight_devices[1]);
}
#else
static inline void z2_pwm_init(void) {}
#endif

/******************************************************************************
 * Framebuffer
 ******************************************************************************/
#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
static struct pxafb_mode_info z2_lcd_modes[] = {
{
	.pixclock	= 192000,
	.xres		= 240,
	.yres		= 320,
	.bpp		= 16,

	.left_margin	= 4,
	.right_margin	= 8,
	.upper_margin	= 4,
	.lower_margin	= 8,

	.hsync_len	= 4,
	.vsync_len	= 4,
},
};

static struct pxafb_mach_info z2_lcd_screen = {
	.modes		= z2_lcd_modes,
	.num_modes      = ARRAY_SIZE(z2_lcd_modes),
	.lcd_conn	= LCD_COLOR_TFT_16BPP | LCD_BIAS_ACTIVE_LOW |
			  LCD_ALTERNATE_MAPPING,
};

static void __init z2_lcd_init(void)
{
	pxa_set_fb_info(NULL, &z2_lcd_screen);
}
#else
static inline void z2_lcd_init(void) {}
#endif

/******************************************************************************
 * SD/MMC card controller
 ******************************************************************************/
#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
static struct pxamci_platform_data z2_mci_platform_data = {
	.ocr_mask		= MMC_VDD_32_33 | MMC_VDD_33_34,
	.detect_delay_ms	= 200,
};

static struct gpiod_lookup_table z2_mci_gpio_table = {
	.dev_id = "pxa2xx-mci.0",
	.table = {
		GPIO_LOOKUP("gpio-pxa", GPIO96_ZIPITZ2_SD_DETECT,
			    "cd", GPIO_ACTIVE_LOW),
		{ },
	},
};

static void __init z2_mmc_init(void)
{
	gpiod_add_lookup_table(&z2_mci_gpio_table);
	pxa_set_mci_info(&z2_mci_platform_data);
}
#else
static inline void z2_mmc_init(void) {}
#endif

/******************************************************************************
 * LEDs
 ******************************************************************************/
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
struct gpio_led z2_gpio_leds[] = {
{
	.name			= "z2:green:wifi",
	.default_trigger	= "none",
	.gpio			= GPIO10_ZIPITZ2_LED_WIFI,
	.active_low		= 1,
}, {
	.name			= "z2:green:charged",
	.default_trigger	= "mmc0",
	.gpio			= GPIO85_ZIPITZ2_LED_CHARGED,
	.active_low		= 1,
}, {
	.name			= "z2:amber:charging",
	.default_trigger	= "Z2-charging-or-full",
	.gpio			= GPIO83_ZIPITZ2_LED_CHARGING,
	.active_low		= 1,
},
};

static struct gpio_led_platform_data z2_gpio_led_info = {
	.leds		= z2_gpio_leds,
	.num_leds	= ARRAY_SIZE(z2_gpio_leds),
};

static struct platform_device z2_leds = {
	.name	= "leds-gpio",
	.id	= -1,
	.dev	= {
		.platform_data	= &z2_gpio_led_info,
	}
};

static void __init z2_leds_init(void)
{
	platform_device_register(&z2_leds);
}
#else
static inline void z2_leds_init(void) {}
#endif

/******************************************************************************
 * GPIO keyboard
 ******************************************************************************/
#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
static const unsigned int z2_matrix_keys[] = {
	KEY(0, 0, KEY_OPTION),
	KEY(1, 0, KEY_UP),
	KEY(2, 0, KEY_DOWN),
	KEY(3, 0, KEY_LEFT),
	KEY(4, 0, KEY_RIGHT),
	KEY(5, 0, KEY_END),
	KEY(6, 0, KEY_KPPLUS),

	KEY(0, 1, KEY_HOME),
	KEY(1, 1, KEY_Q),
	KEY(2, 1, KEY_I),
	KEY(3, 1, KEY_G),
	KEY(4, 1, KEY_X),
	KEY(5, 1, KEY_ENTER),
	KEY(6, 1, KEY_KPMINUS),

	KEY(0, 2, KEY_PAGEUP),
	KEY(1, 2, KEY_W),
	KEY(2, 2, KEY_O),
	KEY(3, 2, KEY_H),
	KEY(4, 2, KEY_C),
	KEY(5, 2, KEY_LEFTALT),

	KEY(0, 3, KEY_PAGEDOWN),
	KEY(1, 3, KEY_E),
	KEY(2, 3, KEY_P),
	KEY(3, 3, KEY_J),
	KEY(4, 3, KEY_V),
	KEY(5, 3, KEY_LEFTSHIFT),

	KEY(0, 4, KEY_ESC),
	KEY(1, 4, KEY_R),
	KEY(2, 4, KEY_A),
	KEY(3, 4, KEY_K),
	KEY(4, 4, KEY_B),
	KEY(5, 4, KEY_LEFTCTRL),

	KEY(0, 5, KEY_TAB),
	KEY(1, 5, KEY_T),
	KEY(2, 5, KEY_S),
	KEY(3, 5, KEY_L),
	KEY(4, 5, KEY_N),
	KEY(5, 5, KEY_SPACE),

	KEY(0, 6, KEY_STOPCD),
	KEY(1, 6, KEY_Y),
	KEY(2, 6, KEY_D),
	KEY(3, 6, KEY_BACKSPACE),
	KEY(4, 6, KEY_M),
	KEY(5, 6, KEY_COMMA),

	KEY(0, 7, KEY_PLAYCD),
	KEY(1, 7, KEY_U),
	KEY(2, 7, KEY_F),
	KEY(3, 7, KEY_Z),
	KEY(4, 7, KEY_SEMICOLON),
	KEY(5, 7, KEY_DOT),
};

static struct matrix_keymap_data z2_matrix_keymap_data = {
	.keymap			= z2_matrix_keys,
	.keymap_size		= ARRAY_SIZE(z2_matrix_keys),
};

static struct pxa27x_keypad_platform_data z2_keypad_platform_data = {
	.matrix_key_rows	= 7,
	.matrix_key_cols	= 8,
	.matrix_keymap_data	= &z2_matrix_keymap_data,

	.debounce_interval	= 30,
};

static void __init z2_mkp_init(void)
{
	pxa_set_keypad_info(&z2_keypad_platform_data);
}
#else
static inline void z2_mkp_init(void) {}
#endif

/******************************************************************************
 * GPIO keys
 ******************************************************************************/
#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
static struct gpio_keys_button z2_pxa_buttons[] = {
	{
		.code		= KEY_POWER,
		.gpio		= GPIO1_ZIPITZ2_POWER_BUTTON,
		.active_low	= 0,
		.desc		= "Power Button",
		.wakeup		= 1,
		.type		= EV_KEY,
	},
	{
		.code		= SW_LID,
		.gpio		= GPIO98_ZIPITZ2_LID_BUTTON,
		.active_low	= 1,
		.desc		= "Lid Switch",
		.wakeup		= 0,
		.type		= EV_SW,
	},
};

static struct gpio_keys_platform_data z2_pxa_keys_data = {
	.buttons	= z2_pxa_buttons,
	.nbuttons	= ARRAY_SIZE(z2_pxa_buttons),
};

static struct platform_device z2_pxa_keys = {
	.name	= "gpio-keys",
	.id	= -1,
	.dev	= {
		.platform_data = &z2_pxa_keys_data,
	},
};

static void __init z2_keys_init(void)
{
	platform_device_register(&z2_pxa_keys);
}
#else
static inline void z2_keys_init(void) {}
#endif

/******************************************************************************
 * Battery
 ******************************************************************************/
#if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
static struct z2_battery_info batt_chip_info = {
	.batt_I2C_bus	= 0,
	.batt_I2C_addr	= 0x55,
	.batt_I2C_reg	= 2,
	.min_voltage	= 3475000,
	.max_voltage	= 4190000,
	.batt_div	= 59,
	.batt_mult	= 1000000,
	.batt_tech	= POWER_SUPPLY_TECHNOLOGY_LION,
	.batt_name	= "Z2",
};

static struct gpiod_lookup_table z2_battery_gpio_table = {
	.dev_id = "aer915",
	.table = {
		GPIO_LOOKUP("gpio-pxa", GPIO0_ZIPITZ2_AC_DETECT,
			    NULL, GPIO_ACTIVE_HIGH),
		{ },
	},
};

static struct i2c_board_info __initdata z2_i2c_board_info[] = {
	{
		I2C_BOARD_INFO("aer915", 0x55),
		.dev_name = "aer915",
		.platform_data	= &batt_chip_info,
	}, {
		I2C_BOARD_INFO("wm8750", 0x1b),
	},

};

static void __init z2_i2c_init(void)
{
	pxa_set_i2c_info(NULL);
	gpiod_add_lookup_table(&z2_battery_gpio_table);
	i2c_register_board_info(0, ARRAY_AND_SIZE(z2_i2c_board_info));
}
#else
static inline void z2_i2c_init(void) {}
#endif

/******************************************************************************
 * SSP Devices - WiFi and LCD control
 ******************************************************************************/
#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
/* WiFi */
static int z2_lbs_spi_setup(struct spi_device *spi)
{
	int ret = 0;

	ret = gpio_request(GPIO14_ZIPITZ2_WIFI_POWER, "WiFi Power");
	if (ret)
		goto err;

	ret = gpio_direction_output(GPIO14_ZIPITZ2_WIFI_POWER, 1);
	if (ret)
		goto err2;

	/* Wait until card is powered on */
	mdelay(180);

	spi->bits_per_word = 16;
	spi->mode = SPI_MODE_2,

	spi_setup(spi);

	return 0;

err2:
	gpio_free(GPIO14_ZIPITZ2_WIFI_POWER);
err:
	return ret;
};

static int z2_lbs_spi_teardown(struct spi_device *spi)
{
	gpio_set_value(GPIO14_ZIPITZ2_WIFI_POWER, 0);
	gpio_free(GPIO14_ZIPITZ2_WIFI_POWER);

	return 0;
};

static struct pxa2xx_spi_chip z2_lbs_chip_info = {
	.rx_threshold	= 8,
	.tx_threshold	= 8,
	.timeout	= 1000,
};

static struct libertas_spi_platform_data z2_lbs_pdata = {
	.use_dummy_writes	= 1,
	.setup			= z2_lbs_spi_setup,
	.teardown		= z2_lbs_spi_teardown,
};

/* LCD */
static struct pxa2xx_spi_chip lms283_chip_info = {
	.rx_threshold	= 1,
	.tx_threshold	= 1,
	.timeout	= 64,
};

static struct gpiod_lookup_table lms283_gpio_table = {
	.dev_id = "spi2.0", /* SPI bus 2 chip select 0 */
	.table = {
		GPIO_LOOKUP("gpio-pxa", GPIO19_ZIPITZ2_LCD_RESET,
			    "reset", GPIO_ACTIVE_LOW),
		{ },
	},
};

static struct spi_board_info spi_board_info[] __initdata = {
{
	.modalias		= "libertas_spi",
	.platform_data		= &z2_lbs_pdata,
	.controller_data	= &z2_lbs_chip_info,
	.irq			= PXA_GPIO_TO_IRQ(GPIO36_ZIPITZ2_WIFI_IRQ),
	.max_speed_hz		= 13000000,
	.bus_num		= 1,
	.chip_select		= 0,
},
{
	.modalias		= "lms283gf05",
	.controller_data	= &lms283_chip_info,
	.max_speed_hz		= 400000,
	.bus_num		= 2,
	.chip_select		= 0,
},
};

static struct pxa2xx_spi_controller pxa_ssp1_master_info = {
	.num_chipselect	= 1,
	.enable_dma	= 1,
};

static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
	.num_chipselect	= 1,
};

static struct gpiod_lookup_table pxa_ssp1_gpio_table = {
	.dev_id = "spi1",
	.table = {
		GPIO_LOOKUP_IDX("gpio-pxa", GPIO24_ZIPITZ2_WIFI_CS, "cs", 0, GPIO_ACTIVE_LOW),
		{ },
	},
};

static struct gpiod_lookup_table pxa_ssp2_gpio_table = {
	.dev_id = "spi2",
	.table = {
		GPIO_LOOKUP_IDX("gpio-pxa", GPIO88_ZIPITZ2_LCD_CS, "cs", 0, GPIO_ACTIVE_LOW),
		{ },
	},
};

static void __init z2_spi_init(void)
{
	gpiod_add_lookup_table(&pxa_ssp1_gpio_table);
	gpiod_add_lookup_table(&pxa_ssp2_gpio_table);
	pxa2xx_set_spi_info(1, &pxa_ssp1_master_info);
	pxa2xx_set_spi_info(2, &pxa_ssp2_master_info);
	gpiod_add_lookup_table(&lms283_gpio_table);
	spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
}
#else
static inline void z2_spi_init(void) {}
#endif

static struct gpiod_lookup_table z2_audio_gpio_table = {
	.dev_id = "soc-audio",
	.table = {
		GPIO_LOOKUP("gpio-pxa", GPIO37_ZIPITZ2_HEADSET_DETECT,
			    "hsdet-gpio", GPIO_ACTIVE_HIGH),
		{ },
	},
};

/******************************************************************************
 * Core power regulator
 ******************************************************************************/
#if defined(CONFIG_REGULATOR_TPS65023) || \
	defined(CONFIG_REGULATOR_TPS65023_MODULE)
static struct regulator_consumer_supply z2_tps65021_consumers[] = {
	REGULATOR_SUPPLY("vcc_core", NULL),
};

static struct regulator_init_data z2_tps65021_info[] = {
	{
		.constraints = {
			.name		= "vcc_core range",
			.min_uV		= 800000,
			.max_uV		= 1600000,
			.always_on	= 1,
			.valid_ops_mask	= REGULATOR_CHANGE_VOLTAGE,
		},
		.consumer_supplies	= z2_tps65021_consumers,
		.num_consumer_supplies	= ARRAY_SIZE(z2_tps65021_consumers),
	}, {
		.constraints = {
			.name		= "DCDC2",
			.min_uV		= 3300000,
			.max_uV		= 3300000,
			.always_on	= 1,
		},
	}, {
		.constraints = {
			.name		= "DCDC3",
			.min_uV		= 1800000,
			.max_uV		= 1800000,
			.always_on	= 1,
		},
	}, {
		.constraints = {
			.name		= "LDO1",
			.min_uV		= 1000000,
			.max_uV		= 3150000,
			.always_on	= 1,
		},
	}, {
		.constraints = {
			.name		= "LDO2",
			.min_uV		= 1050000,
			.max_uV		= 3300000,
			.always_on	= 1,
		},
	}
};

static struct i2c_board_info __initdata z2_pi2c_board_info[] = {
	{
		I2C_BOARD_INFO("tps65021", 0x48),
		.platform_data	= &z2_tps65021_info,
	},
};

static void __init z2_pmic_init(void)
{
	pxa27x_set_i2c_power_info(NULL);
	i2c_register_board_info(1, ARRAY_AND_SIZE(z2_pi2c_board_info));
}
#else
static inline void z2_pmic_init(void) {}
#endif

#ifdef CONFIG_PM
static void z2_power_off(void)
{
	/* We're using deep sleep as poweroff, so clear PSPR to ensure that
	 * bootloader will jump to its entry point in resume handler
	 */
	PSPR = 0x0;
	local_irq_disable();
	pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
	pxa27x_cpu_pm_enter(PM_SUSPEND_MEM);
}
#else
#define z2_power_off   NULL
#endif

/******************************************************************************
 * Machine init
 ******************************************************************************/
static void __init z2_init(void)
{
	pxa2xx_mfp_config(ARRAY_AND_SIZE(z2_pin_config));

	pxa_set_ffuart_info(NULL);
	pxa_set_btuart_info(NULL);
	pxa_set_stuart_info(NULL);

	z2_lcd_init();
	z2_mmc_init();
	z2_mkp_init();
	z2_i2c_init();
	z2_spi_init();
	z2_nor_init();
	z2_pwm_init();
	z2_leds_init();
	z2_keys_init();
	z2_pmic_init();

	gpiod_add_lookup_table(&z2_audio_gpio_table);

	pm_power_off = z2_power_off;
}

MACHINE_START(ZIPIT2, "Zipit Z2")
	.atag_offset	= 0x100,
	.map_io		= pxa27x_map_io,
	.nr_irqs	= PXA_NR_IRQS,
	.init_irq	= pxa27x_init_irq,
	.handle_irq	= pxa27x_handle_irq,
	.init_time	= pxa_timer_init,
	.init_machine	= z2_init,
	.restart	= pxa_restart,
MACHINE_END


code:
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 *  arch/arm/mach-pxa/include/mach/z2.h
 *
 *  Author: Ken McGuire
 *  Created: Feb 6, 2009
 */

#ifndef ASM_ARCH_ZIPIT2_H
#define ASM_ARCH_ZIPIT2_H

/* LEDs */
#define	GPIO10_ZIPITZ2_LED_WIFI		10
#define	GPIO85_ZIPITZ2_LED_CHARGED	85
#define	GPIO83_ZIPITZ2_LED_CHARGING	83

/* SD/MMC */
#define	GPIO96_ZIPITZ2_SD_DETECT	96

/* GPIO Buttons */
#define	GPIO1_ZIPITZ2_POWER_BUTTON	1
#define	GPIO98_ZIPITZ2_LID_BUTTON	98

/* Libertas GSPI8686 WiFi */
#define	GPIO14_ZIPITZ2_WIFI_POWER	14
#define	GPIO24_ZIPITZ2_WIFI_CS		24
#define	GPIO36_ZIPITZ2_WIFI_IRQ		36

/* LCD */
#define	GPIO19_ZIPITZ2_LCD_RESET	19
#define	GPIO88_ZIPITZ2_LCD_CS		88

/* MISC GPIOs */
#define	GPIO0_ZIPITZ2_AC_DETECT		0
#define GPIO37_ZIPITZ2_HEADSET_DETECT	37

#endif


code:
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  Support for the Arcom ZEUS.
 *
 *  Copyright (C) 2006 Arcom Control Systems Ltd.
 *
 *  Loosely based on Arcom's 2.6.16.28.
 *  Maintained by Marc Zyngier <maz@misterjones.org>
 */

#include <linux/cpufreq.h>
#include <linux/interrupt.h>
#include <linux/leds.h>
#include <linux/irq.h>
#include <linux/pm.h>
#include <linux/property.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/serial_8250.h>
#include <linux/dm9000.h>
#include <linux/mmc/host.h>
#include <linux/spi/spi.h>
#include <linux/spi/pxa2xx_spi.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
#include <linux/i2c.h>
#include <linux/platform_data/i2c-pxa.h>
#include <linux/platform_data/pca953x.h>
#include <linux/apm-emulation.h>
#include <linux/regulator/fixed.h>
#include <linux/regulator/machine.h>

#include <asm/mach-types.h>
#include <asm/suspend.h>
#include <asm/system_info.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>

#include "pxa27x.h"
#include "devices.h"
#include "regs-uart.h"
#include <linux/platform_data/usb-ohci-pxa27x.h>
#include <linux/platform_data/mmc-pxamci.h>
#include "pxa27x-udc.h"
#include "udc.h"
#include <linux/platform_data/video-pxafb.h>
#include "pm.h"
#include <linux/platform_data/asoc-pxa.h>
#include "viper-pcmcia.h"
#include "zeus.h"
#include "smemc.h"

#include "generic.h"

/*
 * Interrupt handling
 */

static unsigned long zeus_irq_enabled_mask;
static const int zeus_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, };
static const int zeus_isa_irq_map[] = {
	0,		/* ISA irq #0, invalid */
	0,		/* ISA irq #1, invalid */
	0,		/* ISA irq #2, invalid */
	1 << 0,		/* ISA irq #3 */
	1 << 1,		/* ISA irq #4 */
	1 << 2,		/* ISA irq #5 */
	1 << 3,		/* ISA irq #6 */
	1 << 4,		/* ISA irq #7 */
	0,		/* ISA irq #8, invalid */
	0,		/* ISA irq #9, invalid */
	1 << 5,		/* ISA irq #10 */
	1 << 6,		/* ISA irq #11 */
	1 << 7,		/* ISA irq #12 */
};

static inline int zeus_irq_to_bitmask(unsigned int irq)
{
	return zeus_isa_irq_map[irq - PXA_ISA_IRQ(0)];
}

static inline int zeus_bit_to_irq(int bit)
{
	return zeus_isa_irqs[bit] + PXA_ISA_IRQ(0);
}

static void zeus_ack_irq(struct irq_data *d)
{
	__raw_writew(zeus_irq_to_bitmask(d->irq), ZEUS_CPLD_ISA_IRQ);
}

static void zeus_mask_irq(struct irq_data *d)
{
	zeus_irq_enabled_mask &= ~(zeus_irq_to_bitmask(d->irq));
}

static void zeus_unmask_irq(struct irq_data *d)
{
	zeus_irq_enabled_mask |= zeus_irq_to_bitmask(d->irq);
}

static inline unsigned long zeus_irq_pending(void)
{
	return __raw_readw(ZEUS_CPLD_ISA_IRQ) & zeus_irq_enabled_mask;
}

static void zeus_irq_handler(struct irq_desc *desc)
{
	unsigned int irq;
	unsigned long pending;

	pending = zeus_irq_pending();
	do {
		/* we're in a chained irq handler,
		 * so ack the interrupt by hand */
		desc->irq_data.chip->irq_ack(&desc->irq_data);

		if (likely(pending)) {
			irq = zeus_bit_to_irq(__ffs(pending));
			generic_handle_irq(irq);
		}
		pending = zeus_irq_pending();
	} while (pending);
}

static struct irq_chip zeus_irq_chip = {
	.name		= "ISA",
	.irq_ack	= zeus_ack_irq,
	.irq_mask	= zeus_mask_irq,
	.irq_unmask	= zeus_unmask_irq,
};

static void __init zeus_init_irq(void)
{
	int level;
	int isa_irq;

	pxa27x_init_irq();

	/* Peripheral IRQs. It would be nice to move those inside driver
	   configuration, but it is not supported at the moment. */
	irq_set_irq_type(gpio_to_irq(ZEUS_AC97_GPIO), IRQ_TYPE_EDGE_RISING);
	irq_set_irq_type(gpio_to_irq(ZEUS_WAKEUP_GPIO), IRQ_TYPE_EDGE_RISING);
	irq_set_irq_type(gpio_to_irq(ZEUS_PTT_GPIO), IRQ_TYPE_EDGE_RISING);
	irq_set_irq_type(gpio_to_irq(ZEUS_EXTGPIO_GPIO),
			 IRQ_TYPE_EDGE_FALLING);
	irq_set_irq_type(gpio_to_irq(ZEUS_CAN_GPIO), IRQ_TYPE_EDGE_FALLING);

	/* Setup ISA IRQs */
	for (level = 0; level < ARRAY_SIZE(zeus_isa_irqs); level++) {
		isa_irq = zeus_bit_to_irq(level);
		irq_set_chip_and_handler(isa_irq, &zeus_irq_chip,
					 handle_edge_irq);
		irq_clear_status_flags(isa_irq, IRQ_NOREQUEST | IRQ_NOPROBE);
	}

	irq_set_irq_type(gpio_to_irq(ZEUS_ISA_GPIO), IRQ_TYPE_EDGE_RISING);
	irq_set_chained_handler(gpio_to_irq(ZEUS_ISA_GPIO), zeus_irq_handler);
}

/*
 * Platform devices
 */

/* Flash */
static struct resource zeus_mtd_resources[] = {
	[0] = { /* NOR Flash (up to 64MB) */
		.start	= ZEUS_FLASH_PHYS,
		.end	= ZEUS_FLASH_PHYS + SZ_64M - 1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = { /* SRAM */
		.start	= ZEUS_SRAM_PHYS,
		.end	= ZEUS_SRAM_PHYS + SZ_512K - 1,
		.flags	= IORESOURCE_MEM,
	},
};

static struct physmap_flash_data zeus_flash_data[] = {
	[0] = {
		.width		= 2,
		.parts		= NULL,
		.nr_parts	= 0,
	},
};

static struct platform_device zeus_mtd_devices[] = {
	[0] = {
		.name		= "physmap-flash",
		.id		= 0,
		.dev		= {
			.platform_data = &zeus_flash_data[0],
		},
		.resource	= &zeus_mtd_resources[0],
		.num_resources	= 1,
	},
};

/* Serial */
static struct resource zeus_serial_resources[] = {
	{
		.start	= 0x10000000,
		.end	= 0x1000000f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x10800000,
		.end	= 0x1080000f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x11000000,
		.end	= 0x1100000f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x40100000,
		.end	= 0x4010001f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x40200000,
		.end	= 0x4020001f,
		.flags	= IORESOURCE_MEM,
	},
	{
		.start	= 0x40700000,
		.end	= 0x4070001f,
		.flags	= IORESOURCE_MEM,
	},
};

static struct plat_serial8250_port serial_platform_data[] = {
	/* External UARTs */
	/* FIXME: Shared IRQs on COM1-COM4 will not work properly on v1i1 hardware. */
	{ /* COM1 */
		.mapbase	= 0x10000000,
		.irq		= PXA_GPIO_TO_IRQ(ZEUS_UARTA_GPIO),
		.irqflags	= IRQF_TRIGGER_RISING,
		.uartclk	= 14745600,
		.regshift	= 1,
		.flags		= UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{ /* COM2 */
		.mapbase	= 0x10800000,
		.irq		= PXA_GPIO_TO_IRQ(ZEUS_UARTB_GPIO),
		.irqflags	= IRQF_TRIGGER_RISING,
		.uartclk	= 14745600,
		.regshift	= 1,
		.flags		= UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{ /* COM3 */
		.mapbase	= 0x11000000,
		.irq		= PXA_GPIO_TO_IRQ(ZEUS_UARTC_GPIO),
		.irqflags	= IRQF_TRIGGER_RISING,
		.uartclk	= 14745600,
		.regshift	= 1,
		.flags		= UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{ /* COM4 */
		.mapbase	= 0x11800000,
		.irq		= PXA_GPIO_TO_IRQ(ZEUS_UARTD_GPIO),
		.irqflags	= IRQF_TRIGGER_RISING,
		.uartclk	= 14745600,
		.regshift	= 1,
		.flags		= UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	/* Internal UARTs */
	{ /* FFUART */
		.membase	= (void *)&FFUART,
		.mapbase	= __PREG(FFUART),
		.irq		= IRQ_FFUART,
		.uartclk	= 921600 * 16,
		.regshift	= 2,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{ /* BTUART */
		.membase	= (void *)&BTUART,
		.mapbase	= __PREG(BTUART),
		.irq		= IRQ_BTUART,
		.uartclk	= 921600 * 16,
		.regshift	= 2,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{ /* STUART */
		.membase	= (void *)&STUART,
		.mapbase	= __PREG(STUART),
		.irq		= IRQ_STUART,
		.uartclk	= 921600 * 16,
		.regshift	= 2,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
		.iotype		= UPIO_MEM,
	},
	{ },
};

static struct platform_device zeus_serial_device = {
	.name = "serial8250",
	.id   = PLAT8250_DEV_PLATFORM,
	.dev  = {
		.platform_data = serial_platform_data,
	},
	.num_resources	= ARRAY_SIZE(zeus_serial_resources),
	.resource	= zeus_serial_resources,
};

/* Ethernet */
static struct resource zeus_dm9k0_resource[] = {
	[0] = {
		.start = ZEUS_ETH0_PHYS,
		.end   = ZEUS_ETH0_PHYS + 1,
		.flags = IORESOURCE_MEM
	},
	[1] = {
		.start = ZEUS_ETH0_PHYS + 2,
		.end   = ZEUS_ETH0_PHYS + 3,
		.flags = IORESOURCE_MEM
	},
	[2] = {
		.start = PXA_GPIO_TO_IRQ(ZEUS_ETH0_GPIO),
		.end   = PXA_GPIO_TO_IRQ(ZEUS_ETH0_GPIO),
		.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
	},
};

static struct resource zeus_dm9k1_resource[] = {
	[0] = {
		.start = ZEUS_ETH1_PHYS,
		.end   = ZEUS_ETH1_PHYS + 1,
		.flags = IORESOURCE_MEM
	},
	[1] = {
		.start = ZEUS_ETH1_PHYS + 2,
		.end   = ZEUS_ETH1_PHYS + 3,
		.flags = IORESOURCE_MEM,
	},
	[2] = {
		.start = PXA_GPIO_TO_IRQ(ZEUS_ETH1_GPIO),
		.end   = PXA_GPIO_TO_IRQ(ZEUS_ETH1_GPIO),
		.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
	},
};

static struct dm9000_plat_data zeus_dm9k_platdata = {
	.flags		= DM9000_PLATF_16BITONLY,
};

static struct platform_device zeus_dm9k0_device = {
	.name		= "dm9000",
	.id		= 0,
	.num_resources	= ARRAY_SIZE(zeus_dm9k0_resource),
	.resource	= zeus_dm9k0_resource,
	.dev		= {
		.platform_data = &zeus_dm9k_platdata,
	}
};

static struct platform_device zeus_dm9k1_device = {
	.name		= "dm9000",
	.id		= 1,
	.num_resources	= ARRAY_SIZE(zeus_dm9k1_resource),
	.resource	= zeus_dm9k1_resource,
	.dev		= {
		.platform_data = &zeus_dm9k_platdata,
	}
};

/* External SRAM */
static struct resource zeus_sram_resource = {
	.start		= ZEUS_SRAM_PHYS,
	.end		= ZEUS_SRAM_PHYS + ZEUS_SRAM_SIZE * 2 - 1,
	.flags		= IORESOURCE_MEM,
};

static struct platform_device zeus_sram_device = {
	.name		= "pxa2xx-8bit-sram",
	.id		= 0,
	.num_resources	= 1,
	.resource	= &zeus_sram_resource,
};

/* SPI interface on SSP3 */
static struct pxa2xx_spi_controller pxa2xx_spi_ssp3_master_info = {
	.num_chipselect = 1,
	.enable_dma     = 1,
};

/* CAN bus on SPI */
static struct regulator_consumer_supply can_regulator_consumer =
	REGULATOR_SUPPLY("vdd", "spi3.0");

static struct regulator_init_data can_regulator_init_data = {
	.constraints	= {
		.valid_ops_mask	= REGULATOR_CHANGE_STATUS,
	},
	.consumer_supplies	= &can_regulator_consumer,
	.num_consumer_supplies	= 1,
};

static struct fixed_voltage_config can_regulator_pdata = {
	.supply_name	= "CAN_SHDN",
	.microvolts	= 3300000,
	.init_data	= &can_regulator_init_data,
};

static struct platform_device can_regulator_device = {
	.name	= "reg-fixed-voltage",
	.id	= 0,
	.dev	= {
		.platform_data	= &can_regulator_pdata,
	},
};

static struct gpiod_lookup_table can_regulator_gpiod_table = {
	.dev_id = "reg-fixed-voltage.0",
	.table = {
		GPIO_LOOKUP("gpio-pxa", ZEUS_CAN_SHDN_GPIO,
			    NULL, GPIO_ACTIVE_LOW),
		{ },
	},
};

static const struct property_entry mcp251x_properties[] = {
	PROPERTY_ENTRY_U32("clock-frequency", 16000000),
	{}
};

static const struct software_node mcp251x_node = {
	.properties = mcp251x_properties,
};

static struct spi_board_info zeus_spi_board_info[] = {
	[0] = {
		.modalias	= "mcp2515",
		.swnode		= &mcp251x_node,
		.irq		= PXA_GPIO_TO_IRQ(ZEUS_CAN_GPIO),
		.max_speed_hz	= 1*1000*1000,
		.bus_num	= 3,
		.mode		= SPI_MODE_0,
		.chip_select	= 0,
	},
};

/* Leds */
static struct gpio_led zeus_leds[] = {
	[0] = {
		.name		 = "zeus:yellow:1",
		.default_trigger = "heartbeat",
		.gpio		 = ZEUS_EXT0_GPIO(3),
		.active_low	 = 1,
	},
	[1] = {
		.name		 = "zeus:yellow:2",
		.default_trigger = "default-on",
		.gpio		 = ZEUS_EXT0_GPIO(4),
		.active_low	 = 1,
	},
	[2] = {
		.name		 = "zeus:yellow:3",
		.default_trigger = "default-on",
		.gpio		 = ZEUS_EXT0_GPIO(5),
		.active_low	 = 1,
	},
};

static struct gpio_led_platform_data zeus_leds_info = {
	.leds		= zeus_leds,
	.num_leds	= ARRAY_SIZE(zeus_leds),
};

static struct platform_device zeus_leds_device = {
	.name		= "leds-gpio",
	.id		= -1,
	.dev		= {
		.platform_data	= &zeus_leds_info,
	},
};

static void zeus_cf_reset(int state)
{
	u16 cpld_state = __raw_readw(ZEUS_CPLD_CONTROL);

	if (state)
		cpld_state |= ZEUS_CPLD_CONTROL_CF_RST;
	else
		cpld_state &= ~ZEUS_CPLD_CONTROL_CF_RST;

	__raw_writew(cpld_state, ZEUS_CPLD_CONTROL);
}

static struct arcom_pcmcia_pdata zeus_pcmcia_info = {
	.cd_gpio	= ZEUS_CF_CD_GPIO,
	.rdy_gpio	= ZEUS_CF_RDY_GPIO,
	.pwr_gpio	= ZEUS_CF_PWEN_GPIO,
	.reset		= zeus_cf_reset,
};

static struct platform_device zeus_pcmcia_device = {
	.name		= "zeus-pcmcia",
	.id		= -1,
	.dev		= {
		.platform_data	= &zeus_pcmcia_info,
	},
};

static struct resource zeus_max6369_resource = {
	.start		= ZEUS_CPLD_EXTWDOG_PHYS,
	.end		= ZEUS_CPLD_EXTWDOG_PHYS,
	.flags		= IORESOURCE_MEM,
};

struct platform_device zeus_max6369_device = {
	.name		= "max6369_wdt",
	.id		= -1,
	.resource	= &zeus_max6369_resource,
	.num_resources	= 1,
};

/* AC'97 */
static pxa2xx_audio_ops_t zeus_ac97_info = {
	.reset_gpio = 95,
};

/*
 * USB host
 */

static struct regulator_consumer_supply zeus_ohci_regulator_supplies[] = {
	REGULATOR_SUPPLY("vbus2", "pxa27x-ohci"),
};

static struct regulator_init_data zeus_ohci_regulator_data = {
	.constraints = {
		.valid_ops_mask		= REGULATOR_CHANGE_STATUS,
	},
	.num_consumer_supplies	= ARRAY_SIZE(zeus_ohci_regulator_supplies),
	.consumer_supplies	= zeus_ohci_regulator_supplies,
};

static struct fixed_voltage_config zeus_ohci_regulator_config = {
	.supply_name		= "vbus2",
	.microvolts		= 5000000, /* 5.0V */
	.startup_delay		= 0,
	.init_data		= &zeus_ohci_regulator_data,
};

static struct platform_device zeus_ohci_regulator_device = {
	.name		= "reg-fixed-voltage",
	.id		= 1,
	.dev = {
		.platform_data = &zeus_ohci_regulator_config,
	},
};

static struct gpiod_lookup_table zeus_ohci_regulator_gpiod_table = {
	.dev_id = "reg-fixed-voltage.0",
	.table = {
		GPIO_LOOKUP("gpio-pxa", ZEUS_USB2_PWREN_GPIO,
			    NULL, GPIO_ACTIVE_HIGH),
		{ },
	},
};

static struct pxaohci_platform_data zeus_ohci_platform_data = {
	.port_mode	= PMM_NPS_MODE,
	/* Clear Power Control Polarity Low and set Power Sense
	 * Polarity Low. Supply power to USB ports. */
	.flags		= ENABLE_PORT_ALL | POWER_SENSE_LOW,
};

static void __init zeus_register_ohci(void)
{
	/* Port 2 is shared between host and client interface. */
	UP2OCR = UP2OCR_HXOE | UP2OCR_HXS | UP2OCR_DMPDE | UP2OCR_DPPDE;

	pxa_set_ohci_info(&zeus_ohci_platform_data);
}

/*
 * Flat Panel
 */

static void zeus_lcd_power(int on, struct fb_var_screeninfo *si)
{
	gpio_set_value(ZEUS_LCD_EN_GPIO, on);
}

static void zeus_backlight_power(int on)
{
	gpio_set_value(ZEUS_BKLEN_GPIO, on);
}

static int zeus_setup_fb_gpios(void)
{
	int err;

	if ((err = gpio_request(ZEUS_LCD_EN_GPIO, "LCD_EN")))
		goto out_err;

	if ((err = gpio_direction_output(ZEUS_LCD_EN_GPIO, 0)))
		goto out_err_lcd;

	if ((err = gpio_request(ZEUS_BKLEN_GPIO, "BKLEN")))
		goto out_err_lcd;

	if ((err = gpio_direction_output(ZEUS_BKLEN_GPIO, 0)))
		goto out_err_bkl;

	return 0;

out_err_bkl:
	gpio_free(ZEUS_BKLEN_GPIO);
out_err_lcd:
	gpio_free(ZEUS_LCD_EN_GPIO);
out_err:
	return err;
}

static struct pxafb_mode_info zeus_fb_mode_info[] = {
	{
		.pixclock       = 39722,

		.xres           = 640,
		.yres           = 480,

		.bpp            = 16,

		.hsync_len      = 63,
		.left_margin    = 16,
		.right_margin   = 81,

		.vsync_len      = 2,
		.upper_margin   = 12,
		.lower_margin   = 31,

		.sync		= 0,
	},
};

static struct pxafb_mach_info zeus_fb_info = {
	.modes			= zeus_fb_mode_info,
	.num_modes		= 1,
	.lcd_conn		= LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
	.pxafb_lcd_power	= zeus_lcd_power,
	.pxafb_backlight_power	= zeus_backlight_power,
};

/*
 * MMC/SD Device
 *
 * The card detect interrupt isn't debounced so we delay it by 250ms
 * to give the card a chance to fully insert/eject.
 */

static struct pxamci_platform_data zeus_mci_platform_data = {
	.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34,
	.detect_delay_ms	= 250,
	.gpio_card_ro_invert	= 1,
};

static struct gpiod_lookup_table zeus_mci_gpio_table = {
	.dev_id = "pxa2xx-mci.0",
	.table = {
		GPIO_LOOKUP("gpio-pxa", ZEUS_MMC_CD_GPIO,
			    "cd", GPIO_ACTIVE_LOW),
		GPIO_LOOKUP("gpio-pxa", ZEUS_MMC_WP_GPIO,
			    "wp", GPIO_ACTIVE_HIGH),
		{ },
	},
};

/*
 * USB Device Controller
 */
static void zeus_udc_command(int cmd)
{
	switch (cmd) {
	case PXA2XX_UDC_CMD_DISCONNECT:
		pr_info("zeus: disconnecting USB client\n");
		UP2OCR = UP2OCR_HXOE | UP2OCR_HXS | UP2OCR_DMPDE | UP2OCR_DPPDE;
		break;

	case PXA2XX_UDC_CMD_CONNECT:
		pr_info("zeus: connecting USB client\n");
		UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE;
		break;
	}
}

static struct pxa2xx_udc_mach_info zeus_udc_info = {
	.udc_command = zeus_udc_command,
};

static struct platform_device *zeus_devices[] __initdata = {
	&zeus_serial_device,
	&zeus_mtd_devices[0],
	&zeus_dm9k0_device,
	&zeus_dm9k1_device,
	&zeus_sram_device,
	&zeus_leds_device,
	&zeus_pcmcia_device,
	&zeus_max6369_device,
	&can_regulator_device,
	&zeus_ohci_regulator_device,
};

#ifdef CONFIG_PM
static void zeus_power_off(void)
{
	local_irq_disable();
	cpu_suspend(PWRMODE_DEEPSLEEP, pxa27x_finish_suspend);
}
#else
#define zeus_power_off   NULL
#endif

#ifdef CONFIG_APM_EMULATION
static void zeus_get_power_status(struct apm_power_info *info)
{
	/* Power supply is always present */
	info->ac_line_status	= APM_AC_ONLINE;
	info->battery_status	= APM_BATTERY_STATUS_NOT_PRESENT;
	info->battery_flag	= APM_BATTERY_FLAG_NOT_PRESENT;
}

static inline void zeus_setup_apm(void)
{
	apm_get_power_status = zeus_get_power_status;
}
#else
static inline void zeus_setup_apm(void)
{
}
#endif

static int zeus_get_pcb_info(struct i2c_client *client, unsigned gpio,
			     unsigned ngpio, void *context)
{
	int i;
	u8 pcb_info = 0;

	for (i = 0; i < 8; i++) {
		int pcb_bit = gpio + i + 8;

		if (gpio_request(pcb_bit, "pcb info")) {
			dev_err(&client->dev, "Can't request pcb info %d\n", i);
			continue;
		}

		if (gpio_direction_input(pcb_bit)) {
			dev_err(&client->dev, "Can't read pcb info %d\n", i);
			gpio_free(pcb_bit);
			continue;
		}

		pcb_info |= !!gpio_get_value(pcb_bit) << i;

		gpio_free(pcb_bit);
	}

	dev_info(&client->dev, "Zeus PCB version %d issue %d\n",
		 pcb_info >> 4, pcb_info & 0xf);

	return 0;
}

static struct pca953x_platform_data zeus_pca953x_pdata[] = {
	[0] = { .gpio_base	= ZEUS_EXT0_GPIO_BASE, },
	[1] = {
		.gpio_base	= ZEUS_EXT1_GPIO_BASE,
		.setup		= zeus_get_pcb_info,
	},
	[2] = { .gpio_base = ZEUS_USER_GPIO_BASE, },
};

static struct i2c_board_info __initdata zeus_i2c_devices[] = {
	{
		I2C_BOARD_INFO("pca9535",	0x21),
		.platform_data	= &zeus_pca953x_pdata[0],
	},
	{
		I2C_BOARD_INFO("pca9535",	0x22),
		.platform_data	= &zeus_pca953x_pdata[1],
	},
	{
		I2C_BOARD_INFO("pca9535",	0x20),
		.platform_data	= &zeus_pca953x_pdata[2],
		.irq		= PXA_GPIO_TO_IRQ(ZEUS_EXTGPIO_GPIO),
	},
	{ I2C_BOARD_INFO("lm75a",	0x48) },
	{ I2C_BOARD_INFO("24c01",	0x50) },
	{ I2C_BOARD_INFO("isl1208",	0x6f) },
};

static mfp_cfg_t zeus_pin_config[] __initdata = {
	/* AC97 */
	GPIO28_AC97_BITCLK,
	GPIO29_AC97_SDATA_IN_0,
	GPIO30_AC97_SDATA_OUT,
	GPIO31_AC97_SYNC,

	GPIO15_nCS_1,
	GPIO78_nCS_2,
	GPIO80_nCS_4,
	GPIO33_nCS_5,

	GPIO22_GPIO,
	GPIO32_MMC_CLK,
	GPIO92_MMC_DAT_0,
	GPIO109_MMC_DAT_1,
	GPIO110_MMC_DAT_2,
	GPIO111_MMC_DAT_3,
	GPIO112_MMC_CMD,

	GPIO88_USBH1_PWR,
	GPIO89_USBH1_PEN,
	GPIO119_USBH2_PWR,
	GPIO120_USBH2_PEN,

	GPIO86_LCD_LDD_16,
	GPIO87_LCD_LDD_17,

	GPIO102_GPIO,
	GPIO104_CIF_DD_2,
	GPIO105_CIF_DD_1,

	GPIO81_SSP3_TXD,
	GPIO82_SSP3_RXD,
	GPIO83_SSP3_SFRM,
	GPIO84_SSP3_SCLK,

	GPIO48_nPOE,
	GPIO49_nPWE,
	GPIO50_nPIOR,
	GPIO51_nPIOW,
	GPIO85_nPCE_1,
	GPIO54_nPCE_2,
	GPIO79_PSKTSEL,
	GPIO55_nPREG,
	GPIO56_nPWAIT,
	GPIO57_nIOIS16,
	GPIO36_GPIO,		/* CF CD */
	GPIO97_GPIO,		/* CF PWREN */
	GPIO99_GPIO,		/* CF RDY */
};

/*
 * DM9k MSCx settings:	SRAM, 16 bits
 *			17 cycles delay first access
 *			 5 cycles delay next access
 *			13 cycles recovery time
 *			faster device
 */
#define DM9K_MSC_VALUE		0xe4c9

static void __init zeus_init(void)
{
	u16 dm9000_msc = DM9K_MSC_VALUE;
	u32 msc0, msc1;

	system_rev = __raw_readw(ZEUS_CPLD_VERSION);
	pr_info("Zeus CPLD V%dI%d\n", (system_rev & 0xf0) >> 4, (system_rev & 0x0f));

	/* Fix timings for dm9000s (CS1/CS2)*/
	msc0 = (__raw_readl(MSC0) & 0x0000ffff) | (dm9000_msc << 16);
	msc1 = (__raw_readl(MSC1) & 0xffff0000) | dm9000_msc;
	__raw_writel(msc0, MSC0);
	__raw_writel(msc1, MSC1);

	pm_power_off = zeus_power_off;
	zeus_setup_apm();

	pxa2xx_mfp_config(ARRAY_AND_SIZE(zeus_pin_config));

	gpiod_add_lookup_table(&can_regulator_gpiod_table);
	gpiod_add_lookup_table(&zeus_ohci_regulator_gpiod_table);
	platform_add_devices(zeus_devices, ARRAY_SIZE(zeus_devices));

	zeus_register_ohci();

	if (zeus_setup_fb_gpios())
		pr_err("Failed to setup fb gpios\n");
	else
		pxa_set_fb_info(NULL, &zeus_fb_info);

	gpiod_add_lookup_table(&zeus_mci_gpio_table);
	pxa_set_mci_info(&zeus_mci_platform_data);
	pxa_set_udc_info(&zeus_udc_info);
	pxa_set_ac97_info(&zeus_ac97_info);
	pxa_set_i2c_info(NULL);
	i2c_register_board_info(0, ARRAY_AND_SIZE(zeus_i2c_devices));
	pxa2xx_set_spi_info(3, &pxa2xx_spi_ssp3_master_info);
	spi_register_board_info(zeus_spi_board_info, ARRAY_SIZE(zeus_spi_board_info));

	regulator_has_full_constraints();
}

static struct map_desc zeus_io_desc[] __initdata = {
	{
		.virtual = (unsigned long)ZEUS_CPLD_VERSION,
		.pfn     = __phys_to_pfn(ZEUS_CPLD_VERSION_PHYS),
		.length  = 0x1000,
		.type    = MT_DEVICE,
	},
	{
		.virtual = (unsigned long)ZEUS_CPLD_ISA_IRQ,
		.pfn     = __phys_to_pfn(ZEUS_CPLD_ISA_IRQ_PHYS),
		.length  = 0x1000,
		.type    = MT_DEVICE,
	},
	{
		.virtual = (unsigned long)ZEUS_CPLD_CONTROL,
		.pfn     = __phys_to_pfn(ZEUS_CPLD_CONTROL_PHYS),
		.length  = 0x1000,
		.type    = MT_DEVICE,
	},
	{
		.virtual = (unsigned long)ZEUS_PC104IO,
		.pfn     = __phys_to_pfn(ZEUS_PC104IO_PHYS),
		.length  = 0x00800000,
		.type    = MT_DEVICE,
	},
	{
		/*
		 * ISA I/O space mapping:
		 * -  ports 0x0000-0x0fff are PC/104
		 * -  ports 0x10000-0x10fff are PCMCIA slot 1
		 * -  ports 0x11000-0x11fff are PC/104
		 */
		.virtual = PCI_IO_VIRT_BASE,
		.pfn     = __phys_to_pfn(ZEUS_PC104IO_PHYS),
		.length  = 0x1000,
		.type    = MT_DEVICE,
	},
};

static void __init zeus_map_io(void)
{
	pxa27x_map_io();

	iotable_init(zeus_io_desc, ARRAY_SIZE(zeus_io_desc));

	/* Clear PSPR to ensure a full restart on wake-up. */
	PMCR = PSPR = 0;

	/* enable internal 32.768Khz oscillator (ignore OSCC_OOK) */
	writel(readl(OSCC) | OSCC_OON, OSCC);

	/* Some clock cycles later (from OSCC_ON), programme PCFR (OPDE...).
	 * float chip selects and PCMCIA */
	PCFR = PCFR_OPDE | PCFR_DC_EN | PCFR_FS | PCFR_FP;
}

MACHINE_START(ARCOM_ZEUS, "Arcom/Eurotech ZEUS")
	/* Maintainer: Marc Zyngier <maz@misterjones.org> */
	.atag_offset	= 0x100,
	.map_io		= zeus_map_io,
	.nr_irqs	= ZEUS_NR_IRQS,
	.init_irq	= zeus_init_irq,
	.handle_irq	= pxa27x_handle_irq,
	.init_time	= pxa_timer_init,
	.init_machine	= zeus_init,
	.restart	= pxa_restart,
MACHINE_END


code:
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 *  arch/arm/mach-pxa/include/mach/zeus.h
 *
 *  Author:	David Vrabel
 *  Created:	Sept 28, 2005
 *  Copyright:	Arcom Control Systems Ltd.
 *
 *  Maintained by: Marc Zyngier <maz@misterjones.org>
 */

#ifndef _MACH_ZEUS_H
#define _MACH_ZEUS_H

#define ZEUS_NR_IRQS		(IRQ_BOARD_START + 48)

/* Physical addresses */
#define ZEUS_FLASH_PHYS		PXA_CS0_PHYS
#define ZEUS_ETH0_PHYS		PXA_CS1_PHYS
#define ZEUS_ETH1_PHYS		PXA_CS2_PHYS
#define ZEUS_CPLD_PHYS		(PXA_CS4_PHYS+0x2000000)
#define ZEUS_SRAM_PHYS		PXA_CS5_PHYS
#define ZEUS_PC104IO_PHYS	(0x30000000)

#define ZEUS_CPLD_VERSION_PHYS	(ZEUS_CPLD_PHYS + 0x00000000)
#define ZEUS_CPLD_ISA_IRQ_PHYS	(ZEUS_CPLD_PHYS + 0x00800000)
#define ZEUS_CPLD_CONTROL_PHYS	(ZEUS_CPLD_PHYS + 0x01000000)
#define ZEUS_CPLD_EXTWDOG_PHYS	(ZEUS_CPLD_PHYS + 0x01800000)

/* GPIOs */
#define ZEUS_AC97_GPIO		0
#define ZEUS_WAKEUP_GPIO	1
#define ZEUS_UARTA_GPIO		9
#define ZEUS_UARTB_GPIO		10
#define ZEUS_UARTC_GPIO		12
#define ZEUS_UARTD_GPIO		11
#define ZEUS_ETH0_GPIO		14
#define ZEUS_ISA_GPIO		17
#define ZEUS_BKLEN_GPIO		19
#define ZEUS_USB2_PWREN_GPIO	22
#define ZEUS_PTT_GPIO		27
#define ZEUS_CF_CD_GPIO         35
#define ZEUS_MMC_WP_GPIO        52
#define ZEUS_MMC_CD_GPIO        53
#define ZEUS_EXTGPIO_GPIO	91
#define ZEUS_CF_PWEN_GPIO       97
#define ZEUS_CF_RDY_GPIO        99
#define ZEUS_LCD_EN_GPIO	101
#define ZEUS_ETH1_GPIO		113
#define ZEUS_CAN_GPIO		116

#define ZEUS_EXT0_GPIO_BASE	128
#define ZEUS_EXT1_GPIO_BASE	160
#define ZEUS_USER_GPIO_BASE	192

#define ZEUS_EXT0_GPIO(x)	(ZEUS_EXT0_GPIO_BASE + (x))
#define ZEUS_EXT1_GPIO(x)	(ZEUS_EXT1_GPIO_BASE + (x))
#define ZEUS_USER_GPIO(x)	(ZEUS_USER_GPIO_BASE + (x))

#define	ZEUS_CAN_SHDN_GPIO	ZEUS_EXT1_GPIO(2)

/*
 * CPLD registers:
 * Only 4 registers, but spread over a 32MB address space.
 * Be gentle, and remap that over 32kB...
 */

#define ZEUS_CPLD		IOMEM(0xf0000000)
#define ZEUS_CPLD_VERSION	(ZEUS_CPLD + 0x0000)
#define ZEUS_CPLD_ISA_IRQ	(ZEUS_CPLD + 0x1000)
#define ZEUS_CPLD_CONTROL	(ZEUS_CPLD + 0x2000)

/* CPLD register bits */
#define ZEUS_CPLD_CONTROL_CF_RST        0x01

#define ZEUS_PC104IO		IOMEM(0xf1000000)

#define ZEUS_SRAM_SIZE		(256 * 1024)

#endif