9090#define AT91_TWI_ACR_DATAL (len ) ((len) & 0xff)
9191#define AT91_TWI_ACR_DIR BIT(8)
9292
93+ #define AT91_TWI_FILTR 0x0044
94+ #define AT91_TWI_FILTR_FILT BIT(0)
95+
9396#define AT91_TWI_FMR 0x0050 /* FIFO Mode Register */
9497#define AT91_TWI_FMR_TXRDYM (mode ) (((mode) & 0x3) << 0)
9598#define AT91_TWI_FMR_TXRDYM_MASK (0x3 << 0)
@@ -114,6 +117,7 @@ struct at91_twi_pdata {
114117 bool has_unre_flag ;
115118 bool has_alt_cmd ;
116119 bool has_hold_field ;
120+ bool has_dig_filtr ;
117121 struct at_dma_slave dma_slave ;
118122};
119123
@@ -146,6 +150,7 @@ struct at91_twi_dev {
146150 bool recv_len_abort ;
147151 u32 fifo_size ;
148152 struct at91_twi_dma dma ;
153+ bool enable_dig_filt ;
149154};
150155
151156static unsigned at91_twi_read (struct at91_twi_dev * dev , unsigned reg )
@@ -176,6 +181,8 @@ static void at91_twi_irq_restore(struct at91_twi_dev *dev)
176181
177182static void at91_init_twi_bus (struct at91_twi_dev * dev )
178183{
184+ struct at91_twi_pdata * pdata = dev -> pdata ;
185+
179186 at91_disable_twi_interrupts (dev );
180187 at91_twi_write (dev , AT91_TWI_CR , AT91_TWI_SWRST );
181188 /* FIFO should be enabled immediately after the software reset */
@@ -184,6 +191,10 @@ static void at91_init_twi_bus(struct at91_twi_dev *dev)
184191 at91_twi_write (dev , AT91_TWI_CR , AT91_TWI_MSEN );
185192 at91_twi_write (dev , AT91_TWI_CR , AT91_TWI_SVDIS );
186193 at91_twi_write (dev , AT91_TWI_CWGR , dev -> twi_cwgr_reg );
194+
195+ /* enable digital filter */
196+ if (pdata -> has_dig_filtr && dev -> enable_dig_filt )
197+ at91_twi_write (dev , AT91_TWI_FILTR , AT91_TWI_FILTR_FILT );
187198}
188199
189200/*
@@ -831,6 +842,7 @@ static struct at91_twi_pdata at91rm9200_config = {
831842 .has_unre_flag = true,
832843 .has_alt_cmd = false,
833844 .has_hold_field = false,
845+ .has_dig_filtr = false,
834846};
835847
836848static struct at91_twi_pdata at91sam9261_config = {
@@ -839,6 +851,7 @@ static struct at91_twi_pdata at91sam9261_config = {
839851 .has_unre_flag = false,
840852 .has_alt_cmd = false,
841853 .has_hold_field = false,
854+ .has_dig_filtr = false,
842855};
843856
844857static struct at91_twi_pdata at91sam9260_config = {
@@ -847,6 +860,7 @@ static struct at91_twi_pdata at91sam9260_config = {
847860 .has_unre_flag = false,
848861 .has_alt_cmd = false,
849862 .has_hold_field = false,
863+ .has_dig_filtr = false,
850864};
851865
852866static struct at91_twi_pdata at91sam9g20_config = {
@@ -855,6 +869,7 @@ static struct at91_twi_pdata at91sam9g20_config = {
855869 .has_unre_flag = false,
856870 .has_alt_cmd = false,
857871 .has_hold_field = false,
872+ .has_dig_filtr = false,
858873};
859874
860875static struct at91_twi_pdata at91sam9g10_config = {
@@ -863,6 +878,7 @@ static struct at91_twi_pdata at91sam9g10_config = {
863878 .has_unre_flag = false,
864879 .has_alt_cmd = false,
865880 .has_hold_field = false,
881+ .has_dig_filtr = false,
866882};
867883
868884static const struct platform_device_id at91_twi_devtypes [] = {
@@ -893,6 +909,7 @@ static struct at91_twi_pdata at91sam9x5_config = {
893909 .has_unre_flag = false,
894910 .has_alt_cmd = false,
895911 .has_hold_field = false,
912+ .has_dig_filtr = false,
896913};
897914
898915static struct at91_twi_pdata sama5d4_config = {
@@ -901,6 +918,7 @@ static struct at91_twi_pdata sama5d4_config = {
901918 .has_unre_flag = false,
902919 .has_alt_cmd = false,
903920 .has_hold_field = true,
921+ .has_dig_filtr = true,
904922};
905923
906924static struct at91_twi_pdata sama5d2_config = {
@@ -909,6 +927,7 @@ static struct at91_twi_pdata sama5d2_config = {
909927 .has_unre_flag = true,
910928 .has_alt_cmd = true,
911929 .has_hold_field = true,
930+ .has_dig_filtr = true,
912931};
913932
914933static struct at91_twi_pdata sam9x60_config = {
@@ -917,6 +936,7 @@ static struct at91_twi_pdata sam9x60_config = {
917936 .has_unre_flag = true,
918937 .has_alt_cmd = true,
919938 .has_hold_field = true,
939+ .has_dig_filtr = true,
920940};
921941
922942static const struct of_device_id atmel_twi_dt_ids [] = {
@@ -1116,6 +1136,9 @@ static int at91_twi_probe(struct platform_device *pdev)
11161136 if (rc )
11171137 bus_clk_rate = DEFAULT_TWI_CLK_HZ ;
11181138
1139+ dev -> enable_dig_filt = of_property_read_bool (pdev -> dev .of_node ,
1140+ "enable-dig-filt" );
1141+
11191142 at91_calc_twi_clock (dev , bus_clk_rate );
11201143 at91_init_twi_bus (dev );
11211144
0 commit comments