blob: 6943048a64c2c34f38b946f43b42f404fcbe3076 [file] [log] [blame]
Dmitry Baryshkovd6315942008-06-22 12:01:58 +01001/*
2 * Toshiba TC6393XB SoC support
3 *
4 * Copyright(c) 2005-2006 Chris Humbert
5 * Copyright(c) 2005 Dirk Opfer
6 * Copyright(c) 2005 Ian Molton <spyro@f2s.com>
7 * Copyright(c) 2007 Dmitry Baryshkov
8 *
9 * Based on code written by Sharp/Lineo for 2.4 kernels
10 * Based on locomo.c
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/io.h>
20#include <linux/irq.h>
21#include <linux/platform_device.h>
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010022#include <linux/clk.h>
Ian Molton25d6cbd82008-08-10 23:32:07 +020023#include <linux/err.h>
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +010024#include <linux/mfd/core.h>
25#include <linux/mfd/tmio.h>
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010026#include <linux/mfd/tc6393xb.h>
Linus Walleij4e125f62016-03-30 10:48:06 +020027#include <linux/gpio/driver.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010029
30#define SCR_REVID 0x08 /* b Revision ID */
31#define SCR_ISR 0x50 /* b Interrupt Status */
32#define SCR_IMR 0x52 /* b Interrupt Mask */
33#define SCR_IRR 0x54 /* b Interrupt Routing */
34#define SCR_GPER 0x60 /* w GP Enable */
35#define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
36#define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
37#define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
38#define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
39#define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
40#define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
41#define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
42#define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
43#define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
44#define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
45#define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
46#define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
47#define SCR_CCR 0x98 /* w Clock Control */
48#define SCR_PLL2CR 0x9a /* w PLL2 Control */
49#define SCR_PLL1CR 0x9c /* l PLL1 Control */
50#define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
51#define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
52#define SCR_FER 0xe0 /* b Function Enable */
53#define SCR_MCR 0xe4 /* w Mode Control */
54#define SCR_CONFIG 0xfc /* b Configuration Control */
55#define SCR_DEBUG 0xff /* b Debug */
56
57#define SCR_CCR_CK32K BIT(0)
58#define SCR_CCR_USBCK BIT(1)
59#define SCR_CCR_UNK1 BIT(4)
60#define SCR_CCR_MCLK_MASK (7 << 8)
61#define SCR_CCR_MCLK_OFF (0 << 8)
62#define SCR_CCR_MCLK_12 (1 << 8)
63#define SCR_CCR_MCLK_24 (2 << 8)
64#define SCR_CCR_MCLK_48 (3 << 8)
65#define SCR_CCR_HCLK_MASK (3 << 12)
66#define SCR_CCR_HCLK_24 (0 << 12)
67#define SCR_CCR_HCLK_48 (1 << 12)
68
69#define SCR_FER_USBEN BIT(0) /* USB host enable */
70#define SCR_FER_LCDCVEN BIT(1) /* polysilicon TFT enable */
71#define SCR_FER_SLCDEN BIT(2) /* SLCD enable */
72
73#define SCR_MCR_RDY_MASK (3 << 0)
74#define SCR_MCR_RDY_OPENDRAIN (0 << 0)
75#define SCR_MCR_RDY_TRISTATE (1 << 0)
76#define SCR_MCR_RDY_PUSHPULL (2 << 0)
77#define SCR_MCR_RDY_UNK BIT(2)
78#define SCR_MCR_RDY_EN BIT(3)
79#define SCR_MCR_INT_MASK (3 << 4)
80#define SCR_MCR_INT_OPENDRAIN (0 << 4)
81#define SCR_MCR_INT_TRISTATE (1 << 4)
82#define SCR_MCR_INT_PUSHPULL (2 << 4)
83#define SCR_MCR_INT_UNK BIT(6)
84#define SCR_MCR_INT_EN BIT(7)
85/* bits 8 - 16 are unknown */
86
87#define TC_GPIO_BIT(i) (1 << (i & 0x7))
88
89/*--------------------------------------------------------------------------*/
90
91struct tc6393xb {
92 void __iomem *scr;
93
94 struct gpio_chip gpio;
95
96 struct clk *clk; /* 3,6 Mhz */
97
Julia Cartwrightf5139c22017-03-21 17:43:06 -050098 raw_spinlock_t lock; /* protects RMW cycles */
Dmitry Baryshkovd6315942008-06-22 12:01:58 +010099
100 struct {
101 u8 fer;
102 u16 ccr;
103 u8 gpi_bcr[3];
104 u8 gpo_dsr[3];
105 u8 gpo_doecr[3];
106 } suspend_state;
107
108 struct resource rscr;
109 struct resource *iomem;
110 int irq;
111 int irq_base;
112};
113
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100114enum {
115 TC6393XB_CELL_NAND,
Ian Molton25d6cbd82008-08-10 23:32:07 +0200116 TC6393XB_CELL_MMC,
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200117 TC6393XB_CELL_OHCI,
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200118 TC6393XB_CELL_FB,
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100119};
120
121/*--------------------------------------------------------------------------*/
122
123static int tc6393xb_nand_enable(struct platform_device *nand)
124{
Kefeng Wanged835132019-05-09 22:23:39 +0800125 struct tc6393xb *tc6393xb = dev_get_drvdata(nand->dev.parent);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100126 unsigned long flags;
127
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500128 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100129
130 /* SMD buffer on */
Kefeng Wanged835132019-05-09 22:23:39 +0800131 dev_dbg(nand->dev.parent, "SMD buffer on\n");
Ian Molton25d6cbd82008-08-10 23:32:07 +0200132 tmio_iowrite8(0xff, tc6393xb->scr + SCR_GPI_BCR(1));
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100133
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500134 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100135
136 return 0;
137}
138
Bill Pembertona9e9ce42012-11-19 13:24:21 -0500139static struct resource tc6393xb_nand_resources[] = {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100140 {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100141 .start = 0x1000,
142 .end = 0x1007,
143 .flags = IORESOURCE_MEM,
144 },
145 {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200146 .start = 0x0100,
147 .end = 0x01ff,
148 .flags = IORESOURCE_MEM,
149 },
150 {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100151 .start = IRQ_TC6393_NAND,
152 .end = IRQ_TC6393_NAND,
153 .flags = IORESOURCE_IRQ,
154 },
155};
156
Marek Vasut7745cc82010-10-10 03:55:43 +0200157static struct resource tc6393xb_mmc_resources[] = {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200158 {
159 .start = 0x800,
160 .end = 0x9ff,
161 .flags = IORESOURCE_MEM,
162 },
163 {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200164 .start = IRQ_TC6393_MMC,
165 .end = IRQ_TC6393_MMC,
166 .flags = IORESOURCE_IRQ,
167 },
168};
169
Tobias Klauser3446d4b2009-02-17 10:11:42 +0100170static const struct resource tc6393xb_ohci_resources[] = {
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200171 {
172 .start = 0x3000,
173 .end = 0x31ff,
174 .flags = IORESOURCE_MEM,
175 },
176 {
177 .start = 0x0300,
178 .end = 0x03ff,
179 .flags = IORESOURCE_MEM,
180 },
181 {
182 .start = 0x010000,
183 .end = 0x017fff,
184 .flags = IORESOURCE_MEM,
185 },
186 {
187 .start = 0x018000,
188 .end = 0x01ffff,
189 .flags = IORESOURCE_MEM,
190 },
191 {
192 .start = IRQ_TC6393_OHCI,
193 .end = IRQ_TC6393_OHCI,
194 .flags = IORESOURCE_IRQ,
195 },
196};
197
Bill Pembertona9e9ce42012-11-19 13:24:21 -0500198static struct resource tc6393xb_fb_resources[] = {
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200199 {
200 .start = 0x5000,
201 .end = 0x51ff,
202 .flags = IORESOURCE_MEM,
203 },
204 {
205 .start = 0x0500,
206 .end = 0x05ff,
207 .flags = IORESOURCE_MEM,
208 },
209 {
210 .start = 0x100000,
211 .end = 0x1fffff,
212 .flags = IORESOURCE_MEM,
213 },
214 {
215 .start = IRQ_TC6393_FB,
216 .end = IRQ_TC6393_FB,
217 .flags = IORESOURCE_IRQ,
218 },
219};
220
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200221static int tc6393xb_ohci_enable(struct platform_device *dev)
222{
223 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
224 unsigned long flags;
225 u16 ccr;
226 u8 fer;
227
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500228 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200229
230 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
231 ccr |= SCR_CCR_USBCK;
232 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
233
234 fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
235 fer |= SCR_FER_USBEN;
236 tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
237
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500238 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200239
240 return 0;
241}
242
243static int tc6393xb_ohci_disable(struct platform_device *dev)
244{
245 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
246 unsigned long flags;
247 u16 ccr;
248 u8 fer;
249
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500250 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200251
252 fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
253 fer &= ~SCR_FER_USBEN;
254 tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
255
256 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
257 ccr &= ~SCR_CCR_USBCK;
258 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
259
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500260 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200261
262 return 0;
263}
264
Dmitry Eremin-Solenikov1a5fb992014-10-24 21:19:57 +0400265static int tc6393xb_ohci_suspend(struct platform_device *dev)
266{
267 struct tc6393xb_platform_data *tcpd = dev_get_platdata(dev->dev.parent);
268
269 /* We can't properly store/restore OHCI state, so fail here */
270 if (tcpd->resume_restore)
271 return -EBUSY;
272
273 return tc6393xb_ohci_disable(dev);
274}
275
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200276static int tc6393xb_fb_enable(struct platform_device *dev)
277{
278 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
279 unsigned long flags;
280 u16 ccr;
281
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500282 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200283
284 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
285 ccr &= ~SCR_CCR_MCLK_MASK;
286 ccr |= SCR_CCR_MCLK_48;
287 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
288
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500289 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200290
291 return 0;
292}
293
294static int tc6393xb_fb_disable(struct platform_device *dev)
295{
296 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
297 unsigned long flags;
298 u16 ccr;
299
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500300 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200301
302 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
303 ccr &= ~SCR_CCR_MCLK_MASK;
304 ccr |= SCR_CCR_MCLK_OFF;
305 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
306
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500307 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200308
309 return 0;
310}
311
312int tc6393xb_lcd_set_power(struct platform_device *fb, bool on)
313{
Kefeng Wanged835132019-05-09 22:23:39 +0800314 struct tc6393xb *tc6393xb = dev_get_drvdata(fb->dev.parent);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200315 u8 fer;
316 unsigned long flags;
317
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500318 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200319
320 fer = ioread8(tc6393xb->scr + SCR_FER);
321 if (on)
322 fer |= SCR_FER_SLCDEN;
323 else
324 fer &= ~SCR_FER_SLCDEN;
325 iowrite8(fer, tc6393xb->scr + SCR_FER);
326
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500327 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200328
329 return 0;
330}
331EXPORT_SYMBOL(tc6393xb_lcd_set_power);
332
333int tc6393xb_lcd_mode(struct platform_device *fb,
334 const struct fb_videomode *mode) {
Kefeng Wanged835132019-05-09 22:23:39 +0800335 struct tc6393xb *tc6393xb = dev_get_drvdata(fb->dev.parent);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200336 unsigned long flags;
337
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500338 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200339
340 iowrite16(mode->pixclock, tc6393xb->scr + SCR_PLL1CR + 0);
341 iowrite16(mode->pixclock >> 16, tc6393xb->scr + SCR_PLL1CR + 2);
342
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500343 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200344
345 return 0;
346}
347EXPORT_SYMBOL(tc6393xb_lcd_mode);
348
Ian Molton64e88672010-01-06 13:51:48 +0100349static int tc6393xb_mmc_enable(struct platform_device *mmc)
350{
Kefeng Wanged835132019-05-09 22:23:39 +0800351 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100352
353 tmio_core_mmc_enable(tc6393xb->scr + 0x200, 0,
354 tc6393xb_mmc_resources[0].start & 0xfffe);
355
356 return 0;
357}
358
359static int tc6393xb_mmc_resume(struct platform_device *mmc)
360{
Kefeng Wanged835132019-05-09 22:23:39 +0800361 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100362
363 tmio_core_mmc_resume(tc6393xb->scr + 0x200, 0,
364 tc6393xb_mmc_resources[0].start & 0xfffe);
365
366 return 0;
367}
368
369static void tc6393xb_mmc_pwr(struct platform_device *mmc, int state)
370{
Kefeng Wanged835132019-05-09 22:23:39 +0800371 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100372
373 tmio_core_mmc_pwr(tc6393xb->scr + 0x200, 0, state);
374}
375
376static void tc6393xb_mmc_clk_div(struct platform_device *mmc, int state)
377{
Kefeng Wanged835132019-05-09 22:23:39 +0800378 struct tc6393xb *tc6393xb = dev_get_drvdata(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100379
380 tmio_core_mmc_clk_div(tc6393xb->scr + 0x200, 0, state);
381}
382
383static struct tmio_mmc_data tc6393xb_mmc_data = {
384 .hclk = 24000000,
385 .set_pwr = tc6393xb_mmc_pwr,
386 .set_clk_div = tc6393xb_mmc_clk_div,
387};
388
Bill Pembertona9e9ce42012-11-19 13:24:21 -0500389static struct mfd_cell tc6393xb_cells[] = {
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100390 [TC6393XB_CELL_NAND] = {
391 .name = "tmio-nand",
392 .enable = tc6393xb_nand_enable,
393 .num_resources = ARRAY_SIZE(tc6393xb_nand_resources),
394 .resources = tc6393xb_nand_resources,
395 },
Ian Molton25d6cbd82008-08-10 23:32:07 +0200396 [TC6393XB_CELL_MMC] = {
397 .name = "tmio-mmc",
Ian Molton64e88672010-01-06 13:51:48 +0100398 .enable = tc6393xb_mmc_enable,
399 .resume = tc6393xb_mmc_resume,
Samuel Ortizec719742011-04-06 11:38:14 +0200400 .platform_data = &tc6393xb_mmc_data,
401 .pdata_size = sizeof(tc6393xb_mmc_data),
Ian Molton25d6cbd82008-08-10 23:32:07 +0200402 .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources),
403 .resources = tc6393xb_mmc_resources,
404 },
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200405 [TC6393XB_CELL_OHCI] = {
406 .name = "tmio-ohci",
407 .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
408 .resources = tc6393xb_ohci_resources,
409 .enable = tc6393xb_ohci_enable,
Dmitry Eremin-Solenikov1a5fb992014-10-24 21:19:57 +0400410 .suspend = tc6393xb_ohci_suspend,
Dmitry Baryshkov51a55622008-10-03 20:11:36 +0200411 .resume = tc6393xb_ohci_enable,
412 .disable = tc6393xb_ohci_disable,
413 },
Dmitry Baryshkov9e78cfe2008-10-04 00:50:36 +0200414 [TC6393XB_CELL_FB] = {
415 .name = "tmio-fb",
416 .num_resources = ARRAY_SIZE(tc6393xb_fb_resources),
417 .resources = tc6393xb_fb_resources,
418 .enable = tc6393xb_fb_enable,
419 .suspend = tc6393xb_fb_disable,
420 .resume = tc6393xb_fb_enable,
421 .disable = tc6393xb_fb_disable,
422 },
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100423};
424
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100425/*--------------------------------------------------------------------------*/
426
427static int tc6393xb_gpio_get(struct gpio_chip *chip,
428 unsigned offset)
429{
Linus Walleij4e125f62016-03-30 10:48:06 +0200430 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100431
432 /* XXX: does dsr also represent inputs? */
Linus Walleij2d5f72b82015-12-22 15:47:55 +0100433 return !!(tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8))
434 & TC_GPIO_BIT(offset));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100435}
436
437static void __tc6393xb_gpio_set(struct gpio_chip *chip,
438 unsigned offset, int value)
439{
Linus Walleij4e125f62016-03-30 10:48:06 +0200440 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100441 u8 dsr;
442
Ian Molton25d6cbd82008-08-10 23:32:07 +0200443 dsr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100444 if (value)
445 dsr |= TC_GPIO_BIT(offset);
446 else
447 dsr &= ~TC_GPIO_BIT(offset);
448
Ian Molton25d6cbd82008-08-10 23:32:07 +0200449 tmio_iowrite8(dsr, tc6393xb->scr + SCR_GPO_DSR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100450}
451
452static void tc6393xb_gpio_set(struct gpio_chip *chip,
453 unsigned offset, int value)
454{
Linus Walleij4e125f62016-03-30 10:48:06 +0200455 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100456 unsigned long flags;
457
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500458 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100459
460 __tc6393xb_gpio_set(chip, offset, value);
461
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500462 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100463}
464
465static int tc6393xb_gpio_direction_input(struct gpio_chip *chip,
466 unsigned offset)
467{
Linus Walleij4e125f62016-03-30 10:48:06 +0200468 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100469 unsigned long flags;
470 u8 doecr;
471
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500472 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100473
Ian Molton25d6cbd82008-08-10 23:32:07 +0200474 doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100475 doecr &= ~TC_GPIO_BIT(offset);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200476 tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100477
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500478 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100479
480 return 0;
481}
482
483static int tc6393xb_gpio_direction_output(struct gpio_chip *chip,
484 unsigned offset, int value)
485{
Linus Walleij4e125f62016-03-30 10:48:06 +0200486 struct tc6393xb *tc6393xb = gpiochip_get_data(chip);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100487 unsigned long flags;
488 u8 doecr;
489
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500490 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100491
492 __tc6393xb_gpio_set(chip, offset, value);
493
Ian Molton25d6cbd82008-08-10 23:32:07 +0200494 doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100495 doecr |= TC_GPIO_BIT(offset);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200496 tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100497
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500498 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100499
500 return 0;
501}
502
503static int tc6393xb_register_gpio(struct tc6393xb *tc6393xb, int gpio_base)
504{
505 tc6393xb->gpio.label = "tc6393xb";
506 tc6393xb->gpio.base = gpio_base;
507 tc6393xb->gpio.ngpio = 16;
508 tc6393xb->gpio.set = tc6393xb_gpio_set;
509 tc6393xb->gpio.get = tc6393xb_gpio_get;
510 tc6393xb->gpio.direction_input = tc6393xb_gpio_direction_input;
511 tc6393xb->gpio.direction_output = tc6393xb_gpio_direction_output;
512
Linus Walleij4e125f62016-03-30 10:48:06 +0200513 return gpiochip_add_data(&tc6393xb->gpio, tc6393xb);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100514}
515
516/*--------------------------------------------------------------------------*/
517
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200518static void tc6393xb_irq(struct irq_desc *desc)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100519{
Jiang Liu1e84aa42015-07-13 20:44:56 +0000520 struct tc6393xb *tc6393xb = irq_desc_get_handler_data(desc);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100521 unsigned int isr;
522 unsigned int i, irq_base;
523
524 irq_base = tc6393xb->irq_base;
525
Ian Molton25d6cbd82008-08-10 23:32:07 +0200526 while ((isr = tmio_ioread8(tc6393xb->scr + SCR_ISR) &
527 ~tmio_ioread8(tc6393xb->scr + SCR_IMR)))
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100528 for (i = 0; i < TC6393XB_NR_IRQS; i++) {
529 if (isr & (1 << i))
530 generic_handle_irq(irq_base + i);
531 }
532}
533
Mark Brown01af22e2010-12-12 12:34:04 +0000534static void tc6393xb_irq_ack(struct irq_data *data)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100535{
536}
537
Mark Brown01af22e2010-12-12 12:34:04 +0000538static void tc6393xb_irq_mask(struct irq_data *data)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100539{
Mark Brown01af22e2010-12-12 12:34:04 +0000540 struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100541 unsigned long flags;
542 u8 imr;
543
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500544 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200545 imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
Mark Brown01af22e2010-12-12 12:34:04 +0000546 imr |= 1 << (data->irq - tc6393xb->irq_base);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200547 tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500548 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100549}
550
Mark Brown01af22e2010-12-12 12:34:04 +0000551static void tc6393xb_irq_unmask(struct irq_data *data)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100552{
Mark Brown01af22e2010-12-12 12:34:04 +0000553 struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100554 unsigned long flags;
555 u8 imr;
556
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500557 raw_spin_lock_irqsave(&tc6393xb->lock, flags);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200558 imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
Mark Brown01af22e2010-12-12 12:34:04 +0000559 imr &= ~(1 << (data->irq - tc6393xb->irq_base));
Ian Molton25d6cbd82008-08-10 23:32:07 +0200560 tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500561 raw_spin_unlock_irqrestore(&tc6393xb->lock, flags);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100562}
563
564static struct irq_chip tc6393xb_chip = {
Mark Brown01af22e2010-12-12 12:34:04 +0000565 .name = "tc6393xb",
566 .irq_ack = tc6393xb_irq_ack,
567 .irq_mask = tc6393xb_irq_mask,
568 .irq_unmask = tc6393xb_irq_unmask,
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100569};
570
571static void tc6393xb_attach_irq(struct platform_device *dev)
572{
573 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
574 unsigned int irq, irq_base;
575
576 irq_base = tc6393xb->irq_base;
577
578 for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
Thomas Gleixnerd6f7ce9f2011-03-25 11:12:35 +0000579 irq_set_chip_and_handler(irq, &tc6393xb_chip, handle_edge_irq);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000580 irq_set_chip_data(irq, tc6393xb);
Rob Herring9bd09f32015-07-27 15:55:20 -0500581 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100582 }
583
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000584 irq_set_irq_type(tc6393xb->irq, IRQ_TYPE_EDGE_FALLING);
Thomas Gleixner079140f2015-07-13 20:44:54 +0000585 irq_set_chained_handler_and_data(tc6393xb->irq, tc6393xb_irq,
586 tc6393xb);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100587}
588
589static void tc6393xb_detach_irq(struct platform_device *dev)
590{
591 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
592 unsigned int irq, irq_base;
593
Thomas Gleixner079140f2015-07-13 20:44:54 +0000594 irq_set_chained_handler_and_data(tc6393xb->irq, NULL, NULL);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100595
596 irq_base = tc6393xb->irq_base;
597
598 for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
Rob Herring9bd09f32015-07-27 15:55:20 -0500599 irq_set_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000600 irq_set_chip(irq, NULL);
601 irq_set_chip_data(irq, NULL);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100602 }
603}
604
605/*--------------------------------------------------------------------------*/
606
Bill Pembertonf791be42012-11-19 13:23:04 -0500607static int tc6393xb_probe(struct platform_device *dev)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100608{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900609 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100610 struct tc6393xb *tc6393xb;
Ian Molton25d6cbd82008-08-10 23:32:07 +0200611 struct resource *iomem, *rscr;
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200612 int ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100613
614 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
615 if (!iomem)
616 return -EINVAL;
617
618 tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
619 if (!tc6393xb) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200620 ret = -ENOMEM;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100621 goto err_kzalloc;
622 }
623
Julia Cartwrightf5139c22017-03-21 17:43:06 -0500624 raw_spin_lock_init(&tc6393xb->lock);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100625
626 platform_set_drvdata(dev, tc6393xb);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200627
628 ret = platform_get_irq(dev, 0);
629 if (ret >= 0)
630 tc6393xb->irq = ret;
631 else
632 goto err_noirq;
633
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100634 tc6393xb->iomem = iomem;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100635 tc6393xb->irq_base = tcpd->irq_base;
636
Ian Molton25d6cbd82008-08-10 23:32:07 +0200637 tc6393xb->clk = clk_get(&dev->dev, "CLK_CK3P6MI");
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100638 if (IS_ERR(tc6393xb->clk)) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200639 ret = PTR_ERR(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100640 goto err_clk_get;
641 }
642
643 rscr = &tc6393xb->rscr;
644 rscr->name = "tc6393xb-core";
645 rscr->start = iomem->start;
646 rscr->end = iomem->start + 0xff;
647 rscr->flags = IORESOURCE_MEM;
648
Ian Molton25d6cbd82008-08-10 23:32:07 +0200649 ret = request_resource(iomem, rscr);
650 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100651 goto err_request_scr;
652
H Hartley Sweeten1ecc09e2010-01-05 20:01:16 +0100653 tc6393xb->scr = ioremap(rscr->start, resource_size(rscr));
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100654 if (!tc6393xb->scr) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200655 ret = -ENOMEM;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100656 goto err_ioremap;
657 }
658
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300659 ret = clk_prepare_enable(tc6393xb->clk);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200660 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100661 goto err_clk_enable;
662
Ian Molton25d6cbd82008-08-10 23:32:07 +0200663 ret = tcpd->enable(dev);
664 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100665 goto err_enable;
666
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200667 iowrite8(0, tc6393xb->scr + SCR_FER);
668 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
669 iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48,
670 tc6393xb->scr + SCR_CCR);
671 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
672 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
673 BIT(15), tc6393xb->scr + SCR_MCR);
674 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
675 iowrite8(0, tc6393xb->scr + SCR_IRR);
676 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100677
678 printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
Ian Molton25d6cbd82008-08-10 23:32:07 +0200679 tmio_ioread8(tc6393xb->scr + SCR_REVID),
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100680 (unsigned long) iomem->start, tc6393xb->irq);
681
682 tc6393xb->gpio.base = -1;
683
684 if (tcpd->gpio_base >= 0) {
Ian Molton25d6cbd82008-08-10 23:32:07 +0200685 ret = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base);
686 if (ret)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100687 goto err_gpio_add;
688 }
689
Ian Molton25d6cbd82008-08-10 23:32:07 +0200690 tc6393xb_attach_irq(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100691
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200692 if (tcpd->setup) {
693 ret = tcpd->setup(dev);
694 if (ret)
695 goto err_setup;
696 }
697
Samuel Ortiz7dc00a02011-04-06 12:20:49 +0200698 tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = tcpd->nand_data;
699 tc6393xb_cells[TC6393XB_CELL_NAND].pdata_size =
700 sizeof(*tcpd->nand_data);
Samuel Ortiz1f8c6662011-04-06 12:13:25 +0200701 tc6393xb_cells[TC6393XB_CELL_FB].platform_data = tcpd->fb_data;
702 tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200703
704 ret = mfd_add_devices(&dev->dev, dev->id,
Mark Brown0848c942012-09-11 15:16:36 +0800705 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
706 iomem, tcpd->irq_base, NULL);
Dmitry Baryshkovf024ff12008-06-27 10:37:57 +0100707
Ian Molton25d6cbd82008-08-10 23:32:07 +0200708 if (!ret)
709 return 0;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100710
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200711 if (tcpd->teardown)
712 tcpd->teardown(dev);
713
714err_setup:
Ian Molton25d6cbd82008-08-10 23:32:07 +0200715 tc6393xb_detach_irq(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100716
717err_gpio_add:
718 if (tc6393xb->gpio.base != -1)
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200719 gpiochip_remove(&tc6393xb->gpio);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100720 tcpd->disable(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100721err_enable:
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300722 clk_disable_unprepare(tc6393xb->clk);
Axel Linfa6e4b12010-08-03 11:10:41 +0800723err_clk_enable:
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100724 iounmap(tc6393xb->scr);
725err_ioremap:
726 release_resource(&tc6393xb->rscr);
727err_request_scr:
728 clk_put(tc6393xb->clk);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200729err_noirq:
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100730err_clk_get:
731 kfree(tc6393xb);
732err_kzalloc:
Ian Molton25d6cbd82008-08-10 23:32:07 +0200733 return ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100734}
735
Bill Pemberton4740f732012-11-19 13:26:01 -0500736static int tc6393xb_remove(struct platform_device *dev)
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100737{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900738 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100739 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
740 int ret;
741
Dmitry Baryshkov424f5252008-07-29 01:30:26 +0200742 mfd_remove_devices(&dev->dev);
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200743
744 if (tcpd->teardown)
745 tcpd->teardown(dev);
746
Ian Molton25d6cbd82008-08-10 23:32:07 +0200747 tc6393xb_detach_irq(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100748
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200749 if (tc6393xb->gpio.base != -1)
750 gpiochip_remove(&tc6393xb->gpio);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100751
752 ret = tcpd->disable(dev);
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300753 clk_disable_unprepare(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100754 iounmap(tc6393xb->scr);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100755 release_resource(&tc6393xb->rscr);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100756 clk_put(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100757 kfree(tc6393xb);
758
759 return ret;
760}
761
762#ifdef CONFIG_PM
763static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
764{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900765 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100766 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200767 int i, ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100768
769 tc6393xb->suspend_state.ccr = ioread16(tc6393xb->scr + SCR_CCR);
770 tc6393xb->suspend_state.fer = ioread8(tc6393xb->scr + SCR_FER);
771
772 for (i = 0; i < 3; i++) {
773 tc6393xb->suspend_state.gpo_dsr[i] =
774 ioread8(tc6393xb->scr + SCR_GPO_DSR(i));
775 tc6393xb->suspend_state.gpo_doecr[i] =
776 ioread8(tc6393xb->scr + SCR_GPO_DOECR(i));
777 tc6393xb->suspend_state.gpi_bcr[i] =
778 ioread8(tc6393xb->scr + SCR_GPI_BCR(i));
779 }
Ian Molton25d6cbd82008-08-10 23:32:07 +0200780 ret = tcpd->suspend(dev);
Dmitry Eremin-Solenikova64ab6b2014-11-06 11:52:38 +0300781 clk_disable_unprepare(tc6393xb->clk);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100782
Ian Molton25d6cbd82008-08-10 23:32:07 +0200783 return ret;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100784}
785
786static int tc6393xb_resume(struct platform_device *dev)
787{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900788 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
Ian Molton25d6cbd82008-08-10 23:32:07 +0200789 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
790 int ret;
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200791 int i;
Ian Molton25d6cbd82008-08-10 23:32:07 +0200792
Arvind Yadavb6678052017-06-01 12:44:50 +0530793 ret = clk_prepare_enable(tc6393xb->clk);
794 if (ret)
795 return ret;
Ian Molton25d6cbd82008-08-10 23:32:07 +0200796
797 ret = tcpd->resume(dev);
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100798 if (ret)
799 return ret;
800
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200801 if (!tcpd->resume_restore)
802 return 0;
803
804 iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
805 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
806 iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
807 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
808 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
809 BIT(15), tc6393xb->scr + SCR_MCR);
810 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
811 iowrite8(0, tc6393xb->scr + SCR_IRR);
812 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
813
814 for (i = 0; i < 3; i++) {
815 iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
816 tc6393xb->scr + SCR_GPO_DSR(i));
817 iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
818 tc6393xb->scr + SCR_GPO_DOECR(i));
819 iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
820 tc6393xb->scr + SCR_GPI_BCR(i));
821 }
822
823 return 0;
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100824}
825#else
826#define tc6393xb_suspend NULL
827#define tc6393xb_resume NULL
828#endif
829
830static struct platform_driver tc6393xb_driver = {
831 .probe = tc6393xb_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500832 .remove = tc6393xb_remove,
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100833 .suspend = tc6393xb_suspend,
834 .resume = tc6393xb_resume,
835
836 .driver = {
837 .name = "tc6393xb",
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100838 },
839};
840
841static int __init tc6393xb_init(void)
842{
843 return platform_driver_register(&tc6393xb_driver);
844}
845
846static void __exit tc6393xb_exit(void)
847{
848 platform_driver_unregister(&tc6393xb_driver);
849}
850
851subsys_initcall(tc6393xb_init);
852module_exit(tc6393xb_exit);
853
Ian Molton25d6cbd82008-08-10 23:32:07 +0200854MODULE_LICENSE("GPL v2");
Dmitry Baryshkovd6315942008-06-22 12:01:58 +0100855MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
856MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
857MODULE_ALIAS("platform:tc6393xb");
Ian Molton64e88672010-01-06 13:51:48 +0100858