/*	$NetBSD: bmx280var.h,v 1.3 2025/09/13 16:16:40 thorpej Exp $	*/

/*
 * Copyright (c) 2022 Brad Spencer <brad@anduin.eldar.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _DEV_IC_BMX280VAR_H_
#define _DEV_IC_BMX280VAR_H_

#define BMX280_NUM_SENSORS	3
#define BMX280_TEMP_SENSOR 0
#define BMX280_PRESSURE_SENSOR 1
#define BMX280_HUMIDITY_SENSOR 2

struct bmx280_calibration_blob {
	uint16_t dig_T1;
	int16_t dig_T2;
	int16_t dig_T3;

	uint16_t dig_P1;
	int16_t dig_P2;
	int16_t dig_P3;
	int16_t dig_P4;
	int16_t dig_P5;
	int16_t dig_P6;
	int16_t dig_P7;
	int16_t dig_P8;
	int16_t dig_P9;
	uint8_t dig_H1;
	int16_t dig_H2;
	uint8_t dig_H3;
	int16_t dig_H4;
	int16_t dig_H5;
	int8_t dig_H6;
};

struct bmx280_sc;

struct bmx280_accessfuncs {
	int		(*acquire_bus)(struct bmx280_sc *);
	void		(*release_bus)(struct bmx280_sc *);
	int		(*read_reg)(struct bmx280_sc *, uint8_t, uint8_t *,
			    size_t);
	int		(*write_reg)(struct bmx280_sc *, uint8_t *, size_t);
};

struct bmx280_sc {
	int 		sc_bmx280debug;
	device_t 	sc_dev;
	const struct bmx280_accessfuncs *sc_funcs;

	kmutex_t 	sc_mutex;
	int 		sc_numsensors;
	struct sysmon_envsys *sc_sme;
	struct sysctllog *sc_bmx280log;
	envsys_data_t 	sc_sensors[BMX280_NUM_SENSORS];
	struct bmx280_calibration_blob	sc_cal_blob;
	bool		sc_has_humidity;
	int		sc_readattempts;
	int		sc_osrs_t;
	int		sc_osrs_p;
	int		sc_osrs_h;
	int		sc_irr_samples;
	uint8_t		sc_previous_irr;
	bool		sc_bmx280dump;
	int		sc_waitfactor_t;
	int		sc_waitfactor_p;
	int		sc_waitfactor_h;
};

struct bmx280_sensor {
	const char     *desc;
	enum envsys_units type;
};

struct bmx280_osrs_list {
	const int	text;
	uint8_t		mask;
};

struct bmx280_irr_list {
	const int	text;
	uint8_t		mask;
};

extern const struct device_compatible_entry bmx280_compat_data[];

void	bmx280_attach(struct bmx280_sc *);
int	bmx280_detach(struct bmx280_sc *, int);

#endif
