Lines Matching full:bch

3  * JZ4725B BCH controller driver
59 /* Timeout for BCH calculation/correction. */
62 static inline void jz4725b_bch_config_set(struct ingenic_ecc *bch, u32 cfg) in jz4725b_bch_config_set() argument
64 writel(cfg, bch->base + BCH_BHCSR); in jz4725b_bch_config_set()
67 static inline void jz4725b_bch_config_clear(struct ingenic_ecc *bch, u32 cfg) in jz4725b_bch_config_clear() argument
69 writel(cfg, bch->base + BCH_BHCCR); in jz4725b_bch_config_clear()
72 static int jz4725b_bch_reset(struct ingenic_ecc *bch, in jz4725b_bch_reset() argument
78 writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); in jz4725b_bch_reset()
80 /* Initialise and enable BCH. */ in jz4725b_bch_reset()
81 jz4725b_bch_config_clear(bch, 0x1f); in jz4725b_bch_reset()
82 jz4725b_bch_config_set(bch, BCH_BHCR_BCHE); in jz4725b_bch_reset()
85 jz4725b_bch_config_set(bch, BCH_BHCR_BSEL); in jz4725b_bch_reset()
87 jz4725b_bch_config_clear(bch, BCH_BHCR_BSEL); in jz4725b_bch_reset()
90 jz4725b_bch_config_set(bch, BCH_BHCR_ENCE); in jz4725b_bch_reset()
92 jz4725b_bch_config_clear(bch, BCH_BHCR_ENCE); in jz4725b_bch_reset()
94 jz4725b_bch_config_set(bch, BCH_BHCR_INIT); in jz4725b_bch_reset()
104 /* Set up BCH count register. */ in jz4725b_bch_reset()
107 writel(reg, bch->base + BCH_BHCNT); in jz4725b_bch_reset()
112 static void jz4725b_bch_disable(struct ingenic_ecc *bch) in jz4725b_bch_disable() argument
115 writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); in jz4725b_bch_disable()
118 jz4725b_bch_config_clear(bch, BCH_BHCR_BCHE); in jz4725b_bch_disable()
121 static void jz4725b_bch_write_data(struct ingenic_ecc *bch, const u8 *buf, in jz4725b_bch_write_data() argument
125 writeb(*buf++, bch->base + BCH_BHDR); in jz4725b_bch_write_data()
128 static void jz4725b_bch_read_parity(struct ingenic_ecc *bch, u8 *buf, in jz4725b_bch_read_parity() argument
139 *dest32++ = readl_relaxed(bch->base + BCH_BHPAR0 + offset); in jz4725b_bch_read_parity()
144 val = readl_relaxed(bch->base + BCH_BHPAR0 + offset); in jz4725b_bch_read_parity()
158 static int jz4725b_bch_wait_complete(struct ingenic_ecc *bch, unsigned int irq, in jz4725b_bch_wait_complete() argument
170 ret = readl_relaxed_poll_timeout(bch->base + BCH_BHINT, reg, in jz4725b_bch_wait_complete()
178 writel(reg, bch->base + BCH_BHINT); in jz4725b_bch_wait_complete()
183 static int jz4725b_calculate(struct ingenic_ecc *bch, in jz4725b_calculate() argument
189 mutex_lock(&bch->lock); in jz4725b_calculate()
191 ret = jz4725b_bch_reset(bch, params, true); in jz4725b_calculate()
193 dev_err(bch->dev, "Unable to init BCH with given parameters\n"); in jz4725b_calculate()
197 jz4725b_bch_write_data(bch, buf, params->size); in jz4725b_calculate()
199 ret = jz4725b_bch_wait_complete(bch, BCH_BHINT_ENCF, NULL); in jz4725b_calculate()
201 dev_err(bch->dev, "timed out while calculating ECC\n"); in jz4725b_calculate()
205 jz4725b_bch_read_parity(bch, ecc_code, params->bytes); in jz4725b_calculate()
208 jz4725b_bch_disable(bch); in jz4725b_calculate()
209 mutex_unlock(&bch->lock); in jz4725b_calculate()
214 static int jz4725b_correct(struct ingenic_ecc *bch, in jz4725b_correct() argument
222 mutex_lock(&bch->lock); in jz4725b_correct()
224 ret = jz4725b_bch_reset(bch, params, false); in jz4725b_correct()
226 dev_err(bch->dev, "Unable to init BCH with given parameters\n"); in jz4725b_correct()
230 jz4725b_bch_write_data(bch, buf, params->size); in jz4725b_correct()
231 jz4725b_bch_write_data(bch, ecc_code, params->bytes); in jz4725b_correct()
233 ret = jz4725b_bch_wait_complete(bch, BCH_BHINT_DECF, &reg); in jz4725b_correct()
235 dev_err(bch->dev, "timed out while correcting data\n"); in jz4725b_correct()
258 reg = readl(bch->base + BCH_BHERR0 + (i * 4)); in jz4725b_correct()
266 jz4725b_bch_disable(bch); in jz4725b_correct()
267 mutex_unlock(&bch->lock); in jz4725b_correct()
279 { .compatible = "ingenic,jz4725b-bch", .data = &jz4725b_bch_ops },
287 .name = "jz4725b-bch",
294 MODULE_DESCRIPTION("Ingenic JZ4725B BCH controller driver");