blob: 1083e1b4f25dbbaa85ccea6d02fc008e4b84a57c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * drivers/pcmcia/sa1100_jornada720.c
4 *
5 * Jornada720 PCMCIA specific routines
6 *
7 */
8#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/device.h>
10#include <linux/errno.h>
Russell Kingb96e6c02018-11-28 13:57:23 +000011#include <linux/gpio/consumer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
Arnd Bergmann58409f92014-06-05 23:05:47 +020013#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Russell Kinga09e64f2008-08-05 16:14:15 +010015#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/mach-types.h>
17
18#include "sa1111_generic.h"
19
Russell Kingb96e6c02018-11-28 13:57:23 +000020/*
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 */
27enum {
28 J720_GPIO_PWR,
29 J720_GPIO_3V,
30 J720_GPIO_MAX,
31};
32struct jornada720_data {
33 struct gpio_desc *gpio[J720_GPIO_MAX];
34};
35
36static 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 Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static int
61jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
62{
Russell Kingb96e6c02018-11-28 13:57:23 +000063 struct jornada720_data *j = skt->driver_data;
64 DECLARE_BITMAP(values, J720_GPIO_MAX) = { 0, };
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070065 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070067 printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__,
68 skt->nr, state->Vcc, state->Vpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070070 switch (skt->nr) {
71 case 0:
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070072 switch (state->Vcc) {
73 default:
74 case 0:
Russell Kingb96e6c02018-11-28 13:57:23 +000075 __assign_bit(J720_GPIO_PWR, values, 0);
76 __assign_bit(J720_GPIO_3V, values, 0);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070077 break;
78 case 33:
Russell Kingb96e6c02018-11-28 13:57:23 +000079 __assign_bit(J720_GPIO_PWR, values, 1);
80 __assign_bit(J720_GPIO_3V, values, 1);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070081 break;
82 case 50:
Russell Kingb96e6c02018-11-28 13:57:23 +000083 __assign_bit(J720_GPIO_PWR, values, 1);
84 __assign_bit(J720_GPIO_3V, values, 0);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070085 break;
86 }
87 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070089 case 1:
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070090 switch (state->Vcc) {
91 default:
92 case 0:
Russell Kingb96e6c02018-11-28 13:57:23 +000093 __assign_bit(J720_GPIO_PWR, values, 0);
94 __assign_bit(J720_GPIO_3V, values, 0);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070095 break;
96 case 33:
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070097 case 50:
Russell Kingb96e6c02018-11-28 13:57:23 +000098 __assign_bit(J720_GPIO_PWR, values, 1);
99 __assign_bit(J720_GPIO_3V, values, 1);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700100 break;
101 }
102 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700104 default:
105 return -1;
106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700108 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 Torvalds1da177e2005-04-16 15:20:36 -0700113
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700114 ret = sa1111_pcmcia_configure_socket(skt, state);
Russell Kinge2adbecfc2012-01-16 09:28:49 +0000115 if (ret == 0)
Russell Kingb96e6c02018-11-28 13:57:23 +0000116 ret = gpiod_set_array_value_cansleep(J720_GPIO_MAX, j->gpio,
117 NULL, values);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700119 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
122static struct pcmcia_low_level jornada720_pcmcia_ops = {
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700123 .owner = THIS_MODULE,
Russell Kingb96e6c02018-11-28 13:57:23 +0000124 .hw_init = jornada720_pcmcia_hw_init,
Kristoffer Ericson02e87d12009-09-21 17:03:56 -0700125 .configure_socket = jornada720_pcmcia_configure_socket,
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +0100126 .first = 0,
127 .nr = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
Dmitry Eremin-Solenikov4bc9ef22014-10-21 00:29:24 +0400130int pcmcia_jornada720_init(struct sa1111_dev *sadev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Russell King3f8df892016-09-02 10:14:20 +0100132 /* Fixme: why messing around with SA11x0's GPIO1? */
133 GRER |= 0x00000002;
Russell King - ARM Linuxdabd1462009-03-29 22:35:11 +0100134
Russell King3f8df892016-09-02 10:14:20 +0100135 sa11xx_drv_pcmcia_ops(&jornada720_pcmcia_ops);
136 return sa1111_pcmcia_add(sadev, &jornada720_pcmcia_ops,
137 sa11xx_drv_pcmcia_add_one);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}