Lines Matching refs:spifi
64 static int nxp_spifi_wait_for_cmd(struct nxp_spifi *spifi) in nxp_spifi_wait_for_cmd() argument
69 ret = readb_poll_timeout(spifi->io_base + SPIFI_STAT, stat, in nxp_spifi_wait_for_cmd()
72 dev_warn(spifi->dev, "command timed out\n"); in nxp_spifi_wait_for_cmd()
77 static int nxp_spifi_reset(struct nxp_spifi *spifi) in nxp_spifi_reset() argument
82 writel(SPIFI_STAT_RESET, spifi->io_base + SPIFI_STAT); in nxp_spifi_reset()
83 ret = readb_poll_timeout(spifi->io_base + SPIFI_STAT, stat, in nxp_spifi_reset()
86 dev_warn(spifi->dev, "state reset timed out\n"); in nxp_spifi_reset()
91 static int nxp_spifi_set_memory_mode_off(struct nxp_spifi *spifi) in nxp_spifi_set_memory_mode_off() argument
95 if (!spifi->memory_mode) in nxp_spifi_set_memory_mode_off()
98 ret = nxp_spifi_reset(spifi); in nxp_spifi_set_memory_mode_off()
100 dev_err(spifi->dev, "unable to enter command mode\n"); in nxp_spifi_set_memory_mode_off()
102 spifi->memory_mode = false; in nxp_spifi_set_memory_mode_off()
107 static int nxp_spifi_set_memory_mode_on(struct nxp_spifi *spifi) in nxp_spifi_set_memory_mode_on() argument
112 if (spifi->memory_mode) in nxp_spifi_set_memory_mode_on()
115 writel(spifi->mcmd, spifi->io_base + SPIFI_MCMD); in nxp_spifi_set_memory_mode_on()
116 ret = readb_poll_timeout(spifi->io_base + SPIFI_STAT, stat, in nxp_spifi_set_memory_mode_on()
119 dev_err(spifi->dev, "unable to enter memory mode\n"); in nxp_spifi_set_memory_mode_on()
121 spifi->memory_mode = true; in nxp_spifi_set_memory_mode_on()
129 struct nxp_spifi *spifi = nor->priv; in nxp_spifi_read_reg() local
133 ret = nxp_spifi_set_memory_mode_off(spifi); in nxp_spifi_read_reg()
141 writel(cmd, spifi->io_base + SPIFI_CMD); in nxp_spifi_read_reg()
144 *buf++ = readb(spifi->io_base + SPIFI_DATA); in nxp_spifi_read_reg()
146 return nxp_spifi_wait_for_cmd(spifi); in nxp_spifi_read_reg()
152 struct nxp_spifi *spifi = nor->priv; in nxp_spifi_write_reg() local
156 ret = nxp_spifi_set_memory_mode_off(spifi); in nxp_spifi_write_reg()
165 writel(cmd, spifi->io_base + SPIFI_CMD); in nxp_spifi_write_reg()
168 writeb(*buf++, spifi->io_base + SPIFI_DATA); in nxp_spifi_write_reg()
170 return nxp_spifi_wait_for_cmd(spifi); in nxp_spifi_write_reg()
176 struct nxp_spifi *spifi = nor->priv; in nxp_spifi_read() local
179 ret = nxp_spifi_set_memory_mode_on(spifi); in nxp_spifi_read()
183 memcpy_fromio(buf, spifi->flash_base + from, len); in nxp_spifi_read()
191 struct nxp_spifi *spifi = nor->priv; in nxp_spifi_write() local
196 ret = nxp_spifi_set_memory_mode_off(spifi); in nxp_spifi_write()
200 writel(to, spifi->io_base + SPIFI_ADDR); in nxp_spifi_write()
206 SPIFI_CMD_FRAMEFORM(spifi->nor.addr_nbytes + 1); in nxp_spifi_write()
207 writel(cmd, spifi->io_base + SPIFI_CMD); in nxp_spifi_write()
210 writeb(buf[i], spifi->io_base + SPIFI_DATA); in nxp_spifi_write()
212 ret = nxp_spifi_wait_for_cmd(spifi); in nxp_spifi_write()
221 struct nxp_spifi *spifi = nor->priv; in nxp_spifi_erase() local
225 ret = nxp_spifi_set_memory_mode_off(spifi); in nxp_spifi_erase()
229 writel(offs, spifi->io_base + SPIFI_ADDR); in nxp_spifi_erase()
233 SPIFI_CMD_FRAMEFORM(spifi->nor.addr_nbytes + 1); in nxp_spifi_erase()
234 writel(cmd, spifi->io_base + SPIFI_CMD); in nxp_spifi_erase()
236 return nxp_spifi_wait_for_cmd(spifi); in nxp_spifi_erase()
239 static int nxp_spifi_setup_memory_cmd(struct nxp_spifi *spifi) in nxp_spifi_setup_memory_cmd() argument
241 switch (spifi->nor.read_proto) { in nxp_spifi_setup_memory_cmd()
243 spifi->mcmd = SPIFI_CMD_FIELDFORM_ALL_SERIAL; in nxp_spifi_setup_memory_cmd()
247 spifi->mcmd = SPIFI_CMD_FIELDFORM_QUAD_DUAL_DATA; in nxp_spifi_setup_memory_cmd()
250 dev_err(spifi->dev, "unsupported SPI read mode\n"); in nxp_spifi_setup_memory_cmd()
255 if (spifi->nor.addr_nbytes < 1 || spifi->nor.addr_nbytes > 4) in nxp_spifi_setup_memory_cmd()
258 spifi->mcmd |= SPIFI_CMD_OPCODE(spifi->nor.read_opcode) | in nxp_spifi_setup_memory_cmd()
259 SPIFI_CMD_INTLEN(spifi->nor.read_dummy / 8) | in nxp_spifi_setup_memory_cmd()
260 SPIFI_CMD_FRAMEFORM(spifi->nor.addr_nbytes + 1); in nxp_spifi_setup_memory_cmd()
280 static int nxp_spifi_setup_flash(struct nxp_spifi *spifi, in nxp_spifi_setup_flash() argument
303 dev_err(spifi->dev, "unsupported rx-bus-width\n"); in nxp_spifi_setup_flash()
337 dev_err(spifi->dev, "only mode 0 and 3 supported\n"); in nxp_spifi_setup_flash()
341 writel(ctrl, spifi->io_base + SPIFI_CTRL); in nxp_spifi_setup_flash()
343 spifi->nor.dev = spifi->dev; in nxp_spifi_setup_flash()
344 spi_nor_set_flash_node(&spifi->nor, np); in nxp_spifi_setup_flash()
345 spifi->nor.priv = spifi; in nxp_spifi_setup_flash()
346 spifi->nor.controller_ops = &nxp_spifi_controller_ops; in nxp_spifi_setup_flash()
357 nxp_spifi_dummy_id_read(&spifi->nor); in nxp_spifi_setup_flash()
359 ret = spi_nor_scan(&spifi->nor, NULL, &hwcaps); in nxp_spifi_setup_flash()
361 dev_err(spifi->dev, "device scan failed\n"); in nxp_spifi_setup_flash()
365 ret = nxp_spifi_setup_memory_cmd(spifi); in nxp_spifi_setup_flash()
367 dev_err(spifi->dev, "memory command setup failed\n"); in nxp_spifi_setup_flash()
371 ret = mtd_device_register(&spifi->nor.mtd, NULL, 0); in nxp_spifi_setup_flash()
373 dev_err(spifi->dev, "mtd device parse failed\n"); in nxp_spifi_setup_flash()
383 struct nxp_spifi *spifi; in nxp_spifi_probe() local
386 spifi = devm_kzalloc(&pdev->dev, sizeof(*spifi), GFP_KERNEL); in nxp_spifi_probe()
387 if (!spifi) in nxp_spifi_probe()
390 spifi->io_base = devm_platform_ioremap_resource_byname(pdev, "spifi"); in nxp_spifi_probe()
391 if (IS_ERR(spifi->io_base)) in nxp_spifi_probe()
392 return PTR_ERR(spifi->io_base); in nxp_spifi_probe()
394 spifi->flash_base = devm_platform_ioremap_resource_byname(pdev, "flash"); in nxp_spifi_probe()
395 if (IS_ERR(spifi->flash_base)) in nxp_spifi_probe()
396 return PTR_ERR(spifi->flash_base); in nxp_spifi_probe()
398 spifi->clk_spifi = devm_clk_get(&pdev->dev, "spifi"); in nxp_spifi_probe()
399 if (IS_ERR(spifi->clk_spifi)) { in nxp_spifi_probe()
401 return PTR_ERR(spifi->clk_spifi); in nxp_spifi_probe()
404 spifi->clk_reg = devm_clk_get(&pdev->dev, "reg"); in nxp_spifi_probe()
405 if (IS_ERR(spifi->clk_reg)) { in nxp_spifi_probe()
407 return PTR_ERR(spifi->clk_reg); in nxp_spifi_probe()
410 ret = clk_prepare_enable(spifi->clk_reg); in nxp_spifi_probe()
416 ret = clk_prepare_enable(spifi->clk_spifi); in nxp_spifi_probe()
422 spifi->dev = &pdev->dev; in nxp_spifi_probe()
423 platform_set_drvdata(pdev, spifi); in nxp_spifi_probe()
426 nxp_spifi_reset(spifi); in nxp_spifi_probe()
427 writel(0, spifi->io_base + SPIFI_IDATA); in nxp_spifi_probe()
428 writel(0, spifi->io_base + SPIFI_MCMD); in nxp_spifi_probe()
429 nxp_spifi_reset(spifi); in nxp_spifi_probe()
438 ret = nxp_spifi_setup_flash(spifi, flash_np); in nxp_spifi_probe()
448 clk_disable_unprepare(spifi->clk_spifi); in nxp_spifi_probe()
450 clk_disable_unprepare(spifi->clk_reg); in nxp_spifi_probe()
456 struct nxp_spifi *spifi = platform_get_drvdata(pdev); in nxp_spifi_remove() local
458 mtd_device_unregister(&spifi->nor.mtd); in nxp_spifi_remove()
459 clk_disable_unprepare(spifi->clk_spifi); in nxp_spifi_remove()
460 clk_disable_unprepare(spifi->clk_reg); in nxp_spifi_remove()