Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1904787lqb; Mon, 27 May 2024 01:02:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWDgV1rhe4tQYi4vxLjKNvK5Ep6hohjkbf1f6/1FDA3w2uvH+tlZnks1j4DEXyOFPmu0juwcBLW6cwFQeVXUGRgwC1Bv22H3hZNbuSsA== X-Google-Smtp-Source: AGHT+IHB1b1OvVvqRPH9j8jyk2AlU1Zk+EWLwk4N4c46vh49El5CgtDb0rArXJrdCbetuGd5ZIvX X-Received: by 2002:a17:902:6504:b0:1f4:9468:38b0 with SMTP id d9443c01a7336-1f4946839e6mr19253095ad.61.1716796956121; Mon, 27 May 2024 01:02:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716796956; cv=pass; d=google.com; s=arc-20160816; b=ET03NyYNO0qTkmZNuV5CYYLLheNYNHUnQ0i9MzFpn6FFa2xLrTFhK2dRcIlTHvkRwp rQiCipDdjeAJkNEhs3XFGgyPCw9BEnKsjtZ+78Shjo6lj2B/4NChfVFsdwicaWgW44Fl g2wX2iCWokqK6Njw8eu9yTwXSmb4lNqv2TmsLGkLW9QlyP6p7WU4i70/09uoqDDeEV/k /ijsSyj+sa5eo3ocHk2/ioEggLgsPo/qXx+wmx3/8nkXkK81DXnkttPfvT+t6PdgS2yT m8PtqaF98zqwCQ6x8rvwHiVdzS955Ft7Z35WJQl093EHYms+E6HmWeGlnjZsf59CCYp0 WGLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=eMc9oQ4YVYpAx8gh5q0mqb2/rcNUyELqBXOxKDT4IhA=; fh=4n1H3xYhSE3rbDRCxWiC7a8pPZQXla3wwChGvSAUqu0=; b=z/P68qP5TOLt7KknwZm6AkaaYwgDrJpob8VLBAdBOxBkrOYtx9ph3AA+d7p/QO8Y1M 3CWzemnzWx1cU2Wj0KoQhmRAUHw6ht8Csmw4scux7po/rvbOhEDeJbqdD8XdVBFZoqKZ +WNylwaYKe6GLsAlKjAcBa5brU2RRb+H2xS8O83E+5a0w4LhBkhAl3cKuDVvi3hWAgp9 mrqikLPRqAneaMTnYpcTi47AW7tjdZNK4/9sgMNihCdELJaN80Vl8fRU2hoYfoSXnLQ/ Bbjw04Mld1hJ37C3ncFe9vU9HoyKEOTs+CTaMcDsN8WkKtpDNZJP2sgbUPoaacpfvSM+ hRuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@packett.cool header.s=key1 header.b=glRPCfaZ; arc=pass (i=1 spf=pass spfdomain=packett.cool dkim=pass dkdomain=packett.cool dmarc=pass fromdomain=packett.cool); spf=pass (google.com: domain of linux-kernel+bounces-190184-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190184-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=packett.cool Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f4ac254515si6941905ad.465.2024.05.27.01.02.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 01:02:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190184-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@packett.cool header.s=key1 header.b=glRPCfaZ; arc=pass (i=1 spf=pass spfdomain=packett.cool dkim=pass dkdomain=packett.cool dmarc=pass fromdomain=packett.cool); spf=pass (google.com: domain of linux-kernel+bounces-190184-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190184-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=packett.cool Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D35C9B20FBA for ; Mon, 27 May 2024 08:01:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00BC13B1A2; Mon, 27 May 2024 08:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=packett.cool header.i=@packett.cool header.b="glRPCfaZ" Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB2594594D for ; Mon, 27 May 2024 08:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716796907; cv=none; b=Do2mtFBgeUYL7i58Etpqbck6Axl3r/pEEi50MIEJvWiepf0PNWJklLoYo+8yysx+gYHX52i8od9tZlMhvBJwQfQsDxoUldd+cSzXyWfO8ACe3r4aqWoUX8I+yaWXGuDOVne9VUCyWAQu2JlGPtk/upbWd6gy7FwkuFKThmqRTVE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716796907; c=relaxed/simple; bh=Jkpr43X/qDFxJGmKqmQgShXrBkBVcEw/3bJPwmjpF7Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=P1yTW8888gSMM8ZKlMOaZTDsDPv8DpZU/AiKUZe4IePuUlGFAuygsZbYF1nk2e/JGWotkJ5rwY7T2t2RBpOGa/zxLYBxLWWuvE7E7QWcMQJSe+SC/eK0M+OnoJoZLoYLTvNs6gePq/zuQC7CPzKiDgjdeGCnjZKQH1m3lm7aumw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=packett.cool; spf=pass smtp.mailfrom=packett.cool; dkim=pass (2048-bit key) header.d=packett.cool header.i=@packett.cool header.b=glRPCfaZ; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=packett.cool Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=packett.cool X-Envelope-To: val@packett.cool DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=packett.cool; s=key1; t=1716796901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=eMc9oQ4YVYpAx8gh5q0mqb2/rcNUyELqBXOxKDT4IhA=; b=glRPCfaZfsOQk2KMlum9Ys/c4ChI8IwVLsJNQknIDDSL9PnDCpjjeDtaJddOebaIYhpOYa oup6lF4RomW3VH/pX8fFHODKQHMEASOv9awbgimT88yAndaMKXLoaXIuTps3iO0RoogLqU ENBT8geFuYNp8PtI2qDeMDraUTHUSTJviDv6+bKfV9pXAIR8x5ey54+4eQsbz3YFHhWyw4 NoZKFTS8Z1DqbLGUqlKiNdYF3KrFDteqlBVu+Fayj08F2VwEgIqDDyn+U2aNPCW1BXD1Mj myVpATMESHA+nXhQjYzCb/65azOOXRpzyr2MCASdj0pyRi5A7tQCK1lm2n0L9g== X-Envelope-To: jic23@kernel.org X-Envelope-To: lars@metafoo.de X-Envelope-To: sfr@canb.auug.org.au X-Envelope-To: linux-iio@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Val Packett To: Cc: Val Packett , Jonathan Cameron , Lars-Peter Clausen , Stephen Rothwell , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: accel: mma7660: add mount-matrix support Date: Mon, 27 May 2024 05:00:18 -0300 Message-ID: <20240527080043.2709-1-val@packett.cool> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Allow using the mount-matrix device tree property to align the accelerometer relative to the whole device. Signed-off-by: Val Packett --- drivers/iio/accel/mma7660.c | 50 ++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/drivers/iio/accel/mma7660.c b/drivers/iio/accel/mma7660.c index 260cbceaa..9d23f28d5 100644 --- a/drivers/iio/accel/mma7660.c +++ b/drivers/iio/accel/mma7660.c @@ -38,21 +38,6 @@ static const int mma7660_nscale = 467142857; -#define MMA7660_CHANNEL(reg, axis) { \ - .type = IIO_ACCEL, \ - .address = reg, \ - .modified = 1, \ - .channel2 = IIO_MOD_##axis, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ -} - -static const struct iio_chan_spec mma7660_channels[] = { - MMA7660_CHANNEL(MMA7660_REG_XOUT, X), - MMA7660_CHANNEL(MMA7660_REG_YOUT, Y), - MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z), -}; - enum mma7660_mode { MMA7660_MODE_STANDBY, MMA7660_MODE_ACTIVE @@ -62,6 +47,21 @@ struct mma7660_data { struct i2c_client *client; struct mutex lock; enum mma7660_mode mode; + struct iio_mount_matrix orientation; +}; + +static const struct iio_mount_matrix * +mma7660_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct mma7660_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info mma7660_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, mma7660_get_mount_matrix), + { } }; static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL); @@ -75,6 +75,22 @@ static const struct attribute_group mma7660_attribute_group = { .attrs = mma7660_attributes }; +#define MMA7660_CHANNEL(reg, axis) { \ + .type = IIO_ACCEL, \ + .address = reg, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .ext_info = mma7660_ext_info, \ +} + +static const struct iio_chan_spec mma7660_channels[] = { + MMA7660_CHANNEL(MMA7660_REG_XOUT, X), + MMA7660_CHANNEL(MMA7660_REG_YOUT, Y), + MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z), +}; + static int mma7660_set_mode(struct mma7660_data *data, enum mma7660_mode mode) { @@ -187,6 +203,10 @@ static int mma7660_probe(struct i2c_client *client) mutex_init(&data->lock); data->mode = MMA7660_MODE_STANDBY; + ret = iio_read_mount_matrix(&client->dev, &data->orientation); + if (ret) + return ret; + indio_dev->info = &mma7660_info; indio_dev->name = MMA7660_DRIVER_NAME; indio_dev->modes = INDIO_DIRECT_MODE; -- 2.45.1