From patchwork Wed Aug 31 00:04:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9306195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D55F3607F0 for ; Wed, 31 Aug 2016 00:07:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5A9D28DCB for ; Wed, 31 Aug 2016 00:07:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA72428DD3; Wed, 31 Aug 2016 00:07:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2F4DD28DCB for ; Wed, 31 Aug 2016 00:07:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bet2V-0000Ea-Nf; Wed, 31 Aug 2016 00:05:59 +0000 Received: from mail-qk0-f171.google.com ([209.85.220.171]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bet1f-0007ES-07 for linux-arm-kernel@lists.infradead.org; Wed, 31 Aug 2016 00:05:09 +0000 Received: by mail-qk0-f171.google.com with SMTP id l2so35894811qkf.3 for ; Tue, 30 Aug 2016 17:04:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GevUQfDbDEyEZf2Q78PyFwQgPo8ZfZVFE1GW0mV7kiY=; b=T1RNPAD4ldN6EX9hgdvK/x6D0scE2WaB3jrAm42VlJpSaDL6nKG+ZFcGZvHy18M0iu v+QvOMfpY0lemMpYWeRIZ793HRJRwJPqFKL6fgv7rsDxbOpcfbV8UfWd9QfwytBDWKPe 85cFpIzq97BO2YlY5uXoZs2hQQjlHF1qd6obiV7j/OrMPDYwEyugz2QoKDw76+jJn2M+ b94ad/bwNRLmq8n14zLaNv1lxV14sQHZhbLD6vKv0Skpnje983ek3B+QYza1LOvXo2Ac VXRNvJgncU6sDtGNSMPaQ/oxHw1VrXM50VCZuzroRsyV5qrSCiuDeXJNxAWEtxQCbylh Op8A== X-Gm-Message-State: AE9vXwNLPLUk7dPJT2KPQG3iXPRhFFSUEL7MRimZiAcLpgiStzBQ7C0ltoJUVC/SS51g+MEU X-Received: by 10.55.154.134 with SMTP id c128mr6942587qke.18.1472601885873; Tue, 30 Aug 2016 17:04:45 -0700 (PDT) Received: from labbott-redhat-machine.redhat.com ([2601:602:9800:177f::2946]) by smtp.gmail.com with ESMTPSA id w94sm23253705qte.40.2016.08.30.17.04.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Aug 2016 17:04:44 -0700 (PDT) From: Laura Abbott To: Rob Herring , Frank Rowand , Sumit Semwal , Andrew Andrianov , arve@android.com, Riley Andrews Subject: [PATCHv3 3/3] staging: android: ion: Convert hi6220 to common platform Date: Tue, 30 Aug 2016 17:04:29 -0700 Message-Id: <1472601869-19469-4-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472601869-19469-1-git-send-email-labbott@redhat.com> References: <1472601869-19469-1-git-send-email-labbott@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160830_170507_348958_FE602ABA X-CRM114-Status: GOOD ( 18.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org, Arnd Bergmann , Tom Gall , romlem@google.com, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Colin Cross , Bryan Huntsman , John Stultz , Chen Feng , Mark Rutland , Laura Abbott , mitchelh@codeaurora.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we have common devicetree bindings, convert hisilicon platform to use the binding and parsing methods. Signed-off-by: Laura Abbott --- drivers/staging/android/ion/hisilicon/hi6220_ion.c | 195 +++++---------------- 1 file changed, 44 insertions(+), 151 deletions(-) diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c index fe9f0fd..f392db2 100644 --- a/drivers/staging/android/ion/hisilicon/hi6220_ion.c +++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c @@ -19,181 +19,74 @@ #include #include "../ion_priv.h" #include "../ion.h" +#include "../ion_of.h" -struct hi6220_ion_type_table { - const char *name; - enum ion_heap_type type; +struct hisi_ion_dev { + struct ion_heap **heaps; + struct ion_device *idev; + struct ion_platform_data *data; }; -static struct hi6220_ion_type_table ion_type_table[] = { - {"ion_system", ION_HEAP_TYPE_SYSTEM}, - {"ion_system_contig", ION_HEAP_TYPE_SYSTEM_CONTIG}, - {"ion_carveout", ION_HEAP_TYPE_CARVEOUT}, - {"ion_chunk", ION_HEAP_TYPE_CHUNK}, - {"ion_dma", ION_HEAP_TYPE_DMA}, - {"ion_custom", ION_HEAP_TYPE_CUSTOM}, +static struct ion_of_heap hisi_heaps[] = { + PLATFORM_HEAP("hisilicon,sys_user", 0, + ION_HEAP_TYPE_SYSTEM, "sys_user"), + PLATFORM_HEAP("hisilicon,sys_contig", 1, + ION_HEAP_TYPE_SYSTEM_CONTIG, "sys_contig"), + PLATFORM_HEAP("hisilicon,cma", ION_HEAP_TYPE_DMA, ION_HEAP_TYPE_DMA, + "cma"), + {} }; -static struct ion_device *idev; -static int num_heaps; -static struct ion_heap **heaps; -static struct ion_platform_heap **heaps_data; - -static int get_type_by_name(const char *name, enum ion_heap_type *type) +static int hi6220_ion_probe(struct platform_device *pdev) { + struct hisi_ion_dev *ipdev; int i; - for (i = 0; i < ARRAY_SIZE(ion_type_table); i++) { - if (strncmp(name, ion_type_table[i].name, strlen(name))) - continue; - - *type = ion_type_table[i].type; - return 0; - } - - return -EINVAL; -} - -static int hi6220_set_platform_data(struct platform_device *pdev) -{ - unsigned int base; - unsigned int size; - unsigned int id; - const char *heap_name; - const char *type_name; - enum ion_heap_type type; - int ret; - struct device_node *np; - struct ion_platform_heap *p_data; - const struct device_node *dt_node = pdev->dev.of_node; - int index = 0; - - for_each_child_of_node(dt_node, np) - num_heaps++; - - heaps_data = devm_kzalloc(&pdev->dev, - sizeof(struct ion_platform_heap *) * - num_heaps, - GFP_KERNEL); - if (!heaps_data) + ipdev = devm_kzalloc(&pdev->dev, sizeof(*ipdev), GFP_KERNEL); + if (!ipdev) return -ENOMEM; - for_each_child_of_node(dt_node, np) { - ret = of_property_read_string(np, "heap-name", &heap_name); - if (ret < 0) { - pr_err("check the name of node %s\n", np->name); - continue; - } - - ret = of_property_read_u32(np, "heap-id", &id); - if (ret < 0) { - pr_err("check the id %s\n", np->name); - continue; - } - - ret = of_property_read_u32(np, "heap-base", &base); - if (ret < 0) { - pr_err("check the base of node %s\n", np->name); - continue; - } - - ret = of_property_read_u32(np, "heap-size", &size); - if (ret < 0) { - pr_err("check the size of node %s\n", np->name); - continue; - } - - ret = of_property_read_string(np, "heap-type", &type_name); - if (ret < 0) { - pr_err("check the type of node %s\n", np->name); - continue; - } - - ret = get_type_by_name(type_name, &type); - if (ret < 0) { - pr_err("type name error %s!\n", type_name); - continue; - } - pr_info("heap index %d : name %s base 0x%x size 0x%x id %d type %d\n", - index, heap_name, base, size, id, type); - - p_data = devm_kzalloc(&pdev->dev, - sizeof(struct ion_platform_heap), - GFP_KERNEL); - if (!p_data) - return -ENOMEM; + platform_set_drvdata(pdev, ipdev); - p_data->name = heap_name; - p_data->base = base; - p_data->size = size; - p_data->id = id; - p_data->type = type; + ipdev->idev = ion_device_create(NULL); + if (!ipdev->idev) + return -ENOMEM; - heaps_data[index] = p_data; - index++; - } - return 0; -} + ipdev->data = ion_parse_dt(pdev, hisi_heaps); + if (IS_ERR(ipdev->data)) + return PTR_ERR(ipdev->data); -static int hi6220_ion_probe(struct platform_device *pdev) -{ - int i; - int err; - static struct ion_platform_heap *p_heap; - - idev = ion_device_create(NULL); - err = hi6220_set_platform_data(pdev); - if (err) { - pr_err("ion set platform data error!\n"); - goto err_free_idev; - } - heaps = devm_kzalloc(&pdev->dev, - sizeof(struct ion_heap *) * num_heaps, - GFP_KERNEL); - if (!heaps) { - err = -ENOMEM; - goto err_free_idev; + ipdev->heaps = devm_kzalloc(&pdev->dev, + sizeof(struct ion_heap)*ipdev->data->nr, + GFP_KERNEL); + if (!ipdev->heaps) { + ion_destroy_platform_data(ipdev->data); + return -ENOMEM; } - /* - * create the heaps as specified in the dts file - */ - for (i = 0; i < num_heaps; i++) { - p_heap = heaps_data[i]; - heaps[i] = ion_heap_create(p_heap); - if (IS_ERR_OR_NULL(heaps[i])) { - err = PTR_ERR(heaps[i]); - goto err_free_heaps; + for (i = 0; i < ipdev->data->nr; i++) { + ipdev->heaps[i] = ion_heap_create(&ipdev->data->heaps[i]); + if (!ipdev->heaps) { + ion_destroy_platform_data(ipdev->data); + return -ENOMEM; } - - ion_device_add_heap(idev, heaps[i]); - - pr_info("%s: adding heap %s of type %d with %lx@%lx\n", - __func__, p_heap->name, p_heap->type, - p_heap->base, (unsigned long)p_heap->size); + ion_device_add_heap(ipdev->idev, ipdev->heaps[i]); } - return err; - -err_free_heaps: - for (i = 0; i < num_heaps; ++i) { - ion_heap_destroy(heaps[i]); - heaps[i] = NULL; - } -err_free_idev: - ion_device_destroy(idev); - - return err; + return 0; } static int hi6220_ion_remove(struct platform_device *pdev) { + struct hisi_ion_dev *ipdev; int i; - for (i = 0; i < num_heaps; i++) { - ion_heap_destroy(heaps[i]); - heaps[i] = NULL; + ipdev = platform_get_drvdata(pdev); + + for (i = 0; i < ipdev->data->nr; i++) { + ion_heap_destroy(ipdev->heaps[i]); } - ion_device_destroy(idev); + ion_destroy_platform_data(ipdev->data); + ion_device_destroy(ipdev->idev); return 0; }