By Greg Roumeliotis and Liana B. Baker

(Reuters) - NXP Semiconductors NV <NXPI.O> is exploring selling itself to Qualcomm Inc <QCOM.O> in a deal that could be valued at more than $30 billion, two sources familiar with the matter said on Thursday.

The deal would help diversify Qualcomm's business and make it a bigger supplier to the automotive industry. Talks are in the early stages and NXP may entertain other offers, should they emerge, according to one of the sources.

An agreement with Qualcomm could be struck in the next two to three months, according to the Wall Street Journal, which first reported news of the talks.

Representatives for Netherlands-based NXP and San Diego-based Qualcomm declined to comment.

NXP shares rose 16.9 percent to close at $96.12 on Thursday, while Qualcomm's rose 6.3 percent to $67.45.

NXP closed a nearly $12 billion deal to buy U.S.-based Freescale Semiconductor last December, creating the world's top maker of automotive electronics and doubling the percentage of its auto-related revenue to 40 percent. It could also attract interest from other large semiconductor companies such as Broadcom and Texas Instruments Inc <TXN.O>, analysts have said.

Qualcomm, which supplies Android smartphone makers and Apple Inc <AAPL.O>, has been dealing with slowing smartphone sales and stiff competition from Chinese and Taiwanese rivals.

Qualcomm has so far sat out the transformative consolidation sweeping the industry, which has seen mega-deals such as Avago <AVGO.O> buying Broadcom for $37 billion last year.

Qualcomm gets the bulk of its revenue from chip sales but most of its profit comes from wireless patents it licenses to the mobile industry. It explored a plan to break up its chip business from its patent licensing unit after pressure from activist investor Jana Partners but decided to remain whole.

Mizuho Securities analyst Vijay Rakesh said that the deal would give Qualcomm a roadmap for the next decade while moving away from a maturing handset market and toward the faster growing opportunity in automotives.

Qualcomm was ranked third in terms of revenue among global semiconductor companies in 2015, while NXP ranked No. 7, according to research firm IHS.

RBC analyst Amit Daryanani said the potential deal would be accretive to Qualcomm, which could also use offshore cash.

"Assuming a reasonable valuation is paid, this would be an attractive acquisition for Qualcomm and a good use of $30 billion in cash Qualcomm currently has on their balance sheet," Daryanani said.

NXP has a market value of about $28.5 billion, while Qualcomm's is about $93 billion.

(Reporting by Greg Roumeliotis in New York and Liana B. Baker in San Francisco, Rishika Sadam in Bengaluru and Eric Auchard in Frankfurt; Editing by Ted Kerr, Sriraj Kalluvila and Bernard Orr)