scoop.c (2f8c51493323550529ed295ba6ddcdd3d0f704d5) scoop.c (c353faa4b2abd8d5142640b880532c97a0807460)
1/*
2 * Support code for the SCOOP interface found on various Sharp PDAs
3 *
4 * Copyright (c) 2004 Richard Purdie
5 *
6 * Based on code written by Sharp/Lineo for 2.4 kernels
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 16 unchanged lines hidden (view full) ---

25 is used which is setup by the platform code.
26
27 This file is never modular so this symbol is always
28 accessile to the board support files.
29*/
30struct scoop_pcmcia_config *platform_scoop_config;
31EXPORT_SYMBOL(platform_scoop_config);
32
1/*
2 * Support code for the SCOOP interface found on various Sharp PDAs
3 *
4 * Copyright (c) 2004 Richard Purdie
5 *
6 * Based on code written by Sharp/Lineo for 2.4 kernels
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 16 unchanged lines hidden (view full) ---

25 is used which is setup by the platform code.
26
27 This file is never modular so this symbol is always
28 accessile to the board support files.
29*/
30struct scoop_pcmcia_config *platform_scoop_config;
31EXPORT_SYMBOL(platform_scoop_config);
32
33#define SCOOP_REG(d,adr) (*(volatile __iomem unsigned short*)(d +(adr)))
34
35struct scoop_dev {
36 void __iomem *base;
37 spinlock_t scoop_lock;
38 unsigned short suspend_clr;
39 unsigned short suspend_set;
40 u32 scoop_gpwr;
41};
42
43void reset_scoop(struct device *dev)
44{
45 struct scoop_dev *sdev = dev_get_drvdata(dev);
46
33struct scoop_dev {
34 void __iomem *base;
35 spinlock_t scoop_lock;
36 unsigned short suspend_clr;
37 unsigned short suspend_set;
38 u32 scoop_gpwr;
39};
40
41void reset_scoop(struct device *dev)
42{
43 struct scoop_dev *sdev = dev_get_drvdata(dev);
44
47 SCOOP_REG(sdev->base,SCOOP_MCR) = 0x0100; // 00
48 SCOOP_REG(sdev->base,SCOOP_CDR) = 0x0000; // 04
49 SCOOP_REG(sdev->base,SCOOP_CCR) = 0x0000; // 10
50 SCOOP_REG(sdev->base,SCOOP_IMR) = 0x0000; // 18
51 SCOOP_REG(sdev->base,SCOOP_IRM) = 0x00FF; // 14
52 SCOOP_REG(sdev->base,SCOOP_ISR) = 0x0000; // 1C
53 SCOOP_REG(sdev->base,SCOOP_IRM) = 0x0000;
45 iowrite16(0x0100, sdev->base + SCOOP_MCR); // 00
46 iowrite16(0x0000, sdev->base + SCOOP_CDR); // 04
47 iowrite16(0x0000, sdev->base + SCOOP_CCR); // 10
48 iowrite16(0x0000, sdev->base + SCOOP_IMR); // 18
49 iowrite16(0x00FF, sdev->base + SCOOP_IRM); // 14
50 iowrite16(0x0000, sdev->base + SCOOP_ISR); // 1C
51 iowrite16(0x0000, sdev->base + SCOOP_IRM);
54}
55
56unsigned short set_scoop_gpio(struct device *dev, unsigned short bit)
57{
58 unsigned short gpio_bit;
59 unsigned long flag;
60 struct scoop_dev *sdev = dev_get_drvdata(dev);
61
62 spin_lock_irqsave(&sdev->scoop_lock, flag);
52}
53
54unsigned short set_scoop_gpio(struct device *dev, unsigned short bit)
55{
56 unsigned short gpio_bit;
57 unsigned long flag;
58 struct scoop_dev *sdev = dev_get_drvdata(dev);
59
60 spin_lock_irqsave(&sdev->scoop_lock, flag);
63 gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) | bit;
64 SCOOP_REG(sdev->base, SCOOP_GPWR) = gpio_bit;
61 gpio_bit = ioread16(sdev->base + SCOOP_GPWR) | bit;
62 iowrite16(gpio_bit, sdev->base + SCOOP_GPWR);
65 spin_unlock_irqrestore(&sdev->scoop_lock, flag);
66
67 return gpio_bit;
68}
69
70unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit)
71{
72 unsigned short gpio_bit;
73 unsigned long flag;
74 struct scoop_dev *sdev = dev_get_drvdata(dev);
75
76 spin_lock_irqsave(&sdev->scoop_lock, flag);
63 spin_unlock_irqrestore(&sdev->scoop_lock, flag);
64
65 return gpio_bit;
66}
67
68unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit)
69{
70 unsigned short gpio_bit;
71 unsigned long flag;
72 struct scoop_dev *sdev = dev_get_drvdata(dev);
73
74 spin_lock_irqsave(&sdev->scoop_lock, flag);
77 gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) & ~bit;
78 SCOOP_REG(sdev->base,SCOOP_GPWR) = gpio_bit;
75 gpio_bit = ioread16(sdev->base + SCOOP_GPWR) & ~bit;
76 iowrite16(gpio_bit, sdev->base + SCOOP_GPWR);
79 spin_unlock_irqrestore(&sdev->scoop_lock, flag);
80
81 return gpio_bit;
82}
83
84EXPORT_SYMBOL(set_scoop_gpio);
85EXPORT_SYMBOL(reset_scoop_gpio);
86
87unsigned short read_scoop_reg(struct device *dev, unsigned short reg)
88{
89 struct scoop_dev *sdev = dev_get_drvdata(dev);
77 spin_unlock_irqrestore(&sdev->scoop_lock, flag);
78
79 return gpio_bit;
80}
81
82EXPORT_SYMBOL(set_scoop_gpio);
83EXPORT_SYMBOL(reset_scoop_gpio);
84
85unsigned short read_scoop_reg(struct device *dev, unsigned short reg)
86{
87 struct scoop_dev *sdev = dev_get_drvdata(dev);
90 return SCOOP_REG(sdev->base,reg);
88 return ioread16(sdev->base + reg);
91}
92
93void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data)
94{
95 struct scoop_dev *sdev = dev_get_drvdata(dev);
89}
90
91void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data)
92{
93 struct scoop_dev *sdev = dev_get_drvdata(dev);
96 SCOOP_REG(sdev->base,reg)=data;
94 iowrite16(data, sdev->base + reg);
97}
98
99EXPORT_SYMBOL(reset_scoop);
100EXPORT_SYMBOL(read_scoop_reg);
101EXPORT_SYMBOL(write_scoop_reg);
102
103static void check_scoop_reg(struct scoop_dev *sdev)
104{
105 unsigned short mcr;
106
95}
96
97EXPORT_SYMBOL(reset_scoop);
98EXPORT_SYMBOL(read_scoop_reg);
99EXPORT_SYMBOL(write_scoop_reg);
100
101static void check_scoop_reg(struct scoop_dev *sdev)
102{
103 unsigned short mcr;
104
107 mcr = SCOOP_REG(sdev->base, SCOOP_MCR);
105 mcr = ioread16(sdev->base + SCOOP_MCR);
108 if ((mcr & 0x100) == 0)
106 if ((mcr & 0x100) == 0)
109 SCOOP_REG(sdev->base, SCOOP_MCR) = 0x0101;
107 iowrite16(0x0101, sdev->base + SCOOP_MCR);
110}
111
112#ifdef CONFIG_PM
113static int scoop_suspend(struct platform_device *dev, pm_message_t state)
114{
115 struct scoop_dev *sdev = platform_get_drvdata(dev);
116
117 check_scoop_reg(sdev);
108}
109
110#ifdef CONFIG_PM
111static int scoop_suspend(struct platform_device *dev, pm_message_t state)
112{
113 struct scoop_dev *sdev = platform_get_drvdata(dev);
114
115 check_scoop_reg(sdev);
118 sdev->scoop_gpwr = SCOOP_REG(sdev->base, SCOOP_GPWR);
119 SCOOP_REG(sdev->base, SCOOP_GPWR) = (sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set;
116 sdev->scoop_gpwr = ioread16(sdev->base + SCOOP_GPWR);
117 iowrite16((sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set, sdev->base + SCOOP_GPWR);
120
121 return 0;
122}
123
124static int scoop_resume(struct platform_device *dev)
125{
126 struct scoop_dev *sdev = platform_get_drvdata(dev);
127
128 check_scoop_reg(sdev);
118
119 return 0;
120}
121
122static int scoop_resume(struct platform_device *dev)
123{
124 struct scoop_dev *sdev = platform_get_drvdata(dev);
125
126 check_scoop_reg(sdev);
129 SCOOP_REG(sdev->base,SCOOP_GPWR) = sdev->scoop_gpwr;
127 iowrite16(sdev->scoop_gpwr, sdev->base + SCOOP_GPWR);
130
131 return 0;
132}
133#else
134#define scoop_suspend NULL
135#define scoop_resume NULL
136#endif
137

--- 19 unchanged lines hidden (view full) ---

157 kfree(devptr);
158 return -ENOMEM;
159 }
160
161 platform_set_drvdata(pdev, devptr);
162
163 printk("Sharp Scoop Device found at 0x%08x -> 0x%8p\n",(unsigned int)mem->start, devptr->base);
164
128
129 return 0;
130}
131#else
132#define scoop_suspend NULL
133#define scoop_resume NULL
134#endif
135

--- 19 unchanged lines hidden (view full) ---

155 kfree(devptr);
156 return -ENOMEM;
157 }
158
159 platform_set_drvdata(pdev, devptr);
160
161 printk("Sharp Scoop Device found at 0x%08x -> 0x%8p\n",(unsigned int)mem->start, devptr->base);
162
165 SCOOP_REG(devptr->base, SCOOP_MCR) = 0x0140;
163 iowrite16(0x0140, devptr->base + SCOOP_MCR);
166 reset_scoop(&pdev->dev);
164 reset_scoop(&pdev->dev);
167 SCOOP_REG(devptr->base, SCOOP_CPR) = 0x0000;
168 SCOOP_REG(devptr->base, SCOOP_GPCR) = inf->io_dir & 0xffff;
169 SCOOP_REG(devptr->base, SCOOP_GPWR) = inf->io_out & 0xffff;
165 iowrite16(0x0000, devptr->base + SCOOP_CPR);
166 iowrite16(inf->io_dir & 0xffff, devptr->base + SCOOP_GPCR);
167 iowrite16(inf->io_out & 0xffff, devptr->base + SCOOP_GPWR);
170
171 devptr->suspend_clr = inf->suspend_clr;
172 devptr->suspend_set = inf->suspend_set;
173
174 return 0;
175}
176
177static int __devexit scoop_remove(struct platform_device *pdev)

--- 26 unchanged lines hidden ---
168
169 devptr->suspend_clr = inf->suspend_clr;
170 devptr->suspend_set = inf->suspend_set;
171
172 return 0;
173}
174
175static int __devexit scoop_remove(struct platform_device *pdev)

--- 26 unchanged lines hidden ---