@@ -57,6 +57,7 @@ enum rtl9300_i2c_reg_fields {
5757 F_SDA_SEL ,
5858 F_BUSY ,
5959 F_CLK_DIV ,
60+ F_EXT_SCK_5MS ,
6061
6162 /* keep last */
6263 F_NUM_FIELDS
@@ -77,8 +78,10 @@ struct rtl9300_i2c_drv_data {
7778
7879#define RTL9300_I2C_MUX_NCHAN 8
7980#define RTL9310_I2C_MUX_NCHAN 12
81+ #define RTL9607_I2C_MUX_NCHAN 1
8082
8183#define RTL9300_I2C_MAX_DATA_LEN 16
84+ #define RTL9607_I2C_MAX_DATA_LEN 4
8285
8386struct rtl9300_i2c {
8487 struct regmap * regmap ;
@@ -127,6 +130,14 @@ struct rtl9300_i2c_xfer {
127130#define RTL9310_I2C_MST_MEMADDR_CTRL 0x4
128131#define RTL9310_I2C_MST_DATA_CTRL 0x8
129132
133+ #define RTL9607_I2C_CONFIG 0x22f50
134+ #define RTL9607_IO_MODE_EN 0x23014
135+ #define RTL9607_I2C_IND_WD 0x0
136+ #define RTL9607_I2C_IND_ADR 0x8
137+ #define RTL9607_I2C_IND_CMD 0x10
138+ #define RTL9607_I2C_IND_RD 0x18
139+ #define RTL9607_REG_ADDR_8BIT_LEN 0
140+
130141static int rtl9300_i2c_reg_addr_set (struct rtl9300_i2c * i2c , u32 reg , u16 len )
131142{
132143 int ret ;
@@ -178,6 +189,27 @@ static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
178189 return 0 ;
179190}
180191
192+ static int rtl9607_i2c_config_chan (struct rtl9300_i2c * i2c , struct rtl9300_i2c_chan * chan )
193+ {
194+ const struct rtl9300_i2c_drv_data * drv_data ;
195+ int ret ;
196+
197+ if (i2c -> sda_num == chan -> sda_num )
198+ return 0 ;
199+
200+ ret = regmap_field_write (i2c -> fields [F_CLK_DIV ], chan -> clk_div );
201+ if (ret )
202+ return ret ;
203+
204+ drv_data = device_get_match_data (i2c -> dev );
205+ ret = drv_data -> select_scl (i2c , i2c -> scl_num );
206+ if (ret )
207+ return ret ;
208+
209+ i2c -> sda_num = chan -> sda_num ;
210+ return 0 ;
211+ }
212+
181213static void rtl9300_i2c_config_clock (u32 clock_freq , struct rtl9300_i2c_chan * chan )
182214{
183215 struct rtl9300_i2c * i2c = chan -> i2c ;
@@ -202,6 +234,13 @@ static void rtl9300_i2c_config_clock(u32 clock_freq, struct rtl9300_i2c_chan *ch
202234 }
203235}
204236
237+ static void rtl9607_i2c_config_clock (u32 clock_freq , struct rtl9300_i2c_chan * chan )
238+ {
239+ struct rtl9300_i2c * i2c = chan -> i2c ;
240+
241+ chan -> clk_div = clk_get_rate (i2c -> clk ) / clock_freq - 1 ;
242+ }
243+
205244static int rtl9300_i2c_read (struct rtl9300_i2c * i2c , u8 * buf , u8 len )
206245{
207246 u32 vals [4 ] = {};
@@ -422,6 +461,11 @@ static int rtl9300_i2c_init(struct rtl9300_i2c *i2c)
422461 return regmap_field_write (i2c -> fields [F_RD_MODE ], 0 );
423462}
424463
464+ static int rtl9607_i2c_init (struct rtl9300_i2c * i2c )
465+ {
466+ return regmap_field_write (i2c -> fields [F_EXT_SCK_5MS ], 1 );
467+ }
468+
425469static int rtl9300_i2c_probe (struct platform_device * pdev )
426470{
427471 struct device * dev = & pdev -> dev ;
@@ -574,6 +618,31 @@ static const struct rtl9300_i2c_drv_data rtl9310_i2c_drv_data = {
574618 .reg_addr_8bit_len = RTL9300_REG_ADDR_8BIT_LEN ,
575619};
576620
621+ static const struct rtl9300_i2c_drv_data rtl9607_i2c_drv_data = {
622+ .field_desc = {
623+ [F_SCL_SEL ] = GLB_REG_FIELD (RTL9607_IO_MODE_EN , 13 , 14 ),
624+ [F_EXT_SCK_5MS ] = MST_REG_FIELD (RTL9607_I2C_CONFIG , 26 , 26 ),
625+ [F_DEV_ADDR ] = MST_REG_FIELD (RTL9607_I2C_CONFIG , 14 , 20 ),
626+ [F_MEM_ADDR_WIDTH ] = MST_REG_FIELD (RTL9607_I2C_CONFIG , 12 , 13 ),
627+ [F_DATA_WIDTH ] = MST_REG_FIELD (RTL9607_I2C_CONFIG , 10 , 11 ),
628+ [F_CLK_DIV ] = MST_REG_FIELD (RTL9607_I2C_CONFIG , 0 , 9 ),
629+ [F_I2C_FAIL ] = MST_REG_FIELD (RTL9607_I2C_IND_CMD , 3 , 3 ),
630+ [F_BUSY ] = MST_REG_FIELD (RTL9607_I2C_IND_CMD , 2 , 2 ),
631+ [F_RWOP ] = MST_REG_FIELD (RTL9607_I2C_IND_CMD , 1 , 1 ),
632+ [F_I2C_TRIG ] = MST_REG_FIELD (RTL9607_I2C_IND_CMD , 0 , 0 ),
633+ [F_MEM_ADDR ] = MST_REG_FIELD (RTL9607_I2C_IND_ADR , 0 , 31 ),
634+ },
635+ .select_scl = rtl9310_i2c_select_scl ,
636+ .config_chan = rtl9607_i2c_config_chan ,
637+ .config_clock = rtl9607_i2c_config_clock ,
638+ .misc_init = rtl9607_i2c_init ,
639+ .rd_reg = RTL9607_I2C_IND_RD ,
640+ .wd_reg = RTL9607_I2C_IND_WD ,
641+ .max_nchan = RTL9607_I2C_MUX_NCHAN ,
642+ .max_data_len = RTL9607_I2C_MAX_DATA_LEN ,
643+ .reg_addr_8bit_len = RTL9607_REG_ADDR_8BIT_LEN ,
644+ };
645+
577646static const struct of_device_id i2c_rtl9300_dt_ids [] = {
578647 { .compatible = "realtek,rtl9301-i2c" , .data = (void * ) & rtl9300_i2c_drv_data },
579648 { .compatible = "realtek,rtl9302b-i2c" , .data = (void * ) & rtl9300_i2c_drv_data },
@@ -583,6 +652,7 @@ static const struct of_device_id i2c_rtl9300_dt_ids[] = {
583652 { .compatible = "realtek,rtl9311-i2c" , .data = (void * ) & rtl9310_i2c_drv_data },
584653 { .compatible = "realtek,rtl9312-i2c" , .data = (void * ) & rtl9310_i2c_drv_data },
585654 { .compatible = "realtek,rtl9313-i2c" , .data = (void * ) & rtl9310_i2c_drv_data },
655+ { .compatible = "realtek,rtl9607-i2c" , .data = (void * ) & rtl9607_i2c_drv_data },
586656 {}
587657};
588658MODULE_DEVICE_TABLE (of , i2c_rtl9300_dt_ids );
0 commit comments