arm64: dts: qcom: msm8998-clamshell: Remove retention idle state
[linux/fpc-iii.git] / drivers / pcmcia / sa1111_jornada720.c
blob1083e1b4f25dbbaa85ccea6d02fc008e4b84a57c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * drivers/pcmcia/sa1100_jornada720.c
5 * Jornada720 PCMCIA specific routines
7 */
8 #include <linux/module.h>
9 #include <linux/device.h>
10 #include <linux/errno.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
15 #include <mach/hardware.h>
16 #include <asm/mach-types.h>
18 #include "sa1111_generic.h"
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?
27 enum {
28 J720_GPIO_PWR,
29 J720_GPIO_3V,
30 J720_GPIO_MAX,
32 struct jornada720_data {
33 struct gpio_desc *gpio[J720_GPIO_MAX];
36 static int jornada720_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
38 struct device *dev = skt->socket.dev.parent;
39 struct jornada720_data *j;
41 j = devm_kzalloc(dev, sizeof(*j), GFP_KERNEL);
42 if (!j)
43 return -ENOMEM;
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]);
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]);
55 skt->driver_data = j;
57 return 0;
60 static int
61 jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
63 struct jornada720_data *j = skt->driver_data;
64 DECLARE_BITMAP(values, J720_GPIO_MAX) = { 0, };
65 int ret;
67 printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__,
68 skt->nr, state->Vcc, state->Vpp);
70 switch (skt->nr) {
71 case 0:
72 switch (state->Vcc) {
73 default:
74 case 0:
75 __assign_bit(J720_GPIO_PWR, values, 0);
76 __assign_bit(J720_GPIO_3V, values, 0);
77 break;
78 case 33:
79 __assign_bit(J720_GPIO_PWR, values, 1);
80 __assign_bit(J720_GPIO_3V, values, 1);
81 break;
82 case 50:
83 __assign_bit(J720_GPIO_PWR, values, 1);
84 __assign_bit(J720_GPIO_3V, values, 0);
85 break;
87 break;
89 case 1:
90 switch (state->Vcc) {
91 default:
92 case 0:
93 __assign_bit(J720_GPIO_PWR, values, 0);
94 __assign_bit(J720_GPIO_3V, values, 0);
95 break;
96 case 33:
97 case 50:
98 __assign_bit(J720_GPIO_PWR, values, 1);
99 __assign_bit(J720_GPIO_3V, values, 1);
100 break;
102 break;
104 default:
105 return -1;
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;
114 ret = sa1111_pcmcia_configure_socket(skt, state);
115 if (ret == 0)
116 ret = gpiod_set_array_value_cansleep(J720_GPIO_MAX, j->gpio,
117 NULL, values);
119 return ret;
122 static struct pcmcia_low_level jornada720_pcmcia_ops = {
123 .owner = THIS_MODULE,
124 .hw_init = jornada720_pcmcia_hw_init,
125 .configure_socket = jornada720_pcmcia_configure_socket,
126 .first = 0,
127 .nr = 2,
130 int pcmcia_jornada720_init(struct sa1111_dev *sadev)
132 /* Fixme: why messing around with SA11x0's GPIO1? */
133 GRER |= 0x00000002;
135 sa11xx_drv_pcmcia_ops(&jornada720_pcmcia_ops);
136 return sa1111_pcmcia_add(sadev, &jornada720_pcmcia_ops,
137 sa11xx_drv_pcmcia_add_one);