brintos

brintos / linux-shallow public Read only

0
0
Text · 1.8 KiB · f798b96 Raw
69 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/*3 * Copyright (C) 2022 ROHM Semiconductors4 *5 * ROHM/KIONIX accelerometer driver6 */7 8#include <linux/interrupt.h>9#include <linux/module.h>10#include <linux/regmap.h>11#include <linux/spi/spi.h>12 13#include "kionix-kx022a.h"14 15static int kx022a_spi_probe(struct spi_device *spi)16{17	struct device *dev = &spi->dev;18	const struct kx022a_chip_info *chip_info;19	struct regmap *regmap;20 21	if (!spi->irq) {22		dev_err(dev, "No IRQ configured\n");23		return -EINVAL;24	}25 26	chip_info = spi_get_device_match_data(spi);27	if (!chip_info)28		return -EINVAL;29 30	regmap = devm_regmap_init_spi(spi, chip_info->regmap_config);31	if (IS_ERR(regmap))32		return dev_err_probe(dev, PTR_ERR(regmap),33				     "Failed to initialize Regmap\n");34 35	return kx022a_probe_internal(dev, chip_info);36}37 38static const struct spi_device_id kx022a_id[] = {39	{ .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info },40	{ .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info },41	{ .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },42	{ }43};44MODULE_DEVICE_TABLE(spi, kx022a_id);45 46static const struct of_device_id kx022a_of_match[] = {47	{ .compatible = "kionix,kx022a", .data = &kx022a_chip_info },48	{ .compatible = "kionix,kx132-1211", .data = &kx132_chip_info },49	{ .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },50	{ }51};52MODULE_DEVICE_TABLE(of, kx022a_of_match);53 54static struct spi_driver kx022a_spi_driver = {55	.driver = {56		.name   = "kx022a-spi",57		.of_match_table = kx022a_of_match,58		.probe_type = PROBE_PREFER_ASYNCHRONOUS,59	},60	.probe = kx022a_spi_probe,61	.id_table = kx022a_id,62};63module_spi_driver(kx022a_spi_driver);64 65MODULE_DESCRIPTION("ROHM/Kionix kx022A accelerometer driver");66MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");67MODULE_LICENSE("GPL");68MODULE_IMPORT_NS(IIO_KX022A);69