Path: blob/master/arch/powerpc/platforms/52xx/efika.c
10818 views
/*1* Efika 5K2 platform code2* Some code really inspired from the lite5200b platform.3*4* Copyright (C) 2006 bplan GmbH5*6* This file is licensed under the terms of the GNU General Public License7* version 2. This program is licensed "as is" without any warranty of any8* kind, whether express or implied.9*/1011#include <linux/init.h>12#include <generated/utsrelease.h>13#include <linux/pci.h>14#include <linux/of.h>15#include <asm/prom.h>16#include <asm/time.h>17#include <asm/machdep.h>18#include <asm/rtas.h>19#include <asm/mpc52xx.h>2021#define EFIKA_PLATFORM_NAME "Efika"222324/* ------------------------------------------------------------------------ */25/* PCI accesses thru RTAS */26/* ------------------------------------------------------------------------ */2728#ifdef CONFIG_PCI2930/*31* Access functions for PCI config space using RTAS calls.32*/33static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,34int len, u32 * val)35{36struct pci_controller *hose = pci_bus_to_host(bus);37unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)38| (((bus->number - hose->first_busno) & 0xff) << 16)39| (hose->global_number << 24);40int ret = -1;41int rval;4243rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);44*val = ret;45return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;46}4748static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,49int offset, int len, u32 val)50{51struct pci_controller *hose = pci_bus_to_host(bus);52unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)53| (((bus->number - hose->first_busno) & 0xff) << 16)54| (hose->global_number << 24);55int rval;5657rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,58addr, len, val);59return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;60}6162static struct pci_ops rtas_pci_ops = {63.read = rtas_read_config,64.write = rtas_write_config,65};666768static void __init efika_pcisetup(void)69{70const int *bus_range;71int len;72struct pci_controller *hose;73struct device_node *root;74struct device_node *pcictrl;7576root = of_find_node_by_path("/");77if (root == NULL) {78printk(KERN_WARNING EFIKA_PLATFORM_NAME79": Unable to find the root node\n");80return;81}8283for (pcictrl = NULL;;) {84pcictrl = of_get_next_child(root, pcictrl);85if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))86break;87}8889of_node_put(root);9091if (pcictrl == NULL) {92printk(KERN_WARNING EFIKA_PLATFORM_NAME93": Unable to find the PCI bridge node\n");94return;95}9697bus_range = of_get_property(pcictrl, "bus-range", &len);98if (bus_range == NULL || len < 2 * sizeof(int)) {99printk(KERN_WARNING EFIKA_PLATFORM_NAME100": Can't get bus-range for %s\n", pcictrl->full_name);101goto out_put;102}103104if (bus_range[1] == bus_range[0])105printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",106bus_range[0]);107else108printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",109bus_range[0], bus_range[1]);110printk(" controlled by %s\n", pcictrl->full_name);111printk("\n");112113hose = pcibios_alloc_controller(pcictrl);114if (!hose) {115printk(KERN_WARNING EFIKA_PLATFORM_NAME116": Can't allocate PCI controller structure for %s\n",117pcictrl->full_name);118goto out_put;119}120121hose->first_busno = bus_range[0];122hose->last_busno = bus_range[1];123hose->ops = &rtas_pci_ops;124125pci_process_bridge_OF_ranges(hose, pcictrl, 0);126return;127out_put:128of_node_put(pcictrl);129}130131#else132static void __init efika_pcisetup(void)133{}134#endif135136137138/* ------------------------------------------------------------------------ */139/* Platform setup */140/* ------------------------------------------------------------------------ */141142static void efika_show_cpuinfo(struct seq_file *m)143{144struct device_node *root;145const char *revision;146const char *codegendescription;147const char *codegenvendor;148149root = of_find_node_by_path("/");150if (!root)151return;152153revision = of_get_property(root, "revision", NULL);154codegendescription = of_get_property(root, "CODEGEN,description", NULL);155codegenvendor = of_get_property(root, "CODEGEN,vendor", NULL);156157if (codegendescription)158seq_printf(m, "machine\t\t: %s\n", codegendescription);159else160seq_printf(m, "machine\t\t: Efika\n");161162if (revision)163seq_printf(m, "revision\t: %s\n", revision);164165if (codegenvendor)166seq_printf(m, "vendor\t\t: %s\n", codegenvendor);167168of_node_put(root);169}170171#ifdef CONFIG_PM172static void efika_suspend_prepare(void __iomem *mbar)173{174u8 pin = 4; /* GPIO_WKUP_4 (GPIO_PSC6_0 - IRDA_RX) */175u8 level = 1; /* wakeup on high level */176/* IOW. to wake it up, short pins 1 and 3 on IRDA connector */177mpc52xx_set_wakeup_gpio(pin, level);178}179#endif180181static void __init efika_setup_arch(void)182{183rtas_initialize();184185/* Map important registers from the internal memory map */186mpc52xx_map_common_devices();187188efika_pcisetup();189190#ifdef CONFIG_PM191mpc52xx_suspend.board_suspend_prepare = efika_suspend_prepare;192mpc52xx_pm_init();193#endif194195if (ppc_md.progress)196ppc_md.progress("Linux/PPC " UTS_RELEASE " running on Efika ;-)\n", 0x0);197}198199static int __init efika_probe(void)200{201char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),202"model", NULL);203204if (model == NULL)205return 0;206if (strcmp(model, "EFIKA5K2"))207return 0;208209ISA_DMA_THRESHOLD = ~0L;210DMA_MODE_READ = 0x44;211DMA_MODE_WRITE = 0x48;212213return 1;214}215216define_machine(efika)217{218.name = EFIKA_PLATFORM_NAME,219.probe = efika_probe,220.setup_arch = efika_setup_arch,221.init = mpc52xx_declare_of_platform_devices,222.show_cpuinfo = efika_show_cpuinfo,223.init_IRQ = mpc52xx_init_irq,224.get_irq = mpc52xx_get_irq,225.restart = rtas_restart,226.power_off = rtas_power_off,227.halt = rtas_halt,228.set_rtc_time = rtas_set_rtc_time,229.get_rtc_time = rtas_get_rtc_time,230.progress = rtas_progress,231.get_boot_time = rtas_get_boot_time,232.calibrate_decr = generic_calibrate_decr,233#ifdef CONFIG_PCI234.phys_mem_access_prot = pci_phys_mem_access_prot,235#endif236};237238239240