162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * 1-Wire implementation for the ds2780 chip
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Author: Renata Sayakhova <renata@oktetlabs.ru>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Based on w1-ds2760 driver
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _W1_DS2781_H
1162306a36Sopenharmony_ci#define _W1_DS2781_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* Function commands */
1462306a36Sopenharmony_ci#define W1_DS2781_READ_DATA		0x69
1562306a36Sopenharmony_ci#define W1_DS2781_WRITE_DATA		0x6C
1662306a36Sopenharmony_ci#define W1_DS2781_COPY_DATA		0x48
1762306a36Sopenharmony_ci#define W1_DS2781_RECALL_DATA		0xB8
1862306a36Sopenharmony_ci#define W1_DS2781_LOCK			0x6A
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* Register map */
2162306a36Sopenharmony_ci/* Register 0x00 Reserved */
2262306a36Sopenharmony_ci#define DS2781_STATUS			0x01
2362306a36Sopenharmony_ci#define DS2781_RAAC_MSB			0x02
2462306a36Sopenharmony_ci#define DS2781_RAAC_LSB			0x03
2562306a36Sopenharmony_ci#define DS2781_RSAC_MSB			0x04
2662306a36Sopenharmony_ci#define DS2781_RSAC_LSB			0x05
2762306a36Sopenharmony_ci#define DS2781_RARC			0x06
2862306a36Sopenharmony_ci#define DS2781_RSRC			0x07
2962306a36Sopenharmony_ci#define DS2781_IAVG_MSB			0x08
3062306a36Sopenharmony_ci#define DS2781_IAVG_LSB			0x09
3162306a36Sopenharmony_ci#define DS2781_TEMP_MSB			0x0A
3262306a36Sopenharmony_ci#define DS2781_TEMP_LSB			0x0B
3362306a36Sopenharmony_ci#define DS2781_VOLT_MSB			0x0C
3462306a36Sopenharmony_ci#define DS2781_VOLT_LSB			0x0D
3562306a36Sopenharmony_ci#define DS2781_CURRENT_MSB		0x0E
3662306a36Sopenharmony_ci#define DS2781_CURRENT_LSB		0x0F
3762306a36Sopenharmony_ci#define DS2781_ACR_MSB			0x10
3862306a36Sopenharmony_ci#define DS2781_ACR_LSB			0x11
3962306a36Sopenharmony_ci#define DS2781_ACRL_MSB			0x12
4062306a36Sopenharmony_ci#define DS2781_ACRL_LSB			0x13
4162306a36Sopenharmony_ci#define DS2781_AS			0x14
4262306a36Sopenharmony_ci#define DS2781_SFR			0x15
4362306a36Sopenharmony_ci#define DS2781_FULL_MSB			0x16
4462306a36Sopenharmony_ci#define DS2781_FULL_LSB			0x17
4562306a36Sopenharmony_ci#define DS2781_AE_MSB			0x18
4662306a36Sopenharmony_ci#define DS2781_AE_LSB			0x19
4762306a36Sopenharmony_ci#define DS2781_SE_MSB			0x1A
4862306a36Sopenharmony_ci#define DS2781_SE_LSB			0x1B
4962306a36Sopenharmony_ci/* Register 0x1C - 0x1E Reserved */
5062306a36Sopenharmony_ci#define DS2781_EEPROM		0x1F
5162306a36Sopenharmony_ci#define DS2781_EEPROM_BLOCK0_START	0x20
5262306a36Sopenharmony_ci/* Register 0x20 - 0x2F User EEPROM */
5362306a36Sopenharmony_ci#define DS2781_EEPROM_BLOCK0_END	0x2F
5462306a36Sopenharmony_ci/* Register 0x30 - 0x5F Reserved */
5562306a36Sopenharmony_ci#define DS2781_EEPROM_BLOCK1_START	0x60
5662306a36Sopenharmony_ci#define DS2781_CONTROL			0x60
5762306a36Sopenharmony_ci#define DS2781_AB			0x61
5862306a36Sopenharmony_ci#define DS2781_AC_MSB			0x62
5962306a36Sopenharmony_ci#define DS2781_AC_LSB			0x63
6062306a36Sopenharmony_ci#define DS2781_VCHG			0x64
6162306a36Sopenharmony_ci#define DS2781_IMIN			0x65
6262306a36Sopenharmony_ci#define DS2781_VAE			0x66
6362306a36Sopenharmony_ci#define DS2781_IAE			0x67
6462306a36Sopenharmony_ci#define DS2781_AE_40			0x68
6562306a36Sopenharmony_ci#define DS2781_RSNSP			0x69
6662306a36Sopenharmony_ci#define DS2781_FULL_40_MSB		0x6A
6762306a36Sopenharmony_ci#define DS2781_FULL_40_LSB		0x6B
6862306a36Sopenharmony_ci#define DS2781_FULL_4_SLOPE		0x6C
6962306a36Sopenharmony_ci#define DS2781_FULL_3_SLOPE		0x6D
7062306a36Sopenharmony_ci#define DS2781_FULL_2_SLOPE		0x6E
7162306a36Sopenharmony_ci#define DS2781_FULL_1_SLOPE		0x6F
7262306a36Sopenharmony_ci#define DS2781_AE_4_SLOPE		0x70
7362306a36Sopenharmony_ci#define DS2781_AE_3_SLOPE		0x71
7462306a36Sopenharmony_ci#define DS2781_AE_2_SLOPE		0x72
7562306a36Sopenharmony_ci#define DS2781_AE_1_SLOPE		0x73
7662306a36Sopenharmony_ci#define DS2781_SE_4_SLOPE		0x74
7762306a36Sopenharmony_ci#define DS2781_SE_3_SLOPE		0x75
7862306a36Sopenharmony_ci#define DS2781_SE_2_SLOPE		0x76
7962306a36Sopenharmony_ci#define DS2781_SE_1_SLOPE		0x77
8062306a36Sopenharmony_ci#define DS2781_RSGAIN_MSB		0x78
8162306a36Sopenharmony_ci#define DS2781_RSGAIN_LSB		0x79
8262306a36Sopenharmony_ci#define DS2781_RSTC			0x7A
8362306a36Sopenharmony_ci#define DS2781_COB			0x7B
8462306a36Sopenharmony_ci#define DS2781_TBP34			0x7C
8562306a36Sopenharmony_ci#define DS2781_TBP23			0x7D
8662306a36Sopenharmony_ci#define DS2781_TBP12			0x7E
8762306a36Sopenharmony_ci#define DS2781_EEPROM_BLOCK1_END	0x7F
8862306a36Sopenharmony_ci/* Register 0x7D - 0xFF Reserved */
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define DS2781_FSGAIN_MSB		0xB0
9162306a36Sopenharmony_ci#define DS2781_FSGAIN_LSB		0xB1
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* Number of valid register addresses */
9462306a36Sopenharmony_ci#define DS2781_DATA_SIZE		0xB2
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/* Status register bits */
9762306a36Sopenharmony_ci#define DS2781_STATUS_CHGTF		(1 << 7)
9862306a36Sopenharmony_ci#define DS2781_STATUS_AEF		(1 << 6)
9962306a36Sopenharmony_ci#define DS2781_STATUS_SEF		(1 << 5)
10062306a36Sopenharmony_ci#define DS2781_STATUS_LEARNF		(1 << 4)
10162306a36Sopenharmony_ci/* Bit 3 Reserved */
10262306a36Sopenharmony_ci#define DS2781_STATUS_UVF		(1 << 2)
10362306a36Sopenharmony_ci#define DS2781_STATUS_PORF		(1 << 1)
10462306a36Sopenharmony_ci/* Bit 0 Reserved */
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* Control register bits */
10762306a36Sopenharmony_ci/* Bit 7 Reserved */
10862306a36Sopenharmony_ci#define DS2781_CONTROL_NBEN		(1 << 7)
10962306a36Sopenharmony_ci#define DS2781_CONTROL_UVEN		(1 << 6)
11062306a36Sopenharmony_ci#define DS2781_CONTROL_PMOD		(1 << 5)
11162306a36Sopenharmony_ci#define DS2781_CONTROL_RNAOP		(1 << 4)
11262306a36Sopenharmony_ci#define DS1781_CONTROL_UVTH		(1 << 3)
11362306a36Sopenharmony_ci/* Bit 0 - 2 Reserved */
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci/* Special feature register bits */
11662306a36Sopenharmony_ci/* Bit 1 - 7 Reserved */
11762306a36Sopenharmony_ci#define DS2781_SFR_PIOSC		(1 << 0)
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci/* EEPROM register bits */
12062306a36Sopenharmony_ci#define DS2781_EEPROM_EEC		(1 << 7)
12162306a36Sopenharmony_ci#define DS2781_EEPROM_LOCK		(1 << 6)
12262306a36Sopenharmony_ci/* Bit 2 - 6 Reserved */
12362306a36Sopenharmony_ci#define DS2781_EEPROM_BL1		(1 << 1)
12462306a36Sopenharmony_ci#define DS2781_EEPROM_BL0		(1 << 0)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciextern int w1_ds2781_io(struct device *dev, char *buf, int addr, size_t count,
12762306a36Sopenharmony_ci			int io);
12862306a36Sopenharmony_ciextern int w1_ds2781_eeprom_cmd(struct device *dev, int addr, int cmd);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#endif /* !_W1_DS2781_H */
131