Lines Matching full:eeprom
3 * NXP LPC18xx/LPC43xx EEPROM memory NVMEM driver
38 /* EEPROM device requires a ~1500 kHz clock (min 800 kHz, max 1600 kHz) */
41 /* EEPROM requires 3 ms of erase/program time between each writing */
54 static inline void lpc18xx_eeprom_writel(struct lpc18xx_eeprom_dev *eeprom, in lpc18xx_eeprom_writel() argument
57 writel(val, eeprom->reg_base + reg); in lpc18xx_eeprom_writel()
60 static inline u32 lpc18xx_eeprom_readl(struct lpc18xx_eeprom_dev *eeprom, in lpc18xx_eeprom_readl() argument
63 return readl(eeprom->reg_base + reg); in lpc18xx_eeprom_readl()
66 static int lpc18xx_eeprom_busywait_until_prog(struct lpc18xx_eeprom_dev *eeprom) in lpc18xx_eeprom_busywait_until_prog() argument
71 /* Wait until EEPROM program operation has finished */ in lpc18xx_eeprom_busywait_until_prog()
75 val = lpc18xx_eeprom_readl(eeprom, LPC18XX_EEPROM_INTSTAT); in lpc18xx_eeprom_busywait_until_prog()
78 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_INTSTATCLR, in lpc18xx_eeprom_busywait_until_prog()
93 struct lpc18xx_eeprom_dev *eeprom = context; in lpc18xx_eeprom_gather_write() local
98 * The last page contains the EEPROM initialization data and is not in lpc18xx_eeprom_gather_write()
101 if ((reg > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE) || in lpc18xx_eeprom_gather_write()
102 (reg + bytes > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE)) in lpc18xx_eeprom_gather_write()
106 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, in lpc18xx_eeprom_gather_write()
109 /* Wait 100 us while the EEPROM wakes up */ in lpc18xx_eeprom_gather_write()
113 writel(*(u32 *)val, eeprom->mem_base + offset); in lpc18xx_eeprom_gather_write()
114 ret = lpc18xx_eeprom_busywait_until_prog(eeprom); in lpc18xx_eeprom_gather_write()
118 bytes -= eeprom->val_bytes; in lpc18xx_eeprom_gather_write()
119 val += eeprom->val_bytes; in lpc18xx_eeprom_gather_write()
120 offset += eeprom->val_bytes; in lpc18xx_eeprom_gather_write()
123 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, in lpc18xx_eeprom_gather_write()
132 struct lpc18xx_eeprom_dev *eeprom = context; in lpc18xx_eeprom_read() local
134 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, in lpc18xx_eeprom_read()
137 /* Wait 100 us while the EEPROM wakes up */ in lpc18xx_eeprom_read()
141 *(u32 *)val = readl(eeprom->mem_base + offset); in lpc18xx_eeprom_read()
142 bytes -= eeprom->val_bytes; in lpc18xx_eeprom_read()
143 val += eeprom->val_bytes; in lpc18xx_eeprom_read()
144 offset += eeprom->val_bytes; in lpc18xx_eeprom_read()
147 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, in lpc18xx_eeprom_read()
155 .name = "lpc18xx-eeprom",
164 struct lpc18xx_eeprom_dev *eeprom; in lpc18xx_eeprom_probe() local
171 eeprom = devm_kzalloc(dev, sizeof(*eeprom), GFP_KERNEL); in lpc18xx_eeprom_probe()
172 if (!eeprom) in lpc18xx_eeprom_probe()
176 eeprom->reg_base = devm_ioremap_resource(dev, res); in lpc18xx_eeprom_probe()
177 if (IS_ERR(eeprom->reg_base)) in lpc18xx_eeprom_probe()
178 return PTR_ERR(eeprom->reg_base); in lpc18xx_eeprom_probe()
181 eeprom->mem_base = devm_ioremap_resource(dev, res); in lpc18xx_eeprom_probe()
182 if (IS_ERR(eeprom->mem_base)) in lpc18xx_eeprom_probe()
183 return PTR_ERR(eeprom->mem_base); in lpc18xx_eeprom_probe()
185 eeprom->clk = devm_clk_get(&pdev->dev, "eeprom"); in lpc18xx_eeprom_probe()
186 if (IS_ERR(eeprom->clk)) { in lpc18xx_eeprom_probe()
187 dev_err(&pdev->dev, "failed to get eeprom clock\n"); in lpc18xx_eeprom_probe()
188 return PTR_ERR(eeprom->clk); in lpc18xx_eeprom_probe()
191 ret = clk_prepare_enable(eeprom->clk); in lpc18xx_eeprom_probe()
193 dev_err(dev, "failed to prepare/enable eeprom clk: %d\n", ret); in lpc18xx_eeprom_probe()
210 eeprom->val_bytes = 4; in lpc18xx_eeprom_probe()
211 eeprom->reg_bytes = 4; in lpc18xx_eeprom_probe()
217 clk_rate = clk_get_rate(eeprom->clk); in lpc18xx_eeprom_probe()
219 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_CLKDIV, clk_rate); in lpc18xx_eeprom_probe()
225 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_AUTOPROG, in lpc18xx_eeprom_probe()
228 lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN, in lpc18xx_eeprom_probe()
231 eeprom->size = resource_size(res); in lpc18xx_eeprom_probe()
234 lpc18xx_nvmem_config.priv = eeprom; in lpc18xx_eeprom_probe()
236 eeprom->nvmem = devm_nvmem_register(dev, &lpc18xx_nvmem_config); in lpc18xx_eeprom_probe()
237 if (IS_ERR(eeprom->nvmem)) { in lpc18xx_eeprom_probe()
238 ret = PTR_ERR(eeprom->nvmem); in lpc18xx_eeprom_probe()
242 platform_set_drvdata(pdev, eeprom); in lpc18xx_eeprom_probe()
247 clk_disable_unprepare(eeprom->clk); in lpc18xx_eeprom_probe()
254 struct lpc18xx_eeprom_dev *eeprom = platform_get_drvdata(pdev); in lpc18xx_eeprom_remove() local
256 clk_disable_unprepare(eeprom->clk); in lpc18xx_eeprom_remove()
260 { .compatible = "nxp,lpc1857-eeprom" },
269 .name = "lpc18xx-eeprom",
277 MODULE_DESCRIPTION("NXP LPC18xx EEPROM memory Driver");