xref: /openbmc/linux/drivers/memory/jz4780-nemc.c (revision 911a88829725572820dad9a168e735c606a2fdcb)
1*911a8882SAlex Smith /*
2*911a8882SAlex Smith  * JZ4780 NAND/external memory controller (NEMC)
3*911a8882SAlex Smith  *
4*911a8882SAlex Smith  * Copyright (c) 2015 Imagination Technologies
5*911a8882SAlex Smith  * Author: Alex Smith <alex@alex-smith.me.uk>
6*911a8882SAlex Smith  *
7*911a8882SAlex Smith  * This program is free software; you can redistribute it and/or modify it
8*911a8882SAlex Smith  * under the terms of the GNU General Public License version 2 as published
9*911a8882SAlex Smith  * by the Free Software Foundation.
10*911a8882SAlex Smith  */
11*911a8882SAlex Smith 
12*911a8882SAlex Smith #include <linux/clk.h>
13*911a8882SAlex Smith #include <linux/init.h>
14*911a8882SAlex Smith #include <linux/math64.h>
15*911a8882SAlex Smith #include <linux/of.h>
16*911a8882SAlex Smith #include <linux/of_address.h>
17*911a8882SAlex Smith #include <linux/of_device.h>
18*911a8882SAlex Smith #include <linux/of_platform.h>
19*911a8882SAlex Smith #include <linux/platform_device.h>
20*911a8882SAlex Smith #include <linux/slab.h>
21*911a8882SAlex Smith #include <linux/spinlock.h>
22*911a8882SAlex Smith 
23*911a8882SAlex Smith #include <linux/jz4780-nemc.h>
24*911a8882SAlex Smith 
25*911a8882SAlex Smith #define NEMC_SMCRn(n)		(0x14 + (((n) - 1) * 4))
26*911a8882SAlex Smith #define NEMC_NFCSR		0x50
27*911a8882SAlex Smith 
28*911a8882SAlex Smith #define NEMC_SMCR_SMT		BIT(0)
29*911a8882SAlex Smith #define NEMC_SMCR_BW_SHIFT	6
30*911a8882SAlex Smith #define NEMC_SMCR_BW_MASK	(0x3 << NEMC_SMCR_BW_SHIFT)
31*911a8882SAlex Smith #define NEMC_SMCR_BW_8		(0 << 6)
32*911a8882SAlex Smith #define NEMC_SMCR_TAS_SHIFT	8
33*911a8882SAlex Smith #define NEMC_SMCR_TAS_MASK	(0xf << NEMC_SMCR_TAS_SHIFT)
34*911a8882SAlex Smith #define NEMC_SMCR_TAH_SHIFT	12
35*911a8882SAlex Smith #define NEMC_SMCR_TAH_MASK	(0xf << NEMC_SMCR_TAH_SHIFT)
36*911a8882SAlex Smith #define NEMC_SMCR_TBP_SHIFT	16
37*911a8882SAlex Smith #define NEMC_SMCR_TBP_MASK	(0xf << NEMC_SMCR_TBP_SHIFT)
38*911a8882SAlex Smith #define NEMC_SMCR_TAW_SHIFT	20
39*911a8882SAlex Smith #define NEMC_SMCR_TAW_MASK	(0xf << NEMC_SMCR_TAW_SHIFT)
40*911a8882SAlex Smith #define NEMC_SMCR_TSTRV_SHIFT	24
41*911a8882SAlex Smith #define NEMC_SMCR_TSTRV_MASK	(0x3f << NEMC_SMCR_TSTRV_SHIFT)
42*911a8882SAlex Smith 
43*911a8882SAlex Smith #define NEMC_NFCSR_NFEn(n)	BIT(((n) - 1) << 1)
44*911a8882SAlex Smith #define NEMC_NFCSR_NFCEn(n)	BIT((((n) - 1) << 1) + 1)
45*911a8882SAlex Smith #define NEMC_NFCSR_TNFEn(n)	BIT(16 + (n) - 1)
46*911a8882SAlex Smith 
47*911a8882SAlex Smith struct jz4780_nemc {
48*911a8882SAlex Smith 	spinlock_t lock;
49*911a8882SAlex Smith 	struct device *dev;
50*911a8882SAlex Smith 	void __iomem *base;
51*911a8882SAlex Smith 	struct clk *clk;
52*911a8882SAlex Smith 	uint32_t clk_period;
53*911a8882SAlex Smith 	unsigned long banks_present;
54*911a8882SAlex Smith };
55*911a8882SAlex Smith 
56*911a8882SAlex Smith /**
57*911a8882SAlex Smith  * jz4780_nemc_num_banks() - count the number of banks referenced by a device
58*911a8882SAlex Smith  * @dev: device to count banks for, must be a child of the NEMC.
59*911a8882SAlex Smith  *
60*911a8882SAlex Smith  * Return: The number of unique NEMC banks referred to by the specified NEMC
61*911a8882SAlex Smith  * child device. Unique here means that a device that references the same bank
62*911a8882SAlex Smith  * multiple times in the its "reg" property will only count once.
63*911a8882SAlex Smith  */
64*911a8882SAlex Smith unsigned int jz4780_nemc_num_banks(struct device *dev)
65*911a8882SAlex Smith {
66*911a8882SAlex Smith 	const __be32 *prop;
67*911a8882SAlex Smith 	unsigned int bank, count = 0;
68*911a8882SAlex Smith 	unsigned long referenced = 0;
69*911a8882SAlex Smith 	int i = 0;
70*911a8882SAlex Smith 
71*911a8882SAlex Smith 	while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) {
72*911a8882SAlex Smith 		bank = of_read_number(prop, 1);
73*911a8882SAlex Smith 		if (!(referenced & BIT(bank))) {
74*911a8882SAlex Smith 			referenced |= BIT(bank);
75*911a8882SAlex Smith 			count++;
76*911a8882SAlex Smith 		}
77*911a8882SAlex Smith 	}
78*911a8882SAlex Smith 
79*911a8882SAlex Smith 	return count;
80*911a8882SAlex Smith }
81*911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_num_banks);
82*911a8882SAlex Smith 
83*911a8882SAlex Smith /**
84*911a8882SAlex Smith  * jz4780_nemc_set_type() - set the type of device connected to a bank
85*911a8882SAlex Smith  * @dev: child device of the NEMC.
86*911a8882SAlex Smith  * @bank: bank number to configure.
87*911a8882SAlex Smith  * @type: type of device connected to the bank.
88*911a8882SAlex Smith  */
89*911a8882SAlex Smith void jz4780_nemc_set_type(struct device *dev, unsigned int bank,
90*911a8882SAlex Smith 			  enum jz4780_nemc_bank_type type)
91*911a8882SAlex Smith {
92*911a8882SAlex Smith 	struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent);
93*911a8882SAlex Smith 	uint32_t nfcsr;
94*911a8882SAlex Smith 
95*911a8882SAlex Smith 	nfcsr = readl(nemc->base + NEMC_NFCSR);
96*911a8882SAlex Smith 
97*911a8882SAlex Smith 	/* TODO: Support toggle NAND devices. */
98*911a8882SAlex Smith 	switch (type) {
99*911a8882SAlex Smith 	case JZ4780_NEMC_BANK_SRAM:
100*911a8882SAlex Smith 		nfcsr &= ~(NEMC_NFCSR_TNFEn(bank) | NEMC_NFCSR_NFEn(bank));
101*911a8882SAlex Smith 		break;
102*911a8882SAlex Smith 	case JZ4780_NEMC_BANK_NAND:
103*911a8882SAlex Smith 		nfcsr &= ~NEMC_NFCSR_TNFEn(bank);
104*911a8882SAlex Smith 		nfcsr |= NEMC_NFCSR_NFEn(bank);
105*911a8882SAlex Smith 		break;
106*911a8882SAlex Smith 	}
107*911a8882SAlex Smith 
108*911a8882SAlex Smith 	writel(nfcsr, nemc->base + NEMC_NFCSR);
109*911a8882SAlex Smith }
110*911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_set_type);
111*911a8882SAlex Smith 
112*911a8882SAlex Smith /**
113*911a8882SAlex Smith  * jz4780_nemc_assert() - (de-)assert a NAND device's chip enable pin
114*911a8882SAlex Smith  * @dev: child device of the NEMC.
115*911a8882SAlex Smith  * @bank: bank number of device.
116*911a8882SAlex Smith  * @assert: whether the chip enable pin should be asserted.
117*911a8882SAlex Smith  *
118*911a8882SAlex Smith  * (De-)asserts the chip enable pin for the NAND device connected to the
119*911a8882SAlex Smith  * specified bank.
120*911a8882SAlex Smith  */
121*911a8882SAlex Smith void jz4780_nemc_assert(struct device *dev, unsigned int bank, bool assert)
122*911a8882SAlex Smith {
123*911a8882SAlex Smith 	struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent);
124*911a8882SAlex Smith 	uint32_t nfcsr;
125*911a8882SAlex Smith 
126*911a8882SAlex Smith 	nfcsr = readl(nemc->base + NEMC_NFCSR);
127*911a8882SAlex Smith 
128*911a8882SAlex Smith 	if (assert)
129*911a8882SAlex Smith 		nfcsr |= NEMC_NFCSR_NFCEn(bank);
130*911a8882SAlex Smith 	else
131*911a8882SAlex Smith 		nfcsr &= ~NEMC_NFCSR_NFCEn(bank);
132*911a8882SAlex Smith 
133*911a8882SAlex Smith 	writel(nfcsr, nemc->base + NEMC_NFCSR);
134*911a8882SAlex Smith }
135*911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_assert);
136*911a8882SAlex Smith 
137*911a8882SAlex Smith static uint32_t jz4780_nemc_clk_period(struct jz4780_nemc *nemc)
138*911a8882SAlex Smith {
139*911a8882SAlex Smith 	unsigned long rate;
140*911a8882SAlex Smith 
141*911a8882SAlex Smith 	rate = clk_get_rate(nemc->clk);
142*911a8882SAlex Smith 	if (!rate)
143*911a8882SAlex Smith 		return 0;
144*911a8882SAlex Smith 
145*911a8882SAlex Smith 	/* Return in picoseconds. */
146*911a8882SAlex Smith 	return div64_ul(1000000000000ull, rate);
147*911a8882SAlex Smith }
148*911a8882SAlex Smith 
149*911a8882SAlex Smith static uint32_t jz4780_nemc_ns_to_cycles(struct jz4780_nemc *nemc, uint32_t ns)
150*911a8882SAlex Smith {
151*911a8882SAlex Smith 	return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period;
152*911a8882SAlex Smith }
153*911a8882SAlex Smith 
154*911a8882SAlex Smith static bool jz4780_nemc_configure_bank(struct jz4780_nemc *nemc,
155*911a8882SAlex Smith 				       unsigned int bank,
156*911a8882SAlex Smith 				       struct device_node *node)
157*911a8882SAlex Smith {
158*911a8882SAlex Smith 	uint32_t smcr, val, cycles;
159*911a8882SAlex Smith 
160*911a8882SAlex Smith 	/*
161*911a8882SAlex Smith 	 * Conversion of tBP and tAW cycle counts to values supported by the
162*911a8882SAlex Smith 	 * hardware (round up to the next supported value).
163*911a8882SAlex Smith 	 */
164*911a8882SAlex Smith 	static const uint32_t convert_tBP_tAW[] = {
165*911a8882SAlex Smith 		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
166*911a8882SAlex Smith 
167*911a8882SAlex Smith 		/* 11 - 12 -> 12 cycles */
168*911a8882SAlex Smith 		11, 11,
169*911a8882SAlex Smith 
170*911a8882SAlex Smith 		/* 13 - 15 -> 15 cycles */
171*911a8882SAlex Smith 		12, 12, 12,
172*911a8882SAlex Smith 
173*911a8882SAlex Smith 		/* 16 - 20 -> 20 cycles */
174*911a8882SAlex Smith 		13, 13, 13, 13, 13,
175*911a8882SAlex Smith 
176*911a8882SAlex Smith 		/* 21 - 25 -> 25 cycles */
177*911a8882SAlex Smith 		14, 14, 14, 14, 14,
178*911a8882SAlex Smith 
179*911a8882SAlex Smith 		/* 26 - 31 -> 31 cycles */
180*911a8882SAlex Smith 		15, 15, 15, 15, 15, 15
181*911a8882SAlex Smith 	};
182*911a8882SAlex Smith 
183*911a8882SAlex Smith 	smcr = readl(nemc->base + NEMC_SMCRn(bank));
184*911a8882SAlex Smith 	smcr &= ~NEMC_SMCR_SMT;
185*911a8882SAlex Smith 
186*911a8882SAlex Smith 	if (!of_property_read_u32(node, "ingenic,nemc-bus-width", &val)) {
187*911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_BW_MASK;
188*911a8882SAlex Smith 		switch (val) {
189*911a8882SAlex Smith 		case 8:
190*911a8882SAlex Smith 			smcr |= NEMC_SMCR_BW_8;
191*911a8882SAlex Smith 			break;
192*911a8882SAlex Smith 		default:
193*911a8882SAlex Smith 			/*
194*911a8882SAlex Smith 			 * Earlier SoCs support a 16 bit bus width (the 4780
195*911a8882SAlex Smith 			 * does not), until those are properly supported, error.
196*911a8882SAlex Smith 			 */
197*911a8882SAlex Smith 			dev_err(nemc->dev, "unsupported bus width: %u\n", val);
198*911a8882SAlex Smith 			return false;
199*911a8882SAlex Smith 		}
200*911a8882SAlex Smith 	}
201*911a8882SAlex Smith 
202*911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tAS", &val) == 0) {
203*911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TAS_MASK;
204*911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
205*911a8882SAlex Smith 		if (cycles > 15) {
206*911a8882SAlex Smith 			dev_err(nemc->dev, "tAS %u is too high (%u cycles)\n",
207*911a8882SAlex Smith 				val, cycles);
208*911a8882SAlex Smith 			return false;
209*911a8882SAlex Smith 		}
210*911a8882SAlex Smith 
211*911a8882SAlex Smith 		smcr |= cycles << NEMC_SMCR_TAS_SHIFT;
212*911a8882SAlex Smith 	}
213*911a8882SAlex Smith 
214*911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tAH", &val) == 0) {
215*911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TAH_MASK;
216*911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
217*911a8882SAlex Smith 		if (cycles > 15) {
218*911a8882SAlex Smith 			dev_err(nemc->dev, "tAH %u is too high (%u cycles)\n",
219*911a8882SAlex Smith 				val, cycles);
220*911a8882SAlex Smith 			return false;
221*911a8882SAlex Smith 		}
222*911a8882SAlex Smith 
223*911a8882SAlex Smith 		smcr |= cycles << NEMC_SMCR_TAH_SHIFT;
224*911a8882SAlex Smith 	}
225*911a8882SAlex Smith 
226*911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tBP", &val) == 0) {
227*911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TBP_MASK;
228*911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
229*911a8882SAlex Smith 		if (cycles > 31) {
230*911a8882SAlex Smith 			dev_err(nemc->dev, "tBP %u is too high (%u cycles)\n",
231*911a8882SAlex Smith 				val, cycles);
232*911a8882SAlex Smith 			return false;
233*911a8882SAlex Smith 		}
234*911a8882SAlex Smith 
235*911a8882SAlex Smith 		smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TBP_SHIFT;
236*911a8882SAlex Smith 	}
237*911a8882SAlex Smith 
238*911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tAW", &val) == 0) {
239*911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TAW_MASK;
240*911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
241*911a8882SAlex Smith 		if (cycles > 31) {
242*911a8882SAlex Smith 			dev_err(nemc->dev, "tAW %u is too high (%u cycles)\n",
243*911a8882SAlex Smith 				val, cycles);
244*911a8882SAlex Smith 			return false;
245*911a8882SAlex Smith 		}
246*911a8882SAlex Smith 
247*911a8882SAlex Smith 		smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TAW_SHIFT;
248*911a8882SAlex Smith 	}
249*911a8882SAlex Smith 
250*911a8882SAlex Smith 	if (of_property_read_u32(node, "ingenic,nemc-tSTRV", &val) == 0) {
251*911a8882SAlex Smith 		smcr &= ~NEMC_SMCR_TSTRV_MASK;
252*911a8882SAlex Smith 		cycles = jz4780_nemc_ns_to_cycles(nemc, val);
253*911a8882SAlex Smith 		if (cycles > 63) {
254*911a8882SAlex Smith 			dev_err(nemc->dev, "tSTRV %u is too high (%u cycles)\n",
255*911a8882SAlex Smith 				val, cycles);
256*911a8882SAlex Smith 			return false;
257*911a8882SAlex Smith 		}
258*911a8882SAlex Smith 
259*911a8882SAlex Smith 		smcr |= cycles << NEMC_SMCR_TSTRV_SHIFT;
260*911a8882SAlex Smith 	}
261*911a8882SAlex Smith 
262*911a8882SAlex Smith 	writel(smcr, nemc->base + NEMC_SMCRn(bank));
263*911a8882SAlex Smith 	return true;
264*911a8882SAlex Smith }
265*911a8882SAlex Smith 
266*911a8882SAlex Smith static int jz4780_nemc_probe(struct platform_device *pdev)
267*911a8882SAlex Smith {
268*911a8882SAlex Smith 	struct device *dev = &pdev->dev;
269*911a8882SAlex Smith 	struct jz4780_nemc *nemc;
270*911a8882SAlex Smith 	struct resource *res;
271*911a8882SAlex Smith 	struct device_node *child;
272*911a8882SAlex Smith 	const __be32 *prop;
273*911a8882SAlex Smith 	unsigned int bank;
274*911a8882SAlex Smith 	unsigned long referenced;
275*911a8882SAlex Smith 	int i, ret;
276*911a8882SAlex Smith 
277*911a8882SAlex Smith 	nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL);
278*911a8882SAlex Smith 	if (!nemc)
279*911a8882SAlex Smith 		return -ENOMEM;
280*911a8882SAlex Smith 
281*911a8882SAlex Smith 	spin_lock_init(&nemc->lock);
282*911a8882SAlex Smith 	nemc->dev = dev;
283*911a8882SAlex Smith 
284*911a8882SAlex Smith 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
285*911a8882SAlex Smith 	nemc->base = devm_ioremap_resource(dev, res);
286*911a8882SAlex Smith 	if (IS_ERR(nemc->base)) {
287*911a8882SAlex Smith 		dev_err(dev, "failed to get I/O memory\n");
288*911a8882SAlex Smith 		return PTR_ERR(nemc->base);
289*911a8882SAlex Smith 	}
290*911a8882SAlex Smith 
291*911a8882SAlex Smith 	writel(0, nemc->base + NEMC_NFCSR);
292*911a8882SAlex Smith 
293*911a8882SAlex Smith 	nemc->clk = devm_clk_get(dev, NULL);
294*911a8882SAlex Smith 	if (IS_ERR(nemc->clk)) {
295*911a8882SAlex Smith 		dev_err(dev, "failed to get clock\n");
296*911a8882SAlex Smith 		return PTR_ERR(nemc->clk);
297*911a8882SAlex Smith 	}
298*911a8882SAlex Smith 
299*911a8882SAlex Smith 	ret = clk_prepare_enable(nemc->clk);
300*911a8882SAlex Smith 	if (ret) {
301*911a8882SAlex Smith 		dev_err(dev, "failed to enable clock: %d\n", ret);
302*911a8882SAlex Smith 		return ret;
303*911a8882SAlex Smith 	}
304*911a8882SAlex Smith 
305*911a8882SAlex Smith 	nemc->clk_period = jz4780_nemc_clk_period(nemc);
306*911a8882SAlex Smith 	if (!nemc->clk_period) {
307*911a8882SAlex Smith 		dev_err(dev, "failed to calculate clock period\n");
308*911a8882SAlex Smith 		clk_disable_unprepare(nemc->clk);
309*911a8882SAlex Smith 		return -EINVAL;
310*911a8882SAlex Smith 	}
311*911a8882SAlex Smith 
312*911a8882SAlex Smith 	/*
313*911a8882SAlex Smith 	 * Iterate over child devices, check that they do not conflict with
314*911a8882SAlex Smith 	 * each other, and register child devices for them. If a child device
315*911a8882SAlex Smith 	 * has invalid properties, it is ignored and no platform device is
316*911a8882SAlex Smith 	 * registered for it.
317*911a8882SAlex Smith 	 */
318*911a8882SAlex Smith 	for_each_child_of_node(nemc->dev->of_node, child) {
319*911a8882SAlex Smith 		referenced = 0;
320*911a8882SAlex Smith 		i = 0;
321*911a8882SAlex Smith 		while ((prop = of_get_address(child, i++, NULL, NULL))) {
322*911a8882SAlex Smith 			bank = of_read_number(prop, 1);
323*911a8882SAlex Smith 			if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) {
324*911a8882SAlex Smith 				dev_err(nemc->dev,
325*911a8882SAlex Smith 					"%s requests invalid bank %u\n",
326*911a8882SAlex Smith 					child->full_name, bank);
327*911a8882SAlex Smith 
328*911a8882SAlex Smith 				/* Will continue the outer loop below. */
329*911a8882SAlex Smith 				referenced = 0;
330*911a8882SAlex Smith 				break;
331*911a8882SAlex Smith 			}
332*911a8882SAlex Smith 
333*911a8882SAlex Smith 			referenced |= BIT(bank);
334*911a8882SAlex Smith 		}
335*911a8882SAlex Smith 
336*911a8882SAlex Smith 		if (!referenced) {
337*911a8882SAlex Smith 			dev_err(nemc->dev, "%s has no addresses\n",
338*911a8882SAlex Smith 				child->full_name);
339*911a8882SAlex Smith 			continue;
340*911a8882SAlex Smith 		} else if (nemc->banks_present & referenced) {
341*911a8882SAlex Smith 			dev_err(nemc->dev, "%s conflicts with another node\n",
342*911a8882SAlex Smith 				child->full_name);
343*911a8882SAlex Smith 			continue;
344*911a8882SAlex Smith 		}
345*911a8882SAlex Smith 
346*911a8882SAlex Smith 		/* Configure bank parameters. */
347*911a8882SAlex Smith 		for_each_set_bit(bank, &referenced, JZ4780_NEMC_NUM_BANKS) {
348*911a8882SAlex Smith 			if (!jz4780_nemc_configure_bank(nemc, bank, child)) {
349*911a8882SAlex Smith 				referenced = 0;
350*911a8882SAlex Smith 				break;
351*911a8882SAlex Smith 			}
352*911a8882SAlex Smith 		}
353*911a8882SAlex Smith 
354*911a8882SAlex Smith 		if (referenced) {
355*911a8882SAlex Smith 			if (of_platform_device_create(child, NULL, nemc->dev))
356*911a8882SAlex Smith 				nemc->banks_present |= referenced;
357*911a8882SAlex Smith 		}
358*911a8882SAlex Smith 	}
359*911a8882SAlex Smith 
360*911a8882SAlex Smith 	platform_set_drvdata(pdev, nemc);
361*911a8882SAlex Smith 	dev_info(dev, "JZ4780 NEMC initialised\n");
362*911a8882SAlex Smith 	return 0;
363*911a8882SAlex Smith }
364*911a8882SAlex Smith 
365*911a8882SAlex Smith static int jz4780_nemc_remove(struct platform_device *pdev)
366*911a8882SAlex Smith {
367*911a8882SAlex Smith 	struct jz4780_nemc *nemc = platform_get_drvdata(pdev);
368*911a8882SAlex Smith 
369*911a8882SAlex Smith 	clk_disable_unprepare(nemc->clk);
370*911a8882SAlex Smith 	return 0;
371*911a8882SAlex Smith }
372*911a8882SAlex Smith 
373*911a8882SAlex Smith static const struct of_device_id jz4780_nemc_dt_match[] = {
374*911a8882SAlex Smith 	{ .compatible = "ingenic,jz4780-nemc" },
375*911a8882SAlex Smith 	{},
376*911a8882SAlex Smith };
377*911a8882SAlex Smith 
378*911a8882SAlex Smith static struct platform_driver jz4780_nemc_driver = {
379*911a8882SAlex Smith 	.probe		= jz4780_nemc_probe,
380*911a8882SAlex Smith 	.remove		= jz4780_nemc_remove,
381*911a8882SAlex Smith 	.driver	= {
382*911a8882SAlex Smith 		.name	= "jz4780-nemc",
383*911a8882SAlex Smith 		.of_match_table = of_match_ptr(jz4780_nemc_dt_match),
384*911a8882SAlex Smith 	},
385*911a8882SAlex Smith };
386*911a8882SAlex Smith 
387*911a8882SAlex Smith static int __init jz4780_nemc_init(void)
388*911a8882SAlex Smith {
389*911a8882SAlex Smith 	return platform_driver_register(&jz4780_nemc_driver);
390*911a8882SAlex Smith }
391*911a8882SAlex Smith subsys_initcall(jz4780_nemc_init);
392