Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-09 Thread Kuninori Morimoto

Hi Andy

> >> > +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
> >> > +{
> >> > +   struct device *dev = priv_to_dev(priv);
> >> > +   s32 val;
> >> > +   unsigned int i;
> >> > +
> >> > +   for (i = 0; i < 256; i++) {
> >> > +   val = cs2000_read(priv, DEVICE_CTRL);
> >> > +   if (val < 0)
> >> > +   return val;
> >> > +   if (!(val & PLL_UNLOCK))
> >> > +   return 0;
> >> > +   udelay(1);
> >> > +   }
> >>
> >> unsigned int i = 256;
> >>
> >> do {
> >> val = read();
> >> …
> >> while ((val & PLL_UNLOCK) && --i);
> >>
> >> if (!i) {
> >>  …
> >>  return -EIO;
> >>
> >> Actually -ETIMEDOUT ?
> >>
> >> }
> >
> > What is the motivation of above ?
> > It needs "i" anyway ? it needs to check (val < 0) anyway ?
> > what is the difference between do {} while <-> for(xxx)
> 
> Just a style.
> Still the question about error code.

OK. do {} while is not bad, but for () loop
can avoid pointless check I think. I would like to use it.
And yes, next version will use -ETIMEDOUT

> >> > +   of_property_read_string(np, "clock-output-names", );
> >>
> >> What about device property API?
> >
> > Sorry, which API ?
> > Many other clk-xxx.c are using this style ?
> 
> Never mind then.

Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-09 Thread Andy Shevchenko
On Mon, Nov 9, 2015 at 2:49 AM, Kuninori Morimoto
 wrote:

>> > +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
>> > +{
>> > +   struct device *dev = priv_to_dev(priv);
>> > +   s32 val;
>> > +   unsigned int i;
>> > +
>> > +   for (i = 0; i < 256; i++) {
>> > +   val = cs2000_read(priv, DEVICE_CTRL);
>> > +   if (val < 0)
>> > +   return val;
>> > +   if (!(val & PLL_UNLOCK))
>> > +   return 0;
>> > +   udelay(1);
>> > +   }
>>
>> unsigned int i = 256;
>>
>> do {
>> val = read();
>> …
>> while ((val & PLL_UNLOCK) && --i);
>>
>> if (!i) {
>>  …
>>  return -EIO;
>>
>> Actually -ETIMEDOUT ?
>>
>> }
>
> What is the motivation of above ?
> It needs "i" anyway ? it needs to check (val < 0) anyway ?
> what is the difference between do {} while <-> for(xxx)

Just a style.
Still the question about error code.

>> > +   of_property_read_string(np, "clock-output-names", );
>>
>> What about device property API?
>
> Sorry, which API ?
> Many other clk-xxx.c are using this style ?

Never mind then.

-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-09 Thread Andy Shevchenko
On Mon, Nov 9, 2015 at 2:49 AM, Kuninori Morimoto
 wrote:

>> > +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
>> > +{
>> > +   struct device *dev = priv_to_dev(priv);
>> > +   s32 val;
>> > +   unsigned int i;
>> > +
>> > +   for (i = 0; i < 256; i++) {
>> > +   val = cs2000_read(priv, DEVICE_CTRL);
>> > +   if (val < 0)
>> > +   return val;
>> > +   if (!(val & PLL_UNLOCK))
>> > +   return 0;
>> > +   udelay(1);
>> > +   }
>>
>> unsigned int i = 256;
>>
>> do {
>> val = read();
>> …
>> while ((val & PLL_UNLOCK) && --i);
>>
>> if (!i) {
>>  …
>>  return -EIO;
>>
>> Actually -ETIMEDOUT ?
>>
>> }
>
> What is the motivation of above ?
> It needs "i" anyway ? it needs to check (val < 0) anyway ?
> what is the difference between do {} while <-> for(xxx)

Just a style.
Still the question about error code.

>> > +   of_property_read_string(np, "clock-output-names", );
>>
>> What about device property API?
>
> Sorry, which API ?
> Many other clk-xxx.c are using this style ?

Never mind then.

-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-09 Thread Kuninori Morimoto

Hi Andy

> >> > +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
> >> > +{
> >> > +   struct device *dev = priv_to_dev(priv);
> >> > +   s32 val;
> >> > +   unsigned int i;
> >> > +
> >> > +   for (i = 0; i < 256; i++) {
> >> > +   val = cs2000_read(priv, DEVICE_CTRL);
> >> > +   if (val < 0)
> >> > +   return val;
> >> > +   if (!(val & PLL_UNLOCK))
> >> > +   return 0;
> >> > +   udelay(1);
> >> > +   }
> >>
> >> unsigned int i = 256;
> >>
> >> do {
> >> val = read();
> >> …
> >> while ((val & PLL_UNLOCK) && --i);
> >>
> >> if (!i) {
> >>  …
> >>  return -EIO;
> >>
> >> Actually -ETIMEDOUT ?
> >>
> >> }
> >
> > What is the motivation of above ?
> > It needs "i" anyway ? it needs to check (val < 0) anyway ?
> > what is the difference between do {} while <-> for(xxx)
> 
> Just a style.
> Still the question about error code.

OK. do {} while is not bad, but for () loop
can avoid pointless check I think. I would like to use it.
And yes, next version will use -ETIMEDOUT

> >> > +   of_property_read_string(np, "clock-output-names", );
> >>
> >> What about device property API?
> >
> > Sorry, which API ?
> > Many other clk-xxx.c are using this style ?
> 
> Never mind then.

Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-08 Thread Kuninori Morimoto

Hi

Thank you for your feedback

> > From: Kuninori Morimoto 
> 
> Hmm… Something wrong with send-email settings?

Nothing wrong. I would like to overwrite Author
(Sender and Author are same though...)

> > +#define priv_to_client(priv)   (priv->client)
> 
> to_client()?
> 
> > +#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))
> 
> to_dev() ?

I would like to have "from"

> > +static int cs2000_enable_dev_config(struct cs2000_priv *priv, bool enable)
> > +{
> > +   u32 val;
> > +   int ret;
> > +
> > +   val = enable ? ENDEV1 : 0;
> 
> Put in expression below?
> 
> > +   ret = cs2000_bset(priv, DEVICE_CFG1, ENDEV1, val);
> > +   if (ret < 0)
> > +   return ret;
> > +
> > +   val = enable ? ENDEV2 : 0;
> 
> Same.

OK

> > +   if (rate_in >= 3200 &&
> > +   rate_in < 5600)
> 
> One line here and below?

OK


> > +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
> > +{
> > +   struct device *dev = priv_to_dev(priv);
> > +   s32 val;
> > +   unsigned int i;
> > +
> > +   for (i = 0; i < 256; i++) {
> > +   val = cs2000_read(priv, DEVICE_CTRL);
> > +   if (val < 0)
> > +   return val;
> > +   if (!(val & PLL_UNLOCK))
> > +   return 0;
> > +   udelay(1);
> > +   }
> 
> unsigned int i = 256;
> 
> do {
> val = read();
> …
> while ((val & PLL_UNLOCK) && --i);
> 
> if (!i) {
>  …
>  return -EIO;
> 
> Actually -ETIMEDOUT ?
> 
> }

What is the motivation of above ?
It needs "i" anyway ? it needs to check (val < 0) anyway ?
what is the difference between do {} while <-> for(xxx)

> > +static int cs2000_clk_out_enable(struct cs2000_priv *priv, bool enable)
> > +{
> > +   u32 val = enable ? 0 : 0x3;
> 
> Redundant variable?

OK


> > +static u32 cs2000_rate_to_ratio(u32 rate_in, u32 rate_out)
> > +{
> > +   u64 ratio;
> > +
> > +   /*
> > +* ratio = rate_out / rate_in * 2^20
> > +*
> > +* To avoid over flow, rate_out is u64
> > +* The result should be u32
> > +*/
> > +   ratio = (u64)rate_out << 20;
> > +   do_div(ratio, rate_in);
> > +
> > +   return (u32)ratio;
> 
> No need to do explicit casting.
> 
> > +}
> > +
> > +static unsigned long cs2000_ratio_to_rate(u32 ratio, u32 rate_in)
> > +{
> > +   u64 rate_out;
> > +
> > +   /*
> > +* ratio = rate_out / rate_in * 2^20
> > +*
> > +* To avoid over flow, rate_out is u64
> > +* The result should be u32
> 
> u32 or unsigned long?
> 
> Btw, dots at the end of sentences.
> 
> > +*/
> > +
> > +   rate_out = (u64)ratio * rate_in;
> > +   return (unsigned long)(rate_out >> 20);
> 
> Same.

OK

> > +static int cs2000_ratio_set(struct cs2000_priv *priv,
> > +   int ch, u32 rate_in, u32 rate_out)
> > +{
> > +   u32 val;
> > +   unsigned int i;
> > +   int ret;
> > +
> > +   if (CH_SIZE_ERR(ch))
> > +   return -EINVAL;
> > +
> > +   val = cs2000_rate_to_ratio(rate_in, rate_out);
> > +   for (i = 0; i < 4; i++)
> 
> 4 is magic, you have define already.

OK

> > +   /*
> > +* FIXME
> > +*
> > +* this driver supports static ratio mode only
> > +* at this point
> > +*/
> 
> One line?

OK

> > +static int cs2000_clk_register(struct cs2000_priv *priv)
> > +{
> > +   struct device *dev = priv_to_dev(priv);
> > +   struct device_node *np = dev->of_node;
> > +   struct clk_init_data init;
> > +   const char *name = np->name;
> > +   struct clk *clk;
> > +   static const char *parent_names[CLK_MAX];
> > +   int ch = 0; /* it uses ch0 only at this point */
> > +   int rate;
> > +   int ret;
> > +
> > +   of_property_read_string(np, "clock-output-names", );
> 
> What about device property API?

Sorry, which API ?
Many other clk-xxx.c are using this style ?

> > +static int cs2000_version_print(struct cs2000_priv *priv)
> > +{
> > +   struct i2c_client *client = priv_to_client(priv);
> > +   struct device *dev = >dev;
> > +   s32 val = cs2000_read(priv, DEVICE_ID);
> > +   const char *revision;
> > +
> 
> Move read here to see how val is assigned.
> 
> s32 val;
> 
> …
> 
> val = read();
> 
> > +   if (val < 0)
> > +   return val;
> > +
> > +   /* CS2000 should be 0x0 */
> > +   if (0 != (val >> 3))
> 
> if (val >> 3)
> 
> > +   return -EIO;
> > +
> > +   switch (val & 0x7) {
> 
> magic
> 
> > +   case 0x4:
> 
> magic
> 
> > +   revision = "B2 / B3";
> > +   break;
> > +   case 0x6:
> 
> magic

OK


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-08 Thread Kuninori Morimoto

Hi

Thank you for your feedback

> > From: Kuninori Morimoto 
> 
> Hmm… Something wrong with send-email settings?

Nothing wrong. I would like to overwrite Author
(Sender and Author are same though...)

> > +#define priv_to_client(priv)   (priv->client)
> 
> to_client()?
> 
> > +#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))
> 
> to_dev() ?

I would like to have "from"

> > +static int cs2000_enable_dev_config(struct cs2000_priv *priv, bool enable)
> > +{
> > +   u32 val;
> > +   int ret;
> > +
> > +   val = enable ? ENDEV1 : 0;
> 
> Put in expression below?
> 
> > +   ret = cs2000_bset(priv, DEVICE_CFG1, ENDEV1, val);
> > +   if (ret < 0)
> > +   return ret;
> > +
> > +   val = enable ? ENDEV2 : 0;
> 
> Same.

OK

> > +   if (rate_in >= 3200 &&
> > +   rate_in < 5600)
> 
> One line here and below?

OK


> > +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
> > +{
> > +   struct device *dev = priv_to_dev(priv);
> > +   s32 val;
> > +   unsigned int i;
> > +
> > +   for (i = 0; i < 256; i++) {
> > +   val = cs2000_read(priv, DEVICE_CTRL);
> > +   if (val < 0)
> > +   return val;
> > +   if (!(val & PLL_UNLOCK))
> > +   return 0;
> > +   udelay(1);
> > +   }
> 
> unsigned int i = 256;
> 
> do {
> val = read();
> …
> while ((val & PLL_UNLOCK) && --i);
> 
> if (!i) {
>  …
>  return -EIO;
> 
> Actually -ETIMEDOUT ?
> 
> }

What is the motivation of above ?
It needs "i" anyway ? it needs to check (val < 0) anyway ?
what is the difference between do {} while <-> for(xxx)

> > +static int cs2000_clk_out_enable(struct cs2000_priv *priv, bool enable)
> > +{
> > +   u32 val = enable ? 0 : 0x3;
> 
> Redundant variable?

OK


> > +static u32 cs2000_rate_to_ratio(u32 rate_in, u32 rate_out)
> > +{
> > +   u64 ratio;
> > +
> > +   /*
> > +* ratio = rate_out / rate_in * 2^20
> > +*
> > +* To avoid over flow, rate_out is u64
> > +* The result should be u32
> > +*/
> > +   ratio = (u64)rate_out << 20;
> > +   do_div(ratio, rate_in);
> > +
> > +   return (u32)ratio;
> 
> No need to do explicit casting.
> 
> > +}
> > +
> > +static unsigned long cs2000_ratio_to_rate(u32 ratio, u32 rate_in)
> > +{
> > +   u64 rate_out;
> > +
> > +   /*
> > +* ratio = rate_out / rate_in * 2^20
> > +*
> > +* To avoid over flow, rate_out is u64
> > +* The result should be u32
> 
> u32 or unsigned long?
> 
> Btw, dots at the end of sentences.
> 
> > +*/
> > +
> > +   rate_out = (u64)ratio * rate_in;
> > +   return (unsigned long)(rate_out >> 20);
> 
> Same.

OK

> > +static int cs2000_ratio_set(struct cs2000_priv *priv,
> > +   int ch, u32 rate_in, u32 rate_out)
> > +{
> > +   u32 val;
> > +   unsigned int i;
> > +   int ret;
> > +
> > +   if (CH_SIZE_ERR(ch))
> > +   return -EINVAL;
> > +
> > +   val = cs2000_rate_to_ratio(rate_in, rate_out);
> > +   for (i = 0; i < 4; i++)
> 
> 4 is magic, you have define already.

OK

> > +   /*
> > +* FIXME
> > +*
> > +* this driver supports static ratio mode only
> > +* at this point
> > +*/
> 
> One line?

OK

> > +static int cs2000_clk_register(struct cs2000_priv *priv)
> > +{
> > +   struct device *dev = priv_to_dev(priv);
> > +   struct device_node *np = dev->of_node;
> > +   struct clk_init_data init;
> > +   const char *name = np->name;
> > +   struct clk *clk;
> > +   static const char *parent_names[CLK_MAX];
> > +   int ch = 0; /* it uses ch0 only at this point */
> > +   int rate;
> > +   int ret;
> > +
> > +   of_property_read_string(np, "clock-output-names", );
> 
> What about device property API?

Sorry, which API ?
Many other clk-xxx.c are using this style ?

> > +static int cs2000_version_print(struct cs2000_priv *priv)
> > +{
> > +   struct i2c_client *client = priv_to_client(priv);
> > +   struct device *dev = >dev;
> > +   s32 val = cs2000_read(priv, DEVICE_ID);
> > +   const char *revision;
> > +
> 
> Move read here to see how val is assigned.
> 
> s32 val;
> 
> …
> 
> val = read();
> 
> > +   if (val < 0)
> > +   return val;
> > +
> > +   /* CS2000 should be 0x0 */
> > +   if (0 != (val >> 3))
> 
> if (val >> 3)
> 
> > +   return -EIO;
> > +
> > +   switch (val & 0x7) {
> 
> magic
> 
> > +   case 0x4:
> 
> magic
> 
> > +   revision = "B2 / B3";
> > +   break;
> > +   case 0x6:
> 
> magic

OK


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  

Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-06 Thread Andy Shevchenko
On Tue, Oct 20, 2015 at 4:26 AM, Kuninori Morimoto
 wrote:
> From: Kuninori Morimoto 

Hmm… Something wrong with send-email settings?

> This patch adds CS2000 Fractional-N driver as clock provider.

> +#define CH_SIZE_ERR(ch)((ch < 0) || (ch >= CH_MAX))
> +#define hw_to_priv(_hw)container_of(_hw, struct cs2000_priv, 
> hw)

> +#define priv_to_client(priv)   (priv->client)

to_client()?

> +#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))

to_dev() ?

> +static int cs2000_bset(struct cs2000_priv *priv, u8 addr, u8 mask, u8 val)
> +{
> +   s32 data;
> +
> +   data = cs2000_read(priv, addr);
> +   if (data < 0)
> +   return data;
> +
> +   data &= ~mask;
> +   data |= (val & mask);
> +
> +   return cs2000_write(priv, addr, data);
> +}
> +
> +static int cs2000_enable_dev_config(struct cs2000_priv *priv, bool enable)
> +{
> +   u32 val;
> +   int ret;
> +
> +   val = enable ? ENDEV1 : 0;

Put in expression below?

> +   ret = cs2000_bset(priv, DEVICE_CFG1, ENDEV1, val);
> +   if (ret < 0)
> +   return ret;
> +
> +   val = enable ? ENDEV2 : 0;

Same.

> +   ret = cs2000_bset(priv, GLOBAL_CFG,  ENDEV2, val);
> +   if (ret < 0)
> +   return ret;
> +
> +   return 0;
> +}
> +
> +static int cs2000_clk_in_bound_rate(struct cs2000_priv *priv,
> +   u32 rate_in)
> +{
> +   u32 val;
> +
> +   if (rate_in >= 3200 &&
> +   rate_in < 5600)

One line here and below?

> +   val = 0x0;
> +   else if (rate_in >= 1600 &&
> +rate_in < 2800)
> +   val = 0x1;
> +   else if (rate_in >= 800 &&
> +rate_in < 1400)
> +   val = 0x2;
> +   else
> +   return -EINVAL;
> +
> +   return cs2000_bset(priv, FUNC_CFG1, 0x3 << 3, val << 3);


> +}
> +
> +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
> +{
> +   struct device *dev = priv_to_dev(priv);
> +   s32 val;
> +   unsigned int i;
> +
> +   for (i = 0; i < 256; i++) {
> +   val = cs2000_read(priv, DEVICE_CTRL);
> +   if (val < 0)
> +   return val;
> +   if (!(val & PLL_UNLOCK))
> +   return 0;
> +   udelay(1);
> +   }

unsigned int i = 256;

do {
val = read();
…
while ((val & PLL_UNLOCK) && --i);

if (!i) {
 …
 return -EIO;

Actually -ETIMEDOUT ?

}
return 0;

> +
> +   dev_err(dev, "pll lock failed\n");
> +
> +   return -EIO;
> +}
> +
> +static int cs2000_clk_out_enable(struct cs2000_priv *priv, bool enable)
> +{
> +   u32 val = enable ? 0 : 0x3;

Redundant variable?

> +
> +   /* enable both AUX_OUT, CLK_OUT */
> +   return cs2000_write(priv, DEVICE_CTRL, val);
> +}
> +
> +static u32 cs2000_rate_to_ratio(u32 rate_in, u32 rate_out)
> +{
> +   u64 ratio;
> +
> +   /*
> +* ratio = rate_out / rate_in * 2^20
> +*
> +* To avoid over flow, rate_out is u64
> +* The result should be u32
> +*/
> +   ratio = (u64)rate_out << 20;
> +   do_div(ratio, rate_in);
> +
> +   return (u32)ratio;

No need to do explicit casting.

> +}
> +
> +static unsigned long cs2000_ratio_to_rate(u32 ratio, u32 rate_in)
> +{
> +   u64 rate_out;
> +
> +   /*
> +* ratio = rate_out / rate_in * 2^20
> +*
> +* To avoid over flow, rate_out is u64
> +* The result should be u32

u32 or unsigned long?

Btw, dots at the end of sentences.

> +*/
> +
> +   rate_out = (u64)ratio * rate_in;
> +   return (unsigned long)(rate_out >> 20);

Same.

> +}
> +
> +static int cs2000_ratio_set(struct cs2000_priv *priv,
> +   int ch, u32 rate_in, u32 rate_out)
> +{
> +   u32 val;
> +   unsigned int i;
> +   int ret;
> +
> +   if (CH_SIZE_ERR(ch))
> +   return -EINVAL;
> +
> +   val = cs2000_rate_to_ratio(rate_in, rate_out);
> +   for (i = 0; i < 4; i++)

4 is magic, you have define already.

> +   ret = cs2000_write(priv,
> +  Ratio_Add(ch, i),
> +  Ratio_Val(val, i));
> +   if (ret < 0)
> +   return ret;
> +   }
> +
> +   return 0;
> +}
> +
> +static u32 cs2000_ratio_get(struct cs2000_priv *priv, int ch)
> +{
> +   u32 tmp, val;
> +   unsigned int i;
> +
> +   val = 0;
> +   for (i = 0; i < 4; i++) {

Same.

> +   tmp = cs2000_read(priv,
> + Ratio_Add(ch, i));

One line?

> +   if (tmp < 0)
> +   return 0;
> +
> +   val |= Val_Ratio(tmp, i);
> +   }
> +
> +   return val;
> +}
> +
> +static int cs2000_ratio_select(struct cs2000_priv *priv, int ch)
> +{
> +   int ret;
> +
> +   if (CH_SIZE_ERR(ch))
> +

Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-06 Thread Andy Shevchenko
On Tue, Oct 20, 2015 at 4:26 AM, Kuninori Morimoto
 wrote:
> From: Kuninori Morimoto 

Hmm… Something wrong with send-email settings?

> This patch adds CS2000 Fractional-N driver as clock provider.

> +#define CH_SIZE_ERR(ch)((ch < 0) || (ch >= CH_MAX))
> +#define hw_to_priv(_hw)container_of(_hw, struct cs2000_priv, 
> hw)

> +#define priv_to_client(priv)   (priv->client)

to_client()?

> +#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))

to_dev() ?

> +static int cs2000_bset(struct cs2000_priv *priv, u8 addr, u8 mask, u8 val)
> +{
> +   s32 data;
> +
> +   data = cs2000_read(priv, addr);
> +   if (data < 0)
> +   return data;
> +
> +   data &= ~mask;
> +   data |= (val & mask);
> +
> +   return cs2000_write(priv, addr, data);
> +}
> +
> +static int cs2000_enable_dev_config(struct cs2000_priv *priv, bool enable)
> +{
> +   u32 val;
> +   int ret;
> +
> +   val = enable ? ENDEV1 : 0;

Put in expression below?

> +   ret = cs2000_bset(priv, DEVICE_CFG1, ENDEV1, val);
> +   if (ret < 0)
> +   return ret;
> +
> +   val = enable ? ENDEV2 : 0;

Same.

> +   ret = cs2000_bset(priv, GLOBAL_CFG,  ENDEV2, val);
> +   if (ret < 0)
> +   return ret;
> +
> +   return 0;
> +}
> +
> +static int cs2000_clk_in_bound_rate(struct cs2000_priv *priv,
> +   u32 rate_in)
> +{
> +   u32 val;
> +
> +   if (rate_in >= 3200 &&
> +   rate_in < 5600)

One line here and below?

> +   val = 0x0;
> +   else if (rate_in >= 1600 &&
> +rate_in < 2800)
> +   val = 0x1;
> +   else if (rate_in >= 800 &&
> +rate_in < 1400)
> +   val = 0x2;
> +   else
> +   return -EINVAL;
> +
> +   return cs2000_bset(priv, FUNC_CFG1, 0x3 << 3, val << 3);


> +}
> +
> +static int cs2000_wait_pll_lock(struct cs2000_priv *priv)
> +{
> +   struct device *dev = priv_to_dev(priv);
> +   s32 val;
> +   unsigned int i;
> +
> +   for (i = 0; i < 256; i++) {
> +   val = cs2000_read(priv, DEVICE_CTRL);
> +   if (val < 0)
> +   return val;
> +   if (!(val & PLL_UNLOCK))
> +   return 0;
> +   udelay(1);
> +   }

unsigned int i = 256;

do {
val = read();
…
while ((val & PLL_UNLOCK) && --i);

if (!i) {
 …
 return -EIO;

Actually -ETIMEDOUT ?

}
return 0;

> +
> +   dev_err(dev, "pll lock failed\n");
> +
> +   return -EIO;
> +}
> +
> +static int cs2000_clk_out_enable(struct cs2000_priv *priv, bool enable)
> +{
> +   u32 val = enable ? 0 : 0x3;

Redundant variable?

> +
> +   /* enable both AUX_OUT, CLK_OUT */
> +   return cs2000_write(priv, DEVICE_CTRL, val);
> +}
> +
> +static u32 cs2000_rate_to_ratio(u32 rate_in, u32 rate_out)
> +{
> +   u64 ratio;
> +
> +   /*
> +* ratio = rate_out / rate_in * 2^20
> +*
> +* To avoid over flow, rate_out is u64
> +* The result should be u32
> +*/
> +   ratio = (u64)rate_out << 20;
> +   do_div(ratio, rate_in);
> +
> +   return (u32)ratio;

No need to do explicit casting.

> +}
> +
> +static unsigned long cs2000_ratio_to_rate(u32 ratio, u32 rate_in)
> +{
> +   u64 rate_out;
> +
> +   /*
> +* ratio = rate_out / rate_in * 2^20
> +*
> +* To avoid over flow, rate_out is u64
> +* The result should be u32

u32 or unsigned long?

Btw, dots at the end of sentences.

> +*/
> +
> +   rate_out = (u64)ratio * rate_in;
> +   return (unsigned long)(rate_out >> 20);

Same.

> +}
> +
> +static int cs2000_ratio_set(struct cs2000_priv *priv,
> +   int ch, u32 rate_in, u32 rate_out)
> +{
> +   u32 val;
> +   unsigned int i;
> +   int ret;
> +
> +   if (CH_SIZE_ERR(ch))
> +   return -EINVAL;
> +
> +   val = cs2000_rate_to_ratio(rate_in, rate_out);
> +   for (i = 0; i < 4; i++)

4 is magic, you have define already.

> +   ret = cs2000_write(priv,
> +  Ratio_Add(ch, i),
> +  Ratio_Val(val, i));
> +   if (ret < 0)
> +   return ret;
> +   }
> +
> +   return 0;
> +}
> +
> +static u32 cs2000_ratio_get(struct cs2000_priv *priv, int ch)
> +{
> +   u32 tmp, val;
> +   unsigned int i;
> +
> +   val = 0;
> +   for (i = 0; i < 4; i++) {

Same.

> +   tmp = cs2000_read(priv,
> + Ratio_Add(ch, i));

One line?

> +   if (tmp < 0)
> +   return 0;
> +
> +   val |= Val_Ratio(tmp, i);
> +   }
> +
> +   return val;
> +}
> +
> +static int cs2000_ratio_select(struct cs2000_priv *priv, int 

Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-05 Thread Kuninori Morimoto
Hi again

ping again ?

> [R] 森本 wrote:
> > 
> > From: Kuninori Morimoto 
> > 
> > This patch adds CS2000 Fractional-N driver as clock provider.
> > 
> > Signed-off-by: Kuninori Morimoto 
> > ---
> > v4 -> v5
> > 
> >  - remove "clock-frequency"
> >  - use dev on clk_register()
> >  - remove CLK_IS_BASIC
> >  - .enable -> .prepare since it is using I2C
> >  . .disabe -> .unprepare since it is using I2C
> > 
> >  .../devicetree/bindings/clock/cs2000-cp.txt|  22 +
> >  drivers/clk/Kconfig|   6 +
> >  drivers/clk/Makefile   |   1 +
> >  drivers/clk/clk-cs2000-cp.c| 510 
> > +
> >  4 files changed, 539 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/clock/cs2000-cp.txt
> >  create mode 100644 drivers/clk/clk-cs2000-cp.c
> > 
> > diff --git a/Documentation/devicetree/bindings/clock/cs2000-cp.txt 
> > b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> > new file mode 100644
> > index 000..54e6df0
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> > @@ -0,0 +1,22 @@
> > +CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
> > +
> > +Required properties:
> > +
> > +- compatible:  "cirrus,cs2000-cp"
> > +- reg: The chip select number on the I2C bus
> > +- clocks:  common clock binding for CLK_IN, XTI/REF_CLK
> > +- clock-names: CLK_IN : clk_in, XTI/REF_CLK : ref_clk
> > +- #clock-cells:must be <0>
> > +
> > +Example:
> > +
> > + {
> > +   ...
> > +   cs2000: clk_multiplier@4f {
> > +   #clock-cells = <0>;
> > +   compatible = "cirrus,cs2000-cp";
> > +   reg = <0x4f>;
> > +   clocks = <_sound 0>, <_clk>;
> > +   clock-names = "clk_in", "ref_clk";
> > +   };
> > +};
> > diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> > index 42f7120..0e961b2 100644
> > --- a/drivers/clk/Kconfig
> > +++ b/drivers/clk/Kconfig
> > @@ -95,6 +95,12 @@ config COMMON_CLK_CDCE925
> >   Given a target output frequency, the driver will set the PLL and
> >   divider to best approximate the desired output.
> >  
> > +config COMMON_CLK_CS2000_CP
> > +   tristate "Clock driver for CS2000 Fractional-N Clock Synthesizer & 
> > Clock Multiplier"
> > +   depends on I2C
> > +   help
> > + If you say yes here you get support for the CS2000 clock multiplier.
> > +
> >  config COMMON_CLK_S2MPS11
> > tristate "Clock driver for S2MPS1X/S5M8767 MFD"
> > depends on MFD_SEC_CORE
> > diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> > index 9d31e2c..2fb77a8 100644
> > --- a/drivers/clk/Makefile
> > +++ b/drivers/clk/Makefile
> > @@ -21,6 +21,7 @@ obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)   += 
> > clk-axi-clkgen.o
> >  obj-$(CONFIG_ARCH_AXXIA)   += clk-axm5516.o
> >  obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
> >  obj-$(CONFIG_COMMON_CLK_CDCE706)   += clk-cdce706.o
> > +obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
> >  obj-$(CONFIG_ARCH_CLPS711X)+= clk-clps711x.o
> >  obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
> >  obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
> > diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c
> > new file mode 100644
> > index 000..71d9340
> > --- /dev/null
> > +++ b/drivers/clk/clk-cs2000-cp.c
> > @@ -0,0 +1,510 @@
> > +/*
> > + * CS2000  --  CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock 
> > Multiplier
> > + *
> > + * Copyright (C) 2015 Renesas Electronics Corporation
> > + * Kuninori Morimoto 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define CH_MAX 4
> > +
> > +#define DEVICE_ID  0x1
> > +#define DEVICE_CTRL0x2
> > +#define DEVICE_CFG10x3
> > +#define DEVICE_CFG20x4
> > +#define GLOBAL_CFG 0x5
> > +#define Ratio_Add(x, nth)  (6 + (x * 4) + (nth))
> > +#define Ratio_Val(x, nth)  ((x >> (24 - (8 * nth))) & 0xFF)
> > +#define Val_Ratio(x, nth)  ((x & 0xFF) << (24 - (8 * nth)))
> > +#define FUNC_CFG1  0x16
> > +#define FUNC_CFG2  0x17
> > +
> > +/* DEVICE_CTRL */
> > +#define PLL_UNLOCK (1 << 7)
> > +
> > +/* DEVICE_CFG1 */
> > +#define RSEL(x)(((x) & 0x3) << 3)
> > +#define RSEL_MASK  RSEL(0x3)
> > +#define ENDEV1 (0x1)
> > +
> > +/* GLOBAL_CFG */
> > +#define ENDEV2 (0x1)
> > +
> > +#define CH_SIZE_ERR(ch)((ch < 0) || (ch >= CH_MAX))
> > +#define hw_to_priv(_hw)container_of(_hw, struct cs2000_priv, 
> > hw)
> > +#define priv_to_client(priv)   (priv->client)
> > +#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))
> > +
> > +#define CLK_IN 0
> > 

Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-11-05 Thread Kuninori Morimoto
Hi again

ping again ?

> [R] 森本 wrote:
> > 
> > From: Kuninori Morimoto 
> > 
> > This patch adds CS2000 Fractional-N driver as clock provider.
> > 
> > Signed-off-by: Kuninori Morimoto 
> > ---
> > v4 -> v5
> > 
> >  - remove "clock-frequency"
> >  - use dev on clk_register()
> >  - remove CLK_IS_BASIC
> >  - .enable -> .prepare since it is using I2C
> >  . .disabe -> .unprepare since it is using I2C
> > 
> >  .../devicetree/bindings/clock/cs2000-cp.txt|  22 +
> >  drivers/clk/Kconfig|   6 +
> >  drivers/clk/Makefile   |   1 +
> >  drivers/clk/clk-cs2000-cp.c| 510 
> > +
> >  4 files changed, 539 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/clock/cs2000-cp.txt
> >  create mode 100644 drivers/clk/clk-cs2000-cp.c
> > 
> > diff --git a/Documentation/devicetree/bindings/clock/cs2000-cp.txt 
> > b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> > new file mode 100644
> > index 000..54e6df0
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> > @@ -0,0 +1,22 @@
> > +CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
> > +
> > +Required properties:
> > +
> > +- compatible:  "cirrus,cs2000-cp"
> > +- reg: The chip select number on the I2C bus
> > +- clocks:  common clock binding for CLK_IN, XTI/REF_CLK
> > +- clock-names: CLK_IN : clk_in, XTI/REF_CLK : ref_clk
> > +- #clock-cells:must be <0>
> > +
> > +Example:
> > +
> > + {
> > +   ...
> > +   cs2000: clk_multiplier@4f {
> > +   #clock-cells = <0>;
> > +   compatible = "cirrus,cs2000-cp";
> > +   reg = <0x4f>;
> > +   clocks = <_sound 0>, <_clk>;
> > +   clock-names = "clk_in", "ref_clk";
> > +   };
> > +};
> > diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> > index 42f7120..0e961b2 100644
> > --- a/drivers/clk/Kconfig
> > +++ b/drivers/clk/Kconfig
> > @@ -95,6 +95,12 @@ config COMMON_CLK_CDCE925
> >   Given a target output frequency, the driver will set the PLL and
> >   divider to best approximate the desired output.
> >  
> > +config COMMON_CLK_CS2000_CP
> > +   tristate "Clock driver for CS2000 Fractional-N Clock Synthesizer & 
> > Clock Multiplier"
> > +   depends on I2C
> > +   help
> > + If you say yes here you get support for the CS2000 clock multiplier.
> > +
> >  config COMMON_CLK_S2MPS11
> > tristate "Clock driver for S2MPS1X/S5M8767 MFD"
> > depends on MFD_SEC_CORE
> > diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> > index 9d31e2c..2fb77a8 100644
> > --- a/drivers/clk/Makefile
> > +++ b/drivers/clk/Makefile
> > @@ -21,6 +21,7 @@ obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)   += 
> > clk-axi-clkgen.o
> >  obj-$(CONFIG_ARCH_AXXIA)   += clk-axm5516.o
> >  obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
> >  obj-$(CONFIG_COMMON_CLK_CDCE706)   += clk-cdce706.o
> > +obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
> >  obj-$(CONFIG_ARCH_CLPS711X)+= clk-clps711x.o
> >  obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
> >  obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
> > diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c
> > new file mode 100644
> > index 000..71d9340
> > --- /dev/null
> > +++ b/drivers/clk/clk-cs2000-cp.c
> > @@ -0,0 +1,510 @@
> > +/*
> > + * CS2000  --  CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock 
> > Multiplier
> > + *
> > + * Copyright (C) 2015 Renesas Electronics Corporation
> > + * Kuninori Morimoto 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define CH_MAX 4
> > +
> > +#define DEVICE_ID  0x1
> > +#define DEVICE_CTRL0x2
> > +#define DEVICE_CFG10x3
> > +#define DEVICE_CFG20x4
> > +#define GLOBAL_CFG 0x5
> > +#define Ratio_Add(x, nth)  (6 + (x * 4) + (nth))
> > +#define Ratio_Val(x, nth)  ((x >> (24 - (8 * nth))) & 0xFF)
> > +#define Val_Ratio(x, nth)  ((x & 0xFF) << (24 - (8 * nth)))
> > +#define FUNC_CFG1  0x16
> > +#define FUNC_CFG2  0x17
> > +
> > +/* DEVICE_CTRL */
> > +#define PLL_UNLOCK (1 << 7)
> > +
> > +/* DEVICE_CFG1 */
> > +#define RSEL(x)(((x) & 0x3) << 3)
> > +#define RSEL_MASK  RSEL(0x3)
> > +#define ENDEV1 (0x1)
> > +
> > +/* GLOBAL_CFG */
> > +#define ENDEV2 (0x1)
> > +
> > +#define CH_SIZE_ERR(ch)((ch < 0) || (ch >= CH_MAX))
> > +#define hw_to_priv(_hw)container_of(_hw, struct cs2000_priv, 
> > hw)
> > +#define priv_to_client(priv)   (priv->client)
> 

Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-10-29 Thread Kuninori Morimoto

Hi

ping ?

[R] 森本 wrote:
> 
> From: Kuninori Morimoto 
> 
> This patch adds CS2000 Fractional-N driver as clock provider.
> 
> Signed-off-by: Kuninori Morimoto 
> ---
> v4 -> v5
> 
>  - remove "clock-frequency"
>  - use dev on clk_register()
>  - remove CLK_IS_BASIC
>  - .enable -> .prepare since it is using I2C
>  . .disabe -> .unprepare since it is using I2C
> 
>  .../devicetree/bindings/clock/cs2000-cp.txt|  22 +
>  drivers/clk/Kconfig|   6 +
>  drivers/clk/Makefile   |   1 +
>  drivers/clk/clk-cs2000-cp.c| 510 
> +
>  4 files changed, 539 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/clock/cs2000-cp.txt
>  create mode 100644 drivers/clk/clk-cs2000-cp.c
> 
> diff --git a/Documentation/devicetree/bindings/clock/cs2000-cp.txt 
> b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> new file mode 100644
> index 000..54e6df0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> @@ -0,0 +1,22 @@
> +CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
> +
> +Required properties:
> +
> +- compatible:"cirrus,cs2000-cp"
> +- reg:   The chip select number on the I2C bus
> +- clocks:common clock binding for CLK_IN, XTI/REF_CLK
> +- clock-names:   CLK_IN : clk_in, XTI/REF_CLK : ref_clk
> +- #clock-cells:  must be <0>
> +
> +Example:
> +
> + {
> + ...
> + cs2000: clk_multiplier@4f {
> + #clock-cells = <0>;
> + compatible = "cirrus,cs2000-cp";
> + reg = <0x4f>;
> + clocks = <_sound 0>, <_clk>;
> + clock-names = "clk_in", "ref_clk";
> + };
> +};
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 42f7120..0e961b2 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -95,6 +95,12 @@ config COMMON_CLK_CDCE925
> Given a target output frequency, the driver will set the PLL and
> divider to best approximate the desired output.
>  
> +config COMMON_CLK_CS2000_CP
> + tristate "Clock driver for CS2000 Fractional-N Clock Synthesizer & 
> Clock Multiplier"
> + depends on I2C
> + help
> +   If you say yes here you get support for the CS2000 clock multiplier.
> +
>  config COMMON_CLK_S2MPS11
>   tristate "Clock driver for S2MPS1X/S5M8767 MFD"
>   depends on MFD_SEC_CORE
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index 9d31e2c..2fb77a8 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -21,6 +21,7 @@ obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
>  obj-$(CONFIG_ARCH_AXXIA) += clk-axm5516.o
>  obj-$(CONFIG_ARCH_BCM2835)   += clk-bcm2835.o
>  obj-$(CONFIG_COMMON_CLK_CDCE706) += clk-cdce706.o
> +obj-$(CONFIG_COMMON_CLK_CS2000_CP)   += clk-cs2000-cp.o
>  obj-$(CONFIG_ARCH_CLPS711X)  += clk-clps711x.o
>  obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o
>  obj-$(CONFIG_ARCH_HIGHBANK)  += clk-highbank.o
> diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c
> new file mode 100644
> index 000..71d9340
> --- /dev/null
> +++ b/drivers/clk/clk-cs2000-cp.c
> @@ -0,0 +1,510 @@
> +/*
> + * CS2000  --  CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
> + *
> + * Copyright (C) 2015 Renesas Electronics Corporation
> + * Kuninori Morimoto 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CH_MAX 4
> +
> +#define DEVICE_ID0x1
> +#define DEVICE_CTRL  0x2
> +#define DEVICE_CFG1  0x3
> +#define DEVICE_CFG2  0x4
> +#define GLOBAL_CFG   0x5
> +#define Ratio_Add(x, nth)(6 + (x * 4) + (nth))
> +#define Ratio_Val(x, nth)((x >> (24 - (8 * nth))) & 0xFF)
> +#define Val_Ratio(x, nth)((x & 0xFF) << (24 - (8 * nth)))
> +#define FUNC_CFG10x16
> +#define FUNC_CFG20x17
> +
> +/* DEVICE_CTRL */
> +#define PLL_UNLOCK   (1 << 7)
> +
> +/* DEVICE_CFG1 */
> +#define RSEL(x)  (((x) & 0x3) << 3)
> +#define RSEL_MASKRSEL(0x3)
> +#define ENDEV1   (0x1)
> +
> +/* GLOBAL_CFG */
> +#define ENDEV2   (0x1)
> +
> +#define CH_SIZE_ERR(ch)  ((ch < 0) || (ch >= CH_MAX))
> +#define hw_to_priv(_hw)  container_of(_hw, struct cs2000_priv, 
> hw)
> +#define priv_to_client(priv) (priv->client)
> +#define priv_to_dev(priv)(&(priv_to_client(priv)->dev))
> +
> +#define CLK_IN   0
> +#define REF_CLK  1
> +#define CLK_MAX 2
> +
> +struct cs2000_priv {
> + struct clk_hw hw;
> + struct i2c_client *client;
> + struct clk *clk_in;
> + struct clk *ref_clk;
> + struct clk *clk_out;
> +};
> +
> +static const struct 

Re: [PATCH v5] clk: add CS2000 Fractional-N driver

2015-10-29 Thread Kuninori Morimoto

Hi

ping ?

[R] 森本 wrote:
> 
> From: Kuninori Morimoto 
> 
> This patch adds CS2000 Fractional-N driver as clock provider.
> 
> Signed-off-by: Kuninori Morimoto 
> ---
> v4 -> v5
> 
>  - remove "clock-frequency"
>  - use dev on clk_register()
>  - remove CLK_IS_BASIC
>  - .enable -> .prepare since it is using I2C
>  . .disabe -> .unprepare since it is using I2C
> 
>  .../devicetree/bindings/clock/cs2000-cp.txt|  22 +
>  drivers/clk/Kconfig|   6 +
>  drivers/clk/Makefile   |   1 +
>  drivers/clk/clk-cs2000-cp.c| 510 
> +
>  4 files changed, 539 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/clock/cs2000-cp.txt
>  create mode 100644 drivers/clk/clk-cs2000-cp.c
> 
> diff --git a/Documentation/devicetree/bindings/clock/cs2000-cp.txt 
> b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> new file mode 100644
> index 000..54e6df0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
> @@ -0,0 +1,22 @@
> +CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
> +
> +Required properties:
> +
> +- compatible:"cirrus,cs2000-cp"
> +- reg:   The chip select number on the I2C bus
> +- clocks:common clock binding for CLK_IN, XTI/REF_CLK
> +- clock-names:   CLK_IN : clk_in, XTI/REF_CLK : ref_clk
> +- #clock-cells:  must be <0>
> +
> +Example:
> +
> + {
> + ...
> + cs2000: clk_multiplier@4f {
> + #clock-cells = <0>;
> + compatible = "cirrus,cs2000-cp";
> + reg = <0x4f>;
> + clocks = <_sound 0>, <_clk>;
> + clock-names = "clk_in", "ref_clk";
> + };
> +};
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 42f7120..0e961b2 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -95,6 +95,12 @@ config COMMON_CLK_CDCE925
> Given a target output frequency, the driver will set the PLL and
> divider to best approximate the desired output.
>  
> +config COMMON_CLK_CS2000_CP
> + tristate "Clock driver for CS2000 Fractional-N Clock Synthesizer & 
> Clock Multiplier"
> + depends on I2C
> + help
> +   If you say yes here you get support for the CS2000 clock multiplier.
> +
>  config COMMON_CLK_S2MPS11
>   tristate "Clock driver for S2MPS1X/S5M8767 MFD"
>   depends on MFD_SEC_CORE
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index 9d31e2c..2fb77a8 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -21,6 +21,7 @@ obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
>  obj-$(CONFIG_ARCH_AXXIA) += clk-axm5516.o
>  obj-$(CONFIG_ARCH_BCM2835)   += clk-bcm2835.o
>  obj-$(CONFIG_COMMON_CLK_CDCE706) += clk-cdce706.o
> +obj-$(CONFIG_COMMON_CLK_CS2000_CP)   += clk-cs2000-cp.o
>  obj-$(CONFIG_ARCH_CLPS711X)  += clk-clps711x.o
>  obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o
>  obj-$(CONFIG_ARCH_HIGHBANK)  += clk-highbank.o
> diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c
> new file mode 100644
> index 000..71d9340
> --- /dev/null
> +++ b/drivers/clk/clk-cs2000-cp.c
> @@ -0,0 +1,510 @@
> +/*
> + * CS2000  --  CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
> + *
> + * Copyright (C) 2015 Renesas Electronics Corporation
> + * Kuninori Morimoto 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CH_MAX 4
> +
> +#define DEVICE_ID0x1
> +#define DEVICE_CTRL  0x2
> +#define DEVICE_CFG1  0x3
> +#define DEVICE_CFG2  0x4
> +#define GLOBAL_CFG   0x5
> +#define Ratio_Add(x, nth)(6 + (x * 4) + (nth))
> +#define Ratio_Val(x, nth)((x >> (24 - (8 * nth))) & 0xFF)
> +#define Val_Ratio(x, nth)((x & 0xFF) << (24 - (8 * nth)))
> +#define FUNC_CFG10x16
> +#define FUNC_CFG20x17
> +
> +/* DEVICE_CTRL */
> +#define PLL_UNLOCK   (1 << 7)
> +
> +/* DEVICE_CFG1 */
> +#define RSEL(x)  (((x) & 0x3) << 3)
> +#define RSEL_MASKRSEL(0x3)
> +#define ENDEV1   (0x1)
> +
> +/* GLOBAL_CFG */
> +#define ENDEV2   (0x1)
> +
> +#define CH_SIZE_ERR(ch)  ((ch < 0) || (ch >= CH_MAX))
> +#define hw_to_priv(_hw)  container_of(_hw, struct cs2000_priv, 
> hw)
> +#define priv_to_client(priv) (priv->client)
> +#define priv_to_dev(priv)(&(priv_to_client(priv)->dev))
> +
> +#define CLK_IN   0
> +#define REF_CLK  1
> +#define CLK_MAX 2
> +
> +struct cs2000_priv {
> + struct clk_hw hw;
> + struct i2c_client *client;
> + struct clk 

[PATCH v5] clk: add CS2000 Fractional-N driver

2015-10-19 Thread Kuninori Morimoto
From: Kuninori Morimoto 

This patch adds CS2000 Fractional-N driver as clock provider.

Signed-off-by: Kuninori Morimoto 
---
v4 -> v5

 - remove "clock-frequency"
 - use dev on clk_register()
 - remove CLK_IS_BASIC
 - .enable -> .prepare since it is using I2C
 . .disabe -> .unprepare since it is using I2C

 .../devicetree/bindings/clock/cs2000-cp.txt|  22 +
 drivers/clk/Kconfig|   6 +
 drivers/clk/Makefile   |   1 +
 drivers/clk/clk-cs2000-cp.c| 510 +
 4 files changed, 539 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/cs2000-cp.txt
 create mode 100644 drivers/clk/clk-cs2000-cp.c

diff --git a/Documentation/devicetree/bindings/clock/cs2000-cp.txt 
b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
new file mode 100644
index 000..54e6df0
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
@@ -0,0 +1,22 @@
+CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
+
+Required properties:
+
+- compatible:  "cirrus,cs2000-cp"
+- reg: The chip select number on the I2C bus
+- clocks:  common clock binding for CLK_IN, XTI/REF_CLK
+- clock-names: CLK_IN : clk_in, XTI/REF_CLK : ref_clk
+- #clock-cells:must be <0>
+
+Example:
+
+ {
+   ...
+   cs2000: clk_multiplier@4f {
+   #clock-cells = <0>;
+   compatible = "cirrus,cs2000-cp";
+   reg = <0x4f>;
+   clocks = <_sound 0>, <_clk>;
+   clock-names = "clk_in", "ref_clk";
+   };
+};
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 42f7120..0e961b2 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -95,6 +95,12 @@ config COMMON_CLK_CDCE925
  Given a target output frequency, the driver will set the PLL and
  divider to best approximate the desired output.
 
+config COMMON_CLK_CS2000_CP
+   tristate "Clock driver for CS2000 Fractional-N Clock Synthesizer & 
Clock Multiplier"
+   depends on I2C
+   help
+ If you say yes here you get support for the CS2000 clock multiplier.
+
 config COMMON_CLK_S2MPS11
tristate "Clock driver for S2MPS1X/S5M8767 MFD"
depends on MFD_SEC_CORE
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 9d31e2c..2fb77a8 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)   += clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)   += clk-axm5516.o
 obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
 obj-$(CONFIG_COMMON_CLK_CDCE706)   += clk-cdce706.o
+obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
 obj-$(CONFIG_ARCH_CLPS711X)+= clk-clps711x.o
 obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
 obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c
new file mode 100644
index 000..71d9340
--- /dev/null
+++ b/drivers/clk/clk-cs2000-cp.c
@@ -0,0 +1,510 @@
+/*
+ * CS2000  --  CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ * Kuninori Morimoto 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define CH_MAX 4
+
+#define DEVICE_ID  0x1
+#define DEVICE_CTRL0x2
+#define DEVICE_CFG10x3
+#define DEVICE_CFG20x4
+#define GLOBAL_CFG 0x5
+#define Ratio_Add(x, nth)  (6 + (x * 4) + (nth))
+#define Ratio_Val(x, nth)  ((x >> (24 - (8 * nth))) & 0xFF)
+#define Val_Ratio(x, nth)  ((x & 0xFF) << (24 - (8 * nth)))
+#define FUNC_CFG1  0x16
+#define FUNC_CFG2  0x17
+
+/* DEVICE_CTRL */
+#define PLL_UNLOCK (1 << 7)
+
+/* DEVICE_CFG1 */
+#define RSEL(x)(((x) & 0x3) << 3)
+#define RSEL_MASK  RSEL(0x3)
+#define ENDEV1 (0x1)
+
+/* GLOBAL_CFG */
+#define ENDEV2 (0x1)
+
+#define CH_SIZE_ERR(ch)((ch < 0) || (ch >= CH_MAX))
+#define hw_to_priv(_hw)container_of(_hw, struct cs2000_priv, 
hw)
+#define priv_to_client(priv)   (priv->client)
+#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))
+
+#define CLK_IN 0
+#define REF_CLK1
+#define CLK_MAX 2
+
+struct cs2000_priv {
+   struct clk_hw hw;
+   struct i2c_client *client;
+   struct clk *clk_in;
+   struct clk *ref_clk;
+   struct clk *clk_out;
+};
+
+static const struct of_device_id cs2000_of_match[] = {
+   { .compatible = "cirrus,cs2000-cp", },
+   {},
+};
+MODULE_DEVICE_TABLE(of, cs2000_of_match);
+
+static const struct i2c_device_id cs2000_id[] = {
+   { "cs2000-cp", },
+   {}
+};
+MODULE_DEVICE_TABLE(i2c, cs2000_id);

[PATCH v5] clk: add CS2000 Fractional-N driver

2015-10-19 Thread Kuninori Morimoto
From: Kuninori Morimoto 

This patch adds CS2000 Fractional-N driver as clock provider.

Signed-off-by: Kuninori Morimoto 
---
v4 -> v5

 - remove "clock-frequency"
 - use dev on clk_register()
 - remove CLK_IS_BASIC
 - .enable -> .prepare since it is using I2C
 . .disabe -> .unprepare since it is using I2C

 .../devicetree/bindings/clock/cs2000-cp.txt|  22 +
 drivers/clk/Kconfig|   6 +
 drivers/clk/Makefile   |   1 +
 drivers/clk/clk-cs2000-cp.c| 510 +
 4 files changed, 539 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/cs2000-cp.txt
 create mode 100644 drivers/clk/clk-cs2000-cp.c

diff --git a/Documentation/devicetree/bindings/clock/cs2000-cp.txt 
b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
new file mode 100644
index 000..54e6df0
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/cs2000-cp.txt
@@ -0,0 +1,22 @@
+CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
+
+Required properties:
+
+- compatible:  "cirrus,cs2000-cp"
+- reg: The chip select number on the I2C bus
+- clocks:  common clock binding for CLK_IN, XTI/REF_CLK
+- clock-names: CLK_IN : clk_in, XTI/REF_CLK : ref_clk
+- #clock-cells:must be <0>
+
+Example:
+
+ {
+   ...
+   cs2000: clk_multiplier@4f {
+   #clock-cells = <0>;
+   compatible = "cirrus,cs2000-cp";
+   reg = <0x4f>;
+   clocks = <_sound 0>, <_clk>;
+   clock-names = "clk_in", "ref_clk";
+   };
+};
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 42f7120..0e961b2 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -95,6 +95,12 @@ config COMMON_CLK_CDCE925
  Given a target output frequency, the driver will set the PLL and
  divider to best approximate the desired output.
 
+config COMMON_CLK_CS2000_CP
+   tristate "Clock driver for CS2000 Fractional-N Clock Synthesizer & 
Clock Multiplier"
+   depends on I2C
+   help
+ If you say yes here you get support for the CS2000 clock multiplier.
+
 config COMMON_CLK_S2MPS11
tristate "Clock driver for S2MPS1X/S5M8767 MFD"
depends on MFD_SEC_CORE
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 9d31e2c..2fb77a8 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)   += clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)   += clk-axm5516.o
 obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
 obj-$(CONFIG_COMMON_CLK_CDCE706)   += clk-cdce706.o
+obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
 obj-$(CONFIG_ARCH_CLPS711X)+= clk-clps711x.o
 obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
 obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c
new file mode 100644
index 000..71d9340
--- /dev/null
+++ b/drivers/clk/clk-cs2000-cp.c
@@ -0,0 +1,510 @@
+/*
+ * CS2000  --  CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ * Kuninori Morimoto 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define CH_MAX 4
+
+#define DEVICE_ID  0x1
+#define DEVICE_CTRL0x2
+#define DEVICE_CFG10x3
+#define DEVICE_CFG20x4
+#define GLOBAL_CFG 0x5
+#define Ratio_Add(x, nth)  (6 + (x * 4) + (nth))
+#define Ratio_Val(x, nth)  ((x >> (24 - (8 * nth))) & 0xFF)
+#define Val_Ratio(x, nth)  ((x & 0xFF) << (24 - (8 * nth)))
+#define FUNC_CFG1  0x16
+#define FUNC_CFG2  0x17
+
+/* DEVICE_CTRL */
+#define PLL_UNLOCK (1 << 7)
+
+/* DEVICE_CFG1 */
+#define RSEL(x)(((x) & 0x3) << 3)
+#define RSEL_MASK  RSEL(0x3)
+#define ENDEV1 (0x1)
+
+/* GLOBAL_CFG */
+#define ENDEV2 (0x1)
+
+#define CH_SIZE_ERR(ch)((ch < 0) || (ch >= CH_MAX))
+#define hw_to_priv(_hw)container_of(_hw, struct cs2000_priv, 
hw)
+#define priv_to_client(priv)   (priv->client)
+#define priv_to_dev(priv)  (&(priv_to_client(priv)->dev))
+
+#define CLK_IN 0
+#define REF_CLK1
+#define CLK_MAX 2
+
+struct cs2000_priv {
+   struct clk_hw hw;
+   struct i2c_client *client;
+   struct clk *clk_in;
+   struct clk *ref_clk;
+   struct clk *clk_out;
+};
+
+static const struct of_device_id cs2000_of_match[] = {
+   { .compatible = "cirrus,cs2000-cp", },
+   {},
+};
+MODULE_DEVICE_TABLE(of, cs2000_of_match);
+
+static const struct