4747#define ADC_V1_INTCLR (x ) ((x) + 0x18)
4848#define ADC_V1_MUX (x ) ((x) + 0x1c)
4949
50+ /* S3C2410 ADC registers definitions */
51+ #define ADC_S3C2410_MUX (x ) ((x) + 0x18)
52+
5053/* Future ADC_V2 registers definitions */
5154#define ADC_V2_CON1 (x ) ((x) + 0x00)
5255#define ADC_V2_CON2 (x ) ((x) + 0x04)
6366
6467/* Bit definitions for S3C2410 ADC */
6568#define ADC_S3C2410_CON_SELMUX (x ) (((x) & 7) << 3)
69+ #define ADC_S3C2410_DATX_MASK 0x3FF
70+ #define ADC_S3C2416_CON_RES_SEL (1u << 3)
6671
6772/* Bit definitions for ADC_V2 */
6873#define ADC_V2_CON1_SOFT_RESET (1u << 2)
8085
8186/* Bit definitions common for ADC_V1 and ADC_V2 */
8287#define ADC_CON_EN_START (1u << 0)
88+ #define ADC_CON_EN_START_MASK (0x3 << 0)
8389#define ADC_DATX_MASK 0xFFF
8490
8591#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
@@ -103,6 +109,8 @@ struct exynos_adc {
103109struct exynos_adc_data {
104110 int num_channels ;
105111 bool needs_sclk ;
112+ bool needs_adc_phy ;
113+ u32 mask ;
106114
107115 void (* init_hw )(struct exynos_adc * info );
108116 void (* exit_hw )(struct exynos_adc * info );
@@ -174,7 +182,8 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info)
174182{
175183 u32 con1 ;
176184
177- writel (1 , info -> enable_reg );
185+ if (info -> data -> needs_adc_phy )
186+ writel (1 , info -> enable_reg );
178187
179188 /* set default prescaler values and Enable prescaler */
180189 con1 = ADC_V1_CON_PRSCLV (49 ) | ADC_V1_CON_PRSCEN ;
@@ -188,7 +197,8 @@ static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
188197{
189198 u32 con ;
190199
191- writel (0 , info -> enable_reg );
200+ if (info -> data -> needs_adc_phy )
201+ writel (0 , info -> enable_reg );
192202
193203 con = readl (ADC_V1_CON (info -> regs ));
194204 con |= ADC_V1_CON_STANDBY ;
@@ -213,13 +223,62 @@ static void exynos_adc_v1_start_conv(struct exynos_adc *info,
213223
214224static const struct exynos_adc_data exynos_adc_v1_data = {
215225 .num_channels = MAX_ADC_V1_CHANNELS ,
226+ .mask = ADC_DATX_MASK , /* 12 bit ADC resolution */
227+ .needs_adc_phy = true,
216228
217229 .init_hw = exynos_adc_v1_init_hw ,
218230 .exit_hw = exynos_adc_v1_exit_hw ,
219231 .clear_irq = exynos_adc_v1_clear_irq ,
220232 .start_conv = exynos_adc_v1_start_conv ,
221233};
222234
235+ static void exynos_adc_s3c2416_start_conv (struct exynos_adc * info ,
236+ unsigned long addr )
237+ {
238+ u32 con1 ;
239+
240+ /* Enable 12 bit ADC resolution */
241+ con1 = readl (ADC_V1_CON (info -> regs ));
242+ con1 |= ADC_S3C2416_CON_RES_SEL ;
243+ writel (con1 , ADC_V1_CON (info -> regs ));
244+
245+ /* Select channel for S3C2416 */
246+ writel (addr , ADC_S3C2410_MUX (info -> regs ));
247+
248+ con1 = readl (ADC_V1_CON (info -> regs ));
249+ writel (con1 | ADC_CON_EN_START , ADC_V1_CON (info -> regs ));
250+ }
251+
252+ static struct exynos_adc_data const exynos_adc_s3c2416_data = {
253+ .num_channels = MAX_ADC_V1_CHANNELS ,
254+ .mask = ADC_DATX_MASK , /* 12 bit ADC resolution */
255+
256+ .init_hw = exynos_adc_v1_init_hw ,
257+ .exit_hw = exynos_adc_v1_exit_hw ,
258+ .start_conv = exynos_adc_s3c2416_start_conv ,
259+ };
260+
261+ static void exynos_adc_s3c2443_start_conv (struct exynos_adc * info ,
262+ unsigned long addr )
263+ {
264+ u32 con1 ;
265+
266+ /* Select channel for S3C2433 */
267+ writel (addr , ADC_S3C2410_MUX (info -> regs ));
268+
269+ con1 = readl (ADC_V1_CON (info -> regs ));
270+ writel (con1 | ADC_CON_EN_START , ADC_V1_CON (info -> regs ));
271+ }
272+
273+ static struct exynos_adc_data const exynos_adc_s3c2443_data = {
274+ .num_channels = MAX_ADC_V1_CHANNELS ,
275+ .mask = ADC_S3C2410_DATX_MASK , /* 10 bit ADC resolution */
276+
277+ .init_hw = exynos_adc_v1_init_hw ,
278+ .exit_hw = exynos_adc_v1_exit_hw ,
279+ .start_conv = exynos_adc_s3c2443_start_conv ,
280+ };
281+
223282static void exynos_adc_s3c64xx_start_conv (struct exynos_adc * info ,
224283 unsigned long addr )
225284{
@@ -231,8 +290,18 @@ static void exynos_adc_s3c64xx_start_conv(struct exynos_adc *info,
231290 writel (con1 | ADC_CON_EN_START , ADC_V1_CON (info -> regs ));
232291}
233292
293+ static struct exynos_adc_data const exynos_adc_s3c24xx_data = {
294+ .num_channels = MAX_ADC_V1_CHANNELS ,
295+ .mask = ADC_S3C2410_DATX_MASK , /* 10 bit ADC resolution */
296+
297+ .init_hw = exynos_adc_v1_init_hw ,
298+ .exit_hw = exynos_adc_v1_exit_hw ,
299+ .start_conv = exynos_adc_s3c64xx_start_conv ,
300+ };
301+
234302static struct exynos_adc_data const exynos_adc_s3c64xx_data = {
235303 .num_channels = MAX_ADC_V1_CHANNELS ,
304+ .mask = ADC_DATX_MASK , /* 12 bit ADC resolution */
236305
237306 .init_hw = exynos_adc_v1_init_hw ,
238307 .exit_hw = exynos_adc_v1_exit_hw ,
@@ -244,7 +313,8 @@ static void exynos_adc_v2_init_hw(struct exynos_adc *info)
244313{
245314 u32 con1 , con2 ;
246315
247- writel (1 , info -> enable_reg );
316+ if (info -> data -> needs_adc_phy )
317+ writel (1 , info -> enable_reg );
248318
249319 con1 = ADC_V2_CON1_SOFT_RESET ;
250320 writel (con1 , ADC_V2_CON1 (info -> regs ));
@@ -261,7 +331,8 @@ static void exynos_adc_v2_exit_hw(struct exynos_adc *info)
261331{
262332 u32 con ;
263333
264- writel (0 , info -> enable_reg );
334+ if (info -> data -> needs_adc_phy )
335+ writel (0 , info -> enable_reg );
265336
266337 con = readl (ADC_V2_CON1 (info -> regs ));
267338 con &= ~ADC_CON_EN_START ;
@@ -289,6 +360,8 @@ static void exynos_adc_v2_start_conv(struct exynos_adc *info,
289360
290361static const struct exynos_adc_data exynos_adc_v2_data = {
291362 .num_channels = MAX_ADC_V2_CHANNELS ,
363+ .mask = ADC_DATX_MASK , /* 12 bit ADC resolution */
364+ .needs_adc_phy = true,
292365
293366 .init_hw = exynos_adc_v2_init_hw ,
294367 .exit_hw = exynos_adc_v2_exit_hw ,
@@ -298,7 +371,9 @@ static const struct exynos_adc_data exynos_adc_v2_data = {
298371
299372static const struct exynos_adc_data exynos3250_adc_data = {
300373 .num_channels = MAX_EXYNOS3250_ADC_CHANNELS ,
374+ .mask = ADC_DATX_MASK , /* 12 bit ADC resolution */
301375 .needs_sclk = true,
376+ .needs_adc_phy = true,
302377
303378 .init_hw = exynos_adc_v2_init_hw ,
304379 .exit_hw = exynos_adc_v2_exit_hw ,
@@ -308,6 +383,18 @@ static const struct exynos_adc_data exynos3250_adc_data = {
308383
309384static const struct of_device_id exynos_adc_match [] = {
310385 {
386+ .compatible = "samsung,s3c2410-adc" ,
387+ .data = & exynos_adc_s3c24xx_data ,
388+ }, {
389+ .compatible = "samsung,s3c2416-adc" ,
390+ .data = & exynos_adc_s3c2416_data ,
391+ }, {
392+ .compatible = "samsung,s3c2440-adc" ,
393+ .data = & exynos_adc_s3c24xx_data ,
394+ }, {
395+ .compatible = "samsung,s3c2443-adc" ,
396+ .data = & exynos_adc_s3c2443_data ,
397+ }, {
311398 .compatible = "samsung,s3c6410-adc" ,
312399 .data = & exynos_adc_s3c64xx_data ,
313400 }, {
@@ -373,9 +460,10 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
373460static irqreturn_t exynos_adc_isr (int irq , void * dev_id )
374461{
375462 struct exynos_adc * info = (struct exynos_adc * )dev_id ;
463+ u32 mask = info -> data -> mask ;
376464
377465 /* Read value */
378- info -> value = readl (ADC_V1_DATX (info -> regs )) & ADC_DATX_MASK ;
466+ info -> value = readl (ADC_V1_DATX (info -> regs )) & mask ;
379467
380468 /* clear irq */
381469 if (info -> data -> clear_irq )
@@ -468,10 +556,13 @@ static int exynos_adc_probe(struct platform_device *pdev)
468556 if (IS_ERR (info -> regs ))
469557 return PTR_ERR (info -> regs );
470558
471- mem = platform_get_resource (pdev , IORESOURCE_MEM , 1 );
472- info -> enable_reg = devm_ioremap_resource (& pdev -> dev , mem );
473- if (IS_ERR (info -> enable_reg ))
474- return PTR_ERR (info -> enable_reg );
559+
560+ if (info -> data -> needs_adc_phy ) {
561+ mem = platform_get_resource (pdev , IORESOURCE_MEM , 1 );
562+ info -> enable_reg = devm_ioremap_resource (& pdev -> dev , mem );
563+ if (IS_ERR (info -> enable_reg ))
564+ return PTR_ERR (info -> enable_reg );
565+ }
475566
476567 irq = platform_get_irq (pdev , 0 );
477568 if (irq < 0 ) {
0 commit comments