blob: 05d5059ca203d775d941bc6f52e2025c778f21e7 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Dmitry Baryshkovd6315942008-06-22 12:01:58 +01002/*
3 * Toshiba TC6393XB SoC support
4 *
5 * Copyright(c) 2005-2006 Chris Humbert
6 * Copyright(c) 2005 Dirk Opfer
7 * Copyright(c) 2005 Ian Molton <spyro@f2s.com>
8 * Copyright(c) 2007 Dmitry Baryshkov
9 *
10 * Based on code written by Sharp/Lineo for 2.4 kernels
11 * Based on locomo.c
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010012 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/io.h>
17#include <linux/irq.h>
18#include <linux/platform_device.h>
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010019#include <linux/clk.h>
Ian Molton25d6cbd82008-08-10 23:32:07 +020020#include <linux/err.h>
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +010021#include <linux/mfd/core.h>
22#include <linux/mfd/tmio.h>
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010023#include <linux/mfd/tc6393xb.h>
Linus Walleij4e125f62016-03-30 10:48:06 +020024#include <linux/gpio/driver.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010026
27#define SCR_REVID 0x08 /* b Revision ID */
28#define SCR_ISR 0x50 /* b Interrupt Status */
29#define SCR_IMR 0x52 /* b Interrupt Mask */
30#define SCR_IRR 0x54 /* b Interrupt Routing */
31#define SCR_GPER 0x60 /* w GP Enable */
32#define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
33#define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
34#define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
35#define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
36#define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
37#define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
38#define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
39#define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
40#define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
41#define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
42#define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
43#define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
44#define SCR_CCR 0x98 /* w Clock Control */
45#define SCR_PLL2CR 0x9a /* w PLL2 Control */
46#define SCR_PLL1CR 0x9c /* l PLL1 Control */
47#define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
48#define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
49#define SCR_FER 0xe0 /* b Function Enable */
50#define SCR_MCR 0xe4 /* w Mode Control */
51#define SCR_CONFIG 0xfc /* b Configuration Control */
52#define SCR_DEBUG 0xff /* b Debug */
53
54#define SCR_CCR_CK32K BIT(0)
55#define SCR_CCR_USBCK BIT(1)
56#define SCR_CCR_UNK1 BIT(4)
57#define SCR_CCR_MCLK_MASK (7 << 8)
58#define SCR_CCR_MCLK_OFF (0 << 8)
59#define SCR_CCR_MCLK_12 (1 << 8)
60#define SCR_CCR_MCLK_24 (2 << 8)
61#define SCR_CCR_MCLK_48 (3 << 8)
62#define SCR_CCR_HCLK_MASK (3 << 12)
63#define SCR_CCR_HCLK_24 (0 << 12)
64#define SCR_CCR_HCLK_48 (1 << 12)
65
66#define SCR_FER_USBEN BIT(0) /* USB host enable */
67#define SCR_FER_LCDCVEN BIT(1) /* polysilicon TFT enable */
68#define SCR_FER_SLCDEN BIT(2) /* SLCD enable */
69
70#define SCR_MCR_RDY_MASK (3 << 0)
71#define SCR_MCR_RDY_OPENDRAIN (0 << 0)
72#define SCR_MCR_RDY_TRISTATE (1 << 0)
73#define SCR_MCR_RDY_PUSHPULL (2 << 0)
74#define SCR_MCR_RDY_UNK BIT(2)
75#define SCR_MCR_RDY_EN BIT(3)
76#define SCR_MCR_INT_MASK (3 << 4)
77#define SCR_MCR_INT_OPENDRAIN (0 << 4)
78#define SCR_MCR_INT_TRISTATE (1 << 4)
79#define SCR_MCR_INT_PUSHPULL (2 << 4)
80#define SCR_MCR_INT_UNK BIT(6)
81#define SCR_MCR_INT_EN BIT(7)
82/* bits 8 - 16 are unknown */
83
84#define TC_GPIO_BIT(i) (1 << (i & 0x7))
85
86/*--------------------------------------------------------------------------*/
87
88struct tc6393xb {
89 void __iomem *scr;
90
91 struct gpio_chip gpio;
92
93 struct clk *clk; /* 3,6 Mhz */
94
Julia Cartwrightf5139c22017-03-21 17:43:06 -050095 raw_spinlock_t lock; /* protects RMW cycles */
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010096
97 struct {
98 u8 fer;
99 u16 ccr;
100 u8 gpi_bcr[3];
101 u8 gpo_dsr[3];
102 u8 gpo_doecr[3];
103 } suspend_state;
104
105 struct resource rscr;
106 struct resource *iomem;
107 int irq;
108 int irq_base;
109};
110
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100111enum {
112 TC6393XB_CELL_NAND,
Ian Molton25d6cbd82008-08-10 23:32:07 +0200113 TC6393XB_CELL_MMC,
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200114 TC6393XB_CELL_OHCI,
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200115 TC6393XB_CELL_FB,
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100116};
117
118/*--------------------------------------------------------------------------*/
119
120static int tc6393xb_nand_enable(struct platform_device *nand)
121{
Kefeng Wanged835132019-05-09 22:23:39 +0800122 struct tc6393xb *tc6393xb = dev_get_drvdata(nand->dev.parent);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100123 unsigned long flags;
124
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500125 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100126
127 /* SMD buffer on */
Kefeng Wanged835132019-05-09 22:23:39 +0800128 dev_dbg(nand->dev.parent, "SMD buffer on\n");
Ian Molton25d6cbd82008-08-10 23:32:07 +0200129 tmio_iowrite8(0xff, tc6393xb->scr + SCR_GPI_BCR(1));
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100130
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500131 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100132
133 return 0;
134}
135
Bill Pembertona9e9ce42012-11-19 13:24:21 -0500136static struct resource tc6393xb_nand_resources[] = {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100137 {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100138 .start = 0x1000,
139 .end = 0x1007,
140 .flags = IORESOURCE_MEM,
141 },
142 {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200143 .start = 0x0100,
144 .end = 0x01ff,
145 .flags = IORESOURCE_MEM,
146 },
147 {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100148 .start = IRQ_TC6393_NAND,
149 .end = IRQ_TC6393_NAND,
150 .flags = IORESOURCE_IRQ,
151 },
152};
153
Marek Vasut7745cc82010-10-10 03:55:43 +0200154static struct resource tc6393xb_mmc_resources[] = {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200155 {
156 .start = 0x800,
157 .end = 0x9ff,
158 .flags = IORESOURCE_MEM,
159 },
160 {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200161 .start = IRQ_TC6393_MMC,
162 .end = IRQ_TC6393_MMC,
163 .flags = IORESOURCE_IRQ,
164 },
165};
166
Tobias Klauser3446d4b2009-02-17 10:11:42 +0100167static const struct resource tc6393xb_ohci_resources[] = {
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200168 {
169 .start = 0x3000,
170 .end = 0x31ff,
171 .flags = IORESOURCE_MEM,
172 },
173 {
174 .start = 0x0300,
175 .end = 0x03ff,
176 .flags = IORESOURCE_MEM,
177 },
178 {
179 .start = 0x010000,
180 .end = 0x017fff,
181 .flags = IORESOURCE_MEM,
182 },
183 {
184 .start = 0x018000,
185 .end = 0x01ffff,
186 .flags = IORESOURCE_MEM,
187 },
188 {
189 .start = IRQ_TC6393_OHCI,
190 .end = IRQ_TC6393_OHCI,
191 .flags = IORESOURCE_IRQ,
192 },
193};
194
Bill Pembertona9e9ce42012-11-19 13:24:21 -0500195static struct resource tc6393xb_fb_resources[] = {
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200196 {
197 .start = 0x5000,
198 .end = 0x51ff,
199 .flags = IORESOURCE_MEM,
200 },
201 {
202 .start = 0x0500,
203 .end = 0x05ff,
204 .flags = IORESOURCE_MEM,
205 },
206 {
207 .start = 0x100000,
208 .end = 0x1fffff,
209 .flags = IORESOURCE_MEM,
210 },
211 {
212 .start = IRQ_TC6393_FB,
213 .end = IRQ_TC6393_FB,
214 .flags = IORESOURCE_IRQ,
215 },
216};
217
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200218static int tc6393xb_ohci_enable(struct platform_device *dev)
219{
220 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
221 unsigned long flags;
222 u16 ccr;
223 u8 fer;
224
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500225 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200226
227 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
228 ccr |= SCR_CCR_USBCK;
229 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
230
231 fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
232 fer |= SCR_FER_USBEN;
233 tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
234
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500235 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200236
237 return 0;
238}
239
240static int tc6393xb_ohci_disable(struct platform_device *dev)
241{
242 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
243 unsigned long flags;
244 u16 ccr;
245 u8 fer;
246
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500247 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200248
249 fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
250 fer &= ~SCR_FER_USBEN;
251 tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
252
253 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
254 ccr &= ~SCR_CCR_USBCK;
255 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
256
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500257 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200258
259 return 0;
260}
261
Dmitry Eremin-Solenikov1a5fb992014-10-24 21:19:57 +0400262static int tc6393xb_ohci_suspend(struct platform_device *dev)
263{
264 struct tc6393xb_platform_data *tcpd = dev_get_platdata(dev->dev.parent);
265
266 /* We can't properly store/restore OHCI state, so fail here */
267 if (tcpd->resume_restore)
268 return -EBUSY;
269
270 return tc6393xb_ohci_disable(dev);
271}
272
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200273static int tc6393xb_fb_enable(struct platform_device *dev)
274{
275 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
276 unsigned long flags;
277 u16 ccr;
278
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500279 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200280
281 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
282 ccr &= ~SCR_CCR_MCLK_MASK;
283 ccr |= SCR_CCR_MCLK_48;
284 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
285
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500286 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200287
288 return 0;
289}
290
291static int tc6393xb_fb_disable(struct platform_device *dev)
292{
293 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
294 unsigned long flags;
295 u16 ccr;
296
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500297 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200298
299 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
300 ccr &= ~SCR_CCR_MCLK_MASK;
301 ccr |= SCR_CCR_MCLK_OFF;
302 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
303
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500304 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200305
306 return 0;
307}
308
309int tc6393xb_lcd_set_power(struct platform_device *fb, bool on)
310{
Kefeng Wanged835132019-05-09 22:23:39 +0800311 struct tc6393xb *tc6393xb = dev_get_drvdata(fb->dev.parent);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200312 u8 fer;
313 unsigned long flags;
314
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500315 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200316
317 fer = ioread8(tc6393xb->scr + SCR_FER);
318 if (on)
319 fer |= SCR_FER_SLCDEN;
320 else
321 fer &= ~SCR_FER_SLCDEN;
322 iowrite8(fer, tc6393xb->scr + SCR_FER);
323
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500324 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200325
326 return 0;
327}
328EXPORT_SYMBOL(tc6393xb_lcd_set_power);
329
330int tc6393xb_lcd_mode(struct platform_device *fb,
331 const struct fb_videomode *mode) {
Kefeng Wanged835132019-05-09 22:23:39 +0800332 struct tc6393xb *tc6393xb = dev_get_drvdata(fb->dev.parent);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200333 unsigned long flags;
334
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500335 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200336
337 iowrite16(mode->pixclock, tc6393xb->scr + SCR_PLL1CR + 0);
338 iowrite16(mode->pixclock >> 16, tc6393xb->scr + SCR_PLL1CR + 2);
339
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500340 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200341
342 return 0;
343}
344EXPORT_SYMBOL(tc6393xb_lcd_mode);
345
Ian Molton64e88672010-01-06 13:51:48 +0100346static int tc6393xb_mmc_enable(struct platform_device *mmc)
347{
Kefeng Wanged835132019-05-09 22:23:39 +0800348 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100349
350 tmio_core_mmc_enable(tc6393xb->scr + 0x200, 0,
351 tc6393xb_mmc_resources[0].start & 0xfffe);
352
353 return 0;
354}
355
356static int tc6393xb_mmc_resume(struct platform_device *mmc)
357{
Kefeng Wanged835132019-05-09 22:23:39 +0800358 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100359
360 tmio_core_mmc_resume(tc6393xb->scr + 0x200, 0,
361 tc6393xb_mmc_resources[0].start & 0xfffe);
362
363 return 0;
364}
365
366static void tc6393xb_mmc_pwr(struct platform_device *mmc, int state)
367{
Kefeng Wanged835132019-05-09 22:23:39 +0800368 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100369
370 tmio_core_mmc_pwr(tc6393xb->scr + 0x200, 0, state);
371}
372
373static void tc6393xb_mmc_clk_div(struct platform_device *mmc, int state)
374{
Kefeng Wanged835132019-05-09 22:23:39 +0800375 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100376
377 tmio_core_mmc_clk_div(tc6393xb->scr + 0x200, 0, state);
378}
379
380static struct tmio_mmc_data tc6393xb_mmc_data = {
381 .hclk = 24000000,
382 .set_pwr = tc6393xb_mmc_pwr,
383 .set_clk_div = tc6393xb_mmc_clk_div,
384};
385
Bill Pembertona9e9ce42012-11-19 13:24:21 -0500386static struct mfd_cell tc6393xb_cells[] = {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100387 [TC6393XB_CELL_NAND] = {
388 .name = "tmio-nand",
389 .enable = tc6393xb_nand_enable,
390 .num_resources = ARRAY_SIZE(tc6393xb_nand_resources),
391 .resources = tc6393xb_nand_resources,
392 },
Ian Molton25d6cbd82008-08-10 23:32:07 +0200393 [TC6393XB_CELL_MMC] = {
394 .name = "tmio-mmc",
Ian Molton64e88672010-01-06 13:51:48 +0100395 .enable = tc6393xb_mmc_enable,
396 .resume = tc6393xb_mmc_resume,
Samuel Ortizec719742011-04-06 11:38:14 +0200397 .platform_data = &tc6393xb_mmc_data,
398 .pdata_size = sizeof(tc6393xb_mmc_data),
Ian Molton25d6cbd82008-08-10 23:32:07 +0200399 .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources),
400 .resources = tc6393xb_mmc_resources,
401 },
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200402 [TC6393XB_CELL_OHCI] = {
403 .name = "tmio-ohci",
404 .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
405 .resources = tc6393xb_ohci_resources,
406 .enable = tc6393xb_ohci_enable,
Dmitry Eremin-Solenikov1a5fb992014-10-24 21:19:57 +0400407 .suspend = tc6393xb_ohci_suspend,
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200408 .resume = tc6393xb_ohci_enable,
409 .disable = tc6393xb_ohci_disable,
410 },
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200411 [TC6393XB_CELL_FB] = {
412 .name = "tmio-fb",
413 .num_resources = ARRAY_SIZE(tc6393xb_fb_resources),
414 .resources = tc6393xb_fb_resources,
415 .enable = tc6393xb_fb_enable,
416 .suspend = tc6393xb_fb_disable,
417 .resume = tc6393xb_fb_enable,
418 .disable = tc6393xb_fb_disable,
419 },
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100420};
421
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100422/*--------------------------------------------------------------------------*/
423
424static int tc6393xb_gpio_get(struct gpio_chip *chip,
425 unsigned offset)
426{
Linus Walleij4e125f62016-03-30 10:48:06 +0200427 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100428
429 /* XXX: does dsr also represent inputs? */
Linus Walleij2d5f72b82015-12-22 15:47:55 +0100430 return !!(tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8))
431 & TC_GPIO_BIT(offset));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100432}
433
434static void __tc6393xb_gpio_set(struct gpio_chip *chip,
435 unsigned offset, int value)
436{
Linus Walleij4e125f62016-03-30 10:48:06 +0200437 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100438 u8 dsr;
439
Ian Molton25d6cbd82008-08-10 23:32:07 +0200440 dsr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100441 if (value)
442 dsr |= TC_GPIO_BIT(offset);
443 else
444 dsr &= ~TC_GPIO_BIT(offset);
445
Ian Molton25d6cbd82008-08-10 23:32:07 +0200446 tmio_iowrite8(dsr, tc6393xb->scr + SCR_GPO_DSR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100447}
448
449static void tc6393xb_gpio_set(struct gpio_chip *chip,
450 unsigned offset, int value)
451{
Linus Walleij4e125f62016-03-30 10:48:06 +0200452 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100453 unsigned long flags;
454
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500455 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100456
457 __tc6393xb_gpio_set(chip, offset, value);
458
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500459 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100460}
461
462static int tc6393xb_gpio_direction_input(struct gpio_chip *chip,
463 unsigned offset)
464{
Linus Walleij4e125f62016-03-30 10:48:06 +0200465 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100466 unsigned long flags;
467 u8 doecr;
468
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500469 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100470
Ian Molton25d6cbd82008-08-10 23:32:07 +0200471 doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100472 doecr &= ~TC_GPIO_BIT(offset);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200473 tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100474
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500475 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100476
477 return 0;
478}
479
480static int tc6393xb_gpio_direction_output(struct gpio_chip *chip,
481 unsigned offset, int value)
482{
Linus Walleij4e125f62016-03-30 10:48:06 +0200483 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100484 unsigned long flags;
485 u8 doecr;
486
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500487 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100488
489 __tc6393xb_gpio_set(chip, offset, value);
490
Ian Molton25d6cbd82008-08-10 23:32:07 +0200491 doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100492 doecr |= TC_GPIO_BIT(offset);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200493 tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100494
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500495 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100496
497 return 0;
498}
499
500static int tc6393xb_register_gpio(struct tc6393xb *tc6393xb, int gpio_base)
501{
502 tc6393xb->gpio.label = "tc6393xb";
503 tc6393xb->gpio.base = gpio_base;
504 tc6393xb->gpio.ngpio = 16;
505 tc6393xb->gpio.set = tc6393xb_gpio_set;
506 tc6393xb->gpio.get = tc6393xb_gpio_get;
507 tc6393xb->gpio.direction_input = tc6393xb_gpio_direction_input;
508 tc6393xb->gpio.direction_output = tc6393xb_gpio_direction_output;
509
Linus Walleij4e125f62016-03-30 10:48:06 +0200510 return gpiochip_add_data(&tc6393xb->gpio, tc6393xb);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100511}
512
513/*--------------------------------------------------------------------------*/
514
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200515static void tc6393xb_irq(struct irq_desc *desc)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100516{
Jiang Liu1e84aa42015-07-13 20:44:56 +0000517 struct tc6393xb *tc6393xb = irq_desc_get_handler_data(desc);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100518 unsigned int isr;
519 unsigned int i, irq_base;
520
521 irq_base = tc6393xb->irq_base;
522
Ian Molton25d6cbd82008-08-10 23:32:07 +0200523 while ((isr = tmio_ioread8(tc6393xb->scr + SCR_ISR) &
524 ~tmio_ioread8(tc6393xb->scr + SCR_IMR)))
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100525 for (i = 0; i < TC6393XB_NR_IRQS; i++) {
526 if (isr & (1 << i))
527 generic_handle_irq(irq_base + i);
528 }
529}
530
Mark Brown01af22e2010-12-12 12:34:04 +0000531static void tc6393xb_irq_ack(struct irq_data *data)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100532{
533}
534
Mark Brown01af22e2010-12-12 12:34:04 +0000535static void tc6393xb_irq_mask(struct irq_data *data)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100536{
Mark Brown01af22e2010-12-12 12:34:04 +0000537 struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100538 unsigned long flags;
539 u8 imr;
540
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500541 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200542 imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
Mark Brown01af22e2010-12-12 12:34:04 +0000543 imr |= 1 << (data->irq - tc6393xb->irq_base);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200544 tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500545 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100546}
547
Mark Brown01af22e2010-12-12 12:34:04 +0000548static void tc6393xb_irq_unmask(struct irq_data *data)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100549{
Mark Brown01af22e2010-12-12 12:34:04 +0000550 struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100551 unsigned long flags;
552 u8 imr;
553
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500554 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200555 imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
Mark Brown01af22e2010-12-12 12:34:04 +0000556 imr &= ~(1 << (data->irq - tc6393xb->irq_base));
Ian Molton25d6cbd82008-08-10 23:32:07 +0200557 tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500558 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100559}
560
561static struct irq_chip tc6393xb_chip = {
Mark Brown01af22e2010-12-12 12:34:04 +0000562 .name = "tc6393xb",
563 .irq_ack = tc6393xb_irq_ack,
564 .irq_mask = tc6393xb_irq_mask,
565 .irq_unmask = tc6393xb_irq_unmask,
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100566};
567
568static void tc6393xb_attach_irq(struct platform_device *dev)
569{
570 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
571 unsigned int irq, irq_base;
572
573 irq_base = tc6393xb->irq_base;
574
575 for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
Thomas Gleixnerd6f7ce9f2011-03-25 11:12:35 +0000576 irq_set_chip_and_handler(irq, &tc6393xb_chip, handle_edge_irq);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000577 irq_set_chip_data(irq, tc6393xb);
Rob Herring9bd09f32015-07-27 15:55:20 -0500578 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100579 }
580
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000581 irq_set_irq_type(tc6393xb->irq, IRQ_TYPE_EDGE_FALLING);
Thomas Gleixner079140f2015-07-13 20:44:54 +0000582 irq_set_chained_handler_and_data(tc6393xb->irq, tc6393xb_irq,
583 tc6393xb);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100584}
585
586static void tc6393xb_detach_irq(struct platform_device *dev)
587{
588 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
589 unsigned int irq, irq_base;
590
Thomas Gleixner079140f2015-07-13 20:44:54 +0000591 irq_set_chained_handler_and_data(tc6393xb->irq, NULL, NULL);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100592
593 irq_base = tc6393xb->irq_base;
594
595 for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
Rob Herring9bd09f32015-07-27 15:55:20 -0500596 irq_set_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000597 irq_set_chip(irq, NULL);
598 irq_set_chip_data(irq, NULL);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100599 }
600}
601
602/*--------------------------------------------------------------------------*/
603
Bill Pembertonf791be42012-11-19 13:23:04 -0500604static int tc6393xb_probe(struct platform_device *dev)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100605{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900606 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100607 struct tc6393xb *tc6393xb;
Ian Molton25d6cbd82008-08-10 23:32:07 +0200608 struct resource *iomem, *rscr;
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200609 int ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100610
611 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
612 if (!iomem)
613 return -EINVAL;
614
615 tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
616 if (!tc6393xb) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200617 ret = -ENOMEM;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100618 goto err_kzalloc;
619 }
620
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500621 raw_spin_lock_init(&tc6393xb->lock);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100622
623 platform_set_drvdata(dev, tc6393xb);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200624
625 ret = platform_get_irq(dev, 0);
626 if (ret >= 0)
627 tc6393xb->irq = ret;
628 else
629 goto err_noirq;
630
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100631 tc6393xb->iomem = iomem;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100632 tc6393xb->irq_base = tcpd->irq_base;
633
Ian Molton25d6cbd82008-08-10 23:32:07 +0200634 tc6393xb->clk = clk_get(&dev->dev, "CLK_CK3P6MI");
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100635 if (IS_ERR(tc6393xb->clk)) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200636 ret = PTR_ERR(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100637 goto err_clk_get;
638 }
639
640 rscr = &tc6393xb->rscr;
641 rscr->name = "tc6393xb-core";
642 rscr->start = iomem->start;
643 rscr->end = iomem->start + 0xff;
644 rscr->flags = IORESOURCE_MEM;
645
Ian Molton25d6cbd82008-08-10 23:32:07 +0200646 ret = request_resource(iomem, rscr);
647 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100648 goto err_request_scr;
649
H Hartley Sweeten1ecc09e2010-01-05 20:01:16 +0100650 tc6393xb->scr = ioremap(rscr->start, resource_size(rscr));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100651 if (!tc6393xb->scr) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200652 ret = -ENOMEM;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100653 goto err_ioremap;
654 }
655
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300656 ret = clk_prepare_enable(tc6393xb->clk);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200657 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100658 goto err_clk_enable;
659
Ian Molton25d6cbd82008-08-10 23:32:07 +0200660 ret = tcpd->enable(dev);
661 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100662 goto err_enable;
663
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200664 iowrite8(0, tc6393xb->scr + SCR_FER);
665 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
666 iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48,
667 tc6393xb->scr + SCR_CCR);
668 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
669 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
670 BIT(15), tc6393xb->scr + SCR_MCR);
671 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
672 iowrite8(0, tc6393xb->scr + SCR_IRR);
673 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100674
675 printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
Ian Molton25d6cbd82008-08-10 23:32:07 +0200676 tmio_ioread8(tc6393xb->scr + SCR_REVID),
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100677 (unsigned long) iomem->start, tc6393xb->irq);
678
679 tc6393xb->gpio.base = -1;
680
681 if (tcpd->gpio_base >= 0) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200682 ret = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base);
683 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100684 goto err_gpio_add;
685 }
686
Ian Molton25d6cbd82008-08-10 23:32:07 +0200687 tc6393xb_attach_irq(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100688
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200689 if (tcpd->setup) {
690 ret = tcpd->setup(dev);
691 if (ret)
692 goto err_setup;
693 }
694
Samuel Ortiz7dc00a02011-04-06 12:20:49 +0200695 tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = tcpd->nand_data;
696 tc6393xb_cells[TC6393XB_CELL_NAND].pdata_size =
697 sizeof(*tcpd->nand_data);
Samuel Ortiz1f8c6662011-04-06 12:13:25 +0200698 tc6393xb_cells[TC6393XB_CELL_FB].platform_data = tcpd->fb_data;
699 tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200700
701 ret = mfd_add_devices(&dev->dev, dev->id,
Mark Brown0848c942012-09-11 15:16:36 +0800702 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
703 iomem, tcpd->irq_base, NULL);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100704
Ian Molton25d6cbd82008-08-10 23:32:07 +0200705 if (!ret)
706 return 0;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100707
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200708 if (tcpd->teardown)
709 tcpd->teardown(dev);
710
711err_setup:
Ian Molton25d6cbd82008-08-10 23:32:07 +0200712 tc6393xb_detach_irq(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100713
714err_gpio_add:
715 if (tc6393xb->gpio.base != -1)
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200716 gpiochip_remove(&tc6393xb->gpio);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100717 tcpd->disable(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100718err_enable:
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300719 clk_disable_unprepare(tc6393xb->clk);
Axel Linfa6e4b12010-08-03 11:10:41 +0800720err_clk_enable:
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100721 iounmap(tc6393xb->scr);
722err_ioremap:
723 release_resource(&tc6393xb->rscr);
724err_request_scr:
725 clk_put(tc6393xb->clk);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200726err_noirq:
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100727err_clk_get:
728 kfree(tc6393xb);
729err_kzalloc:
Ian Molton25d6cbd82008-08-10 23:32:07 +0200730 return ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100731}
732
Bill Pemberton4740f732012-11-19 13:26:01 -0500733static int tc6393xb_remove(struct platform_device *dev)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100734{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900735 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100736 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
737 int ret;
738
Dmitry Baryshkov424f5252008-07-29 01:30:26 +0200739 mfd_remove_devices(&dev->dev);
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200740
741 if (tcpd->teardown)
742 tcpd->teardown(dev);
743
Ian Molton25d6cbd82008-08-10 23:32:07 +0200744 tc6393xb_detach_irq(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100745
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200746 if (tc6393xb->gpio.base != -1)
747 gpiochip_remove(&tc6393xb->gpio);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100748
749 ret = tcpd->disable(dev);
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300750 clk_disable_unprepare(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100751 iounmap(tc6393xb->scr);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100752 release_resource(&tc6393xb->rscr);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100753 clk_put(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100754 kfree(tc6393xb);
755
756 return ret;
757}
758
759#ifdef CONFIG_PM
760static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
761{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900762 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100763 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200764 int i, ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100765
766 tc6393xb->suspend_state.ccr = ioread16(tc6393xb->scr + SCR_CCR);
767 tc6393xb->suspend_state.fer = ioread8(tc6393xb->scr + SCR_FER);
768
769 for (i = 0; i < 3; i++) {
770 tc6393xb->suspend_state.gpo_dsr[i] =
771 ioread8(tc6393xb->scr + SCR_GPO_DSR(i));
772 tc6393xb->suspend_state.gpo_doecr[i] =
773 ioread8(tc6393xb->scr + SCR_GPO_DOECR(i));
774 tc6393xb->suspend_state.gpi_bcr[i] =
775 ioread8(tc6393xb->scr + SCR_GPI_BCR(i));
776 }
Ian Molton25d6cbd82008-08-10 23:32:07 +0200777 ret = tcpd->suspend(dev);
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300778 clk_disable_unprepare(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100779
Ian Molton25d6cbd82008-08-10 23:32:07 +0200780 return ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100781}
782
783static int tc6393xb_resume(struct platform_device *dev)
784{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900785 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200786 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
787 int ret;
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200788 int i;
Ian Molton25d6cbd82008-08-10 23:32:07 +0200789
Arvind Yadavb6678052017-06-01 12:44:50 +0530790 ret = clk_prepare_enable(tc6393xb->clk);
791 if (ret)
792 return ret;
Ian Molton25d6cbd82008-08-10 23:32:07 +0200793
794 ret = tcpd->resume(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100795 if (ret)
796 return ret;
797
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200798 if (!tcpd->resume_restore)
799 return 0;
800
801 iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
802 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
803 iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
804 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
805 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
806 BIT(15), tc6393xb->scr + SCR_MCR);
807 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
808 iowrite8(0, tc6393xb->scr + SCR_IRR);
809 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
810
811 for (i = 0; i < 3; i++) {
812 iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
813 tc6393xb->scr + SCR_GPO_DSR(i));
814 iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
815 tc6393xb->scr + SCR_GPO_DOECR(i));
816 iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
817 tc6393xb->scr + SCR_GPI_BCR(i));
818 }
819
820 return 0;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100821}
822#else
823#define tc6393xb_suspend NULL
824#define tc6393xb_resume NULL
825#endif
826
827static struct platform_driver tc6393xb_driver = {
828 .probe = tc6393xb_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500829 .remove = tc6393xb_remove,
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100830 .suspend = tc6393xb_suspend,
831 .resume = tc6393xb_resume,
832
833 .driver = {
834 .name = "tc6393xb",
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100835 },
836};
837
838static int __init tc6393xb_init(void)
839{
840 return platform_driver_register(&tc6393xb_driver);
841}
842
843static void __exit tc6393xb_exit(void)
844{
845 platform_driver_unregister(&tc6393xb_driver);
846}
847
848subsys_initcall(tc6393xb_init);
849module_exit(tc6393xb_exit);
850
Ian Molton25d6cbd82008-08-10 23:32:07 +0200851MODULE_LICENSE("GPL v2");
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100852MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
853MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
854MODULE_ALIAS("platform:tc6393xb");
Ian Molton64e88672010-01-06 13:51:48 +0100855