18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * 1-Wire implementation for the ds2780 chip
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Author: Renata Sayakhova <renata@oktetlabs.ru>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Based on w1-ds2760 driver
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _W1_DS2781_H
118c2ecf20Sopenharmony_ci#define _W1_DS2781_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Function commands */
148c2ecf20Sopenharmony_ci#define W1_DS2781_READ_DATA		0x69
158c2ecf20Sopenharmony_ci#define W1_DS2781_WRITE_DATA		0x6C
168c2ecf20Sopenharmony_ci#define W1_DS2781_COPY_DATA		0x48
178c2ecf20Sopenharmony_ci#define W1_DS2781_RECALL_DATA		0xB8
188c2ecf20Sopenharmony_ci#define W1_DS2781_LOCK			0x6A
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Register map */
218c2ecf20Sopenharmony_ci/* Register 0x00 Reserved */
228c2ecf20Sopenharmony_ci#define DS2781_STATUS			0x01
238c2ecf20Sopenharmony_ci#define DS2781_RAAC_MSB			0x02
248c2ecf20Sopenharmony_ci#define DS2781_RAAC_LSB			0x03
258c2ecf20Sopenharmony_ci#define DS2781_RSAC_MSB			0x04
268c2ecf20Sopenharmony_ci#define DS2781_RSAC_LSB			0x05
278c2ecf20Sopenharmony_ci#define DS2781_RARC			0x06
288c2ecf20Sopenharmony_ci#define DS2781_RSRC			0x07
298c2ecf20Sopenharmony_ci#define DS2781_IAVG_MSB			0x08
308c2ecf20Sopenharmony_ci#define DS2781_IAVG_LSB			0x09
318c2ecf20Sopenharmony_ci#define DS2781_TEMP_MSB			0x0A
328c2ecf20Sopenharmony_ci#define DS2781_TEMP_LSB			0x0B
338c2ecf20Sopenharmony_ci#define DS2781_VOLT_MSB			0x0C
348c2ecf20Sopenharmony_ci#define DS2781_VOLT_LSB			0x0D
358c2ecf20Sopenharmony_ci#define DS2781_CURRENT_MSB		0x0E
368c2ecf20Sopenharmony_ci#define DS2781_CURRENT_LSB		0x0F
378c2ecf20Sopenharmony_ci#define DS2781_ACR_MSB			0x10
388c2ecf20Sopenharmony_ci#define DS2781_ACR_LSB			0x11
398c2ecf20Sopenharmony_ci#define DS2781_ACRL_MSB			0x12
408c2ecf20Sopenharmony_ci#define DS2781_ACRL_LSB			0x13
418c2ecf20Sopenharmony_ci#define DS2781_AS			0x14
428c2ecf20Sopenharmony_ci#define DS2781_SFR			0x15
438c2ecf20Sopenharmony_ci#define DS2781_FULL_MSB			0x16
448c2ecf20Sopenharmony_ci#define DS2781_FULL_LSB			0x17
458c2ecf20Sopenharmony_ci#define DS2781_AE_MSB			0x18
468c2ecf20Sopenharmony_ci#define DS2781_AE_LSB			0x19
478c2ecf20Sopenharmony_ci#define DS2781_SE_MSB			0x1A
488c2ecf20Sopenharmony_ci#define DS2781_SE_LSB			0x1B
498c2ecf20Sopenharmony_ci/* Register 0x1C - 0x1E Reserved */
508c2ecf20Sopenharmony_ci#define DS2781_EEPROM		0x1F
518c2ecf20Sopenharmony_ci#define DS2781_EEPROM_BLOCK0_START	0x20
528c2ecf20Sopenharmony_ci/* Register 0x20 - 0x2F User EEPROM */
538c2ecf20Sopenharmony_ci#define DS2781_EEPROM_BLOCK0_END	0x2F
548c2ecf20Sopenharmony_ci/* Register 0x30 - 0x5F Reserved */
558c2ecf20Sopenharmony_ci#define DS2781_EEPROM_BLOCK1_START	0x60
568c2ecf20Sopenharmony_ci#define DS2781_CONTROL			0x60
578c2ecf20Sopenharmony_ci#define DS2781_AB			0x61
588c2ecf20Sopenharmony_ci#define DS2781_AC_MSB			0x62
598c2ecf20Sopenharmony_ci#define DS2781_AC_LSB			0x63
608c2ecf20Sopenharmony_ci#define DS2781_VCHG			0x64
618c2ecf20Sopenharmony_ci#define DS2781_IMIN			0x65
628c2ecf20Sopenharmony_ci#define DS2781_VAE			0x66
638c2ecf20Sopenharmony_ci#define DS2781_IAE			0x67
648c2ecf20Sopenharmony_ci#define DS2781_AE_40			0x68
658c2ecf20Sopenharmony_ci#define DS2781_RSNSP			0x69
668c2ecf20Sopenharmony_ci#define DS2781_FULL_40_MSB		0x6A
678c2ecf20Sopenharmony_ci#define DS2781_FULL_40_LSB		0x6B
688c2ecf20Sopenharmony_ci#define DS2781_FULL_4_SLOPE		0x6C
698c2ecf20Sopenharmony_ci#define DS2781_FULL_3_SLOPE		0x6D
708c2ecf20Sopenharmony_ci#define DS2781_FULL_2_SLOPE		0x6E
718c2ecf20Sopenharmony_ci#define DS2781_FULL_1_SLOPE		0x6F
728c2ecf20Sopenharmony_ci#define DS2781_AE_4_SLOPE		0x70
738c2ecf20Sopenharmony_ci#define DS2781_AE_3_SLOPE		0x71
748c2ecf20Sopenharmony_ci#define DS2781_AE_2_SLOPE		0x72
758c2ecf20Sopenharmony_ci#define DS2781_AE_1_SLOPE		0x73
768c2ecf20Sopenharmony_ci#define DS2781_SE_4_SLOPE		0x74
778c2ecf20Sopenharmony_ci#define DS2781_SE_3_SLOPE		0x75
788c2ecf20Sopenharmony_ci#define DS2781_SE_2_SLOPE		0x76
798c2ecf20Sopenharmony_ci#define DS2781_SE_1_SLOPE		0x77
808c2ecf20Sopenharmony_ci#define DS2781_RSGAIN_MSB		0x78
818c2ecf20Sopenharmony_ci#define DS2781_RSGAIN_LSB		0x79
828c2ecf20Sopenharmony_ci#define DS2781_RSTC			0x7A
838c2ecf20Sopenharmony_ci#define DS2781_COB			0x7B
848c2ecf20Sopenharmony_ci#define DS2781_TBP34			0x7C
858c2ecf20Sopenharmony_ci#define DS2781_TBP23			0x7D
868c2ecf20Sopenharmony_ci#define DS2781_TBP12			0x7E
878c2ecf20Sopenharmony_ci#define DS2781_EEPROM_BLOCK1_END	0x7F
888c2ecf20Sopenharmony_ci/* Register 0x7D - 0xFF Reserved */
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define DS2781_FSGAIN_MSB		0xB0
918c2ecf20Sopenharmony_ci#define DS2781_FSGAIN_LSB		0xB1
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* Number of valid register addresses */
948c2ecf20Sopenharmony_ci#define DS2781_DATA_SIZE		0xB2
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* Status register bits */
978c2ecf20Sopenharmony_ci#define DS2781_STATUS_CHGTF		(1 << 7)
988c2ecf20Sopenharmony_ci#define DS2781_STATUS_AEF		(1 << 6)
998c2ecf20Sopenharmony_ci#define DS2781_STATUS_SEF		(1 << 5)
1008c2ecf20Sopenharmony_ci#define DS2781_STATUS_LEARNF		(1 << 4)
1018c2ecf20Sopenharmony_ci/* Bit 3 Reserved */
1028c2ecf20Sopenharmony_ci#define DS2781_STATUS_UVF		(1 << 2)
1038c2ecf20Sopenharmony_ci#define DS2781_STATUS_PORF		(1 << 1)
1048c2ecf20Sopenharmony_ci/* Bit 0 Reserved */
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Control register bits */
1078c2ecf20Sopenharmony_ci/* Bit 7 Reserved */
1088c2ecf20Sopenharmony_ci#define DS2781_CONTROL_NBEN		(1 << 7)
1098c2ecf20Sopenharmony_ci#define DS2781_CONTROL_UVEN		(1 << 6)
1108c2ecf20Sopenharmony_ci#define DS2781_CONTROL_PMOD		(1 << 5)
1118c2ecf20Sopenharmony_ci#define DS2781_CONTROL_RNAOP		(1 << 4)
1128c2ecf20Sopenharmony_ci#define DS1781_CONTROL_UVTH		(1 << 3)
1138c2ecf20Sopenharmony_ci/* Bit 0 - 2 Reserved */
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* Special feature register bits */
1168c2ecf20Sopenharmony_ci/* Bit 1 - 7 Reserved */
1178c2ecf20Sopenharmony_ci#define DS2781_SFR_PIOSC		(1 << 0)
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* EEPROM register bits */
1208c2ecf20Sopenharmony_ci#define DS2781_EEPROM_EEC		(1 << 7)
1218c2ecf20Sopenharmony_ci#define DS2781_EEPROM_LOCK		(1 << 6)
1228c2ecf20Sopenharmony_ci/* Bit 2 - 6 Reserved */
1238c2ecf20Sopenharmony_ci#define DS2781_EEPROM_BL1		(1 << 1)
1248c2ecf20Sopenharmony_ci#define DS2781_EEPROM_BL0		(1 << 0)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciextern int w1_ds2781_io(struct device *dev, char *buf, int addr, size_t count,
1278c2ecf20Sopenharmony_ci			int io);
1288c2ecf20Sopenharmony_ciextern int w1_ds2781_eeprom_cmd(struct device *dev, int addr, int cmd);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#endif /* !_W1_DS2781_H */
131