blob: 8a20ec4991c878eb00b7a2b0551cf50e2320a7dd [file] [log] [blame]
Bayi Cheng3ce351b2015-11-18 11:30:02 +08001/*
2 * Copyright (c) 2015 MediaTek Inc.
3 * Author: Bayi Cheng <bayi.cheng@mediatek.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/clk.h>
16#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/init.h>
19#include <linux/io.h>
20#include <linux/iopoll.h>
21#include <linux/ioport.h>
22#include <linux/math64.h>
23#include <linux/module.h>
Bayi Cheng3ce351b2015-11-18 11:30:02 +080024#include <linux/mutex.h>
25#include <linux/of.h>
26#include <linux/of_device.h>
27#include <linux/pinctrl/consumer.h>
28#include <linux/platform_device.h>
29#include <linux/slab.h>
30#include <linux/mtd/mtd.h>
31#include <linux/mtd/partitions.h>
32#include <linux/mtd/spi-nor.h>
33
34#define MTK_NOR_CMD_REG 0x00
35#define MTK_NOR_CNT_REG 0x04
36#define MTK_NOR_RDSR_REG 0x08
37#define MTK_NOR_RDATA_REG 0x0c
38#define MTK_NOR_RADR0_REG 0x10
39#define MTK_NOR_RADR1_REG 0x14
40#define MTK_NOR_RADR2_REG 0x18
41#define MTK_NOR_WDATA_REG 0x1c
42#define MTK_NOR_PRGDATA0_REG 0x20
43#define MTK_NOR_PRGDATA1_REG 0x24
44#define MTK_NOR_PRGDATA2_REG 0x28
45#define MTK_NOR_PRGDATA3_REG 0x2c
46#define MTK_NOR_PRGDATA4_REG 0x30
47#define MTK_NOR_PRGDATA5_REG 0x34
48#define MTK_NOR_SHREG0_REG 0x38
49#define MTK_NOR_SHREG1_REG 0x3c
50#define MTK_NOR_SHREG2_REG 0x40
51#define MTK_NOR_SHREG3_REG 0x44
52#define MTK_NOR_SHREG4_REG 0x48
53#define MTK_NOR_SHREG5_REG 0x4c
54#define MTK_NOR_SHREG6_REG 0x50
55#define MTK_NOR_SHREG7_REG 0x54
56#define MTK_NOR_SHREG8_REG 0x58
57#define MTK_NOR_SHREG9_REG 0x5c
58#define MTK_NOR_CFG1_REG 0x60
59#define MTK_NOR_CFG2_REG 0x64
60#define MTK_NOR_CFG3_REG 0x68
61#define MTK_NOR_STATUS0_REG 0x70
62#define MTK_NOR_STATUS1_REG 0x74
63#define MTK_NOR_STATUS2_REG 0x78
64#define MTK_NOR_STATUS3_REG 0x7c
65#define MTK_NOR_FLHCFG_REG 0x84
66#define MTK_NOR_TIME_REG 0x94
67#define MTK_NOR_PP_DATA_REG 0x98
68#define MTK_NOR_PREBUF_STUS_REG 0x9c
69#define MTK_NOR_DELSEL0_REG 0xa0
70#define MTK_NOR_DELSEL1_REG 0xa4
71#define MTK_NOR_INTRSTUS_REG 0xa8
72#define MTK_NOR_INTREN_REG 0xac
73#define MTK_NOR_CHKSUM_CTL_REG 0xb8
74#define MTK_NOR_CHKSUM_REG 0xbc
75#define MTK_NOR_CMD2_REG 0xc0
76#define MTK_NOR_WRPROT_REG 0xc4
77#define MTK_NOR_RADR3_REG 0xc8
78#define MTK_NOR_DUAL_REG 0xcc
79#define MTK_NOR_DELSEL2_REG 0xd0
80#define MTK_NOR_DELSEL3_REG 0xd4
81#define MTK_NOR_DELSEL4_REG 0xd8
82
83/* commands for mtk nor controller */
84#define MTK_NOR_READ_CMD 0x0
85#define MTK_NOR_RDSR_CMD 0x2
86#define MTK_NOR_PRG_CMD 0x4
87#define MTK_NOR_WR_CMD 0x10
88#define MTK_NOR_PIO_WR_CMD 0x90
89#define MTK_NOR_WRSR_CMD 0x20
90#define MTK_NOR_PIO_READ_CMD 0x81
91#define MTK_NOR_WR_BUF_ENABLE 0x1
92#define MTK_NOR_WR_BUF_DISABLE 0x0
93#define MTK_NOR_ENABLE_SF_CMD 0x30
94#define MTK_NOR_DUAD_ADDR_EN 0x8
95#define MTK_NOR_QUAD_READ_EN 0x4
96#define MTK_NOR_DUAL_ADDR_EN 0x2
97#define MTK_NOR_DUAL_READ_EN 0x1
98#define MTK_NOR_DUAL_DISABLE 0x0
99#define MTK_NOR_FAST_READ 0x1
100
101#define SFLASH_WRBUF_SIZE 128
102
103/* Can shift up to 48 bits (6 bytes) of TX/RX */
104#define MTK_NOR_MAX_RX_TX_SHIFT 6
105/* can shift up to 56 bits (7 bytes) transfer by MTK_NOR_PRG_CMD */
106#define MTK_NOR_MAX_SHIFT 7
Guochun Mao8abe9042017-04-05 16:37:42 +0800107/* nor controller 4-byte address mode enable bit */
108#define MTK_NOR_4B_ADDR_EN BIT(4)
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800109
110/* Helpers for accessing the program data / shift data registers */
111#define MTK_NOR_PRG_REG(n) (MTK_NOR_PRGDATA0_REG + 4 * (n))
112#define MTK_NOR_SHREG(n) (MTK_NOR_SHREG0_REG + 4 * (n))
113
114struct mt8173_nor {
115 struct spi_nor nor;
116 struct device *dev;
117 void __iomem *base; /* nor flash base address */
118 struct clk *spi_clk;
119 struct clk *nor_clk;
120};
121
122static void mt8173_nor_set_read_mode(struct mt8173_nor *mt8173_nor)
123{
124 struct spi_nor *nor = &mt8173_nor->nor;
125
Cyrille Pitchencfc56042017-04-25 22:08:46 +0200126 switch (nor->read_proto) {
127 case SNOR_PROTO_1_1_1:
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800128 writeb(nor->read_opcode, mt8173_nor->base +
129 MTK_NOR_PRGDATA3_REG);
130 writeb(MTK_NOR_FAST_READ, mt8173_nor->base +
131 MTK_NOR_CFG1_REG);
132 break;
Cyrille Pitchencfc56042017-04-25 22:08:46 +0200133 case SNOR_PROTO_1_1_2:
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800134 writeb(nor->read_opcode, mt8173_nor->base +
135 MTK_NOR_PRGDATA3_REG);
136 writeb(MTK_NOR_DUAL_READ_EN, mt8173_nor->base +
137 MTK_NOR_DUAL_REG);
138 break;
Cyrille Pitchencfc56042017-04-25 22:08:46 +0200139 case SNOR_PROTO_1_1_4:
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800140 writeb(nor->read_opcode, mt8173_nor->base +
141 MTK_NOR_PRGDATA4_REG);
142 writeb(MTK_NOR_QUAD_READ_EN, mt8173_nor->base +
143 MTK_NOR_DUAL_REG);
144 break;
145 default:
146 writeb(MTK_NOR_DUAL_DISABLE, mt8173_nor->base +
147 MTK_NOR_DUAL_REG);
148 break;
149 }
150}
151
152static int mt8173_nor_execute_cmd(struct mt8173_nor *mt8173_nor, u8 cmdval)
153{
154 int reg;
155 u8 val = cmdval & 0x1f;
156
157 writeb(cmdval, mt8173_nor->base + MTK_NOR_CMD_REG);
158 return readl_poll_timeout(mt8173_nor->base + MTK_NOR_CMD_REG, reg,
159 !(reg & val), 100, 10000);
160}
161
162static int mt8173_nor_do_tx_rx(struct mt8173_nor *mt8173_nor, u8 op,
163 u8 *tx, int txlen, u8 *rx, int rxlen)
164{
165 int len = 1 + txlen + rxlen;
166 int i, ret, idx;
167
168 if (len > MTK_NOR_MAX_SHIFT)
169 return -EINVAL;
170
171 writeb(len * 8, mt8173_nor->base + MTK_NOR_CNT_REG);
172
173 /* start at PRGDATA5, go down to PRGDATA0 */
174 idx = MTK_NOR_MAX_RX_TX_SHIFT - 1;
175
176 /* opcode */
177 writeb(op, mt8173_nor->base + MTK_NOR_PRG_REG(idx));
178 idx--;
179
180 /* program TX data */
181 for (i = 0; i < txlen; i++, idx--)
182 writeb(tx[i], mt8173_nor->base + MTK_NOR_PRG_REG(idx));
183
184 /* clear out rest of TX registers */
185 while (idx >= 0) {
186 writeb(0, mt8173_nor->base + MTK_NOR_PRG_REG(idx));
187 idx--;
188 }
189
190 ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PRG_CMD);
191 if (ret)
192 return ret;
193
194 /* restart at first RX byte */
195 idx = rxlen - 1;
196
197 /* read out RX data */
198 for (i = 0; i < rxlen; i++, idx--)
199 rx[i] = readb(mt8173_nor->base + MTK_NOR_SHREG(idx));
200
201 return 0;
202}
203
204/* Do a WRSR (Write Status Register) command */
205static int mt8173_nor_wr_sr(struct mt8173_nor *mt8173_nor, u8 sr)
206{
207 writeb(sr, mt8173_nor->base + MTK_NOR_PRGDATA5_REG);
208 writeb(8, mt8173_nor->base + MTK_NOR_CNT_REG);
209 return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WRSR_CMD);
210}
211
212static int mt8173_nor_write_buffer_enable(struct mt8173_nor *mt8173_nor)
213{
214 u8 reg;
215
216 /* the bit0 of MTK_NOR_CFG2_REG is pre-fetch buffer
217 * 0: pre-fetch buffer use for read
218 * 1: pre-fetch buffer use for page program
219 */
220 writel(MTK_NOR_WR_BUF_ENABLE, mt8173_nor->base + MTK_NOR_CFG2_REG);
221 return readb_poll_timeout(mt8173_nor->base + MTK_NOR_CFG2_REG, reg,
222 0x01 == (reg & 0x01), 100, 10000);
223}
224
225static int mt8173_nor_write_buffer_disable(struct mt8173_nor *mt8173_nor)
226{
227 u8 reg;
228
229 writel(MTK_NOR_WR_BUF_DISABLE, mt8173_nor->base + MTK_NOR_CFG2_REG);
230 return readb_poll_timeout(mt8173_nor->base + MTK_NOR_CFG2_REG, reg,
231 MTK_NOR_WR_BUF_DISABLE == (reg & 0x1), 100,
232 10000);
233}
234
Guochun Mao8abe9042017-04-05 16:37:42 +0800235static void mt8173_nor_set_addr_width(struct mt8173_nor *mt8173_nor)
236{
237 u8 val;
238 struct spi_nor *nor = &mt8173_nor->nor;
239
240 val = readb(mt8173_nor->base + MTK_NOR_DUAL_REG);
241
242 switch (nor->addr_width) {
243 case 3:
244 val &= ~MTK_NOR_4B_ADDR_EN;
245 break;
246 case 4:
247 val |= MTK_NOR_4B_ADDR_EN;
248 break;
249 default:
250 dev_warn(mt8173_nor->dev, "Unexpected address width %u.\n",
251 nor->addr_width);
252 break;
253 }
254
255 writeb(val, mt8173_nor->base + MTK_NOR_DUAL_REG);
256}
257
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800258static void mt8173_nor_set_addr(struct mt8173_nor *mt8173_nor, u32 addr)
259{
260 int i;
261
Guochun Mao8abe9042017-04-05 16:37:42 +0800262 mt8173_nor_set_addr_width(mt8173_nor);
263
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800264 for (i = 0; i < 3; i++) {
265 writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR0_REG + i * 4);
266 addr >>= 8;
267 }
268 /* Last register is non-contiguous */
269 writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR3_REG);
270}
271
Michal Suchanek59451e12016-05-05 17:31:47 -0700272static ssize_t mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length,
Michal Suchanek2dd087b2016-05-05 17:31:53 -0700273 u_char *buffer)
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800274{
275 int i, ret;
276 int addr = (int)from;
277 u8 *buf = (u8 *)buffer;
278 struct mt8173_nor *mt8173_nor = nor->priv;
279
280 /* set mode for fast read mode ,dual mode or quad mode */
281 mt8173_nor_set_read_mode(mt8173_nor);
282 mt8173_nor_set_addr(mt8173_nor, addr);
283
Michal Suchanek2dd087b2016-05-05 17:31:53 -0700284 for (i = 0; i < length; i++) {
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800285 ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_READ_CMD);
286 if (ret < 0)
287 return ret;
288 buf[i] = readb(mt8173_nor->base + MTK_NOR_RDATA_REG);
289 }
Brian Norris78b400f2016-05-05 17:31:50 -0700290 return length;
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800291}
292
293static int mt8173_nor_write_single_byte(struct mt8173_nor *mt8173_nor,
294 int addr, int length, u8 *data)
295{
296 int i, ret;
297
298 mt8173_nor_set_addr(mt8173_nor, addr);
299
300 for (i = 0; i < length; i++) {
Bayi Cheng80e1ca62015-12-18 11:02:40 +0800301 writeb(*data++, mt8173_nor->base + MTK_NOR_WDATA_REG);
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800302 ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_WR_CMD);
303 if (ret < 0)
304 return ret;
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800305 }
306 return 0;
307}
308
309static int mt8173_nor_write_buffer(struct mt8173_nor *mt8173_nor, int addr,
310 const u8 *buf)
311{
312 int i, bufidx, data;
313
314 mt8173_nor_set_addr(mt8173_nor, addr);
315
316 bufidx = 0;
317 for (i = 0; i < SFLASH_WRBUF_SIZE; i += 4) {
318 data = buf[bufidx + 3]<<24 | buf[bufidx + 2]<<16 |
319 buf[bufidx + 1]<<8 | buf[bufidx];
320 bufidx += 4;
321 writel(data, mt8173_nor->base + MTK_NOR_PP_DATA_REG);
322 }
323 return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WR_CMD);
324}
325
Michal Suchanek59451e12016-05-05 17:31:47 -0700326static ssize_t mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len,
Michal Suchanek2dd087b2016-05-05 17:31:53 -0700327 const u_char *buf)
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800328{
329 int ret;
330 struct mt8173_nor *mt8173_nor = nor->priv;
Brian Norris78b400f2016-05-05 17:31:50 -0700331 size_t i;
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800332
333 ret = mt8173_nor_write_buffer_enable(mt8173_nor);
Michal Suchanek59451e12016-05-05 17:31:47 -0700334 if (ret < 0) {
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800335 dev_warn(mt8173_nor->dev, "write buffer enable failed!\n");
Michal Suchanek59451e12016-05-05 17:31:47 -0700336 return ret;
337 }
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800338
Brian Norris78b400f2016-05-05 17:31:50 -0700339 for (i = 0; i + SFLASH_WRBUF_SIZE <= len; i += SFLASH_WRBUF_SIZE) {
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800340 ret = mt8173_nor_write_buffer(mt8173_nor, to, buf);
Michal Suchanek59451e12016-05-05 17:31:47 -0700341 if (ret < 0) {
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800342 dev_err(mt8173_nor->dev, "write buffer failed!\n");
Michal Suchanek59451e12016-05-05 17:31:47 -0700343 return ret;
344 }
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800345 to += SFLASH_WRBUF_SIZE;
346 buf += SFLASH_WRBUF_SIZE;
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800347 }
348 ret = mt8173_nor_write_buffer_disable(mt8173_nor);
Michal Suchanek59451e12016-05-05 17:31:47 -0700349 if (ret < 0) {
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800350 dev_warn(mt8173_nor->dev, "write buffer disable failed!\n");
Michal Suchanek59451e12016-05-05 17:31:47 -0700351 return ret;
352 }
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800353
Brian Norris78b400f2016-05-05 17:31:50 -0700354 if (i < len) {
355 ret = mt8173_nor_write_single_byte(mt8173_nor, to,
356 (int)(len - i), (u8 *)buf);
Michal Suchanek59451e12016-05-05 17:31:47 -0700357 if (ret < 0) {
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800358 dev_err(mt8173_nor->dev, "write single byte failed!\n");
Michal Suchanek59451e12016-05-05 17:31:47 -0700359 return ret;
360 }
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800361 }
Michal Suchanek59451e12016-05-05 17:31:47 -0700362
Brian Norris78b400f2016-05-05 17:31:50 -0700363 return len;
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800364}
365
366static int mt8173_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
367{
368 int ret;
369 struct mt8173_nor *mt8173_nor = nor->priv;
370
371 switch (opcode) {
372 case SPINOR_OP_RDSR:
373 ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_RDSR_CMD);
374 if (ret < 0)
375 return ret;
376 if (len == 1)
377 *buf = readb(mt8173_nor->base + MTK_NOR_RDSR_REG);
378 else
379 dev_err(mt8173_nor->dev, "len should be 1 for read status!\n");
380 break;
381 default:
382 ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, NULL, 0, buf, len);
383 break;
384 }
385 return ret;
386}
387
388static int mt8173_nor_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
389 int len)
390{
391 int ret;
392 struct mt8173_nor *mt8173_nor = nor->priv;
393
394 switch (opcode) {
395 case SPINOR_OP_WRSR:
396 /* We only handle 1 byte */
397 ret = mt8173_nor_wr_sr(mt8173_nor, *buf);
398 break;
399 default:
400 ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, buf, len, NULL, 0);
401 if (ret)
402 dev_warn(mt8173_nor->dev, "write reg failure!\n");
403 break;
404 }
405 return ret;
406}
407
Geert Uytterhoeven92752d92016-01-15 14:46:29 +0100408static int mtk_nor_init(struct mt8173_nor *mt8173_nor,
409 struct device_node *flash_node)
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800410{
Cyrille Pitchencfc56042017-04-25 22:08:46 +0200411 const struct spi_nor_hwcaps hwcaps = {
412 .mask = SNOR_HWCAPS_READ_FAST |
413 SNOR_HWCAPS_READ_1_1_2 |
414 SNOR_HWCAPS_PP,
415 };
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800416 int ret;
417 struct spi_nor *nor;
418
419 /* initialize controller to accept commands */
420 writel(MTK_NOR_ENABLE_SF_CMD, mt8173_nor->base + MTK_NOR_WRPROT_REG);
421
422 nor = &mt8173_nor->nor;
423 nor->dev = mt8173_nor->dev;
424 nor->priv = mt8173_nor;
425 spi_nor_set_flash_node(nor, flash_node);
426
427 /* fill the hooks to spi nor */
428 nor->read = mt8173_nor_read;
429 nor->read_reg = mt8173_nor_read_reg;
430 nor->write = mt8173_nor_write;
431 nor->write_reg = mt8173_nor_write_reg;
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800432 nor->mtd.name = "mtk_nor";
433 /* initialized with NULL */
Cyrille Pitchencfc56042017-04-25 22:08:46 +0200434 ret = spi_nor_scan(nor, NULL, &hwcaps);
Bayi Cheng3ce351b2015-11-18 11:30:02 +0800435 if (ret)
436 return ret;
437
438 return mtd_device_register(&nor->mtd, NULL, 0);
439}
440
441static int mtk_nor_drv_probe(struct platform_device *pdev)
442{
443 struct device_node *flash_np;
444 struct resource *res;
445 int ret;
446 struct mt8173_nor *mt8173_nor;
447
448 if (!pdev->dev.of_node) {
449 dev_err(&pdev->dev, "No DT found\n");
450 return -EINVAL;
451 }
452
453 mt8173_nor = devm_kzalloc(&pdev->dev, sizeof(*mt8173_nor), GFP_KERNEL);
454 if (!mt8173_nor)
455 return -ENOMEM;
456 platform_set_drvdata(pdev, mt8173_nor);
457
458 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
459 mt8173_nor->base = devm_ioremap_resource(&pdev->dev, res);
460 if (IS_ERR(mt8173_nor->base))
461 return PTR_ERR(mt8173_nor->base);
462
463 mt8173_nor->spi_clk = devm_clk_get(&pdev->dev, "spi");
464 if (IS_ERR(mt8173_nor->spi_clk))
465 return PTR_ERR(mt8173_nor->spi_clk);
466
467 mt8173_nor->nor_clk = devm_clk_get(&pdev->dev, "sf");
468 if (IS_ERR(mt8173_nor->nor_clk))
469 return PTR_ERR(mt8173_nor->nor_clk);
470
471 mt8173_nor->dev = &pdev->dev;
472 ret = clk_prepare_enable(mt8173_nor->spi_clk);
473 if (ret)
474 return ret;
475
476 ret = clk_prepare_enable(mt8173_nor->nor_clk);
477 if (ret) {
478 clk_disable_unprepare(mt8173_nor->spi_clk);
479 return ret;
480 }
481 /* only support one attached flash */
482 flash_np = of_get_next_available_child(pdev->dev.of_node, NULL);
483 if (!flash_np) {
484 dev_err(&pdev->dev, "no SPI flash device to configure\n");
485 ret = -ENODEV;
486 goto nor_free;
487 }
488 ret = mtk_nor_init(mt8173_nor, flash_np);
489
490nor_free:
491 if (ret) {
492 clk_disable_unprepare(mt8173_nor->spi_clk);
493 clk_disable_unprepare(mt8173_nor->nor_clk);
494 }
495 return ret;
496}
497
498static int mtk_nor_drv_remove(struct platform_device *pdev)
499{
500 struct mt8173_nor *mt8173_nor = platform_get_drvdata(pdev);
501
502 clk_disable_unprepare(mt8173_nor->spi_clk);
503 clk_disable_unprepare(mt8173_nor->nor_clk);
504 return 0;
505}
506
507static const struct of_device_id mtk_nor_of_ids[] = {
508 { .compatible = "mediatek,mt8173-nor"},
509 { /* sentinel */ }
510};
511MODULE_DEVICE_TABLE(of, mtk_nor_of_ids);
512
513static struct platform_driver mtk_nor_driver = {
514 .probe = mtk_nor_drv_probe,
515 .remove = mtk_nor_drv_remove,
516 .driver = {
517 .name = "mtk-nor",
518 .of_match_table = mtk_nor_of_ids,
519 },
520};
521
522module_platform_driver(mtk_nor_driver);
523MODULE_LICENSE("GPL v2");
524MODULE_DESCRIPTION("MediaTek SPI NOR Flash Driver");