57
57
#define PIN_CFG_FILCLKSEL BIT(12)
58
58
#define PIN_CFG_IOLH_C BIT(13)
59
59
#define PIN_CFG_SOFT_PS BIT(14)
60
+ #define PIN_CFG_OEN BIT(15)
60
61
61
62
#define RZG2L_MPXED_COMMON_PIN_FUNCS (group ) \
62
63
(PIN_CFG_IOLH_##group | \
107
108
#define IEN (off ) (0x1800 + (off) * 8)
108
109
#define ISEL (off ) (0x2C00 + (off) * 8)
109
110
#define SD_CH (off , ch ) ((off) + (ch) * 4)
111
+ #define ETH_POC (off , ch ) ((off) + (ch) * 4)
110
112
#define QSPI (0x3008)
113
+ #define ETH_MODE (0x3018)
111
114
115
+ #define PVDD_2500 2 /* I/O domain voltage 2.5V */
112
116
#define PVDD_1800 1 /* I/O domain voltage <= 1.8V */
113
117
#define PVDD_3300 0 /* I/O domain voltage >= 3.3V */
114
118
115
119
#define PWPR_B0WI BIT(7) /* Bit Write Disable */
116
120
#define PWPR_PFCWE BIT(6) /* PFC Register Write Enable */
117
121
118
122
#define PM_MASK 0x03
119
- #define PVDD_MASK 0x01
120
123
#define PFC_MASK 0x07
121
124
#define IEN_MASK 0x01
122
125
#define IOLH_MASK 0x03
135
138
* struct rzg2l_register_offsets - specific register offsets
136
139
* @pwpr: PWPR register offset
137
140
* @sd_ch: SD_CH register offset
141
+ * @eth_poc: ETH_POC register offset
138
142
*/
139
143
struct rzg2l_register_offsets {
140
144
u16 pwpr ;
141
145
u16 sd_ch ;
146
+ u16 eth_poc ;
142
147
};
143
148
144
149
/**
@@ -167,6 +172,8 @@ enum rzg2l_iolh_index {
167
172
* @iolh_groupb_oi: IOLH group B output impedance specific values
168
173
* @drive_strength_ua: drive strength in uA is supported (otherwise mA is supported)
169
174
* @func_base: base number for port function (see register PFC)
175
+ * @oen_max_pin: the maximum pin number supporting output enable
176
+ * @oen_max_port: the maximum port number supporting output enable
170
177
*/
171
178
struct rzg2l_hwcfg {
172
179
const struct rzg2l_register_offsets regs ;
@@ -176,6 +183,8 @@ struct rzg2l_hwcfg {
176
183
u16 iolh_groupb_oi [4 ];
177
184
bool drive_strength_ua ;
178
185
u8 func_base ;
186
+ u8 oen_max_pin ;
187
+ u8 oen_max_port ;
179
188
};
180
189
181
190
struct rzg2l_dedicated_configs {
@@ -376,8 +385,11 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
376
385
goto done ;
377
386
}
378
387
379
- if (num_pinmux )
388
+ if (num_pinmux ) {
380
389
nmaps += 1 ;
390
+ if (num_configs )
391
+ nmaps += 1 ;
392
+ }
381
393
382
394
if (num_pins )
383
395
nmaps += num_pins ;
@@ -462,6 +474,16 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
462
474
maps [idx ].data .mux .function = name ;
463
475
idx ++ ;
464
476
477
+ if (num_configs ) {
478
+ ret = rzg2l_map_add_config (& maps [idx ], name ,
479
+ PIN_MAP_TYPE_CONFIGS_GROUP ,
480
+ configs , num_configs );
481
+ if (ret < 0 )
482
+ goto remove_group ;
483
+
484
+ idx ++ ;
485
+ }
486
+
465
487
dev_dbg (pctrl -> dev , "Parsed %pOF with %d pins\n" , np , num_pinmux );
466
488
ret = 0 ;
467
489
goto done ;
@@ -591,6 +613,10 @@ static int rzg2l_caps_to_pwr_reg(const struct rzg2l_register_offsets *regs, u32
591
613
return SD_CH (regs -> sd_ch , 0 );
592
614
if (caps & PIN_CFG_IO_VMC_SD1 )
593
615
return SD_CH (regs -> sd_ch , 1 );
616
+ if (caps & PIN_CFG_IO_VMC_ETH0 )
617
+ return ETH_POC (regs -> eth_poc , 0 );
618
+ if (caps & PIN_CFG_IO_VMC_ETH1 )
619
+ return ETH_POC (regs -> eth_poc , 1 );
594
620
if (caps & PIN_CFG_IO_VMC_QSPI )
595
621
return QSPI ;
596
622
@@ -602,6 +628,7 @@ static int rzg2l_get_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps
602
628
const struct rzg2l_hwcfg * hwcfg = pctrl -> data -> hwcfg ;
603
629
const struct rzg2l_register_offsets * regs = & hwcfg -> regs ;
604
630
int pwr_reg ;
631
+ u8 val ;
605
632
606
633
if (caps & PIN_CFG_SOFT_PS )
607
634
return pctrl -> settings [pin ].power_source ;
@@ -610,25 +637,51 @@ static int rzg2l_get_power_source(struct rzg2l_pinctrl *pctrl, u32 pin, u32 caps
610
637
if (pwr_reg < 0 )
611
638
return pwr_reg ;
612
639
613
- return (readl (pctrl -> base + pwr_reg ) & PVDD_MASK ) ? 1800 : 3300 ;
640
+ val = readb (pctrl -> base + pwr_reg );
641
+ switch (val ) {
642
+ case PVDD_1800 :
643
+ return 1800 ;
644
+ case PVDD_2500 :
645
+ return 2500 ;
646
+ case PVDD_3300 :
647
+ return 3300 ;
648
+ default :
649
+ /* Should not happen. */
650
+ return - EINVAL ;
651
+ }
614
652
}
615
653
616
654
static int rzg2l_set_power_source (struct rzg2l_pinctrl * pctrl , u32 pin , u32 caps , u32 ps )
617
655
{
618
656
const struct rzg2l_hwcfg * hwcfg = pctrl -> data -> hwcfg ;
619
657
const struct rzg2l_register_offsets * regs = & hwcfg -> regs ;
620
658
int pwr_reg ;
659
+ u8 val ;
621
660
622
661
if (caps & PIN_CFG_SOFT_PS ) {
623
662
pctrl -> settings [pin ].power_source = ps ;
624
663
return 0 ;
625
664
}
626
665
666
+ switch (ps ) {
667
+ case 1800 :
668
+ val = PVDD_1800 ;
669
+ break ;
670
+ case 2500 :
671
+ val = PVDD_2500 ;
672
+ break ;
673
+ case 3300 :
674
+ val = PVDD_3300 ;
675
+ break ;
676
+ default :
677
+ return - EINVAL ;
678
+ }
679
+
627
680
pwr_reg = rzg2l_caps_to_pwr_reg (regs , caps );
628
681
if (pwr_reg < 0 )
629
682
return pwr_reg ;
630
683
631
- writel (( ps == 1800 ) ? PVDD_1800 : PVDD_3300 , pctrl -> base + pwr_reg );
684
+ writeb ( val , pctrl -> base + pwr_reg );
632
685
pctrl -> settings [pin ].power_source = ps ;
633
686
634
687
return 0 ;
@@ -735,6 +788,66 @@ static bool rzg2l_ds_is_supported(struct rzg2l_pinctrl *pctrl, u32 caps,
735
788
return false;
736
789
}
737
790
791
+ static bool rzg2l_oen_is_supported (u32 caps , u8 pin , u8 max_pin )
792
+ {
793
+ if (!(caps & PIN_CFG_OEN ))
794
+ return false;
795
+
796
+ if (pin > max_pin )
797
+ return false;
798
+
799
+ return true;
800
+ }
801
+
802
+ static u8 rzg2l_pin_to_oen_bit (u32 offset , u8 pin , u8 max_port )
803
+ {
804
+ if (pin )
805
+ pin *= 2 ;
806
+
807
+ if (offset / RZG2L_PINS_PER_PORT == max_port )
808
+ pin += 1 ;
809
+
810
+ return pin ;
811
+ }
812
+
813
+ static u32 rzg2l_read_oen (struct rzg2l_pinctrl * pctrl , u32 caps , u32 offset , u8 pin )
814
+ {
815
+ u8 max_port = pctrl -> data -> hwcfg -> oen_max_port ;
816
+ u8 max_pin = pctrl -> data -> hwcfg -> oen_max_pin ;
817
+ u8 bit ;
818
+
819
+ if (!rzg2l_oen_is_supported (caps , pin , max_pin ))
820
+ return 0 ;
821
+
822
+ bit = rzg2l_pin_to_oen_bit (offset , pin , max_port );
823
+
824
+ return !(readb (pctrl -> base + ETH_MODE ) & BIT (bit ));
825
+ }
826
+
827
+ static int rzg2l_write_oen (struct rzg2l_pinctrl * pctrl , u32 caps , u32 offset , u8 pin , u8 oen )
828
+ {
829
+ u8 max_port = pctrl -> data -> hwcfg -> oen_max_port ;
830
+ u8 max_pin = pctrl -> data -> hwcfg -> oen_max_pin ;
831
+ unsigned long flags ;
832
+ u8 val , bit ;
833
+
834
+ if (!rzg2l_oen_is_supported (caps , pin , max_pin ))
835
+ return - EINVAL ;
836
+
837
+ bit = rzg2l_pin_to_oen_bit (offset , pin , max_port );
838
+
839
+ spin_lock_irqsave (& pctrl -> lock , flags );
840
+ val = readb (pctrl -> base + ETH_MODE );
841
+ if (oen )
842
+ val &= ~BIT (bit );
843
+ else
844
+ val |= BIT (bit );
845
+ writeb (val , pctrl -> base + ETH_MODE );
846
+ spin_unlock_irqrestore (& pctrl -> lock , flags );
847
+
848
+ return 0 ;
849
+ }
850
+
738
851
static int rzg2l_pinctrl_pinconf_get (struct pinctrl_dev * pctldev ,
739
852
unsigned int _pin ,
740
853
unsigned long * config )
@@ -772,6 +885,12 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
772
885
return - EINVAL ;
773
886
break ;
774
887
888
+ case PIN_CONFIG_OUTPUT_ENABLE :
889
+ arg = rzg2l_read_oen (pctrl , cfg , _pin , bit );
890
+ if (!arg )
891
+ return - EINVAL ;
892
+ break ;
893
+
775
894
case PIN_CONFIG_POWER_SOURCE :
776
895
ret = rzg2l_get_power_source (pctrl , _pin , cfg );
777
896
if (ret < 0 )
@@ -842,7 +961,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
842
961
struct rzg2l_pinctrl_pin_settings settings = pctrl -> settings [_pin ];
843
962
unsigned int * pin_data = pin -> drv_data ;
844
963
enum pin_config_param param ;
845
- unsigned int i ;
964
+ unsigned int i , arg , index ;
846
965
u32 cfg , off ;
847
966
int ret ;
848
967
u8 bit ;
@@ -864,24 +983,28 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
864
983
for (i = 0 ; i < num_configs ; i ++ ) {
865
984
param = pinconf_to_config_param (_configs [i ]);
866
985
switch (param ) {
867
- case PIN_CONFIG_INPUT_ENABLE : {
868
- unsigned int arg =
869
- pinconf_to_config_argument (_configs [i ]);
986
+ case PIN_CONFIG_INPUT_ENABLE :
987
+ arg = pinconf_to_config_argument (_configs [i ]);
870
988
871
989
if (!(cfg & PIN_CFG_IEN ))
872
990
return - EINVAL ;
873
991
874
992
rzg2l_rmw_pin_config (pctrl , IEN (off ), bit , IEN_MASK , !!arg );
875
993
break ;
876
- }
994
+
995
+ case PIN_CONFIG_OUTPUT_ENABLE :
996
+ arg = pinconf_to_config_argument (_configs [i ]);
997
+ ret = rzg2l_write_oen (pctrl , cfg , _pin , bit , !!arg );
998
+ if (ret )
999
+ return ret ;
1000
+ break ;
877
1001
878
1002
case PIN_CONFIG_POWER_SOURCE :
879
1003
settings .power_source = pinconf_to_config_argument (_configs [i ]);
880
1004
break ;
881
1005
882
- case PIN_CONFIG_DRIVE_STRENGTH : {
883
- unsigned int arg = pinconf_to_config_argument (_configs [i ]);
884
- unsigned int index ;
1006
+ case PIN_CONFIG_DRIVE_STRENGTH :
1007
+ arg = pinconf_to_config_argument (_configs [i ]);
885
1008
886
1009
if (!(cfg & PIN_CFG_IOLH_A ) || hwcfg -> drive_strength_ua )
887
1010
return - EINVAL ;
@@ -896,7 +1019,6 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
896
1019
897
1020
rzg2l_rmw_pin_config (pctrl , IOLH (off ), bit , IOLH_MASK , index );
898
1021
break ;
899
- }
900
1022
901
1023
case PIN_CONFIG_DRIVE_STRENGTH_UA :
902
1024
if (!(cfg & (PIN_CFG_IOLH_A | PIN_CFG_IOLH_B | PIN_CFG_IOLH_C )) ||
@@ -906,9 +1028,8 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
906
1028
settings .drive_strength_ua = pinconf_to_config_argument (_configs [i ]);
907
1029
break ;
908
1030
909
- case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS : {
910
- unsigned int arg = pinconf_to_config_argument (_configs [i ]);
911
- unsigned int index ;
1031
+ case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS :
1032
+ arg = pinconf_to_config_argument (_configs [i ]);
912
1033
913
1034
if (!(cfg & PIN_CFG_IOLH_B ) || !hwcfg -> iolh_groupb_oi [0 ])
914
1035
return - EINVAL ;
@@ -922,7 +1043,6 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
922
1043
923
1044
rzg2l_rmw_pin_config (pctrl , IOLH (off ), bit , IOLH_MASK , index );
924
1045
break ;
925
- }
926
1046
927
1047
default :
928
1048
return - EOPNOTSUPP ;
@@ -1323,7 +1443,8 @@ static const u32 r9a07g043_gpio_configs[] = {
1323
1443
static const u32 r9a08g045_gpio_configs [] = {
1324
1444
RZG2L_GPIO_PORT_PACK (4 , 0x20 , RZG3S_MPXED_PIN_FUNCS (A )), /* P0 */
1325
1445
RZG2L_GPIO_PORT_PACK (5 , 0x30 , RZG2L_MPXED_ETH_PIN_FUNCS (PIN_CFG_IOLH_C |
1326
- PIN_CFG_IO_VMC_ETH0 )), /* P1 */
1446
+ PIN_CFG_IO_VMC_ETH0 )) |
1447
+ PIN_CFG_OEN | PIN_CFG_IEN , /* P1 */
1327
1448
RZG2L_GPIO_PORT_PACK (4 , 0x31 , RZG2L_MPXED_ETH_PIN_FUNCS (PIN_CFG_IOLH_C |
1328
1449
PIN_CFG_IO_VMC_ETH0 )), /* P2 */
1329
1450
RZG2L_GPIO_PORT_PACK (4 , 0x32 , RZG2L_MPXED_ETH_PIN_FUNCS (PIN_CFG_IOLH_C |
@@ -1333,7 +1454,8 @@ static const u32 r9a08g045_gpio_configs[] = {
1333
1454
RZG2L_GPIO_PORT_PACK (5 , 0x21 , RZG3S_MPXED_PIN_FUNCS (A )), /* P5 */
1334
1455
RZG2L_GPIO_PORT_PACK (5 , 0x22 , RZG3S_MPXED_PIN_FUNCS (A )), /* P6 */
1335
1456
RZG2L_GPIO_PORT_PACK (5 , 0x34 , RZG2L_MPXED_ETH_PIN_FUNCS (PIN_CFG_IOLH_C |
1336
- PIN_CFG_IO_VMC_ETH1 )), /* P7 */
1457
+ PIN_CFG_IO_VMC_ETH1 )) |
1458
+ PIN_CFG_OEN | PIN_CFG_IEN , /* P7 */
1337
1459
RZG2L_GPIO_PORT_PACK (5 , 0x35 , RZG2L_MPXED_ETH_PIN_FUNCS (PIN_CFG_IOLH_C |
1338
1460
PIN_CFG_IO_VMC_ETH1 )), /* P8 */
1339
1461
RZG2L_GPIO_PORT_PACK (4 , 0x36 , RZG2L_MPXED_ETH_PIN_FUNCS (PIN_CFG_IOLH_C |
@@ -1878,6 +2000,7 @@ static const struct rzg2l_hwcfg rzg2l_hwcfg = {
1878
2000
.regs = {
1879
2001
.pwpr = 0x3014 ,
1880
2002
.sd_ch = 0x3000 ,
2003
+ .eth_poc = 0x300c ,
1881
2004
},
1882
2005
.iolh_groupa_ua = {
1883
2006
/* 3v3 power source */
@@ -1890,6 +2013,7 @@ static const struct rzg2l_hwcfg rzg3s_hwcfg = {
1890
2013
.regs = {
1891
2014
.pwpr = 0x3000 ,
1892
2015
.sd_ch = 0x3004 ,
2016
+ .eth_poc = 0x3010 ,
1893
2017
},
1894
2018
.iolh_groupa_ua = {
1895
2019
/* 1v8 power source */
@@ -1913,6 +2037,8 @@ static const struct rzg2l_hwcfg rzg3s_hwcfg = {
1913
2037
},
1914
2038
.drive_strength_ua = true,
1915
2039
.func_base = 1 ,
2040
+ .oen_max_pin = 1 , /* Pin 1 of P0 and P7 is the maximum OEN pin. */
2041
+ .oen_max_port = 7 , /* P7_1 is the maximum OEN port. */
1916
2042
};
1917
2043
1918
2044
static struct rzg2l_pinctrl_data r9a07g043_data = {
0 commit comments