From patchwork Thu Oct 8 07:55:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Feng X-Patchwork-Id: 54622 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 07DF622FF8 for ; Thu, 8 Oct 2015 08:13:00 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf19626657lbb.3 for ; Thu, 08 Oct 2015 01:12:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=rC/WfQ1V54NVA4llz885dhWXdXyCK/AVgXUB7jfYRFc=; b=I0m87kYhUrePQbLRQ5NSnQxhO2um6Sizv//VLpjXhL23dan1MKpz0z9y94YLJ9IBMq RWWtWwSAVepJ5FhIBBoneYMYlJfJ6v+bMV/OGlRIBHodqaRG1TbclLzNdH+aHthZt44D YHG8bdRP5RfpZh5J3hhdu0xPTtUcTjqZV5ipNkgoAdimDMfwIotSh5dVPTDAwQnyH2Pk EHijeqf0kGEeWR9Pci9wcETxv2Hd94ji1IlpIm3e9JqYhaMpHrgzMLhR+jyp86upxrei Eu4AdZjfpAExKhwXFmFSjPQQcb20nSy80ztSTv0Wf66GFxSLXpNkFOZzw3+i0xoe9FI5 nr4Q== X-Gm-Message-State: ALoCoQnrcs6StDoHku72iUct+vTEJz/xksxCmhr4xDL/kUHtqOw+vLzuVIMUAjpRoNP1Zdi0QjK5 X-Received: by 10.112.140.202 with SMTP id ri10mr449947lbb.10.1444291978874; Thu, 08 Oct 2015 01:12:58 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.78.81 with SMTP id c78ls145455lfb.45.gmail; Thu, 08 Oct 2015 01:12:58 -0700 (PDT) X-Received: by 10.25.21.79 with SMTP id l76mr1937849lfi.79.1444291978706; Thu, 08 Oct 2015 01:12:58 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id k20si28747296lfe.96.2015.10.08.01.12.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 01:12:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbwt4 with SMTP id wt4so38075054lbb.1 for ; Thu, 08 Oct 2015 01:12:58 -0700 (PDT) X-Received: by 10.25.210.206 with SMTP id j197mr1909185lfg.86.1444291978508; Thu, 08 Oct 2015 01:12:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp429178lbq; Thu, 8 Oct 2015 01:12:56 -0700 (PDT) X-Received: by 10.107.18.231 with SMTP id 100mr7015028ios.15.1444291976611; Thu, 08 Oct 2015 01:12:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n31si30742046ioe.74.2015.10.08.01.12.56; Thu, 08 Oct 2015 01:12:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752890AbbJHIMx (ORCPT + 30 others); Thu, 8 Oct 2015 04:12:53 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:28056 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbbJHIMt (ORCPT ); Thu, 8 Oct 2015 04:12:49 -0400 Received: from 172.24.1.50 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.50]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOO10162; Thu, 08 Oct 2015 15:55:27 +0800 (CST) Received: from u105-115.huawei.com (10.141.105.115) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Oct 2015 15:55:16 +0800 From: Chen Feng To: , , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH 2/3] staging: android: ion: Add ion driver for Hi6220 SoC platform Date: Thu, 8 Oct 2015 15:55:12 +0800 Message-ID: <1444290913-76936-2-git-send-email-puck.chen@hisilicon.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444290913-76936-1-git-send-email-puck.chen@hisilicon.com> References: <1444290913-76936-1-git-send-email-puck.chen@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.141.105.115] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090202.56162553.0067, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: d28ded7ff46e6f47764ff606d9c17ee9 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: puck.chen@hisilicon.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Chen Feng Signed-off-by: Yu Dongbin --- drivers/staging/android/ion/Kconfig | 7 + drivers/staging/android/ion/Makefile | 1 + drivers/staging/android/ion/hisilicon/Kconfig | 5 + drivers/staging/android/ion/hisilicon/Makefile | 1 + drivers/staging/android/ion/hisilicon/hi6220_ion.c | 201 +++++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 drivers/staging/android/ion/hisilicon/Kconfig create mode 100644 drivers/staging/android/ion/hisilicon/Makefile create mode 100644 drivers/staging/android/ion/hisilicon/hi6220_ion.c diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig index 3452346..19c1572 100644 --- a/drivers/staging/android/ion/Kconfig +++ b/drivers/staging/android/ion/Kconfig @@ -33,3 +33,10 @@ config ION_TEGRA help Choose this option if you wish to use ion on an nVidia Tegra. +config ION_HISI + tristate "Ion for Hisilicon" + depends on ARCH_HISI && ION + help + Choose this option if you wish to use ion on Hisilicon Platform. + +source "drivers/staging/android/ion/hisilicon/Kconfig" diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile index b56fd2b..18cc2aa 100644 --- a/drivers/staging/android/ion/Makefile +++ b/drivers/staging/android/ion/Makefile @@ -7,4 +7,5 @@ endif obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o obj-$(CONFIG_ION_TEGRA) += tegra/ +obj-$(CONFIG_ION_HISI) += hisilicon/ diff --git a/drivers/staging/android/ion/hisilicon/Kconfig b/drivers/staging/android/ion/hisilicon/Kconfig new file mode 100644 index 0000000..2b4bd07 --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/Kconfig @@ -0,0 +1,5 @@ +config HI6220_ION + bool "Hi6220 ION Driver" + depends on ARCH_HISI && ION + help + Build the Hisilicon Hi6220 ion driver. diff --git a/drivers/staging/android/ion/hisilicon/Makefile b/drivers/staging/android/ion/hisilicon/Makefile new file mode 100644 index 0000000..2a89414 --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_HI6220_ION) += hi6220_ion.o diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c new file mode 100644 index 0000000..b7d39b8 --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c @@ -0,0 +1,201 @@ +#define pr_fmt(fmt) "Ion: " fmt + +#include +#include +#include +#include +#include +#include "../ion_priv.h" +#include "../ion.h" + +struct hi6220_ion_type_table { + const char *name; + enum ion_heap_type type; +}; + +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_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) +{ + int i, n; + + n = ARRAY_SIZE(ion_type_table); + for (i = 0; i < n; i++) { + if (strncmp(name, ion_type_table[i].name, strlen(name))) + continue; + + *type = ion_type_table[i].type; + return 0; + } + + return -1; +} + +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); + + for_each_child_of_node(dt_node, np) { + p_data = devm_kzalloc(&pdev->dev, + sizeof(struct ion_platform_heap), + GFP_KERNEL); + + 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->name = heap_name; + p_data->base = base; + p_data->size = size; + p_data->id = id; + p_data->type = type; + + heaps_data[index] = p_data; + index++; + } + return 0; +} + +static int __init hi6220_ion_probe(struct platform_device *pdev) +{ + int i; + int err = 0; + static struct ion_platform_heap *p_heap; + + idev = ion_device_create(NULL); + if (IS_ERR_OR_NULL(idev)) { + pr_err("ion_device_create err %lx\n", PTR_ERR(idev)); + return PTR_ERR(idev); + } + + hi6220_set_platform_data(pdev); + + heaps = devm_kzalloc(&pdev->dev, + sizeof(struct ion_heap *) * num_heaps, + GFP_KERNEL); + + /* + * 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 out; + } + + 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); + } + return err; +out: + for (i = 0; i < num_heaps; ++i) + ion_heap_destroy(heaps[i]); + return err; +} + +static int hi6220_ion_remove(struct platform_device *pdev) +{ + int i; + + ion_device_destroy(idev); + for (i = 0; i < num_heaps; i++) { + if (!heaps[i]) + continue; + ion_heap_destroy(heaps[i]); + heaps[i] = NULL; + } + + return 0; +} + +static const struct of_device_id hi6220_ion_match_table[] = { + {.compatible = "hisilicon,hi6220-ion"}, + {}, +}; + +static struct platform_driver hi6220_ion_driver = { + .probe = hi6220_ion_probe, + .remove = hi6220_ion_remove, + .driver = { + .name = "ion-hi6220", + .of_match_table = hi6220_ion_match_table, + }, +}; + +static int __init hi6220_ion_init(void) +{ + int ret; + + ret = platform_driver_register(&hi6220_ion_driver); + return ret; +} + +subsys_initcall(hi6220_ion_init);