@@ -182,6 +182,7 @@ struct sunxi_nand_hw_ecc {
182182 *
183183 * @node: used to store NAND chips into a list
184184 * @nand: base NAND chip structure
185+ * @ecc: ECC controller structure
185186 * @clk_rate: clk_rate required for this NAND chip
186187 * @timing_cfg: TIMING_CFG register value for this NAND chip
187188 * @timing_ctl: TIMING_CTL register value for this NAND chip
@@ -191,6 +192,7 @@ struct sunxi_nand_hw_ecc {
191192struct sunxi_nand_chip {
192193 struct list_head node ;
193194 struct nand_chip nand ;
195+ struct sunxi_nand_hw_ecc * ecc ;
194196 unsigned long clk_rate ;
195197 u32 timing_cfg ;
196198 u32 timing_ctl ;
@@ -676,15 +678,15 @@ static void sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, uint8_t *buf,
676678
677679static void sunxi_nfc_hw_ecc_enable (struct nand_chip * nand )
678680{
681+ struct sunxi_nand_chip * sunxi_nand = to_sunxi_nand (nand );
679682 struct sunxi_nfc * nfc = to_sunxi_nfc (nand -> controller );
680- struct sunxi_nand_hw_ecc * data = nand -> ecc .priv ;
681683 u32 ecc_ctl ;
682684
683685 ecc_ctl = readl (nfc -> regs + NFC_REG_ECC_CTL );
684686 ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE |
685687 NFC_ECC_BLOCK_SIZE_MSK );
686- ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE (data -> mode ) | NFC_ECC_EXCEPTION |
687- NFC_ECC_PIPELINE ;
688+ ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE (sunxi_nand -> ecc -> mode ) |
689+ NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE ;
688690
689691 if (nand -> ecc .size == 512 )
690692 ecc_ctl |= NFC_ECC_BLOCK_512 ;
@@ -1597,20 +1599,20 @@ static const struct mtd_ooblayout_ops sunxi_nand_ooblayout_ops = {
15971599 .free = sunxi_nand_ooblayout_free ,
15981600};
15991601
1600- static void sunxi_nand_hw_ecc_ctrl_cleanup (struct nand_ecc_ctrl * ecc )
1602+ static void sunxi_nand_hw_ecc_ctrl_cleanup (struct sunxi_nand_chip * sunxi_nand )
16011603{
1602- kfree (ecc -> priv );
1604+ kfree (sunxi_nand -> ecc );
16031605}
16041606
16051607static int sunxi_nand_hw_ecc_ctrl_init (struct nand_chip * nand ,
16061608 struct nand_ecc_ctrl * ecc ,
16071609 struct device_node * np )
16081610{
16091611 static const u8 strengths [] = { 16 , 24 , 28 , 32 , 40 , 48 , 56 , 60 , 64 };
1612+ struct sunxi_nand_chip * sunxi_nand = to_sunxi_nand (nand );
16101613 struct sunxi_nfc * nfc = to_sunxi_nfc (nand -> controller );
16111614 struct mtd_info * mtd = nand_to_mtd (nand );
16121615 struct nand_device * nanddev = mtd_to_nanddev (mtd );
1613- struct sunxi_nand_hw_ecc * data ;
16141616 int nsectors ;
16151617 int ret ;
16161618 int i ;
@@ -1647,8 +1649,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
16471649 if (ecc -> size != 512 && ecc -> size != 1024 )
16481650 return - EINVAL ;
16491651
1650- data = kzalloc (sizeof (* data ), GFP_KERNEL );
1651- if (!data )
1652+ sunxi_nand -> ecc = kzalloc (sizeof (* sunxi_nand -> ecc ), GFP_KERNEL );
1653+ if (!sunxi_nand -> ecc )
16521654 return - ENOMEM ;
16531655
16541656 /* Prefer 1k ECC chunk over 512 ones */
@@ -1675,7 +1677,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
16751677 goto err ;
16761678 }
16771679
1678- data -> mode = i ;
1680+ sunxi_nand -> ecc -> mode = i ;
16791681
16801682 /* HW ECC always request ECC bytes for 1024 bytes blocks */
16811683 ecc -> bytes = DIV_ROUND_UP (ecc -> strength * fls (8 * 1024 ), 8 );
@@ -1693,7 +1695,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
16931695 ecc -> read_oob = sunxi_nfc_hw_ecc_read_oob ;
16941696 ecc -> write_oob = sunxi_nfc_hw_ecc_write_oob ;
16951697 mtd_set_ooblayout (mtd , & sunxi_nand_ooblayout_ops );
1696- ecc -> priv = data ;
16971698
16981699 if (nfc -> dmac ) {
16991700 ecc -> read_page = sunxi_nfc_hw_ecc_read_page_dma ;
@@ -1714,16 +1715,18 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
17141715 return 0 ;
17151716
17161717err :
1717- kfree (data );
1718+ kfree (sunxi_nand -> ecc );
17181719
17191720 return ret ;
17201721}
17211722
1722- static void sunxi_nand_ecc_cleanup (struct nand_ecc_ctrl * ecc )
1723+ static void sunxi_nand_ecc_cleanup (struct sunxi_nand_chip * sunxi_nand )
17231724{
1725+ struct nand_ecc_ctrl * ecc = & sunxi_nand -> nand .ecc ;
1726+
17241727 switch (ecc -> engine_type ) {
17251728 case NAND_ECC_ENGINE_TYPE_ON_HOST :
1726- sunxi_nand_hw_ecc_ctrl_cleanup (ecc );
1729+ sunxi_nand_hw_ecc_ctrl_cleanup (sunxi_nand );
17271730 break ;
17281731 case NAND_ECC_ENGINE_TYPE_NONE :
17291732 default :
@@ -2053,7 +2056,7 @@ static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc)
20532056 ret = mtd_device_unregister (nand_to_mtd (chip ));
20542057 WARN_ON (ret );
20552058 nand_cleanup (chip );
2056- sunxi_nand_ecc_cleanup (& chip -> ecc );
2059+ sunxi_nand_ecc_cleanup (sunxi_nand );
20572060 list_del (& sunxi_nand -> node );
20582061 }
20592062}
0 commit comments