Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * PCMCIA driver for SL811HS (as found in REX-CFU1U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Filename: sl811_cs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author:   Yukio Yamamoto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Port to sl811-hcd and 2.6.x by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *    Botond Botyanszki <boti@rocketmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *    Simon Pickering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  Last update: 2005-05-12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <pcmcia/cistpl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <pcmcia/cisreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <pcmcia/ds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/usb/sl811.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) MODULE_AUTHOR("Botond Botyanszki");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /* MACROS                                                             */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* VARIABLES                                                          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) typedef struct local_info_t {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct pcmcia_device	*p_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) } local_info_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static void sl811_cs_release(struct pcmcia_device * link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static void release_platform_dev(struct device * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	dev_dbg(dev, "sl811_cs platform_dev release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	dev->parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static struct sl811_platform_data platform_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.potpg		= 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.power		= 50,		/* == 100mA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	// .reset	= ... FIXME:  invoke CF reset on the card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static struct resource resources[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	[0] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		.flags	= IORESOURCE_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	[1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		// .name   = "address",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		.flags	= IORESOURCE_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		// .name   = "data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		.flags	= IORESOURCE_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) extern struct platform_driver sl811h_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static struct platform_device platform_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.id			= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		.platform_data = &platform_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		.release       = release_platform_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.resource		= resources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.num_resources		= ARRAY_SIZE(resources),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			 int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (platform_dev.dev.parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	platform_dev.dev.parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	/* finish seting up the platform device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	resources[0].start = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	resources[1].start = base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	resources[1].end = base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	resources[2].start = base_addr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	resources[2].end   = base_addr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/* The driver core will probe for us.  We know sl811-hcd has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 * initialized already because of the link order dependency created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * by referencing "sl811h_driver".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	platform_dev.name = sl811h_driver.driver.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return platform_device_register(&platform_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void sl811_cs_detach(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	dev_dbg(&link->dev, "sl811_cs_detach\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	sl811_cs_release(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* This points to the parent local_info_t struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	kfree(link->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void sl811_cs_release(struct pcmcia_device * link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	dev_dbg(&link->dev, "sl811_cs_release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	pcmcia_disable_device(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	platform_device_unregister(&platform_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (p_dev->config_index == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return pcmcia_request_io(p_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int sl811_cs_config(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct device		*parent = &link->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int			ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	dev_dbg(&link->dev, "sl811_cs_config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	link->config_flags |= CONF_ENABLE_IRQ |	CONF_AUTO_SET_VPP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* require an IRQ and two registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (resource_size(link->resource[0]) < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (!link->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	ret = pcmcia_enable_device(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			< 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		printk(KERN_WARNING "sl811_cs_config failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		sl811_cs_release(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return  -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int sl811_cs_probe(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	local_info_t *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (!local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	local->p_dev = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	link->priv = local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return sl811_cs_config(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static const struct pcmcia_device_id sl811_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	PCMCIA_DEVICE_NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct pcmcia_driver sl811_cs_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.name		= "sl811_cs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.probe		= sl811_cs_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.remove		= sl811_cs_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.id_table	= sl811_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) module_pcmcia_driver(sl811_cs_driver);