Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * drivers/pcmcia/sa1100_jornada720.c |
| 4 | * |
| 5 | * Jornada720 PCMCIA specific routines |
| 6 | * |
| 7 | */ |
| 8 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/device.h> |
| 10 | #include <linux/errno.h> |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 11 | #include <linux/gpio/consumer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
Arnd Bergmann | 58409f9 | 2014-06-05 23:05:47 +0200 | [diff] [blame] | 13 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 15 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/mach-types.h> |
| 17 | |
| 18 | #include "sa1111_generic.h" |
| 19 | |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 20 | /* |
| 21 | * Socket 0 power: GPIO A0 |
| 22 | * Socket 0 3V: GPIO A2 |
| 23 | * Socket 1 power: GPIO A1 & GPIO A3 |
| 24 | * Socket 1 3V: GPIO A3 |
| 25 | * Does Socket 1 3V actually do anything? |
| 26 | */ |
| 27 | enum { |
| 28 | J720_GPIO_PWR, |
| 29 | J720_GPIO_3V, |
| 30 | J720_GPIO_MAX, |
| 31 | }; |
| 32 | struct jornada720_data { |
| 33 | struct gpio_desc *gpio[J720_GPIO_MAX]; |
| 34 | }; |
| 35 | |
| 36 | static int jornada720_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 37 | { |
| 38 | struct device *dev = skt->socket.dev.parent; |
| 39 | struct jornada720_data *j; |
| 40 | |
| 41 | j = devm_kzalloc(dev, sizeof(*j), GFP_KERNEL); |
| 42 | if (!j) |
| 43 | return -ENOMEM; |
| 44 | |
| 45 | j->gpio[J720_GPIO_PWR] = devm_gpiod_get(dev, skt->nr ? "s1-power" : |
| 46 | "s0-power", GPIOD_OUT_LOW); |
| 47 | if (IS_ERR(j->gpio[J720_GPIO_PWR])) |
| 48 | return PTR_ERR(j->gpio[J720_GPIO_PWR]); |
| 49 | |
| 50 | j->gpio[J720_GPIO_3V] = devm_gpiod_get(dev, skt->nr ? "s1-3v" : |
| 51 | "s0-3v", GPIOD_OUT_LOW); |
| 52 | if (IS_ERR(j->gpio[J720_GPIO_3V])) |
| 53 | return PTR_ERR(j->gpio[J720_GPIO_3V]); |
| 54 | |
| 55 | skt->driver_data = j; |
| 56 | |
| 57 | return 0; |
| 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int |
| 61 | jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) |
| 62 | { |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 63 | struct jornada720_data *j = skt->driver_data; |
| 64 | DECLARE_BITMAP(values, J720_GPIO_MAX) = { 0, }; |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 65 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 67 | printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__, |
| 68 | skt->nr, state->Vcc, state->Vpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 70 | switch (skt->nr) { |
| 71 | case 0: |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 72 | switch (state->Vcc) { |
| 73 | default: |
| 74 | case 0: |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 75 | __assign_bit(J720_GPIO_PWR, values, 0); |
| 76 | __assign_bit(J720_GPIO_3V, values, 0); |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 77 | break; |
| 78 | case 33: |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 79 | __assign_bit(J720_GPIO_PWR, values, 1); |
| 80 | __assign_bit(J720_GPIO_3V, values, 1); |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 81 | break; |
| 82 | case 50: |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 83 | __assign_bit(J720_GPIO_PWR, values, 1); |
| 84 | __assign_bit(J720_GPIO_3V, values, 0); |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 85 | break; |
| 86 | } |
| 87 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 89 | case 1: |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 90 | switch (state->Vcc) { |
| 91 | default: |
| 92 | case 0: |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 93 | __assign_bit(J720_GPIO_PWR, values, 0); |
| 94 | __assign_bit(J720_GPIO_3V, values, 0); |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 95 | break; |
| 96 | case 33: |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 97 | case 50: |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 98 | __assign_bit(J720_GPIO_PWR, values, 1); |
| 99 | __assign_bit(J720_GPIO_3V, values, 1); |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 100 | break; |
| 101 | } |
| 102 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 104 | default: |
| 105 | return -1; |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 108 | if (state->Vpp != state->Vcc && state->Vpp != 0) { |
| 109 | printk(KERN_ERR "%s(): slot cannot support VPP %u\n", |
| 110 | __func__, state->Vpp); |
| 111 | return -EPERM; |
| 112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 114 | ret = sa1111_pcmcia_configure_socket(skt, state); |
Russell King | e2adbecfc | 2012-01-16 09:28:49 +0000 | [diff] [blame] | 115 | if (ret == 0) |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 116 | ret = gpiod_set_array_value_cansleep(J720_GPIO_MAX, j->gpio, |
| 117 | NULL, values); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 119 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static struct pcmcia_low_level jornada720_pcmcia_ops = { |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 123 | .owner = THIS_MODULE, |
Russell King | b96e6c0 | 2018-11-28 13:57:23 +0000 | [diff] [blame] | 124 | .hw_init = jornada720_pcmcia_hw_init, |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 125 | .configure_socket = jornada720_pcmcia_configure_socket, |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 126 | .first = 0, |
| 127 | .nr = 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
Dmitry Eremin-Solenikov | 4bc9ef2 | 2014-10-21 00:29:24 +0400 | [diff] [blame] | 130 | int pcmcia_jornada720_init(struct sa1111_dev *sadev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Russell King | 3f8df89 | 2016-09-02 10:14:20 +0100 | [diff] [blame] | 132 | /* Fixme: why messing around with SA11x0's GPIO1? */ |
| 133 | GRER |= 0x00000002; |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 134 | |
Russell King | 3f8df89 | 2016-09-02 10:14:20 +0100 | [diff] [blame] | 135 | sa11xx_drv_pcmcia_ops(&jornada720_pcmcia_ops); |
| 136 | return sa1111_pcmcia_add(sadev, &jornada720_pcmcia_ops, |
| 137 | sa11xx_drv_pcmcia_add_one); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |