xref: /openbmc/linux/drivers/memory/jz4780-nemc.c (revision d171df6b73bb2e20d54d53a497cb405c0c902579)
1911a8882SAlex Smith /*
2911a8882SAlex Smith  * JZ4780 NAND/external memory controller (NEMC)
3911a8882SAlex Smith  *
4911a8882SAlex Smith  * Copyright (c) 2015 Imagination Technologies
5911a8882SAlex Smith  * Author: Alex Smith <alex@alex-smith.me.uk>
6911a8882SAlex Smith  *
7911a8882SAlex Smith  * This program is free software; you can redistribute it and/or modify it
8911a8882SAlex Smith  * under the terms of the GNU General Public License version 2 as published
9911a8882SAlex Smith  * by the Free Software Foundation.
10911a8882SAlex Smith  */
11911a8882SAlex Smith 
12911a8882SAlex Smith #include <linux/clk.h>
13911a8882SAlex Smith #include <linux/init.h>
14911a8882SAlex Smith #include <linux/math64.h>
15911a8882SAlex Smith #include <linux/of.h>
16911a8882SAlex Smith #include <linux/of_address.h>
17911a8882SAlex Smith #include <linux/of_device.h>
18911a8882SAlex Smith #include <linux/of_platform.h>
19911a8882SAlex Smith #include <linux/platform_device.h>
20911a8882SAlex Smith #include <linux/slab.h>
21911a8882SAlex Smith #include <linux/spinlock.h>
22911a8882SAlex Smith 
23911a8882SAlex Smith #include <linux/jz4780-nemc.h>
24911a8882SAlex Smith 
25911a8882SAlex Smith #define NEMC_SMCRn(n)		(0x14 + (((n) - 1) * 4))
26911a8882SAlex Smith #define NEMC_NFCSR		0x50
27911a8882SAlex Smith 
28911a8882SAlex Smith #define NEMC_SMCR_SMT		BIT(0)
29911a8882SAlex Smith #define NEMC_SMCR_BW_SHIFT	6
30911a8882SAlex Smith #define NEMC_SMCR_BW_MASK	(0x3 << NEMC_SMCR_BW_SHIFT)
31911a8882SAlex Smith #define NEMC_SMCR_BW_8		(0 << 6)
32911a8882SAlex Smith #define NEMC_SMCR_TAS_SHIFT	8
33911a8882SAlex Smith #define NEMC_SMCR_TAS_MASK	(0xf << NEMC_SMCR_TAS_SHIFT)
34911a8882SAlex Smith #define NEMC_SMCR_TAH_SHIFT	12
35911a8882SAlex Smith #define NEMC_SMCR_TAH_MASK	(0xf << NEMC_SMCR_TAH_SHIFT)
36911a8882SAlex Smith #define NEMC_SMCR_TBP_SHIFT	16
37911a8882SAlex Smith #define NEMC_SMCR_TBP_MASK	(0xf << NEMC_SMCR_TBP_SHIFT)
38911a8882SAlex Smith #define NEMC_SMCR_TAW_SHIFT	20
39911a8882SAlex Smith #define NEMC_SMCR_TAW_MASK	(0xf << NEMC_SMCR_TAW_SHIFT)
40911a8882SAlex Smith #define NEMC_SMCR_TSTRV_SHIFT	24
41911a8882SAlex Smith #define NEMC_SMCR_TSTRV_MASK	(0x3f << NEMC_SMCR_TSTRV_SHIFT)
42911a8882SAlex Smith 
43911a8882SAlex Smith #define NEMC_NFCSR_NFEn(n)	BIT(((n) - 1) << 1)
44911a8882SAlex Smith #define NEMC_NFCSR_NFCEn(n)	BIT((((n) - 1) << 1) + 1)
45911a8882SAlex Smith #define NEMC_NFCSR_TNFEn(n)	BIT(16 + (n) - 1)
46911a8882SAlex Smith 
47fcbc3b10SPaul Cercueil struct jz_soc_info {
48fcbc3b10SPaul Cercueil 	u8 tas_tah_cycles_max;
49fcbc3b10SPaul Cercueil };
50fcbc3b10SPaul Cercueil 
51911a8882SAlex Smith struct jz4780_nemc {
52911a8882SAlex Smith 	spinlock_t lock;
53911a8882SAlex Smith 	struct device *dev;
54fcbc3b10SPaul Cercueil 	const struct jz_soc_info *soc_info;
55911a8882SAlex Smith 	void __iomem *base;
56911a8882SAlex Smith 	struct clk *clk;
57911a8882SAlex Smith 	uint32_t clk_period;
58911a8882SAlex Smith 	unsigned long banks_present;
59911a8882SAlex Smith };
60911a8882SAlex Smith 
61911a8882SAlex Smith /**
62911a8882SAlex Smith  * jz4780_nemc_num_banks() - count the number of banks referenced by a device
63911a8882SAlex Smith  * @dev: device to count banks for, must be a child of the NEMC.
64911a8882SAlex Smith  *
65911a8882SAlex Smith  * Return: The number of unique NEMC banks referred to by the specified NEMC
66911a8882SAlex Smith  * child device. Unique here means that a device that references the same bank
67*d171df6bSGeert Uytterhoeven  * multiple times in its "reg" property will only count once.
68911a8882SAlex Smith  */
69911a8882SAlex Smith unsigned int jz4780_nemc_num_banks(struct device *dev)
70911a8882SAlex Smith {
71911a8882SAlex Smith 	const __be32 *prop;
72911a8882SAlex Smith 	unsigned int bank, count = 0;
73911a8882SAlex Smith 	unsigned long referenced = 0;
74911a8882SAlex Smith 	int i = 0;
75911a8882SAlex Smith 
76911a8882SAlex Smith 	while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) {
77911a8882SAlex Smith 		bank = of_read_number(prop, 1);
78911a8882SAlex Smith 		if (!(referenced & BIT(bank))) {
79911a8882SAlex Smith 			referenced |= BIT(bank);
80911a8882SAlex Smith 			count++;
81911a8882SAlex Smith 		}
82911a8882SAlex Smith 	}
83911a8882SAlex Smith 
84911a8882SAlex Smith 	return count;
85911a8882SAlex Smith }
86911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_num_banks);
87911a8882SAlex Smith 
88911a8882SAlex Smith /**
89911a8882SAlex Smith  * jz4780_nemc_set_type() - set the type of device connected to a bank
90911a8882SAlex Smith  * @dev: child device of the NEMC.
91911a8882SAlex Smith  * @bank: bank number to configure.
92911a8882SAlex Smith  * @type: type of device connected to the bank.
93911a8882SAlex Smith  */
94911a8882SAlex Smith void jz4780_nemc_set_type(struct device *dev, unsigned int bank,
95911a8882SAlex Smith 			  enum jz4780_nemc_bank_type type)
96911a8882SAlex Smith {
97911a8882SAlex Smith 	struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent);
98911a8882SAlex Smith 	uint32_t nfcsr;
99911a8882SAlex Smith 
100911a8882SAlex Smith 	nfcsr = readl(nemc->base + NEMC_NFCSR);
101911a8882SAlex Smith 
102911a8882SAlex Smith 	/* TODO: Support toggle NAND devices. */
103911a8882SAlex Smith 	switch (type) {
104911a8882SAlex Smith 	case JZ4780_NEMC_BANK_SRAM:
105911a8882SAlex Smith 		nfcsr &= ~(NEMC_NFCSR_TNFEn(bank) | NEMC_NFCSR_NFEn(bank));
106911a8882SAlex Smith 		break;
107911a8882SAlex Smith 	case JZ4780_NEMC_BANK_NAND:
108911a8882SAlex Smith 		nfcsr &= ~NEMC_NFCSR_TNFEn(bank);
109911a8882SAlex Smith 		nfcsr |= NEMC_NFCSR_NFEn(bank);
110911a8882SAlex Smith 		break;
111911a8882SAlex Smith 	}
112911a8882SAlex Smith 
113911a8882SAlex Smith 	writel(nfcsr, nemc->base + NEMC_NFCSR);
114911a8882SAlex Smith }
115911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_set_type);
116911a8882SAlex Smith 
117911a8882SAlex Smith /**
118911a8882SAlex Smith  * jz4780_nemc_assert() - (de-)assert a NAND device's chip enable pin
119911a8882SAlex Smith  * @dev: child device of the NEMC.
120911a8882SAlex Smith  * @bank: bank number of device.
121911a8882SAlex Smith  * @assert: whether the chip enable pin should be asserted.
122911a8882SAlex Smith  *
123911a8882SAlex Smith  * (De-)asserts the chip enable pin for the NAND device connected to the
124911a8882SAlex Smith  * specified bank.
125911a8882SAlex Smith  */
126911a8882SAlex Smith void jz4780_nemc_assert(struct device *dev, unsigned int bank, bool assert)
127911a8882SAlex Smith {
128911a8882SAlex Smith 	struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent);
129911a8882SAlex Smith 	uint32_t nfcsr;
130911a8882SAlex Smith 
131911a8882SAlex Smith 	nfcsr = readl(nemc->base + NEMC_NFCSR);
132911a8882SAlex Smith 
133911a8882SAlex Smith 	if (assert)
134911a8882SAlex Smith 		nfcsr |= NEMC_NFCSR_NFCEn(bank);
135911a8882SAlex Smith 	else
136911a8882SAlex Smith 		nfcsr &= ~NEMC_NFCSR_NFCEn(bank);
137911a8882SAlex Smith 
138911a8882SAlex Smith 	writel(nfcsr, nemc->base + NEMC_NFCSR);
139911a8882SAlex Smith }
140911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_assert);
141911a8882SAlex Smith 
142911a8882SAlex Smith static uint32_t jz4780_nemc_clk_period(struct jz4780_nemc *nemc)
143911a8882SAlex Smith {
144911a8882SAlex Smith 	unsigned long rate;
145911a8882SAlex Smith 
146911a8882SAlex Smith 	rate = clk_get_rate(nemc->clk);
147911a8882SAlex Smith 	if (!rate)
148911a8882SAlex Smith 		return 0;
149911a8882SAlex Smith 
150911a8882SAlex Smith 	/* Return in picoseconds. */
151911a8882SAlex Smith 	return div64_ul(1000000000000ull, rate);
152911a8882SAlex Smith }
153911a8882SAlex Smith 
154911a8882SAlex Smith static uint32_t jz4780_nemc_ns_to_cycles(struct jz4780_nemc *nemc, uint32_t ns)
155911a8882SAlex Smith {
156911a8882SAlex Smith 	return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period;
157911a8882SAlex Smith }
158911a8882SAlex Smith 
159911a8882SAlex Smith static bool jz4780_nemc_configure_bank(struct jz4780_nemc *nemc,
160911a8882SAlex Smith 				       unsigned int bank,
161911a8882SAlex Smith 				       struct device_node *node)
162911a8882SAlex Smith {
163911a8882SAlex Smith 	uint32_t smcr, val, cycles;
164911a8882SAlex Smith 
165911a8882SAlex Smith 	/*
166911a8882SAlex Smith 	 * Conversion of tBP and tAW cycle counts to values supported by the
167911a8882SAlex Smith 	 * hardware (round up to the next supported value).
168911a8882SAlex Smith 	 */
16956a171e5SPaul Cercueil 	static const u8 convert_tBP_tAW[] = {
170911a8882SAlex Smith 		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
171911a8882SAlex Smith 
172911a8882SAlex Smith 		/* 11 - 12 -> 12 cycles */
173911a8882SAlex Smith 		11, 11,
174911a8882SAlex Smith 
175911a8882SAlex Smith 		/* 13 - 15 -> 15 cycles */
176911a8882SAlex Smith 		12, 12, 12,
177911a8882SAlex Smith 
178911a8882SAlex Smith 		/* 16 - 20 -> 20 cycles */
179911a8882SAlex Smith 		13, 13, 13, 13, 13,
180911a8882SAlex Smith 
181911a8882SAlex Smith 		/* 21 - 25 -> 25 cycles */
182911a8882SAlex Smith 		14, 14, 14, 14, 14,
183911a8882SAlex Smith 
184911a8882SAlex Smith 		/* 26 - 31 -> 31 cycles */
185911a8882SAlex Smith 		15, 15, 15, 15, 15, 15
186911a8882SAlex Smith 	};
187911a8882SAlex Smith 
188911a8882SAlex Smith 	smcr = readl(nemc->base + NEMC_SMCRn(bank));
189911a8882SAlex Smith 	smcr &= ~NEMC_SMCR_SMT;
190911a8882SAlex Smith 
191911a8882SAlex Smith 	if (!of_property_read_u32(node, "ingenic,nemc-bus-width", &val)) {
192911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_BW_MASK;
193911a8882SAlex Smith 		switch (val) {
194911a8882SAlex Smith 		case 8:
195911a8882SAlex Smith 			smcr |= NEMC_SMCR_BW_8;
196911a8882SAlex Smith 			break;
197911a8882SAlex Smith 		default:
198911a8882SAlex Smith 			/*
199911a8882SAlex Smith 			 * Earlier SoCs support a 16 bit bus width (the 4780
200911a8882SAlex Smith 			 * does not), until those are properly supported, error.
201911a8882SAlex Smith 			 */
202911a8882SAlex Smith 			dev_err(nemc->dev, "unsupported bus width: %u\n", val);
203911a8882SAlex Smith 			return false;
204911a8882SAlex Smith 		}
205911a8882SAlex Smith 	}
206911a8882SAlex Smith 
207911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tAS", &val) == 0) {
208911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TAS_MASK;
209911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
210fcbc3b10SPaul Cercueil 		if (cycles > nemc->soc_info->tas_tah_cycles_max) {
211911a8882SAlex Smith 			dev_err(nemc->dev, "tAS %u is too high (%u cycles)\n",
212911a8882SAlex Smith 				val, cycles);
213911a8882SAlex Smith 			return false;
214911a8882SAlex Smith 		}
215911a8882SAlex Smith 
216911a8882SAlex Smith 		smcr |= cycles << NEMC_SMCR_TAS_SHIFT;
217911a8882SAlex Smith 	}
218911a8882SAlex Smith 
219911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tAH", &val) == 0) {
220911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TAH_MASK;
221911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
222fcbc3b10SPaul Cercueil 		if (cycles > nemc->soc_info->tas_tah_cycles_max) {
223911a8882SAlex Smith 			dev_err(nemc->dev, "tAH %u is too high (%u cycles)\n",
224911a8882SAlex Smith 				val, cycles);
225911a8882SAlex Smith 			return false;
226911a8882SAlex Smith 		}
227911a8882SAlex Smith 
228911a8882SAlex Smith 		smcr |= cycles << NEMC_SMCR_TAH_SHIFT;
229911a8882SAlex Smith 	}
230911a8882SAlex Smith 
231911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tBP", &val) == 0) {
232911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TBP_MASK;
233911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
234911a8882SAlex Smith 		if (cycles > 31) {
235911a8882SAlex Smith 			dev_err(nemc->dev, "tBP %u is too high (%u cycles)\n",
236911a8882SAlex Smith 				val, cycles);
237911a8882SAlex Smith 			return false;
238911a8882SAlex Smith 		}
239911a8882SAlex Smith 
240911a8882SAlex Smith 		smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TBP_SHIFT;
241911a8882SAlex Smith 	}
242911a8882SAlex Smith 
243911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tAW", &val) == 0) {
244911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TAW_MASK;
245911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
246911a8882SAlex Smith 		if (cycles > 31) {
247911a8882SAlex Smith 			dev_err(nemc->dev, "tAW %u is too high (%u cycles)\n",
248911a8882SAlex Smith 				val, cycles);
249911a8882SAlex Smith 			return false;
250911a8882SAlex Smith 		}
251911a8882SAlex Smith 
252911a8882SAlex Smith 		smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TAW_SHIFT;
253911a8882SAlex Smith 	}
254911a8882SAlex Smith 
255911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tSTRV", &val) == 0) {
256911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TSTRV_MASK;
257911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
258911a8882SAlex Smith 		if (cycles > 63) {
259911a8882SAlex Smith 			dev_err(nemc->dev, "tSTRV %u is too high (%u cycles)\n",
260911a8882SAlex Smith 				val, cycles);
261911a8882SAlex Smith 			return false;
262911a8882SAlex Smith 		}
263911a8882SAlex Smith 
264911a8882SAlex Smith 		smcr |= cycles << NEMC_SMCR_TSTRV_SHIFT;
265911a8882SAlex Smith 	}
266911a8882SAlex Smith 
267911a8882SAlex Smith 	writel(smcr, nemc->base + NEMC_SMCRn(bank));
268911a8882SAlex Smith 	return true;
269911a8882SAlex Smith }
270911a8882SAlex Smith 
271911a8882SAlex Smith static int jz4780_nemc_probe(struct platform_device *pdev)
272911a8882SAlex Smith {
273911a8882SAlex Smith 	struct device *dev = &pdev->dev;
274911a8882SAlex Smith 	struct jz4780_nemc *nemc;
275911a8882SAlex Smith 	struct resource *res;
276911a8882SAlex Smith 	struct device_node *child;
277911a8882SAlex Smith 	const __be32 *prop;
278911a8882SAlex Smith 	unsigned int bank;
279911a8882SAlex Smith 	unsigned long referenced;
280911a8882SAlex Smith 	int i, ret;
281911a8882SAlex Smith 
282911a8882SAlex Smith 	nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL);
283911a8882SAlex Smith 	if (!nemc)
284911a8882SAlex Smith 		return -ENOMEM;
285911a8882SAlex Smith 
286fcbc3b10SPaul Cercueil 	nemc->soc_info = device_get_match_data(dev);
287fcbc3b10SPaul Cercueil 	if (!nemc->soc_info)
288fcbc3b10SPaul Cercueil 		return -EINVAL;
289fcbc3b10SPaul Cercueil 
290911a8882SAlex Smith 	spin_lock_init(&nemc->lock);
291911a8882SAlex Smith 	nemc->dev = dev;
292911a8882SAlex Smith 
293911a8882SAlex Smith 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
294911a8882SAlex Smith 	nemc->base = devm_ioremap_resource(dev, res);
295911a8882SAlex Smith 	if (IS_ERR(nemc->base)) {
296911a8882SAlex Smith 		dev_err(dev, "failed to get I/O memory\n");
297911a8882SAlex Smith 		return PTR_ERR(nemc->base);
298911a8882SAlex Smith 	}
299911a8882SAlex Smith 
300911a8882SAlex Smith 	writel(0, nemc->base + NEMC_NFCSR);
301911a8882SAlex Smith 
302911a8882SAlex Smith 	nemc->clk = devm_clk_get(dev, NULL);
303911a8882SAlex Smith 	if (IS_ERR(nemc->clk)) {
304911a8882SAlex Smith 		dev_err(dev, "failed to get clock\n");
305911a8882SAlex Smith 		return PTR_ERR(nemc->clk);
306911a8882SAlex Smith 	}
307911a8882SAlex Smith 
308911a8882SAlex Smith 	ret = clk_prepare_enable(nemc->clk);
309911a8882SAlex Smith 	if (ret) {
310911a8882SAlex Smith 		dev_err(dev, "failed to enable clock: %d\n", ret);
311911a8882SAlex Smith 		return ret;
312911a8882SAlex Smith 	}
313911a8882SAlex Smith 
314911a8882SAlex Smith 	nemc->clk_period = jz4780_nemc_clk_period(nemc);
315911a8882SAlex Smith 	if (!nemc->clk_period) {
316911a8882SAlex Smith 		dev_err(dev, "failed to calculate clock period\n");
317911a8882SAlex Smith 		clk_disable_unprepare(nemc->clk);
318911a8882SAlex Smith 		return -EINVAL;
319911a8882SAlex Smith 	}
320911a8882SAlex Smith 
321911a8882SAlex Smith 	/*
322911a8882SAlex Smith 	 * Iterate over child devices, check that they do not conflict with
323911a8882SAlex Smith 	 * each other, and register child devices for them. If a child device
324911a8882SAlex Smith 	 * has invalid properties, it is ignored and no platform device is
325911a8882SAlex Smith 	 * registered for it.
326911a8882SAlex Smith 	 */
327911a8882SAlex Smith 	for_each_child_of_node(nemc->dev->of_node, child) {
328911a8882SAlex Smith 		referenced = 0;
329911a8882SAlex Smith 		i = 0;
330911a8882SAlex Smith 		while ((prop = of_get_address(child, i++, NULL, NULL))) {
331911a8882SAlex Smith 			bank = of_read_number(prop, 1);
332911a8882SAlex Smith 			if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) {
333911a8882SAlex Smith 				dev_err(nemc->dev,
334db749d17SRob Herring 					"%pOF requests invalid bank %u\n",
335db749d17SRob Herring 					child, bank);
336911a8882SAlex Smith 
337911a8882SAlex Smith 				/* Will continue the outer loop below. */
338911a8882SAlex Smith 				referenced = 0;
339911a8882SAlex Smith 				break;
340911a8882SAlex Smith 			}
341911a8882SAlex Smith 
342911a8882SAlex Smith 			referenced |= BIT(bank);
343911a8882SAlex Smith 		}
344911a8882SAlex Smith 
345911a8882SAlex Smith 		if (!referenced) {
346db749d17SRob Herring 			dev_err(nemc->dev, "%pOF has no addresses\n",
347db749d17SRob Herring 				child);
348911a8882SAlex Smith 			continue;
349911a8882SAlex Smith 		} else if (nemc->banks_present & referenced) {
350db749d17SRob Herring 			dev_err(nemc->dev, "%pOF conflicts with another node\n",
351db749d17SRob Herring 				child);
352911a8882SAlex Smith 			continue;
353911a8882SAlex Smith 		}
354911a8882SAlex Smith 
355911a8882SAlex Smith 		/* Configure bank parameters. */
356911a8882SAlex Smith 		for_each_set_bit(bank, &referenced, JZ4780_NEMC_NUM_BANKS) {
357911a8882SAlex Smith 			if (!jz4780_nemc_configure_bank(nemc, bank, child)) {
358911a8882SAlex Smith 				referenced = 0;
359911a8882SAlex Smith 				break;
360911a8882SAlex Smith 			}
361911a8882SAlex Smith 		}
362911a8882SAlex Smith 
363911a8882SAlex Smith 		if (referenced) {
364911a8882SAlex Smith 			if (of_platform_device_create(child, NULL, nemc->dev))
365911a8882SAlex Smith 				nemc->banks_present |= referenced;
366911a8882SAlex Smith 		}
367911a8882SAlex Smith 	}
368911a8882SAlex Smith 
369911a8882SAlex Smith 	platform_set_drvdata(pdev, nemc);
370911a8882SAlex Smith 	dev_info(dev, "JZ4780 NEMC initialised\n");
371911a8882SAlex Smith 	return 0;
372911a8882SAlex Smith }
373911a8882SAlex Smith 
374911a8882SAlex Smith static int jz4780_nemc_remove(struct platform_device *pdev)
375911a8882SAlex Smith {
376911a8882SAlex Smith 	struct jz4780_nemc *nemc = platform_get_drvdata(pdev);
377911a8882SAlex Smith 
378911a8882SAlex Smith 	clk_disable_unprepare(nemc->clk);
379911a8882SAlex Smith 	return 0;
380911a8882SAlex Smith }
381911a8882SAlex Smith 
382fcbc3b10SPaul Cercueil static const struct jz_soc_info jz4740_soc_info = {
383fcbc3b10SPaul Cercueil 	.tas_tah_cycles_max = 7,
384fcbc3b10SPaul Cercueil };
385fcbc3b10SPaul Cercueil 
386fcbc3b10SPaul Cercueil static const struct jz_soc_info jz4780_soc_info = {
387fcbc3b10SPaul Cercueil 	.tas_tah_cycles_max = 15,
388fcbc3b10SPaul Cercueil };
389fcbc3b10SPaul Cercueil 
390911a8882SAlex Smith static const struct of_device_id jz4780_nemc_dt_match[] = {
391fcbc3b10SPaul Cercueil 	{ .compatible = "ingenic,jz4740-nemc", .data = &jz4740_soc_info, },
392fcbc3b10SPaul Cercueil 	{ .compatible = "ingenic,jz4780-nemc", .data = &jz4780_soc_info, },
393911a8882SAlex Smith 	{},
394911a8882SAlex Smith };
395911a8882SAlex Smith 
396911a8882SAlex Smith static struct platform_driver jz4780_nemc_driver = {
397911a8882SAlex Smith 	.probe		= jz4780_nemc_probe,
398911a8882SAlex Smith 	.remove		= jz4780_nemc_remove,
399911a8882SAlex Smith 	.driver	= {
400911a8882SAlex Smith 		.name	= "jz4780-nemc",
401911a8882SAlex Smith 		.of_match_table = of_match_ptr(jz4780_nemc_dt_match),
402911a8882SAlex Smith 	},
403911a8882SAlex Smith };
404911a8882SAlex Smith 
405911a8882SAlex Smith static int __init jz4780_nemc_init(void)
406911a8882SAlex Smith {
407911a8882SAlex Smith 	return platform_driver_register(&jz4780_nemc_driver);
408911a8882SAlex Smith }
409911a8882SAlex Smith subsys_initcall(jz4780_nemc_init);
410