/**
 * Copyright 2025 Sony Corporation
 */
/**
 * @section LICENSE
 * Copyright (c) 2023 Bosch Sensortec GmbH All Rights Reserved.
 *
 * This software program is licensed subject to the GNU General
 * Public License (GPL).Version 2,June 1991,
 * available at http://www.fsf.org/copyleft/gpl.html
 *
 * @file		bma4xy_driver.h
 * @date		2023-03-06
 * @version		v1.13.0
 *
 * @brief		   The head file of BMA4XY device driver core code
 *
 */
#ifndef _BMA4XY_DRIVER_H
#define _BMA4XY_DRIVER_H

/*********************************************************************/
/* System header files */
/*********************************************************************/

#include <linux/types.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/input.h>
#include <linux/workqueue.h>
#include <linux/slab.h>
#include <linux/firmware.h>
#include "bma4_defs.h"
#include "bma4.h"

/*********************************************************************/
/* Own header files */
/*********************************************************************/
#include "bma456o.h"

/*********************************************************************/
/* Sensor name definition */
/*********************************************************************/
/*! Name of the device driver and accel input device*/
#define SENSOR1_NAME					"bma4xy_acc"
/*! Name of the feature input device 1 */
#define SENSOR1_NAME_FEATURE			"bma4xy_feature"

/*! Name of the device driver and accel input device*/
#define SENSOR2_NAME					"bma4xy_acc_1"
/*! Name of the feature input device 2 */
#define SENSOR2_NAME_FEATURE			"bma4xy_feature_1"

#define BMA456_SET_BITSLICE(regvar, bitname, val) \
	((regvar & ~bitname##_MSK) | \
	((val << bitname##_POS) & bitname##_MSK))


/**\name NVM_PROG POSITION AND MASK*/
#define BMA4_NVM_PROG_EN_POS                       (1)
#define BMA4_NVM_PROG_EN_MSK                       (0x02)

/* Generic */
// #define BMA4XY_ENABLE_INT1				(1)
#define BMA4XY_FIFO_BUFSIZE				1024
#define BMA4XY_FIFO_ACCEL_FRAME_COUNT   100
#define BMA4XY_I2C_WRITE_DELAY_TIME		(1)
#define BMA4XY_MAX_RETRY_I2C_XFER		(10)
#define REL_FEAT_STATUS					(1)
#define REL_HW_STATUS					(2)

#define BMA4_NVM_PROG_CMD				(0xA0)
#define BMA4_NVM_CONF_ADDR				(0x6A)
#define BMA4_CMD_RDY_MSK				(0x10)
#define BMA4_CMD_RDY_POS				(0x04)
#define BMA4_CMD_RDY					(0x10)

struct bma4xy_client_data {
	struct bma4_dev device;
	struct device *dev;
	struct input_dev *acc_input;
	struct input_dev *feat_input;
	u8 acc_fifo_enable;
	u16 fifo_bytecount;
	int IRQ;
	u8 gpio_pin;
	struct work_struct irq_work;
	struct mutex lock;
	char *config_stream_name;
	int reg_sel;
	int reg_len;
	u16 delay_time;
	atomic_t in_suspend;
	u8 trigger_orient_pos;
	u8 selftest;
	u8 orient_en;
	u8 fifo_full_int_en;
	u8 fifo_wm_int_en;
	u8 err_int_en;
	u8 data_rdy_en;
	u8 sensor_init;
	u8 device_id;

#ifdef SONY_BMA456_SUSRES_RESTORE
	// for parameter restore
	struct bma4_accel_config acc_config;
#endif // SONY_BMA456_SUSRES_RESTORE
};

/**
 * bma4xy_probe - This is the probe function for bma4xy sensor.
 * Called from the I2C driver probe function to initialize the sensor.
 *
 * @client_data : Structure instance of client data.
 * @dev : Structure instance of device.
 *
 * Return : Result of execution status
 * * 0 - Success
 * * negative value -> Error
 */
int bma4xy_probe(struct bma4xy_client_data *client_data, struct device *dev);

/**
 * bma4xy_remove - This function removes the driver from the device.
 *
 * @dev : Structure instance of device.
 *
 * Return : Result of execution status
 * * 0 - Success
 * * negative value -> Error
 */
int bma4xy_remove(struct device *dev);

#ifdef SONY_BMA456_SUSRES_RESTORE
int sony_sensor_init(struct device *dev);
int sony_set_acc_op_mode(struct device *dev);
int sony_set_acc_config(struct device *dev);
#endif // SONY_BMA456_SUSRES_RESTORE

#endif
