aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2013-01-23 08:24:08 -0500
committerLinus Walleij <linus.walleij@linaro.org>2013-02-05 07:54:23 -0500
commit83b423c885337415a680748cbd40f732734ab0b1 (patch)
tree711bdfdcd2cd6976f4ccce5b3b0c9355c9159a41 /drivers/pinctrl
parent1abeebeaa5c0d577c1c66c19aa75470fcefd8396 (diff)
pinctrl/abx500: beautify the ABX500 pin control driver
This patch provides some superficial changes to the driver to aid with readability and maintainability. We're mostly fixing things like white-space errors, spreading out code which as been clumped together impeding readability and comment layout, such as using the new "/**" comment start for function headers etc. No code semantics were harmed in the making of this patch. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/pinctrl-abx500.c94
1 files changed, 59 insertions, 35 deletions
diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c
index 305a9cb5cf80..426b47cd6433 100644
--- a/drivers/pinctrl/pinctrl-abx500.c
+++ b/drivers/pinctrl/pinctrl-abx500.c
@@ -127,7 +127,7 @@ static inline struct abx500_pinctrl *to_abx500_pinctrl(struct gpio_chip *chip)
127} 127}
128 128
129static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg, 129static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg,
130 unsigned offset, bool *bit) 130 unsigned offset, bool *bit)
131{ 131{
132 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 132 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
133 u8 pos = offset % 8; 133 u8 pos = offset % 8;
@@ -149,7 +149,7 @@ static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg,
149} 149}
150 150
151static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg, 151static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg,
152 unsigned offset, int val) 152 unsigned offset, int val)
153{ 153{
154 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 154 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
155 u8 pos = offset % 8; 155 u8 pos = offset % 8;
@@ -160,12 +160,14 @@ static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg,
160 AB8500_MISC, reg, BIT(pos), val << pos); 160 AB8500_MISC, reg, BIT(pos), val << pos);
161 if (ret < 0) 161 if (ret < 0)
162 dev_err(pct->dev, "%s write failed\n", __func__); 162 dev_err(pct->dev, "%s write failed\n", __func__);
163
163 return ret; 164 return ret;
164} 165}
166
165/** 167/**
166 * abx500_gpio_get() - Get the particular GPIO value 168 * abx500_gpio_get() - Get the particular GPIO value
167 * @chip: Gpio device 169 * @chip: Gpio device
168 * @offset: GPIO number to read 170 * @offset: GPIO number to read
169 */ 171 */
170static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset) 172static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset)
171{ 173{
@@ -179,6 +181,7 @@ static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset)
179 dev_err(pct->dev, "%s failed\n", __func__); 181 dev_err(pct->dev, "%s failed\n", __func__);
180 return ret; 182 return ret;
181 } 183 }
184
182 return bit; 185 return bit;
183} 186}
184 187
@@ -193,7 +196,7 @@ static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
193} 196}
194 197
195static int abx500_config_pull_updown(struct abx500_pinctrl *pct, 198static int abx500_config_pull_updown(struct abx500_pinctrl *pct,
196 int offset, enum abx500_gpio_pull_updown val) 199 int offset, enum abx500_gpio_pull_updown val)
197{ 200{
198 u8 pos; 201 u8 pos;
199 int ret; 202 int ret;
@@ -223,6 +226,7 @@ static int abx500_config_pull_updown(struct abx500_pinctrl *pct,
223out: 226out:
224 if (ret < 0) 227 if (ret < 0)
225 dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); 228 dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
229
226 return ret; 230 return ret;
227} 231}
228 232
@@ -234,6 +238,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip,
234 struct pullud *pullud = pct->soc->pullud; 238 struct pullud *pullud = pct->soc->pullud;
235 unsigned gpio; 239 unsigned gpio;
236 int ret; 240 int ret;
241
237 /* set direction as output */ 242 /* set direction as output */
238 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_DIR1_REG, offset, 1); 243 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_DIR1_REG, offset, 1);
239 if (ret < 0) 244 if (ret < 0)
@@ -253,6 +258,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip,
253 if (ret < 0) 258 if (ret < 0)
254 return ret; 259 return ret;
255 } 260 }
261
256 /* set the output as 1 or 0 */ 262 /* set the output as 1 or 0 */
257 return abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val); 263 return abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val);
258} 264}
@@ -284,13 +290,14 @@ static int abx500_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
284} 290}
285 291
286static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, 292static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
287 unsigned gpio, int alt_setting) 293 unsigned gpio, int alt_setting)
288{ 294{
289 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 295 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
290 struct alternate_functions af = pct->soc->alternate_functions[gpio]; 296 struct alternate_functions af = pct->soc->alternate_functions[gpio];
291 int ret; 297 int ret;
292 int val; 298 int val;
293 unsigned offset; 299 unsigned offset;
300
294 const char *modes[] = { 301 const char *modes[] = {
295 [ABX500_DEFAULT] = "default", 302 [ABX500_DEFAULT] = "default",
296 [ABX500_ALT_A] = "altA", 303 [ABX500_ALT_A] = "altA",
@@ -309,6 +316,7 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
309 316
310 /* on ABx5xx, there is no GPIO0, so adjust the offset */ 317 /* on ABx5xx, there is no GPIO0, so adjust the offset */
311 offset = gpio - 1; 318 offset = gpio - 1;
319
312 switch (alt_setting) { 320 switch (alt_setting) {
313 case ABX500_DEFAULT: 321 case ABX500_DEFAULT:
314 /* 322 /*
@@ -324,6 +332,7 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
324 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, 332 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
325 offset, val); 333 offset, val);
326 break; 334 break;
335
327 case ABX500_ALT_A: 336 case ABX500_ALT_A:
328 /* 337 /*
329 * for ABx5xx family, alt_a mode is always selected by 338 * for ABx5xx family, alt_a mode is always selected by
@@ -348,6 +357,7 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
348 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, 357 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
349 offset, 1); 358 offset, 1);
350 break; 359 break;
360
351 case ABX500_ALT_B: 361 case ABX500_ALT_B:
352 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, 362 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
353 offset, 0); 363 offset, 0);
@@ -359,6 +369,7 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
359 af.alt_bit2, 369 af.alt_bit2,
360 !!(af.altb_val && BIT(1))); 370 !!(af.altb_val && BIT(1)));
361 break; 371 break;
372
362 case ABX500_ALT_C: 373 case ABX500_ALT_C:
363 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, 374 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
364 offset, 0); 375 offset, 0);
@@ -370,13 +381,15 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
370 381
371 default: 382 default:
372 dev_dbg(pct->dev, "unknow alt_setting %d\n", alt_setting); 383 dev_dbg(pct->dev, "unknow alt_setting %d\n", alt_setting);
384
373 return -EINVAL; 385 return -EINVAL;
374 } 386 }
387
375 return ret; 388 return ret;
376} 389}
377 390
378static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, 391static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
379 unsigned gpio) 392 unsigned gpio)
380{ 393{
381 u8 mode; 394 u8 mode;
382 bool bit_mode; 395 bool bit_mode;
@@ -404,6 +417,7 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
404 "alt_bitX value not in correct range (-1 to 7)\n"); 417 "alt_bitX value not in correct range (-1 to 7)\n");
405 return -EINVAL; 418 return -EINVAL;
406 } 419 }
420
407 /* if alt_bit2 is used, alt_bit1 must be used too */ 421 /* if alt_bit2 is used, alt_bit1 must be used too */
408 if ((af.alt_bit2 != UNUSED) && (af.alt_bit1 == UNUSED)) { 422 if ((af.alt_bit2 != UNUSED) && (af.alt_bit1 == UNUSED)) {
409 dev_err(pct->dev, 423 dev_err(pct->dev,
@@ -420,6 +434,7 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
420 */ 434 */
421 if (mode) 435 if (mode)
422 return ABX500_DEFAULT; 436 return ABX500_DEFAULT;
437
423 /* 438 /*
424 * pin use the AlternatFunction register 439 * pin use the AlternatFunction register
425 * read alt_bit1 value 440 * read alt_bit1 value
@@ -448,8 +463,9 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
448#include <linux/seq_file.h> 463#include <linux/seq_file.h>
449 464
450static void abx500_gpio_dbg_show_one(struct seq_file *s, 465static void abx500_gpio_dbg_show_one(struct seq_file *s,
451 struct pinctrl_dev *pctldev, struct gpio_chip *chip, 466 struct pinctrl_dev *pctldev,
452 unsigned offset, unsigned gpio) 467 struct gpio_chip *chip,
468 unsigned offset, unsigned gpio)
453{ 469{
454 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 470 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
455 const char *label = gpiochip_is_requested(chip, offset - 1); 471 const char *label = gpiochip_is_requested(chip, offset - 1);
@@ -457,6 +473,7 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
457 int mode = -1; 473 int mode = -1;
458 bool is_out; 474 bool is_out;
459 bool pull; 475 bool pull;
476
460 const char *modes[] = { 477 const char *modes[] = {
461 [ABX500_DEFAULT] = "default", 478 [ABX500_DEFAULT] = "default",
462 [ABX500_ALT_A] = "altA", 479 [ABX500_ALT_A] = "altA",
@@ -516,9 +533,9 @@ static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
516 533
517#else 534#else
518static inline void abx500_gpio_dbg_show_one(struct seq_file *s, 535static inline void abx500_gpio_dbg_show_one(struct seq_file *s,
519 struct pinctrl_dev *pctldev, 536 struct pinctrl_dev *pctldev,
520 struct gpio_chip *chip, 537 struct gpio_chip *chip,
521 unsigned offset, unsigned gpio) 538 unsigned offset, unsigned gpio)
522{ 539{
523} 540}
524#define abx500_gpio_dbg_show NULL 541#define abx500_gpio_dbg_show NULL
@@ -780,9 +797,9 @@ static const char *abx500_pmx_get_func_name(struct pinctrl_dev *pctldev,
780} 797}
781 798
782static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev, 799static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev,
783 unsigned function, 800 unsigned function,
784 const char * const **groups, 801 const char * const **groups,
785 unsigned * const num_groups) 802 unsigned * const num_groups)
786{ 803{
787 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 804 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
788 805
@@ -830,7 +847,7 @@ static void abx500_disable_lazy_irq(struct gpio_chip *chip, unsigned gpio)
830} 847}
831 848
832static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function, 849static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
833 unsigned group) 850 unsigned group)
834{ 851{
835 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 852 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
836 struct gpio_chip *chip = &pct->chip; 853 struct gpio_chip *chip = &pct->chip;
@@ -851,11 +868,12 @@ static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
851 abx500_disable_lazy_irq(chip, g->pins[i]); 868 abx500_disable_lazy_irq(chip, g->pins[i]);
852 ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting); 869 ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting);
853 } 870 }
871
854 return ret; 872 return ret;
855} 873}
856 874
857static void abx500_pmx_disable(struct pinctrl_dev *pctldev, 875static void abx500_pmx_disable(struct pinctrl_dev *pctldev,
858 unsigned function, unsigned group) 876 unsigned function, unsigned group)
859{ 877{
860 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 878 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
861 const struct abx500_pingroup *g; 879 const struct abx500_pingroup *g;
@@ -869,8 +887,8 @@ static void abx500_pmx_disable(struct pinctrl_dev *pctldev,
869} 887}
870 888
871int abx500_gpio_request_enable(struct pinctrl_dev *pctldev, 889int abx500_gpio_request_enable(struct pinctrl_dev *pctldev,
872 struct pinctrl_gpio_range *range, 890 struct pinctrl_gpio_range *range,
873 unsigned offset) 891 unsigned offset)
874{ 892{
875 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 893 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
876 const struct abx500_pinrange *p; 894 const struct abx500_pinrange *p;
@@ -908,8 +926,8 @@ int abx500_gpio_request_enable(struct pinctrl_dev *pctldev,
908} 926}
909 927
910static void abx500_gpio_disable_free(struct pinctrl_dev *pctldev, 928static void abx500_gpio_disable_free(struct pinctrl_dev *pctldev,
911 struct pinctrl_gpio_range *range, 929 struct pinctrl_gpio_range *range,
912 unsigned offset) 930 unsigned offset)
913{ 931{
914} 932}
915 933
@@ -931,7 +949,7 @@ static int abx500_get_groups_cnt(struct pinctrl_dev *pctldev)
931} 949}
932 950
933static const char *abx500_get_group_name(struct pinctrl_dev *pctldev, 951static const char *abx500_get_group_name(struct pinctrl_dev *pctldev,
934 unsigned selector) 952 unsigned selector)
935{ 953{
936 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 954 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
937 955
@@ -939,19 +957,20 @@ static const char *abx500_get_group_name(struct pinctrl_dev *pctldev,
939} 957}
940 958
941static int abx500_get_group_pins(struct pinctrl_dev *pctldev, 959static int abx500_get_group_pins(struct pinctrl_dev *pctldev,
942 unsigned selector, 960 unsigned selector,
943 const unsigned **pins, 961 const unsigned **pins,
944 unsigned *num_pins) 962 unsigned *num_pins)
945{ 963{
946 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 964 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
947 965
948 *pins = pct->soc->groups[selector].pins; 966 *pins = pct->soc->groups[selector].pins;
949 *num_pins = pct->soc->groups[selector].npins; 967 *num_pins = pct->soc->groups[selector].npins;
968
950 return 0; 969 return 0;
951} 970}
952 971
953static void abx500_pin_dbg_show(struct pinctrl_dev *pctldev, 972static void abx500_pin_dbg_show(struct pinctrl_dev *pctldev,
954 struct seq_file *s, unsigned offset) 973 struct seq_file *s, unsigned offset)
955{ 974{
956 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 975 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
957 struct gpio_chip *chip = &pct->chip; 976 struct gpio_chip *chip = &pct->chip;
@@ -968,15 +987,15 @@ static struct pinctrl_ops abx500_pinctrl_ops = {
968}; 987};
969 988
970int abx500_pin_config_get(struct pinctrl_dev *pctldev, 989int abx500_pin_config_get(struct pinctrl_dev *pctldev,
971 unsigned pin, 990 unsigned pin,
972 unsigned long *config) 991 unsigned long *config)
973{ 992{
974 return -ENOSYS; 993 return -ENOSYS;
975} 994}
976 995
977int abx500_pin_config_set(struct pinctrl_dev *pctldev, 996int abx500_pin_config_set(struct pinctrl_dev *pctldev,
978 unsigned pin, 997 unsigned pin,
979 unsigned long config) 998 unsigned long config)
980{ 999{
981 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 1000 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
982 struct pullud *pullud = pct->soc->pullud; 1001 struct pullud *pullud = pct->soc->pullud;
@@ -990,6 +1009,7 @@ int abx500_pin_config_set(struct pinctrl_dev *pctldev,
990 pin, config, (param == PIN_CONFIG_OUTPUT) ? "output " : "input", 1009 pin, config, (param == PIN_CONFIG_OUTPUT) ? "output " : "input",
991 (param == PIN_CONFIG_OUTPUT) ? (argument ? "high" : "low") : 1010 (param == PIN_CONFIG_OUTPUT) ? (argument ? "high" : "low") :
992 (argument ? "pull up" : "pull down")); 1011 (argument ? "pull up" : "pull down"));
1012
993 /* on ABx500, there is no GPIO0, so adjust the offset */ 1013 /* on ABx500, there is no GPIO0, so adjust the offset */
994 offset = pin - 1; 1014 offset = pin - 1;
995 1015
@@ -1018,13 +1038,18 @@ int abx500_pin_config_set(struct pinctrl_dev *pctldev,
1018 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG, 1038 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG,
1019 offset, argument ? 0 : 1); 1039 offset, argument ? 0 : 1);
1020 break; 1040 break;
1041
1021 case PIN_CONFIG_OUTPUT: 1042 case PIN_CONFIG_OUTPUT:
1022 ret = abx500_gpio_direction_output(chip, offset, argument); 1043 ret = abx500_gpio_direction_output(chip, offset, argument);
1044
1023 break; 1045 break;
1046
1024 default: 1047 default:
1025 dev_err(chip->dev, "illegal configuration requested\n"); 1048 dev_err(chip->dev, "illegal configuration requested\n");
1049
1026 return -EINVAL; 1050 return -EINVAL;
1027 } 1051 }
1052
1028 return ret; 1053 return ret;
1029} 1054}
1030 1055
@@ -1090,7 +1115,7 @@ static int abx500_gpio_probe(struct platform_device *pdev)
1090 int i; 1115 int i;
1091 1116
1092 pdata = abx500_pdata->gpio; 1117 pdata = abx500_pdata->gpio;
1093 if (!pdata) { 1118 if (!pdata) {
1094 dev_err(&pdev->dev, "gpio platform data missing\n"); 1119 dev_err(&pdev->dev, "gpio platform data missing\n");
1095 return -ENODEV; 1120 return -ENODEV;
1096 } 1121 }
@@ -1150,8 +1175,7 @@ static int abx500_gpio_probe(struct platform_device *pdev)
1150 goto out_free; 1175 goto out_free;
1151 ret = gpiochip_add(&pct->chip); 1176 ret = gpiochip_add(&pct->chip);
1152 if (ret) { 1177 if (ret) {
1153 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", 1178 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
1154 ret);
1155 goto out_rem_irq; 1179 goto out_rem_irq;
1156 } 1180 }
1157 dev_info(&pdev->dev, "added gpiochip\n"); 1181 dev_info(&pdev->dev, "added gpiochip\n");
@@ -1193,9 +1217,9 @@ out_free:
1193 return ret; 1217 return ret;
1194} 1218}
1195 1219
1196/* 1220/**
1197 * abx500_gpio_remove() - remove Ab8500-gpio driver 1221 * abx500_gpio_remove() - remove Ab8500-gpio driver
1198 * @pdev : Platform device registered 1222 * @pdev: Platform device registered
1199 */ 1223 */
1200static int abx500_gpio_remove(struct platform_device *pdev) 1224static int abx500_gpio_remove(struct platform_device *pdev)
1201{ 1225{