1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 23b10e6ebSOliver Schinagl /* 33b10e6ebSOliver Schinagl * Sunxi platform Push-Push i2c register definition. 43b10e6ebSOliver Schinagl * 53b10e6ebSOliver Schinagl * (c) Copyright 2013 Oliver Schinagl <oliver@schinagl.nl> 63b10e6ebSOliver Schinagl * http://linux-sunxi.org 73b10e6ebSOliver Schinagl * 83b10e6ebSOliver Schinagl * (c)Copyright 2006-2013 93b10e6ebSOliver Schinagl * Allwinner Technology Co., Ltd. <www.allwinnertech.com> 103b10e6ebSOliver Schinagl * Berg Xing <bergxing@allwinnertech.com> 113b10e6ebSOliver Schinagl * Tom Cubie <tangliang@allwinnertech.com> 123b10e6ebSOliver Schinagl */ 133b10e6ebSOliver Schinagl 143b10e6ebSOliver Schinagl #ifndef _SUNXI_P2WI_H 153b10e6ebSOliver Schinagl #define _SUNXI_P2WI_H 163b10e6ebSOliver Schinagl 173b10e6ebSOliver Schinagl #include <linux/types.h> 183b10e6ebSOliver Schinagl 193b10e6ebSOliver Schinagl #define P2WI_CTRL_RESET (0x1 << 0) 203b10e6ebSOliver Schinagl #define P2WI_CTRL_IRQ_EN (0x1 << 1) 213b10e6ebSOliver Schinagl #define P2WI_CTRL_TRANS_ABORT (0x1 << 6) 223b10e6ebSOliver Schinagl #define P2WI_CTRL_TRANS_START (0x1 << 7) 233b10e6ebSOliver Schinagl 243b10e6ebSOliver Schinagl #define __P2WI_CC_CLK(n) (((n) & 0xff) << 0) 253b10e6ebSOliver Schinagl #define P2WI_CC_CLK_MASK __P2WI_CC_CLK_DIV(0xff) 263b10e6ebSOliver Schinagl #define __P2WI_CC_CLK_DIV(n) (((n) >> 1) - 1) 273b10e6ebSOliver Schinagl #define P2WI_CC_CLK_DIV(n) \ 283b10e6ebSOliver Schinagl __P2WI_CC_CLK(__P2WI_CC_CLK_DIV(n)) 293b10e6ebSOliver Schinagl #define P2WI_CC_SDA_OUT_DELAY(n) (((n) & 0x7) << 8) 303b10e6ebSOliver Schinagl #define P2WI_CC_SDA_OUT_DELAY_MASK P2WI_CC_SDA_OUT_DELAY(0x7) 313b10e6ebSOliver Schinagl 323b10e6ebSOliver Schinagl #define P2WI_IRQ_TRANS_DONE (0x1 << 0) 333b10e6ebSOliver Schinagl #define P2WI_IRQ_TRANS_ERR (0x1 << 1) 343b10e6ebSOliver Schinagl #define P2WI_IRQ_LOAD_BUSY (0x1 << 2) 353b10e6ebSOliver Schinagl 363b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_DONE (0x1 << 0) 373b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR (0x1 << 1) 383b10e6ebSOliver Schinagl #define P2WI_STAT_LOAD_BUSY (0x1 << 2) 393b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR(n) (((n) & 0xff) << 8) 403b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_MASK __P2WI_STAT_TRANS_ERR_ID(0xff) 413b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_1 0x01 423b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_2 0x02 433b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_3 0x04 443b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_4 0x08 453b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_5 0x10 463b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_6 0x20 473b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_7 0x40 483b10e6ebSOliver Schinagl #define __P2WI_STAT_TRANS_ERR_BYTE_8 0x80 493b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_1 \ 503b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_1) 513b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_2 \ 523b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_2) 533b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_3 \ 543b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_3) 553b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_4 \ 563b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_4) 573b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_5 \ 583b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_5) 593b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_6 \ 603b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_6) 613b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_7 \ 623b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_7) 633b10e6ebSOliver Schinagl #define P2WI_STAT_TRANS_ERR_BYTE_8 \ 643b10e6ebSOliver Schinagl __P2WI_STAT_TRANS_ERR(__P2WI_STAT_TRANS_ERR_BYTE_8) 653b10e6ebSOliver Schinagl 663b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_1(n) (((n) & 0xff) << 0) 673b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_1_MASK P2WI_DATADDR_BYTE_1(0xff) 683b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_2(n) (((n) & 0xff) << 8) 693b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_2_MASK P2WI_DATADDR_BYTE_2(0xff) 703b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_3(n) (((n) & 0xff) << 16) 713b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_3_MASK P2WI_DATADDR_BYTE_3(0xff) 723b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_4(n) (((n) & 0xff) << 24) 733b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_4_MASK P2WI_DATADDR_BYTE_4(0xff) 743b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_5(n) (((n) & 0xff) << 0) 753b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_5_MASK P2WI_DATADDR_BYTE_5(0xff) 763b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_6(n) (((n) & 0xff) << 8) 773b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_6_MASK P2WI_DATADDR_BYTE_6(0xff) 783b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_7(n) (((n) & 0xff) << 16) 793b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_7_MASK P2WI_DATADDR_BYTE_7(0xff) 803b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_8(n) (((n) & 0xff) << 24) 813b10e6ebSOliver Schinagl #define P2WI_DATADDR_BYTE_8_MASK P2WI_DATADDR_BYTE_8(0xff) 823b10e6ebSOliver Schinagl 833b10e6ebSOliver Schinagl #define __P2WI_DATA_NUM_BYTES(n) (((n) & 0x7) << 0) 843b10e6ebSOliver Schinagl #define P2WI_DATA_NUM_BYTES_MASK __P2WI_DATA_NUM_BYTES(0x7) 853b10e6ebSOliver Schinagl #define P2WI_DATA_NUM_BYTES(n) __P2WI_DATA_NUM_BYTES((n) - 1) 863b10e6ebSOliver Schinagl #define P2WI_DATA_NUM_BYTES_READ (0x1 << 4) 873b10e6ebSOliver Schinagl 883b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_1(n) (((n) & 0xff) << 0) 893b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_1_MASK P2WI_DATA_BYTE_1(0xff) 903b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_2(n) (((n) & 0xff) << 8) 913b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_2_MASK P2WI_DATA_BYTE_2(0xff) 923b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_3(n) (((n) & 0xff) << 16) 933b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_3_MASK P2WI_DATA_BYTE_3(0xff) 943b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_4(n) (((n) & 0xff) << 24) 953b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_4_MASK P2WI_DATA_BYTE_4(0xff) 963b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_5(n) (((n) & 0xff) << 0) 973b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_5_MASK P2WI_DATA_BYTE_5(0xff) 983b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_6(n) (((n) & 0xff) << 8) 993b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_6_MASK P2WI_DATA_BYTE_6(0xff) 1003b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_7(n) (((n) & 0xff) << 16) 1013b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_7_MASK P2WI_DATA_BYTE_7(0xff) 1023b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_8(n) (((n) & 0xff) << 24) 1033b10e6ebSOliver Schinagl #define P2WI_DATA_BYTE_8_MASK P2WI_DATA_BYTE_8(0xff) 1043b10e6ebSOliver Schinagl 1053b10e6ebSOliver Schinagl #define P2WI_LINECTRL_SDA_CTRL_EN (0x1 << 0) 1063b10e6ebSOliver Schinagl #define P2WI_LINECTRL_SDA_OUT_HIGH (0x1 << 1) 1073b10e6ebSOliver Schinagl #define P2WI_LINECTRL_SCL_CTRL_EN (0x1 << 2) 1083b10e6ebSOliver Schinagl #define P2WI_LINECTRL_SCL_OUT_HIGH (0x1 << 3) 1093b10e6ebSOliver Schinagl #define P2WI_LINECTRL_SDA_STATE_HIGH (0x1 << 4) 1103b10e6ebSOliver Schinagl #define P2WI_LINECTRL_SCL_STATE_HIGH (0x1 << 5) 1113b10e6ebSOliver Schinagl 1123b10e6ebSOliver Schinagl #define P2WI_PM_DEV_ADDR(n) (((n) & 0xff) << 0) 1133b10e6ebSOliver Schinagl #define P2WI_PM_DEV_ADDR_MASK P2WI_PM_DEV_ADDR(0xff) 1143b10e6ebSOliver Schinagl #define P2WI_PM_CTRL_ADDR(n) (((n) & 0xff) << 8) 1153b10e6ebSOliver Schinagl #define P2WI_PM_CTRL_ADDR_MASK P2WI_PM_CTRL_ADDR(0xff) 1163b10e6ebSOliver Schinagl #define P2WI_PM_INIT_DATA(n) (((n) & 0xff) << 16) 1173b10e6ebSOliver Schinagl #define P2WI_PM_INIT_DATA_MASK P2WI_PM_INIT_DATA(0xff) 1183b10e6ebSOliver Schinagl #define P2WI_PM_INIT_SEND (0x1 << 31) 1193b10e6ebSOliver Schinagl 1203b10e6ebSOliver Schinagl struct sunxi_p2wi_reg { 1213b10e6ebSOliver Schinagl u32 ctrl; /* 0x00 control */ 1223b10e6ebSOliver Schinagl u32 cc; /* 0x04 clock control */ 1233b10e6ebSOliver Schinagl u32 irq; /* 0x08 interrupt */ 1243b10e6ebSOliver Schinagl u32 status; /* 0x0c status */ 1253b10e6ebSOliver Schinagl u32 dataddr0; /* 0x10 data address 0 */ 1263b10e6ebSOliver Schinagl u32 dataddr1; /* 0x14 data address 1 */ 1273b10e6ebSOliver Schinagl u32 numbytes; /* 0x18 num bytes */ 1283b10e6ebSOliver Schinagl u32 data0; /* 0x1c data buffer 0 */ 1293b10e6ebSOliver Schinagl u32 data1; /* 0x20 data buffer 1 */ 1303b10e6ebSOliver Schinagl u32 linectrl; /* 0x24 line control */ 1313b10e6ebSOliver Schinagl u32 pm; /* 0x28 power management */ 1323b10e6ebSOliver Schinagl }; 1333b10e6ebSOliver Schinagl 1343b10e6ebSOliver Schinagl void p2wi_init(void); 1353b10e6ebSOliver Schinagl int p2wi_change_to_p2wi_mode(u8 slave_addr, u8 ctrl_reg, u8 init_data); 1363b10e6ebSOliver Schinagl int p2wi_read(const u8 addr, u8 *data); 1373b10e6ebSOliver Schinagl int p2wi_write(const u8 addr, u8 data); 1383b10e6ebSOliver Schinagl 1393b10e6ebSOliver Schinagl #endif /* _SUNXI_P2WI_H */ 140