From: maxime.ripard@free-electrons.com (Maxime Ripard)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/9] ARM: sunxi: quirk support
Date: Sun, 3 Aug 2014 14:42:11 +0200 [thread overview]
Message-ID: <20140803124211.GU3952@lukather> (raw)
In-Reply-To: <1406842092-25207-3-git-send-email-emilio@elopez.com.ar>
On Thu, Jul 31, 2014 at 06:28:05PM -0300, Emilio L?pez wrote:
> Currently, some hardware revisions of sunxi SoCs need special care on
> some blocks because of hardware differences and/or bugs. Unfortunately,
> it is unfeasible to account for these issues directly when writing the
> device tree, as SoC revision can vary between different units of the
> same device. This commit introduces a place to adjust DT compatibles
> as needed to work around said issues before devices are probed. To
> demonstrate usage, two quirks are added for the PLL2 and audio codec
> on sun4i.
>
> Signed-off-by: Emilio L?pez <emilio@elopez.com.ar>
> ---
> arch/arm/mach-sunxi/Makefile | 2 +-
> arch/arm/mach-sunxi/quirks.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 83 insertions(+), 1 deletion(-)
> create mode 100644 arch/arm/mach-sunxi/quirks.c
>
> diff --git a/arch/arm/mach-sunxi/Makefile b/arch/arm/mach-sunxi/Makefile
> index 589239b..7c13f99 100644
> --- a/arch/arm/mach-sunxi/Makefile
> +++ b/arch/arm/mach-sunxi/Makefile
> @@ -1,2 +1,2 @@
> -obj-$(CONFIG_ARCH_SUNXI) += sunxi.o sunxi-soc-id.o
> +obj-$(CONFIG_ARCH_SUNXI) += sunxi.o sunxi-soc-id.o quirks.o
> obj-$(CONFIG_SMP) += platsmp.o
> diff --git a/arch/arm/mach-sunxi/quirks.c b/arch/arm/mach-sunxi/quirks.c
> new file mode 100644
> index 0000000..99cdaa0
> --- /dev/null
> +++ b/arch/arm/mach-sunxi/quirks.c
> @@ -0,0 +1,82 @@
> +/*
> + * Runtime quirk handling for sunxi SoCs
> + *
> + * Copyright 2014 Emilio L?pez
> + *
> + * Emilio L?pez <emilio@elopez.com.ar>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/of.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +
> +#include "sunxi-soc-id.h"
> +
> +static int __init update_compatible_string(const char *oldc, const char *newc)
> +{
> + int count = 0;
> + struct property *newprop;
> + size_t newlen = strlen(newc);
> + struct device_node *np = NULL;
> +
> + for_each_compatible_node(np, NULL, oldc) {
> + newprop = kzalloc(sizeof(*newprop), GFP_KERNEL);
> + if (!newprop)
> + return -ENOMEM;
> +
> + newprop->name = kstrdup("compatible", GFP_KERNEL);
> + newprop->value = kstrdup(newc, GFP_KERNEL);
> + newprop->length = newlen;
> +
> + if (!newprop->name || !newprop->value) {
> + kfree(newprop);
> + return -ENOMEM;
> + }
> +
> + of_update_property(np, newprop);
> + count++;
> + }
> +
> + return count;
> +}
> +
> +static void __init sun4i_pll2_quirk(void)
> +{
> + /* Only revision A is affected */
> + if (sunxi_soc_revision() != 'A')
> + return;
> +
> + WARN_ON(!update_compatible_string("allwinner,sun4i-a10-b-pll2",
> + "allwinner,sun4i-a10-a-pll2"));
> +}
> +
> +static void __init sun4i_codec_quirk(void)
> +{
> + /* Only revision A is affected */
> + if (sunxi_soc_revision() != 'A')
> + return;
> +
> + WARN_ON(!update_compatible_string("allwinner,sun4i-a10-b-codec",
> + "allwinner,sun4i-a10-a-codec"));
> +}
> +
> +static int __init sunxi_apply_quirks(void)
> +{
> + if (of_machine_is_compatible("allwinner,sun4i-a10")) {
> + sun4i_pll2_quirk();
> + sun4i_codec_quirk();
> + }
> +
> + return 0;
> +}
> +postcore_initcall(sunxi_apply_quirks)
Have you tested it? My guess is that it wolud have to run *much*
sooner, before of_platform_populate to be effective.
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140803/343600df/attachment.sig>
next prev parent reply other threads:[~2014-08-03 12:42 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-31 21:28 [PATCH 0/9] Audio clocks for sun[457]i, SoC revision detection Emilio López
2014-07-31 21:28 ` [PATCH 1/9] ARM: sunxi: introduce SoC identification support Emilio López
2014-08-03 12:40 ` Maxime Ripard
2014-08-03 21:45 ` Emilio López
2014-08-04 8:08 ` Lee Jones
2014-08-04 19:48 ` Maxime Ripard
2014-07-31 21:28 ` [PATCH 2/9] ARM: sunxi: quirk support Emilio López
2014-08-03 12:42 ` Maxime Ripard [this message]
2014-08-03 21:37 ` Emilio López
2014-08-04 19:32 ` Maxime Ripard
2014-07-31 21:28 ` [PATCH 3/9] ARM: sunxi: make sun6i SMP ops static Emilio López
2014-08-03 12:41 ` Maxime Ripard
2014-07-31 21:28 ` [PATCH 4/9] clk: sunxi: PLL2 support for sun4i, sun5i and sun7i Emilio López
2014-08-03 12:44 ` Maxime Ripard
2014-08-03 15:58 ` Chen-Yu Tsai
2014-08-03 18:48 ` Maxime Ripard
2014-08-03 22:02 ` Emilio López
2014-08-04 20:02 ` Maxime Ripard
2014-08-04 20:23 ` Emilio López
2014-08-07 11:23 ` Maxime Ripard
2014-08-06 13:51 ` jonsmirl at gmail.com
2014-08-06 15:20 ` jonsmirl at gmail.com
2014-08-08 0:03 ` jonsmirl at gmail.com
2014-07-31 21:28 ` [PATCH 5/9] clk: sunxi: codec clock support Emilio López
2014-07-31 21:28 ` [PATCH 6/9] clk: sunxi: mod1 " Emilio López
2014-08-03 12:47 ` Maxime Ripard
2014-08-03 22:11 ` Emilio López
2014-08-04 19:52 ` Maxime Ripard
2014-07-31 21:28 ` [PATCH 7/9] ARM: sunxi: dt: Add PLL2 support Emilio López
2014-07-31 21:46 ` jonsmirl at gmail.com
2014-08-03 12:50 ` Maxime Ripard
2014-08-03 15:55 ` Chen-Yu Tsai
2014-08-03 22:15 ` Emilio López
2014-08-04 19:53 ` Maxime Ripard
2014-07-31 21:28 ` [PATCH 8/9] ARM: sunxi: dt: Add codec clock support Emilio López
2014-07-31 21:28 ` [PATCH 9/9] ARM: sun7i: dt: Add mod1 clock nodes Emilio López
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140803124211.GU3952@lukather \
--to=maxime.ripard@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.