From patchwork Mon May 27 19:11:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 2621261 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id AD219DF215 for ; Mon, 27 May 2013 19:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756769Ab3E0TMW (ORCPT ); Mon, 27 May 2013 15:12:22 -0400 Received: from www.linutronix.de ([62.245.132.108]:48327 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756670Ab3E0TMU (ORCPT ); Mon, 27 May 2013 15:12:20 -0400 Received: from localhost ([127.0.0.1] helo=localhost.localdomain) by Galois.linutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1Uh2qB-0008KD-0W; Mon, 27 May 2013 21:12:19 +0200 From: Sebastian Andrzej Siewior To: linux-input@vger.kernel.org, linux-iio@vger.kernel.org Cc: Samuel Ortiz , Jonathan Cameron , Dmitry Torokhov , Felipe Balbi , "Patil, Rachna" , Pantelis Antoniou , Sebastian Andrzej Siewior Subject: [PATCH 04/19] input: touchscreen: am335x: Add DT support Date: Mon, 27 May 2013 21:11:51 +0200 Message-Id: <1369681926-22185-5-git-send-email-bigeasy@linutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1369681926-22185-1-git-send-email-bigeasy@linutronix.de> References: <1369681926-22185-1-git-send-email-bigeasy@linutronix.de> X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: "Patil, Rachna" Add DT support for client touchscreen driver [ panto@antoniou-consulting.com : use of_get_child_by_name instead of of_find_node_by_name ] Signed-off-by: Pantelis Antoniou Signed-off-by: Patil, Rachna Signed-off-by: Felipe Balbi [ bigeasy: shift the code to the left ] Signed-off-by: Sebastian Andrzej Siewior --- drivers/input/touchscreen/ti_am335x_tsc.c | 87 ++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c index 064d2b2..be5cb67 100644 --- a/drivers/input/touchscreen/ti_am335x_tsc.c +++ b/drivers/input/touchscreen/ti_am335x_tsc.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include @@ -366,6 +368,67 @@ static irqreturn_t titsc_irq(int irq, void *dev) return IRQ_HANDLED; } +static int titsc_parse_dt(struct ti_tscadc_dev *tscadc_dev, + struct titsc *ts_dev) +{ + struct device_node *node = tscadc_dev->dev->of_node; + int err, i; + u32 val32, wires_conf[4]; + + if (!node) + return -EINVAL; + + node = of_get_child_by_name(node, "tsc"); + if (!node) + return -EINVAL; + err = of_property_read_u32(node, "ti,wires", &val32); + if (err < 0) + goto error_ret; + ts_dev->wires = val32; + + err = of_property_read_u32(node, + "ti,x-plate-resistance", &val32); + if (err < 0) + goto error_ret; + ts_dev->x_plate_resistance = val32; + + err = of_property_read_u32(node, + "ti,steps-to-configure", &val32); + if (err < 0) + goto error_ret; + ts_dev->steps_to_configure = val32; + + err = of_property_read_u32_array(node, "ti,wire-config", + wires_conf, ARRAY_SIZE(wires_conf)); + if (err < 0) + goto error_ret; + + for (i = 0; i < ARRAY_SIZE(wires_conf); i++) + ts_dev->config_inp[i] = wires_conf[i]; + return 0; + +error_ret: + return err; +} + +static int titsc_parse_pdata(struct ti_tscadc_dev *tscadc_dev, + struct titsc *ts_dev) +{ + struct mfd_tscadc_board *pdata = tscadc_dev->dev->platform_data; + + if (!pdata) + return -EINVAL; + + ts_dev->wires = pdata->tsc_init->wires; + ts_dev->x_plate_resistance = + pdata->tsc_init->x_plate_resistance; + ts_dev->steps_to_configure = + pdata->tsc_init->steps_to_configure; + memcpy(ts_dev->config_inp, pdata->tsc_init->wire_config, + sizeof(pdata->tsc_init->wire_config)); + return 0; +} + /* * The functions for inserting/removing driver as a module. */ @@ -375,16 +438,8 @@ static int titsc_probe(struct platform_device *pdev) struct titsc *ts_dev; struct input_dev *input_dev; struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data; - struct mfd_tscadc_board *pdata; int err; - pdata = tscadc_dev->dev->platform_data; - - if (!pdata) { - dev_err(&pdev->dev, "Could not find platform data\n"); - return -EINVAL; - } - /* Allocate memory for device */ ts_dev = kzalloc(sizeof(struct titsc), GFP_KERNEL); input_dev = input_allocate_device(); @@ -398,11 +453,17 @@ static int titsc_probe(struct platform_device *pdev) ts_dev->mfd_tscadc = tscadc_dev; ts_dev->input = input_dev; ts_dev->irq = tscadc_dev->irq; - ts_dev->wires = pdata->tsc_init->wires; - ts_dev->x_plate_resistance = pdata->tsc_init->x_plate_resistance; - ts_dev->steps_to_configure = pdata->tsc_init->steps_to_configure; - memcpy(ts_dev->config_inp, pdata->tsc_init->wire_config, - sizeof(pdata->tsc_init->wire_config)); + + if (tscadc_dev->dev->platform_data) + err = titsc_parse_pdata(tscadc_dev, ts_dev); + else + err = titsc_parse_dt(tscadc_dev, ts_dev); + + if (err) { + dev_err(&pdev->dev, "Could not find platform data\n"); + err = -EINVAL; + goto err_free_mem; + } err = request_irq(ts_dev->irq, titsc_irq, 0, pdev->dev.driver->name, ts_dev);