From patchwork Tue Oct 17 10:42:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 10011637 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 6E8CE60235 for ; Tue, 17 Oct 2017 10:43:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61FA628845 for ; Tue, 17 Oct 2017 10:43:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 565E028847; Tue, 17 Oct 2017 10:43:07 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEBA628845 for ; Tue, 17 Oct 2017 10:43:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756311AbdJQKnG (ORCPT ); Tue, 17 Oct 2017 06:43:06 -0400 Received: from mailout2.hostsharing.net ([83.223.90.233]:48511 "EHLO mailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757656AbdJQKnG (ORCPT ); Tue, 17 Oct 2017 06:43:06 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Organization Validation Secure Server CA" (not verified)) by mailout2.hostsharing.net (Postfix) with ESMTPS id 5DF9E10189B74; Tue, 17 Oct 2017 12:43:04 +0200 (CEST) Received: from localhost (p4FC97DB7.dip0.t-ipconnect.de [79.201.125.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id EA01D603DFA9; Tue, 17 Oct 2017 12:43:03 +0200 (CEST) X-Mailbox-Line: From 43bd5525f1db09764a40f4e225a772b30603c3f5 Mon Sep 17 00:00:00 2001 Message-Id: <43bd5525f1db09764a40f4e225a772b30603c3f5.1508232186.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Tue, 17 Oct 2017 12:42:00 +0200 Subject: [PATCH v2 3/3] iio: dac: ti-dac082s085: Read chip spec from device table To: Jonathan Cameron Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mathias Duckeck , Phil Elwell , linux-iio@vger.kernel.org Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The two properties unique to each supported chip, resolution and number of channels, are currently gleaned from the chip's name. E.g. dac102s085 is a dual channel 10-bit DAC. ^^^ This was deemed unmaintainable by the subsystem maintainer once the driver is extended to support further chips, hence it was requested to add an explicit table for chip-specific information and use an enum to reference into it. This adds 17 LoC without any immediate gain, so make the change in a separate commit which can be reverted if we determine in 10 years that it was unnecessary. Signed-off-by: Lukas Wunner --- drivers/iio/dac/ti-dac082s085.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/iio/dac/ti-dac082s085.c b/drivers/iio/dac/ti-dac082s085.c index 0fefb110be69..2c1556f32574 100644 --- a/drivers/iio/dac/ti-dac082s085.c +++ b/drivers/iio/dac/ti-dac082s085.c @@ -20,6 +20,22 @@ #include #include +enum { dual_8bit, dual_10bit, dual_12bit, quad_8bit, quad_10bit, quad_12bit }; + +struct ti_dac_spec { + u8 num_channels; + u8 resolution; +}; + +static const struct ti_dac_spec ti_dac_spec[] = { + [dual_8bit] = { .num_channels = 2, .resolution = 8 }, + [dual_10bit] = { .num_channels = 2, .resolution = 10 }, + [dual_12bit] = { .num_channels = 2, .resolution = 12 }, + [quad_8bit] = { .num_channels = 4, .resolution = 8 }, + [quad_10bit] = { .num_channels = 4, .resolution = 10 }, + [quad_12bit] = { .num_channels = 4, .resolution = 12 }, +}; + /** * struct ti_dac_chip - TI DAC chip * @lock: protects write sequences @@ -246,6 +262,7 @@ static const struct iio_info ti_dac_info = { static int ti_dac_probe(struct spi_device *spi) { struct device *dev = &spi->dev; + const struct ti_dac_spec *spec; struct ti_dac_chip *ti_dac; struct iio_dev *indio_dev; int ret; @@ -267,9 +284,9 @@ static int ti_dac_probe(struct spi_device *spi) spi_message_init_with_transfers(&ti_dac->mesg, &ti_dac->xfer, 1); ti_dac->mesg.spi = spi; - ret = sscanf(spi->modalias, "dac%2hhu%1d", - &ti_dac->resolution, &indio_dev->num_channels); - WARN_ON(ret != 2); + spec = &ti_dac_spec[spi_get_device_id(spi)->driver_data]; + indio_dev->num_channels = spec->num_channels; + ti_dac->resolution = spec->resolution; ti_dac->vref = devm_regulator_get(dev, "vref"); if (IS_ERR(ti_dac->vref)) @@ -325,12 +342,12 @@ MODULE_DEVICE_TABLE(of, ti_dac_of_id); #endif static const struct spi_device_id ti_dac_spi_id[] = { - { "dac082s085" }, - { "dac102s085" }, - { "dac122s085" }, - { "dac084s085" }, - { "dac104s085" }, - { "dac124s085" }, + { "dac082s085", dual_8bit }, + { "dac102s085", dual_10bit }, + { "dac122s085", dual_12bit }, + { "dac084s085", quad_8bit }, + { "dac104s085", quad_10bit }, + { "dac124s085", quad_12bit }, { } }; MODULE_DEVICE_TABLE(spi, ti_dac_spi_id);