linux/drivers/iio/magnetometer/mmc35240.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * MMC35240 - MEMSIC 3-axis Magnetic Sensor
 *
 * Copyright (c) 2015, Intel Corporation.
 *
 * IIO driver for MMC35240 (7-bit I2C slave address 0x30).
 *
 * TODO: offset, ACPI, continuous measurement mode, PM
 */

#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/regmap.h>
#include <linux/pm.h>

#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>

#define MMC35240_DRV_NAME
#define MMC35240_REGMAP_NAME

#define MMC35240_REG_XOUT_L
#define MMC35240_REG_XOUT_H
#define MMC35240_REG_YOUT_L
#define MMC35240_REG_YOUT_H
#define MMC35240_REG_ZOUT_L
#define MMC35240_REG_ZOUT_H

#define MMC35240_REG_STATUS
#define MMC35240_REG_CTRL0
#define MMC35240_REG_CTRL1

#define MMC35240_REG_ID

#define MMC35240_STATUS_MEAS_DONE_BIT

#define MMC35240_CTRL0_REFILL_BIT
#define MMC35240_CTRL0_RESET_BIT
#define MMC35240_CTRL0_SET_BIT
#define MMC35240_CTRL0_CMM_BIT
#define MMC35240_CTRL0_TM_BIT

/* output resolution bits */
#define MMC35240_CTRL1_BW0_BIT
#define MMC35240_CTRL1_BW1_BIT

#define MMC35240_CTRL1_BW_MASK
#define MMC35240_CTRL1_BW_SHIFT

#define MMC35240_WAIT_CHARGE_PUMP
#define MMC35240_WAIT_SET_RESET

/*
 * Memsic OTP process code piece is put here for reference:
 *
 * #define OTP_CONVERT(REG)  ((float)((REG) >=32 ? (32 - (REG)) : (REG)) * 0.006
 * 1) For X axis, the COEFFICIENT is always 1.
 * 2) For Y axis, the COEFFICIENT is as below:
 *    f_OTP_matrix[4] = OTP_CONVERT(((reg_data[1] & 0x03) << 4) |
 *                                   (reg_data[2] >> 4)) + 1.0;
 * 3) For Z axis, the COEFFICIENT is as below:
 *    f_OTP_matrix[8] = (OTP_CONVERT(reg_data[3] & 0x3f) + 1) * 1.35;
 * We implemented the OTP logic into driver.
 */

/* scale = 1000 here for Y otp */
#define MMC35240_OTP_CONVERT_Y(REG)

/* 0.6 * 1.35 = 0.81, scale 10000 for Z otp */
#define MMC35240_OTP_CONVERT_Z(REG)

#define MMC35240_X_COEFF(x)
#define MMC35240_Y_COEFF(y)
#define MMC35240_Z_COEFF(z)

#define MMC35240_OTP_START_ADDR

enum mmc35240_resolution {};

enum mmc35240_axis {};

static const struct {} mmc35240_props_table[] =;

struct mmc35240_data {};

static const struct {} mmc35240_samp_freq[] =;

static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("1.5 13 25 50");

#define MMC35240_CHANNEL(_axis)

static const struct iio_chan_spec mmc35240_channels[] =;

static struct attribute *mmc35240_attributes[] =;

static const struct attribute_group mmc35240_attribute_group =;

static int mmc35240_get_samp_freq_index(struct mmc35240_data *data,
					int val, int val2)
{}

static int mmc35240_hw_set(struct mmc35240_data *data, bool set)
{}

static int mmc35240_init(struct mmc35240_data *data)
{}

static int mmc35240_take_measurement(struct mmc35240_data *data)
{}

static int mmc35240_read_measurement(struct mmc35240_data *data, __le16 buf[3])
{}

/**
 * mmc35240_raw_to_mgauss - convert raw readings to milli gauss. Also apply
 *			    compensation for output value.
 *
 * @data: device private data
 * @index: axis index for which we want the conversion
 * @buf: raw data to be converted, 2 bytes in little endian format
 * @val: compensated output reading (unit is milli gauss)
 *
 * Returns: 0 in case of success, -EINVAL when @index is not valid
 */
static int mmc35240_raw_to_mgauss(struct mmc35240_data *data, int index,
				  __le16 buf[], int *val)
{}

static int mmc35240_read_raw(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan, int *val,
			     int *val2, long mask)
{}

static int mmc35240_write_raw(struct iio_dev *indio_dev,
			      struct iio_chan_spec const *chan, int val,
			      int val2, long mask)
{}

static const struct iio_info mmc35240_info =;

static bool mmc35240_is_writeable_reg(struct device *dev, unsigned int reg)
{}

static bool mmc35240_is_readable_reg(struct device *dev, unsigned int reg)
{}

static bool mmc35240_is_volatile_reg(struct device *dev, unsigned int reg)
{}

static const struct reg_default mmc35240_reg_defaults[] =;

static const struct regmap_config mmc35240_regmap_config =;

static int mmc35240_probe(struct i2c_client *client)
{}

static int mmc35240_suspend(struct device *dev)
{}

static int mmc35240_resume(struct device *dev)
{}

static DEFINE_SIMPLE_DEV_PM_OPS(mmc35240_pm_ops, mmc35240_suspend,
				mmc35240_resume);

static const struct of_device_id mmc35240_of_match[] =;
MODULE_DEVICE_TABLE(of, mmc35240_of_match);

static const struct acpi_device_id mmc35240_acpi_match[] =;
MODULE_DEVICE_TABLE(acpi, mmc35240_acpi_match);

static const struct i2c_device_id mmc35240_id[] =;
MODULE_DEVICE_TABLE(i2c, mmc35240_id);

static struct i2c_driver mmc35240_driver =;

module_i2c_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();