From owner-svn-src-all@FreeBSD.ORG Sun Jul 11 20:49:36 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE78F1065673; Sun, 11 Jul 2010 20:49:36 +0000 (UTC) (envelope-from raj@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9413D8FC13; Sun, 11 Jul 2010 20:49:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6BKna8v086805; Sun, 11 Jul 2010 20:49:36 GMT (envelope-from raj@svn.freebsd.org) Received: (from raj@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6BKnaqL086803; Sun, 11 Jul 2010 20:49:36 GMT (envelope-from raj@svn.freebsd.org) Message-Id: <201007112049.o6BKnaqL086803@svn.freebsd.org> From: Rafal Jaworowski Date: Sun, 11 Jul 2010 20:49:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r209906 - head/sys/dev/fdt X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Jul 2010 20:49:36 -0000 Author: raj Date: Sun Jul 11 20:49:36 2010 New Revision: 209906 URL: http://svn.freebsd.org/changeset/base/209906 Log: Introduce PowerPC-specific helper routines for FDT. Reviewed by: imp Sponsored by: The FreeBSD Foundation Added: head/sys/dev/fdt/fdt_powerpc.c (contents, props changed) Added: head/sys/dev/fdt/fdt_powerpc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/fdt/fdt_powerpc.c Sun Jul 11 20:49:36 2010 (r209906) @@ -0,0 +1,168 @@ +/*- + * Copyright (c) 2009-2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Semihalf under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "ofw_bus_if.h" +#include "fdt_common.h" + +static void +fdt_fixup_busfreq(phandle_t root) +{ + phandle_t sb, cpus, child; + pcell_t freq; + + /* + * Do a strict check so as to skip non-SOC nodes, which also claim + * simple-bus compatibility such as eLBC etc. + */ + if ((sb = fdt_find_compatible(root, "simple-bus", 1)) == 0) + return; + + /* + * This fixup uses /cpus/ bus-frequency prop value to set simple-bus + * bus-frequency property. + */ + if ((cpus = OF_finddevice("/cpus")) == 0) + return; + + if ((child = OF_child(cpus)) == 0) + return; + + if (OF_getprop(child, "bus-frequency", (void *)&freq, + sizeof(freq)) <= 0) + return; + + OF_setprop(sb, "bus-frequency", (void *)&freq, sizeof(freq)); +} + +struct fdt_fixup_entry fdt_fixup_table[] = { + { "fsl,MPC8572DS", &fdt_fixup_busfreq }, + { "MPC8555CDS", &fdt_fixup_busfreq }, + { NULL, NULL } +}; + +static int +fdt_pic_decode_iic(phandle_t node, pcell_t *intr, int *interrupt, int *trig, + int *pol) +{ + if (!fdt_is_compatible(node, "chrp,iic")) + return (ENXIO); + + *interrupt = intr[0]; + + switch (intr[1]) { + case 0: + /* Active L level */ + *trig = INTR_TRIGGER_LEVEL; + *pol = INTR_POLARITY_LOW; + break; + case 1: + /* Active H level */ + *trig = INTR_TRIGGER_LEVEL; + *pol = INTR_POLARITY_HIGH; + break; + case 2: + /* H to L edge */ + *trig = INTR_TRIGGER_EDGE; + *pol = INTR_POLARITY_LOW; + break; + case 3: + /* L to H edge */ + *trig = INTR_TRIGGER_EDGE; + *pol = INTR_POLARITY_HIGH; + break; + default: + *trig = INTR_TRIGGER_CONFORM; + *pol = INTR_POLARITY_CONFORM; + } + return (0); +} + +static int +fdt_pic_decode_openpic(phandle_t node, pcell_t *intr, int *interrupt, + int *trig, int *pol) +{ + + if (!fdt_is_compatible(node, "chrp,open-pic")) + return (ENXIO); + + /* + * XXX The interrupt number read out from the MPC85XX device tree is + * already offset by 16 to reflect the 'internal' IRQ range shift on + * the OpenPIC. + */ + *interrupt = intr[0]; + + switch (intr[1]) { + case 0: + /* L to H edge */ + *trig = INTR_TRIGGER_EDGE; + *pol = INTR_POLARITY_HIGH; + break; + case 1: + /* Active L level */ + *trig = INTR_TRIGGER_LEVEL; + *pol = INTR_POLARITY_LOW; + break; + case 2: + /* Active H level */ + *trig = INTR_TRIGGER_LEVEL; + *pol = INTR_POLARITY_HIGH; + break; + case 3: + /* H to L edge */ + *trig = INTR_TRIGGER_EDGE; + *pol = INTR_POLARITY_LOW; + break; + default: + *trig = INTR_TRIGGER_CONFORM; + *pol = INTR_POLARITY_CONFORM; + } + return (0); +} + +fdt_pic_decode_t fdt_pic_table[] = { + &fdt_pic_decode_iic, + &fdt_pic_decode_openpic, + NULL +};